1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 pragma Style_Checks (All_Checks);
28 -- Turn off subprogram body ordering check. Subprograms are in order
29 -- by RM section rather than alphabetical
34 -- Local functions, used only in this chapter
36 function P_Formal_Derived_Type_Definition return Node_Id;
37 function P_Formal_Discrete_Type_Definition return Node_Id;
38 function P_Formal_Fixed_Point_Definition return Node_Id;
39 function P_Formal_Floating_Point_Definition return Node_Id;
40 function P_Formal_Modular_Type_Definition return Node_Id;
41 function P_Formal_Package_Declaration return Node_Id;
42 function P_Formal_Private_Type_Definition return Node_Id;
43 function P_Formal_Signed_Integer_Type_Definition return Node_Id;
44 function P_Formal_Subprogram_Declaration return Node_Id;
45 function P_Formal_Type_Declaration return Node_Id;
46 function P_Formal_Type_Definition return Node_Id;
47 function P_Generic_Association return Node_Id;
49 procedure P_Formal_Object_Declarations (Decls : List_Id);
50 -- Scans one or more formal object declarations and appends them to
51 -- Decls. Scans more than one declaration only in the case where the
52 -- source has a declaration with multiple defining identifiers.
54 --------------------------------
55 -- 12.1 Generic (also 8.5.5) --
56 --------------------------------
58 -- This routine parses either one of the forms of a generic declaration
59 -- or a generic renaming declaration.
61 -- GENERIC_DECLARATION ::=
62 -- GENERIC_SUBPROGRAM_DECLARATION | GENERIC_PACKAGE_DECLARATION
64 -- GENERIC_SUBPROGRAM_DECLARATION ::=
65 -- GENERIC_FORMAL_PART SUBPROGRAM_SPECIFICATION;
67 -- GENERIC_PACKAGE_DECLARATION ::=
68 -- GENERIC_FORMAL_PART PACKAGE_SPECIFICATION;
70 -- GENERIC_FORMAL_PART ::=
71 -- generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
73 -- GENERIC_RENAMING_DECLARATION ::=
74 -- generic package DEFINING_PROGRAM_UNIT_NAME
75 -- renames generic_package_NAME
76 -- | generic procedure DEFINING_PROGRAM_UNIT_NAME
77 -- renames generic_procedure_NAME
78 -- | generic function DEFINING_PROGRAM_UNIT_NAME
79 -- renames generic_function_NAME
81 -- GENERIC_FORMAL_PARAMETER_DECLARATION ::=
82 -- FORMAL_OBJECT_DECLARATION
83 -- | FORMAL_TYPE_DECLARATION
84 -- | FORMAL_SUBPROGRAM_DECLARATION
85 -- | FORMAL_PACKAGE_DECLARATION
87 -- The caller has checked that the initial token is GENERIC
89 -- Error recovery: can raise Error_Resync
91 function P_Generic return Node_Id is
92 Gen_Sloc : constant Source_Ptr := Token_Ptr;
97 Ren_Token : Token_Type;
98 Scan_State : Saved_Scan_State;
101 Scan; -- past GENERIC
103 if Token = Tok_Private then
104 Error_Msg_SC ("PRIVATE goes before GENERIC, not after");
105 Scan; -- past junk PRIVATE token
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
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);
138 Scan; -- past RENAMES
139 Set_Defining_Unit_Name (Decl_Node, Def_Unit);
140 Set_Name (Decl_Node, P_Name);
147 -- Fall through if this is *not* a generic renaming declaration
149 Restore_Scan_State (Scan_State);
152 -- Loop through generic parameter declarations and use clauses
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
162 if Token = Tok_Use then
163 Append (P_Use_Clause, Decls);
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
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);
184 ("FUNCTION, PROCEDURE or PACKAGE expected here");
185 Resync_Past_Semicolon;
188 elsif Token = Tok_Subtype then
189 Error_Msg_SC ("subtype declaration not allowed " &
190 "as generic parameter declaration!");
191 Resync_Past_Semicolon;
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));
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
214 Error_Msg_SP ("child unit allowed only at library level");
219 Set_Generic_Formal_Declarations (Gen_Decl, Decls);
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;
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
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
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)
299 Association_List := New_List;
303 Append (P_Generic_Association, Association_List);
304 exit when not Comma_Present;
308 return Association_List;
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;
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
340 ("partial parametrization of formal packages" &
341 " is an Ada 2005 extension");
343 ("\unit must be compiled with -gnat05 switch");
348 if Token /= Tok_Arrow then
349 Error_Msg_BC ("expect arrow after others");
354 if Token /= Tok_Box then
355 Error_Msg_BC ("expect Box after arrow");
360 -- Source position of the others choice is beginning of construct
362 return New_Node (N_Others_Choice, Sloc (Generic_Assoc_Node));
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
372 Set_Selector_Name (Generic_Assoc_Node, Param_Name_Node);
374 Restore_Scan_State (Scan_State); -- to designator
378 -- In Ada 2005 the actual can be a box
380 if Token = Tok_Box then
382 Set_Box_Present (Generic_Assoc_Node);
383 Set_Explicit_Generic_Actual_Parameter (Generic_Assoc_Node, Empty);
386 Set_Explicit_Generic_Actual_Parameter
387 (Generic_Assoc_Node, P_Expression);
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
416 Not_Null_Present : Boolean := False;
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.
426 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
429 while Comma_Present loop
430 Num_Idents := Num_Idents + 1;
431 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_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);
445 -- Loop through defining identifiers in list
449 Decl_Node := New_Node (N_Formal_Object_Declaration, Token_Ptr);
450 Set_Defining_Identifier (Decl_Node, Idents (Ident));
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
468 ("access definition not allowed in formal object " &
470 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
473 -- Formal object with a subtype mark
476 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
477 Set_Subtype_Mark (Decl_Node, P_Subtype_Mark_Resync);
481 Set_Default_Expression (Decl_Node, Init_Expr_Opt);
484 Set_Prev_Ids (Decl_Node, True);
487 if Ident < Num_Idents then
488 Set_More_Ids (Decl_Node, True);
491 Append (Decl_Node, Decls);
493 exit Ident_Loop when Ident = Num_Idents;
495 Restore_Scan_State (Scan_State);
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
518 Decl_Node := New_Node (N_Formal_Type_Declaration, Token_Ptr);
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);
525 Set_Discriminant_Specifications
526 (Decl_Node, P_Known_Discriminant_Part_Opt);
531 Def_Node := P_Formal_Type_Definition;
533 if Def_Node /= Error then
534 Set_Formal_Type_Definition (Decl_Node, Def_Node);
540 -- If we have semicolon, skip it to avoid cascaded errors
542 if Token = Tok_Semicolon then
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;
578 if Token_Name = Name_Abstract then
579 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
582 if Token_Name = Name_Tagged then
583 Check_95_Keyword (Tok_Tagged, Tok_Private);
584 Check_95_Keyword (Tok_Tagged, Tok_Limited);
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.
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;
612 Restore_Scan_State (Scan_State); -- to ABSTRACT
613 return P_Formal_Private_Type_Definition;
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;
623 Restore_Scan_State (Scan_State); -- to ABSTRACT
624 return P_Formal_Private_Type_Definition;
628 return P_Access_Type_Definition;
631 return P_Array_Type_Definition;
634 return P_Formal_Fixed_Point_Definition;
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;
646 Save_Scan_State (Scan_State);
647 Scan; -- past LIMITED
649 if Token = Tok_Interface then
651 P_Interface_Type_Definition (Abstract_Present => False);
652 Set_Limited_Present (Typedef_Node);
655 elsif Token = Tok_New then
656 Restore_Scan_State (Scan_State); -- to LIMITED
657 return P_Formal_Derived_Type_Definition;
660 if Token = Tok_Abstract then
661 Error_Msg_SC ("ABSTRACT must come before LIMITED");
662 Scan; -- past improper ABSTRACT
664 if Token = Tok_New then
665 Restore_Scan_State (Scan_State); -- to LIMITED
666 return P_Formal_Derived_Type_Definition;
669 Restore_Scan_State (Scan_State);
670 return P_Formal_Private_Type_Definition;
674 Restore_Scan_State (Scan_State);
675 return P_Formal_Private_Type_Definition;
679 return P_Formal_Modular_Type_Definition;
682 return P_Formal_Derived_Type_Definition;
685 if P_Null_Exclusion then
686 Typedef_Node := P_Access_Type_Definition;
687 Set_Null_Exclusion_Present (Typedef_Node);
691 Error_Msg_SC ("expect valid formal access definition!");
692 Resync_Past_Semicolon;
698 return P_Formal_Private_Type_Definition;
701 return P_Formal_Signed_Integer_Type_Definition;
704 Error_Msg_SC ("record not allowed in generic type definition!");
705 Discard_Junk_Node (P_Record_Definition);
708 -- Ada 2005 (AI-345): Task, Protected or Synchronized interface or
709 -- (AI-443): Synchronized formal derived type declaration.
716 Saved_Token : constant Token_Type := Token;
719 Scan; -- past TASK, PROTECTED or SYNCHRONIZED
721 -- Synchronized derived type
723 if Token = Tok_New then
724 Typedef_Node := P_Formal_Derived_Type_Definition;
726 if Saved_Token = Tok_Synchronized then
727 Set_Synchronized_Present (Typedef_Node);
729 Error_Msg_SC ("invalid kind of formal derived type");
736 P_Interface_Type_Definition (Abstract_Present => False);
740 Set_Task_Present (Typedef_Node);
742 when Tok_Protected =>
743 Set_Protected_Present (Typedef_Node);
745 when Tok_Synchronized =>
746 Set_Synchronized_Present (Typedef_Node);
757 Error_Msg_BC ("expecting generic type definition here");
758 Resync_Past_Semicolon;
762 end P_Formal_Type_Definition;
764 --------------------------------------------
765 -- 12.5.1 Formal Private Type Definition --
766 --------------------------------------------
768 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
769 -- [[abstract] tagged] [limited] private
771 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
774 -- Error recovery: cannot raise Error_Resync
776 function P_Formal_Private_Type_Definition return Node_Id is
780 Def_Node := New_Node (N_Formal_Private_Type_Definition, Token_Ptr);
782 if Token = Tok_Abstract then
783 Scan; -- past ABSTRACT
785 if Token_Name = Name_Tagged then
786 Check_95_Keyword (Tok_Tagged, Tok_Private);
787 Check_95_Keyword (Tok_Tagged, Tok_Limited);
790 if Token /= Tok_Tagged then
791 Error_Msg_SP ("ABSTRACT must be followed by TAGGED");
793 Set_Abstract_Present (Def_Node, True);
797 if Token = Tok_Tagged then
798 Set_Tagged_Present (Def_Node, True);
802 if Token = Tok_Limited then
803 Set_Limited_Present (Def_Node, True);
804 Scan; -- past LIMITED
807 if Token = Tok_Abstract then
808 if Prev_Token = Tok_Tagged then
809 Error_Msg_SC ("ABSTRACT must come before TAGGED");
810 elsif Prev_Token = Tok_Limited then
811 Error_Msg_SC ("ABSTRACT must come before LIMITED");
814 Resync_Past_Semicolon;
816 elsif Token = Tok_Tagged then
817 Error_Msg_SC ("TAGGED must come before LIMITED");
818 Resync_Past_Semicolon;
821 Set_Sloc (Def_Node, Token_Ptr);
824 end P_Formal_Private_Type_Definition;
826 --------------------------------------------
827 -- 12.5.1 Formal Derived Type Definition --
828 --------------------------------------------
830 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
831 -- [abstract] [limited | synchronized]
832 -- new SUBTYPE_MARK [[and INTERFACE_LIST] with private]
834 -- The caller has checked the initial token(s) is/are NEW, ASTRACT NEW,
835 -- or LIMITED NEW, ABSTRACT LIMITED NEW, SYNCHRONIZED NEW or ABSTRACT
838 -- Error recovery: cannot raise Error_Resync
840 function P_Formal_Derived_Type_Definition return Node_Id is
844 Def_Node := New_Node (N_Formal_Derived_Type_Definition, Token_Ptr);
846 if Token = Tok_Abstract then
847 Set_Abstract_Present (Def_Node);
848 Scan; -- past ABSTRACT
851 if Token = Tok_Limited then
852 Set_Limited_Present (Def_Node);
853 Scan; -- past LIMITED
855 if Ada_Version < Ada_05 then
857 ("LIMITED in derived type is an Ada 2005 extension");
859 ("\unit must be compiled with -gnat05 switch");
862 elsif Token = Tok_Synchronized then
863 Set_Synchronized_Present (Def_Node);
864 Scan; -- past SYNCHRONIZED
866 if Ada_Version < Ada_05 then
868 ("SYNCHRONIZED in derived type is an Ada 2005 extension");
870 ("\unit must be compiled with -gnat05 switch");
874 if Token = Tok_Abstract then
875 Scan; -- past ABSTRACT, diagnosed already in caller.
879 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
882 -- Ada 2005 (AI-251): Deal with interfaces
884 if Token = Tok_And then
887 if Ada_Version < Ada_05 then
889 ("abstract interface is an Ada 2005 extension");
890 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
893 Set_Interface_List (Def_Node, New_List);
896 Append (P_Qualified_Simple_Name, Interface_List (Def_Node));
897 exit when Token /= Tok_And;
902 if Token = Tok_With then
904 Set_Private_Present (Def_Node, True);
907 elsif Token = Tok_Tagged then
910 if Token = Tok_Private then
911 Error_Msg_SC ("TAGGED should be WITH");
912 Set_Private_Present (Def_Node, True);
920 end P_Formal_Derived_Type_Definition;
922 ---------------------------------------------
923 -- 12.5.2 Formal Discrete Type Definition --
924 ---------------------------------------------
926 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
928 -- The caller has checked the initial token is left paren
930 -- Error recovery: cannot raise Error_Resync
932 function P_Formal_Discrete_Type_Definition return Node_Id is
936 Def_Node := New_Node (N_Formal_Discrete_Type_Definition, Token_Ptr);
937 Scan; -- past left paren
941 end P_Formal_Discrete_Type_Definition;
943 ---------------------------------------------------
944 -- 12.5.2 Formal Signed Integer Type Definition --
945 ---------------------------------------------------
947 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
949 -- The caller has checked the initial token is RANGE
951 -- Error recovery: cannot raise Error_Resync
953 function P_Formal_Signed_Integer_Type_Definition return Node_Id is
958 New_Node (N_Formal_Signed_Integer_Type_Definition, Token_Ptr);
962 end P_Formal_Signed_Integer_Type_Definition;
964 --------------------------------------------
965 -- 12.5.2 Formal Modular Type Definition --
966 --------------------------------------------
968 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
970 -- The caller has checked the initial token is MOD
972 -- Error recovery: cannot raise Error_Resync
974 function P_Formal_Modular_Type_Definition return Node_Id is
979 New_Node (N_Formal_Modular_Type_Definition, Token_Ptr);
983 end P_Formal_Modular_Type_Definition;
985 ----------------------------------------------
986 -- 12.5.2 Formal Floating Point Definition --
987 ----------------------------------------------
989 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
991 -- The caller has checked the initial token is DIGITS
993 -- Error recovery: cannot raise Error_Resync
995 function P_Formal_Floating_Point_Definition return Node_Id is
1000 New_Node (N_Formal_Floating_Point_Definition, Token_Ptr);
1001 Scan; -- past DIGITS
1004 end P_Formal_Floating_Point_Definition;
1006 -------------------------------------------
1007 -- 12.5.2 Formal Fixed Point Definition --
1008 -------------------------------------------
1010 -- This routine parses either a formal ordinary fixed point definition
1011 -- or a formal decimal fixed point definition:
1013 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
1015 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
1017 -- The caller has checked the initial token is DELTA
1019 -- Error recovery: cannot raise Error_Resync
1021 function P_Formal_Fixed_Point_Definition return Node_Id is
1023 Delta_Sloc : Source_Ptr;
1026 Delta_Sloc := Token_Ptr;
1030 if Token = Tok_Digits then
1032 New_Node (N_Formal_Decimal_Fixed_Point_Definition, Delta_Sloc);
1033 Scan; -- past DIGITS
1037 New_Node (N_Formal_Ordinary_Fixed_Point_Definition, Delta_Sloc);
1041 end P_Formal_Fixed_Point_Definition;
1043 ----------------------------------------------------
1044 -- 12.5.2 Formal Ordinary Fixed Point Definition --
1045 ----------------------------------------------------
1047 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1049 ---------------------------------------------------
1050 -- 12.5.2 Formal Decimal Fixed Point Definition --
1051 ---------------------------------------------------
1053 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1055 ------------------------------------------
1056 -- 12.5.3 Formal Array Type Definition --
1057 ------------------------------------------
1059 -- Parsed by P_Formal_Type_Definition (12.5)
1061 -------------------------------------------
1062 -- 12.5.4 Formal Access Type Definition --
1063 -------------------------------------------
1065 -- Parsed by P_Formal_Type_Definition (12.5)
1067 -----------------------------------------
1068 -- 12.6 Formal Subprogram Declaration --
1069 -----------------------------------------
1071 -- FORMAL_SUBPROGRAM_DECLARATION ::=
1072 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
1073 -- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
1075 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
1076 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
1078 -- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
1079 -- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT];
1081 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
1083 -- DEFAULT_NAME ::= NAME | null
1085 -- The caller has checked that the initial tokens are WITH FUNCTION or
1086 -- WITH PROCEDURE, and the initial WITH has been scanned out.
1088 -- A null default is an Ada 2005 feature
1090 -- Error recovery: cannot raise Error_Resync
1092 function P_Formal_Subprogram_Declaration return Node_Id is
1093 Prev_Sloc : constant Source_Ptr := Prev_Token_Ptr;
1094 Spec_Node : constant Node_Id := P_Subprogram_Specification;
1098 if Token = Tok_Is then
1099 T_Is; -- past IS, skip extra IS or ";"
1101 if Token = Tok_Abstract then
1103 New_Node (N_Formal_Abstract_Subprogram_Declaration, Prev_Sloc);
1104 Scan; -- past ABSTRACT
1106 if Ada_Version < Ada_05 then
1108 ("formal abstract subprograms are an Ada 2005 extension");
1109 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1114 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1117 Set_Specification (Def_Node, Spec_Node);
1119 if Token = Tok_Semicolon then
1122 elsif Token = Tok_Box then
1123 Set_Box_Present (Def_Node, True);
1127 elsif Token = Tok_Null then
1128 if Ada_Version < Ada_05 then
1130 ("null default subprograms are an Ada 2005 extension");
1131 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1134 if Nkind (Spec_Node) = N_Procedure_Specification then
1135 Set_Null_Present (Spec_Node);
1137 Error_Msg_SP ("only procedures can be null");
1144 Set_Default_Name (Def_Node, P_Name);
1150 New_Node (N_Formal_Concrete_Subprogram_Declaration, Prev_Sloc);
1151 Set_Specification (Def_Node, Spec_Node);
1156 end P_Formal_Subprogram_Declaration;
1158 ------------------------------
1159 -- 12.6 Subprogram Default --
1160 ------------------------------
1162 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1164 ------------------------
1165 -- 12.6 Default Name --
1166 ------------------------
1168 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1170 --------------------------------------
1171 -- 12.7 Formal Package Declaration --
1172 --------------------------------------
1174 -- FORMAL_PACKAGE_DECLARATION ::=
1175 -- with package DEFINING_IDENTIFIER
1176 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
1178 -- FORMAL_PACKAGE_ACTUAL_PART ::=
1179 -- ([OTHERS =>] <>) |
1180 -- [GENERIC_ACTUAL_PART]
1181 -- (FORMAL_PACKAGE_ASSOCIATION {, FORMAL_PACKAGE_ASSOCIATION}
1184 -- FORMAL_PACKAGE_ASSOCIATION ::=
1185 -- GENERIC_ASSOCIATION
1186 -- | GENERIC_FORMAL_PARAMETER_SELECTOR_NAME => <>
1188 -- The caller has checked that the initial tokens are WITH PACKAGE,
1189 -- and the initial WITH has been scanned out (so Token = Tok_Package).
1191 -- Error recovery: cannot raise Error_Resync
1193 function P_Formal_Package_Declaration return Node_Id is
1195 Scan_State : Saved_Scan_State;
1198 Def_Node := New_Node (N_Formal_Package_Declaration, Prev_Token_Ptr);
1199 Scan; -- past PACKAGE
1200 Set_Defining_Identifier (Def_Node, P_Defining_Identifier (C_Is));
1203 Set_Name (Def_Node, P_Qualified_Simple_Name);
1205 if Token = Tok_Left_Paren then
1206 Save_Scan_State (Scan_State); -- at the left paren
1207 Scan; -- past the left paren
1209 if Token = Tok_Box then
1210 Set_Box_Present (Def_Node, True);
1215 Restore_Scan_State (Scan_State); -- to the left paren
1216 Set_Generic_Associations (Def_Node, P_Generic_Actual_Part_Opt);
1222 end P_Formal_Package_Declaration;
1224 --------------------------------------
1225 -- 12.7 Formal Package Actual Part --
1226 --------------------------------------
1228 -- Parsed by P_Formal_Package_Declaration (12.7)