OSDN Git Service

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