OSDN Git Service

optimize
[pf3gnuchains/gcc-fork.git] / gcc / ada / par-ch12.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                             P A R . C H 1 2                              --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2004 Free Software Foundation, Inc.          --
10 --                                                                          --
11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
12 -- terms of the  GNU General Public License as published  by the Free Soft- --
13 -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
17 -- for  more details.  You should have  received  a copy of the GNU General --
18 -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 pragma Style_Checks (All_Checks);
28 --  Turn off subprogram body ordering check. Subprograms are in order
29 --  by RM section rather than alphabetical
30
31 separate (Par)
32 package body Ch12 is
33
34    --  Local functions, used only in this chapter
35
36    function P_Formal_Derived_Type_Definition           return Node_Id;
37    function P_Formal_Discrete_Type_Definition          return Node_Id;
38    function P_Formal_Fixed_Point_Definition            return Node_Id;
39    function P_Formal_Floating_Point_Definition         return Node_Id;
40    function P_Formal_Modular_Type_Definition           return Node_Id;
41    function P_Formal_Package_Declaration               return Node_Id;
42    function P_Formal_Private_Type_Definition           return Node_Id;
43    function P_Formal_Signed_Integer_Type_Definition    return Node_Id;
44    function P_Formal_Subprogram_Declaration            return Node_Id;
45    function P_Formal_Type_Declaration                  return Node_Id;
46    function P_Formal_Type_Definition                   return Node_Id;
47    function P_Generic_Association                      return Node_Id;
48
49    procedure P_Formal_Object_Declarations (Decls : List_Id);
50    --  Scans one or more formal object declarations and appends them to
51    --  Decls. Scans more than one declaration only in the case where the
52    --  source has a declaration with multiple defining identifiers.
53
54    --------------------------------
55    -- 12.1  Generic (also 8.5.5) --
56    --------------------------------
57
58    --  This routine parses either one of the forms of a generic declaration
59    --  or a generic renaming declaration.
60
61    --  GENERIC_DECLARATION ::=
62    --    GENERIC_SUBPROGRAM_DECLARATION | GENERIC_PACKAGE_DECLARATION
63
64    --  GENERIC_SUBPROGRAM_DECLARATION ::=
65    --    GENERIC_FORMAL_PART SUBPROGRAM_SPECIFICATION;
66
67    --  GENERIC_PACKAGE_DECLARATION ::=
68    --    GENERIC_FORMAL_PART PACKAGE_SPECIFICATION;
69
70    --  GENERIC_FORMAL_PART ::=
71    --    generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
72
73    --  GENERIC_RENAMING_DECLARATION ::=
74    --    generic package DEFINING_PROGRAM_UNIT_NAME
75    --      renames generic_package_NAME
76    --  | generic procedure DEFINING_PROGRAM_UNIT_NAME
77    --      renames generic_procedure_NAME
78    --  | generic function DEFINING_PROGRAM_UNIT_NAME
79    --      renames generic_function_NAME
80
81    --  GENERIC_FORMAL_PARAMETER_DECLARATION ::=
82    --    FORMAL_OBJECT_DECLARATION
83    --  | FORMAL_TYPE_DECLARATION
84    --  | FORMAL_SUBPROGRAM_DECLARATION
85    --  | FORMAL_PACKAGE_DECLARATION
86
87    --  The caller has checked that the initial token is GENERIC
88
89    --  Error recovery: can raise Error_Resync
90
91    function P_Generic return Node_Id is
92       Gen_Sloc   : constant Source_Ptr := Token_Ptr;
93       Gen_Decl   : Node_Id;
94       Decl_Node  : Node_Id;
95       Decls      : List_Id;
96       Def_Unit   : Node_Id;
97       Ren_Token  : Token_Type;
98       Scan_State : Saved_Scan_State;
99
100    begin
101       Scan; -- past GENERIC
102
103       if Token = Tok_Private then
104          Error_Msg_SC ("PRIVATE goes before GENERIC, not after");
105          Scan; -- past junk PRIVATE token
106       end if;
107
108       Save_Scan_State (Scan_State); -- at token past GENERIC
109
110       --  Check for generic renaming declaration case
111
112       if Token = Tok_Package
113         or else Token = Tok_Function
114         or else Token = Tok_Procedure
115       then
116          Ren_Token := Token;
117          Scan; -- scan past PACKAGE, FUNCTION or PROCEDURE
118
119          if Token = Tok_Identifier then
120             Def_Unit := P_Defining_Program_Unit_Name;
121
122             Check_Misspelling_Of (Tok_Renames);
123
124             if Token = Tok_Renames then
125                if Ren_Token = Tok_Package then
126                   Decl_Node := New_Node
127                     (N_Generic_Package_Renaming_Declaration, Gen_Sloc);
128
129                elsif Ren_Token = Tok_Procedure then
130                   Decl_Node := New_Node
131                     (N_Generic_Procedure_Renaming_Declaration, Gen_Sloc);
132
133                else -- Ren_Token = Tok_Function then
134                   Decl_Node := New_Node
135                     (N_Generic_Function_Renaming_Declaration, Gen_Sloc);
136                end if;
137
138                Scan; -- past RENAMES
139                Set_Defining_Unit_Name (Decl_Node, Def_Unit);
140                Set_Name (Decl_Node, P_Name);
141                TF_Semicolon;
142                return Decl_Node;
143             end if;
144          end if;
145       end if;
146
147       --  Fall through if this is *not* a generic renaming declaration
148
149       Restore_Scan_State (Scan_State);
150       Decls := New_List;
151
152       --  Loop through generic parameter declarations and use clauses
153
154       Decl_Loop : loop
155          P_Pragmas_Opt (Decls);
156          Ignore (Tok_Private);
157
158          if Token = Tok_Use then
159             Append (P_Use_Clause, Decls);
160          else
161             --  Parse a generic parameter declaration
162
163             if Token = Tok_Identifier then
164                P_Formal_Object_Declarations (Decls);
165
166             elsif Token = Tok_Type then
167                Append (P_Formal_Type_Declaration, Decls);
168
169             elsif Token = Tok_With then
170                Scan; -- past WITH
171
172                if Token = Tok_Package then
173                   Append (P_Formal_Package_Declaration, Decls);
174
175                elsif Token = Tok_Procedure or Token = Tok_Function then
176                   Append (P_Formal_Subprogram_Declaration, Decls);
177
178                else
179                   Error_Msg_BC
180                     ("FUNCTION, PROCEDURE or PACKAGE expected here");
181                   Resync_Past_Semicolon;
182                end if;
183
184             elsif Token = Tok_Subtype then
185                Error_Msg_SC ("subtype declaration not allowed " &
186                                 "as generic parameter declaration!");
187                Resync_Past_Semicolon;
188
189             else
190                exit Decl_Loop;
191             end if;
192          end if;
193
194       end loop Decl_Loop;
195
196       --  Generic formal part is scanned, scan out subprogram or package spec
197
198       if Token = Tok_Package then
199          Gen_Decl := New_Node (N_Generic_Package_Declaration, Gen_Sloc);
200          Set_Specification (Gen_Decl, P_Package (Pf_Spcn));
201       else
202          Gen_Decl := New_Node (N_Generic_Subprogram_Declaration, Gen_Sloc);
203
204          Set_Specification (Gen_Decl, P_Subprogram_Specification);
205
206          if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
207                                              N_Defining_Program_Unit_Name
208            and then Scope.Last > 0
209          then
210             Error_Msg_SP ("child unit allowed only at library level");
211          end if;
212          TF_Semicolon;
213       end if;
214
215       Set_Generic_Formal_Declarations (Gen_Decl, Decls);
216       return Gen_Decl;
217    end P_Generic;
218
219    -------------------------------
220    -- 12.1  Generic Declaration --
221    -------------------------------
222
223    --  Parsed by P_Generic (12.1)
224
225    ------------------------------------------
226    -- 12.1  Generic Subprogram Declaration --
227    ------------------------------------------
228
229    --  Parsed by P_Generic (12.1)
230
231    ---------------------------------------
232    -- 12.1  Generic Package Declaration --
233    ---------------------------------------
234
235    --  Parsed by P_Generic (12.1)
236
237    -------------------------------
238    -- 12.1  Generic Formal Part --
239    -------------------------------
240
241    --  Parsed by P_Generic (12.1)
242
243    -------------------------------------------------
244    -- 12.1   Generic Formal Parameter Declaration --
245    -------------------------------------------------
246
247    --  Parsed by P_Generic (12.1)
248
249    ---------------------------------
250    -- 12.3  Generic Instantiation --
251    ---------------------------------
252
253    --  Generic package instantiation parsed by P_Package (7.1)
254    --  Generic procedure instantiation parsed by P_Subprogram (6.1)
255    --  Generic function instantiation parsed by P_Subprogram (6.1)
256
257    -------------------------------
258    -- 12.3  Generic Actual Part --
259    -------------------------------
260
261    --  GENERIC_ACTUAL_PART ::=
262    --    (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
263
264    --  Returns a list of generic associations, or Empty if none are present
265
266    --  Error recovery: cannot raise Error_Resync
267
268    function P_Generic_Actual_Part_Opt return List_Id is
269       Association_List : List_Id;
270
271    begin
272       --  Figure out if a generic actual part operation is present. Clearly
273       --  there is no generic actual part if the current token is semicolon
274
275       if Token = Tok_Semicolon then
276          return No_List;
277
278       --  If we don't have a left paren, then we have an error, and the job
279       --  is to figure out whether a left paren or semicolon was intended.
280       --  We assume a missing left paren (and hence a generic actual part
281       --  present) if the current token is not on a new line, or if it is
282       --  indented from the subprogram token. Otherwise assume missing
283       --  semicolon (which will be diagnosed by caller) and no generic part
284
285       elsif Token /= Tok_Left_Paren
286         and then Token_Is_At_Start_Of_Line
287         and then Start_Column <= Scope.Table (Scope.Last).Ecol
288       then
289          return No_List;
290
291       --  Otherwise we have a generic actual part (either a left paren is
292       --  present, or we have decided that there must be a missing left paren)
293
294       else
295          Association_List := New_List;
296          T_Left_Paren;
297
298          loop
299             Append (P_Generic_Association, Association_List);
300             exit when not Comma_Present;
301          end loop;
302
303          T_Right_Paren;
304          return Association_List;
305       end if;
306
307    end P_Generic_Actual_Part_Opt;
308
309    -------------------------------
310    -- 12.3  Generic Association --
311    -------------------------------
312
313    --  GENERIC_ASSOCIATION ::=
314    --    [generic_formal_parameter_SELECTOR_NAME =>]
315    --      EXPLICIT_GENERIC_ACTUAL_PARAMETER
316
317    --  EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
318    --    EXPRESSION      | variable_NAME   | subprogram_NAME
319    --  | entry_NAME      | SUBTYPE_MARK    | package_instance_NAME
320
321    --  Error recovery: cannot raise Error_Resync
322
323    function P_Generic_Association return Node_Id is
324       Scan_State         : Saved_Scan_State;
325       Param_Name_Node    : Node_Id;
326       Generic_Assoc_Node : Node_Id;
327
328    begin
329       Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
330
331       if Token in Token_Class_Desig then
332          Param_Name_Node := Token_Node;
333          Save_Scan_State (Scan_State); -- at designator
334          Scan; -- past simple name or operator symbol
335
336          if Token = Tok_Arrow then
337             Scan; -- past arrow
338             Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
339          else
340             Restore_Scan_State (Scan_State); -- to designator
341          end if;
342       end if;
343
344       Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, P_Expression);
345       return Generic_Assoc_Node;
346    end P_Generic_Association;
347
348    ---------------------------------------------
349    -- 12.3  Explicit Generic Actual Parameter --
350    ---------------------------------------------
351
352    --  Parsed by P_Generic_Association (12.3)
353
354    --------------------------------------
355    -- 12.4  Formal Object Declarations --
356    --------------------------------------
357
358    --  FORMAL_OBJECT_DECLARATION ::=
359    --    DEFINING_IDENTIFIER_LIST :
360    --      MODE SUBTYPE_MARK [:= DEFAULT_EXPRESSION];
361
362    --  The caller has checked that the initial token is an identifier
363
364    --  Error recovery: cannot raise Error_Resync
365
366    procedure P_Formal_Object_Declarations (Decls : List_Id) is
367       Decl_Node  : Node_Id;
368       Scan_State : Saved_Scan_State;
369       Num_Idents : Nat;
370       Ident      : Nat;
371
372       Idents : array (Int range 1 .. 4096) of Entity_Id;
373       --  This array holds the list of defining identifiers. The upper bound
374       --  of 4096 is intended to be essentially infinite, and we do not even
375       --  bother to check for it being exceeded.
376
377    begin
378       Idents (1) := P_Defining_Identifier (C_Comma_Colon);
379       Num_Idents := 1;
380
381       while Comma_Present loop
382          Num_Idents := Num_Idents + 1;
383          Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
384       end loop;
385
386       T_Colon;
387
388       --  If there are multiple identifiers, we repeatedly scan the
389       --  type and initialization expression information by resetting
390       --  the scan pointer (so that we get completely separate trees
391       --  for each occurrence).
392
393       if Num_Idents > 1 then
394          Save_Scan_State (Scan_State);
395       end if;
396
397       --  Loop through defining identifiers in list
398
399       Ident := 1;
400       Ident_Loop : loop
401          Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
402          Set_Defining_Identifier (Decl_Node, Idents (Ident));
403          P_Mode (Decl_Node);
404          Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
405          No_Constraint;
406          Set_Expression (Decl_Node, Init_Expr_Opt);
407
408          if Ident > 1 then
409             Set_Prev_Ids (Decl_Node, True);
410          end if;
411
412          if Ident < Num_Idents then
413             Set_More_Ids (Decl_Node, True);
414          end if;
415
416          Append (Decl_Node, Decls);
417
418          exit Ident_Loop when Ident = Num_Idents;
419          Ident := Ident + 1;
420          Restore_Scan_State (Scan_State);
421       end loop Ident_Loop;
422
423       TF_Semicolon;
424    end P_Formal_Object_Declarations;
425
426    -----------------------------------
427    -- 12.5  Formal Type Declaration --
428    -----------------------------------
429
430    --  FORMAL_TYPE_DECLARATION ::=
431    --    type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
432    --      is FORMAL_TYPE_DEFINITION;
433
434    --  The caller has checked that the initial token is TYPE
435
436    --  Error recovery: cannot raise Error_Resync
437
438    function P_Formal_Type_Declaration return Node_Id is
439       Decl_Node  : Node_Id;
440       Def_Node   : Node_Id;
441
442    begin
443       Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
444       Scan; -- past TYPE
445       Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
446
447       if P_Unknown_Discriminant_Part_Opt then
448          Set_Unknown_Discriminants_Present (Decl_Node, True);
449       else
450          Set_Discriminant_Specifications
451            (Decl_Node, P_Known_Discriminant_Part_Opt);
452       end if;
453
454       T_Is;
455
456       Def_Node := P_Formal_Type_Definition;
457
458       if Def_Node /= Error then
459          Set_Formal_Type_Definition (Decl_Node, Def_Node);
460          TF_Semicolon;
461
462       else
463          Decl_Node := Error;
464
465          --  If we have semicolon, skip it to avoid cascaded errors
466
467          if Token = Tok_Semicolon then
468             Scan;
469          end if;
470       end if;
471
472       return Decl_Node;
473    end P_Formal_Type_Declaration;
474
475    ----------------------------------
476    -- 12.5  Formal Type Definition --
477    ----------------------------------
478
479    --  FORMAL_TYPE_DEFINITION ::=
480    --    FORMAL_PRIVATE_TYPE_DEFINITION
481    --  | FORMAL_DERIVED_TYPE_DEFINITION
482    --  | FORMAL_DISCRETE_TYPE_DEFINITION
483    --  | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
484    --  | FORMAL_MODULAR_TYPE_DEFINITION
485    --  | FORMAL_FLOATING_POINT_DEFINITION
486    --  | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
487    --  | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
488    --  | FORMAL_ARRAY_TYPE_DEFINITION
489    --  | FORMAL_ACCESS_TYPE_DEFINITION
490
491    --  FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
492
493    --  FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
494
495    function P_Formal_Type_Definition return Node_Id is
496       Scan_State : Saved_Scan_State;
497
498    begin
499       if Token_Name = Name_Abstract then
500          Check_95_Keyword (Tok_Abstract, Tok_Tagged);
501       end if;
502
503       if Token_Name = Name_Tagged then
504          Check_95_Keyword (Tok_Tagged, Tok_Private);
505          Check_95_Keyword (Tok_Tagged, Tok_Limited);
506       end if;
507
508       case Token is
509
510          --  Mostly we can tell what we have from the initial token. The one
511          --  exception is ABSTRACT, where we have to scan ahead to see if we
512          --  have a formal derived type or a formal private type definition.
513
514          when Tok_Abstract =>
515             Save_Scan_State (Scan_State);
516             Scan; -- past ABSTRACT
517
518             if Token = Tok_New then
519                Restore_Scan_State (Scan_State); -- to ABSTRACT
520                return P_Formal_Derived_Type_Definition;
521
522             else
523                Restore_Scan_State (Scan_State); -- to ABSTRACT
524                return P_Formal_Private_Type_Definition;
525             end if;
526
527          when Tok_Private | Tok_Limited | Tok_Tagged =>
528             return P_Formal_Private_Type_Definition;
529
530          when Tok_New =>
531             return P_Formal_Derived_Type_Definition;
532
533          when Tok_Left_Paren =>
534             return P_Formal_Discrete_Type_Definition;
535
536          when Tok_Range =>
537             return P_Formal_Signed_Integer_Type_Definition;
538
539          when Tok_Mod =>
540             return P_Formal_Modular_Type_Definition;
541
542          when Tok_Digits =>
543             return P_Formal_Floating_Point_Definition;
544
545          when Tok_Delta =>
546             return P_Formal_Fixed_Point_Definition;
547
548          when Tok_Array =>
549             return P_Array_Type_Definition;
550
551          when Tok_Access =>
552             return P_Access_Type_Definition;
553
554          when Tok_Record =>
555             Error_Msg_SC ("record not allowed in generic type definition!");
556             Discard_Junk_Node (P_Record_Definition);
557             return Error;
558
559          when others =>
560             Error_Msg_BC ("expecting generic type definition here");
561             Resync_Past_Semicolon;
562             return Error;
563
564       end case;
565    end P_Formal_Type_Definition;
566
567    --------------------------------------------
568    -- 12.5.1  Formal Private Type Definition --
569    --------------------------------------------
570
571    --  FORMAL_PRIVATE_TYPE_DEFINITION ::=
572    --    [[abstract] tagged] [limited] private
573
574    --  The caller has checked the initial token is PRIVATE, ABSTRACT,
575    --   TAGGED or LIMITED
576
577    --  Error recovery: cannot raise Error_Resync
578
579    function P_Formal_Private_Type_Definition return Node_Id is
580       Def_Node : Node_Id;
581
582    begin
583       Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
584
585       if Token = Tok_Abstract then
586          Scan; -- past ABSTRACT
587
588          if Token_Name = Name_Tagged then
589             Check_95_Keyword (Tok_Tagged, Tok_Private);
590             Check_95_Keyword (Tok_Tagged, Tok_Limited);
591          end if;
592
593          if Token /= Tok_Tagged then
594             Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
595          else
596             Set_Abstract_Present (Def_Node, True);
597          end if;
598       end if;
599
600       if Token = Tok_Tagged then
601          Set_Tagged_Present (Def_Node, True);
602          Scan; -- past TAGGED
603       end if;
604
605       if Token = Tok_Limited then
606          Set_Limited_Present (Def_Node, True);
607          Scan; -- past LIMITED
608       end if;
609
610       Set_Sloc (Def_Node, Token_Ptr);
611       T_Private;
612       return Def_Node;
613    end P_Formal_Private_Type_Definition;
614
615    --------------------------------------------
616    -- 12.5.1  Formal Derived Type Definition --
617    --------------------------------------------
618
619    --  FORMAL_DERIVED_TYPE_DEFINITION ::=
620    --    [abstract] new SUBTYPE_MARK [with private]
621
622    --  The caller has checked the initial token(s) is/are NEW or ASTRACT NEW
623
624    --  Error recovery: cannot raise Error_Resync
625
626    function P_Formal_Derived_Type_Definition return Node_Id is
627       Def_Node : Node_Id;
628
629    begin
630       Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
631
632       if Token = Tok_Abstract then
633          Set_Abstract_Present (Def_Node);
634          Scan; -- past ABSTRACT
635       end if;
636
637       Scan; -- past NEW;
638       Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
639       No_Constraint;
640
641       if Token = Tok_With then
642          Scan; -- past WITH
643          Set_Private_Present (Def_Node, True);
644          T_Private;
645
646       elsif Token = Tok_Tagged then
647          Scan;
648
649          if Token = Tok_Private then
650             Error_Msg_SC ("TAGGED should be WITH");
651             Set_Private_Present (Def_Node, True);
652             T_Private;
653          else
654             Ignore (Tok_Tagged);
655          end if;
656       end if;
657
658       return Def_Node;
659    end P_Formal_Derived_Type_Definition;
660
661    ---------------------------------------------
662    -- 12.5.2  Formal Discrete Type Definition --
663    ---------------------------------------------
664
665    --  FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
666
667    --  The caller has checked the initial token is left paren
668
669    --  Error recovery: cannot raise Error_Resync
670
671    function P_Formal_Discrete_Type_Definition return Node_Id is
672       Def_Node : Node_Id;
673
674    begin
675       Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
676       Scan; -- past left paren
677       T_Box;
678       T_Right_Paren;
679       return Def_Node;
680    end P_Formal_Discrete_Type_Definition;
681
682    ---------------------------------------------------
683    -- 12.5.2  Formal Signed Integer Type Definition --
684    ---------------------------------------------------
685
686    --  FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
687
688    --  The caller has checked the initial token is RANGE
689
690    --  Error recovery: cannot raise Error_Resync
691
692    function P_Formal_Signed_Integer_Type_Definition return Node_Id is
693       Def_Node : Node_Id;
694
695    begin
696       Def_Node :=
697         New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
698       Scan; -- past RANGE
699       T_Box;
700       return Def_Node;
701    end P_Formal_Signed_Integer_Type_Definition;
702
703    --------------------------------------------
704    -- 12.5.2  Formal Modular Type Definition --
705    --------------------------------------------
706
707    --  FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
708
709    --  The caller has checked the initial token is MOD
710
711    --  Error recovery: cannot raise Error_Resync
712
713    function P_Formal_Modular_Type_Definition return Node_Id is
714       Def_Node : Node_Id;
715
716    begin
717       Def_Node :=
718         New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
719       Scan; -- past MOD
720       T_Box;
721       return Def_Node;
722    end P_Formal_Modular_Type_Definition;
723
724    ----------------------------------------------
725    -- 12.5.2  Formal Floating Point Definition --
726    ----------------------------------------------
727
728    --  FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
729
730    --  The caller has checked the initial token is DIGITS
731
732    --  Error recovery: cannot raise Error_Resync
733
734    function P_Formal_Floating_Point_Definition return Node_Id is
735       Def_Node : Node_Id;
736
737    begin
738       Def_Node :=
739         New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
740       Scan; -- past DIGITS
741       T_Box;
742       return Def_Node;
743    end P_Formal_Floating_Point_Definition;
744
745    -------------------------------------------
746    -- 12.5.2  Formal Fixed Point Definition --
747    -------------------------------------------
748
749    --  This routine parses either a formal ordinary fixed point definition
750    --  or a formal decimal fixed point definition:
751
752    --  FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
753
754    --  FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
755
756    --  The caller has checked the initial token is DELTA
757
758    --  Error recovery: cannot raise Error_Resync
759
760    function P_Formal_Fixed_Point_Definition return Node_Id is
761       Def_Node   : Node_Id;
762       Delta_Sloc : Source_Ptr;
763
764    begin
765       Delta_Sloc := Token_Ptr;
766       Scan; -- past DELTA
767       T_Box;
768
769       if Token = Tok_Digits then
770          Def_Node :=
771            New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
772          Scan; -- past DIGITS
773          T_Box;
774       else
775          Def_Node :=
776            New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
777       end if;
778
779       return Def_Node;
780    end P_Formal_Fixed_Point_Definition;
781
782    ----------------------------------------------------
783    -- 12.5.2  Formal Ordinary Fixed Point Definition --
784    ----------------------------------------------------
785
786    --  Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
787
788    ---------------------------------------------------
789    -- 12.5.2  Formal Decimal Fixed Point Definition --
790    ---------------------------------------------------
791
792    --  Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
793
794    ------------------------------------------
795    -- 12.5.3  Formal Array Type Definition --
796    ------------------------------------------
797
798    --  Parsed by P_Formal_Type_Definition (12.5)
799
800    -------------------------------------------
801    -- 12.5.4  Formal Access Type Definition --
802    -------------------------------------------
803
804    --  Parsed by P_Formal_Type_Definition (12.5)
805
806    -----------------------------------------
807    -- 12.6  Formal Subprogram Declaration --
808    -----------------------------------------
809
810    --  FORMAL_SUBPROGRAM_DECLARATION ::=
811    --    with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
812
813    --  SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
814
815    --  DEFAULT_NAME ::= NAME
816
817    --  The caller has checked that the initial tokens are WITH FUNCTION or
818    --  WITH PROCEDURE, and the initial WITH has been scanned out.
819
820    --  Note: we separate this into two procedures because the name is allowed
821    --  to be an operator symbol for a function, but not for a procedure.
822
823    --  Error recovery: cannot raise Error_Resync
824
825    function P_Formal_Subprogram_Declaration return Node_Id is
826       Def_Node : Node_Id;
827
828    begin
829       Def_Node := New_Node (N_Formal_Subprogram_Declaration, Prev_Token_Ptr);
830       Set_Specification (Def_Node, P_Subprogram_Specification);
831
832       if Token = Tok_Is then
833          T_Is; -- past IS, skip extra IS or ";"
834
835          if Token = Tok_Box then
836             Set_Box_Present (Def_Node, True);
837             Scan; -- past <>
838
839          else
840             Set_Default_Name (Def_Node, P_Name);
841          end if;
842
843       end if;
844
845       T_Semicolon;
846       return Def_Node;
847    end P_Formal_Subprogram_Declaration;
848
849    ------------------------------
850    -- 12.6  Subprogram Default --
851    ------------------------------
852
853    --  Parsed by P_Formal_Procedure_Declaration (12.6)
854
855    ------------------------
856    -- 12.6  Default Name --
857    ------------------------
858
859    --  Parsed by P_Formal_Procedure_Declaration (12.6)
860
861    --------------------------------------
862    -- 12.7  Formal Package Declaration --
863    --------------------------------------
864
865    --  FORMAL_PACKAGE_DECLARATION ::=
866    --    with package DEFINING_IDENTIFIER
867    --      is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
868
869    --  FORMAL_PACKAGE_ACTUAL_PART ::=
870    --    (<>) | [GENERIC_ACTUAL_PART]
871
872    --  The caller has checked that the initial tokens are WITH PACKAGE,
873    --  and the initial WITH has been scanned out (so Token = Tok_Package).
874
875    --  Error recovery: cannot raise Error_Resync
876
877    function P_Formal_Package_Declaration return Node_Id is
878       Def_Node : Node_Id;
879       Scan_State : Saved_Scan_State;
880
881    begin
882       Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
883       Scan; -- past PACKAGE
884       Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
885       T_Is;
886       T_New;
887       Set_Name (Def_Node, P_Qualified_Simple_Name);
888
889       if Token = Tok_Left_Paren then
890          Save_Scan_State (Scan_State); -- at the left paren
891          Scan; -- past the left paren
892
893          if Token = Tok_Box then
894             Set_Box_Present (Def_Node, True);
895             Scan; -- past box
896             T_Right_Paren;
897
898          else
899             Restore_Scan_State (Scan_State); -- to the left paren
900             Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
901          end if;
902       end if;
903
904       T_Semicolon;
905       return Def_Node;
906    end P_Formal_Package_Declaration;
907
908    --------------------------------------
909    -- 12.7  Formal Package Actual Part --
910    --------------------------------------
911
912    --  Parsed by P_Formal_Package_Declaration (12.7)
913
914 end Ch12;