1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, 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.
30 with Sinfo
.CN
; use Sinfo
.CN
;
40 -----------------------
41 -- Local Subprograms --
42 -----------------------
44 function P_Component_List
return Node_Id
;
45 function P_Defining_Character_Literal
return Node_Id
;
46 function P_Delta_Constraint
return Node_Id
;
47 function P_Derived_Type_Def_Or_Private_Ext_Decl
return Node_Id
;
48 function P_Digits_Constraint
return Node_Id
;
49 function P_Discriminant_Association
return Node_Id
;
50 function P_Enumeration_Literal_Specification
return Node_Id
;
51 function P_Enumeration_Type_Definition
return Node_Id
;
52 function P_Fixed_Point_Definition
return Node_Id
;
53 function P_Floating_Point_Definition
return Node_Id
;
54 function P_Index_Or_Discriminant_Constraint
return Node_Id
;
55 function P_Real_Range_Specification_Opt
return Node_Id
;
56 function P_Subtype_Declaration
return Node_Id
;
57 function P_Type_Declaration
return Node_Id
;
58 function P_Modular_Type_Definition
return Node_Id
;
59 function P_Variant
return Node_Id
;
60 function P_Variant_Part
return Node_Id
;
62 procedure Check_Restricted_Expression
(N
: Node_Id
);
63 -- Check that the expression N meets the Restricted_Expression syntax.
64 -- The syntax is as follows:
66 -- RESTRICTED_EXPRESSION ::=
67 -- RESTRICTED_RELATION {and RESTRICTED_RELATION}
68 -- | RESTRICTED_RELATION {and then RESTRICTED_RELATION}
69 -- | RESTRICTED_RELATION {or RESTRICTED_RELATION}
70 -- | RESTRICTED_RELATION {or else RESTRICTED_RELATION}
71 -- | RESTRICTED_RELATION {xor RESTRICTED_RELATION}
73 -- RESTRICTED_RELATION ::=
74 -- SIMPLE_EXPRESSION [RELATIONAL_OPERATOR SIMPLE_EXPRESSION]
76 -- This syntax is used for choices when extensions (and set notations)
77 -- are enabled, to remove the ambiguity of "when X in A | B". We consider
78 -- it very unlikely that this will ever arise in practice.
80 procedure P_Declarative_Item
83 Declare_Expression
: Boolean;
85 In_Statements
: Boolean);
86 -- Parses a single declarative item. The parameters have the same meaning
87 -- as for P_Declarative_Items. If the declarative item has multiple
88 -- identifiers, as in "X, Y, Z : ...", then one declaration is appended to
89 -- Decls for each of the identifiers.
91 procedure P_Identifier_Declarations
95 In_Statements
: Boolean);
96 -- Parses a sequence of declarations for an identifier or list of
97 -- identifiers, and appends them to the given list. The parameters
98 -- have the same meaning as for P_Declarative_Items.
100 procedure Statement_When_Declaration_Expected
104 -- Called when a statement is found at a point where a declaration was
105 -- expected. The parameters have the same meaning as for
106 -- P_Declarative_Items.
108 procedure Set_Declaration_Expected
;
109 -- Posts a "declaration expected" error messages at the start of the
110 -- current token, and if this is the first such message issued, saves
111 -- the message id in Missing_Begin_Msg, for possible later replacement.
113 ---------------------------------
114 -- Check_Restricted_Expression --
115 ---------------------------------
117 procedure Check_Restricted_Expression
(N
: Node_Id
) is
119 if Nkind
(N
) in N_Op_And | N_Op_Or | N_Op_Xor | N_And_Then | N_Or_Else
121 Check_Restricted_Expression
(Left_Opnd
(N
));
122 Check_Restricted_Expression
(Right_Opnd
(N
));
124 elsif Nkind
(N
) in N_In | N_Not_In
125 and then Paren_Count
(N
) = 0
127 Error_Msg_N
("|this expression must be parenthesized!", N
);
129 end Check_Restricted_Expression
;
135 function Init_Expr_Opt
(P
: Boolean := False) return Node_Id
is
137 -- For colon, assume it means := unless it is at the end of
138 -- a line, in which case guess that it means a semicolon.
140 if Token
= Tok_Colon
then
141 if Token_Is_At_End_Of_Line
then
146 -- Here if := or something that we will take as equivalent
148 elsif Token
in Tok_Colon_Equal | Tok_Equal | Tok_Is
then
151 -- Another possibility. If we have a literal followed by a semicolon,
152 -- we assume that we have a missing colon-equal.
154 elsif Token
in Token_Class_Literal
then
156 Scan_State
: Saved_Scan_State
;
159 Save_Scan_State
(Scan_State
);
160 Scan
; -- past literal or identifier
162 if Token
= Tok_Semicolon
then
163 Restore_Scan_State
(Scan_State
);
165 Restore_Scan_State
(Scan_State
);
170 -- Otherwise we definitely have no initialization expression
176 -- Merge here if we have an initialization expression
183 return P_Expression_No_Right_Paren
;
187 ----------------------------
188 -- 3.1 Basic Declaration --
189 ----------------------------
191 -- Parsed by P_Basic_Declarative_Items (3.9)
193 ------------------------------
194 -- 3.1 Defining Identifier --
195 ------------------------------
197 -- DEFINING_IDENTIFIER ::= IDENTIFIER
199 -- Error recovery: can raise Error_Resync
201 function P_Defining_Identifier
(C
: Id_Check
:= None
) return Node_Id
is
202 Ident_Node
: Node_Id
:= P_Identifier
(C
, True);
205 -- If we already have a defining identifier, clean it out and make
206 -- a new clean identifier. This situation arises in some error cases
207 -- and we need to fix it.
209 if Nkind
(Ident_Node
) = N_Defining_Identifier
then
210 Ident_Node
:= Make_Identifier
(Sloc
(Ident_Node
), Chars
(Ident_Node
));
213 -- Change identifier to defining identifier if not in error
215 if Ident_Node
/= Error
then
216 Change_Identifier_To_Defining_Identifier
(Ident_Node
);
218 -- Warn if standard redefinition, except that we never warn on a
219 -- record field definition (since this is always a harmless case).
221 if not Inside_Record_Definition
then
222 Warn_If_Standard_Redefinition
(Ident_Node
);
227 end P_Defining_Identifier
;
229 -----------------------------
230 -- 3.2.1 Type Declaration --
231 -----------------------------
233 -- TYPE_DECLARATION ::=
234 -- FULL_TYPE_DECLARATION
235 -- | INCOMPLETE_TYPE_DECLARATION
236 -- | PRIVATE_TYPE_DECLARATION
237 -- | PRIVATE_EXTENSION_DECLARATION
239 -- FULL_TYPE_DECLARATION ::=
240 -- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION
241 -- [ASPECT_SPECIFICATIONS];
242 -- | CONCURRENT_TYPE_DECLARATION
244 -- INCOMPLETE_TYPE_DECLARATION ::=
245 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] [is tagged];
247 -- PRIVATE_TYPE_DECLARATION ::=
248 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
249 -- is [abstract] [tagged] [limited] private
250 -- [ASPECT_SPECIFICATIONS];
252 -- PRIVATE_EXTENSION_DECLARATION ::=
253 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
254 -- [abstract] [limited | synchronized]
255 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
256 -- with private [ASPECT_SPECIFICATIONS];
258 -- TYPE_DEFINITION ::=
259 -- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
260 -- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
261 -- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
262 -- | DERIVED_TYPE_DEFINITION | INTERFACE_TYPE_DEFINITION
264 -- INTEGER_TYPE_DEFINITION ::=
265 -- SIGNED_INTEGER_TYPE_DEFINITION
266 -- MODULAR_TYPE_DEFINITION
268 -- INTERFACE_TYPE_DEFINITION ::=
269 -- [limited | task | protected | synchronized ] interface
270 -- [and INTERFACE_LIST]
272 -- Error recovery: can raise Error_Resync
274 -- The processing for full type declarations, incomplete type declarations,
275 -- private type declarations and type definitions is included in this
276 -- function. The processing for concurrent type declarations is NOT here,
277 -- but rather in chapter 9 (this function handles only declarations
278 -- starting with TYPE).
280 function P_Type_Declaration
return Node_Id
is
281 Abstract_Present
: Boolean := False;
282 Abstract_Loc
: Source_Ptr
:= No_Location
;
284 Discr_List
: List_Id
;
285 Discr_Sloc
: Source_Ptr
;
287 Ident_Node
: Node_Id
;
288 Is_Derived_Iface
: Boolean := False;
289 Type_Loc
: Source_Ptr
;
290 Type_Start_Col
: Column_Number
;
291 Unknown_Dis
: Boolean;
293 Typedef_Node
: Node_Id
;
294 -- Normally holds type definition, except in the case of a private
295 -- extension declaration, in which case it holds the declaration itself
298 Type_Loc
:= Token_Ptr
;
299 Type_Start_Col
:= Start_Column
;
301 -- If we have TYPE, then proceed ahead and scan identifier
303 if Token
= Tok_Type
then
304 Type_Token_Location
:= Type_Loc
;
306 Ident_Node
:= P_Defining_Identifier
(C_Is
);
308 -- Otherwise this is an error case
312 Type_Token_Location
:= Type_Loc
;
313 Ident_Node
:= P_Defining_Identifier
(C_Is
);
316 Discr_Sloc
:= Token_Ptr
;
318 if P_Unknown_Discriminant_Part_Opt
then
320 Discr_List
:= No_List
;
322 Unknown_Dis
:= False;
323 Discr_List
:= P_Known_Discriminant_Part_Opt
;
326 -- Incomplete type declaration. We complete the processing for this
327 -- case here and return the resulting incomplete type declaration node
329 if Token
= Tok_Semicolon
then
331 Decl_Node
:= New_Node
(N_Incomplete_Type_Declaration
, Type_Loc
);
332 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
333 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
334 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
341 -- Full type declaration or private type declaration, must have IS
343 if Token
= Tok_Equal
then
345 Scan
; -- past = used in place of IS
347 elsif Token
= Tok_Renames
then
348 Error_Msg_SC
-- CODEFIX
349 ("RENAMES should be IS");
350 Scan
; -- past RENAMES used in place of IS
356 -- First an error check, if we have two identifiers in a row, a likely
357 -- possibility is that the first of the identifiers is an incorrectly
360 if Token
= Tok_Identifier
then
362 SS
: Saved_Scan_State
;
366 Save_Scan_State
(SS
);
367 Scan
; -- past initial identifier
368 I2
:= (Token
= Tok_Identifier
);
369 Restore_Scan_State
(SS
);
373 (Bad_Spelling_Of
(Tok_Abstract
) or else
374 Bad_Spelling_Of
(Tok_Access
) or else
375 Bad_Spelling_Of
(Tok_Aliased
) or else
376 Bad_Spelling_Of
(Tok_Constant
))
383 -- Check for misuse of Ada 95 keyword abstract in Ada 83 mode
385 if Token_Name
= Name_Abstract
then
386 Check_95_Keyword
(Tok_Abstract
, Tok_Tagged
);
387 Check_95_Keyword
(Tok_Abstract
, Tok_New
);
390 -- Check cases of misuse of ABSTRACT
392 if Token
= Tok_Abstract
then
393 Abstract_Present
:= True;
394 Abstract_Loc
:= Token_Ptr
;
395 Scan
; -- past ABSTRACT
397 -- Ada 2005 (AI-419): AARM 3.4 (2/2)
399 if (Ada_Version
< Ada_2005
and then Token
= Tok_Limited
)
400 or else Token
in Tok_Private | Tok_Record | Tok_Null
402 Error_Msg_AP
("TAGGED expected");
406 -- Check for misuse of Ada 95 keyword Tagged
408 if Token_Name
= Name_Tagged
then
409 Check_95_Keyword
(Tok_Tagged
, Tok_Private
);
410 Check_95_Keyword
(Tok_Tagged
, Tok_Limited
);
411 Check_95_Keyword
(Tok_Tagged
, Tok_Record
);
414 -- Special check for misuse of Aliased
416 if Token
= Tok_Aliased
or else Token_Name
= Name_Aliased
then
417 Error_Msg_SC
("ALIASED not allowed in type definition");
418 Scan
; -- past ALIASED
421 -- The following processing deals with either a private type declaration
422 -- or a full type declaration. In the private type case, we build the
423 -- N_Private_Type_Declaration node, setting its Tagged_Present and
424 -- Limited_Present flags, on encountering the Private keyword, and
425 -- leave Typedef_Node set to Empty. For the full type declaration
426 -- case, Typedef_Node gets set to the type definition.
428 Typedef_Node
:= Empty
;
430 -- Switch on token following the IS. The loop normally runs once. It
431 -- only runs more than once if an error is detected, to try again after
432 -- detecting and fixing up the error.
437 | Tok_Not
-- Ada 2005 (AI-231)
439 Typedef_Node
:= P_Access_Type_Definition
;
443 Typedef_Node
:= P_Array_Type_Definition
;
447 Typedef_Node
:= P_Fixed_Point_Definition
;
451 Typedef_Node
:= P_Floating_Point_Definition
;
457 when Tok_Integer_Literal
=>
459 Typedef_Node
:= P_Signed_Integer_Type_Definition
;
463 Typedef_Node
:= P_Record_Definition
;
466 when Tok_Left_Paren
=>
467 Typedef_Node
:= P_Enumeration_Type_Definition
;
469 End_Labl
:= Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
470 Set_Comes_From_Source
(End_Labl
, False);
472 Set_End_Label
(Typedef_Node
, End_Labl
);
476 Typedef_Node
:= P_Modular_Type_Definition
;
480 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
482 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
483 and then Present
(Record_Extension_Part
(Typedef_Node
))
485 End_Labl
:= Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
486 Set_Comes_From_Source
(End_Labl
, False);
489 (Record_Extension_Part
(Typedef_Node
), End_Labl
);
495 Typedef_Node
:= P_Signed_Integer_Type_Definition
;
499 Typedef_Node
:= P_Record_Definition
;
501 End_Labl
:= Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
502 Set_Comes_From_Source
(End_Labl
, False);
504 Set_End_Label
(Typedef_Node
, End_Labl
);
510 -- Ada 2005 (AI-326): If the words IS TAGGED appear, the type
511 -- is a tagged incomplete type.
513 if Ada_Version
>= Ada_2005
514 and then Token
= Tok_Semicolon
519 New_Node
(N_Incomplete_Type_Declaration
, Type_Loc
);
520 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
521 Set_Tagged_Present
(Decl_Node
);
522 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
523 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
528 if Token
= Tok_Abstract
then
529 Error_Msg_SC
-- CODEFIX
530 ("ABSTRACT must come before TAGGED");
531 Abstract_Present
:= True;
532 Abstract_Loc
:= Token_Ptr
;
533 Scan
; -- past ABSTRACT
536 if Token
= Tok_Limited
then
537 Scan
; -- past LIMITED
539 -- TAGGED LIMITED PRIVATE case
541 if Token
= Tok_Private
then
543 New_Node
(N_Private_Type_Declaration
, Type_Loc
);
544 Set_Tagged_Present
(Decl_Node
, True);
545 Set_Limited_Present
(Decl_Node
, True);
546 Scan
; -- past PRIVATE
548 -- TAGGED LIMITED RECORD
551 Typedef_Node
:= P_Record_Definition
;
552 Set_Tagged_Present
(Typedef_Node
, True);
553 Set_Limited_Present
(Typedef_Node
, True);
556 Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
557 Set_Comes_From_Source
(End_Labl
, False);
559 Set_End_Label
(Typedef_Node
, End_Labl
);
565 if Token
= Tok_Private
then
567 New_Node
(N_Private_Type_Declaration
, Type_Loc
);
568 Set_Tagged_Present
(Decl_Node
, True);
569 Scan
; -- past PRIVATE
574 Typedef_Node
:= P_Record_Definition
;
575 Set_Tagged_Present
(Typedef_Node
, True);
578 Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
579 Set_Comes_From_Source
(End_Labl
, False);
581 Set_End_Label
(Typedef_Node
, End_Labl
);
588 Scan
; -- past LIMITED
591 if Token
= Tok_Tagged
then
592 Error_Msg_SC
-- CODEFIX
593 ("TAGGED must come before LIMITED");
596 elsif Token
= Tok_Abstract
then
597 Error_Msg_SC
-- CODEFIX
598 ("ABSTRACT must come before LIMITED");
599 Scan
; -- past ABSTRACT
606 -- LIMITED RECORD or LIMITED NULL RECORD
608 if Token
in Tok_Record | Tok_Null
then
609 if Ada_Version
= Ada_83
then
611 ("(Ada 83) limited record declaration not allowed!");
613 -- In Ada 2005, "abstract limited" can appear before "new",
614 -- but it cannot be part of an untagged record declaration.
616 elsif Abstract_Present
617 and then Prev_Token
/= Tok_Tagged
619 Error_Msg_SP
("TAGGED expected");
622 Typedef_Node
:= P_Record_Definition
;
623 Set_Limited_Present
(Typedef_Node
, True);
624 End_Labl
:= Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
625 Set_Comes_From_Source
(End_Labl
, False);
627 Set_End_Label
(Typedef_Node
, End_Labl
);
629 -- Ada 2005 (AI-251): LIMITED INTERFACE
631 -- If we are compiling in Ada 83 or Ada 95 mode, "interface"
632 -- is not a reserved word but we force its analysis to
633 -- generate the corresponding usage error.
635 elsif Token
= Tok_Interface
636 or else (Token
= Tok_Identifier
637 and then Chars
(Token_Node
) = Name_Interface
)
640 P_Interface_Type_Definition
(Abstract_Present
);
641 Abstract_Present
:= True;
642 Set_Limited_Present
(Typedef_Node
);
644 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
then
645 Is_Derived_Iface
:= True;
648 -- Ada 2005 (AI-419): LIMITED NEW
650 elsif Token
= Tok_New
then
651 Error_Msg_Ada_2005_Extension
("LIMITED in derived type");
653 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
654 Set_Limited_Present
(Typedef_Node
);
656 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
657 and then Present
(Record_Extension_Part
(Typedef_Node
))
660 Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
661 Set_Comes_From_Source
(End_Labl
, False);
664 (Record_Extension_Part
(Typedef_Node
), End_Labl
);
667 -- LIMITED PRIVATE is the only remaining possibility here
670 Decl_Node
:= New_Node
(N_Private_Type_Declaration
, Type_Loc
);
671 Set_Limited_Present
(Decl_Node
, True);
672 T_Private
; -- past PRIVATE (or complain if not there)
677 -- Here we have an identifier after the IS, which is certainly
678 -- wrong and which might be one of several different mistakes.
680 when Tok_Identifier
=>
682 -- First case, if identifier is on same line, then probably we
683 -- have something like "type X is Integer .." and the best
684 -- diagnosis is a missing NEW. Note: the missing new message
685 -- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl.
687 if not Token_Is_At_Start_Of_Line
then
688 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
690 -- If the identifier is at the start of the line, and is in the
691 -- same column as the type declaration itself then we consider
692 -- that we had a missing type definition on the previous line
694 elsif Start_Column
<= Type_Start_Col
then
695 Error_Msg_AP
("type definition expected");
696 Typedef_Node
:= Error
;
698 -- If the identifier is at the start of the line, and is in
699 -- a column to the right of the type declaration line, then we
700 -- may have something like:
705 -- and the best diagnosis is a missing record keyword
708 Typedef_Node
:= P_Record_Definition
;
713 -- Ada 2005 (AI-251): INTERFACE
715 when Tok_Interface
=>
716 Typedef_Node
:= P_Interface_Type_Definition
(Abstract_Present
);
717 Abstract_Present
:= True;
721 Decl_Node
:= New_Node
(N_Private_Type_Declaration
, Type_Loc
);
722 Scan
; -- past PRIVATE
724 -- Check error cases of private [abstract] tagged
726 if Token
= Tok_Abstract
then
727 Error_Msg_SC
("`ABSTRACT TAGGED` must come before PRIVATE");
728 Scan
; -- past ABSTRACT
730 if Token
= Tok_Tagged
then
734 elsif Token
= Tok_Tagged
then
735 Error_Msg_SC
("TAGGED must come before PRIVATE");
741 -- Ada 2005 (AI-345): Protected, synchronized or task interface
742 -- or Ada 2005 (AI-443): Synchronized private extension.
749 Saved_Token
: constant Token_Type
:= Token
;
752 Scan
; -- past TASK, PROTECTED or SYNCHRONIZED
754 -- Synchronized private extension
756 if Token
= Tok_New
then
757 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
759 if Saved_Token
= Tok_Synchronized
then
760 if Nkind
(Typedef_Node
) =
761 N_Derived_Type_Definition
764 ("SYNCHRONIZED not allowed for record extension",
767 Set_Synchronized_Present
(Typedef_Node
);
771 Error_Msg_SC
("invalid kind of private extension");
777 if Token
/= Tok_Interface
then
778 Error_Msg_SC
("NEW or INTERFACE expected");
782 P_Interface_Type_Definition
(Abstract_Present
);
783 Abstract_Present
:= True;
787 Set_Task_Present
(Typedef_Node
);
789 when Tok_Protected
=>
790 Set_Protected_Present
(Typedef_Node
);
792 when Tok_Synchronized
=>
793 Set_Synchronized_Present
(Typedef_Node
);
796 pragma Assert
(False);
804 -- Anything else is an error
807 if Bad_Spelling_Of
(Tok_Access
)
809 Bad_Spelling_Of
(Tok_Array
)
811 Bad_Spelling_Of
(Tok_Delta
)
813 Bad_Spelling_Of
(Tok_Digits
)
815 Bad_Spelling_Of
(Tok_Limited
)
817 Bad_Spelling_Of
(Tok_Private
)
819 Bad_Spelling_Of
(Tok_Range
)
821 Bad_Spelling_Of
(Tok_Record
)
823 Bad_Spelling_Of
(Tok_Tagged
)
828 Error_Msg_AP
("type definition expected");
834 -- For the private type declaration case, the private type declaration
835 -- node has been built, with the Tagged_Present and Limited_Present
836 -- flags set as needed, and Typedef_Node is left set to Empty.
838 if No
(Typedef_Node
) then
839 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
840 Set_Abstract_Present
(Decl_Node
, Abstract_Present
);
842 -- For a private extension declaration, Typedef_Node contains the
843 -- N_Private_Extension_Declaration node, which we now complete. Note
844 -- that the private extension declaration, unlike a full type
845 -- declaration, does permit unknown discriminants.
847 elsif Nkind
(Typedef_Node
) = N_Private_Extension_Declaration
then
848 Decl_Node
:= Typedef_Node
;
849 Set_Sloc
(Decl_Node
, Type_Loc
);
850 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
851 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
853 -- In the full type declaration case, Typedef_Node has the type
854 -- definition and here is where we build the full type declaration
855 -- node. This is also where we check for improper use of an unknown
856 -- discriminant part (not allowed for full type declaration).
859 if Nkind
(Typedef_Node
) = N_Record_Definition
860 or else (Nkind
(Typedef_Node
) = N_Derived_Type_Definition
861 and then Present
(Record_Extension_Part
(Typedef_Node
)))
862 or else Is_Derived_Iface
864 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
866 elsif Abstract_Present
then
867 Error_Msg
("ABSTRACT not allowed here, ignored", Abstract_Loc
);
870 Decl_Node
:= New_Node
(N_Full_Type_Declaration
, Type_Loc
);
871 Set_Type_Definition
(Decl_Node
, Typedef_Node
);
875 ("full type declaration cannot have unknown discriminants",
880 -- Remaining processing is common for all three cases
882 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
883 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
884 P_Aspect_Specifications
(Decl_Node
);
886 end P_Type_Declaration
;
888 ----------------------------------
889 -- 3.2.1 Full Type Declaration --
890 ----------------------------------
892 -- Parsed by P_Type_Declaration (3.2.1)
894 ----------------------------
895 -- 3.2.1 Type Definition --
896 ----------------------------
898 -- Parsed by P_Type_Declaration (3.2.1)
900 --------------------------------
901 -- 3.2.2 Subtype Declaration --
902 --------------------------------
904 -- SUBTYPE_DECLARATION ::=
905 -- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION
906 -- [ASPECT_SPECIFICATIONS];
908 -- The caller has checked that the initial token is SUBTYPE
910 -- Error recovery: can raise Error_Resync
912 function P_Subtype_Declaration
return Node_Id
is
914 Not_Null_Present
: Boolean := False;
917 Decl_Node
:= New_Node
(N_Subtype_Declaration
, Token_Ptr
);
918 Scan
; -- past SUBTYPE
919 Set_Defining_Identifier
(Decl_Node
, P_Defining_Identifier
(C_Is
));
922 if Token
= Tok_New
then
923 Error_Msg_SC
-- CODEFIX
924 ("NEW ignored (only allowed in type declaration)");
928 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
929 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
931 Set_Subtype_Indication
932 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
933 P_Aspect_Specifications
(Decl_Node
);
935 end P_Subtype_Declaration
;
937 -------------------------------
938 -- 3.2.2 Subtype Indication --
939 -------------------------------
941 -- SUBTYPE_INDICATION ::=
942 -- [not null] SUBTYPE_MARK [CONSTRAINT]
944 -- Error recovery: can raise Error_Resync
946 function P_Null_Exclusion
947 (Allow_Anonymous_In_95
: Boolean := False) return Boolean
949 Not_Loc
: constant Source_Ptr
:= Token_Ptr
;
950 -- Source position of "not", if present
953 if Token
/= Tok_Not
then
959 if Token
= Tok_Null
then
962 -- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95,
963 -- except in the case of anonymous access types.
965 -- Allow_Anonymous_In_95 will be True if we're parsing a formal
966 -- parameter or discriminant, which are the only places where
967 -- anonymous access types occur in Ada 95. "Formal : not null
968 -- access ..." is legal in Ada 95, whereas "Formal : not null
969 -- Named_Access_Type" is not.
971 if Ada_Version
>= Ada_2005
972 or else (Ada_Version
>= Ada_95
973 and then Allow_Anonymous_In_95
974 and then Token
= Tok_Access
)
980 ("`NOT NULL` access type is an Ada 2005 extension", Not_Loc
);
982 ("\unit should be compiled with -gnat05 switch", Not_Loc
);
986 Error_Msg_SP
("NULL expected");
989 if Token
= Tok_New
then
990 Error_Msg
("`NOT NULL` comes after NEW, not before", Not_Loc
);
995 end P_Null_Exclusion
;
997 function P_Subtype_Indication
998 (Not_Null_Present
: Boolean := False) return Node_Id
1000 Type_Node
: Node_Id
;
1003 if Token
in Tok_Identifier | Tok_Operator_Symbol
then
1004 Type_Node
:= P_Subtype_Mark
;
1005 return P_Subtype_Indication
(Type_Node
, Not_Null_Present
);
1008 -- Check for error of using record definition and treat it nicely,
1009 -- otherwise things are really messed up, so resynchronize.
1011 if Token
= Tok_Record
then
1012 Error_Msg_SC
("anonymous record definition not permitted");
1013 Discard_Junk_Node
(P_Record_Definition
);
1017 Error_Msg_AP
("subtype indication expected");
1021 end P_Subtype_Indication
;
1023 -- The following function is identical except that it is called with
1024 -- the subtype mark already scanned out, and it scans out the constraint
1026 -- Error recovery: can raise Error_Resync
1028 function P_Subtype_Indication
1029 (Subtype_Mark
: Node_Id
;
1030 Not_Null_Present
: Boolean := False) return Node_Id
1032 Indic_Node
: Node_Id
;
1033 Constr_Node
: Node_Id
;
1036 Constr_Node
:= P_Constraint_Opt
;
1040 (Nkind
(Constr_Node
) = N_Range_Constraint
1041 and then Nkind
(Range_Expression
(Constr_Node
)) = N_Error
)
1043 return Subtype_Mark
;
1045 if Not_Null_Present
then
1046 Error_Msg_SP
("`NOT NULL` not allowed if constraint given");
1049 Indic_Node
:= New_Node
(N_Subtype_Indication
, Sloc
(Subtype_Mark
));
1050 Set_Subtype_Mark
(Indic_Node
, Check_Subtype_Mark
(Subtype_Mark
));
1051 Set_Constraint
(Indic_Node
, Constr_Node
);
1054 end P_Subtype_Indication
;
1056 -------------------------
1057 -- 3.2.2 Subtype Mark --
1058 -------------------------
1060 -- SUBTYPE_MARK ::= subtype_NAME;
1062 -- Note: The subtype mark which appears after an IN or NOT IN
1063 -- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
1065 -- Error recovery: cannot raise Error_Resync
1067 function P_Subtype_Mark
return Node_Id
is
1069 return P_Subtype_Mark_Resync
;
1071 when Error_Resync
=>
1075 -- This routine differs from P_Subtype_Mark in that it insists that an
1076 -- identifier be present, and if it is not, it raises Error_Resync.
1078 -- Error recovery: can raise Error_Resync
1080 function P_Subtype_Mark_Resync
return Node_Id
is
1081 Type_Node
: Node_Id
;
1084 if Token
= Tok_Access
then
1085 Error_Msg_SC
("anonymous access type definition not allowed here");
1086 Scan
; -- past ACCESS
1089 if Token
= Tok_Array
then
1090 Error_Msg_SC
("anonymous array definition not allowed here");
1091 Discard_Junk_Node
(P_Array_Type_Definition
);
1095 Type_Node
:= P_Qualified_Simple_Name_Resync
;
1097 -- Check for a subtype mark attribute. The only valid possibilities
1098 -- are 'CLASS and 'BASE. Anything else is a definite error. We may
1099 -- as well catch it here.
1101 if Token
= Tok_Apostrophe
then
1102 return P_Subtype_Mark_Attribute
(Type_Node
);
1107 end P_Subtype_Mark_Resync
;
1109 -- The following function is called to scan out a subtype mark attribute.
1110 -- The caller has already scanned out the subtype mark, which is passed in
1111 -- as the argument, and has checked that the current token is apostrophe.
1113 -- Only a special subclass of attributes, called type attributes
1114 -- (see Snames package) are allowed in this syntactic position.
1116 -- Note: if the apostrophe is followed by other than an identifier, then
1117 -- the input expression is returned unchanged, and the scan pointer is
1118 -- left pointing to the apostrophe.
1120 -- Error recovery: can raise Error_Resync
1122 function P_Subtype_Mark_Attribute
(Type_Node
: Node_Id
) return Node_Id
is
1123 Attr_Node
: Node_Id
:= Empty
;
1124 Scan_State
: Saved_Scan_State
;
1128 Prefix
:= Check_Subtype_Mark
(Type_Node
);
1130 if Prefix
= Error
then
1134 -- Loop through attributes appearing (more than one can appear as for
1135 -- for example in X'Base'Class). We are at an apostrophe on entry to
1136 -- this loop, and it runs once for each attribute parsed, with
1137 -- Prefix being the current possible prefix if it is an attribute.
1140 Save_Scan_State
(Scan_State
); -- at Apostrophe
1141 Scan
; -- past apostrophe
1143 if Token
/= Tok_Identifier
then
1144 Restore_Scan_State
(Scan_State
); -- to apostrophe
1145 return Prefix
; -- no attribute after all
1147 elsif not Is_Type_Attribute_Name
(Token_Name
) then
1149 ("attribute & may not be used in a subtype mark", Token_Node
);
1154 Make_Attribute_Reference
(Prev_Token_Ptr
,
1156 Attribute_Name
=> Token_Name
);
1157 Scan
; -- past type attribute identifier
1160 exit when Token
/= Tok_Apostrophe
;
1161 Prefix
:= Attr_Node
;
1164 -- Fall through here after scanning type attribute
1167 end P_Subtype_Mark_Attribute
;
1169 -----------------------
1170 -- 3.2.2 Constraint --
1171 -----------------------
1173 -- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
1175 -- SCALAR_CONSTRAINT ::=
1176 -- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
1178 -- COMPOSITE_CONSTRAINT ::=
1179 -- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
1181 -- If no constraint is present, this function returns Empty
1183 -- Error recovery: can raise Error_Resync
1185 function P_Constraint_Opt
return Node_Id
is
1187 if Token
= Tok_Range
or else Bad_Spelling_Of
(Tok_Range
) then
1188 return P_Range_Constraint
;
1190 elsif Token
= Tok_Digits
or else Bad_Spelling_Of
(Tok_Digits
) then
1191 return P_Digits_Constraint
;
1193 elsif Token
= Tok_Delta
or else Bad_Spelling_Of
(Tok_Delta
) then
1194 return P_Delta_Constraint
;
1196 elsif Token
= Tok_Left_Paren
then
1197 return P_Index_Or_Discriminant_Constraint
;
1199 elsif Token
= Tok_In
then
1201 return P_Constraint_Opt
;
1203 -- One more possibility is e.g. 1 .. 10 (i.e. missing RANGE keyword)
1205 elsif Token
= Tok_Identifier
or else
1206 Token
= Tok_Integer_Literal
or else
1207 Token
= Tok_Real_Literal
1210 Scan_State
: Saved_Scan_State
;
1213 Save_Scan_State
(Scan_State
); -- at identifier or literal
1214 Scan
; -- past identifier or literal
1216 if Token
= Tok_Dot_Dot
then
1217 Restore_Scan_State
(Scan_State
);
1218 Error_Msg_BC
("missing RANGE keyword");
1219 return P_Range_Constraint
;
1221 Restore_Scan_State
(Scan_State
);
1226 -- Nothing worked, no constraint there
1231 end P_Constraint_Opt
;
1233 ------------------------------
1234 -- 3.2.2 Scalar Constraint --
1235 ------------------------------
1237 -- Parsed by P_Constraint_Opt (3.2.2)
1239 ---------------------------------
1240 -- 3.2.2 Composite Constraint --
1241 ---------------------------------
1243 -- Parsed by P_Constraint_Opt (3.2.2)
1245 --------------------------------------------------------
1246 -- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
1247 --------------------------------------------------------
1249 -- This routine scans out a declaration starting with an identifier:
1251 -- OBJECT_DECLARATION ::=
1252 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1253 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
1254 -- [ASPECT_SPECIFICATIONS];
1255 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1256 -- ACCESS_DEFINITION [:= EXPRESSION]
1257 -- [ASPECT_SPECIFICATIONS];
1258 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1259 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION]
1260 -- [ASPECT_SPECIFICATIONS];
1262 -- NUMBER_DECLARATION ::=
1263 -- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
1265 -- OBJECT_RENAMING_DECLARATION ::=
1266 -- DEFINING_IDENTIFIER :
1267 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME
1268 -- [ASPECT_SPECIFICATIONS];
1269 -- | DEFINING_IDENTIFIER :
1270 -- ACCESS_DEFINITION renames object_NAME
1271 -- [ASPECT_SPECIFICATIONS];
1273 -- EXCEPTION_RENAMING_DECLARATION ::=
1274 -- DEFINING_IDENTIFIER : exception renames exception_NAME
1275 -- [ASPECT_SPECIFICATIONS];
1277 -- EXCEPTION_DECLARATION ::=
1278 -- DEFINING_IDENTIFIER_LIST : exception
1279 -- [ASPECT_SPECIFICATIONS];
1281 -- Note that the ALIASED indication in an object declaration is
1282 -- marked by a flag in the parent node.
1284 -- The caller has checked that the initial token is an identifier
1286 -- The value returned is a list of declarations, one for each identifier
1287 -- in the list (as described in Sinfo, we always split up multiple
1288 -- declarations into the equivalent sequence of single declarations
1289 -- using the More_Ids and Prev_Ids flags to preserve the source).
1291 -- If the identifier turns out to be a probable statement rather than
1292 -- an identifier, then the scan is left pointing to the identifier and
1293 -- No_List is returned.
1295 -- Error recovery: can raise Error_Resync
1297 procedure P_Identifier_Declarations
1301 In_Statements
: Boolean)
1304 Decl_Node
: Node_Id
;
1305 Type_Node
: Node_Id
;
1306 Ident_Sloc
: Source_Ptr
;
1307 Scan_State
: Saved_Scan_State
;
1308 List_OK
: Boolean := True;
1310 Init_Expr
: Node_Id
;
1311 Init_Loc
: Source_Ptr
;
1312 Con_Loc
: Source_Ptr
;
1313 Not_Null_Present
: Boolean := False;
1315 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
1316 -- Used to save identifiers in the identifier list. The upper bound
1317 -- of 4096 is expected to be infinite in practice, and we do not even
1318 -- bother to check if this upper bound is exceeded.
1320 Num_Idents
: Nat
:= 1;
1321 -- Number of identifiers stored in Idents
1323 function Identifier_Starts_Statement
return Boolean;
1324 -- Called with Token being an identifier that might start a declaration
1325 -- or a statement. True if we are parsing declarations in a sequence of
1326 -- statements, and this identifier is the start of a statement. If this
1327 -- is true, we quit parsing declarations, and return Done = True so the
1328 -- caller will switch to parsing statements.
1331 -- This procedure is called in renames cases to make sure that we do
1332 -- not have more than one identifier. If we do have more than one
1333 -- then an error message is issued (and the declaration is split into
1334 -- multiple declarations)
1336 function Token_Is_Renames
return Boolean;
1337 -- Checks if current token is RENAMES, and if so, scans past it and
1338 -- returns True, otherwise returns False. Includes checking for some
1339 -- common error cases.
1341 ---------------------------------
1342 -- Identifier_Starts_Statement --
1343 ---------------------------------
1345 function Identifier_Starts_Statement
return Boolean is
1346 pragma Assert
(Token
= Tok_Identifier
);
1347 Scan_State
: Saved_Scan_State
;
1348 Result
: Boolean := False;
1350 if not In_Statements
then
1354 Save_Scan_State
(Scan_State
);
1358 when Tok_Comma
=> -- "X, ..." is a declaration
1362 -- "X : ..." is usually a declaration, but "X : begin..." is
1363 -- not. We return true for things like "X : Y : begin...",
1364 -- which is a syntax error, because that gives better error
1365 -- recovery for some ACATS.
1369 if Token
in Token_Class_Labeled_Stmt
then
1372 elsif Token
= Tok_Identifier
then
1374 if Token
= Tok_Colon
then
1376 if Token
in Token_Class_Labeled_Stmt
then
1386 Restore_Scan_State
(Scan_State
);
1388 end Identifier_Starts_Statement
;
1394 procedure No_List
is
1396 if Num_Idents
> 1 then
1398 ("identifier list not allowed for RENAMES",
1405 ----------------------
1406 -- Token_Is_Renames --
1407 ----------------------
1409 function Token_Is_Renames
return Boolean is
1410 At_Colon
: Saved_Scan_State
;
1413 if Token
= Tok_Colon
then
1414 Save_Scan_State
(At_Colon
);
1416 Check_Misspelling_Of
(Tok_Renames
);
1418 if Token
= Tok_Renames
then
1419 Error_Msg_SP
-- CODEFIX
1420 ("|extra "":"" ignored");
1421 Scan
; -- past RENAMES
1424 Restore_Scan_State
(At_Colon
);
1429 Check_Misspelling_Of
(Tok_Renames
);
1431 if Token
= Tok_Renames
then
1432 Scan
; -- past RENAMES
1438 end Token_Is_Renames
;
1440 -- Start of processing for P_Identifier_Declarations
1443 if Identifier_Starts_Statement
then
1448 Ident_Sloc
:= Token_Ptr
;
1449 Save_Scan_State
(Scan_State
); -- at first identifier
1450 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
1452 -- If we have a colon after the identifier, then we can assume that
1453 -- this is in fact a valid identifier declaration and can steam ahead.
1455 if Token
= Tok_Colon
then
1458 -- If we have a comma, then scan out the list of identifiers
1460 elsif Token
= Tok_Comma
then
1461 while Comma_Present
loop
1462 Num_Idents
:= Num_Idents
+ 1;
1463 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
1466 Save_Scan_State
(Scan_State
); -- at colon
1469 -- If we have an identifier followed by := then we assume that what is
1470 -- really meant is an assignment statement. The assignment statement
1471 -- is scanned out and added to the list of declarations. An exception
1472 -- occurs if the := is followed by the keyword constant, in which case
1473 -- we assume it was meant to be a colon.
1475 elsif Token
= Tok_Colon_Equal
then
1478 if Token
= Tok_Constant
then
1479 Error_Msg_SP
("colon expected");
1482 Restore_Scan_State
(Scan_State
);
1484 -- Reset Token_Node, because it already got changed from an
1485 -- Identifier to a Defining_Identifier, and we don't want that
1489 Make_Identifier
(Sloc
(Token_Node
), Chars
(Token_Node
));
1491 -- And now scan out one or more statements
1493 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
1497 -- If we have an IS keyword, then assume the TYPE keyword was missing
1499 elsif Token
= Tok_Is
then
1500 Restore_Scan_State
(Scan_State
);
1501 Append_To
(Decls
, P_Type_Declaration
);
1505 -- AI12-0275: Object renaming declaration without subtype_mark or
1506 -- access_definition
1508 elsif Token
= Tok_Renames
then
1509 Error_Msg_Ada_2022_Feature
1510 ("object renaming without subtype", Token_Ptr
);
1512 Scan
; -- past renames
1515 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1516 Set_Name
(Decl_Node
, P_Name
);
1517 Set_Defining_Identifier
(Decl_Node
, Idents
(1));
1519 P_Aspect_Specifications
(Decl_Node
, Semicolon
=> False);
1523 Append
(Decl_Node
, Decls
);
1528 -- Otherwise we have an error situation
1531 Restore_Scan_State
(Scan_State
);
1533 -- First case is possible misuse of PROTECTED in Ada 83 mode. If
1534 -- so, fix the keyword and return to scan the protected declaration.
1536 if Token_Name
= Name_Protected
then
1537 Check_95_Keyword
(Tok_Protected
, Tok_Identifier
);
1538 Check_95_Keyword
(Tok_Protected
, Tok_Type
);
1539 Check_95_Keyword
(Tok_Protected
, Tok_Body
);
1541 if Token
= Tok_Protected
then
1546 -- Check misspelling possibilities. If so, correct the misspelling
1547 -- and return to scan out the resulting declaration.
1549 elsif Bad_Spelling_Of
(Tok_Function
)
1550 or else Bad_Spelling_Of
(Tok_Procedure
)
1551 or else Bad_Spelling_Of
(Tok_Package
)
1552 or else Bad_Spelling_Of
(Tok_Pragma
)
1553 or else Bad_Spelling_Of
(Tok_Protected
)
1554 or else Bad_Spelling_Of
(Tok_Generic
)
1555 or else Bad_Spelling_Of
(Tok_Subtype
)
1556 or else Bad_Spelling_Of
(Tok_Type
)
1557 or else Bad_Spelling_Of
(Tok_Task
)
1558 or else Bad_Spelling_Of
(Tok_Use
)
1559 or else Bad_Spelling_Of
(Tok_For
)
1564 -- Otherwise we definitely have an ordinary identifier with a junk
1567 elsif In_Statements
then
1572 -- If in -gnatd.2 mode, try for statements
1574 if Debug_Flag_Dot_2
then
1575 Restore_Scan_State
(Scan_State
);
1577 -- Reset Token_Node, because it already got changed from an
1578 -- Identifier to a Defining_Identifier, and we don't want that
1582 Make_Identifier
(Sloc
(Token_Node
), Chars
(Token_Node
));
1584 -- And now scan out one or more statements
1586 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
1589 -- Normal case, just complain and skip to semicolon
1592 Set_Declaration_Expected
;
1593 Resync_Past_Semicolon
;
1600 -- Come here with an identifier list and colon scanned out. We now
1601 -- build the nodes for the declarative items. One node is built for
1602 -- each identifier in the list, with the type information being
1603 -- repeated by rescanning the appropriate section of source.
1605 -- First an error check, if we have two identifiers in a row, a likely
1606 -- possibility is that the first of the identifiers is an incorrectly
1609 if Token
= Tok_Identifier
then
1611 SS
: Saved_Scan_State
;
1615 Save_Scan_State
(SS
);
1616 Scan
; -- past initial identifier
1617 I2
:= (Token
= Tok_Identifier
);
1618 Restore_Scan_State
(SS
);
1622 (Bad_Spelling_Of
(Tok_Access
) or else
1623 Bad_Spelling_Of
(Tok_Aliased
) or else
1624 Bad_Spelling_Of
(Tok_Constant
))
1631 -- Loop through identifiers
1636 -- Check for some cases of misused Ada 95 keywords
1638 if Token_Name
= Name_Aliased
then
1639 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1640 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1641 Check_95_Keyword
(Tok_Aliased
, Tok_Constant
);
1646 if Token
= Tok_Constant
then
1647 Con_Loc
:= Token_Ptr
;
1648 Scan
; -- past CONSTANT
1650 -- Number declaration, initialization required
1652 Init_Expr
:= Init_Expr_Opt
;
1654 if Present
(Init_Expr
) then
1655 if Not_Null_Present
then
1657 ("`NOT NULL` not allowed in numeric expression");
1660 Decl_Node
:= New_Node
(N_Number_Declaration
, Ident_Sloc
);
1661 Set_Expression
(Decl_Node
, Init_Expr
);
1663 -- Constant object declaration
1666 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1667 Set_Constant_Present
(Decl_Node
, True);
1669 if Token_Name
= Name_Aliased
then
1670 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1671 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1674 if Token
= Tok_Aliased
then
1675 Error_Msg_SC
-- CODEFIX
1676 ("ALIASED should be before CONSTANT");
1677 Scan
; -- past ALIASED
1678 Set_Aliased_Present
(Decl_Node
, True);
1681 if Token
= Tok_Array
then
1682 Set_Object_Definition
1683 (Decl_Node
, P_Array_Type_Definition
);
1686 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1687 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1689 if Token
= Tok_Access
then
1690 Error_Msg_Ada_2005_Extension
1691 ("generalized use of anonymous access types");
1693 Set_Object_Definition
1694 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1696 Set_Object_Definition
1697 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1701 if Token
= Tok_Renames
then
1703 ("CONSTANT not permitted in renaming declaration",
1705 Scan
; -- Past renames
1706 Discard_Junk_Node
(P_Name
);
1712 elsif Token
= Tok_Exception
then
1713 Scan
; -- past EXCEPTION
1715 if Token_Is_Renames
then
1718 New_Node
(N_Exception_Renaming_Declaration
, Ident_Sloc
);
1719 Set_Name
(Decl_Node
, P_Qualified_Simple_Name_Resync
);
1722 Decl_Node
:= New_Node
(N_Exception_Declaration
, Prev_Token_Ptr
);
1725 -- Aliased case (note that an object definition is required)
1727 elsif Token
= Tok_Aliased
then
1728 Scan
; -- past ALIASED
1729 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1730 Set_Aliased_Present
(Decl_Node
, True);
1732 if Token
= Tok_Constant
then
1733 Scan
; -- past CONSTANT
1734 Set_Constant_Present
(Decl_Node
, True);
1737 if Token
= Tok_Array
then
1738 Set_Object_Definition
1739 (Decl_Node
, P_Array_Type_Definition
);
1742 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1743 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1745 -- Access definition (AI-406) or subtype indication
1747 if Token
= Tok_Access
then
1748 Error_Msg_Ada_2005_Extension
1749 ("generalized use of anonymous access types");
1751 Set_Object_Definition
1752 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1754 Set_Object_Definition
1755 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1761 elsif Token
= Tok_Array
then
1762 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1763 Set_Object_Definition
(Decl_Node
, P_Array_Type_Definition
);
1765 -- Ada 2005 (AI-254, AI-406)
1767 elsif Token
= Tok_Not
then
1769 -- OBJECT_DECLARATION ::=
1770 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1771 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
1772 -- [ASPECT_SPECIFICATIONS];
1773 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1774 -- ACCESS_DEFINITION [:= EXPRESSION]
1775 -- [ASPECT_SPECIFICATIONS];
1777 -- OBJECT_RENAMING_DECLARATION ::=
1778 -- DEFINING_IDENTIFIER :
1779 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME
1780 -- [ASPECT_SPECIFICATIONS];
1781 -- | DEFINING_IDENTIFIER :
1782 -- ACCESS_DEFINITION renames object_NAME
1783 -- [ASPECT_SPECIFICATIONS];
1785 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/423)
1787 if Token
= Tok_Access
then
1788 Error_Msg_Ada_2005_Extension
1789 ("generalized use of anonymous access types");
1791 Acc_Node
:= P_Access_Definition
(Not_Null_Present
);
1793 if Token
/= Tok_Renames
then
1794 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1795 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1798 Scan
; -- past renames
1801 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1802 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1803 Set_Name
(Decl_Node
, P_Name
);
1807 Type_Node
:= P_Subtype_Mark
;
1809 -- Object renaming declaration
1811 if Token_Is_Renames
then
1812 if Ada_Version
< Ada_2005
then
1814 ("`NOT NULL` not allowed in object renaming");
1817 -- Ada 2005 (AI-423): Object renaming declaration with
1818 -- a null exclusion.
1823 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1824 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1825 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1826 Set_Name
(Decl_Node
, P_Name
);
1829 -- Object declaration
1832 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1833 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1834 Set_Object_Definition
1836 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1838 -- RENAMES at this point means that we had the combination
1839 -- of a constraint on the Type_Node and renames, which is
1842 if Token_Is_Renames
then
1844 ("constraint not allowed in object renaming "
1846 Constraint
(Object_Definition
(Decl_Node
)));
1852 -- Ada 2005 (AI-230): Access Definition case
1854 elsif Token
= Tok_Access
then
1855 Error_Msg_Ada_2005_Extension
1856 ("generalized use of anonymous access types");
1858 Acc_Node
:= P_Access_Definition
(Null_Exclusion_Present
=> False);
1860 -- Object declaration with access definition, or renaming
1862 if Token
/= Tok_Renames
then
1863 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1864 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1867 Scan
; -- past renames
1870 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1871 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1872 Set_Name
(Decl_Node
, P_Name
);
1875 -- Subtype indication case
1878 Type_Node
:= P_Subtype_Mark
;
1880 -- Object renaming declaration
1882 if Token_Is_Renames
then
1885 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1886 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1887 Set_Name
(Decl_Node
, P_Name
);
1889 -- Object declaration
1892 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1893 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1894 Set_Object_Definition
1896 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1898 -- RENAMES at this point means that we had the combination of
1899 -- a constraint on the Type_Node and renames, which is illegal
1901 if Token_Is_Renames
then
1903 ("constraint not allowed in object renaming declaration",
1904 Constraint
(Object_Definition
(Decl_Node
)));
1910 -- Scan out initialization, allowed only for object declaration
1912 Init_Loc
:= Token_Ptr
;
1913 Init_Expr
:= Init_Expr_Opt
;
1915 if Present
(Init_Expr
) then
1916 if Nkind
(Decl_Node
) = N_Object_Declaration
then
1917 Set_Expression
(Decl_Node
, Init_Expr
);
1918 Set_Has_Init_Expression
(Decl_Node
);
1920 Error_Msg
("initialization not allowed here", Init_Loc
);
1924 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
1925 P_Aspect_Specifications
(Decl_Node
, Semicolon
=> False);
1927 -- Allow initialization expression to follow aspects (note that in
1928 -- this case P_Aspect_Specifications already issued an error msg).
1930 if Token
= Tok_Colon_Equal
then
1931 if Is_Non_Empty_List
(Aspect_Specifications
(Decl_Node
)) then
1933 ("aspect specifications must come after initialization "
1935 Sloc
(First
(Aspect_Specifications
(Decl_Node
))));
1938 -- In any case, the assignment symbol doesn't belong.
1940 Error_Msg
("misplaced assignment symbol", Scan_Ptr
);
1943 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
1944 Set_Has_Init_Expression
(Decl_Node
);
1947 -- Now scan out the semicolon, which we deferred above
1952 if Ident
< Num_Idents
then
1953 Set_More_Ids
(Decl_Node
, True);
1957 Set_Prev_Ids
(Decl_Node
, True);
1961 Append
(Decl_Node
, Decls
);
1962 exit Ident_Loop
when Ident
= Num_Idents
;
1963 Restore_Scan_State
(Scan_State
);
1966 end loop Ident_Loop
;
1969 end P_Identifier_Declarations
;
1971 -------------------------------
1972 -- 3.3.1 Object Declaration --
1973 -------------------------------
1975 -- OBJECT DECLARATION ::=
1976 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1977 -- SUBTYPE_INDICATION [:= EXPRESSION];
1978 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1979 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1980 -- | SINGLE_TASK_DECLARATION
1981 -- | SINGLE_PROTECTED_DECLARATION
1983 -- Cases starting with TASK are parsed by P_Task (9.1)
1984 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1985 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1987 -------------------------------------
1988 -- 3.3.1 Defining Identifier List --
1989 -------------------------------------
1991 -- DEFINING_IDENTIFIER_LIST ::=
1992 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1994 -- Always parsed by the construct in which it appears. See special
1995 -- section on "Handling of Defining Identifier Lists" in this unit.
1997 -------------------------------
1998 -- 3.3.2 Number Declaration --
1999 -------------------------------
2001 -- Parsed by P_Identifier_Declarations (3.3)
2003 -------------------------------------------------------------------------
2004 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
2005 -------------------------------------------------------------------------
2007 -- DERIVED_TYPE_DEFINITION ::=
2008 -- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
2009 -- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
2011 -- PRIVATE_EXTENSION_DECLARATION ::=
2012 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
2013 -- [abstract] [limited | synchronized]
2014 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
2015 -- with private [ASPECT_SPECIFICATIONS];
2017 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
2019 -- The caller has already scanned out the part up to the NEW, and Token
2020 -- either contains Tok_New (or ought to, if it doesn't this procedure
2021 -- will post an appropriate "NEW expected" message).
2023 -- Note: the caller is responsible for filling in the Sloc field of
2024 -- the returned node in the private extension declaration case as
2025 -- well as the stuff relating to the discriminant part.
2027 -- Error recovery: can raise Error_Resync;
2029 function P_Derived_Type_Def_Or_Private_Ext_Decl
return Node_Id
is
2030 Typedef_Node
: Node_Id
;
2031 Typedecl_Node
: Node_Id
;
2032 Not_Null_Present
: Boolean := False;
2035 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
2037 if Ada_Version
< Ada_2005
2038 and then Token
= Tok_Identifier
2039 and then Token_Name
= Name_Interface
2042 ("abstract interface is an Ada 2005 extension");
2043 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2048 if Token
= Tok_Abstract
then
2049 Error_Msg_SC
-- CODEFIX
2050 ("ABSTRACT must come before NEW, not after");
2054 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
2055 Set_Null_Exclusion_Present
(Typedef_Node
, Not_Null_Present
);
2056 Set_Subtype_Indication
(Typedef_Node
,
2057 P_Subtype_Indication
(Not_Null_Present
));
2059 -- Ada 2005 (AI-251): Deal with interfaces
2061 if Token
= Tok_And
then
2064 Error_Msg_Ada_2005_Extension
("abstract interface");
2066 Set_Interface_List
(Typedef_Node
, New_List
);
2069 Append
(P_Qualified_Simple_Name
, Interface_List
(Typedef_Node
));
2070 exit when Token
/= Tok_And
;
2074 if Token
/= Tok_With
then
2075 Error_Msg_SC
("WITH expected");
2080 -- Deal with record extension, note that we assume that a WITH is
2081 -- missing in the case of "type X is new Y record ..." or in the
2082 -- case of "type X is new Y null record".
2084 -- First make sure we don't have an aspect specification. If we do
2085 -- return now, so that our caller can check it (the WITH here is not
2086 -- part of a type extension).
2088 if Aspect_Specifications_Present
then
2089 return Typedef_Node
;
2091 -- OK, not an aspect specification, so continue test for extension
2093 elsif Token
in Tok_With | Tok_Record | Tok_Null
then
2094 T_With
; -- past WITH or give error message
2096 if Token
= Tok_Limited
then
2097 Error_Msg_SC
("LIMITED keyword not allowed in private extension");
2098 Scan
; -- ignore LIMITED
2101 -- Private extension declaration
2103 if Token
= Tok_Private
then
2104 Scan
; -- past PRIVATE
2106 -- Throw away the type definition node and build the type
2107 -- declaration node. Note the caller must set the Sloc,
2108 -- Discriminant_Specifications, Unknown_Discriminants_Present,
2109 -- and Defined_Identifier fields in the returned node.
2112 Make_Private_Extension_Declaration
(No_Location
,
2113 Defining_Identifier
=> Empty
,
2114 Subtype_Indication
=> Subtype_Indication
(Typedef_Node
),
2115 Abstract_Present
=> Abstract_Present
(Typedef_Node
),
2116 Interface_List
=> Interface_List
(Typedef_Node
));
2118 return Typedecl_Node
;
2120 -- Derived type definition with record extension part
2123 Set_Record_Extension_Part
(Typedef_Node
, P_Record_Definition
);
2124 return Typedef_Node
;
2127 -- Derived type definition with no record extension part
2130 return Typedef_Node
;
2132 end P_Derived_Type_Def_Or_Private_Ext_Decl
;
2134 ---------------------------
2135 -- 3.5 Range Constraint --
2136 ---------------------------
2138 -- RANGE_CONSTRAINT ::= range RANGE
2140 -- The caller has checked that the initial token is RANGE or some
2141 -- misspelling of it, or it may be absent completely (and a message
2142 -- has already been issued).
2144 -- Error recovery: cannot raise Error_Resync
2146 function P_Range_Constraint
return Node_Id
is
2147 Range_Node
: Node_Id
;
2150 Range_Node
:= New_Node
(N_Range_Constraint
, Token_Ptr
);
2152 -- Skip range keyword if present
2154 if Token
= Tok_Range
or else Bad_Spelling_Of
(Tok_Range
) then
2158 Set_Range_Expression
(Range_Node
, P_Range
);
2160 end P_Range_Constraint
;
2167 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2169 -- Note: the range that appears in a membership test is parsed by
2170 -- P_Range_Or_Subtype_Mark (3.5).
2172 -- Error recovery: cannot raise Error_Resync
2174 function P_Range
return Node_Id
is
2175 Expr_Node
: Node_Id
;
2176 Range_Node
: Node_Id
;
2179 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2181 if Expr_Form
= EF_Range_Attr
then
2184 elsif Token
= Tok_Dot_Dot
then
2185 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2186 Set_Low_Bound
(Range_Node
, Expr_Node
);
2188 Expr_Node
:= P_Expression
;
2189 Check_Simple_Expression
(Expr_Node
);
2190 Set_High_Bound
(Range_Node
, Expr_Node
);
2193 -- Anything else is an error
2196 T_Dot_Dot
; -- force missing .. message
2201 ----------------------------------
2202 -- 3.5 P_Range_Or_Subtype_Mark --
2203 ----------------------------------
2206 -- RANGE_ATTRIBUTE_REFERENCE
2207 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2209 -- This routine scans out the range or subtype mark that forms the right
2210 -- operand of a membership test (it is not used in any other contexts, and
2211 -- error messages are specialized with this knowledge in mind).
2213 -- Note: as documented in the Sinfo interface, although the syntax only
2214 -- allows a subtype mark, we in fact allow any simple expression to be
2215 -- returned from this routine. The semantics is responsible for issuing
2216 -- an appropriate message complaining if the argument is not a name.
2217 -- This simplifies the coding and error recovery processing in the
2218 -- parser, and in any case it is preferable not to consider this a
2219 -- syntax error and to continue with the semantic analysis.
2221 -- Error recovery: cannot raise Error_Resync
2223 function P_Range_Or_Subtype_Mark
2224 (Allow_Simple_Expression
: Boolean := False) return Node_Id
2226 Expr_Node
: Node_Id
;
2227 Range_Node
: Node_Id
;
2228 Save_Loc
: Source_Ptr
;
2230 -- Start of processing for P_Range_Or_Subtype_Mark
2233 -- Save location of possible junk parentheses
2235 Save_Loc
:= Token_Ptr
;
2237 -- Scan out either a simple expression or a range (this accepts more
2238 -- than is legal here, but as explained above, we like to allow more
2239 -- with a proper diagnostic, and in the case of a membership operation
2240 -- where sets are allowed, a simple expression is permissible anyway.
2242 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2246 if Expr_Form
= EF_Range_Attr
then
2249 -- Simple_Expression .. Simple_Expression
2251 elsif Token
= Tok_Dot_Dot
then
2252 Check_Simple_Expression
(Expr_Node
);
2253 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2254 Set_Low_Bound
(Range_Node
, Expr_Node
);
2256 Set_High_Bound
(Range_Node
, P_Simple_Expression
);
2259 -- Case of subtype mark (optionally qualified simple name or an
2260 -- attribute whose prefix is an optionally qualified simple name)
2262 elsif Expr_Form
= EF_Simple_Name
2263 or else Nkind
(Expr_Node
) = N_Attribute_Reference
2265 -- Check for error of range constraint after a subtype mark
2267 if Token
= Tok_Range
then
2268 Error_Msg_SC
("range constraint not allowed in membership test");
2272 -- Check for error of DIGITS or DELTA after a subtype mark
2274 elsif Token
in Tok_Digits | Tok_Delta
then
2276 ("accuracy definition not allowed in membership test");
2277 Scan
; -- past DIGITS or DELTA
2280 -- Attribute reference, may or may not be OK, but in any case we
2283 elsif Token
= Tok_Apostrophe
then
2284 return P_Subtype_Mark_Attribute
(Expr_Node
);
2286 -- OK case of simple name, just return it
2292 -- Simple expression case
2294 elsif Expr_Form
= EF_Simple
and then Allow_Simple_Expression
then
2297 -- Here we have some kind of error situation. Check for junk parens
2298 -- then return what we have, caller will deal with other errors.
2301 if Nkind
(Expr_Node
) in N_Subexpr
2302 and then Paren_Count
(Expr_Node
) /= 0
2304 Error_Msg
("|parentheses not allowed for subtype mark", Save_Loc
);
2305 Set_Paren_Count
(Expr_Node
, 0);
2310 end P_Range_Or_Subtype_Mark
;
2312 ----------------------------------------
2313 -- 3.5.1 Enumeration Type Definition --
2314 ----------------------------------------
2316 -- ENUMERATION_TYPE_DEFINITION ::=
2317 -- (ENUMERATION_LITERAL_SPECIFICATION
2318 -- {, ENUMERATION_LITERAL_SPECIFICATION})
2320 -- The caller has already scanned out the TYPE keyword
2322 -- Error recovery: can raise Error_Resync;
2324 function P_Enumeration_Type_Definition
return Node_Id
is
2325 Typedef_Node
: Node_Id
;
2328 Typedef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Token_Ptr
);
2329 Set_Literals
(Typedef_Node
, New_List
);
2334 Append
(P_Enumeration_Literal_Specification
, Literals
(Typedef_Node
));
2335 exit when not Comma_Present
;
2339 return Typedef_Node
;
2340 end P_Enumeration_Type_Definition
;
2342 ----------------------------------------------
2343 -- 3.5.1 Enumeration Literal Specification --
2344 ----------------------------------------------
2346 -- ENUMERATION_LITERAL_SPECIFICATION ::=
2347 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
2349 -- Error recovery: can raise Error_Resync
2351 function P_Enumeration_Literal_Specification
return Node_Id
is
2353 if Token
= Tok_Char_Literal
then
2354 return P_Defining_Character_Literal
;
2356 return P_Defining_Identifier
(C_Comma_Right_Paren
);
2358 end P_Enumeration_Literal_Specification
;
2360 ---------------------------------------
2361 -- 3.5.1 Defining_Character_Literal --
2362 ---------------------------------------
2364 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
2366 -- Error recovery: cannot raise Error_Resync
2368 -- The caller has checked that the current token is a character literal
2370 function P_Defining_Character_Literal
return Node_Id
is
2371 Literal_Node
: Node_Id
;
2373 Literal_Node
:= Token_Node
;
2374 Change_Character_Literal_To_Defining_Character_Literal
(Literal_Node
);
2375 Scan
; -- past character literal
2376 return Literal_Node
;
2377 end P_Defining_Character_Literal
;
2379 ------------------------------------
2380 -- 3.5.4 Integer Type Definition --
2381 ------------------------------------
2383 -- Parsed by P_Type_Declaration (3.2.1)
2385 -------------------------------------------
2386 -- 3.5.4 Signed Integer Type Definition --
2387 -------------------------------------------
2389 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
2390 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2392 -- Normally the initial token on entry is RANGE, but in some
2393 -- error conditions, the range token was missing and control is
2394 -- passed with Token pointing to first token of the first expression.
2396 -- Error recovery: cannot raise Error_Resync
2398 function P_Signed_Integer_Type_Definition
return Node_Id
is
2399 Typedef_Node
: Node_Id
;
2400 Expr_Node
: Node_Id
;
2403 Typedef_Node
:= New_Node
(N_Signed_Integer_Type_Definition
, Token_Ptr
);
2405 if Token
= Tok_Range
then
2409 Expr_Node
:= P_Expression_Or_Range_Attribute
;
2411 -- Range case (not permitted by the grammar, this is surprising but
2412 -- the grammar in the RM is as quoted above, and does not allow Range).
2414 if Expr_Form
= EF_Range_Attr
then
2416 ("Range attribute not allowed here, use First .. Last", Expr_Node
);
2417 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2418 Set_Attribute_Name
(Expr_Node
, Name_First
);
2419 Set_High_Bound
(Typedef_Node
, Copy_Separate_Tree
(Expr_Node
));
2420 Set_Attribute_Name
(High_Bound
(Typedef_Node
), Name_Last
);
2422 -- Normal case of explicit range
2425 Check_Simple_Expression
(Expr_Node
);
2426 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2428 Expr_Node
:= P_Expression
;
2429 Check_Simple_Expression
(Expr_Node
);
2430 Set_High_Bound
(Typedef_Node
, Expr_Node
);
2433 return Typedef_Node
;
2434 end P_Signed_Integer_Type_Definition
;
2436 ------------------------------------
2437 -- 3.5.4 Modular Type Definition --
2438 ------------------------------------
2440 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
2442 -- The caller has checked that the initial token is MOD
2444 -- Error recovery: cannot raise Error_Resync
2446 function P_Modular_Type_Definition
return Node_Id
is
2447 Typedef_Node
: Node_Id
;
2450 if Ada_Version
= Ada_83
then
2451 Error_Msg_SC
("(Ada 83) modular types not allowed");
2454 Typedef_Node
:= New_Node
(N_Modular_Type_Definition
, Token_Ptr
);
2456 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2458 -- Handle mod L..R cleanly
2460 if Token
= Tok_Dot_Dot
then
2461 Error_Msg_SC
("range not allowed for modular type");
2463 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2466 return Typedef_Node
;
2467 end P_Modular_Type_Definition
;
2469 ---------------------------------
2470 -- 3.5.6 Real Type Definition --
2471 ---------------------------------
2473 -- Parsed by P_Type_Declaration (3.2.1)
2475 --------------------------------------
2476 -- 3.5.7 Floating Point Definition --
2477 --------------------------------------
2479 -- FLOATING_POINT_DEFINITION ::=
2480 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2482 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
2484 -- The caller has checked that the initial token is DIGITS
2486 -- Error recovery: cannot raise Error_Resync
2488 function P_Floating_Point_Definition
return Node_Id
is
2489 Digits_Loc
: constant Source_Ptr
:= Token_Ptr
;
2491 Expr_Node
: Node_Id
;
2494 Scan
; -- past DIGITS
2495 Expr_Node
:= P_Expression_No_Right_Paren
;
2496 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2498 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
2500 if Token
= Tok_Delta
then
2501 Error_Msg_SC
-- CODEFIX
2502 ("|DELTA must come before DIGITS");
2503 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Digits_Loc
);
2505 Set_Delta_Expression
(Def_Node
, P_Expression_No_Right_Paren
);
2507 -- OK floating-point definition
2510 Def_Node
:= New_Node
(N_Floating_Point_Definition
, Digits_Loc
);
2513 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2514 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2516 end P_Floating_Point_Definition
;
2518 -------------------------------------
2519 -- 3.5.7 Real Range Specification --
2520 -------------------------------------
2522 -- REAL_RANGE_SPECIFICATION ::=
2523 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2525 -- Error recovery: cannot raise Error_Resync
2527 function P_Real_Range_Specification_Opt
return Node_Id
is
2528 Specification_Node
: Node_Id
;
2529 Expr_Node
: Node_Id
;
2532 if Token
= Tok_Range
then
2533 Specification_Node
:=
2534 New_Node
(N_Real_Range_Specification
, Token_Ptr
);
2536 Expr_Node
:= P_Expression_No_Right_Paren
;
2537 Check_Simple_Expression
(Expr_Node
);
2538 Set_Low_Bound
(Specification_Node
, Expr_Node
);
2540 Expr_Node
:= P_Expression_No_Right_Paren
;
2541 Check_Simple_Expression
(Expr_Node
);
2542 Set_High_Bound
(Specification_Node
, Expr_Node
);
2543 return Specification_Node
;
2547 end P_Real_Range_Specification_Opt
;
2549 -----------------------------------
2550 -- 3.5.9 Fixed Point Definition --
2551 -----------------------------------
2553 -- FIXED_POINT_DEFINITION ::=
2554 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
2556 -- ORDINARY_FIXED_POINT_DEFINITION ::=
2557 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
2559 -- DECIMAL_FIXED_POINT_DEFINITION ::=
2560 -- delta static_EXPRESSION
2561 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2563 -- The caller has checked that the initial token is DELTA
2565 -- Error recovery: cannot raise Error_Resync
2567 function P_Fixed_Point_Definition
return Node_Id
is
2568 Delta_Node
: Node_Id
;
2569 Delta_Loc
: Source_Ptr
;
2571 Expr_Node
: Node_Id
;
2574 Delta_Loc
:= Token_Ptr
;
2576 Delta_Node
:= P_Expression_No_Right_Paren
;
2577 Check_Simple_Expression_In_Ada_83
(Delta_Node
);
2579 if Token
= Tok_Digits
then
2580 if Ada_Version
= Ada_83
then
2581 Error_Msg_SC
("(Ada 83) decimal fixed type not allowed!");
2584 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Delta_Loc
);
2585 Scan
; -- past DIGITS
2586 Expr_Node
:= P_Expression_No_Right_Paren
;
2587 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2588 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2591 Def_Node
:= New_Node
(N_Ordinary_Fixed_Point_Definition
, Delta_Loc
);
2593 -- Range is required in ordinary fixed point case
2595 if Token
/= Tok_Range
then
2596 Error_Msg_AP
("range must be given for fixed-point type");
2601 Set_Delta_Expression
(Def_Node
, Delta_Node
);
2602 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2604 end P_Fixed_Point_Definition
;
2606 --------------------------------------------
2607 -- 3.5.9 Ordinary Fixed Point Definition --
2608 --------------------------------------------
2610 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2612 -------------------------------------------
2613 -- 3.5.9 Decimal Fixed Point Definition --
2614 -------------------------------------------
2616 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2618 ------------------------------
2619 -- 3.5.9 Digits Constraint --
2620 ------------------------------
2622 -- DIGITS_CONSTRAINT ::=
2623 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2625 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2627 -- The caller has checked that the initial token is DIGITS
2629 function P_Digits_Constraint
return Node_Id
is
2630 Constraint_Node
: Node_Id
;
2631 Expr_Node
: Node_Id
;
2634 Constraint_Node
:= New_Node
(N_Digits_Constraint
, Token_Ptr
);
2635 Scan
; -- past DIGITS
2636 Expr_Node
:= P_Expression
;
2637 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2638 Set_Digits_Expression
(Constraint_Node
, Expr_Node
);
2640 if Token
= Tok_Range
then
2641 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2644 return Constraint_Node
;
2645 end P_Digits_Constraint
;
2647 -----------------------------
2648 -- 3.5.9 Delta Constraint --
2649 -----------------------------
2651 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2653 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2655 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2656 -- (also true in formal modes).
2658 -- The caller has checked that the initial token is DELTA
2660 -- Error recovery: cannot raise Error_Resync
2662 function P_Delta_Constraint
return Node_Id
is
2663 Constraint_Node
: Node_Id
;
2664 Expr_Node
: Node_Id
;
2667 Constraint_Node
:= New_Node
(N_Delta_Constraint
, Token_Ptr
);
2669 Expr_Node
:= P_Expression
;
2670 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2672 Set_Delta_Expression
(Constraint_Node
, Expr_Node
);
2674 if Token
= Tok_Range
then
2675 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2678 return Constraint_Node
;
2679 end P_Delta_Constraint
;
2681 --------------------------------
2682 -- 3.6 Array Type Definition --
2683 --------------------------------
2685 -- ARRAY_TYPE_DEFINITION ::=
2686 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2688 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2689 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2690 -- COMPONENT_DEFINITION
2692 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2694 -- CONSTRAINED_ARRAY_DEFINITION ::=
2695 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2696 -- COMPONENT_DEFINITION
2698 -- DISCRETE_SUBTYPE_DEFINITION ::=
2699 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2701 -- COMPONENT_DEFINITION ::=
2702 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2704 -- The caller has checked that the initial token is ARRAY
2706 -- Error recovery: can raise Error_Resync
2708 function P_Array_Type_Definition
return Node_Id
is
2709 Array_Loc
: Source_Ptr
;
2710 CompDef_Node
: Node_Id
;
2712 Not_Null_Present
: Boolean := False;
2713 Subs_List
: List_Id
;
2714 Scan_State
: Saved_Scan_State
;
2715 Aliased_Present
: Boolean := False;
2717 procedure P_Index_Subtype_Def_With_Fixed_Lower_Bound
2718 (Subtype_Mark
: Node_Id
);
2719 -- Parse an unconstrained index range with a fixed lower bound:
2720 -- subtype_mark range <expression> .. <>
2721 -- This procedure creates a subtype_indication node for the index.
2723 --------------------------------------------
2724 -- P_Index_Range_With_Fixed_Lower_Bound --
2725 --------------------------------------------
2727 procedure P_Index_Subtype_Def_With_Fixed_Lower_Bound
2728 (Subtype_Mark
: Node_Id
)
2730 Low_Expr_Node
: constant Node_Id
:= P_Expression
;
2731 High_Expr_Node
: Node_Id
;
2732 Indic_Node
: Node_Id
;
2733 Constr_Node
: Node_Id
;
2734 Range_Node
: Node_Id
;
2737 T_Dot_Dot
; -- Error if no ..
2739 -- A box is required at this point, and we'll set the upper bound to
2740 -- the same expression as the lower bound (see further below), to
2741 -- avoid problems with trying to analyze an Empty node. Analysis can
2742 -- still tell that this is a fixed-lower-bound range because the
2743 -- index is represented by a subtype_indication in an unconstrained
2744 -- array type definition.
2746 if Token
= Tok_Box
then
2748 High_Expr_Node
:= Low_Expr_Node
;
2750 -- Error if no <> was found, and try to parse an expression since
2751 -- it's likely one was given in place of the <>.
2754 Error_Msg_AP
-- CODEFIX
2755 ("missing ""'<'>""");
2757 High_Expr_Node
:= P_Expression
;
2760 Constr_Node
:= New_Node
(N_Range_Constraint
, Token_Ptr
);
2761 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2762 Set_Range_Expression
(Constr_Node
, Range_Node
);
2764 Check_Simple_Expression
(Low_Expr_Node
);
2766 Set_Low_Bound
(Range_Node
, Low_Expr_Node
);
2767 Set_High_Bound
(Range_Node
, High_Expr_Node
);
2770 New_Node
(N_Subtype_Indication
, Sloc
(Subtype_Mark
));
2771 Set_Subtype_Mark
(Indic_Node
, Check_Subtype_Mark
(Subtype_Mark
));
2772 Set_Constraint
(Indic_Node
, Constr_Node
);
2774 Append
(Indic_Node
, Subs_List
);
2775 end P_Index_Subtype_Def_With_Fixed_Lower_Bound
;
2779 Is_Constrained_Array_Def
: Boolean := True;
2780 Subtype_Mark_Node
: Node_Id
;
2782 -- Start of processing for P_Array_Type_Definition
2785 Array_Loc
:= Token_Ptr
;
2787 Subs_List
:= New_List
;
2790 -- It's quite tricky to disentangle these two possibilities, so we do
2791 -- a prescan to determine which case we have and then reset the scan.
2792 -- The prescan skips past possible subtype mark tokens.
2794 Save_Scan_State
(Scan_State
); -- just after paren
2796 while Token
in Token_Class_Desig
or else
2797 Token
= Tok_Dot
or else
2798 Token
= Tok_Apostrophe
-- because of 'BASE, 'CLASS
2803 -- If we end up on RANGE <> then we have the unconstrained case. We
2804 -- will also allow the RANGE to be omitted, just to improve error
2805 -- handling for a case like array (integer <>) of integer;
2807 Scan
; -- past possible RANGE or <>
2809 if (Prev_Token
= Tok_Range
and then Token
= Tok_Box
) or else
2810 Prev_Token
= Tok_Box
2812 Def_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Array_Loc
);
2813 Restore_Scan_State
(Scan_State
); -- to first subtype mark
2815 Is_Constrained_Array_Def
:= False;
2817 -- Now parse a sequence of indexes where each is either of form:
2818 -- <subtype_mark> range <>
2820 -- <subtype_mark> range <expr> .. <>
2822 -- The latter syntax indicates an index with a fixed lower bound,
2823 -- and only applies when extensions are enabled (-gnatX).
2826 Subtype_Mark_Node
:= P_Subtype_Mark_Resync
;
2830 -- Normal "subtype_mark range <>" form, so simply append
2831 -- the subtype reference.
2833 if Token
= Tok_Box
then
2834 Append
(Subtype_Mark_Node
, Subs_List
);
2837 -- Fixed-lower-bound form ("subtype_mark range <expr> .. <>")
2840 P_Index_Subtype_Def_With_Fixed_Lower_Bound
(Subtype_Mark_Node
);
2842 Error_Msg_GNAT_Extension
("fixed-lower-bound array", Token_Ptr
,
2843 Is_Core_Extension
=> True);
2846 exit when Token
in Tok_Right_Paren | Tok_Of
;
2850 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2852 -- If we don't have "range <>", then "range" will be followed by an
2853 -- expression, for either a normal range or a fixed-lower-bound range
2854 -- ("<exp> .. <>"), and we have to know which, in order to determine
2855 -- whether to parse the indexes for an unconstrained or constrained
2856 -- array definition. So we look ahead to see if "<>" follows the "..".
2857 -- If not, then this must be a discrete_subtype_indication for a
2858 -- constrained_array_definition, which will be processed further below.
2860 elsif Prev_Token
= Tok_Range
2861 and then Token
not in Tok_Right_Paren | Tok_Comma
2863 -- If we have an expression followed by "..", then scan farther
2864 -- and check for "<>" to see if we have a fixed-lower-bound range.
2866 if P_Expression_Or_Range_Attribute
/= Error
2867 and then Expr_Form
/= EF_Range_Attr
2868 and then Token
= Tok_Dot_Dot
2872 -- If there's a "<>", then we know we have a fixed-lower-bound
2873 -- index, so we can proceed with parsing an unconstrained array
2876 if Token
= Tok_Box
then
2877 Is_Constrained_Array_Def
:= False;
2880 New_Node
(N_Unconstrained_Array_Definition
, Array_Loc
);
2882 Restore_Scan_State
(Scan_State
); -- to first subtype mark
2884 -- Now parse a sequence of indexes where each is either of
2886 -- <subtype_mark> range <>
2888 -- <subtype_mark> range <expr> .. <>
2890 -- The latter indicates an index with a fixed lower bound,
2891 -- and only applies when extensions are enabled (-gnatX).
2894 Subtype_Mark_Node
:= P_Subtype_Mark_Resync
;
2898 -- Normal "subtype_mark range <>" form, so simply append
2899 -- the subtype reference.
2901 if Token
= Tok_Box
then
2902 Append
(Subtype_Mark_Node
, Subs_List
);
2905 -- This must be an index of form:
2906 -- <subtype_mark> range <expr> .. <>"
2909 P_Index_Subtype_Def_With_Fixed_Lower_Bound
2910 (Subtype_Mark_Node
);
2912 Error_Msg_GNAT_Extension
2913 ("fixed-lower-bound array", Token_Ptr
,
2914 Is_Core_Extension
=> True);
2917 exit when Token
in Tok_Right_Paren | Tok_Of
;
2921 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2926 if Is_Constrained_Array_Def
then
2927 Def_Node
:= New_Node
(N_Constrained_Array_Definition
, Array_Loc
);
2928 Restore_Scan_State
(Scan_State
); -- to first discrete range
2931 Append
(P_Discrete_Subtype_Definition
, Subs_List
);
2932 exit when not Comma_Present
;
2935 Set_Discrete_Subtype_Definitions
(Def_Node
, Subs_List
);
2941 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
2943 if Token_Name
= Name_Aliased
then
2944 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
2947 if Token
= Tok_Aliased
then
2948 Aliased_Present
:= True;
2949 Scan
; -- past ALIASED
2952 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
2954 -- Ada 2005 (AI-230): Access Definition case
2956 if Token
= Tok_Access
then
2957 Error_Msg_Ada_2005_Extension
2958 ("generalized use of anonymous access types");
2960 -- AI95-406 makes "aliased" legal (and useless) in this context so
2961 -- followintg code which used to be needed is commented out.
2963 -- if Aliased_Present then
2964 -- Error_Msg_SP ("ALIASED not allowed here");
2967 Set_Subtype_Indication
(CompDef_Node
, Empty
);
2968 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2969 Set_Access_Definition
(CompDef_Node
,
2970 P_Access_Definition
(Not_Null_Present
));
2973 Set_Access_Definition
(CompDef_Node
, Empty
);
2974 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2975 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
2976 Set_Subtype_Indication
(CompDef_Node
,
2977 P_Subtype_Indication
(Not_Null_Present
));
2980 Set_Component_Definition
(Def_Node
, CompDef_Node
);
2983 end P_Array_Type_Definition
;
2985 -----------------------------------------
2986 -- 3.6 Unconstrained Array Definition --
2987 -----------------------------------------
2989 -- Parsed by P_Array_Type_Definition (3.6)
2991 ---------------------------------------
2992 -- 3.6 Constrained Array Definition --
2993 ---------------------------------------
2995 -- Parsed by P_Array_Type_Definition (3.6)
2997 --------------------------------------
2998 -- 3.6 Discrete Subtype Definition --
2999 --------------------------------------
3001 -- DISCRETE_SUBTYPE_DEFINITION ::=
3002 -- discrete_SUBTYPE_INDICATION | RANGE
3004 -- Note: the discrete subtype definition appearing in a constrained
3005 -- array definition is parsed by P_Array_Type_Definition (3.6)
3007 -- Error recovery: cannot raise Error_Resync
3009 function P_Discrete_Subtype_Definition
return Node_Id
is
3011 -- The syntax of a discrete subtype definition is identical to that
3012 -- of a discrete range, so we simply share the same parsing code.
3014 return P_Discrete_Range
;
3015 end P_Discrete_Subtype_Definition
;
3017 -------------------------------
3018 -- 3.6 Component Definition --
3019 -------------------------------
3021 -- For the array case, parsed by P_Array_Type_Definition (3.6)
3022 -- For the record case, parsed by P_Component_Declaration (3.8)
3024 -----------------------------
3025 -- 3.6.1 Index Constraint --
3026 -----------------------------
3028 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
3030 ---------------------------
3031 -- 3.6.1 Discrete Range --
3032 ---------------------------
3034 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
3036 -- The possible forms for a discrete range are:
3038 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
3039 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
3040 -- Range_Attribute (RANGE, 3.5)
3041 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
3043 -- Error recovery: cannot raise Error_Resync
3045 function P_Discrete_Range
return Node_Id
is
3046 Expr_Node
: Node_Id
;
3047 Range_Node
: Node_Id
;
3050 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
3052 if Expr_Form
= EF_Range_Attr
then
3055 elsif Token
= Tok_Range
then
3056 if Expr_Form
/= EF_Simple_Name
then
3057 Error_Msg_SC
("range must be preceded by subtype mark");
3060 return P_Subtype_Indication
(Expr_Node
);
3062 -- Check Expression .. Expression case
3064 elsif Token
= Tok_Dot_Dot
then
3065 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
3066 Set_Low_Bound
(Range_Node
, Expr_Node
);
3069 Style
.Check_Xtra_Parens
(Expr_Node
);
3073 Expr_Node
:= P_Expression
;
3074 Check_Simple_Expression
(Expr_Node
);
3075 Set_High_Bound
(Range_Node
, Expr_Node
);
3077 -- If Expr_Node (ignoring parentheses) is not a simple expression
3078 -- then emit a style check.
3081 and then Nkind
(Expr_Node
) not in N_Op_Boolean | N_Subexpr
3083 Style
.Check_Xtra_Parens
(Expr_Node
);
3088 -- Otherwise we must have a subtype mark, or an Ada 2012 iterator
3090 elsif Expr_Form
= EF_Simple_Name
then
3093 -- The domain of iteration must be a name. Semantics will determine that
3094 -- the expression has the proper form.
3096 elsif Ada_Version
>= Ada_2012
then
3099 -- If incorrect, complain that we expect ..
3105 end P_Discrete_Range
;
3107 ----------------------------
3108 -- 3.7 Discriminant Part --
3109 ----------------------------
3111 -- DISCRIMINANT_PART ::=
3112 -- UNKNOWN_DISCRIMINANT_PART
3113 -- | KNOWN_DISCRIMINANT_PART
3115 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
3116 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
3118 ------------------------------------
3119 -- 3.7 Unknown Discriminant Part --
3120 ------------------------------------
3122 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
3124 -- If no unknown discriminant part is present, then False is returned,
3125 -- otherwise the unknown discriminant is scanned out and True is returned.
3127 -- Error recovery: cannot raise Error_Resync
3129 function P_Unknown_Discriminant_Part_Opt
return Boolean is
3130 Scan_State
: Saved_Scan_State
;
3133 -- If <> right now, then this is missing left paren
3135 if Token
= Tok_Box
then
3138 -- If not <> or left paren, then definitely no box
3140 elsif Token
/= Tok_Left_Paren
then
3143 -- Left paren, so might be a box after it
3146 Save_Scan_State
(Scan_State
);
3147 Scan
; -- past the left paren
3149 if Token
/= Tok_Box
then
3150 Restore_Scan_State
(Scan_State
);
3155 -- We are now pointing to the box
3157 if Ada_Version
= Ada_83
then
3158 Error_Msg_SC
("(Ada 83) unknown discriminant not allowed!");
3161 Scan
; -- past the box
3162 U_Right_Paren
; -- must be followed by right paren
3164 end P_Unknown_Discriminant_Part_Opt
;
3166 ----------------------------------
3167 -- 3.7 Known Discriminant Part --
3168 ----------------------------------
3170 -- KNOWN_DISCRIMINANT_PART ::=
3171 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
3173 -- DISCRIMINANT_SPECIFICATION ::=
3174 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
3175 -- [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATION]
3176 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
3177 -- [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATION]
3179 -- If no known discriminant part is present, then No_List is returned
3181 -- Error recovery: cannot raise Error_Resync
3183 function P_Known_Discriminant_Part_Opt
return List_Id
is
3184 Specification_Node
: Node_Id
;
3185 Specification_List
: List_Id
;
3186 Ident_Sloc
: Source_Ptr
;
3187 Scan_State
: Saved_Scan_State
;
3189 Not_Null_Present
: Boolean;
3192 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3193 -- This array holds the list of defining identifiers. The upper bound
3194 -- of 4096 is intended to be essentially infinite, and we do not even
3195 -- bother to check for it being exceeded.
3198 if Token
= Tok_Left_Paren
then
3199 Specification_List
:= New_List
;
3201 P_Pragmas_Misplaced
;
3203 Specification_Loop
: loop
3205 Ident_Sloc
:= Token_Ptr
;
3206 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3209 while Comma_Present
loop
3210 Num_Idents
:= Num_Idents
+ 1;
3211 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3214 -- If there are multiple identifiers, we repeatedly scan the
3215 -- type and initialization expression information by resetting
3216 -- the scan pointer (so that we get completely separate trees
3217 -- for each occurrence).
3219 if Num_Idents
> 1 then
3220 Save_Scan_State
(Scan_State
);
3225 -- Loop through defining identifiers in list
3229 Specification_Node
:=
3230 New_Node
(N_Discriminant_Specification
, Ident_Sloc
);
3231 Set_Defining_Identifier
(Specification_Node
, Idents
(Ident
));
3232 Not_Null_Present
:= -- Ada 2005 (AI-231, AI-447)
3233 P_Null_Exclusion
(Allow_Anonymous_In_95
=> True);
3235 if Token
= Tok_Access
then
3236 if Ada_Version
= Ada_83
then
3238 ("(Ada 83) access discriminant not allowed!");
3241 Set_Discriminant_Type
3242 (Specification_Node
,
3243 P_Access_Definition
(Not_Null_Present
));
3245 -- Catch ouf-of-order keywords
3247 elsif Token
= Tok_Constant
then
3250 if Token
= Tok_Access
then
3251 Error_Msg_SC
-- CODEFIX
3252 ("ACCESS must come before CONSTANT");
3253 Set_Discriminant_Type
3254 (Specification_Node
,
3255 P_Access_Definition
(Not_Null_Present
));
3258 Error_Msg_SC
("misplaced CONSTANT");
3262 Set_Discriminant_Type
3263 (Specification_Node
, P_Subtype_Mark
);
3265 Set_Null_Exclusion_Present
-- Ada 2005 (AI-231)
3266 (Specification_Node
, Not_Null_Present
);
3270 (Specification_Node
, Init_Expr_Opt
(True));
3272 if Token
= Tok_With
then
3273 P_Aspect_Specifications
(Specification_Node
, False);
3277 Set_Prev_Ids
(Specification_Node
, True);
3280 if Ident
< Num_Idents
then
3281 Set_More_Ids
(Specification_Node
, True);
3284 Append
(Specification_Node
, Specification_List
);
3285 exit Ident_Loop
when Ident
= Num_Idents
;
3287 Restore_Scan_State
(Scan_State
);
3289 end loop Ident_Loop
;
3291 exit Specification_Loop
when Token
/= Tok_Semicolon
;
3293 P_Pragmas_Misplaced
;
3294 end loop Specification_Loop
;
3297 return Specification_List
;
3302 end P_Known_Discriminant_Part_Opt
;
3304 -------------------------------------
3305 -- 3.7 Discriminant Specification --
3306 -------------------------------------
3308 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
3310 -----------------------------
3311 -- 3.7 Default Expression --
3312 -----------------------------
3314 -- Always parsed (simply as an Expression) by the parent construct
3316 ------------------------------------
3317 -- 3.7.1 Discriminant Constraint --
3318 ------------------------------------
3320 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
3322 --------------------------------------------------------
3323 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
3324 --------------------------------------------------------
3326 -- DISCRIMINANT_CONSTRAINT ::=
3327 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
3329 -- DISCRIMINANT_ASSOCIATION ::=
3330 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3333 -- This routine parses either an index or a discriminant constraint. As
3334 -- is clear from the above grammar, it is often possible to clearly
3335 -- determine which of the two possibilities we have, but there are
3336 -- cases (those in which we have a series of expressions of the same
3337 -- syntactic form as subtype indications), where we cannot tell. Since
3338 -- this means that in any case the semantic phase has to distinguish
3339 -- between the two, there is not much point in the parser trying to
3340 -- distinguish even those cases where the difference is clear. In any
3341 -- case, if we have a situation like:
3343 -- (A => 123, 235 .. 500)
3345 -- it is not clear which of the two items is the wrong one, better to
3346 -- let the semantic phase give a clear message. Consequently, this
3347 -- routine in general returns a list of items which can be either
3348 -- discrete ranges or discriminant associations.
3350 -- The caller has checked that the initial token is a left paren
3352 -- Error recovery: can raise Error_Resync
3354 function P_Index_Or_Discriminant_Constraint
return Node_Id
is
3355 Scan_State
: Saved_Scan_State
;
3356 Constr_Node
: Node_Id
;
3357 Constr_List
: List_Id
;
3358 Expr_Node
: Node_Id
;
3359 Result_Node
: Node_Id
;
3362 Result_Node
:= New_Node
(N_Index_Or_Discriminant_Constraint
, Token_Ptr
);
3364 Constr_List
:= New_List
;
3365 Set_Constraints
(Result_Node
, Constr_List
);
3367 -- The two syntactic forms are a little mixed up, so what we are doing
3368 -- here is looking at the first entry to determine which case we have
3370 -- A discriminant constraint is a list of discriminant associations,
3371 -- which have one of the following possible forms:
3375 -- Id | Id | .. | Id => Expression
3377 -- An index constraint is a list of discrete ranges which have one
3378 -- of the following possible forms:
3381 -- Subtype_Mark range Range
3383 -- Simple_Expression .. Simple_Expression
3385 -- Loop through discriminants in list
3388 -- Check cases of Id => Expression or Id | Id => Expression
3390 if Token
= Tok_Identifier
then
3391 Save_Scan_State
(Scan_State
); -- at Id
3394 if Token
in Tok_Arrow | Tok_Vertical_Bar
then
3395 Restore_Scan_State
(Scan_State
); -- to Id
3396 Append
(P_Discriminant_Association
, Constr_List
);
3399 Restore_Scan_State
(Scan_State
); -- to Id
3403 -- Otherwise scan out an expression and see what we have got
3405 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3407 if Expr_Form
= EF_Range_Attr
then
3408 Append
(Expr_Node
, Constr_List
);
3410 elsif Token
= Tok_Range
then
3411 if Expr_Form
/= EF_Simple_Name
then
3412 Error_Msg_SC
("subtype mark required before RANGE");
3415 Append
(P_Subtype_Indication
(Expr_Node
), Constr_List
);
3418 -- Check Simple_Expression .. Simple_Expression case
3420 elsif Token
= Tok_Dot_Dot
then
3421 Check_Simple_Expression
(Expr_Node
);
3422 Constr_Node
:= New_Node
(N_Range
, Token_Ptr
);
3423 Set_Low_Bound
(Constr_Node
, Expr_Node
);
3426 -- If the upper bound is given by "<>", this is an index for
3427 -- a fixed-lower-bound subtype, so set the expression to Empty
3428 -- for now (it will be set to the ranges maximum upper bound
3429 -- later during analysis), and scan to the next token.
3431 if Token
= Tok_Box
then
3432 Error_Msg_GNAT_Extension
("fixed-lower-bound array", Token_Ptr
,
3433 Is_Core_Extension
=> True);
3438 -- Otherwise parse the range's upper bound expression
3441 Expr_Node
:= P_Expression
;
3442 Check_Simple_Expression
(Expr_Node
);
3445 Set_High_Bound
(Constr_Node
, Expr_Node
);
3446 Append
(Constr_Node
, Constr_List
);
3449 -- Case of an expression which could be either form
3452 Append
(Expr_Node
, Constr_List
);
3456 -- Here with a single entry scanned
3459 exit when not Comma_Present
;
3465 end P_Index_Or_Discriminant_Constraint
;
3467 -------------------------------------
3468 -- 3.7.1 Discriminant Association --
3469 -------------------------------------
3471 -- DISCRIMINANT_ASSOCIATION ::=
3472 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3475 -- This routine is used only when the name list is present and the caller
3476 -- has already checked this (by scanning ahead and repositioning the
3479 -- Error_Recovery: cannot raise Error_Resync;
3481 function P_Discriminant_Association
return Node_Id
is
3482 Discr_Node
: Node_Id
;
3483 Names_List
: List_Id
;
3484 Ident_Sloc
: Source_Ptr
;
3487 Ident_Sloc
:= Token_Ptr
;
3488 Names_List
:= New_List
;
3491 Append
(P_Identifier
(C_Vertical_Bar_Arrow
), Names_List
);
3492 exit when Token
/= Tok_Vertical_Bar
;
3496 Discr_Node
:= New_Node
(N_Discriminant_Association
, Ident_Sloc
);
3497 Set_Selector_Names
(Discr_Node
, Names_List
);
3499 Set_Expression
(Discr_Node
, P_Expression
);
3501 end P_Discriminant_Association
;
3503 ---------------------------------
3504 -- 3.8 Record Type Definition --
3505 ---------------------------------
3507 -- RECORD_TYPE_DEFINITION ::=
3508 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3510 -- There is no node in the tree for a record type definition. Instead
3511 -- a record definition node appears, with possible Abstract_Present,
3512 -- Tagged_Present, and Limited_Present flags set appropriately.
3514 ----------------------------
3515 -- 3.8 Record Definition --
3516 ----------------------------
3518 -- RECORD_DEFINITION ::=
3524 -- Note: in the case where a record definition node is used to represent
3525 -- a record type definition, the caller sets the Tagged_Present and
3526 -- Limited_Present flags in the resulting N_Record_Definition node as
3529 -- Note that the RECORD token at the start may be missing in certain
3530 -- error situations, so this function is expected to post the error
3532 -- Error recovery: can raise Error_Resync
3534 function P_Record_Definition
return Node_Id
is
3536 procedure Catch_Out_Of_Order_Keywords
(Keyword
: String);
3537 -- Catch ouf-of-order keywords in a record definition
3539 ---------------------------------
3540 -- Catch_Out_Of_Order_Keywords --
3541 ---------------------------------
3543 procedure Catch_Out_Of_Order_Keywords
(Keyword
: String) is
3546 if Token
= Tok_Abstract
then
3547 Error_Msg_SC
-- CODEFIX
3548 ("ABSTRACT must come before " & Keyword
);
3549 Scan
; -- past ABSTRACT
3551 elsif Token
= Tok_Tagged
then
3552 Error_Msg_SC
-- CODEFIX
3553 ("TAGGED must come before " & Keyword
);
3554 Scan
; -- past TAGGED
3556 elsif Token
= Tok_Limited
then
3557 Error_Msg_SC
-- CODEFIX
3558 ("LIMITED must come before " & Keyword
);
3559 Scan
; -- past LIMITED
3565 end Catch_Out_Of_Order_Keywords
;
3569 -- Start of processing for P_Record_Definition
3572 Inside_Record_Definition
:= True;
3573 Rec_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3577 if Token
= Tok_Null
then
3580 Catch_Out_Of_Order_Keywords
("NULL");
3582 Set_Null_Present
(Rec_Node
, True);
3583 Catch_Out_Of_Order_Keywords
("RECORD");
3585 -- Catch incomplete declaration to prevent cascaded errors, see
3586 -- ACATS B393002 for an example.
3588 elsif Token
= Tok_Semicolon
then
3589 Error_Msg_AP
("missing record definition");
3591 -- Case starting with RECORD keyword. Build scope stack entry. For the
3592 -- column, we use the first non-blank character on the line, to deal
3593 -- with situations such as:
3599 -- which is not official RM indentation, but is not uncommon usage, and
3600 -- in particular is standard GNAT coding style, so handle it nicely.
3604 Scopes
(Scope
.Last
).Etyp
:= E_Record
;
3605 Scopes
(Scope
.Last
).Ecol
:= Start_Column
;
3606 Scopes
(Scope
.Last
).Sloc
:= Token_Ptr
;
3607 Scopes
(Scope
.Last
).Labl
:= Error
;
3608 Scopes
(Scope
.Last
).Junk
:= (Token
/= Tok_Record
);
3611 Catch_Out_Of_Order_Keywords
("RECORD");
3613 Set_Component_List
(Rec_Node
, P_Component_List
);
3616 exit when Check_End
;
3617 Discard_Junk_Node
(P_Component_List
);
3621 Inside_Record_Definition
:= False;
3623 end P_Record_Definition
;
3625 -------------------------
3626 -- 3.8 Component List --
3627 -------------------------
3629 -- COMPONENT_LIST ::=
3630 -- COMPONENT_ITEM {COMPONENT_ITEM}
3631 -- | {COMPONENT_ITEM} VARIANT_PART
3634 -- Error recovery: cannot raise Error_Resync
3636 function P_Component_List
return Node_Id
is
3637 Component_List_Node
: Node_Id
;
3638 Decls_List
: List_Id
;
3639 Scan_State
: Saved_Scan_State
;
3640 Null_Loc
: Source_Ptr
;
3643 Component_List_Node
:= New_Node
(N_Component_List
, Token_Ptr
);
3644 Decls_List
:= New_List
;
3648 if Token
= Tok_Null
then
3649 Null_Loc
:= Token_Ptr
;
3652 P_Pragmas_Opt
(Decls_List
);
3654 -- If we have an END or WHEN now, everything is fine, otherwise we
3655 -- complain about the null, ignore it, and scan for more components.
3657 if Token
in Tok_End | Tok_When
then
3658 Set_Null_Present
(Component_List_Node
, True);
3659 return Component_List_Node
;
3661 Error_Msg
("NULL component only allowed in null record", Null_Loc
);
3665 -- Scan components for non-null record
3667 P_Pragmas_Opt
(Decls_List
);
3669 if Token
/= Tok_Case
then
3671 P_Component_Items
(Decls_List
);
3672 P_Pragmas_Opt
(Decls_List
);
3674 exit when Token
in Tok_End | Tok_Case | Tok_When
;
3676 -- We are done if we do not have an identifier. However, if we
3677 -- have a misspelled reserved identifier that is in a column to
3678 -- the right of the record definition, we will treat it as an
3679 -- identifier. It turns out to be too dangerous in practice to
3680 -- accept such a mis-spelled identifier which does not have this
3681 -- additional clue that confirms the incorrect spelling.
3683 if Token
/= Tok_Identifier
then
3684 if Start_Column
> Scopes
(Scope
.Last
).Ecol
3685 and then Is_Reserved_Identifier
3687 Save_Scan_State
(Scan_State
); -- at reserved id
3688 Scan
; -- possible reserved id
3690 if Token
in Tok_Comma | Tok_Colon
then
3691 Restore_Scan_State
(Scan_State
);
3692 Scan_Reserved_Identifier
(Force_Msg
=> True);
3694 -- Note reserved identifier used as field name after all
3695 -- because not followed by colon or comma.
3698 Restore_Scan_State
(Scan_State
);
3702 -- Non-identifier that definitely was not reserved id
3711 if Token
= Tok_Case
then
3712 Set_Variant_Part
(Component_List_Node
, P_Variant_Part
);
3714 -- Check for junk after variant part
3716 if Token
= Tok_Identifier
then
3717 Save_Scan_State
(Scan_State
);
3718 Scan
; -- past identifier
3720 if Token
= Tok_Colon
then
3721 Restore_Scan_State
(Scan_State
);
3722 Error_Msg_SC
("component may not follow variant part");
3723 Discard_Junk_Node
(P_Component_List
);
3725 elsif Token
= Tok_Case
then
3726 Restore_Scan_State
(Scan_State
);
3727 Error_Msg_SC
("only one variant part allowed in a record");
3728 Discard_Junk_Node
(P_Component_List
);
3731 Restore_Scan_State
(Scan_State
);
3736 Set_Component_Items
(Component_List_Node
, Decls_List
);
3737 return Component_List_Node
;
3738 end P_Component_List
;
3740 -------------------------
3741 -- 3.8 Component Item --
3742 -------------------------
3744 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3746 -- COMPONENT_DECLARATION ::=
3747 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3748 -- [:= DEFAULT_EXPRESSION]
3749 -- [ASPECT_SPECIFICATIONS];
3751 -- COMPONENT_DEFINITION ::=
3752 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3754 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3755 -- the scan is positioned past the following semicolon.
3757 -- Note: we do not yet allow representation clauses to appear as component
3758 -- items, do we need to add this capability sometime in the future ???
3760 procedure P_Component_Items
(Decls
: List_Id
) is
3761 Aliased_Present
: Boolean := False;
3762 CompDef_Node
: Node_Id
;
3763 Decl_Node
: Node_Id
:= Empty
; -- initialize to prevent warning
3764 Scan_State
: Saved_Scan_State
;
3765 Not_Null_Present
: Boolean := False;
3768 Ident_Sloc
: Source_Ptr
;
3770 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3771 -- This array holds the list of defining identifiers. The upper bound
3772 -- of 4096 is intended to be essentially infinite, and we do not even
3773 -- bother to check for it being exceeded.
3776 if Token
/= Tok_Identifier
then
3777 Error_Msg_SC
("component declaration expected");
3778 Resync_Past_Semicolon
;
3782 Ident_Sloc
:= Token_Ptr
;
3784 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3787 while Comma_Present
loop
3788 Num_Idents
:= Num_Idents
+ 1;
3789 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3792 -- If there are multiple identifiers, we repeatedly scan the
3793 -- type and initialization expression information by resetting
3794 -- the scan pointer (so that we get completely separate trees
3795 -- for each occurrence).
3797 if Num_Idents
> 1 then
3798 Save_Scan_State
(Scan_State
);
3803 -- Loop through defining identifiers in list
3808 -- The following block is present to catch Error_Resync
3809 -- which causes the parse to be reset past the semicolon
3812 Decl_Node
:= New_Node
(N_Component_Declaration
, Ident_Sloc
);
3813 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
3815 if Token
= Tok_Constant
then
3816 Error_Msg_SC
("constant component not permitted");
3820 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
3822 if Token_Name
= Name_Aliased
then
3823 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
3826 if Token
= Tok_Aliased
then
3827 Aliased_Present
:= True;
3828 Scan
; -- past ALIASED
3831 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
3833 -- Ada 2005 (AI-230): Access Definition case
3835 if Token
= Tok_Access
then
3836 Error_Msg_Ada_2005_Extension
3837 ("generalized use of anonymous access types");
3839 -- AI95-406 makes "aliased" legal (and useless) here, so the
3840 -- following code which used to be required is commented out.
3842 -- if Aliased_Present then
3843 -- Error_Msg_SP ("ALIASED not allowed here");
3846 Set_Subtype_Indication
(CompDef_Node
, Empty
);
3847 Set_Aliased_Present
(CompDef_Node
, False);
3848 Set_Access_Definition
(CompDef_Node
,
3849 P_Access_Definition
(Not_Null_Present
));
3852 Set_Access_Definition
(CompDef_Node
, Empty
);
3853 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
3854 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
3856 if Token
= Tok_Array
then
3857 Error_Msg_SC
("anonymous array not allowed as component");
3861 Set_Subtype_Indication
(CompDef_Node
,
3862 P_Subtype_Indication
(Not_Null_Present
));
3865 Set_Component_Definition
(Decl_Node
, CompDef_Node
);
3866 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
3869 Set_Prev_Ids
(Decl_Node
, True);
3872 if Ident
< Num_Idents
then
3873 Set_More_Ids
(Decl_Node
, True);
3876 Append
(Decl_Node
, Decls
);
3879 when Error_Resync
=>
3880 if Token
/= Tok_End
then
3881 Resync_Past_Semicolon
;
3885 exit Ident_Loop
when Ident
= Num_Idents
;
3887 Restore_Scan_State
(Scan_State
);
3889 end loop Ident_Loop
;
3891 P_Aspect_Specifications
(Decl_Node
);
3892 end P_Component_Items
;
3894 --------------------------------
3895 -- 3.8 Component Declaration --
3896 --------------------------------
3898 -- Parsed by P_Component_Items (3.8)
3900 -------------------------
3901 -- 3.8.1 Variant Part --
3902 -------------------------
3905 -- case discriminant_DIRECT_NAME is
3910 -- The caller has checked that the initial token is CASE
3912 -- Error recovery: cannot raise Error_Resync
3914 function P_Variant_Part
return Node_Id
is
3915 Variant_Part_Node
: Node_Id
;
3916 Variants_List
: List_Id
;
3917 Case_Node
: Node_Id
;
3920 Variant_Part_Node
:= New_Node
(N_Variant_Part
, Token_Ptr
);
3922 Scopes
(Scope
.Last
).Etyp
:= E_Case
;
3923 Scopes
(Scope
.Last
).Sloc
:= Token_Ptr
;
3924 Scopes
(Scope
.Last
).Ecol
:= Start_Column
;
3927 Case_Node
:= P_Expression
;
3928 Set_Name
(Variant_Part_Node
, Case_Node
);
3930 if Nkind
(Case_Node
) /= N_Identifier
then
3931 Set_Name
(Variant_Part_Node
, Error
);
3932 Error_Msg
("discriminant name expected", Sloc
(Case_Node
));
3934 elsif Paren_Count
(Case_Node
) /= 0 then
3936 ("|discriminant name may not be parenthesized",
3938 Set_Paren_Count
(Case_Node
, 0);
3942 Variants_List
:= New_List
;
3943 P_Pragmas_Opt
(Variants_List
);
3945 -- Test missing variant
3947 if Token
= Tok_End
then
3948 Error_Msg_BC
("WHEN expected (must have at least one variant)");
3950 Append
(P_Variant
, Variants_List
);
3953 -- Loop through variants, note that we allow if in place of when,
3954 -- this error will be detected and handled in P_Variant.
3957 P_Pragmas_Opt
(Variants_List
);
3959 if Token
not in Tok_When | Tok_If | Tok_Others
then
3960 exit when Check_End
;
3963 Append
(P_Variant
, Variants_List
);
3966 Set_Variants
(Variant_Part_Node
, Variants_List
);
3967 return Variant_Part_Node
;
3970 --------------------
3972 --------------------
3975 -- when DISCRETE_CHOICE_LIST =>
3978 -- Error recovery: cannot raise Error_Resync
3980 -- The initial token on entry is either WHEN, IF or OTHERS
3982 function P_Variant
return Node_Id
is
3983 Variant_Node
: Node_Id
;
3986 -- Special check to recover nicely from use of IF in place of WHEN
3988 if Token
= Tok_If
then
3995 Variant_Node
:= New_Node
(N_Variant
, Prev_Token_Ptr
);
3996 Set_Discrete_Choices
(Variant_Node
, P_Discrete_Choice_List
);
3998 Set_Component_List
(Variant_Node
, P_Component_List
);
3999 return Variant_Node
;
4002 ---------------------------------
4003 -- 3.8.1 Discrete Choice List --
4004 ---------------------------------
4006 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
4008 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
4010 -- Note: in Ada 83, the expression must be a simple expression
4012 -- Error recovery: cannot raise Error_Resync
4014 function P_Discrete_Choice_List
return List_Id
is
4016 Expr_Node
: Node_Id
:= Empty
; -- initialize to prevent warning
4017 Choice_Node
: Node_Id
;
4020 Choices
:= New_List
;
4022 if Token
= Tok_Others
then
4023 Append
(New_Node
(N_Others_Choice
, Token_Ptr
), Choices
);
4024 Scan
; -- past OTHERS
4028 -- Scan out expression or range attribute
4030 Expr_Node
:= P_Expression_Or_Range_Attribute
;
4031 Ignore
(Tok_Right_Paren
);
4033 if Token
= Tok_Colon
4034 and then Nkind
(Expr_Node
) = N_Identifier
4036 Error_Msg_SP
("label not permitted in this context");
4041 elsif Expr_Form
= EF_Range_Attr
then
4042 Append
(Expr_Node
, Choices
);
4046 elsif Token
= Tok_Dot_Dot
then
4047 Check_Simple_Expression
(Expr_Node
);
4048 Choice_Node
:= New_Node
(N_Range
, Token_Ptr
);
4049 Set_Low_Bound
(Choice_Node
, Expr_Node
);
4051 Expr_Node
:= P_Expression_No_Right_Paren
;
4052 Check_Simple_Expression
(Expr_Node
);
4053 Set_High_Bound
(Choice_Node
, Expr_Node
);
4054 Append
(Choice_Node
, Choices
);
4056 -- Simple name, must be subtype, so range allowed
4058 elsif Expr_Form
= EF_Simple_Name
then
4059 if Token
= Tok_Range
then
4060 Append
(P_Subtype_Indication
(Expr_Node
), Choices
);
4062 elsif Token
in Token_Class_Consk
then
4064 ("the only constraint allowed here " &
4065 "is a range constraint");
4066 Discard_Junk_Node
(P_Constraint_Opt
);
4067 Append
(Expr_Node
, Choices
);
4070 Append
(Expr_Node
, Choices
);
4076 -- In Ada 2012 mode, the expression must be a simple
4077 -- expression. The reason for this restriction (i.e. going
4078 -- back to the Ada 83 rule) is to avoid ambiguities when set
4079 -- membership operations are allowed, consider the
4082 -- when A in 1 .. 10 | 12 =>
4084 -- This is ambiguous without parentheses, so we require one
4085 -- of the following two parenthesized forms to disambiguate:
4087 -- one of the following:
4089 -- when (A in 1 .. 10 | 12) =>
4090 -- when (A in 1 .. 10) | 12 =>
4092 -- To solve this, in Ada 2012 mode, we disallow the use of
4093 -- membership operations in expressions in choices.
4095 -- Technically in the grammar, the expression must match the
4096 -- grammar for restricted expression.
4098 if Ada_Version
>= Ada_2012
then
4099 Check_Restricted_Expression
(Expr_Node
);
4101 -- In Ada 83 mode, the syntax required a simple expression
4104 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
4107 Append
(Expr_Node
, Choices
);
4111 when Error_Resync
=>
4117 if Token
= Tok_Comma
then
4118 if Nkind
(Expr_Node
) = N_Iterated_Component_Association
then
4124 if Token
= Tok_Vertical_Bar
then
4125 Error_Msg_SP
-- CODEFIX
4126 ("|extra "","" ignored");
4130 Error_Msg_SP
-- CODEFIX
4131 (""","" should be ""'|""");
4135 exit when Token
/= Tok_Vertical_Bar
;
4142 end P_Discrete_Choice_List
;
4144 ----------------------------
4145 -- 3.8.1 Discrete Choice --
4146 ----------------------------
4148 -- Parsed by P_Discrete_Choice_List (3.8.1)
4150 ----------------------------------
4151 -- 3.9.1 Record Extension Part --
4152 ----------------------------------
4154 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
4156 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
4158 --------------------------------------
4159 -- 3.9.4 Interface Type Definition --
4160 --------------------------------------
4162 -- INTERFACE_TYPE_DEFINITION ::=
4163 -- [limited | task | protected | synchronized] interface
4164 -- [and INTERFACE_LIST]
4166 -- Error recovery: cannot raise Error_Resync
4168 function P_Interface_Type_Definition
4169 (Abstract_Present
: Boolean) return Node_Id
4171 Typedef_Node
: Node_Id
;
4174 Error_Msg_Ada_2005_Extension
("abstract interface");
4176 if Abstract_Present
then
4178 ("ABSTRACT not allowed in interface type definition " &
4182 Scan
; -- past INTERFACE
4184 -- Ada 2005 (AI-345): In case of interfaces with a null list of
4185 -- interfaces we build a record_definition node.
4187 if Token
= Tok_Semicolon
or else Aspect_Specifications_Present
then
4188 Typedef_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
4190 Set_Abstract_Present
(Typedef_Node
);
4191 Set_Tagged_Present
(Typedef_Node
);
4192 Set_Null_Present
(Typedef_Node
);
4193 Set_Interface_Present
(Typedef_Node
);
4195 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
4196 -- a list of interfaces we build a derived_type_definition node. This
4197 -- simplifies the semantic analysis (and hence further maintenance)
4200 if Token
/= Tok_And
then
4201 Error_Msg_AP
("AND expected");
4206 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
4208 Set_Abstract_Present
(Typedef_Node
);
4209 Set_Interface_Present
(Typedef_Node
);
4210 Set_Subtype_Indication
(Typedef_Node
, P_Qualified_Simple_Name
);
4212 Set_Record_Extension_Part
(Typedef_Node
,
4213 New_Node
(N_Record_Definition
, Token_Ptr
));
4214 Set_Null_Present
(Record_Extension_Part
(Typedef_Node
));
4216 if Token
= Tok_And
then
4217 Set_Interface_List
(Typedef_Node
, New_List
);
4221 Append
(P_Qualified_Simple_Name
,
4222 Interface_List
(Typedef_Node
));
4223 exit when Token
/= Tok_And
;
4229 return Typedef_Node
;
4230 end P_Interface_Type_Definition
;
4232 ----------------------------------
4233 -- 3.10 Access Type Definition --
4234 ----------------------------------
4236 -- ACCESS_TYPE_DEFINITION ::=
4237 -- ACCESS_TO_OBJECT_DEFINITION
4238 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
4240 -- ACCESS_TO_OBJECT_DEFINITION ::=
4241 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
4243 -- GENERAL_ACCESS_MODIFIER ::= all | constant
4245 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4246 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4247 -- | [NULL_EXCLUSION] access [protected] function
4248 -- PARAMETER_AND_RESULT_PROFILE
4250 -- PARAMETER_PROFILE ::= [FORMAL_PART]
4252 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
4254 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
4255 -- parsed the null_exclusion part and has also removed the ACCESS token;
4256 -- otherwise the caller has just checked that the initial token is ACCESS
4258 -- Error recovery: can raise Error_Resync
4260 function P_Access_Type_Definition
4261 (Header_Already_Parsed
: Boolean := False) return Node_Id
4263 procedure Check_Junk_Subprogram_Name
;
4264 -- Used in access to subprogram definition cases to check for an
4265 -- identifier or operator symbol that does not belong.
4267 --------------------------------
4268 -- Check_Junk_Subprogram_Name --
4269 --------------------------------
4271 procedure Check_Junk_Subprogram_Name
is
4272 Saved_State
: Saved_Scan_State
;
4275 if Token
in Tok_Identifier | Tok_Operator_Symbol
then
4276 Save_Scan_State
(Saved_State
);
4277 Scan
; -- past possible junk subprogram name
4279 if Token
in Tok_Left_Paren | Tok_Semicolon
then
4280 Error_Msg_SP
("unexpected subprogram name ignored");
4282 Restore_Scan_State
(Saved_State
);
4285 end Check_Junk_Subprogram_Name
;
4287 Access_Loc
: constant Source_Ptr
:= Token_Ptr
;
4288 Prot_Flag
: Boolean;
4289 Not_Null_Present
: Boolean := False;
4290 Not_Null_Subtype
: Boolean := False;
4291 Not_Null_Subtype_Loc
: Source_Ptr
; -- loc of second "not null"
4292 Type_Def_Node
: Node_Id
;
4293 Result_Not_Null
: Boolean;
4294 Result_Node
: Node_Id
;
4296 -- Start of processing for P_Access_Type_Definition
4299 if not Header_Already_Parsed
then
4300 -- NOT NULL ACCESS... is a common form of access definition. ACCESS
4301 -- NOT NULL... is certainly rare, but syntactically legal. NOT NULL
4302 -- ACCESS NOT NULL... is rarer yet, and also legal. The last two
4303 -- cases are only meaningful if the following subtype indication
4304 -- denotes an access type. We check below for "not null procedure"
4305 -- and "not null function"; in the access-to-object case it is a
4306 -- semantic check. The flag Not_Null_Subtype indicates that this
4307 -- second null exclusion is present in the access type definition.
4309 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4311 if Token
/= Tok_Access
then
4317 Scan
; -- past ACCESS
4319 Not_Null_Subtype_Loc
:= Token_Ptr
;
4320 Not_Null_Subtype
:= P_Null_Exclusion
; -- Might also appear
4323 if Token_Name
= Name_Protected
then
4324 Check_95_Keyword
(Tok_Protected
, Tok_Procedure
);
4325 Check_95_Keyword
(Tok_Protected
, Tok_Function
);
4328 Prot_Flag
:= (Token
= Tok_Protected
);
4331 Scan
; -- past PROTECTED
4333 if Token
not in Tok_Procedure | Tok_Function
then
4334 Error_Msg_SC
-- CODEFIX
4335 ("FUNCTION or PROCEDURE expected");
4339 -- Access-to-subprogram case
4341 if Token
in Tok_Procedure | Tok_Function
then
4343 -- Check for "not null [protected] procedure" and "not null
4344 -- [protected] function".
4346 if Not_Null_Subtype
then
4348 ("null exclusion must apply to access type",
4349 Not_Null_Subtype_Loc
);
4353 if Token
= Tok_Procedure
then
4354 if Ada_Version
= Ada_83
then
4355 Error_Msg_SC
("(Ada 83) access to procedure not allowed!");
4358 Type_Def_Node
:= New_Node
(N_Access_Procedure_Definition
, Access_Loc
);
4359 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4360 Scan
; -- past PROCEDURE
4361 Check_Junk_Subprogram_Name
;
4362 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4363 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4365 elsif Token
= Tok_Function
then
4366 if Ada_Version
= Ada_83
then
4367 Error_Msg_SC
("(Ada 83) access to function not allowed!");
4370 Type_Def_Node
:= New_Node
(N_Access_Function_Definition
, Access_Loc
);
4371 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4372 Scan
; -- past FUNCTION
4373 Check_Junk_Subprogram_Name
;
4374 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4375 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4378 Result_Not_Null
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4380 -- Ada 2005 (AI-318-02)
4382 if Token
= Tok_Access
then
4383 Error_Msg_Ada_2005_Extension
("anonymous access result type");
4385 Result_Node
:= P_Access_Definition
(Result_Not_Null
);
4388 Result_Node
:= P_Subtype_Mark
;
4391 -- A null exclusion on the result type must be recorded in a flag
4392 -- distinct from the one used for the access-to-subprogram type's
4395 Set_Null_Exclusion_In_Return_Present
4396 (Type_Def_Node
, Result_Not_Null
);
4399 Set_Result_Definition
(Type_Def_Node
, Result_Node
);
4401 -- Access-to-object case
4404 Type_Def_Node
:= New_Node
(N_Access_To_Object_Definition
, Access_Loc
);
4405 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4406 Set_Null_Excluding_Subtype
(Type_Def_Node
, Not_Null_Subtype
);
4408 if Token
in Tok_All | Tok_Constant
then
4409 if Ada_Version
= Ada_83
then
4410 Error_Msg_SC
("(Ada 83) access modifier not allowed!");
4413 if Token
= Tok_All
then
4414 Set_All_Present
(Type_Def_Node
, True);
4417 Set_Constant_Present
(Type_Def_Node
, True);
4420 Scan
; -- past ALL or CONSTANT
4423 Set_Subtype_Indication
(Type_Def_Node
,
4424 P_Subtype_Indication
(Not_Null_Present
));
4427 return Type_Def_Node
;
4428 end P_Access_Type_Definition
;
4430 ---------------------------------------
4431 -- 3.10 Access To Object Definition --
4432 ---------------------------------------
4434 -- Parsed by P_Access_Type_Definition (3.10)
4436 -----------------------------------
4437 -- 3.10 General Access Modifier --
4438 -----------------------------------
4440 -- Parsed by P_Access_Type_Definition (3.10)
4442 -------------------------------------------
4443 -- 3.10 Access To Subprogram Definition --
4444 -------------------------------------------
4446 -- Parsed by P_Access_Type_Definition (3.10)
4448 -----------------------------
4449 -- 3.10 Access Definition --
4450 -----------------------------
4452 -- ACCESS_DEFINITION ::=
4453 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4454 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
4456 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4457 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4458 -- | [NULL_EXCLUSION] access [protected] function
4459 -- PARAMETER_AND_RESULT_PROFILE
4461 -- The caller has parsed the null-exclusion part and it has also checked
4462 -- that the next token is ACCESS
4464 -- Error recovery: cannot raise Error_Resync
4466 function P_Access_Definition
4467 (Null_Exclusion_Present
: Boolean) return Node_Id
4470 Subp_Node
: Node_Id
;
4473 Def_Node
:= New_Node
(N_Access_Definition
, Token_Ptr
);
4474 Scan
; -- past ACCESS
4476 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
4478 if Token
in Tok_Protected | Tok_Procedure | Tok_Function
then
4479 Error_Msg_Ada_2005_Extension
("access-to-subprogram");
4481 Subp_Node
:= P_Access_Type_Definition
(Header_Already_Parsed
=> True);
4482 Set_Null_Exclusion_Present
(Subp_Node
, Null_Exclusion_Present
);
4483 Set_Access_To_Subprogram_Definition
(Def_Node
, Subp_Node
);
4485 -- Ada 2005 (AI-231)
4486 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4489 Set_Null_Exclusion_Present
(Def_Node
, Null_Exclusion_Present
);
4491 if Token
= Tok_All
then
4492 if Ada_Version
< Ada_2005
then
4494 ("ALL not permitted for anonymous access type");
4498 Set_All_Present
(Def_Node
);
4500 elsif Token
= Tok_Constant
then
4501 Error_Msg_Ada_2005_Extension
("access-to-constant");
4503 Scan
; -- past CONSTANT
4504 Set_Constant_Present
(Def_Node
);
4507 Set_Subtype_Mark
(Def_Node
, P_Subtype_Mark
);
4512 end P_Access_Definition
;
4514 -----------------------------------------
4515 -- 3.10.1 Incomplete Type Declaration --
4516 -----------------------------------------
4518 -- Parsed by P_Type_Declaration (3.2.1)
4520 ----------------------------
4521 -- 3.11 Declarative Part --
4522 ----------------------------
4524 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
4526 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Item
4527 -- handles errors, and returns cleanly after an error has occurred)
4529 function P_Declarative_Part
return List_Id
is
4530 Decls
: constant List_Id
:= New_List
;
4532 -- Indicate no bad declarations detected yet. This will be reset by
4533 -- P_Declarative_Items if a bad declaration is discovered.
4535 Missing_Begin_Msg
:= No_Error_Msg
;
4537 -- Get rid of active SIS entry from outer scope. This means we will
4538 -- miss some nested cases, but it doesn't seem worth the effort. See
4539 -- discussion in Par for further details
4541 SIS_Entry_Active
:= False;
4544 (Decls
, Declare_Expression
=> False,
4545 In_Spec
=> False, In_Statements
=> False);
4547 -- Get rid of active SIS entry which is left set only if we scanned a
4548 -- procedure declaration and have not found the body. We could give
4549 -- an error message, but that really would be usurping the role of
4550 -- semantic analysis (this really is a missing body case).
4552 SIS_Entry_Active
:= False;
4554 end P_Declarative_Part
;
4556 ----------------------------
4557 -- 3.11 Declarative Item --
4558 ----------------------------
4560 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4562 -- Can return Error if a junk declaration is found, or Empty if no
4563 -- declaration is found (i.e. a token ending declarations, such as
4564 -- BEGIN or END is encountered).
4566 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4567 -- then the scan is set past the next semicolon and Error is returned.
4569 procedure P_Declarative_Item
4572 Declare_Expression
: Boolean;
4574 In_Statements
: Boolean)
4576 Scan_State
: Saved_Scan_State
;
4581 -- In -gnatg mode, we don't want a "bad indentation" error inside a
4582 -- declare_expression.
4584 if Style_Check
and not Declare_Expression
then
4585 Style
.Check_Indentation
;
4595 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4600 -- Check for loop (premature statement)
4602 Save_Scan_State
(Scan_State
);
4606 Is_Statement
: Boolean := True;
4608 if Token
= Tok_Identifier
then
4609 Scan
; -- past identifier
4610 if Token
in Tok_Use | Tok_Apostrophe
then
4611 Is_Statement
:= False;
4612 elsif Token
= Tok_Dot
then
4614 if Token
= Tok_Identifier
then
4616 Is_Statement
:= Token
in Tok_In | Tok_Of
;
4620 Is_Statement
:= False;
4623 Restore_Scan_State
(Scan_State
);
4625 if Is_Statement
then
4626 if not In_Statements
then
4627 Statement_When_Declaration_Expected
4628 (Decls
, Done
, In_Spec
);
4633 Append
(P_Representation_Clause
, Decls
);
4639 Append
(P_Generic
, Decls
);
4641 when Tok_Identifier
=>
4644 -- Special check for misuse of overriding not in Ada 2005 mode
4646 if Token_Name
= Name_Overriding
4647 and then not Next_Token_Is
(Tok_Colon
)
4649 Error_Msg_SC
("overriding indicator is an Ada 2005 extension");
4650 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4652 Token
:= Tok_Overriding
;
4653 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4655 -- Normal case, no overriding, or overriding followed by colon
4658 P_Identifier_Declarations
(Decls
, Done
, In_Spec
, In_Statements
);
4663 Append
(P_Package
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4666 -- If we see a pragma and In_Statements is true, we want to let
4667 -- the statement-parser deal with it.
4669 if In_Statements
then
4672 Append
(P_Pragma
, Decls
);
4675 when Tok_Protected
=>
4677 Scan
; -- past PROTECTED
4678 Append
(P_Protected
, Decls
);
4682 Append
(P_Subtype_Declaration
, Decls
);
4687 Append
(P_Task
, Decls
);
4691 Append
(P_Type_Declaration
, Decls
);
4695 P_Use_Clause
(Decls
);
4700 if Aspect_Specifications_Present
(Strict
=> True) then
4702 -- If we are after a semicolon, complain that it was ignored.
4703 -- But we don't really ignore it, since we dump the aspects,
4704 -- so we make the error message a normal fatal message which
4705 -- will inhibit semantic analysis anyway).
4707 if Prev_Token
= Tok_Semicolon
then
4708 Error_Msg_SP
-- CODEFIX
4709 ("extra "";"" ignored");
4711 -- If not just past semicolon, just complain that aspects are
4712 -- not allowed at this point.
4715 Error_Msg_SC
("aspect specifications not allowed here");
4718 -- Assume that this is a misplaced aspect specification within
4719 -- a declarative list. After discarding the misplaced aspects
4720 -- we can continue the scan.
4723 Dummy_Node
: constant Node_Id
:=
4724 New_Node
(N_Package_Specification
, Token_Ptr
);
4725 pragma Warnings
(Off
, Dummy_Node
);
4726 -- Dummy node to attach aspect specifications to. We will
4727 -- then throw them away.
4730 P_Aspect_Specifications
(Dummy_Node
, Semicolon
=> True);
4733 -- Here if not aspect specifications case
4736 Error_Msg_SC
("WITH can only appear in context clause");
4740 -- BEGIN terminates the scan of a sequence of declarations unless
4741 -- there is a missing subprogram body, see section on handling
4742 -- semicolon in place of IS. We only treat the begin as satisfying
4743 -- the subprogram declaration if it falls in the expected column
4747 if SIS_Entry_Active
and then Start_Column
>= SIS_Ecol
then
4749 -- Here we have the case where a BEGIN is encountered during
4750 -- declarations in a declarative part, or at the outer level,
4751 -- and there is a subprogram declaration outstanding for which
4752 -- no body has been supplied. This is the case where we assume
4753 -- that the semicolon in the subprogram declaration should
4754 -- really have been is. The active SIS entry describes the
4755 -- subprogram declaration. On return the declaration has been
4756 -- modified to become a body.
4759 Specification_Node
: Node_Id
;
4760 Decl_Node
: Node_Id
;
4761 Body_Node
: Node_Id
;
4764 -- First issue the error message. If we had a missing
4765 -- semicolon in the declaration, then change the message
4766 -- to <missing "is">
4768 if SIS_Missing_Semicolon_Message
/= No_Error_Msg
then
4769 Change_Error_Text
-- Replace: "missing "";"" "
4770 (SIS_Missing_Semicolon_Message
, "missing ""is""");
4772 -- Otherwise we saved the semicolon position, so complain
4775 Error_Msg
-- CODEFIX
4776 ("|"";"" should be IS", SIS_Semicolon_Sloc
);
4779 -- The next job is to fix up any declarations that occurred
4780 -- between the procedure header and the BEGIN. These got
4781 -- chained to the outer declarative region (immediately
4782 -- after the procedure declaration) and they should be
4783 -- chained to the subprogram itself, which is a body
4784 -- rather than a spec.
4786 Specification_Node
:= Specification
(SIS_Declaration_Node
);
4787 Change_Node
(SIS_Declaration_Node
, N_Subprogram_Body
);
4788 Body_Node
:= SIS_Declaration_Node
;
4789 Set_Specification
(Body_Node
, Specification_Node
);
4790 Set_Declarations
(Body_Node
, New_List
);
4793 Decl_Node
:= Remove_Next
(Body_Node
);
4794 exit when Decl_Node
= Empty
;
4795 Append
(Decl_Node
, Declarations
(Body_Node
));
4798 -- Now make the scope table entry for the Begin-End and
4802 Scopes
(Scope
.Last
).Sloc
:= SIS_Sloc
;
4803 Scopes
(Scope
.Last
).Etyp
:= E_Name
;
4804 Scopes
(Scope
.Last
).Ecol
:= SIS_Ecol
;
4805 Scopes
(Scope
.Last
).Labl
:= SIS_Labl
;
4806 Scopes
(Scope
.Last
).Lreq
:= False;
4807 SIS_Entry_Active
:= False;
4809 Set_Handled_Statement_Sequence
(Body_Node
,
4810 P_Handled_Sequence_Of_Statements
);
4811 End_Statements
(Handled_Statement_Sequence
(Body_Node
));
4818 -- Normally an END terminates the scan for basic declarative items.
4819 -- The one exception is END RECORD, which is probably left over from
4823 Save_Scan_State
(Scan_State
); -- at END
4826 if Token
= Tok_Record
then
4827 Error_Msg_SP
("no RECORD for this `end record`!");
4828 Scan
; -- past RECORD
4831 -- This might happen because of misplaced aspect specification.
4832 -- After discarding the misplaced aspects we can continue the
4836 Restore_Scan_State
(Scan_State
); -- to END
4840 -- The following tokens which can only be the start of a statement
4841 -- are considered to end a declarative part (i.e. we have a missing
4842 -- BEGIN situation). We are fairly conservative in making this
4843 -- judgment, because it is a real mess to go into statement mode
4844 -- prematurely in response to a junk declaration.
4859 -- If we parsing declarations in a sequence of statements, we want
4860 -- to let the caller continue parsing statements.
4862 if In_Statements
then
4865 -- Otherwise, give an error. But before we decide that it's a
4866 -- statement, check for a reserved word misused as an identifier.
4868 elsif Is_Reserved_Identifier
then
4869 Save_Scan_State
(Scan_State
);
4870 Scan
; -- past the token
4872 -- If reserved identifier not followed by colon or comma, then
4873 -- this is most likely an assignment statement to the bad id.
4875 if Token
not in Tok_Colon | Tok_Comma
then
4876 Restore_Scan_State
(Scan_State
);
4877 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4879 -- Otherwise we have a declaration of the bad id
4882 Restore_Scan_State
(Scan_State
);
4883 Scan_Reserved_Identifier
(Force_Msg
=> True);
4884 P_Identifier_Declarations
4885 (Decls
, Done
, In_Spec
, In_Statements
);
4888 -- If not reserved identifier, then it's an incorrectly placed a
4892 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4895 -- The token RETURN may well also signal a missing BEGIN situation,
4896 -- however, we never let it end the declarative part, because it
4897 -- might also be part of a half-baked function declaration. If we are
4898 -- In_Statements, then let the caller parse it; otherwise, it's an
4902 if In_Statements
then
4905 Error_Msg_SC
("misplaced RETURN statement");
4909 -- PRIVATE definitely terminates the declarations in a spec,
4910 -- and is an error in a body.
4916 Error_Msg_SC
("PRIVATE not allowed in body");
4917 Scan
; -- past PRIVATE
4920 -- An end of file definitely terminates the declarations
4925 -- The remaining tokens do not end the scan, but cannot start a
4926 -- valid declaration, so we signal an error and resynchronize.
4927 -- But first check for misuse of a reserved identifier.
4930 if In_Statements
then
4935 -- Here we check for a reserved identifier
4937 if Is_Reserved_Identifier
then
4938 Save_Scan_State
(Scan_State
);
4939 Scan
; -- past the token
4941 if Token
not in Tok_Colon | Tok_Comma
then
4942 Restore_Scan_State
(Scan_State
);
4943 Set_Declaration_Expected
;
4946 Restore_Scan_State
(Scan_State
);
4947 Scan_Reserved_Identifier
(Force_Msg
=> True);
4949 P_Identifier_Declarations
4950 (Decls
, Done
, In_Spec
, In_Statements
);
4954 Set_Declaration_Expected
;
4959 -- To resynchronize after an error, we scan to the next semicolon and
4960 -- return with Done = False, indicating that there may still be more
4961 -- valid declarations to come.
4964 when Error_Resync
=>
4965 Resync_Past_Semicolon
;
4966 end P_Declarative_Item
;
4968 procedure P_Declarative_Items
4970 Declare_Expression
: Boolean;
4972 In_Statements
: Boolean)
4978 (Decls
, Done
, Declare_Expression
, In_Spec
, In_Statements
);
4981 end P_Declarative_Items
;
4983 ----------------------------------
4984 -- 3.11 Basic Declarative Item --
4985 ----------------------------------
4987 -- BASIC_DECLARATIVE_ITEM ::=
4988 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4990 -- Scan zero or more basic declarative items
4992 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4993 -- the scan pointer is repositioned past the next semicolon, and the scan
4994 -- for declarative items continues.
4996 function P_Basic_Declarative_Items
4997 (Declare_Expression
: Boolean) return List_Id
5000 Decls
: constant List_Id
:= New_List
;
5004 -- Indicate no bad declarations detected yet in the current context:
5005 -- visible or private declarations of a package spec.
5007 Missing_Begin_Msg
:= No_Error_Msg
;
5009 -- Get rid of active SIS entry from outer scope. This means we will
5010 -- miss some nested cases, but it doesn't seem worth the effort. See
5011 -- discussion in Par for further details
5013 SIS_Entry_Active
:= False;
5016 (Decls
, Declare_Expression
, In_Spec
=> True, In_Statements
=> False);
5018 -- Get rid of active SIS entry. This is set only if we have scanned a
5019 -- procedure declaration and have not found the body. We could give
5020 -- an error message, but that really would be usurping the role of
5021 -- semantic analysis (this really is a case of a missing body).
5023 SIS_Entry_Active
:= False;
5025 -- Test for assorted illegal declarations not diagnosed elsewhere
5027 Decl
:= First
(Decls
);
5029 while Present
(Decl
) loop
5030 Kind
:= Nkind
(Decl
);
5032 -- Test for body scanned, not acceptable as basic decl item
5034 if Kind
= N_Subprogram_Body
or else
5035 Kind
= N_Package_Body
or else
5036 Kind
= N_Task_Body
or else
5037 Kind
= N_Protected_Body
5039 if Declare_Expression
then
5041 ("proper body not allowed in declare_expression",
5045 ("proper body not allowed in package spec",
5049 -- Complete declaration of mangled subprogram body, for better
5050 -- recovery if analysis is attempted.
5052 if Nkind
(Decl
) in N_Subprogram_Body | N_Package_Body | N_Task_Body
5053 and then No
(Handled_Statement_Sequence
(Decl
))
5055 Set_Handled_Statement_Sequence
(Decl
,
5056 Make_Handled_Sequence_Of_Statements
(Sloc
(Decl
),
5057 Statements
=> New_List
));
5060 -- Test for body stub scanned, not acceptable as basic decl item
5062 elsif Kind
in N_Body_Stub
then
5063 Error_Msg
("body stub not allowed in package spec", Sloc
(Decl
));
5065 elsif Kind
= N_Assignment_Statement
then
5067 ("assignment statement not allowed in package spec",
5075 end P_Basic_Declarative_Items
;
5081 -- For proper body, see below
5082 -- For body stub, see 10.1.3
5084 -----------------------
5085 -- 3.11 Proper Body --
5086 -----------------------
5088 -- Subprogram body is parsed by P_Subprogram (6.1)
5089 -- Package body is parsed by P_Package (7.1)
5090 -- Task body is parsed by P_Task (9.1)
5091 -- Protected body is parsed by P_Protected (9.4)
5093 ------------------------------
5094 -- Set_Declaration_Expected --
5095 ------------------------------
5097 procedure Set_Declaration_Expected
is
5099 Error_Msg_SC
("declaration expected");
5101 if Missing_Begin_Msg
= No_Error_Msg
then
5102 Missing_Begin_Msg
:= Get_Msg_Id
;
5104 end Set_Declaration_Expected
;
5106 ----------------------
5107 -- Skip_Declaration --
5108 ----------------------
5110 procedure Skip_Declaration
(S
: List_Id
) is
5111 Ignored_Done
: Boolean;
5114 (S
, Ignored_Done
, Declare_Expression
=> False, In_Spec
=> False,
5115 In_Statements
=> False);
5116 end Skip_Declaration
;
5118 -----------------------------------------
5119 -- Statement_When_Declaration_Expected --
5120 -----------------------------------------
5122 procedure Statement_When_Declaration_Expected
5128 -- Case of second occurrence of statement in one declaration sequence
5130 if Missing_Begin_Msg
/= No_Error_Msg
then
5132 -- In the procedure spec case, just ignore it, we only give one
5133 -- message for the first occurrence, since otherwise we may get
5134 -- horrible cascading if BODY was missing in the header line.
5139 -- Just ignore it if we are in -gnatd.2 (allow statements to appear
5140 -- in declaration sequences) mode.
5142 elsif Debug_Flag_Dot_2
then
5145 -- In the declarative part case, take a second statement as a sure
5146 -- sign that we really have a missing BEGIN, and end the declarative
5147 -- part now. Note that the caller will fix up the first message to
5148 -- say "missing BEGIN" so that's how the error will be signalled.
5155 -- Case of first occurrence of unexpected statement
5158 -- Do not give error message if we are operating in -gnatd.2 mode
5159 -- (alllow statements to appear in declarative parts).
5161 if not Debug_Flag_Dot_2
then
5163 -- If we are in a package spec, then give message of statement
5164 -- not allowed in package spec. This message never gets changed.
5167 Error_Msg_SC
("statement not allowed in package spec");
5169 -- If in declarative part, then we give the message complaining
5170 -- about finding a statement when a declaration is expected. This
5171 -- gets changed to a complaint about a missing BEGIN if we later
5172 -- find that no BEGIN is present.
5175 Error_Msg_SC
("statement not allowed in declarative part");
5178 -- Capture message Id. This is used for two purposes, first to
5179 -- stop multiple messages, see test above, and second, to allow
5180 -- the replacement of the message in the declarative part case.
5182 Missing_Begin_Msg
:= Get_Msg_Id
;
5186 -- In all cases except the case in which we decided to terminate the
5187 -- declaration sequence on a second error, we scan out the statement
5188 -- and append it to the list of declarations (note that the semantics
5189 -- can handle statements in a declaration list so if we proceed to
5190 -- call the semantic phase, all will be (reasonably) well.
5192 Append_List_To
(Decls
, P_Sequence_Of_Statements
(SS_Unco
));
5194 -- Done is set to False, since we want to continue the scan of
5195 -- declarations, hoping that this statement was a temporary glitch.
5196 -- If we indeed are now in the statement part (i.e. this was a missing
5197 -- BEGIN, then it's not terrible, we will simply keep calling this
5198 -- procedure to process the statements one by one, and then finally
5199 -- hit the missing BEGIN, which will clean up the error message.
5202 end Statement_When_Declaration_Expected
;