Daily bump.
[official-gcc.git] / gcc / ada / par-ch12.adb
blob3c192f2877b80a1ef4743bc5fb83a0ae83c6dd1a
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-2013, 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
65 -- [ASPECT_SPECIFICATIONS];
67 -- GENERIC_PACKAGE_DECLARATION ::=
68 -- GENERIC_FORMAL_PART PACKAGE_SPECIFICATION
69 -- [ASPECT_SPECIFICATIONS];
71 -- GENERIC_FORMAL_PART ::=
72 -- generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
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
82 -- GENERIC_FORMAL_PARAMETER_DECLARATION ::=
83 -- FORMAL_OBJECT_DECLARATION
84 -- | FORMAL_TYPE_DECLARATION
85 -- | FORMAL_SUBPROGRAM_DECLARATION
86 -- | FORMAL_PACKAGE_DECLARATION
88 -- The caller has checked that the initial token is GENERIC
90 -- Error recovery: can raise Error_Resync
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;
101 begin
102 Scan; -- past GENERIC
104 if Token = Tok_Private then
105 Error_Msg_SC -- CODEFIX
106 ("PRIVATE goes before GENERIC, not after");
107 Scan; -- past junk PRIVATE token
108 end if;
110 Save_Scan_State (Scan_State); -- at token past GENERIC
112 -- Check for generic renaming declaration case
114 if Token = Tok_Package
115 or else Token = Tok_Function
116 or else Token = Tok_Procedure
117 then
118 Ren_Token := Token;
119 Scan; -- scan past PACKAGE, FUNCTION or PROCEDURE
121 if Token = Tok_Identifier then
122 Def_Unit := P_Defining_Program_Unit_Name;
124 Check_Misspelling_Of (Tok_Renames);
126 if Token = Tok_Renames then
127 if Ren_Token = Tok_Package then
128 Decl_Node := New_Node
129 (N_Generic_Package_Renaming_Declaration, Gen_Sloc);
131 elsif Ren_Token = Tok_Procedure then
132 Decl_Node := New_Node
133 (N_Generic_Procedure_Renaming_Declaration, Gen_Sloc);
135 else -- Ren_Token = Tok_Function then
136 Decl_Node := New_Node
137 (N_Generic_Function_Renaming_Declaration, Gen_Sloc);
138 end if;
140 Scan; -- past RENAMES
141 Set_Defining_Unit_Name (Decl_Node, Def_Unit);
142 Set_Name (Decl_Node, P_Name);
143 TF_Semicolon;
144 return Decl_Node;
145 end if;
146 end if;
147 end if;
149 -- Fall through if this is *not* a generic renaming declaration
151 Restore_Scan_State (Scan_State);
152 Decls := New_List;
154 -- Loop through generic parameter declarations and use clauses
156 Decl_Loop : loop
157 P_Pragmas_Opt (Decls);
159 if Token = Tok_Private then
160 Error_Msg_S ("generic private child packages not permitted");
161 Scan; -- past PRIVATE
162 end if;
164 if Token = Tok_Use then
165 Append (P_Use_Clause, Decls);
166 else
167 -- Parse a generic parameter declaration
169 if Token = Tok_Identifier then
170 P_Formal_Object_Declarations (Decls);
172 elsif Token = Tok_Type then
173 Append (P_Formal_Type_Declaration, Decls);
175 elsif Token = Tok_With then
176 Scan; -- past WITH
178 if Token = Tok_Package then
179 Append (P_Formal_Package_Declaration, Decls);
181 elsif Token = Tok_Procedure or Token = Tok_Function then
182 Append (P_Formal_Subprogram_Declaration, Decls);
184 else
185 Error_Msg_BC -- CODEFIX
186 ("FUNCTION, PROCEDURE or PACKAGE expected here");
187 Resync_Past_Semicolon;
188 end if;
190 elsif Token = Tok_Subtype then
191 Error_Msg_SC ("subtype declaration not allowed " &
192 "as generic parameter declaration!");
193 Resync_Past_Semicolon;
195 else
196 exit Decl_Loop;
197 end if;
198 end if;
199 end loop Decl_Loop;
201 -- Generic formal part is scanned, scan out subprogram or package spec
203 if Token = Tok_Package then
204 Gen_Decl := New_Node (N_Generic_Package_Declaration, Gen_Sloc);
205 Set_Specification (Gen_Decl, P_Package (Pf_Spcn));
207 -- Aspects have been parsed by the package spec. Move them to the
208 -- generic declaration where they belong.
210 Move_Aspects (Specification (Gen_Decl), Gen_Decl);
212 else
213 Gen_Decl := New_Node (N_Generic_Subprogram_Declaration, Gen_Sloc);
215 Set_Specification (Gen_Decl, P_Subprogram_Specification);
217 if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
218 N_Defining_Program_Unit_Name
219 and then Scope.Last > 0
220 then
221 Error_Msg_SP ("child unit allowed only at library level");
222 end if;
224 P_Aspect_Specifications (Gen_Decl);
225 end if;
227 Set_Generic_Formal_Declarations (Gen_Decl, Decls);
228 return Gen_Decl;
229 end P_Generic;
231 -------------------------------
232 -- 12.1 Generic Declaration --
233 -------------------------------
235 -- Parsed by P_Generic (12.1)
237 ------------------------------------------
238 -- 12.1 Generic Subprogram Declaration --
239 ------------------------------------------
241 -- Parsed by P_Generic (12.1)
243 ---------------------------------------
244 -- 12.1 Generic Package Declaration --
245 ---------------------------------------
247 -- Parsed by P_Generic (12.1)
249 -------------------------------
250 -- 12.1 Generic Formal Part --
251 -------------------------------
253 -- Parsed by P_Generic (12.1)
255 -------------------------------------------------
256 -- 12.1 Generic Formal Parameter Declaration --
257 -------------------------------------------------
259 -- Parsed by P_Generic (12.1)
261 ---------------------------------
262 -- 12.3 Generic Instantiation --
263 ---------------------------------
265 -- Generic package instantiation parsed by P_Package (7.1)
266 -- Generic procedure instantiation parsed by P_Subprogram (6.1)
267 -- Generic function instantiation parsed by P_Subprogram (6.1)
269 -------------------------------
270 -- 12.3 Generic Actual Part --
271 -------------------------------
273 -- GENERIC_ACTUAL_PART ::=
274 -- (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
276 -- Returns a list of generic associations, or Empty if none are present
278 -- Error recovery: cannot raise Error_Resync
280 function P_Generic_Actual_Part_Opt return List_Id is
281 Association_List : List_Id;
283 begin
284 -- Figure out if a generic actual part operation is present. Clearly
285 -- there is no generic actual part if the current token is semicolon
286 -- or if we have aspect specifications present.
288 if Token = Tok_Semicolon or else Aspect_Specifications_Present then
289 return No_List;
291 -- If we don't have a left paren, then we have an error, and the job
292 -- is to figure out whether a left paren or semicolon was intended.
293 -- We assume a missing left paren (and hence a generic actual part
294 -- present) if the current token is not on a new line, or if it is
295 -- indented from the subprogram token. Otherwise assume missing
296 -- semicolon (which will be diagnosed by caller) and no generic part
298 elsif Token /= Tok_Left_Paren
299 and then Token_Is_At_Start_Of_Line
300 and then Start_Column <= Scope.Table (Scope.Last).Ecol
301 then
302 return No_List;
304 -- Otherwise we have a generic actual part (either a left paren is
305 -- present, or we have decided that there must be a missing left paren)
307 else
308 Association_List := New_List;
309 T_Left_Paren;
311 loop
312 Append (P_Generic_Association, Association_List);
313 exit when not Comma_Present;
314 end loop;
316 T_Right_Paren;
317 return Association_List;
318 end if;
320 end P_Generic_Actual_Part_Opt;
322 -------------------------------
323 -- 12.3 Generic Association --
324 -------------------------------
326 -- GENERIC_ASSOCIATION ::=
327 -- [generic_formal_parameter_SELECTOR_NAME =>]
328 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER
330 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
331 -- EXPRESSION | variable_NAME | subprogram_NAME
332 -- | entry_NAME | SUBTYPE_MARK | package_instance_NAME
334 -- Error recovery: cannot raise Error_Resync
336 function P_Generic_Association return Node_Id is
337 Scan_State : Saved_Scan_State;
338 Param_Name_Node : Node_Id;
339 Generic_Assoc_Node : Node_Id;
341 begin
342 Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
344 -- Ada 2005: an association can be given by: others => <>
346 if Token = Tok_Others then
347 if Ada_Version < Ada_2005 then
348 Error_Msg_SP
349 ("partial parametrization of formal packages" &
350 " is an Ada 2005 extension");
351 Error_Msg_SP
352 ("\unit must be compiled with -gnat05 switch");
353 end if;
355 Scan; -- past OTHERS
357 if Token /= Tok_Arrow then
358 Error_Msg_BC ("expect arrow after others");
359 else
360 Scan; -- past arrow
361 end if;
363 if Token /= Tok_Box then
364 Error_Msg_BC ("expect Box after arrow");
365 else
366 Scan; -- past box
367 end if;
369 -- Source position of the others choice is beginning of construct
371 return New_Node (N_Others_Choice, Sloc (Generic_Assoc_Node));
372 end if;
374 if Token in Token_Class_Desig then
375 Param_Name_Node := Token_Node;
376 Save_Scan_State (Scan_State); -- at designator
377 Scan; -- past simple name or operator symbol
379 if Token = Tok_Arrow then
380 Scan; -- past arrow
381 Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
382 else
383 Restore_Scan_State (Scan_State); -- to designator
384 end if;
385 end if;
387 -- In Ada 2005 the actual can be a box
389 if Token = Tok_Box then
390 Scan;
391 Set_Box_Present (Generic_Assoc_Node);
392 Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, Empty);
394 else
395 Set_Explicit_Generic_Actual_Parameter
396 (Generic_Assoc_Node, P_Expression);
397 end if;
399 return Generic_Assoc_Node;
400 end P_Generic_Association;
402 ---------------------------------------------
403 -- 12.3 Explicit Generic Actual Parameter --
404 ---------------------------------------------
406 -- Parsed by P_Generic_Association (12.3)
408 --------------------------------------
409 -- 12.4 Formal Object Declarations --
410 --------------------------------------
412 -- FORMAL_OBJECT_DECLARATION ::=
413 -- DEFINING_IDENTIFIER_LIST :
414 -- MODE [NULL_EXCLUSION] SUBTYPE_MARK [:= DEFAULT_EXPRESSION]
415 -- [ASPECT_SPECIFICATIONS];
416 -- | DEFINING_IDENTIFIER_LIST :
417 -- MODE ACCESS_DEFINITION [:= DEFAULT_EXPRESSION];
418 -- [ASPECT_SPECIFICATIONS];
420 -- The caller has checked that the initial token is an identifier
422 -- Error recovery: cannot raise Error_Resync
424 procedure P_Formal_Object_Declarations (Decls : List_Id) is
425 Decl_Node : Node_Id;
426 Ident : Nat;
427 Not_Null_Present : Boolean := False;
428 Num_Idents : Nat;
429 Scan_State : Saved_Scan_State;
431 Idents : array (Int range 1 .. 4096) of Entity_Id;
432 -- This array holds the list of defining identifiers. The upper bound
433 -- of 4096 is intended to be essentially infinite, and we do not even
434 -- bother to check for it being exceeded.
436 begin
437 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
438 Num_Idents := 1;
439 while Comma_Present loop
440 Num_Idents := Num_Idents + 1;
441 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
442 end loop;
444 T_Colon;
446 -- If there are multiple identifiers, we repeatedly scan the
447 -- type and initialization expression information by resetting
448 -- the scan pointer (so that we get completely separate trees
449 -- for each occurrence).
451 if Num_Idents > 1 then
452 Save_Scan_State (Scan_State);
453 end if;
455 -- Loop through defining identifiers in list
457 Ident := 1;
458 Ident_Loop : loop
459 Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
460 Set_Defining_Identifier (Decl_Node, Idents (Ident));
461 P_Mode (Decl_Node);
463 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-423)
465 -- Ada 2005 (AI-423): Formal object with an access definition
467 if Token = Tok_Access then
469 -- The access definition is still parsed and set even though
470 -- the compilation may not use the proper switch. This action
471 -- ensures the required local error recovery.
473 Set_Access_Definition (Decl_Node,
474 P_Access_Definition (Not_Null_Present));
476 if Ada_Version < Ada_2005 then
477 Error_Msg_SP
478 ("access definition not allowed in formal object " &
479 "declaration");
480 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
481 end if;
483 -- Formal object with a subtype mark
485 else
486 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
487 Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
488 end if;
490 No_Constraint;
491 Set_Default_Expression (Decl_Node, Init_Expr_Opt);
492 P_Aspect_Specifications (Decl_Node);
494 if Ident > 1 then
495 Set_Prev_Ids (Decl_Node, True);
496 end if;
498 if Ident < Num_Idents then
499 Set_More_Ids (Decl_Node, True);
500 end if;
502 Append (Decl_Node, Decls);
504 exit Ident_Loop when Ident = Num_Idents;
505 Ident := Ident + 1;
506 Restore_Scan_State (Scan_State);
507 end loop Ident_Loop;
508 end P_Formal_Object_Declarations;
510 -----------------------------------
511 -- 12.5 Formal Type Declaration --
512 -----------------------------------
514 -- FORMAL_TYPE_DECLARATION ::=
515 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
516 -- is FORMAL_TYPE_DEFINITION
517 -- [ASPECT_SPECIFICATIONS];
519 -- The caller has checked that the initial token is TYPE
521 -- Error recovery: cannot raise Error_Resync
523 function P_Formal_Type_Declaration return Node_Id is
524 Decl_Node : Node_Id;
525 Def_Node : Node_Id;
527 begin
528 Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
529 Scan; -- past TYPE
530 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
532 if P_Unknown_Discriminant_Part_Opt then
533 Set_Unknown_Discriminants_Present (Decl_Node, True);
534 else
535 Set_Discriminant_Specifications
536 (Decl_Node, P_Known_Discriminant_Part_Opt);
537 end if;
539 if Token = Tok_Semicolon then
541 -- Ada 2012: Incomplete formal type
543 Scan; -- past semicolon
545 if Ada_Version < Ada_2012 then
546 Error_Msg_N
547 ("`formal incomplete type` is an Ada 2012 feature", Decl_Node);
548 Error_Msg_N
549 ("\unit must be compiled with -gnat2012 switch", Decl_Node);
550 end if;
552 Set_Formal_Type_Definition
553 (Decl_Node,
554 New_Node (N_Formal_Incomplete_Type_Definition, Token_Ptr));
555 return Decl_Node;
557 else
558 T_Is;
559 end if;
561 Def_Node := P_Formal_Type_Definition;
563 if Nkind (Def_Node) = N_Formal_Incomplete_Type_Definition
564 and then Ada_Version < Ada_2012
565 then
566 Error_Msg_N
567 ("`formal incomplete type` is an Ada 2012 feature", Decl_Node);
568 Error_Msg_N
569 ("\unit must be compiled with -gnat2012 switch", Decl_Node);
570 end if;
572 if Def_Node /= Error then
573 Set_Formal_Type_Definition (Decl_Node, Def_Node);
574 P_Aspect_Specifications (Decl_Node);
576 else
577 Decl_Node := Error;
579 -- If we have aspect specifications, skip them
581 if Aspect_Specifications_Present then
582 P_Aspect_Specifications (Error);
584 -- If we have semicolon, skip it to avoid cascaded errors
586 elsif Token = Tok_Semicolon then
587 Scan; -- past semicolon
588 end if;
589 end if;
591 return Decl_Node;
592 end P_Formal_Type_Declaration;
594 ----------------------------------
595 -- 12.5 Formal Type Definition --
596 ----------------------------------
598 -- FORMAL_TYPE_DEFINITION ::=
599 -- FORMAL_PRIVATE_TYPE_DEFINITION
600 -- | FORMAL_INCOMPLETE_TYPE_DEFINITION
601 -- | FORMAL_DERIVED_TYPE_DEFINITION
602 -- | FORMAL_DISCRETE_TYPE_DEFINITION
603 -- | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
604 -- | FORMAL_MODULAR_TYPE_DEFINITION
605 -- | FORMAL_FLOATING_POINT_DEFINITION
606 -- | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
607 -- | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
608 -- | FORMAL_ARRAY_TYPE_DEFINITION
609 -- | FORMAL_ACCESS_TYPE_DEFINITION
610 -- | FORMAL_INTERFACE_TYPE_DEFINITION
612 -- FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
614 -- FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
616 -- FORMAL_INTERFACE_TYPE_DEFINITION ::= INTERFACE_TYPE_DEFINITION
618 function P_Formal_Type_Definition return Node_Id is
619 Scan_State : Saved_Scan_State;
620 Typedef_Node : Node_Id;
622 begin
623 if Token_Name = Name_Abstract then
624 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
625 end if;
627 if Token_Name = Name_Tagged then
628 Check_95_Keyword (Tok_Tagged, Tok_Private);
629 Check_95_Keyword (Tok_Tagged, Tok_Limited);
630 end if;
632 case Token is
634 -- Mostly we can tell what we have from the initial token. The one
635 -- exception is ABSTRACT, where we have to scan ahead to see if we
636 -- have a formal derived type or a formal private type definition.
638 -- In addition, in Ada 2005 LIMITED may appear after abstract, so
639 -- that the lookahead must be extended by one more token.
641 when Tok_Abstract =>
642 Save_Scan_State (Scan_State);
643 Scan; -- past ABSTRACT
645 if Token = Tok_New then
646 Restore_Scan_State (Scan_State); -- to ABSTRACT
647 return P_Formal_Derived_Type_Definition;
649 elsif Token = Tok_Limited then
650 Scan; -- past LIMITED
652 if Token = Tok_New then
653 Restore_Scan_State (Scan_State); -- to ABSTRACT
654 return P_Formal_Derived_Type_Definition;
656 else
657 Restore_Scan_State (Scan_State); -- to ABSTRACT
658 return P_Formal_Private_Type_Definition;
659 end if;
661 -- Ada 2005 (AI-443): Abstract synchronized formal derived type
663 elsif Token = Tok_Synchronized then
664 Restore_Scan_State (Scan_State); -- to ABSTRACT
665 return P_Formal_Derived_Type_Definition;
667 else
668 Restore_Scan_State (Scan_State); -- to ABSTRACT
669 return P_Formal_Private_Type_Definition;
670 end if;
672 when Tok_Access =>
673 return P_Access_Type_Definition;
675 when Tok_Array =>
676 return P_Array_Type_Definition;
678 when Tok_Delta =>
679 return P_Formal_Fixed_Point_Definition;
681 when Tok_Digits =>
682 return P_Formal_Floating_Point_Definition;
684 when Tok_Interface => -- Ada 2005 (AI-251)
685 return P_Interface_Type_Definition (Abstract_Present => False);
687 when Tok_Left_Paren =>
688 return P_Formal_Discrete_Type_Definition;
690 when Tok_Limited =>
691 Save_Scan_State (Scan_State);
692 Scan; -- past LIMITED
694 if Token = Tok_Interface then
695 Typedef_Node :=
696 P_Interface_Type_Definition (Abstract_Present => False);
697 Set_Limited_Present (Typedef_Node);
698 return Typedef_Node;
700 elsif Token = Tok_New then
701 Restore_Scan_State (Scan_State); -- to LIMITED
702 return P_Formal_Derived_Type_Definition;
704 else
705 if Token = Tok_Abstract then
706 Error_Msg_SC -- CODEFIX
707 ("ABSTRACT must come before LIMITED");
708 Scan; -- past improper ABSTRACT
710 if Token = Tok_New then
711 Restore_Scan_State (Scan_State); -- to LIMITED
712 return P_Formal_Derived_Type_Definition;
714 else
715 Restore_Scan_State (Scan_State);
716 return P_Formal_Private_Type_Definition;
717 end if;
718 end if;
720 Restore_Scan_State (Scan_State);
721 return P_Formal_Private_Type_Definition;
722 end if;
724 when Tok_Mod =>
725 return P_Formal_Modular_Type_Definition;
727 when Tok_New =>
728 return P_Formal_Derived_Type_Definition;
730 when Tok_Not =>
731 if P_Null_Exclusion then
732 Typedef_Node := P_Access_Type_Definition;
733 Set_Null_Exclusion_Present (Typedef_Node);
734 return Typedef_Node;
736 else
737 Error_Msg_SC ("expect valid formal access definition!");
738 Resync_Past_Semicolon;
739 return Error;
740 end if;
742 when Tok_Private =>
743 return P_Formal_Private_Type_Definition;
745 when Tok_Tagged =>
746 if Next_Token_Is (Tok_Semicolon) then
747 Typedef_Node :=
748 New_Node (N_Formal_Incomplete_Type_Definition, Token_Ptr);
749 Set_Tagged_Present (Typedef_Node);
751 Scan; -- past tagged
752 return Typedef_Node;
754 else
755 return P_Formal_Private_Type_Definition;
756 end if;
758 when Tok_Range =>
759 return P_Formal_Signed_Integer_Type_Definition;
761 when Tok_Record =>
762 Error_Msg_SC ("record not allowed in generic type definition!");
763 Discard_Junk_Node (P_Record_Definition);
764 return Error;
766 -- Ada 2005 (AI-345): Task, Protected or Synchronized interface or
767 -- (AI-443): Synchronized formal derived type declaration.
769 when Tok_Protected |
770 Tok_Synchronized |
771 Tok_Task =>
773 declare
774 Saved_Token : constant Token_Type := Token;
776 begin
777 Scan; -- past TASK, PROTECTED or SYNCHRONIZED
779 -- Synchronized derived type
781 if Token = Tok_New then
782 Typedef_Node := P_Formal_Derived_Type_Definition;
784 if Saved_Token = Tok_Synchronized then
785 Set_Synchronized_Present (Typedef_Node);
786 else
787 Error_Msg_SC ("invalid kind of formal derived type");
788 end if;
790 -- Interface
792 else
793 Typedef_Node :=
794 P_Interface_Type_Definition (Abstract_Present => False);
796 case Saved_Token is
797 when Tok_Task =>
798 Set_Task_Present (Typedef_Node);
800 when Tok_Protected =>
801 Set_Protected_Present (Typedef_Node);
803 when Tok_Synchronized =>
804 Set_Synchronized_Present (Typedef_Node);
806 when others =>
807 null;
808 end case;
809 end if;
811 return Typedef_Node;
812 end;
814 when others =>
815 Error_Msg_BC ("expecting generic type definition here");
816 Resync_Past_Semicolon;
817 return Error;
819 end case;
820 end P_Formal_Type_Definition;
822 --------------------------------------------
823 -- 12.5.1 Formal Private Type Definition --
824 --------------------------------------------
826 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
827 -- [[abstract] tagged] [limited] private
829 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
830 -- TAGGED or LIMITED
832 -- Error recovery: cannot raise Error_Resync
834 function P_Formal_Private_Type_Definition return Node_Id is
835 Def_Node : Node_Id;
837 begin
838 Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
840 if Token = Tok_Abstract then
841 Scan; -- past ABSTRACT
843 if Token_Name = Name_Tagged then
844 Check_95_Keyword (Tok_Tagged, Tok_Private);
845 Check_95_Keyword (Tok_Tagged, Tok_Limited);
846 end if;
848 if Token /= Tok_Tagged then
849 Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
850 else
851 Set_Abstract_Present (Def_Node, True);
852 end if;
853 end if;
855 if Token = Tok_Tagged then
856 Set_Tagged_Present (Def_Node, True);
857 Scan; -- past TAGGED
858 end if;
860 if Token = Tok_Limited then
861 Set_Limited_Present (Def_Node, True);
862 Scan; -- past LIMITED
863 end if;
865 if Token = Tok_Abstract then
866 if Prev_Token = Tok_Tagged then
867 Error_Msg_SC -- CODEFIX
868 ("ABSTRACT must come before TAGGED");
869 elsif Prev_Token = Tok_Limited then
870 Error_Msg_SC -- CODEFIX
871 ("ABSTRACT must come before LIMITED");
872 end if;
874 Resync_Past_Semicolon;
876 elsif Token = Tok_Tagged then
877 Error_Msg_SC -- CODEFIX
878 ("TAGGED must come before LIMITED");
879 Resync_Past_Semicolon;
880 end if;
882 Set_Sloc (Def_Node, Token_Ptr);
883 T_Private;
885 if Token = Tok_Tagged then -- CODEFIX
886 Error_Msg_SC ("TAGGED must come before PRIVATE");
887 Scan; -- past TAGGED
889 elsif Token = Tok_Abstract then -- CODEFIX
890 Error_Msg_SC ("`ABSTRACT TAGGED` must come before PRIVATE");
891 Scan; -- past ABSTRACT
893 if Token = Tok_Tagged then
894 Scan; -- past TAGGED
895 end if;
896 end if;
898 return Def_Node;
899 end P_Formal_Private_Type_Definition;
901 --------------------------------------------
902 -- 12.5.1 Formal Derived Type Definition --
903 --------------------------------------------
905 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
906 -- [abstract] [limited | synchronized]
907 -- new SUBTYPE_MARK [[and INTERFACE_LIST] with private]
909 -- The caller has checked the initial token(s) is/are NEW, ABSTRACT NEW,
910 -- or LIMITED NEW, ABSTRACT LIMITED NEW, SYNCHRONIZED NEW or ABSTRACT
911 -- SYNCHRONIZED NEW.
913 -- Error recovery: cannot raise Error_Resync
915 function P_Formal_Derived_Type_Definition return Node_Id is
916 Def_Node : Node_Id;
918 begin
919 Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
921 if Token = Tok_Abstract then
922 Set_Abstract_Present (Def_Node);
923 Scan; -- past ABSTRACT
924 end if;
926 if Token = Tok_Limited then
927 Set_Limited_Present (Def_Node);
928 Scan; -- past LIMITED
930 if Ada_Version < Ada_2005 then
931 Error_Msg_SP
932 ("LIMITED in derived type is an Ada 2005 extension");
933 Error_Msg_SP
934 ("\unit must be compiled with -gnat05 switch");
935 end if;
937 elsif Token = Tok_Synchronized then
938 Set_Synchronized_Present (Def_Node);
939 Scan; -- past SYNCHRONIZED
941 if Ada_Version < Ada_2005 then
942 Error_Msg_SP
943 ("SYNCHRONIZED in derived type is an Ada 2005 extension");
944 Error_Msg_SP
945 ("\unit must be compiled with -gnat05 switch");
946 end if;
947 end if;
949 if Token = Tok_Abstract then
950 Scan; -- past ABSTRACT, diagnosed already in caller.
951 end if;
953 Scan; -- past NEW;
954 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
955 No_Constraint;
957 -- Ada 2005 (AI-251): Deal with interfaces
959 if Token = Tok_And then
960 Scan; -- past AND
962 if Ada_Version < Ada_2005 then
963 Error_Msg_SP
964 ("abstract interface is an Ada 2005 extension");
965 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
966 end if;
968 Set_Interface_List (Def_Node, New_List);
970 loop
971 Append (P_Qualified_Simple_Name, Interface_List (Def_Node));
972 exit when Token /= Tok_And;
973 Scan; -- past AND
974 end loop;
975 end if;
977 if Token = Tok_With then
978 Scan; -- past WITH
979 Set_Private_Present (Def_Node, True);
980 T_Private;
982 elsif Token = Tok_Tagged then
983 Scan;
985 if Token = Tok_Private then
986 Error_Msg_SC -- CODEFIX
987 ("TAGGED should be WITH");
988 Set_Private_Present (Def_Node, True);
989 T_Private;
990 else
991 Ignore (Tok_Tagged);
992 end if;
993 end if;
995 return Def_Node;
996 end P_Formal_Derived_Type_Definition;
998 ---------------------------------------------
999 -- 12.5.2 Formal Discrete Type Definition --
1000 ---------------------------------------------
1002 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
1004 -- The caller has checked the initial token is left paren
1006 -- Error recovery: cannot raise Error_Resync
1008 function P_Formal_Discrete_Type_Definition return Node_Id is
1009 Def_Node : Node_Id;
1011 begin
1012 Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
1013 Scan; -- past left paren
1014 T_Box;
1015 T_Right_Paren;
1016 return Def_Node;
1017 end P_Formal_Discrete_Type_Definition;
1019 ---------------------------------------------------
1020 -- 12.5.2 Formal Signed Integer Type Definition --
1021 ---------------------------------------------------
1023 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
1025 -- The caller has checked the initial token is RANGE
1027 -- Error recovery: cannot raise Error_Resync
1029 function P_Formal_Signed_Integer_Type_Definition return Node_Id is
1030 Def_Node : Node_Id;
1032 begin
1033 Def_Node :=
1034 New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
1035 Scan; -- past RANGE
1036 T_Box;
1037 return Def_Node;
1038 end P_Formal_Signed_Integer_Type_Definition;
1040 --------------------------------------------
1041 -- 12.5.2 Formal Modular Type Definition --
1042 --------------------------------------------
1044 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
1046 -- The caller has checked the initial token is MOD
1048 -- Error recovery: cannot raise Error_Resync
1050 function P_Formal_Modular_Type_Definition return Node_Id is
1051 Def_Node : Node_Id;
1053 begin
1054 Def_Node :=
1055 New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
1056 Scan; -- past MOD
1057 T_Box;
1058 return Def_Node;
1059 end P_Formal_Modular_Type_Definition;
1061 ----------------------------------------------
1062 -- 12.5.2 Formal Floating Point Definition --
1063 ----------------------------------------------
1065 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
1067 -- The caller has checked the initial token is DIGITS
1069 -- Error recovery: cannot raise Error_Resync
1071 function P_Formal_Floating_Point_Definition return Node_Id is
1072 Def_Node : Node_Id;
1074 begin
1075 Def_Node :=
1076 New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
1077 Scan; -- past DIGITS
1078 T_Box;
1079 return Def_Node;
1080 end P_Formal_Floating_Point_Definition;
1082 -------------------------------------------
1083 -- 12.5.2 Formal Fixed Point Definition --
1084 -------------------------------------------
1086 -- This routine parses either a formal ordinary fixed point definition
1087 -- or a formal decimal fixed point definition:
1089 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
1091 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
1093 -- The caller has checked the initial token is DELTA
1095 -- Error recovery: cannot raise Error_Resync
1097 function P_Formal_Fixed_Point_Definition return Node_Id is
1098 Def_Node : Node_Id;
1099 Delta_Sloc : Source_Ptr;
1101 begin
1102 Delta_Sloc := Token_Ptr;
1103 Scan; -- past DELTA
1104 T_Box;
1106 if Token = Tok_Digits then
1107 Def_Node :=
1108 New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
1109 Scan; -- past DIGITS
1110 T_Box;
1111 else
1112 Def_Node :=
1113 New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
1114 end if;
1116 return Def_Node;
1117 end P_Formal_Fixed_Point_Definition;
1119 ----------------------------------------------------
1120 -- 12.5.2 Formal Ordinary Fixed Point Definition --
1121 ----------------------------------------------------
1123 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1125 ---------------------------------------------------
1126 -- 12.5.2 Formal Decimal Fixed Point Definition --
1127 ---------------------------------------------------
1129 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1131 ------------------------------------------
1132 -- 12.5.3 Formal Array Type Definition --
1133 ------------------------------------------
1135 -- Parsed by P_Formal_Type_Definition (12.5)
1137 -------------------------------------------
1138 -- 12.5.4 Formal Access Type Definition --
1139 -------------------------------------------
1141 -- Parsed by P_Formal_Type_Definition (12.5)
1143 -----------------------------------------
1144 -- 12.6 Formal Subprogram Declaration --
1145 -----------------------------------------
1147 -- FORMAL_SUBPROGRAM_DECLARATION ::=
1148 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
1149 -- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
1151 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
1152 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT]
1153 -- [ASPECT_SPECIFICATIONS];
1155 -- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
1156 -- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT]
1157 -- [ASPECT_SPECIFICATIONS];
1159 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
1161 -- DEFAULT_NAME ::= NAME | null
1163 -- The caller has checked that the initial tokens are WITH FUNCTION or
1164 -- WITH PROCEDURE, and the initial WITH has been scanned out.
1166 -- A null default is an Ada 2005 feature
1168 -- Error recovery: cannot raise Error_Resync
1170 function P_Formal_Subprogram_Declaration return Node_Id is
1171 Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
1172 Spec_Node : constant Node_Id := P_Subprogram_Specification;
1173 Def_Node : Node_Id;
1175 begin
1176 if Token = Tok_Is then
1177 T_Is; -- past IS, skip extra IS or ";"
1179 if Token = Tok_Abstract then
1180 Def_Node :=
1181 New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
1182 Scan; -- past ABSTRACT
1184 if Ada_Version < Ada_2005 then
1185 Error_Msg_SP
1186 ("formal abstract subprograms are an Ada 2005 extension");
1187 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1188 end if;
1190 else
1191 Def_Node :=
1192 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1193 end if;
1195 Set_Specification (Def_Node, Spec_Node);
1197 if Token = Tok_Semicolon then
1198 null;
1200 elsif Aspect_Specifications_Present then
1201 null;
1203 elsif Token = Tok_Box then
1204 Set_Box_Present (Def_Node, True);
1205 Scan; -- past <>
1207 elsif Token = Tok_Null then
1208 if Ada_Version < Ada_2005 then
1209 Error_Msg_SP
1210 ("null default subprograms are an Ada 2005 extension");
1211 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1212 end if;
1214 if Nkind (Spec_Node) = N_Procedure_Specification then
1215 Set_Null_Present (Spec_Node);
1216 else
1217 Error_Msg_SP ("only procedures can be null");
1218 end if;
1220 Scan; -- past NULL
1222 else
1223 Set_Default_Name (Def_Node, P_Name);
1224 end if;
1226 else
1227 Def_Node :=
1228 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1229 Set_Specification (Def_Node, Spec_Node);
1230 end if;
1232 P_Aspect_Specifications (Def_Node);
1233 return Def_Node;
1234 end P_Formal_Subprogram_Declaration;
1236 ------------------------------
1237 -- 12.6 Subprogram Default --
1238 ------------------------------
1240 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1242 ------------------------
1243 -- 12.6 Default Name --
1244 ------------------------
1246 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1248 --------------------------------------
1249 -- 12.7 Formal Package Declaration --
1250 --------------------------------------
1252 -- FORMAL_PACKAGE_DECLARATION ::=
1253 -- with package DEFINING_IDENTIFIER
1254 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART
1255 -- [ASPECT_SPECIFICATIONS];
1257 -- FORMAL_PACKAGE_ACTUAL_PART ::=
1258 -- ([OTHERS =>] <>) |
1259 -- [GENERIC_ACTUAL_PART]
1260 -- (FORMAL_PACKAGE_ASSOCIATION {, FORMAL_PACKAGE_ASSOCIATION}
1261 -- [, OTHERS => <>)
1263 -- FORMAL_PACKAGE_ASSOCIATION ::=
1264 -- GENERIC_ASSOCIATION
1265 -- | GENERIC_FORMAL_PARAMETER_SELECTOR_NAME => <>
1267 -- The caller has checked that the initial tokens are WITH PACKAGE,
1268 -- and the initial WITH has been scanned out (so Token = Tok_Package).
1270 -- Error recovery: cannot raise Error_Resync
1272 function P_Formal_Package_Declaration return Node_Id is
1273 Def_Node : Node_Id;
1274 Scan_State : Saved_Scan_State;
1276 begin
1277 Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
1278 Scan; -- past PACKAGE
1279 Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
1280 T_Is;
1281 T_New;
1282 Set_Name (Def_Node, P_Qualified_Simple_Name);
1284 if Token = Tok_Left_Paren then
1285 Save_Scan_State (Scan_State); -- at the left paren
1286 Scan; -- past the left paren
1288 if Token = Tok_Box then
1289 Set_Box_Present (Def_Node, True);
1290 Scan; -- past box
1291 T_Right_Paren;
1293 else
1294 Restore_Scan_State (Scan_State); -- to the left paren
1295 Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
1296 end if;
1297 end if;
1299 P_Aspect_Specifications (Def_Node);
1300 return Def_Node;
1301 end P_Formal_Package_Declaration;
1303 --------------------------------------
1304 -- 12.7 Formal Package Actual Part --
1305 --------------------------------------
1307 -- Parsed by P_Formal_Package_Declaration (12.7)
1309 end Ch12;