OSDN Git Service

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