Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / ada / par-ch12.adb
blob642c05a331baccb6bcaa6ea74ece671e5a636802
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-2010, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 pragma Style_Checks (All_Checks);
27 -- Turn off subprogram body ordering check. Subprograms are in order
28 -- by RM section rather than alphabetical
30 separate (Par)
31 package body Ch12 is
33 -- Local functions, used only in this chapter
35 function P_Formal_Derived_Type_Definition return Node_Id;
36 function P_Formal_Discrete_Type_Definition return Node_Id;
37 function P_Formal_Fixed_Point_Definition return Node_Id;
38 function P_Formal_Floating_Point_Definition return Node_Id;
39 function P_Formal_Modular_Type_Definition return Node_Id;
40 function P_Formal_Package_Declaration return Node_Id;
41 function P_Formal_Private_Type_Definition return Node_Id;
42 function P_Formal_Signed_Integer_Type_Definition return Node_Id;
43 function P_Formal_Subprogram_Declaration return Node_Id;
44 function P_Formal_Type_Declaration return Node_Id;
45 function P_Formal_Type_Definition return Node_Id;
46 function P_Generic_Association return Node_Id;
48 procedure P_Formal_Object_Declarations (Decls : List_Id);
49 -- Scans one or more formal object declarations and appends them to
50 -- Decls. Scans more than one declaration only in the case where the
51 -- source has a declaration with multiple defining identifiers.
53 --------------------------------
54 -- 12.1 Generic (also 8.5.5) --
55 --------------------------------
57 -- This routine parses either one of the forms of a generic declaration
58 -- or a generic renaming declaration.
60 -- GENERIC_DECLARATION ::=
61 -- GENERIC_SUBPROGRAM_DECLARATION | GENERIC_PACKAGE_DECLARATION
63 -- GENERIC_SUBPROGRAM_DECLARATION ::=
64 -- GENERIC_FORMAL_PART SUBPROGRAM_SPECIFICATION;
66 -- GENERIC_PACKAGE_DECLARATION ::=
67 -- GENERIC_FORMAL_PART PACKAGE_SPECIFICATION;
69 -- GENERIC_FORMAL_PART ::=
70 -- generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
72 -- GENERIC_RENAMING_DECLARATION ::=
73 -- generic package DEFINING_PROGRAM_UNIT_NAME
74 -- renames generic_package_NAME
75 -- | generic procedure DEFINING_PROGRAM_UNIT_NAME
76 -- renames generic_procedure_NAME
77 -- | generic function DEFINING_PROGRAM_UNIT_NAME
78 -- renames generic_function_NAME
80 -- GENERIC_FORMAL_PARAMETER_DECLARATION ::=
81 -- FORMAL_OBJECT_DECLARATION
82 -- | FORMAL_TYPE_DECLARATION
83 -- | FORMAL_SUBPROGRAM_DECLARATION
84 -- | FORMAL_PACKAGE_DECLARATION
86 -- The caller has checked that the initial token is GENERIC
88 -- Error recovery: can raise Error_Resync
90 function P_Generic return Node_Id is
91 Gen_Sloc : constant Source_Ptr := Token_Ptr;
92 Gen_Decl : Node_Id;
93 Decl_Node : Node_Id;
94 Decls : List_Id;
95 Def_Unit : Node_Id;
96 Ren_Token : Token_Type;
97 Scan_State : Saved_Scan_State;
99 begin
100 Scan; -- past GENERIC
102 if Token = Tok_Private then
103 Error_Msg_SC -- CODEFIX
104 ("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);
157 if Token = Tok_Private then
158 Error_Msg_S ("generic private child packages not permitted");
159 Scan; -- past PRIVATE
160 end if;
162 if Token = Tok_Use then
163 Append (P_Use_Clause, Decls);
164 else
165 -- Parse a generic parameter declaration
167 if Token = Tok_Identifier then
168 P_Formal_Object_Declarations (Decls);
170 elsif Token = Tok_Type then
171 Append (P_Formal_Type_Declaration, Decls);
173 elsif Token = Tok_With then
174 Scan; -- past WITH
176 if Token = Tok_Package then
177 Append (P_Formal_Package_Declaration, Decls);
179 elsif Token = Tok_Procedure or Token = Tok_Function then
180 Append (P_Formal_Subprogram_Declaration, Decls);
182 else
183 Error_Msg_BC -- CODEFIX
184 ("FUNCTION, PROCEDURE or PACKAGE expected here");
185 Resync_Past_Semicolon;
186 end if;
188 elsif Token = Tok_Subtype then
189 Error_Msg_SC ("subtype declaration not allowed " &
190 "as generic parameter declaration!");
191 Resync_Past_Semicolon;
193 else
194 exit Decl_Loop;
195 end if;
196 end if;
198 end loop Decl_Loop;
200 -- Generic formal part is scanned, scan out subprogram or package spec
202 if Token = Tok_Package then
203 Gen_Decl := New_Node (N_Generic_Package_Declaration, Gen_Sloc);
204 Set_Specification (Gen_Decl, P_Package (Pf_Spcn));
205 else
206 Gen_Decl := New_Node (N_Generic_Subprogram_Declaration, Gen_Sloc);
208 Set_Specification (Gen_Decl, P_Subprogram_Specification);
210 if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
211 N_Defining_Program_Unit_Name
212 and then Scope.Last > 0
213 then
214 Error_Msg_SP ("child unit allowed only at library level");
215 end if;
216 TF_Semicolon;
217 end if;
219 Set_Generic_Formal_Declarations (Gen_Decl, Decls);
220 return Gen_Decl;
221 end P_Generic;
223 -------------------------------
224 -- 12.1 Generic Declaration --
225 -------------------------------
227 -- Parsed by P_Generic (12.1)
229 ------------------------------------------
230 -- 12.1 Generic Subprogram Declaration --
231 ------------------------------------------
233 -- Parsed by P_Generic (12.1)
235 ---------------------------------------
236 -- 12.1 Generic Package Declaration --
237 ---------------------------------------
239 -- Parsed by P_Generic (12.1)
241 -------------------------------
242 -- 12.1 Generic Formal Part --
243 -------------------------------
245 -- Parsed by P_Generic (12.1)
247 -------------------------------------------------
248 -- 12.1 Generic Formal Parameter Declaration --
249 -------------------------------------------------
251 -- Parsed by P_Generic (12.1)
253 ---------------------------------
254 -- 12.3 Generic Instantiation --
255 ---------------------------------
257 -- Generic package instantiation parsed by P_Package (7.1)
258 -- Generic procedure instantiation parsed by P_Subprogram (6.1)
259 -- Generic function instantiation parsed by P_Subprogram (6.1)
261 -------------------------------
262 -- 12.3 Generic Actual Part --
263 -------------------------------
265 -- GENERIC_ACTUAL_PART ::=
266 -- (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
268 -- Returns a list of generic associations, or Empty if none are present
270 -- Error recovery: cannot raise Error_Resync
272 function P_Generic_Actual_Part_Opt return List_Id is
273 Association_List : List_Id;
275 begin
276 -- Figure out if a generic actual part operation is present. Clearly
277 -- there is no generic actual part if the current token is semicolon
279 if Token = Tok_Semicolon then
280 return No_List;
282 -- If we don't have a left paren, then we have an error, and the job
283 -- is to figure out whether a left paren or semicolon was intended.
284 -- We assume a missing left paren (and hence a generic actual part
285 -- present) if the current token is not on a new line, or if it is
286 -- indented from the subprogram token. Otherwise assume missing
287 -- semicolon (which will be diagnosed by caller) and no generic part
289 elsif Token /= Tok_Left_Paren
290 and then Token_Is_At_Start_Of_Line
291 and then Start_Column <= Scope.Table (Scope.Last).Ecol
292 then
293 return No_List;
295 -- Otherwise we have a generic actual part (either a left paren is
296 -- present, or we have decided that there must be a missing left paren)
298 else
299 Association_List := New_List;
300 T_Left_Paren;
302 loop
303 Append (P_Generic_Association, Association_List);
304 exit when not Comma_Present;
305 end loop;
307 T_Right_Paren;
308 return Association_List;
309 end if;
311 end P_Generic_Actual_Part_Opt;
313 -------------------------------
314 -- 12.3 Generic Association --
315 -------------------------------
317 -- GENERIC_ASSOCIATION ::=
318 -- [generic_formal_parameter_SELECTOR_NAME =>]
319 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER
321 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
322 -- EXPRESSION | variable_NAME | subprogram_NAME
323 -- | entry_NAME | SUBTYPE_MARK | package_instance_NAME
325 -- Error recovery: cannot raise Error_Resync
327 function P_Generic_Association return Node_Id is
328 Scan_State : Saved_Scan_State;
329 Param_Name_Node : Node_Id;
330 Generic_Assoc_Node : Node_Id;
332 begin
333 Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
335 -- Ada2005: an association can be given by: others => <>
337 if Token = Tok_Others then
338 if Ada_Version < Ada_05 then
339 Error_Msg_SP
340 ("partial parametrization of formal packages" &
341 " is an Ada 2005 extension");
342 Error_Msg_SP
343 ("\unit must be compiled with -gnat05 switch");
344 end if;
346 Scan; -- past OTHERS
348 if Token /= Tok_Arrow then
349 Error_Msg_BC ("expect arrow after others");
350 else
351 Scan; -- past arrow
352 end if;
354 if Token /= Tok_Box then
355 Error_Msg_BC ("expect Box after arrow");
356 else
357 Scan; -- past box
358 end if;
360 -- Source position of the others choice is beginning of construct
362 return New_Node (N_Others_Choice, Sloc (Generic_Assoc_Node));
363 end if;
365 if Token in Token_Class_Desig then
366 Param_Name_Node := Token_Node;
367 Save_Scan_State (Scan_State); -- at designator
368 Scan; -- past simple name or operator symbol
370 if Token = Tok_Arrow then
371 Scan; -- past arrow
372 Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
373 else
374 Restore_Scan_State (Scan_State); -- to designator
375 end if;
376 end if;
378 -- In Ada 2005 the actual can be a box
380 if Token = Tok_Box then
381 Scan;
382 Set_Box_Present (Generic_Assoc_Node);
383 Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, Empty);
385 else
386 Set_Explicit_Generic_Actual_Parameter
387 (Generic_Assoc_Node, P_Expression);
388 end if;
390 return Generic_Assoc_Node;
391 end P_Generic_Association;
393 ---------------------------------------------
394 -- 12.3 Explicit Generic Actual Parameter --
395 ---------------------------------------------
397 -- Parsed by P_Generic_Association (12.3)
399 --------------------------------------
400 -- 12.4 Formal Object Declarations --
401 --------------------------------------
403 -- FORMAL_OBJECT_DECLARATION ::=
404 -- DEFINING_IDENTIFIER_LIST :
405 -- MODE [NULL_EXCLUSION] SUBTYPE_MARK [:= DEFAULT_EXPRESSION];
406 -- | DEFINING_IDENTIFIER_LIST :
407 -- MODE ACCESS_DEFINITION [:= DEFAULT_EXPRESSION];
409 -- The caller has checked that the initial token is an identifier
411 -- Error recovery: cannot raise Error_Resync
413 procedure P_Formal_Object_Declarations (Decls : List_Id) is
414 Decl_Node : Node_Id;
415 Ident : Nat;
416 Not_Null_Present : Boolean := False;
417 Num_Idents : Nat;
418 Scan_State : Saved_Scan_State;
420 Idents : array (Int range 1 .. 4096) of Entity_Id;
421 -- This array holds the list of defining identifiers. The upper bound
422 -- of 4096 is intended to be essentially infinite, and we do not even
423 -- bother to check for it being exceeded.
425 begin
426 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
427 Num_Idents := 1;
429 while Comma_Present loop
430 Num_Idents := Num_Idents + 1;
431 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
432 end loop;
434 T_Colon;
436 -- If there are multiple identifiers, we repeatedly scan the
437 -- type and initialization expression information by resetting
438 -- the scan pointer (so that we get completely separate trees
439 -- for each occurrence).
441 if Num_Idents > 1 then
442 Save_Scan_State (Scan_State);
443 end if;
445 -- Loop through defining identifiers in list
447 Ident := 1;
448 Ident_Loop : loop
449 Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
450 Set_Defining_Identifier (Decl_Node, Idents (Ident));
451 P_Mode (Decl_Node);
453 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-423)
455 -- Ada 2005 (AI-423): Formal object with an access definition
457 if Token = Tok_Access then
459 -- The access definition is still parsed and set even though
460 -- the compilation may not use the proper switch. This action
461 -- ensures the required local error recovery.
463 Set_Access_Definition (Decl_Node,
464 P_Access_Definition (Not_Null_Present));
466 if Ada_Version < Ada_05 then
467 Error_Msg_SP
468 ("access definition not allowed in formal object " &
469 "declaration");
470 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
471 end if;
473 -- Formal object with a subtype mark
475 else
476 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
477 Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
478 end if;
480 No_Constraint;
481 Set_Default_Expression (Decl_Node, Init_Expr_Opt);
483 if Ident > 1 then
484 Set_Prev_Ids (Decl_Node, True);
485 end if;
487 if Ident < Num_Idents then
488 Set_More_Ids (Decl_Node, True);
489 end if;
491 Append (Decl_Node, Decls);
493 exit Ident_Loop when Ident = Num_Idents;
494 Ident := Ident + 1;
495 Restore_Scan_State (Scan_State);
496 end loop Ident_Loop;
498 TF_Semicolon;
499 end P_Formal_Object_Declarations;
501 -----------------------------------
502 -- 12.5 Formal Type Declaration --
503 -----------------------------------
505 -- FORMAL_TYPE_DECLARATION ::=
506 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
507 -- is FORMAL_TYPE_DEFINITION;
509 -- The caller has checked that the initial token is TYPE
511 -- Error recovery: cannot raise Error_Resync
513 function P_Formal_Type_Declaration return Node_Id is
514 Decl_Node : Node_Id;
515 Def_Node : Node_Id;
517 begin
518 Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
519 Scan; -- past TYPE
520 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
522 if P_Unknown_Discriminant_Part_Opt then
523 Set_Unknown_Discriminants_Present (Decl_Node, True);
524 else
525 Set_Discriminant_Specifications
526 (Decl_Node, P_Known_Discriminant_Part_Opt);
527 end if;
529 T_Is;
531 Def_Node := P_Formal_Type_Definition;
533 if Def_Node /= Error then
534 Set_Formal_Type_Definition (Decl_Node, Def_Node);
535 TF_Semicolon;
537 else
538 Decl_Node := Error;
540 -- If we have semicolon, skip it to avoid cascaded errors
542 if Token = Tok_Semicolon then
543 Scan;
544 end if;
545 end if;
547 return Decl_Node;
548 end P_Formal_Type_Declaration;
550 ----------------------------------
551 -- 12.5 Formal Type Definition --
552 ----------------------------------
554 -- FORMAL_TYPE_DEFINITION ::=
555 -- FORMAL_PRIVATE_TYPE_DEFINITION
556 -- | FORMAL_DERIVED_TYPE_DEFINITION
557 -- | FORMAL_DISCRETE_TYPE_DEFINITION
558 -- | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
559 -- | FORMAL_MODULAR_TYPE_DEFINITION
560 -- | FORMAL_FLOATING_POINT_DEFINITION
561 -- | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
562 -- | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
563 -- | FORMAL_ARRAY_TYPE_DEFINITION
564 -- | FORMAL_ACCESS_TYPE_DEFINITION
565 -- | FORMAL_INTERFACE_TYPE_DEFINITION
567 -- FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
569 -- FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
571 -- FORMAL_INTERFACE_TYPE_DEFINITION ::= INTERFACE_TYPE_DEFINITION
573 function P_Formal_Type_Definition return Node_Id is
574 Scan_State : Saved_Scan_State;
575 Typedef_Node : Node_Id;
577 begin
578 if Token_Name = Name_Abstract then
579 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
580 end if;
582 if Token_Name = Name_Tagged then
583 Check_95_Keyword (Tok_Tagged, Tok_Private);
584 Check_95_Keyword (Tok_Tagged, Tok_Limited);
585 end if;
587 case Token is
589 -- Mostly we can tell what we have from the initial token. The one
590 -- exception is ABSTRACT, where we have to scan ahead to see if we
591 -- have a formal derived type or a formal private type definition.
593 -- In addition, in Ada 2005 LIMITED may appear after abstract, so
594 -- that the lookahead must be extended by one more token.
596 when Tok_Abstract =>
597 Save_Scan_State (Scan_State);
598 Scan; -- past ABSTRACT
600 if Token = Tok_New then
601 Restore_Scan_State (Scan_State); -- to ABSTRACT
602 return P_Formal_Derived_Type_Definition;
604 elsif Token = Tok_Limited then
605 Scan; -- past LIMITED
607 if Token = Tok_New then
608 Restore_Scan_State (Scan_State); -- to ABSTRACT
609 return P_Formal_Derived_Type_Definition;
611 else
612 Restore_Scan_State (Scan_State); -- to ABSTRACT
613 return P_Formal_Private_Type_Definition;
614 end if;
616 -- Ada 2005 (AI-443): Abstract synchronized formal derived type
618 elsif Token = Tok_Synchronized then
619 Restore_Scan_State (Scan_State); -- to ABSTRACT
620 return P_Formal_Derived_Type_Definition;
622 else
623 Restore_Scan_State (Scan_State); -- to ABSTRACT
624 return P_Formal_Private_Type_Definition;
625 end if;
627 when Tok_Access =>
628 return P_Access_Type_Definition;
630 when Tok_Array =>
631 return P_Array_Type_Definition;
633 when Tok_Delta =>
634 return P_Formal_Fixed_Point_Definition;
636 when Tok_Digits =>
637 return P_Formal_Floating_Point_Definition;
639 when Tok_Interface => -- Ada 2005 (AI-251)
640 return P_Interface_Type_Definition (Abstract_Present => False);
642 when Tok_Left_Paren =>
643 return P_Formal_Discrete_Type_Definition;
645 when Tok_Limited =>
646 Save_Scan_State (Scan_State);
647 Scan; -- past LIMITED
649 if Token = Tok_Interface then
650 Typedef_Node :=
651 P_Interface_Type_Definition (Abstract_Present => False);
652 Set_Limited_Present (Typedef_Node);
653 return Typedef_Node;
655 elsif Token = Tok_New then
656 Restore_Scan_State (Scan_State); -- to LIMITED
657 return P_Formal_Derived_Type_Definition;
659 else
660 if Token = Tok_Abstract then
661 Error_Msg_SC -- CODEFIX
662 ("ABSTRACT must come before LIMITED");
663 Scan; -- past improper ABSTRACT
665 if Token = Tok_New then
666 Restore_Scan_State (Scan_State); -- to LIMITED
667 return P_Formal_Derived_Type_Definition;
669 else
670 Restore_Scan_State (Scan_State);
671 return P_Formal_Private_Type_Definition;
672 end if;
673 end if;
675 Restore_Scan_State (Scan_State);
676 return P_Formal_Private_Type_Definition;
677 end if;
679 when Tok_Mod =>
680 return P_Formal_Modular_Type_Definition;
682 when Tok_New =>
683 return P_Formal_Derived_Type_Definition;
685 when Tok_Not =>
686 if P_Null_Exclusion then
687 Typedef_Node := P_Access_Type_Definition;
688 Set_Null_Exclusion_Present (Typedef_Node);
689 return Typedef_Node;
691 else
692 Error_Msg_SC ("expect valid formal access definition!");
693 Resync_Past_Semicolon;
694 return Error;
695 end if;
697 when Tok_Private |
698 Tok_Tagged =>
699 return P_Formal_Private_Type_Definition;
701 when Tok_Range =>
702 return P_Formal_Signed_Integer_Type_Definition;
704 when Tok_Record =>
705 Error_Msg_SC ("record not allowed in generic type definition!");
706 Discard_Junk_Node (P_Record_Definition);
707 return Error;
709 -- Ada 2005 (AI-345): Task, Protected or Synchronized interface or
710 -- (AI-443): Synchronized formal derived type declaration.
712 when Tok_Protected |
713 Tok_Synchronized |
714 Tok_Task =>
716 declare
717 Saved_Token : constant Token_Type := Token;
719 begin
720 Scan; -- past TASK, PROTECTED or SYNCHRONIZED
722 -- Synchronized derived type
724 if Token = Tok_New then
725 Typedef_Node := P_Formal_Derived_Type_Definition;
727 if Saved_Token = Tok_Synchronized then
728 Set_Synchronized_Present (Typedef_Node);
729 else
730 Error_Msg_SC ("invalid kind of formal derived type");
731 end if;
733 -- Interface
735 else
736 Typedef_Node :=
737 P_Interface_Type_Definition (Abstract_Present => False);
739 case Saved_Token is
740 when Tok_Task =>
741 Set_Task_Present (Typedef_Node);
743 when Tok_Protected =>
744 Set_Protected_Present (Typedef_Node);
746 when Tok_Synchronized =>
747 Set_Synchronized_Present (Typedef_Node);
749 when others =>
750 null;
751 end case;
752 end if;
754 return Typedef_Node;
755 end;
757 when others =>
758 Error_Msg_BC ("expecting generic type definition here");
759 Resync_Past_Semicolon;
760 return Error;
762 end case;
763 end P_Formal_Type_Definition;
765 --------------------------------------------
766 -- 12.5.1 Formal Private Type Definition --
767 --------------------------------------------
769 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
770 -- [[abstract] tagged] [limited] private
772 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
773 -- TAGGED or LIMITED
775 -- Error recovery: cannot raise Error_Resync
777 function P_Formal_Private_Type_Definition return Node_Id is
778 Def_Node : Node_Id;
780 begin
781 Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
783 if Token = Tok_Abstract then
784 Scan; -- past ABSTRACT
786 if Token_Name = Name_Tagged then
787 Check_95_Keyword (Tok_Tagged, Tok_Private);
788 Check_95_Keyword (Tok_Tagged, Tok_Limited);
789 end if;
791 if Token /= Tok_Tagged then
792 Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
793 else
794 Set_Abstract_Present (Def_Node, True);
795 end if;
796 end if;
798 if Token = Tok_Tagged then
799 Set_Tagged_Present (Def_Node, True);
800 Scan; -- past TAGGED
801 end if;
803 if Token = Tok_Limited then
804 Set_Limited_Present (Def_Node, True);
805 Scan; -- past LIMITED
806 end if;
808 if Token = Tok_Abstract then
809 if Prev_Token = Tok_Tagged then
810 Error_Msg_SC -- CODEFIX
811 ("ABSTRACT must come before TAGGED");
812 elsif Prev_Token = Tok_Limited then
813 Error_Msg_SC -- CODEFIX
814 ("ABSTRACT must come before LIMITED");
815 end if;
817 Resync_Past_Semicolon;
819 elsif Token = Tok_Tagged then
820 Error_Msg_SC -- CODEFIX
821 ("TAGGED must come before LIMITED");
822 Resync_Past_Semicolon;
823 end if;
825 Set_Sloc (Def_Node, Token_Ptr);
826 T_Private;
827 return Def_Node;
828 end P_Formal_Private_Type_Definition;
830 --------------------------------------------
831 -- 12.5.1 Formal Derived Type Definition --
832 --------------------------------------------
834 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
835 -- [abstract] [limited | synchronized]
836 -- new SUBTYPE_MARK [[and INTERFACE_LIST] with private]
838 -- The caller has checked the initial token(s) is/are NEW, ABSTRACT NEW,
839 -- or LIMITED NEW, ABSTRACT LIMITED NEW, SYNCHRONIZED NEW or ABSTRACT
840 -- SYNCHRONIZED NEW.
842 -- Error recovery: cannot raise Error_Resync
844 function P_Formal_Derived_Type_Definition return Node_Id is
845 Def_Node : Node_Id;
847 begin
848 Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
850 if Token = Tok_Abstract then
851 Set_Abstract_Present (Def_Node);
852 Scan; -- past ABSTRACT
853 end if;
855 if Token = Tok_Limited then
856 Set_Limited_Present (Def_Node);
857 Scan; -- past LIMITED
859 if Ada_Version < Ada_05 then
860 Error_Msg_SP
861 ("LIMITED in derived type is an Ada 2005 extension");
862 Error_Msg_SP
863 ("\unit must be compiled with -gnat05 switch");
864 end if;
866 elsif Token = Tok_Synchronized then
867 Set_Synchronized_Present (Def_Node);
868 Scan; -- past SYNCHRONIZED
870 if Ada_Version < Ada_05 then
871 Error_Msg_SP
872 ("SYNCHRONIZED in derived type is an Ada 2005 extension");
873 Error_Msg_SP
874 ("\unit must be compiled with -gnat05 switch");
875 end if;
876 end if;
878 if Token = Tok_Abstract then
879 Scan; -- past ABSTRACT, diagnosed already in caller.
880 end if;
882 Scan; -- past NEW;
883 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
884 No_Constraint;
886 -- Ada 2005 (AI-251): Deal with interfaces
888 if Token = Tok_And then
889 Scan; -- past AND
891 if Ada_Version < Ada_05 then
892 Error_Msg_SP
893 ("abstract interface is an Ada 2005 extension");
894 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
895 end if;
897 Set_Interface_List (Def_Node, New_List);
899 loop
900 Append (P_Qualified_Simple_Name, Interface_List (Def_Node));
901 exit when Token /= Tok_And;
902 Scan; -- past AND
903 end loop;
904 end if;
906 if Token = Tok_With then
907 Scan; -- past WITH
908 Set_Private_Present (Def_Node, True);
909 T_Private;
911 elsif Token = Tok_Tagged then
912 Scan;
914 if Token = Tok_Private then
915 Error_Msg_SC -- CODEFIX
916 ("TAGGED should be WITH");
917 Set_Private_Present (Def_Node, True);
918 T_Private;
919 else
920 Ignore (Tok_Tagged);
921 end if;
922 end if;
924 return Def_Node;
925 end P_Formal_Derived_Type_Definition;
927 ---------------------------------------------
928 -- 12.5.2 Formal Discrete Type Definition --
929 ---------------------------------------------
931 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
933 -- The caller has checked the initial token is left paren
935 -- Error recovery: cannot raise Error_Resync
937 function P_Formal_Discrete_Type_Definition return Node_Id is
938 Def_Node : Node_Id;
940 begin
941 Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
942 Scan; -- past left paren
943 T_Box;
944 T_Right_Paren;
945 return Def_Node;
946 end P_Formal_Discrete_Type_Definition;
948 ---------------------------------------------------
949 -- 12.5.2 Formal Signed Integer Type Definition --
950 ---------------------------------------------------
952 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
954 -- The caller has checked the initial token is RANGE
956 -- Error recovery: cannot raise Error_Resync
958 function P_Formal_Signed_Integer_Type_Definition return Node_Id is
959 Def_Node : Node_Id;
961 begin
962 Def_Node :=
963 New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
964 Scan; -- past RANGE
965 T_Box;
966 return Def_Node;
967 end P_Formal_Signed_Integer_Type_Definition;
969 --------------------------------------------
970 -- 12.5.2 Formal Modular Type Definition --
971 --------------------------------------------
973 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
975 -- The caller has checked the initial token is MOD
977 -- Error recovery: cannot raise Error_Resync
979 function P_Formal_Modular_Type_Definition return Node_Id is
980 Def_Node : Node_Id;
982 begin
983 Def_Node :=
984 New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
985 Scan; -- past MOD
986 T_Box;
987 return Def_Node;
988 end P_Formal_Modular_Type_Definition;
990 ----------------------------------------------
991 -- 12.5.2 Formal Floating Point Definition --
992 ----------------------------------------------
994 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
996 -- The caller has checked the initial token is DIGITS
998 -- Error recovery: cannot raise Error_Resync
1000 function P_Formal_Floating_Point_Definition return Node_Id is
1001 Def_Node : Node_Id;
1003 begin
1004 Def_Node :=
1005 New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
1006 Scan; -- past DIGITS
1007 T_Box;
1008 return Def_Node;
1009 end P_Formal_Floating_Point_Definition;
1011 -------------------------------------------
1012 -- 12.5.2 Formal Fixed Point Definition --
1013 -------------------------------------------
1015 -- This routine parses either a formal ordinary fixed point definition
1016 -- or a formal decimal fixed point definition:
1018 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
1020 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
1022 -- The caller has checked the initial token is DELTA
1024 -- Error recovery: cannot raise Error_Resync
1026 function P_Formal_Fixed_Point_Definition return Node_Id is
1027 Def_Node : Node_Id;
1028 Delta_Sloc : Source_Ptr;
1030 begin
1031 Delta_Sloc := Token_Ptr;
1032 Scan; -- past DELTA
1033 T_Box;
1035 if Token = Tok_Digits then
1036 Def_Node :=
1037 New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
1038 Scan; -- past DIGITS
1039 T_Box;
1040 else
1041 Def_Node :=
1042 New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
1043 end if;
1045 return Def_Node;
1046 end P_Formal_Fixed_Point_Definition;
1048 ----------------------------------------------------
1049 -- 12.5.2 Formal Ordinary Fixed Point Definition --
1050 ----------------------------------------------------
1052 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1054 ---------------------------------------------------
1055 -- 12.5.2 Formal Decimal Fixed Point Definition --
1056 ---------------------------------------------------
1058 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1060 ------------------------------------------
1061 -- 12.5.3 Formal Array Type Definition --
1062 ------------------------------------------
1064 -- Parsed by P_Formal_Type_Definition (12.5)
1066 -------------------------------------------
1067 -- 12.5.4 Formal Access Type Definition --
1068 -------------------------------------------
1070 -- Parsed by P_Formal_Type_Definition (12.5)
1072 -----------------------------------------
1073 -- 12.6 Formal Subprogram Declaration --
1074 -----------------------------------------
1076 -- FORMAL_SUBPROGRAM_DECLARATION ::=
1077 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
1078 -- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
1080 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
1081 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
1083 -- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
1084 -- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT];
1086 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
1088 -- DEFAULT_NAME ::= NAME | null
1090 -- The caller has checked that the initial tokens are WITH FUNCTION or
1091 -- WITH PROCEDURE, and the initial WITH has been scanned out.
1093 -- A null default is an Ada 2005 feature
1095 -- Error recovery: cannot raise Error_Resync
1097 function P_Formal_Subprogram_Declaration return Node_Id is
1098 Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
1099 Spec_Node : constant Node_Id := P_Subprogram_Specification;
1100 Def_Node : Node_Id;
1102 begin
1103 if Token = Tok_Is then
1104 T_Is; -- past IS, skip extra IS or ";"
1106 if Token = Tok_Abstract then
1107 Def_Node :=
1108 New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
1109 Scan; -- past ABSTRACT
1111 if Ada_Version < Ada_05 then
1112 Error_Msg_SP
1113 ("formal abstract subprograms are an Ada 2005 extension");
1114 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1115 end if;
1117 else
1118 Def_Node :=
1119 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1120 end if;
1122 Set_Specification (Def_Node, Spec_Node);
1124 if Token = Tok_Semicolon then
1125 Scan; -- past ";"
1127 elsif Token = Tok_Box then
1128 Set_Box_Present (Def_Node, True);
1129 Scan; -- past <>
1130 T_Semicolon;
1132 elsif Token = Tok_Null then
1133 if Ada_Version < Ada_05 then
1134 Error_Msg_SP
1135 ("null default subprograms are an Ada 2005 extension");
1136 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1137 end if;
1139 if Nkind (Spec_Node) = N_Procedure_Specification then
1140 Set_Null_Present (Spec_Node);
1141 else
1142 Error_Msg_SP ("only procedures can be null");
1143 end if;
1145 Scan; -- past NULL
1146 T_Semicolon;
1148 else
1149 Set_Default_Name (Def_Node, P_Name);
1150 T_Semicolon;
1151 end if;
1153 else
1154 Def_Node :=
1155 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1156 Set_Specification (Def_Node, Spec_Node);
1157 T_Semicolon;
1158 end if;
1160 return Def_Node;
1161 end P_Formal_Subprogram_Declaration;
1163 ------------------------------
1164 -- 12.6 Subprogram Default --
1165 ------------------------------
1167 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1169 ------------------------
1170 -- 12.6 Default Name --
1171 ------------------------
1173 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1175 --------------------------------------
1176 -- 12.7 Formal Package Declaration --
1177 --------------------------------------
1179 -- FORMAL_PACKAGE_DECLARATION ::=
1180 -- with package DEFINING_IDENTIFIER
1181 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
1183 -- FORMAL_PACKAGE_ACTUAL_PART ::=
1184 -- ([OTHERS =>] <>) |
1185 -- [GENERIC_ACTUAL_PART]
1186 -- (FORMAL_PACKAGE_ASSOCIATION {, FORMAL_PACKAGE_ASSOCIATION}
1187 -- [, OTHERS => <>)
1189 -- FORMAL_PACKAGE_ASSOCIATION ::=
1190 -- GENERIC_ASSOCIATION
1191 -- | GENERIC_FORMAL_PARAMETER_SELECTOR_NAME => <>
1193 -- The caller has checked that the initial tokens are WITH PACKAGE,
1194 -- and the initial WITH has been scanned out (so Token = Tok_Package).
1196 -- Error recovery: cannot raise Error_Resync
1198 function P_Formal_Package_Declaration return Node_Id is
1199 Def_Node : Node_Id;
1200 Scan_State : Saved_Scan_State;
1202 begin
1203 Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
1204 Scan; -- past PACKAGE
1205 Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
1206 T_Is;
1207 T_New;
1208 Set_Name (Def_Node, P_Qualified_Simple_Name);
1210 if Token = Tok_Left_Paren then
1211 Save_Scan_State (Scan_State); -- at the left paren
1212 Scan; -- past the left paren
1214 if Token = Tok_Box then
1215 Set_Box_Present (Def_Node, True);
1216 Scan; -- past box
1217 T_Right_Paren;
1219 else
1220 Restore_Scan_State (Scan_State); -- to the left paren
1221 Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
1222 end if;
1223 end if;
1225 T_Semicolon;
1226 return Def_Node;
1227 end P_Formal_Package_Declaration;
1229 --------------------------------------
1230 -- 12.7 Formal Package Actual Part --
1231 --------------------------------------
1233 -- Parsed by P_Formal_Package_Declaration (12.7)
1235 end Ch12;