OSDN Git Service

* 3vtrasym.adb:
[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-2003 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          Set_Specification (Gen_Decl, P_Subprogram_Specification);
204          TF_Semicolon;
205       end if;
206
207       Set_Generic_Formal_Declarations (Gen_Decl, Decls);
208       return Gen_Decl;
209    end P_Generic;
210
211    -------------------------------
212    -- 12.1  Generic Declaration --
213    -------------------------------
214
215    --  Parsed by P_Generic (12.1)
216
217    ------------------------------------------
218    -- 12.1  Generic Subprogram Declaration --
219    ------------------------------------------
220
221    --  Parsed by P_Generic (12.1)
222
223    ---------------------------------------
224    -- 12.1  Generic Package Declaration --
225    ---------------------------------------
226
227    --  Parsed by P_Generic (12.1)
228
229    -------------------------------
230    -- 12.1  Generic Formal Part --
231    -------------------------------
232
233    --  Parsed by P_Generic (12.1)
234
235    -------------------------------------------------
236    -- 12.1   Generic Formal Parameter Declaration --
237    -------------------------------------------------
238
239    --  Parsed by P_Generic (12.1)
240
241    ---------------------------------
242    -- 12.3  Generic Instantiation --
243    ---------------------------------
244
245    --  Generic package instantiation parsed by P_Package (7.1)
246    --  Generic procedure instantiation parsed by P_Subprogram (6.1)
247    --  Generic function instantiation parsed by P_Subprogram (6.1)
248
249    -------------------------------
250    -- 12.3  Generic Actual Part --
251    -------------------------------
252
253    --  GENERIC_ACTUAL_PART ::=
254    --    (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
255
256    --  Returns a list of generic associations, or Empty if none are present
257
258    --  Error recovery: cannot raise Error_Resync
259
260    function P_Generic_Actual_Part_Opt return List_Id is
261       Association_List : List_Id;
262
263    begin
264       --  Figure out if a generic actual part operation is present. Clearly
265       --  there is no generic actual part if the current token is semicolon
266
267       if Token = Tok_Semicolon then
268          return No_List;
269
270       --  If we don't have a left paren, then we have an error, and the job
271       --  is to figure out whether a left paren or semicolon was intended.
272       --  We assume a missing left paren (and hence a generic actual part
273       --  present) if the current token is not on a new line, or if it is
274       --  indented from the subprogram token. Otherwise assume missing
275       --  semicolon (which will be diagnosed by caller) and no generic part
276
277       elsif Token /= Tok_Left_Paren
278         and then Token_Is_At_Start_Of_Line
279         and then Start_Column <= Scope.Table (Scope.Last).Ecol
280       then
281          return No_List;
282
283       --  Otherwise we have a generic actual part (either a left paren is
284       --  present, or we have decided that there must be a missing left paren)
285
286       else
287          Association_List := New_List;
288          T_Left_Paren;
289
290          loop
291             Append (P_Generic_Association, Association_List);
292             exit when not Comma_Present;
293          end loop;
294
295          T_Right_Paren;
296          return Association_List;
297       end if;
298
299    end P_Generic_Actual_Part_Opt;
300
301    -------------------------------
302    -- 12.3  Generic Association --
303    -------------------------------
304
305    --  GENERIC_ASSOCIATION ::=
306    --    [generic_formal_parameter_SELECTOR_NAME =>]
307    --      EXPLICIT_GENERIC_ACTUAL_PARAMETER
308
309    --  EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
310    --    EXPRESSION      | variable_NAME   | subprogram_NAME
311    --  | entry_NAME      | SUBTYPE_MARK    | package_instance_NAME
312
313    --  Error recovery: cannot raise Error_Resync
314
315    function P_Generic_Association return Node_Id is
316       Scan_State         : Saved_Scan_State;
317       Param_Name_Node    : Node_Id;
318       Generic_Assoc_Node : Node_Id;
319
320    begin
321       Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
322
323       if Token in Token_Class_Desig then
324          Param_Name_Node := Token_Node;
325          Save_Scan_State (Scan_State); -- at designator
326          Scan; -- past simple name or operator symbol
327
328          if Token = Tok_Arrow then
329             Scan; -- past arrow
330             Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
331          else
332             Restore_Scan_State (Scan_State); -- to designator
333          end if;
334       end if;
335
336       Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, P_Expression);
337       return Generic_Assoc_Node;
338    end P_Generic_Association;
339
340    ---------------------------------------------
341    -- 12.3  Explicit Generic Actual Parameter --
342    ---------------------------------------------
343
344    --  Parsed by P_Generic_Association (12.3)
345
346    --------------------------------------
347    -- 12.4  Formal Object Declarations --
348    --------------------------------------
349
350    --  FORMAL_OBJECT_DECLARATION ::=
351    --    DEFINING_IDENTIFIER_LIST :
352    --      MODE SUBTYPE_MARK [:= DEFAULT_EXPRESSION];
353
354    --  The caller has checked that the initial token is an identifier
355
356    --  Error recovery: cannot raise Error_Resync
357
358    procedure P_Formal_Object_Declarations (Decls : List_Id) is
359       Decl_Node  : Node_Id;
360       Scan_State : Saved_Scan_State;
361       Num_Idents : Nat;
362       Ident      : Nat;
363
364       Idents : array (Int range 1 .. 4096) of Entity_Id;
365       --  This array holds the list of defining identifiers. The upper bound
366       --  of 4096 is intended to be essentially infinite, and we do not even
367       --  bother to check for it being exceeded.
368
369    begin
370       Idents (1) := P_Defining_Identifier (C_Comma_Colon);
371       Num_Idents := 1;
372
373       while Comma_Present loop
374          Num_Idents := Num_Idents + 1;
375          Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
376       end loop;
377
378       T_Colon;
379
380       --  If there are multiple identifiers, we repeatedly scan the
381       --  type and initialization expression information by resetting
382       --  the scan pointer (so that we get completely separate trees
383       --  for each occurrence).
384
385       if Num_Idents > 1 then
386          Save_Scan_State (Scan_State);
387       end if;
388
389       --  Loop through defining identifiers in list
390
391       Ident := 1;
392       Ident_Loop : loop
393          Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
394          Set_Defining_Identifier (Decl_Node, Idents (Ident));
395          P_Mode (Decl_Node);
396          Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
397          No_Constraint;
398          Set_Expression (Decl_Node, Init_Expr_Opt);
399
400          if Ident > 1 then
401             Set_Prev_Ids (Decl_Node, True);
402          end if;
403
404          if Ident < Num_Idents then
405             Set_More_Ids (Decl_Node, True);
406          end if;
407
408          Append (Decl_Node, Decls);
409
410          exit Ident_Loop when Ident = Num_Idents;
411          Ident := Ident + 1;
412          Restore_Scan_State (Scan_State);
413       end loop Ident_Loop;
414
415       TF_Semicolon;
416    end P_Formal_Object_Declarations;
417
418    -----------------------------------
419    -- 12.5  Formal Type Declaration --
420    -----------------------------------
421
422    --  FORMAL_TYPE_DECLARATION ::=
423    --    type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
424    --      is FORMAL_TYPE_DEFINITION;
425
426    --  The caller has checked that the initial token is TYPE
427
428    --  Error recovery: cannot raise Error_Resync
429
430    function P_Formal_Type_Declaration return Node_Id is
431       Decl_Node  : Node_Id;
432       Def_Node   : Node_Id;
433
434    begin
435       Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
436       Scan; -- past TYPE
437       Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
438
439       if P_Unknown_Discriminant_Part_Opt then
440          Set_Unknown_Discriminants_Present (Decl_Node, True);
441       else
442          Set_Discriminant_Specifications
443            (Decl_Node, P_Known_Discriminant_Part_Opt);
444       end if;
445
446       T_Is;
447
448       Def_Node := P_Formal_Type_Definition;
449
450       if Def_Node /= Error then
451          Set_Formal_Type_Definition (Decl_Node, Def_Node);
452          TF_Semicolon;
453
454       else
455          Decl_Node := Error;
456
457          --  If we have semicolon, skip it to avoid cascaded errors
458
459          if Token = Tok_Semicolon then
460             Scan;
461          end if;
462       end if;
463
464       return Decl_Node;
465    end P_Formal_Type_Declaration;
466
467    ----------------------------------
468    -- 12.5  Formal Type Definition --
469    ----------------------------------
470
471    --  FORMAL_TYPE_DEFINITION ::=
472    --    FORMAL_PRIVATE_TYPE_DEFINITION
473    --  | FORMAL_DERIVED_TYPE_DEFINITION
474    --  | FORMAL_DISCRETE_TYPE_DEFINITION
475    --  | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
476    --  | FORMAL_MODULAR_TYPE_DEFINITION
477    --  | FORMAL_FLOATING_POINT_DEFINITION
478    --  | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
479    --  | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
480    --  | FORMAL_ARRAY_TYPE_DEFINITION
481    --  | FORMAL_ACCESS_TYPE_DEFINITION
482
483    --  FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
484
485    --  FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
486
487    function P_Formal_Type_Definition return Node_Id is
488       Scan_State : Saved_Scan_State;
489
490    begin
491       if Token_Name = Name_Abstract then
492          Check_95_Keyword (Tok_Abstract, Tok_Tagged);
493       end if;
494
495       if Token_Name = Name_Tagged then
496          Check_95_Keyword (Tok_Tagged, Tok_Private);
497          Check_95_Keyword (Tok_Tagged, Tok_Limited);
498       end if;
499
500       case Token is
501
502          --  Mostly we can tell what we have from the initial token. The one
503          --  exception is ABSTRACT, where we have to scan ahead to see if we
504          --  have a formal derived type or a formal private type definition.
505
506          when Tok_Abstract =>
507             Save_Scan_State (Scan_State);
508             Scan; -- past ABSTRACT
509
510             if Token = Tok_New then
511                Restore_Scan_State (Scan_State); -- to ABSTRACT
512                return P_Formal_Derived_Type_Definition;
513
514             else
515                Restore_Scan_State (Scan_State); -- to ABSTRACT
516                return P_Formal_Private_Type_Definition;
517             end if;
518
519          when Tok_Private | Tok_Limited | Tok_Tagged =>
520             return P_Formal_Private_Type_Definition;
521
522          when Tok_New =>
523             return P_Formal_Derived_Type_Definition;
524
525          when Tok_Left_Paren =>
526             return P_Formal_Discrete_Type_Definition;
527
528          when Tok_Range =>
529             return P_Formal_Signed_Integer_Type_Definition;
530
531          when Tok_Mod =>
532             return P_Formal_Modular_Type_Definition;
533
534          when Tok_Digits =>
535             return P_Formal_Floating_Point_Definition;
536
537          when Tok_Delta =>
538             return P_Formal_Fixed_Point_Definition;
539
540          when Tok_Array =>
541             return P_Array_Type_Definition;
542
543          when Tok_Access =>
544             return P_Access_Type_Definition;
545
546          when Tok_Record =>
547             Error_Msg_SC ("record not allowed in generic type definition!");
548             Discard_Junk_Node (P_Record_Definition);
549             return Error;
550
551          when others =>
552             Error_Msg_BC ("expecting generic type definition here");
553             Resync_Past_Semicolon;
554             return Error;
555
556       end case;
557    end P_Formal_Type_Definition;
558
559    --------------------------------------------
560    -- 12.5.1  Formal Private Type Definition --
561    --------------------------------------------
562
563    --  FORMAL_PRIVATE_TYPE_DEFINITION ::=
564    --    [[abstract] tagged] [limited] private
565
566    --  The caller has checked the initial token is PRIVATE, ABSTRACT,
567    --   TAGGED or LIMITED
568
569    --  Error recovery: cannot raise Error_Resync
570
571    function P_Formal_Private_Type_Definition return Node_Id is
572       Def_Node : Node_Id;
573
574    begin
575       Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
576
577       if Token = Tok_Abstract then
578          Scan; -- past ABSTRACT
579
580          if Token_Name = Name_Tagged then
581             Check_95_Keyword (Tok_Tagged, Tok_Private);
582             Check_95_Keyword (Tok_Tagged, Tok_Limited);
583          end if;
584
585          if Token /= Tok_Tagged then
586             Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
587          else
588             Set_Abstract_Present (Def_Node, True);
589          end if;
590       end if;
591
592       if Token = Tok_Tagged then
593          Set_Tagged_Present (Def_Node, True);
594          Scan; -- past TAGGED
595       end if;
596
597       if Token = Tok_Limited then
598          Set_Limited_Present (Def_Node, True);
599          Scan; -- past LIMITED
600       end if;
601
602       Set_Sloc (Def_Node, Token_Ptr);
603       T_Private;
604       return Def_Node;
605    end P_Formal_Private_Type_Definition;
606
607    --------------------------------------------
608    -- 12.5.1  Formal Derived Type Definition --
609    --------------------------------------------
610
611    --  FORMAL_DERIVED_TYPE_DEFINITION ::=
612    --    [abstract] new SUBTYPE_MARK [with private]
613
614    --  The caller has checked the initial token(s) is/are NEW or ASTRACT NEW
615
616    --  Error recovery: cannot raise Error_Resync
617
618    function P_Formal_Derived_Type_Definition return Node_Id is
619       Def_Node : Node_Id;
620
621    begin
622       Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
623
624       if Token = Tok_Abstract then
625          Set_Abstract_Present (Def_Node);
626          Scan; -- past ABSTRACT
627       end if;
628
629       Scan; -- past NEW;
630       Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
631       No_Constraint;
632
633       if Token = Tok_With then
634          Scan; -- past WITH
635          Set_Private_Present (Def_Node, True);
636          T_Private;
637
638       elsif Token = Tok_Tagged then
639          Scan;
640
641          if Token = Tok_Private then
642             Error_Msg_SC ("TAGGED should be WITH");
643             Set_Private_Present (Def_Node, True);
644             T_Private;
645          else
646             Ignore (Tok_Tagged);
647          end if;
648       end if;
649
650       return Def_Node;
651    end P_Formal_Derived_Type_Definition;
652
653    ---------------------------------------------
654    -- 12.5.2  Formal Discrete Type Definition --
655    ---------------------------------------------
656
657    --  FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
658
659    --  The caller has checked the initial token is left paren
660
661    --  Error recovery: cannot raise Error_Resync
662
663    function P_Formal_Discrete_Type_Definition return Node_Id is
664       Def_Node : Node_Id;
665
666    begin
667       Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
668       Scan; -- past left paren
669       T_Box;
670       T_Right_Paren;
671       return Def_Node;
672    end P_Formal_Discrete_Type_Definition;
673
674    ---------------------------------------------------
675    -- 12.5.2  Formal Signed Integer Type Definition --
676    ---------------------------------------------------
677
678    --  FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
679
680    --  The caller has checked the initial token is RANGE
681
682    --  Error recovery: cannot raise Error_Resync
683
684    function P_Formal_Signed_Integer_Type_Definition return Node_Id is
685       Def_Node : Node_Id;
686
687    begin
688       Def_Node :=
689         New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
690       Scan; -- past RANGE
691       T_Box;
692       return Def_Node;
693    end P_Formal_Signed_Integer_Type_Definition;
694
695    --------------------------------------------
696    -- 12.5.2  Formal Modular Type Definition --
697    --------------------------------------------
698
699    --  FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
700
701    --  The caller has checked the initial token is MOD
702
703    --  Error recovery: cannot raise Error_Resync
704
705    function P_Formal_Modular_Type_Definition return Node_Id is
706       Def_Node : Node_Id;
707
708    begin
709       Def_Node :=
710         New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
711       Scan; -- past MOD
712       T_Box;
713       return Def_Node;
714    end P_Formal_Modular_Type_Definition;
715
716    ----------------------------------------------
717    -- 12.5.2  Formal Floating Point Definition --
718    ----------------------------------------------
719
720    --  FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
721
722    --  The caller has checked the initial token is DIGITS
723
724    --  Error recovery: cannot raise Error_Resync
725
726    function P_Formal_Floating_Point_Definition return Node_Id is
727       Def_Node : Node_Id;
728
729    begin
730       Def_Node :=
731         New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
732       Scan; -- past DIGITS
733       T_Box;
734       return Def_Node;
735    end P_Formal_Floating_Point_Definition;
736
737    -------------------------------------------
738    -- 12.5.2  Formal Fixed Point Definition --
739    -------------------------------------------
740
741    --  This routine parses either a formal ordinary fixed point definition
742    --  or a formal decimal fixed point definition:
743
744    --  FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
745
746    --  FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
747
748    --  The caller has checked the initial token is DELTA
749
750    --  Error recovery: cannot raise Error_Resync
751
752    function P_Formal_Fixed_Point_Definition return Node_Id is
753       Def_Node   : Node_Id;
754       Delta_Sloc : Source_Ptr;
755
756    begin
757       Delta_Sloc := Token_Ptr;
758       Scan; -- past DELTA
759       T_Box;
760
761       if Token = Tok_Digits then
762          Def_Node :=
763            New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
764          Scan; -- past DIGITS
765          T_Box;
766       else
767          Def_Node :=
768            New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
769       end if;
770
771       return Def_Node;
772    end P_Formal_Fixed_Point_Definition;
773
774    ----------------------------------------------------
775    -- 12.5.2  Formal Ordinary Fixed Point Definition --
776    ----------------------------------------------------
777
778    --  Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
779
780    ---------------------------------------------------
781    -- 12.5.2  Formal Decimal Fixed Point Definition --
782    ---------------------------------------------------
783
784    --  Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
785
786    ------------------------------------------
787    -- 12.5.3  Formal Array Type Definition --
788    ------------------------------------------
789
790    --  Parsed by P_Formal_Type_Definition (12.5)
791
792    -------------------------------------------
793    -- 12.5.4  Formal Access Type Definition --
794    -------------------------------------------
795
796    --  Parsed by P_Formal_Type_Definition (12.5)
797
798    -----------------------------------------
799    -- 12.6  Formal Subprogram Declaration --
800    -----------------------------------------
801
802    --  FORMAL_SUBPROGRAM_DECLARATION ::=
803    --    with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
804
805    --  SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
806
807    --  DEFAULT_NAME ::= NAME
808
809    --  The caller has checked that the initial tokens are WITH FUNCTION or
810    --  WITH PROCEDURE, and the initial WITH has been scanned out.
811
812    --  Note: we separate this into two procedures because the name is allowed
813    --  to be an operator symbol for a function, but not for a procedure.
814
815    --  Error recovery: cannot raise Error_Resync
816
817    function P_Formal_Subprogram_Declaration return Node_Id is
818       Def_Node : Node_Id;
819
820    begin
821       Def_Node := New_Node (N_Formal_Subprogram_Declaration, Prev_Token_Ptr);
822       Set_Specification (Def_Node, P_Subprogram_Specification);
823
824       if Token = Tok_Is then
825          T_Is; -- past IS, skip extra IS or ";"
826
827          if Token = Tok_Box then
828             Set_Box_Present (Def_Node, True);
829             Scan; -- past <>
830
831          else
832             Set_Default_Name (Def_Node, P_Name);
833          end if;
834
835       end if;
836
837       T_Semicolon;
838       return Def_Node;
839    end P_Formal_Subprogram_Declaration;
840
841    ------------------------------
842    -- 12.6  Subprogram Default --
843    ------------------------------
844
845    --  Parsed by P_Formal_Procedure_Declaration (12.6)
846
847    ------------------------
848    -- 12.6  Default Name --
849    ------------------------
850
851    --  Parsed by P_Formal_Procedure_Declaration (12.6)
852
853    --------------------------------------
854    -- 12.7  Formal Package Declaration --
855    --------------------------------------
856
857    --  FORMAL_PACKAGE_DECLARATION ::=
858    --    with package DEFINING_IDENTIFIER
859    --      is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
860
861    --  FORMAL_PACKAGE_ACTUAL_PART ::=
862    --    (<>) | [GENERIC_ACTUAL_PART]
863
864    --  The caller has checked that the initial tokens are WITH PACKAGE,
865    --  and the initial WITH has been scanned out (so Token = Tok_Package).
866
867    --  Error recovery: cannot raise Error_Resync
868
869    function P_Formal_Package_Declaration return Node_Id is
870       Def_Node : Node_Id;
871       Scan_State : Saved_Scan_State;
872
873    begin
874       Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
875       Scan; -- past PACKAGE
876       Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
877       T_Is;
878       T_New;
879       Set_Name (Def_Node, P_Qualified_Simple_Name);
880
881       if Token = Tok_Left_Paren then
882          Save_Scan_State (Scan_State); -- at the left paren
883          Scan; -- past the left paren
884
885          if Token = Tok_Box then
886             Set_Box_Present (Def_Node, True);
887             Scan; -- past box
888             T_Right_Paren;
889
890          else
891             Restore_Scan_State (Scan_State); -- to the left paren
892             Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
893          end if;
894       end if;
895
896       T_Semicolon;
897       return Def_Node;
898    end P_Formal_Package_Declaration;
899
900    --------------------------------------
901    -- 12.7  Formal Package Actual Part --
902    --------------------------------------
903
904    --  Parsed by P_Formal_Package_Declaration (12.7)
905
906 end Ch12;