2011-06-29 François Dumont <francois.cppdevs@free.fr>
[official-gcc.git] / gcc / ada / par-ch12.adb
blob9e80403895e8b988cac11a1e9dac597d41bb8307
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
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, Gen_Decl));
207 else
208 Gen_Decl := New_Node (N_Generic_Subprogram_Declaration, Gen_Sloc);
210 Set_Specification (Gen_Decl, P_Subprogram_Specification);
212 if Nkind (Defining_Unit_Name (Specification (Gen_Decl))) =
213 N_Defining_Program_Unit_Name
214 and then Scope.Last > 0
215 then
216 Error_Msg_SP ("child unit allowed only at library level");
217 end if;
219 P_Aspect_Specifications (Gen_Decl);
220 end if;
222 Set_Generic_Formal_Declarations (Gen_Decl, Decls);
223 return Gen_Decl;
224 end P_Generic;
226 -------------------------------
227 -- 12.1 Generic Declaration --
228 -------------------------------
230 -- Parsed by P_Generic (12.1)
232 ------------------------------------------
233 -- 12.1 Generic Subprogram Declaration --
234 ------------------------------------------
236 -- Parsed by P_Generic (12.1)
238 ---------------------------------------
239 -- 12.1 Generic Package Declaration --
240 ---------------------------------------
242 -- Parsed by P_Generic (12.1)
244 -------------------------------
245 -- 12.1 Generic Formal Part --
246 -------------------------------
248 -- Parsed by P_Generic (12.1)
250 -------------------------------------------------
251 -- 12.1 Generic Formal Parameter Declaration --
252 -------------------------------------------------
254 -- Parsed by P_Generic (12.1)
256 ---------------------------------
257 -- 12.3 Generic Instantiation --
258 ---------------------------------
260 -- Generic package instantiation parsed by P_Package (7.1)
261 -- Generic procedure instantiation parsed by P_Subprogram (6.1)
262 -- Generic function instantiation parsed by P_Subprogram (6.1)
264 -------------------------------
265 -- 12.3 Generic Actual Part --
266 -------------------------------
268 -- GENERIC_ACTUAL_PART ::=
269 -- (GENERIC_ASSOCIATION {, GENERIC_ASSOCIATION})
271 -- Returns a list of generic associations, or Empty if none are present
273 -- Error recovery: cannot raise Error_Resync
275 function P_Generic_Actual_Part_Opt return List_Id is
276 Association_List : List_Id;
278 begin
279 -- Figure out if a generic actual part operation is present. Clearly
280 -- there is no generic actual part if the current token is semicolon
281 -- or if we have aspect specifications present.
283 if Token = Tok_Semicolon or else Aspect_Specifications_Present then
284 return No_List;
286 -- If we don't have a left paren, then we have an error, and the job
287 -- is to figure out whether a left paren or semicolon was intended.
288 -- We assume a missing left paren (and hence a generic actual part
289 -- present) if the current token is not on a new line, or if it is
290 -- indented from the subprogram token. Otherwise assume missing
291 -- semicolon (which will be diagnosed by caller) and no generic part
293 elsif Token /= Tok_Left_Paren
294 and then Token_Is_At_Start_Of_Line
295 and then Start_Column <= Scope.Table (Scope.Last).Ecol
296 then
297 return No_List;
299 -- Otherwise we have a generic actual part (either a left paren is
300 -- present, or we have decided that there must be a missing left paren)
302 else
303 Association_List := New_List;
304 T_Left_Paren;
306 loop
307 Append (P_Generic_Association, Association_List);
308 exit when not Comma_Present;
309 end loop;
311 T_Right_Paren;
312 return Association_List;
313 end if;
315 end P_Generic_Actual_Part_Opt;
317 -------------------------------
318 -- 12.3 Generic Association --
319 -------------------------------
321 -- GENERIC_ASSOCIATION ::=
322 -- [generic_formal_parameter_SELECTOR_NAME =>]
323 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER
325 -- EXPLICIT_GENERIC_ACTUAL_PARAMETER ::=
326 -- EXPRESSION | variable_NAME | subprogram_NAME
327 -- | entry_NAME | SUBTYPE_MARK | package_instance_NAME
329 -- Error recovery: cannot raise Error_Resync
331 function P_Generic_Association return Node_Id is
332 Scan_State : Saved_Scan_State;
333 Param_Name_Node : Node_Id;
334 Generic_Assoc_Node : Node_Id;
336 begin
337 Generic_Assoc_Node := New_Node (N_Generic_Association, Token_Ptr);
339 -- Ada2005: an association can be given by: others => <>
341 if Token = Tok_Others then
342 if Ada_Version < Ada_2005 then
343 Error_Msg_SP
344 ("partial parametrization of formal packages" &
345 " is an Ada 2005 extension");
346 Error_Msg_SP
347 ("\unit must be compiled with -gnat05 switch");
348 end if;
350 Scan; -- past OTHERS
352 if Token /= Tok_Arrow then
353 Error_Msg_BC ("expect arrow after others");
354 else
355 Scan; -- past arrow
356 end if;
358 if Token /= Tok_Box then
359 Error_Msg_BC ("expect Box after arrow");
360 else
361 Scan; -- past box
362 end if;
364 -- Source position of the others choice is beginning of construct
366 return New_Node (N_Others_Choice, Sloc (Generic_Assoc_Node));
367 end if;
369 if Token in Token_Class_Desig then
370 Param_Name_Node := Token_Node;
371 Save_Scan_State (Scan_State); -- at designator
372 Scan; -- past simple name or operator symbol
374 if Token = Tok_Arrow then
375 Scan; -- past arrow
376 Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
377 else
378 Restore_Scan_State (Scan_State); -- to designator
379 end if;
380 end if;
382 -- In Ada 2005 the actual can be a box
384 if Token = Tok_Box then
385 Scan;
386 Set_Box_Present (Generic_Assoc_Node);
387 Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, Empty);
389 else
390 Set_Explicit_Generic_Actual_Parameter
391 (Generic_Assoc_Node, P_Expression);
392 end if;
394 return Generic_Assoc_Node;
395 end P_Generic_Association;
397 ---------------------------------------------
398 -- 12.3 Explicit Generic Actual Parameter --
399 ---------------------------------------------
401 -- Parsed by P_Generic_Association (12.3)
403 --------------------------------------
404 -- 12.4 Formal Object Declarations --
405 --------------------------------------
407 -- FORMAL_OBJECT_DECLARATION ::=
408 -- DEFINING_IDENTIFIER_LIST :
409 -- MODE [NULL_EXCLUSION] SUBTYPE_MARK [:= DEFAULT_EXPRESSION]
410 -- [ASPECT_SPECIFICATIONS];
411 -- | DEFINING_IDENTIFIER_LIST :
412 -- MODE ACCESS_DEFINITION [:= DEFAULT_EXPRESSION];
413 -- [ASPECT_SPECIFICATIONS];
415 -- The caller has checked that the initial token is an identifier
417 -- Error recovery: cannot raise Error_Resync
419 procedure P_Formal_Object_Declarations (Decls : List_Id) is
420 Decl_Node : Node_Id;
421 Ident : Nat;
422 Not_Null_Present : Boolean := False;
423 Num_Idents : Nat;
424 Scan_State : Saved_Scan_State;
426 Idents : array (Int range 1 .. 4096) of Entity_Id;
427 -- This array holds the list of defining identifiers. The upper bound
428 -- of 4096 is intended to be essentially infinite, and we do not even
429 -- bother to check for it being exceeded.
431 begin
432 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
433 Num_Idents := 1;
434 while Comma_Present loop
435 Num_Idents := Num_Idents + 1;
436 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
437 end loop;
439 T_Colon;
441 -- If there are multiple identifiers, we repeatedly scan the
442 -- type and initialization expression information by resetting
443 -- the scan pointer (so that we get completely separate trees
444 -- for each occurrence).
446 if Num_Idents > 1 then
447 Save_Scan_State (Scan_State);
448 end if;
450 -- Loop through defining identifiers in list
452 Ident := 1;
453 Ident_Loop : loop
454 Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
455 Set_Defining_Identifier (Decl_Node, Idents (Ident));
456 P_Mode (Decl_Node);
458 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-423)
460 -- Ada 2005 (AI-423): Formal object with an access definition
462 if Token = Tok_Access then
464 -- The access definition is still parsed and set even though
465 -- the compilation may not use the proper switch. This action
466 -- ensures the required local error recovery.
468 Set_Access_Definition (Decl_Node,
469 P_Access_Definition (Not_Null_Present));
471 if Ada_Version < Ada_2005 then
472 Error_Msg_SP
473 ("access definition not allowed in formal object " &
474 "declaration");
475 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
476 end if;
478 -- Formal object with a subtype mark
480 else
481 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
482 Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
483 end if;
485 No_Constraint;
486 Set_Default_Expression (Decl_Node, Init_Expr_Opt);
487 P_Aspect_Specifications (Decl_Node);
489 if Ident > 1 then
490 Set_Prev_Ids (Decl_Node, True);
491 end if;
493 if Ident < Num_Idents then
494 Set_More_Ids (Decl_Node, True);
495 end if;
497 Append (Decl_Node, Decls);
499 exit Ident_Loop when Ident = Num_Idents;
500 Ident := Ident + 1;
501 Restore_Scan_State (Scan_State);
502 end loop Ident_Loop;
503 end P_Formal_Object_Declarations;
505 -----------------------------------
506 -- 12.5 Formal Type Declaration --
507 -----------------------------------
509 -- FORMAL_TYPE_DECLARATION ::=
510 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
511 -- is FORMAL_TYPE_DEFINITION
512 -- [ASPECT_SPECIFICATIONS];
514 -- The caller has checked that the initial token is TYPE
516 -- Error recovery: cannot raise Error_Resync
518 function P_Formal_Type_Declaration return Node_Id is
519 Decl_Node : Node_Id;
520 Def_Node : Node_Id;
522 begin
523 Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
524 Scan; -- past TYPE
525 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier);
527 if P_Unknown_Discriminant_Part_Opt then
528 Set_Unknown_Discriminants_Present (Decl_Node, True);
529 else
530 Set_Discriminant_Specifications
531 (Decl_Node, P_Known_Discriminant_Part_Opt);
532 end if;
534 T_Is;
536 Def_Node := P_Formal_Type_Definition;
538 if Def_Node /= Error then
539 Set_Formal_Type_Definition (Decl_Node, Def_Node);
540 P_Aspect_Specifications (Decl_Node);
542 else
543 Decl_Node := Error;
545 -- If we have aspect specifications, skip them
547 if Aspect_Specifications_Present then
548 P_Aspect_Specifications (Error);
550 -- If we have semicolon, skip it to avoid cascaded errors
552 elsif Token = Tok_Semicolon then
553 Scan; -- past semicolon
554 end if;
555 end if;
557 return Decl_Node;
558 end P_Formal_Type_Declaration;
560 ----------------------------------
561 -- 12.5 Formal Type Definition --
562 ----------------------------------
564 -- FORMAL_TYPE_DEFINITION ::=
565 -- FORMAL_PRIVATE_TYPE_DEFINITION
566 -- | FORMAL_DERIVED_TYPE_DEFINITION
567 -- | FORMAL_DISCRETE_TYPE_DEFINITION
568 -- | FORMAL_SIGNED_INTEGER_TYPE_DEFINITION
569 -- | FORMAL_MODULAR_TYPE_DEFINITION
570 -- | FORMAL_FLOATING_POINT_DEFINITION
571 -- | FORMAL_ORDINARY_FIXED_POINT_DEFINITION
572 -- | FORMAL_DECIMAL_FIXED_POINT_DEFINITION
573 -- | FORMAL_ARRAY_TYPE_DEFINITION
574 -- | FORMAL_ACCESS_TYPE_DEFINITION
575 -- | FORMAL_INTERFACE_TYPE_DEFINITION
577 -- FORMAL_ARRAY_TYPE_DEFINITION ::= ARRAY_TYPE_DEFINITION
579 -- FORMAL_ACCESS_TYPE_DEFINITION ::= ACCESS_TYPE_DEFINITION
581 -- FORMAL_INTERFACE_TYPE_DEFINITION ::= INTERFACE_TYPE_DEFINITION
583 function P_Formal_Type_Definition return Node_Id is
584 Scan_State : Saved_Scan_State;
585 Typedef_Node : Node_Id;
587 begin
588 if Token_Name = Name_Abstract then
589 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
590 end if;
592 if Token_Name = Name_Tagged then
593 Check_95_Keyword (Tok_Tagged, Tok_Private);
594 Check_95_Keyword (Tok_Tagged, Tok_Limited);
595 end if;
597 case Token is
599 -- Mostly we can tell what we have from the initial token. The one
600 -- exception is ABSTRACT, where we have to scan ahead to see if we
601 -- have a formal derived type or a formal private type definition.
603 -- In addition, in Ada 2005 LIMITED may appear after abstract, so
604 -- that the lookahead must be extended by one more token.
606 when Tok_Abstract =>
607 Save_Scan_State (Scan_State);
608 Scan; -- past ABSTRACT
610 if Token = Tok_New then
611 Restore_Scan_State (Scan_State); -- to ABSTRACT
612 return P_Formal_Derived_Type_Definition;
614 elsif Token = Tok_Limited then
615 Scan; -- past LIMITED
617 if Token = Tok_New then
618 Restore_Scan_State (Scan_State); -- to ABSTRACT
619 return P_Formal_Derived_Type_Definition;
621 else
622 Restore_Scan_State (Scan_State); -- to ABSTRACT
623 return P_Formal_Private_Type_Definition;
624 end if;
626 -- Ada 2005 (AI-443): Abstract synchronized formal derived type
628 elsif Token = Tok_Synchronized then
629 Restore_Scan_State (Scan_State); -- to ABSTRACT
630 return P_Formal_Derived_Type_Definition;
632 else
633 Restore_Scan_State (Scan_State); -- to ABSTRACT
634 return P_Formal_Private_Type_Definition;
635 end if;
637 when Tok_Access =>
638 return P_Access_Type_Definition;
640 when Tok_Array =>
641 return P_Array_Type_Definition;
643 when Tok_Delta =>
644 return P_Formal_Fixed_Point_Definition;
646 when Tok_Digits =>
647 return P_Formal_Floating_Point_Definition;
649 when Tok_Interface => -- Ada 2005 (AI-251)
650 return P_Interface_Type_Definition (Abstract_Present => False);
652 when Tok_Left_Paren =>
653 return P_Formal_Discrete_Type_Definition;
655 when Tok_Limited =>
656 Save_Scan_State (Scan_State);
657 Scan; -- past LIMITED
659 if Token = Tok_Interface then
660 Typedef_Node :=
661 P_Interface_Type_Definition (Abstract_Present => False);
662 Set_Limited_Present (Typedef_Node);
663 return Typedef_Node;
665 elsif Token = Tok_New then
666 Restore_Scan_State (Scan_State); -- to LIMITED
667 return P_Formal_Derived_Type_Definition;
669 else
670 if Token = Tok_Abstract then
671 Error_Msg_SC -- CODEFIX
672 ("ABSTRACT must come before LIMITED");
673 Scan; -- past improper ABSTRACT
675 if Token = Tok_New then
676 Restore_Scan_State (Scan_State); -- to LIMITED
677 return P_Formal_Derived_Type_Definition;
679 else
680 Restore_Scan_State (Scan_State);
681 return P_Formal_Private_Type_Definition;
682 end if;
683 end if;
685 Restore_Scan_State (Scan_State);
686 return P_Formal_Private_Type_Definition;
687 end if;
689 when Tok_Mod =>
690 return P_Formal_Modular_Type_Definition;
692 when Tok_New =>
693 return P_Formal_Derived_Type_Definition;
695 when Tok_Not =>
696 if P_Null_Exclusion then
697 Typedef_Node := P_Access_Type_Definition;
698 Set_Null_Exclusion_Present (Typedef_Node);
699 return Typedef_Node;
701 else
702 Error_Msg_SC ("expect valid formal access definition!");
703 Resync_Past_Semicolon;
704 return Error;
705 end if;
707 when Tok_Private |
708 Tok_Tagged =>
709 return P_Formal_Private_Type_Definition;
711 when Tok_Range =>
712 return P_Formal_Signed_Integer_Type_Definition;
714 when Tok_Record =>
715 Error_Msg_SC ("record not allowed in generic type definition!");
716 Discard_Junk_Node (P_Record_Definition);
717 return Error;
719 -- Ada 2005 (AI-345): Task, Protected or Synchronized interface or
720 -- (AI-443): Synchronized formal derived type declaration.
722 when Tok_Protected |
723 Tok_Synchronized |
724 Tok_Task =>
726 declare
727 Saved_Token : constant Token_Type := Token;
729 begin
730 Scan; -- past TASK, PROTECTED or SYNCHRONIZED
732 -- Synchronized derived type
734 if Token = Tok_New then
735 Typedef_Node := P_Formal_Derived_Type_Definition;
737 if Saved_Token = Tok_Synchronized then
738 Set_Synchronized_Present (Typedef_Node);
739 else
740 Error_Msg_SC ("invalid kind of formal derived type");
741 end if;
743 -- Interface
745 else
746 Typedef_Node :=
747 P_Interface_Type_Definition (Abstract_Present => False);
749 case Saved_Token is
750 when Tok_Task =>
751 Set_Task_Present (Typedef_Node);
753 when Tok_Protected =>
754 Set_Protected_Present (Typedef_Node);
756 when Tok_Synchronized =>
757 Set_Synchronized_Present (Typedef_Node);
759 when others =>
760 null;
761 end case;
762 end if;
764 return Typedef_Node;
765 end;
767 when others =>
768 Error_Msg_BC ("expecting generic type definition here");
769 Resync_Past_Semicolon;
770 return Error;
772 end case;
773 end P_Formal_Type_Definition;
775 --------------------------------------------
776 -- 12.5.1 Formal Private Type Definition --
777 --------------------------------------------
779 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
780 -- [[abstract] tagged] [limited] private
782 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
783 -- TAGGED or LIMITED
785 -- Error recovery: cannot raise Error_Resync
787 function P_Formal_Private_Type_Definition return Node_Id is
788 Def_Node : Node_Id;
790 begin
791 Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
793 if Token = Tok_Abstract then
794 Scan; -- past ABSTRACT
796 if Token_Name = Name_Tagged then
797 Check_95_Keyword (Tok_Tagged, Tok_Private);
798 Check_95_Keyword (Tok_Tagged, Tok_Limited);
799 end if;
801 if Token /= Tok_Tagged then
802 Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
803 else
804 Set_Abstract_Present (Def_Node, True);
805 end if;
806 end if;
808 if Token = Tok_Tagged then
809 Set_Tagged_Present (Def_Node, True);
810 Scan; -- past TAGGED
811 end if;
813 if Token = Tok_Limited then
814 Set_Limited_Present (Def_Node, True);
815 Scan; -- past LIMITED
816 end if;
818 if Token = Tok_Abstract then
819 if Prev_Token = Tok_Tagged then
820 Error_Msg_SC -- CODEFIX
821 ("ABSTRACT must come before TAGGED");
822 elsif Prev_Token = Tok_Limited then
823 Error_Msg_SC -- CODEFIX
824 ("ABSTRACT must come before LIMITED");
825 end if;
827 Resync_Past_Semicolon;
829 elsif Token = Tok_Tagged then
830 Error_Msg_SC -- CODEFIX
831 ("TAGGED must come before LIMITED");
832 Resync_Past_Semicolon;
833 end if;
835 Set_Sloc (Def_Node, Token_Ptr);
836 T_Private;
838 if Token = Tok_Tagged then -- CODEFIX
839 Error_Msg_SC ("TAGGED must come before PRIVATE");
840 Scan; -- past TAGGED
842 elsif Token = Tok_Abstract then -- CODEFIX
843 Error_Msg_SC ("`ABSTRACT TAGGED` must come before PRIVATE");
844 Scan; -- past ABSTRACT
846 if Token = Tok_Tagged then
847 Scan; -- past TAGGED
848 end if;
849 end if;
851 return Def_Node;
852 end P_Formal_Private_Type_Definition;
854 --------------------------------------------
855 -- 12.5.1 Formal Derived Type Definition --
856 --------------------------------------------
858 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
859 -- [abstract] [limited | synchronized]
860 -- new SUBTYPE_MARK [[and INTERFACE_LIST] with private]
862 -- The caller has checked the initial token(s) is/are NEW, ABSTRACT NEW,
863 -- or LIMITED NEW, ABSTRACT LIMITED NEW, SYNCHRONIZED NEW or ABSTRACT
864 -- SYNCHRONIZED NEW.
866 -- Error recovery: cannot raise Error_Resync
868 function P_Formal_Derived_Type_Definition return Node_Id is
869 Def_Node : Node_Id;
871 begin
872 Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
874 if Token = Tok_Abstract then
875 Set_Abstract_Present (Def_Node);
876 Scan; -- past ABSTRACT
877 end if;
879 if Token = Tok_Limited then
880 Set_Limited_Present (Def_Node);
881 Scan; -- past LIMITED
883 if Ada_Version < Ada_2005 then
884 Error_Msg_SP
885 ("LIMITED in derived type is an Ada 2005 extension");
886 Error_Msg_SP
887 ("\unit must be compiled with -gnat05 switch");
888 end if;
890 elsif Token = Tok_Synchronized then
891 Set_Synchronized_Present (Def_Node);
892 Scan; -- past SYNCHRONIZED
894 if Ada_Version < Ada_2005 then
895 Error_Msg_SP
896 ("SYNCHRONIZED in derived type is an Ada 2005 extension");
897 Error_Msg_SP
898 ("\unit must be compiled with -gnat05 switch");
899 end if;
900 end if;
902 if Token = Tok_Abstract then
903 Scan; -- past ABSTRACT, diagnosed already in caller.
904 end if;
906 Scan; -- past NEW;
907 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
908 No_Constraint;
910 -- Ada 2005 (AI-251): Deal with interfaces
912 if Token = Tok_And then
913 Scan; -- past AND
915 if Ada_Version < Ada_2005 then
916 Error_Msg_SP
917 ("abstract interface is an Ada 2005 extension");
918 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
919 end if;
921 Set_Interface_List (Def_Node, New_List);
923 loop
924 Append (P_Qualified_Simple_Name, Interface_List (Def_Node));
925 exit when Token /= Tok_And;
926 Scan; -- past AND
927 end loop;
928 end if;
930 if Token = Tok_With then
931 Scan; -- past WITH
932 Set_Private_Present (Def_Node, True);
933 T_Private;
935 elsif Token = Tok_Tagged then
936 Scan;
938 if Token = Tok_Private then
939 Error_Msg_SC -- CODEFIX
940 ("TAGGED should be WITH");
941 Set_Private_Present (Def_Node, True);
942 T_Private;
943 else
944 Ignore (Tok_Tagged);
945 end if;
946 end if;
948 return Def_Node;
949 end P_Formal_Derived_Type_Definition;
951 ---------------------------------------------
952 -- 12.5.2 Formal Discrete Type Definition --
953 ---------------------------------------------
955 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
957 -- The caller has checked the initial token is left paren
959 -- Error recovery: cannot raise Error_Resync
961 function P_Formal_Discrete_Type_Definition return Node_Id is
962 Def_Node : Node_Id;
964 begin
965 Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
966 Scan; -- past left paren
967 T_Box;
968 T_Right_Paren;
969 return Def_Node;
970 end P_Formal_Discrete_Type_Definition;
972 ---------------------------------------------------
973 -- 12.5.2 Formal Signed Integer Type Definition --
974 ---------------------------------------------------
976 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
978 -- The caller has checked the initial token is RANGE
980 -- Error recovery: cannot raise Error_Resync
982 function P_Formal_Signed_Integer_Type_Definition return Node_Id is
983 Def_Node : Node_Id;
985 begin
986 Def_Node :=
987 New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
988 Scan; -- past RANGE
989 T_Box;
990 return Def_Node;
991 end P_Formal_Signed_Integer_Type_Definition;
993 --------------------------------------------
994 -- 12.5.2 Formal Modular Type Definition --
995 --------------------------------------------
997 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
999 -- The caller has checked the initial token is MOD
1001 -- Error recovery: cannot raise Error_Resync
1003 function P_Formal_Modular_Type_Definition return Node_Id is
1004 Def_Node : Node_Id;
1006 begin
1007 Def_Node :=
1008 New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
1009 Scan; -- past MOD
1010 T_Box;
1011 return Def_Node;
1012 end P_Formal_Modular_Type_Definition;
1014 ----------------------------------------------
1015 -- 12.5.2 Formal Floating Point Definition --
1016 ----------------------------------------------
1018 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
1020 -- The caller has checked the initial token is DIGITS
1022 -- Error recovery: cannot raise Error_Resync
1024 function P_Formal_Floating_Point_Definition return Node_Id is
1025 Def_Node : Node_Id;
1027 begin
1028 Def_Node :=
1029 New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
1030 Scan; -- past DIGITS
1031 T_Box;
1032 return Def_Node;
1033 end P_Formal_Floating_Point_Definition;
1035 -------------------------------------------
1036 -- 12.5.2 Formal Fixed Point Definition --
1037 -------------------------------------------
1039 -- This routine parses either a formal ordinary fixed point definition
1040 -- or a formal decimal fixed point definition:
1042 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
1044 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
1046 -- The caller has checked the initial token is DELTA
1048 -- Error recovery: cannot raise Error_Resync
1050 function P_Formal_Fixed_Point_Definition return Node_Id is
1051 Def_Node : Node_Id;
1052 Delta_Sloc : Source_Ptr;
1054 begin
1055 Delta_Sloc := Token_Ptr;
1056 Scan; -- past DELTA
1057 T_Box;
1059 if Token = Tok_Digits then
1060 Def_Node :=
1061 New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
1062 Scan; -- past DIGITS
1063 T_Box;
1064 else
1065 Def_Node :=
1066 New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
1067 end if;
1069 return Def_Node;
1070 end P_Formal_Fixed_Point_Definition;
1072 ----------------------------------------------------
1073 -- 12.5.2 Formal Ordinary Fixed Point Definition --
1074 ----------------------------------------------------
1076 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1078 ---------------------------------------------------
1079 -- 12.5.2 Formal Decimal Fixed Point Definition --
1080 ---------------------------------------------------
1082 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1084 ------------------------------------------
1085 -- 12.5.3 Formal Array Type Definition --
1086 ------------------------------------------
1088 -- Parsed by P_Formal_Type_Definition (12.5)
1090 -------------------------------------------
1091 -- 12.5.4 Formal Access Type Definition --
1092 -------------------------------------------
1094 -- Parsed by P_Formal_Type_Definition (12.5)
1096 -----------------------------------------
1097 -- 12.6 Formal Subprogram Declaration --
1098 -----------------------------------------
1100 -- FORMAL_SUBPROGRAM_DECLARATION ::=
1101 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
1102 -- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
1104 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
1105 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT]
1106 -- [ASPECT_SPECIFICATIONS];
1108 -- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
1109 -- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT]
1110 -- [ASPECT_SPECIFICATIONS];
1112 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
1114 -- DEFAULT_NAME ::= NAME | null
1116 -- The caller has checked that the initial tokens are WITH FUNCTION or
1117 -- WITH PROCEDURE, and the initial WITH has been scanned out.
1119 -- A null default is an Ada 2005 feature
1121 -- Error recovery: cannot raise Error_Resync
1123 function P_Formal_Subprogram_Declaration return Node_Id is
1124 Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
1125 Spec_Node : constant Node_Id := P_Subprogram_Specification;
1126 Def_Node : Node_Id;
1128 begin
1129 if Token = Tok_Is then
1130 T_Is; -- past IS, skip extra IS or ";"
1132 if Token = Tok_Abstract then
1133 Def_Node :=
1134 New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
1135 Scan; -- past ABSTRACT
1137 if Ada_Version < Ada_2005 then
1138 Error_Msg_SP
1139 ("formal abstract subprograms are an Ada 2005 extension");
1140 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1141 end if;
1143 else
1144 Def_Node :=
1145 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1146 end if;
1148 Set_Specification (Def_Node, Spec_Node);
1150 if Token = Tok_Semicolon then
1151 null;
1153 elsif Aspect_Specifications_Present then
1154 null;
1156 elsif Token = Tok_Box then
1157 Set_Box_Present (Def_Node, True);
1158 Scan; -- past <>
1160 elsif Token = Tok_Null then
1161 if Ada_Version < Ada_2005 then
1162 Error_Msg_SP
1163 ("null default subprograms are an Ada 2005 extension");
1164 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1165 end if;
1167 if Nkind (Spec_Node) = N_Procedure_Specification then
1168 Set_Null_Present (Spec_Node);
1169 else
1170 Error_Msg_SP ("only procedures can be null");
1171 end if;
1173 Scan; -- past NULL
1175 else
1176 Set_Default_Name (Def_Node, P_Name);
1177 end if;
1179 else
1180 Def_Node :=
1181 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1182 Set_Specification (Def_Node, Spec_Node);
1183 end if;
1185 P_Aspect_Specifications (Def_Node);
1186 return Def_Node;
1187 end P_Formal_Subprogram_Declaration;
1189 ------------------------------
1190 -- 12.6 Subprogram Default --
1191 ------------------------------
1193 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1195 ------------------------
1196 -- 12.6 Default Name --
1197 ------------------------
1199 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1201 --------------------------------------
1202 -- 12.7 Formal Package Declaration --
1203 --------------------------------------
1205 -- FORMAL_PACKAGE_DECLARATION ::=
1206 -- with package DEFINING_IDENTIFIER
1207 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART
1208 -- [ASPECT_SPECIFICATIONS];
1210 -- FORMAL_PACKAGE_ACTUAL_PART ::=
1211 -- ([OTHERS =>] <>) |
1212 -- [GENERIC_ACTUAL_PART]
1213 -- (FORMAL_PACKAGE_ASSOCIATION {, FORMAL_PACKAGE_ASSOCIATION}
1214 -- [, OTHERS => <>)
1216 -- FORMAL_PACKAGE_ASSOCIATION ::=
1217 -- GENERIC_ASSOCIATION
1218 -- | GENERIC_FORMAL_PARAMETER_SELECTOR_NAME => <>
1220 -- The caller has checked that the initial tokens are WITH PACKAGE,
1221 -- and the initial WITH has been scanned out (so Token = Tok_Package).
1223 -- Error recovery: cannot raise Error_Resync
1225 function P_Formal_Package_Declaration return Node_Id is
1226 Def_Node : Node_Id;
1227 Scan_State : Saved_Scan_State;
1229 begin
1230 Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
1231 Scan; -- past PACKAGE
1232 Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
1233 T_Is;
1234 T_New;
1235 Set_Name (Def_Node, P_Qualified_Simple_Name);
1237 if Token = Tok_Left_Paren then
1238 Save_Scan_State (Scan_State); -- at the left paren
1239 Scan; -- past the left paren
1241 if Token = Tok_Box then
1242 Set_Box_Present (Def_Node, True);
1243 Scan; -- past box
1244 T_Right_Paren;
1246 else
1247 Restore_Scan_State (Scan_State); -- to the left paren
1248 Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
1249 end if;
1250 end if;
1252 P_Aspect_Specifications (Def_Node);
1253 return Def_Node;
1254 end P_Formal_Package_Declaration;
1256 --------------------------------------
1257 -- 12.7 Formal Package Actual Part --
1258 --------------------------------------
1260 -- Parsed by P_Formal_Package_Declaration (12.7)
1262 end Ch12;