1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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
33 -- Local functions, used only in this chapter
35 function P_Formal_Derived_Type_Definition
return Node_Id
;
36 function P_Formal_Discrete_Type_Definition
return Node_Id
;
37 function P_Formal_Fixed_Point_Definition
return Node_Id
;
38 function P_Formal_Floating_Point_Definition
return Node_Id
;
39 function P_Formal_Modular_Type_Definition
return Node_Id
;
40 function P_Formal_Package_Declaration
return Node_Id
;
41 function P_Formal_Private_Type_Definition
return Node_Id
;
42 function P_Formal_Signed_Integer_Type_Definition
return Node_Id
;
43 function P_Formal_Subprogram_Declaration
return Node_Id
;
44 function P_Formal_Type_Declaration
return Node_Id
;
45 function P_Formal_Type_Definition
return Node_Id
;
46 function P_Generic_Association
return Node_Id
;
48 procedure P_Formal_Object_Declarations
(Decls
: List_Id
);
49 -- Scans one or more formal object declarations and appends them to
50 -- Decls. Scans more than one declaration only in the case where the
51 -- source has a declaration with multiple defining identifiers.
53 --------------------------------
54 -- 12.1 Generic (also 8.5.5) --
55 --------------------------------
57 -- This routine parses either one of the forms of a generic declaration
58 -- or a generic renaming declaration.
60 -- GENERIC_DECLARATION ::=
61 -- GENERIC_SUBPROGRAM_DECLARATION | GENERIC_PACKAGE_DECLARATION
63 -- GENERIC_SUBPROGRAM_DECLARATION ::=
64 -- GENERIC_FORMAL_PART SUBPROGRAM_SPECIFICATION;
66 -- GENERIC_PACKAGE_DECLARATION ::=
67 -- GENERIC_FORMAL_PART PACKAGE_SPECIFICATION;
69 -- GENERIC_FORMAL_PART ::=
70 -- generic {GENERIC_FORMAL_PARAMETER_DECLARATION | USE_CLAUSE}
72 -- GENERIC_RENAMING_DECLARATION ::=
73 -- generic package DEFINING_PROGRAM_UNIT_NAME
74 -- renames generic_package_NAME
75 -- | generic procedure DEFINING_PROGRAM_UNIT_NAME
76 -- renames generic_procedure_NAME
77 -- | generic function DEFINING_PROGRAM_UNIT_NAME
78 -- renames generic_function_NAME
80 -- GENERIC_FORMAL_PARAMETER_DECLARATION ::=
81 -- FORMAL_OBJECT_DECLARATION
82 -- | FORMAL_TYPE_DECLARATION
83 -- | FORMAL_SUBPROGRAM_DECLARATION
84 -- | FORMAL_PACKAGE_DECLARATION
86 -- The caller has checked that the initial token is GENERIC
88 -- Error recovery: can raise Error_Resync
90 function P_Generic
return Node_Id
is
91 Gen_Sloc
: constant Source_Ptr
:= Token_Ptr
;
96 Ren_Token
: Token_Type
;
97 Scan_State
: Saved_Scan_State
;
100 Scan
; -- past GENERIC
102 if Token
= Tok_Private
then
103 Error_Msg_SC
-- CODEFIX
104 ("PRIVATE goes before GENERIC, not after");
105 Scan
; -- past junk PRIVATE token
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
);
183 Error_Msg_BC
-- CODEFIX
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
-- CODEFIX
662 ("ABSTRACT must come before LIMITED");
663 Scan
; -- past improper ABSTRACT
665 if Token
= Tok_New
then
666 Restore_Scan_State
(Scan_State
); -- to LIMITED
667 return P_Formal_Derived_Type_Definition
;
670 Restore_Scan_State
(Scan_State
);
671 return P_Formal_Private_Type_Definition
;
675 Restore_Scan_State
(Scan_State
);
676 return P_Formal_Private_Type_Definition
;
680 return P_Formal_Modular_Type_Definition
;
683 return P_Formal_Derived_Type_Definition
;
686 if P_Null_Exclusion
then
687 Typedef_Node
:= P_Access_Type_Definition
;
688 Set_Null_Exclusion_Present
(Typedef_Node
);
692 Error_Msg_SC
("expect valid formal access definition!");
693 Resync_Past_Semicolon
;
699 return P_Formal_Private_Type_Definition
;
702 return P_Formal_Signed_Integer_Type_Definition
;
705 Error_Msg_SC
("record not allowed in generic type definition!");
706 Discard_Junk_Node
(P_Record_Definition
);
709 -- Ada 2005 (AI-345): Task, Protected or Synchronized interface or
710 -- (AI-443): Synchronized formal derived type declaration.
717 Saved_Token
: constant Token_Type
:= Token
;
720 Scan
; -- past TASK, PROTECTED or SYNCHRONIZED
722 -- Synchronized derived type
724 if Token
= Tok_New
then
725 Typedef_Node
:= P_Formal_Derived_Type_Definition
;
727 if Saved_Token
= Tok_Synchronized
then
728 Set_Synchronized_Present
(Typedef_Node
);
730 Error_Msg_SC
("invalid kind of formal derived type");
737 P_Interface_Type_Definition
(Abstract_Present
=> False);
741 Set_Task_Present
(Typedef_Node
);
743 when Tok_Protected
=>
744 Set_Protected_Present
(Typedef_Node
);
746 when Tok_Synchronized
=>
747 Set_Synchronized_Present
(Typedef_Node
);
758 Error_Msg_BC
("expecting generic type definition here");
759 Resync_Past_Semicolon
;
763 end P_Formal_Type_Definition
;
765 --------------------------------------------
766 -- 12.5.1 Formal Private Type Definition --
767 --------------------------------------------
769 -- FORMAL_PRIVATE_TYPE_DEFINITION ::=
770 -- [[abstract] tagged] [limited] private
772 -- The caller has checked the initial token is PRIVATE, ABSTRACT,
775 -- Error recovery: cannot raise Error_Resync
777 function P_Formal_Private_Type_Definition
return Node_Id
is
781 Def_Node
:= New_Node
(N_Formal_Private_Type_Definition
, Token_Ptr
);
783 if Token
= Tok_Abstract
then
784 Scan
; -- past ABSTRACT
786 if Token_Name
= Name_Tagged
then
787 Check_95_Keyword
(Tok_Tagged
, Tok_Private
);
788 Check_95_Keyword
(Tok_Tagged
, Tok_Limited
);
791 if Token
/= Tok_Tagged
then
792 Error_Msg_SP
("ABSTRACT must be followed by TAGGED");
794 Set_Abstract_Present
(Def_Node
, True);
798 if Token
= Tok_Tagged
then
799 Set_Tagged_Present
(Def_Node
, True);
803 if Token
= Tok_Limited
then
804 Set_Limited_Present
(Def_Node
, True);
805 Scan
; -- past LIMITED
808 if Token
= Tok_Abstract
then
809 if Prev_Token
= Tok_Tagged
then
810 Error_Msg_SC
-- CODEFIX
811 ("ABSTRACT must come before TAGGED");
812 elsif Prev_Token
= Tok_Limited
then
813 Error_Msg_SC
-- CODEFIX
814 ("ABSTRACT must come before LIMITED");
817 Resync_Past_Semicolon
;
819 elsif Token
= Tok_Tagged
then
820 Error_Msg_SC
-- CODEFIX
821 ("TAGGED must come before LIMITED");
822 Resync_Past_Semicolon
;
825 Set_Sloc
(Def_Node
, Token_Ptr
);
828 end P_Formal_Private_Type_Definition
;
830 --------------------------------------------
831 -- 12.5.1 Formal Derived Type Definition --
832 --------------------------------------------
834 -- FORMAL_DERIVED_TYPE_DEFINITION ::=
835 -- [abstract] [limited | synchronized]
836 -- new SUBTYPE_MARK [[and INTERFACE_LIST] with private]
838 -- The caller has checked the initial token(s) is/are NEW, ABSTRACT NEW,
839 -- or LIMITED NEW, ABSTRACT LIMITED NEW, SYNCHRONIZED NEW or ABSTRACT
842 -- Error recovery: cannot raise Error_Resync
844 function P_Formal_Derived_Type_Definition
return Node_Id
is
848 Def_Node
:= New_Node
(N_Formal_Derived_Type_Definition
, Token_Ptr
);
850 if Token
= Tok_Abstract
then
851 Set_Abstract_Present
(Def_Node
);
852 Scan
; -- past ABSTRACT
855 if Token
= Tok_Limited
then
856 Set_Limited_Present
(Def_Node
);
857 Scan
; -- past LIMITED
859 if Ada_Version
< Ada_05
then
861 ("LIMITED in derived type is an Ada 2005 extension");
863 ("\unit must be compiled with -gnat05 switch");
866 elsif Token
= Tok_Synchronized
then
867 Set_Synchronized_Present
(Def_Node
);
868 Scan
; -- past SYNCHRONIZED
870 if Ada_Version
< Ada_05
then
872 ("SYNCHRONIZED in derived type is an Ada 2005 extension");
874 ("\unit must be compiled with -gnat05 switch");
878 if Token
= Tok_Abstract
then
879 Scan
; -- past ABSTRACT, diagnosed already in caller.
883 Set_Subtype_Mark
(Def_Node
, P_Subtype_Mark
);
886 -- Ada 2005 (AI-251): Deal with interfaces
888 if Token
= Tok_And
then
891 if Ada_Version
< Ada_05
then
893 ("abstract interface is an Ada 2005 extension");
894 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
897 Set_Interface_List
(Def_Node
, New_List
);
900 Append
(P_Qualified_Simple_Name
, Interface_List
(Def_Node
));
901 exit when Token
/= Tok_And
;
906 if Token
= Tok_With
then
908 Set_Private_Present
(Def_Node
, True);
911 elsif Token
= Tok_Tagged
then
914 if Token
= Tok_Private
then
915 Error_Msg_SC
-- CODEFIX
916 ("TAGGED should be WITH");
917 Set_Private_Present
(Def_Node
, True);
925 end P_Formal_Derived_Type_Definition
;
927 ---------------------------------------------
928 -- 12.5.2 Formal Discrete Type Definition --
929 ---------------------------------------------
931 -- FORMAL_DISCRETE_TYPE_DEFINITION ::= (<>)
933 -- The caller has checked the initial token is left paren
935 -- Error recovery: cannot raise Error_Resync
937 function P_Formal_Discrete_Type_Definition
return Node_Id
is
941 Def_Node
:= New_Node
(N_Formal_Discrete_Type_Definition
, Token_Ptr
);
942 Scan
; -- past left paren
946 end P_Formal_Discrete_Type_Definition
;
948 ---------------------------------------------------
949 -- 12.5.2 Formal Signed Integer Type Definition --
950 ---------------------------------------------------
952 -- FORMAL_SIGNED_INTEGER_TYPE_DEFINITION ::= range <>
954 -- The caller has checked the initial token is RANGE
956 -- Error recovery: cannot raise Error_Resync
958 function P_Formal_Signed_Integer_Type_Definition
return Node_Id
is
963 New_Node
(N_Formal_Signed_Integer_Type_Definition
, Token_Ptr
);
967 end P_Formal_Signed_Integer_Type_Definition
;
969 --------------------------------------------
970 -- 12.5.2 Formal Modular Type Definition --
971 --------------------------------------------
973 -- FORMAL_MODULAR_TYPE_DEFINITION ::= mod <>
975 -- The caller has checked the initial token is MOD
977 -- Error recovery: cannot raise Error_Resync
979 function P_Formal_Modular_Type_Definition
return Node_Id
is
984 New_Node
(N_Formal_Modular_Type_Definition
, Token_Ptr
);
988 end P_Formal_Modular_Type_Definition
;
990 ----------------------------------------------
991 -- 12.5.2 Formal Floating Point Definition --
992 ----------------------------------------------
994 -- FORMAL_FLOATING_POINT_DEFINITION ::= digits <>
996 -- The caller has checked the initial token is DIGITS
998 -- Error recovery: cannot raise Error_Resync
1000 function P_Formal_Floating_Point_Definition
return Node_Id
is
1005 New_Node
(N_Formal_Floating_Point_Definition
, Token_Ptr
);
1006 Scan
; -- past DIGITS
1009 end P_Formal_Floating_Point_Definition
;
1011 -------------------------------------------
1012 -- 12.5.2 Formal Fixed Point Definition --
1013 -------------------------------------------
1015 -- This routine parses either a formal ordinary fixed point definition
1016 -- or a formal decimal fixed point definition:
1018 -- FORMAL_ORDINARY_FIXED_POINT_DEFINITION ::= delta <>
1020 -- FORMAL_DECIMAL_FIXED_POINT_DEFINITION ::= delta <> digits <>
1022 -- The caller has checked the initial token is DELTA
1024 -- Error recovery: cannot raise Error_Resync
1026 function P_Formal_Fixed_Point_Definition
return Node_Id
is
1028 Delta_Sloc
: Source_Ptr
;
1031 Delta_Sloc
:= Token_Ptr
;
1035 if Token
= Tok_Digits
then
1037 New_Node
(N_Formal_Decimal_Fixed_Point_Definition
, Delta_Sloc
);
1038 Scan
; -- past DIGITS
1042 New_Node
(N_Formal_Ordinary_Fixed_Point_Definition
, Delta_Sloc
);
1046 end P_Formal_Fixed_Point_Definition
;
1048 ----------------------------------------------------
1049 -- 12.5.2 Formal Ordinary Fixed Point Definition --
1050 ----------------------------------------------------
1052 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1054 ---------------------------------------------------
1055 -- 12.5.2 Formal Decimal Fixed Point Definition --
1056 ---------------------------------------------------
1058 -- Parsed by P_Formal_Fixed_Point_Definition (12.5.2)
1060 ------------------------------------------
1061 -- 12.5.3 Formal Array Type Definition --
1062 ------------------------------------------
1064 -- Parsed by P_Formal_Type_Definition (12.5)
1066 -------------------------------------------
1067 -- 12.5.4 Formal Access Type Definition --
1068 -------------------------------------------
1070 -- Parsed by P_Formal_Type_Definition (12.5)
1072 -----------------------------------------
1073 -- 12.6 Formal Subprogram Declaration --
1074 -----------------------------------------
1076 -- FORMAL_SUBPROGRAM_DECLARATION ::=
1077 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION
1078 -- | FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION
1080 -- FORMAL_CONCRETE_SUBPROGRAM_DECLARATION ::=
1081 -- with SUBPROGRAM_SPECIFICATION [is SUBPROGRAM_DEFAULT];
1083 -- FORMAL_ABSTRACT_SUBPROGRAM_DECLARATION ::=
1084 -- with SUBPROGRAM_SPECIFICATION is abstract [SUBPROGRAM_DEFAULT];
1086 -- SUBPROGRAM_DEFAULT ::= DEFAULT_NAME | <>
1088 -- DEFAULT_NAME ::= NAME | null
1090 -- The caller has checked that the initial tokens are WITH FUNCTION or
1091 -- WITH PROCEDURE, and the initial WITH has been scanned out.
1093 -- A null default is an Ada 2005 feature
1095 -- Error recovery: cannot raise Error_Resync
1097 function P_Formal_Subprogram_Declaration
return Node_Id
is
1098 Prev_Sloc
: constant Source_Ptr
:= Prev_Token_Ptr
;
1099 Spec_Node
: constant Node_Id
:= P_Subprogram_Specification
;
1103 if Token
= Tok_Is
then
1104 T_Is
; -- past IS, skip extra IS or ";"
1106 if Token
= Tok_Abstract
then
1108 New_Node
(N_Formal_Abstract_Subprogram_Declaration
, Prev_Sloc
);
1109 Scan
; -- past ABSTRACT
1111 if Ada_Version
< Ada_05
then
1113 ("formal abstract subprograms are an Ada 2005 extension");
1114 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1119 New_Node
(N_Formal_Concrete_Subprogram_Declaration
, Prev_Sloc
);
1122 Set_Specification
(Def_Node
, Spec_Node
);
1124 if Token
= Tok_Semicolon
then
1127 elsif Token
= Tok_Box
then
1128 Set_Box_Present
(Def_Node
, True);
1132 elsif Token
= Tok_Null
then
1133 if Ada_Version
< Ada_05
then
1135 ("null default subprograms are an Ada 2005 extension");
1136 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1139 if Nkind
(Spec_Node
) = N_Procedure_Specification
then
1140 Set_Null_Present
(Spec_Node
);
1142 Error_Msg_SP
("only procedures can be null");
1149 Set_Default_Name
(Def_Node
, P_Name
);
1155 New_Node
(N_Formal_Concrete_Subprogram_Declaration
, Prev_Sloc
);
1156 Set_Specification
(Def_Node
, Spec_Node
);
1161 end P_Formal_Subprogram_Declaration
;
1163 ------------------------------
1164 -- 12.6 Subprogram Default --
1165 ------------------------------
1167 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1169 ------------------------
1170 -- 12.6 Default Name --
1171 ------------------------
1173 -- Parsed by P_Formal_Procedure_Declaration (12.6)
1175 --------------------------------------
1176 -- 12.7 Formal Package Declaration --
1177 --------------------------------------
1179 -- FORMAL_PACKAGE_DECLARATION ::=
1180 -- with package DEFINING_IDENTIFIER
1181 -- is new generic_package_NAME FORMAL_PACKAGE_ACTUAL_PART;
1183 -- FORMAL_PACKAGE_ACTUAL_PART ::=
1184 -- ([OTHERS =>] <>) |
1185 -- [GENERIC_ACTUAL_PART]
1186 -- (FORMAL_PACKAGE_ASSOCIATION {, FORMAL_PACKAGE_ASSOCIATION}
1189 -- FORMAL_PACKAGE_ASSOCIATION ::=
1190 -- GENERIC_ASSOCIATION
1191 -- | GENERIC_FORMAL_PARAMETER_SELECTOR_NAME => <>
1193 -- The caller has checked that the initial tokens are WITH PACKAGE,
1194 -- and the initial WITH has been scanned out (so Token = Tok_Package).
1196 -- Error recovery: cannot raise Error_Resync
1198 function P_Formal_Package_Declaration
return Node_Id
is
1200 Scan_State
: Saved_Scan_State
;
1203 Def_Node
:= New_Node
(N_Formal_Package_Declaration
, Prev_Token_Ptr
);
1204 Scan
; -- past PACKAGE
1205 Set_Defining_Identifier
(Def_Node
, P_Defining_Identifier
(C_Is
));
1208 Set_Name
(Def_Node
, P_Qualified_Simple_Name
);
1210 if Token
= Tok_Left_Paren
then
1211 Save_Scan_State
(Scan_State
); -- at the left paren
1212 Scan
; -- past the left paren
1214 if Token
= Tok_Box
then
1215 Set_Box_Present
(Def_Node
, True);
1220 Restore_Scan_State
(Scan_State
); -- to the left paren
1221 Set_Generic_Associations
(Def_Node
, P_Generic_Actual_Part_Opt
);
1227 end P_Formal_Package_Declaration
;
1229 --------------------------------------
1230 -- 12.7 Formal Package Actual Part --
1231 --------------------------------------
1233 -- Parsed by P_Formal_Package_Declaration (12.7)