Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / ada / par-ch12.adb
blob7dcc6ba08e12d2d54c964179cd3640db25591c8b
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-2005 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 ------------------------------------------------------------------------------
27 pragma Style_Checks (All_Checks);
28 -- Turn off subprogram body ordering check. Subprograms are in order
29 -- by RM section rather than alphabetical
31 separate (Par)
32 package body Ch12 is
34 -- Local functions, used only in this chapter
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;
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.
54 --------------------------------
55 -- 12.1 Generic (also 8.5.5) --
56 --------------------------------
58 -- This routine parses either one of the forms of a generic declaration
59 -- or a generic renaming declaration.
61 -- GENERIC_DECLARATION ::=
62 -- GENERIC_SUBPROGRAM_DECLARATION | GENERIC_PACKAGE_DECLARATION
64 -- GENERIC_SUBPROGRAM_DECLARATION ::=
65 -- GENERIC_FORMAL_PART SUBPROGRAM_SPECIFICATION;
67 -- GENERIC_PACKAGE_DECLARATION ::=
68 -- GENERIC_FORMAL_PART PACKAGE_SPECIFICATION;
70 -- GENERIC_FORMAL_PART ::=
71 -- generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
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
81 -- GENERIC_FORMAL_PARAMETER_DECLARATION ::=
82 -- FORMAL_OBJECT_DECLARATION
83 -- | FORMAL_TYPE_DECLARATION
84 -- | FORMAL_SUBPROGRAM_DECLARATION
85 -- | FORMAL_PACKAGE_DECLARATION
87 -- The caller has checked that the initial token is GENERIC
89 -- Error recovery: can raise Error_Resync
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;
100 begin
101 Scan; -- past GENERIC
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;
108 Save_Scan_State (Scan_State); -- at token past GENERIC
110 -- Check for generic renaming declaration case
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
119 if Token = Tok_Identifier then
120 Def_Unit := P_Defining_Program_Unit_Name;
122 Check_Misspelling_Of (Tok_Renames);
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);
129 elsif Ren_Token = Tok_Procedure then
130 Decl_Node := New_Node
131 (N_Generic_Procedure_Renaming_Declaration, Gen_Sloc);
133 else -- Ren_Token = Tok_Function then
134 Decl_Node := New_Node
135 (N_Generic_Function_Renaming_Declaration, Gen_Sloc);
136 end if;
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;
147 -- Fall through if this is *not* a generic renaming declaration
149 Restore_Scan_State (Scan_State);
150 Decls := New_List;
152 -- Loop through generic parameter declarations and use clauses
154 Decl_Loop : loop
155 P_Pragmas_Opt (Decls);
156 Ignore (Tok_Private);
158 if Token = Tok_Use then
159 Append (P_Use_Clause, Decls);
160 else
161 -- Parse a generic parameter declaration
163 if Token = Tok_Identifier then
164 P_Formal_Object_Declarations (Decls);
166 elsif Token = Tok_Type then
167 Append (P_Formal_Type_Declaration, Decls);
169 elsif Token = Tok_With then
170 Scan; -- past WITH
172 if Token = Tok_Package then
173 Append (P_Formal_Package_Declaration, Decls);
175 elsif Token = Tok_Procedure or Token = Tok_Function then
176 Append (P_Formal_Subprogram_Declaration, Decls);
178 else
179 Error_Msg_BC
180 ("FUNCTION, PROCEDURE or PACKAGE expected here");
181 Resync_Past_Semicolon;
182 end if;
184 elsif Token = Tok_Subtype then
185 Error_Msg_SC ("subtype declaration not allowed " &
186 "as generic parameter declaration!");
187 Resync_Past_Semicolon;
189 else
190 exit Decl_Loop;
191 end if;
192 end if;
194 end loop Decl_Loop;
196 -- Generic formal part is scanned, scan out subprogram or package spec
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);
204 Set_Specification (Gen_Decl, P_Subprogram_Specification);
206 if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
207 N_Defining_Program_Unit_Name
208 and then Scope.Last > 0
209 then
210 Error_Msg_SP ("child unit allowed only at library level");
211 end if;
212 TF_Semicolon;
213 end if;
215 Set_Generic_Formal_Declarations (Gen_Decl, Decls);
216 return Gen_Decl;
217 end P_Generic;
219 -------------------------------
220 -- 12.1 Generic Declaration --
221 -------------------------------
223 -- Parsed by P_Generic (12.1)
225 ------------------------------------------
226 -- 12.1 Generic Subprogram Declaration --
227 ------------------------------------------
229 -- Parsed by P_Generic (12.1)
231 ---------------------------------------
232 -- 12.1 Generic Package Declaration --
233 ---------------------------------------
235 -- Parsed by P_Generic (12.1)
237 -------------------------------
238 -- 12.1 Generic Formal Part --
239 -------------------------------
241 -- Parsed by P_Generic (12.1)
243 -------------------------------------------------
244 -- 12.1 Generic Formal Parameter Declaration --
245 -------------------------------------------------
247 -- Parsed by P_Generic (12.1)
249 ---------------------------------
250 -- 12.3 Generic Instantiation --
251 ---------------------------------
253 -- Generic package instantiation parsed by P_Package (7.1)
254 -- Generic procedure instantiation parsed by P_Subprogram (6.1)
255 -- Generic function instantiation parsed by P_Subprogram (6.1)
257 -------------------------------
258 -- 12.3 Generic Actual Part --
259 -------------------------------
261 -- GENERIC_ACTUAL_PART ::=
262 -- (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
264 -- Returns a list of generic associations, or Empty if none are present
266 -- Error recovery: cannot raise Error_Resync
268 function P_Generic_Actual_Part_Opt return List_Id is
269 Association_List : List_Id;
271 begin
272 -- Figure out if a generic actual part operation is present. Clearly
273 -- there is no generic actual part if the current token is semicolon
275 if Token = Tok_Semicolon then
276 return No_List;
278 -- If we don't have a left paren, then we have an error, and the job
279 -- is to figure out whether a left paren or semicolon was intended.
280 -- We assume a missing left paren (and hence a generic actual part
281 -- present) if the current token is not on a new line, or if it is
282 -- indented from the subprogram token. Otherwise assume missing
283 -- semicolon (which will be diagnosed by caller) and no generic part
285 elsif Token /= Tok_Left_Paren
286 and then Token_Is_At_Start_Of_Line
287 and then Start_Column <= Scope.Table (Scope.Last).Ecol
288 then
289 return No_List;
291 -- Otherwise we have a generic actual part (either a left paren is
292 -- present, or we have decided that there must be a missing left paren)
294 else
295 Association_List := New_List;
296 T_Left_Paren;
298 loop
299 Append (P_Generic_Association, Association_List);
300 exit when not Comma_Present;
301 end loop;
303 T_Right_Paren;
304 return Association_List;
305 end if;
307 end P_Generic_Actual_Part_Opt;
309 -------------------------------
310 -- 12.3 Generic Association --
311 -------------------------------
313 -- GENERIC_ASSOCIATION ::=
314 -- [generic_formal_parameter_SELECTOR_NAME =>]
315 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER
317 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
318 -- EXPRESSION | variable_NAME | subprogram_NAME
319 -- | entry_NAME | SUBTYPE_MARK | package_instance_NAME
321 -- Error recovery: cannot raise Error_Resync
323 function P_Generic_Association return Node_Id is
324 Scan_State : Saved_Scan_State;
325 Param_Name_Node : Node_Id;
326 Generic_Assoc_Node : Node_Id;
328 begin
329 Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
331 if Token in Token_Class_Desig then
332 Param_Name_Node := Token_Node;
333 Save_Scan_State (Scan_State); -- at designator
334 Scan; -- past simple name or operator symbol
336 if Token = Tok_Arrow then
337 Scan; -- past arrow
338 Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
339 else
340 Restore_Scan_State (Scan_State); -- to designator
341 end if;
342 end if;
344 Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, P_Expression);
345 return Generic_Assoc_Node;
346 end P_Generic_Association;
348 ---------------------------------------------
349 -- 12.3 Explicit Generic Actual Parameter --
350 ---------------------------------------------
352 -- Parsed by P_Generic_Association (12.3)
354 --------------------------------------
355 -- 12.4 Formal Object Declarations --
356 --------------------------------------
358 -- FORMAL_OBJECT_DECLARATION ::=
359 -- DEFINING_IDENTIFIER_LIST :
360 -- MODE SUBTYPE_MARK [:= DEFAULT_EXPRESSION];
362 -- The caller has checked that the initial token is an identifier
364 -- Error recovery: cannot raise Error_Resync
366 procedure P_Formal_Object_Declarations (Decls : List_Id) is
367 Decl_Node : Node_Id;
368 Scan_State : Saved_Scan_State;
369 Num_Idents : Nat;
370 Ident : Nat;
372 Idents : array (Int range 1 .. 4096) of Entity_Id;
373 -- This array holds the list of defining identifiers. The upper bound
374 -- of 4096 is intended to be essentially infinite, and we do not even
375 -- bother to check for it being exceeded.
377 begin
378 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
379 Num_Idents := 1;
381 while Comma_Present loop
382 Num_Idents := Num_Idents + 1;
383 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
384 end loop;
386 T_Colon;
388 -- If there are multiple identifiers, we repeatedly scan the
389 -- type and initialization expression information by resetting
390 -- the scan pointer (so that we get completely separate trees
391 -- for each occurrence).
393 if Num_Idents > 1 then
394 Save_Scan_State (Scan_State);
395 end if;
397 -- Loop through defining identifiers in list
399 Ident := 1;
400 Ident_Loop : loop
401 Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
402 Set_Defining_Identifier (Decl_Node, Idents (Ident));
403 P_Mode (Decl_Node);
404 Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
405 No_Constraint;
406 Set_Expression (Decl_Node, Init_Expr_Opt);
408 if Ident > 1 then
409 Set_Prev_Ids (Decl_Node, True);
410 end if;
412 if Ident < Num_Idents then
413 Set_More_Ids (Decl_Node, True);
414 end if;
416 Append (Decl_Node, Decls);
418 exit Ident_Loop when Ident = Num_Idents;
419 Ident := Ident + 1;
420 Restore_Scan_State (Scan_State);
421 end loop Ident_Loop;
423 TF_Semicolon;
424 end P_Formal_Object_Declarations;
426 -----------------------------------
427 -- 12.5 Formal Type Declaration --
428 -----------------------------------
430 -- FORMAL_TYPE_DECLARATION ::=
431 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
432 -- is FORMAL_TYPE_DEFINITION;
434 -- The caller has checked that the initial token is TYPE
436 -- Error recovery: cannot raise Error_Resync
438 function P_Formal_Type_Declaration return Node_Id is
439 Decl_Node : Node_Id;
440 Def_Node : Node_Id;
442 begin
443 Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
444 Scan; -- past TYPE
445 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
447 if P_Unknown_Discriminant_Part_Opt then
448 Set_Unknown_Discriminants_Present (Decl_Node, True);
449 else
450 Set_Discriminant_Specifications
451 (Decl_Node, P_Known_Discriminant_Part_Opt);
452 end if;
454 T_Is;
456 Def_Node := P_Formal_Type_Definition;
458 if Def_Node /= Error then
459 Set_Formal_Type_Definition (Decl_Node, Def_Node);
460 TF_Semicolon;
462 else
463 Decl_Node := Error;
465 -- If we have semicolon, skip it to avoid cascaded errors
467 if Token = Tok_Semicolon then
468 Scan;
469 end if;
470 end if;
472 return Decl_Node;
473 end P_Formal_Type_Declaration;
475 ----------------------------------
476 -- 12.5 Formal Type Definition --
477 ----------------------------------
479 -- FORMAL_TYPE_DEFINITION ::=
480 -- FORMAL_PRIVATE_TYPE_DEFINITION
481 -- | FORMAL_DERIVED_TYPE_DEFINITION
482 -- | FORMAL_DISCRETE_TYPE_DEFINITION
483 -- | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
484 -- | FORMAL_MODULAR_TYPE_DEFINITION
485 -- | FORMAL_FLOATING_POINT_DEFINITION
486 -- | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
487 -- | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
488 -- | FORMAL_ARRAY_TYPE_DEFINITION
489 -- | FORMAL_ACCESS_TYPE_DEFINITION
491 -- FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
493 -- FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
495 function P_Formal_Type_Definition return Node_Id is
496 Scan_State : Saved_Scan_State;
498 begin
499 if Token_Name = Name_Abstract then
500 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
501 end if;
503 if Token_Name = Name_Tagged then
504 Check_95_Keyword (Tok_Tagged, Tok_Private);
505 Check_95_Keyword (Tok_Tagged, Tok_Limited);
506 end if;
508 case Token is
510 -- Mostly we can tell what we have from the initial token. The one
511 -- exception is ABSTRACT, where we have to scan ahead to see if we
512 -- have a formal derived type or a formal private type definition.
514 when Tok_Abstract =>
515 Save_Scan_State (Scan_State);
516 Scan; -- past ABSTRACT
518 if Token = Tok_New then
519 Restore_Scan_State (Scan_State); -- to ABSTRACT
520 return P_Formal_Derived_Type_Definition;
522 else
523 Restore_Scan_State (Scan_State); -- to ABSTRACT
524 return P_Formal_Private_Type_Definition;
525 end if;
527 when Tok_Private | Tok_Limited | Tok_Tagged =>
528 return P_Formal_Private_Type_Definition;
530 when Tok_New =>
531 return P_Formal_Derived_Type_Definition;
533 when Tok_Left_Paren =>
534 return P_Formal_Discrete_Type_Definition;
536 when Tok_Range =>
537 return P_Formal_Signed_Integer_Type_Definition;
539 when Tok_Mod =>
540 return P_Formal_Modular_Type_Definition;
542 when Tok_Digits =>
543 return P_Formal_Floating_Point_Definition;
545 when Tok_Delta =>
546 return P_Formal_Fixed_Point_Definition;
548 when Tok_Array =>
549 return P_Array_Type_Definition;
551 when Tok_Access =>
552 return P_Access_Type_Definition;
554 when Tok_Record =>
555 Error_Msg_SC ("record not allowed in generic type definition!");
556 Discard_Junk_Node (P_Record_Definition);
557 return Error;
559 when others =>
560 Error_Msg_BC ("expecting generic type definition here");
561 Resync_Past_Semicolon;
562 return Error;
564 end case;
565 end P_Formal_Type_Definition;
567 --------------------------------------------
568 -- 12.5.1 Formal Private Type Definition --
569 --------------------------------------------
571 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
572 -- [[abstract] tagged] [limited] private
574 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
575 -- TAGGED or LIMITED
577 -- Error recovery: cannot raise Error_Resync
579 function P_Formal_Private_Type_Definition return Node_Id is
580 Def_Node : Node_Id;
582 begin
583 Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
585 if Token = Tok_Abstract then
586 Scan; -- past ABSTRACT
588 if Token_Name = Name_Tagged then
589 Check_95_Keyword (Tok_Tagged, Tok_Private);
590 Check_95_Keyword (Tok_Tagged, Tok_Limited);
591 end if;
593 if Token /= Tok_Tagged then
594 Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
595 else
596 Set_Abstract_Present (Def_Node, True);
597 end if;
598 end if;
600 if Token = Tok_Tagged then
601 Set_Tagged_Present (Def_Node, True);
602 Scan; -- past TAGGED
603 end if;
605 if Token = Tok_Limited then
606 Set_Limited_Present (Def_Node, True);
607 Scan; -- past LIMITED
608 end if;
610 Set_Sloc (Def_Node, Token_Ptr);
611 T_Private;
612 return Def_Node;
613 end P_Formal_Private_Type_Definition;
615 --------------------------------------------
616 -- 12.5.1 Formal Derived Type Definition --
617 --------------------------------------------
619 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
620 -- [abstract] new SUBTYPE_MARK [with private]
622 -- The caller has checked the initial token(s) is/are NEW or ASTRACT NEW
624 -- Error recovery: cannot raise Error_Resync
626 function P_Formal_Derived_Type_Definition return Node_Id is
627 Def_Node : Node_Id;
629 begin
630 Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
632 if Token = Tok_Abstract then
633 Set_Abstract_Present (Def_Node);
634 Scan; -- past ABSTRACT
635 end if;
637 Scan; -- past NEW;
638 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
639 No_Constraint;
641 if Token = Tok_With then
642 Scan; -- past WITH
643 Set_Private_Present (Def_Node, True);
644 T_Private;
646 elsif Token = Tok_Tagged then
647 Scan;
649 if Token = Tok_Private then
650 Error_Msg_SC ("TAGGED should be WITH");
651 Set_Private_Present (Def_Node, True);
652 T_Private;
653 else
654 Ignore (Tok_Tagged);
655 end if;
656 end if;
658 return Def_Node;
659 end P_Formal_Derived_Type_Definition;
661 ---------------------------------------------
662 -- 12.5.2 Formal Discrete Type Definition --
663 ---------------------------------------------
665 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
667 -- The caller has checked the initial token is left paren
669 -- Error recovery: cannot raise Error_Resync
671 function P_Formal_Discrete_Type_Definition return Node_Id is
672 Def_Node : Node_Id;
674 begin
675 Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
676 Scan; -- past left paren
677 T_Box;
678 T_Right_Paren;
679 return Def_Node;
680 end P_Formal_Discrete_Type_Definition;
682 ---------------------------------------------------
683 -- 12.5.2 Formal Signed Integer Type Definition --
684 ---------------------------------------------------
686 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
688 -- The caller has checked the initial token is RANGE
690 -- Error recovery: cannot raise Error_Resync
692 function P_Formal_Signed_Integer_Type_Definition return Node_Id is
693 Def_Node : Node_Id;
695 begin
696 Def_Node :=
697 New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
698 Scan; -- past RANGE
699 T_Box;
700 return Def_Node;
701 end P_Formal_Signed_Integer_Type_Definition;
703 --------------------------------------------
704 -- 12.5.2 Formal Modular Type Definition --
705 --------------------------------------------
707 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
709 -- The caller has checked the initial token is MOD
711 -- Error recovery: cannot raise Error_Resync
713 function P_Formal_Modular_Type_Definition return Node_Id is
714 Def_Node : Node_Id;
716 begin
717 Def_Node :=
718 New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
719 Scan; -- past MOD
720 T_Box;
721 return Def_Node;
722 end P_Formal_Modular_Type_Definition;
724 ----------------------------------------------
725 -- 12.5.2 Formal Floating Point Definition --
726 ----------------------------------------------
728 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
730 -- The caller has checked the initial token is DIGITS
732 -- Error recovery: cannot raise Error_Resync
734 function P_Formal_Floating_Point_Definition return Node_Id is
735 Def_Node : Node_Id;
737 begin
738 Def_Node :=
739 New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
740 Scan; -- past DIGITS
741 T_Box;
742 return Def_Node;
743 end P_Formal_Floating_Point_Definition;
745 -------------------------------------------
746 -- 12.5.2 Formal Fixed Point Definition --
747 -------------------------------------------
749 -- This routine parses either a formal ordinary fixed point definition
750 -- or a formal decimal fixed point definition:
752 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
754 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
756 -- The caller has checked the initial token is DELTA
758 -- Error recovery: cannot raise Error_Resync
760 function P_Formal_Fixed_Point_Definition return Node_Id is
761 Def_Node : Node_Id;
762 Delta_Sloc : Source_Ptr;
764 begin
765 Delta_Sloc := Token_Ptr;
766 Scan; -- past DELTA
767 T_Box;
769 if Token = Tok_Digits then
770 Def_Node :=
771 New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
772 Scan; -- past DIGITS
773 T_Box;
774 else
775 Def_Node :=
776 New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
777 end if;
779 return Def_Node;
780 end P_Formal_Fixed_Point_Definition;
782 ----------------------------------------------------
783 -- 12.5.2 Formal Ordinary Fixed Point Definition --
784 ----------------------------------------------------
786 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
788 ---------------------------------------------------
789 -- 12.5.2 Formal Decimal Fixed Point Definition --
790 ---------------------------------------------------
792 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
794 ------------------------------------------
795 -- 12.5.3 Formal Array Type Definition --
796 ------------------------------------------
798 -- Parsed by P_Formal_Type_Definition (12.5)
800 -------------------------------------------
801 -- 12.5.4 Formal Access Type Definition --
802 -------------------------------------------
804 -- Parsed by P_Formal_Type_Definition (12.5)
806 -----------------------------------------
807 -- 12.6 Formal Subprogram Declaration --
808 -----------------------------------------
810 -- FORMAL_SUBPROGRAM_DECLARATION ::=
811 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
812 -- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
814 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
815 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
817 -- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
818 -- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT];
820 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
822 -- DEFAULT_NAME ::= NAME
824 -- The caller has checked that the initial tokens are WITH FUNCTION or
825 -- WITH PROCEDURE, and the initial WITH has been scanned out.
827 -- Error recovery: cannot raise Error_Resync
829 function P_Formal_Subprogram_Declaration return Node_Id is
830 Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
831 Spec_Node : constant Node_Id := P_Subprogram_Specification;
832 Def_Node : Node_Id;
834 begin
835 if Token = Tok_Is then
836 T_Is; -- past IS, skip extra IS or ";"
838 if Token = Tok_Abstract then
839 Def_Node :=
840 New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
841 Scan; -- past ABSTRACT
843 if Ada_Version < Ada_05 then
844 Error_Msg_SP
845 ("formal abstract subprograms are an Ada 2005 extension");
846 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
847 end if;
849 else
850 Def_Node :=
851 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
852 end if;
854 Set_Specification (Def_Node, Spec_Node);
856 if Token = Tok_Semicolon then
857 Scan; -- past ";"
859 elsif Token = Tok_Box then
860 Set_Box_Present (Def_Node, True);
861 Scan; -- past <>
862 T_Semicolon;
864 else
865 Set_Default_Name (Def_Node, P_Name);
866 T_Semicolon;
867 end if;
869 else
870 Def_Node :=
871 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
872 Set_Specification (Def_Node, Spec_Node);
873 T_Semicolon;
874 end if;
876 return Def_Node;
877 end P_Formal_Subprogram_Declaration;
879 ------------------------------
880 -- 12.6 Subprogram Default --
881 ------------------------------
883 -- Parsed by P_Formal_Procedure_Declaration (12.6)
885 ------------------------
886 -- 12.6 Default Name --
887 ------------------------
889 -- Parsed by P_Formal_Procedure_Declaration (12.6)
891 --------------------------------------
892 -- 12.7 Formal Package Declaration --
893 --------------------------------------
895 -- FORMAL_PACKAGE_DECLARATION ::=
896 -- with package DEFINING_IDENTIFIER
897 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
899 -- FORMAL_PACKAGE_ACTUAL_PART ::=
900 -- (<>) | [GENERIC_ACTUAL_PART]
902 -- The caller has checked that the initial tokens are WITH PACKAGE,
903 -- and the initial WITH has been scanned out (so Token = Tok_Package).
905 -- Error recovery: cannot raise Error_Resync
907 function P_Formal_Package_Declaration return Node_Id is
908 Def_Node : Node_Id;
909 Scan_State : Saved_Scan_State;
911 begin
912 Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
913 Scan; -- past PACKAGE
914 Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
915 T_Is;
916 T_New;
917 Set_Name (Def_Node, P_Qualified_Simple_Name);
919 if Token = Tok_Left_Paren then
920 Save_Scan_State (Scan_State); -- at the left paren
921 Scan; -- past the left paren
923 if Token = Tok_Box then
924 Set_Box_Present (Def_Node, True);
925 Scan; -- past box
926 T_Right_Paren;
928 else
929 Restore_Scan_State (Scan_State); -- to the left paren
930 Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
931 end if;
932 end if;
934 T_Semicolon;
935 return Def_Node;
936 end P_Formal_Package_Declaration;
938 --------------------------------------
939 -- 12.7 Formal Package Actual Part --
940 --------------------------------------
942 -- Parsed by P_Formal_Package_Declaration (12.7)
944 end Ch12;