1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2022, 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 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
);
2845 exit when Token
in Tok_Right_Paren | Tok_Of
;
2849 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2851 -- If we don't have "range <>", then "range" will be followed by an
2852 -- expression, for either a normal range or a fixed-lower-bound range
2853 -- ("<exp> .. <>"), and we have to know which, in order to determine
2854 -- whether to parse the indexes for an unconstrained or constrained
2855 -- array definition. So we look ahead to see if "<>" follows the "..".
2856 -- If not, then this must be a discrete_subtype_indication for a
2857 -- constrained_array_definition, which will be processed further below.
2859 elsif Prev_Token
= Tok_Range
2860 and then Token
not in Tok_Right_Paren | Tok_Comma
2862 -- If we have an expression followed by "..", then scan farther
2863 -- and check for "<>" to see if we have a fixed-lower-bound range.
2865 if P_Expression_Or_Range_Attribute
/= Error
2866 and then Expr_Form
/= EF_Range_Attr
2867 and then Token
= Tok_Dot_Dot
2871 -- If there's a "<>", then we know we have a fixed-lower-bound
2872 -- index, so we can proceed with parsing an unconstrained array
2875 if Token
= Tok_Box
then
2876 Is_Constrained_Array_Def
:= False;
2879 New_Node
(N_Unconstrained_Array_Definition
, Array_Loc
);
2881 Restore_Scan_State
(Scan_State
); -- to first subtype mark
2883 -- Now parse a sequence of indexes where each is either of
2885 -- <subtype_mark> range <>
2887 -- <subtype_mark> range <expr> .. <>
2889 -- The latter indicates an index with a fixed lower bound,
2890 -- and only applies when extensions are enabled (-gnatX).
2893 Subtype_Mark_Node
:= P_Subtype_Mark_Resync
;
2897 -- Normal "subtype_mark range <>" form, so simply append
2898 -- the subtype reference.
2900 if Token
= Tok_Box
then
2901 Append
(Subtype_Mark_Node
, Subs_List
);
2904 -- This must be an index of form:
2905 -- <subtype_mark> range <expr> .. <>"
2908 P_Index_Subtype_Def_With_Fixed_Lower_Bound
2909 (Subtype_Mark_Node
);
2911 Error_Msg_GNAT_Extension
2912 ("fixed-lower-bound array", Token_Ptr
);
2915 exit when Token
in Tok_Right_Paren | Tok_Of
;
2919 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2924 if Is_Constrained_Array_Def
then
2925 Def_Node
:= New_Node
(N_Constrained_Array_Definition
, Array_Loc
);
2926 Restore_Scan_State
(Scan_State
); -- to first discrete range
2929 Append
(P_Discrete_Subtype_Definition
, Subs_List
);
2930 exit when not Comma_Present
;
2933 Set_Discrete_Subtype_Definitions
(Def_Node
, Subs_List
);
2939 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
2941 if Token_Name
= Name_Aliased
then
2942 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
2945 if Token
= Tok_Aliased
then
2946 Aliased_Present
:= True;
2947 Scan
; -- past ALIASED
2950 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
2952 -- Ada 2005 (AI-230): Access Definition case
2954 if Token
= Tok_Access
then
2955 Error_Msg_Ada_2005_Extension
2956 ("generalized use of anonymous access types");
2958 -- AI95-406 makes "aliased" legal (and useless) in this context so
2959 -- followintg code which used to be needed is commented out.
2961 -- if Aliased_Present then
2962 -- Error_Msg_SP ("ALIASED not allowed here");
2965 Set_Subtype_Indication
(CompDef_Node
, Empty
);
2966 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2967 Set_Access_Definition
(CompDef_Node
,
2968 P_Access_Definition
(Not_Null_Present
));
2971 Set_Access_Definition
(CompDef_Node
, Empty
);
2972 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2973 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
2974 Set_Subtype_Indication
(CompDef_Node
,
2975 P_Subtype_Indication
(Not_Null_Present
));
2978 Set_Component_Definition
(Def_Node
, CompDef_Node
);
2981 end P_Array_Type_Definition
;
2983 -----------------------------------------
2984 -- 3.6 Unconstrained Array Definition --
2985 -----------------------------------------
2987 -- Parsed by P_Array_Type_Definition (3.6)
2989 ---------------------------------------
2990 -- 3.6 Constrained Array Definition --
2991 ---------------------------------------
2993 -- Parsed by P_Array_Type_Definition (3.6)
2995 --------------------------------------
2996 -- 3.6 Discrete Subtype Definition --
2997 --------------------------------------
2999 -- DISCRETE_SUBTYPE_DEFINITION ::=
3000 -- discrete_SUBTYPE_INDICATION | RANGE
3002 -- Note: the discrete subtype definition appearing in a constrained
3003 -- array definition is parsed by P_Array_Type_Definition (3.6)
3005 -- Error recovery: cannot raise Error_Resync
3007 function P_Discrete_Subtype_Definition
return Node_Id
is
3009 -- The syntax of a discrete subtype definition is identical to that
3010 -- of a discrete range, so we simply share the same parsing code.
3012 return P_Discrete_Range
;
3013 end P_Discrete_Subtype_Definition
;
3015 -------------------------------
3016 -- 3.6 Component Definition --
3017 -------------------------------
3019 -- For the array case, parsed by P_Array_Type_Definition (3.6)
3020 -- For the record case, parsed by P_Component_Declaration (3.8)
3022 -----------------------------
3023 -- 3.6.1 Index Constraint --
3024 -----------------------------
3026 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
3028 ---------------------------
3029 -- 3.6.1 Discrete Range --
3030 ---------------------------
3032 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
3034 -- The possible forms for a discrete range are:
3036 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
3037 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
3038 -- Range_Attribute (RANGE, 3.5)
3039 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
3041 -- Error recovery: cannot raise Error_Resync
3043 function P_Discrete_Range
return Node_Id
is
3044 Expr_Node
: Node_Id
;
3045 Range_Node
: Node_Id
;
3048 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
3050 if Expr_Form
= EF_Range_Attr
then
3053 elsif Token
= Tok_Range
then
3054 if Expr_Form
/= EF_Simple_Name
then
3055 Error_Msg_SC
("range must be preceded by subtype mark");
3058 return P_Subtype_Indication
(Expr_Node
);
3060 -- Check Expression .. Expression case
3062 elsif Token
= Tok_Dot_Dot
then
3063 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
3064 Set_Low_Bound
(Range_Node
, Expr_Node
);
3066 Expr_Node
:= P_Expression
;
3067 Check_Simple_Expression
(Expr_Node
);
3068 Set_High_Bound
(Range_Node
, Expr_Node
);
3071 -- Otherwise we must have a subtype mark, or an Ada 2012 iterator
3073 elsif Expr_Form
= EF_Simple_Name
then
3076 -- The domain of iteration must be a name. Semantics will determine that
3077 -- the expression has the proper form.
3079 elsif Ada_Version
>= Ada_2012
then
3082 -- If incorrect, complain that we expect ..
3088 end P_Discrete_Range
;
3090 ----------------------------
3091 -- 3.7 Discriminant Part --
3092 ----------------------------
3094 -- DISCRIMINANT_PART ::=
3095 -- UNKNOWN_DISCRIMINANT_PART
3096 -- | KNOWN_DISCRIMINANT_PART
3098 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
3099 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
3101 ------------------------------------
3102 -- 3.7 Unknown Discriminant Part --
3103 ------------------------------------
3105 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
3107 -- If no unknown discriminant part is present, then False is returned,
3108 -- otherwise the unknown discriminant is scanned out and True is returned.
3110 -- Error recovery: cannot raise Error_Resync
3112 function P_Unknown_Discriminant_Part_Opt
return Boolean is
3113 Scan_State
: Saved_Scan_State
;
3116 -- If <> right now, then this is missing left paren
3118 if Token
= Tok_Box
then
3121 -- If not <> or left paren, then definitely no box
3123 elsif Token
/= Tok_Left_Paren
then
3126 -- Left paren, so might be a box after it
3129 Save_Scan_State
(Scan_State
);
3130 Scan
; -- past the left paren
3132 if Token
/= Tok_Box
then
3133 Restore_Scan_State
(Scan_State
);
3138 -- We are now pointing to the box
3140 if Ada_Version
= Ada_83
then
3141 Error_Msg_SC
("(Ada 83) unknown discriminant not allowed!");
3144 Scan
; -- past the box
3145 U_Right_Paren
; -- must be followed by right paren
3147 end P_Unknown_Discriminant_Part_Opt
;
3149 ----------------------------------
3150 -- 3.7 Known Discriminant Part --
3151 ----------------------------------
3153 -- KNOWN_DISCRIMINANT_PART ::=
3154 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
3156 -- DISCRIMINANT_SPECIFICATION ::=
3157 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
3158 -- [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATION]
3159 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
3160 -- [:= DEFAULT_EXPRESSION] [ASPECT_SPECIFICATION]
3162 -- If no known discriminant part is present, then No_List is returned
3164 -- Error recovery: cannot raise Error_Resync
3166 function P_Known_Discriminant_Part_Opt
return List_Id
is
3167 Specification_Node
: Node_Id
;
3168 Specification_List
: List_Id
;
3169 Ident_Sloc
: Source_Ptr
;
3170 Scan_State
: Saved_Scan_State
;
3172 Not_Null_Present
: Boolean;
3175 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3176 -- This array holds the list of defining identifiers. The upper bound
3177 -- of 4096 is intended to be essentially infinite, and we do not even
3178 -- bother to check for it being exceeded.
3181 if Token
= Tok_Left_Paren
then
3182 Specification_List
:= New_List
;
3184 P_Pragmas_Misplaced
;
3186 Specification_Loop
: loop
3188 Ident_Sloc
:= Token_Ptr
;
3189 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3192 while Comma_Present
loop
3193 Num_Idents
:= Num_Idents
+ 1;
3194 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3197 -- If there are multiple identifiers, we repeatedly scan the
3198 -- type and initialization expression information by resetting
3199 -- the scan pointer (so that we get completely separate trees
3200 -- for each occurrence).
3202 if Num_Idents
> 1 then
3203 Save_Scan_State
(Scan_State
);
3208 -- Loop through defining identifiers in list
3212 Specification_Node
:=
3213 New_Node
(N_Discriminant_Specification
, Ident_Sloc
);
3214 Set_Defining_Identifier
(Specification_Node
, Idents
(Ident
));
3215 Not_Null_Present
:= -- Ada 2005 (AI-231, AI-447)
3216 P_Null_Exclusion
(Allow_Anonymous_In_95
=> True);
3218 if Token
= Tok_Access
then
3219 if Ada_Version
= Ada_83
then
3221 ("(Ada 83) access discriminant not allowed!");
3224 Set_Discriminant_Type
3225 (Specification_Node
,
3226 P_Access_Definition
(Not_Null_Present
));
3228 -- Catch ouf-of-order keywords
3230 elsif Token
= Tok_Constant
then
3233 if Token
= Tok_Access
then
3234 Error_Msg_SC
-- CODEFIX
3235 ("ACCESS must come before CONSTANT");
3236 Set_Discriminant_Type
3237 (Specification_Node
,
3238 P_Access_Definition
(Not_Null_Present
));
3241 Error_Msg_SC
("misplaced CONSTANT");
3245 Set_Discriminant_Type
3246 (Specification_Node
, P_Subtype_Mark
);
3248 Set_Null_Exclusion_Present
-- Ada 2005 (AI-231)
3249 (Specification_Node
, Not_Null_Present
);
3253 (Specification_Node
, Init_Expr_Opt
(True));
3255 if Token
= Tok_With
then
3256 P_Aspect_Specifications
(Specification_Node
, False);
3260 Set_Prev_Ids
(Specification_Node
, True);
3263 if Ident
< Num_Idents
then
3264 Set_More_Ids
(Specification_Node
, True);
3267 Append
(Specification_Node
, Specification_List
);
3268 exit Ident_Loop
when Ident
= Num_Idents
;
3270 Restore_Scan_State
(Scan_State
);
3272 end loop Ident_Loop
;
3274 exit Specification_Loop
when Token
/= Tok_Semicolon
;
3276 P_Pragmas_Misplaced
;
3277 end loop Specification_Loop
;
3280 return Specification_List
;
3285 end P_Known_Discriminant_Part_Opt
;
3287 -------------------------------------
3288 -- 3.7 Discriminant Specification --
3289 -------------------------------------
3291 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
3293 -----------------------------
3294 -- 3.7 Default Expression --
3295 -----------------------------
3297 -- Always parsed (simply as an Expression) by the parent construct
3299 ------------------------------------
3300 -- 3.7.1 Discriminant Constraint --
3301 ------------------------------------
3303 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
3305 --------------------------------------------------------
3306 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
3307 --------------------------------------------------------
3309 -- DISCRIMINANT_CONSTRAINT ::=
3310 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
3312 -- DISCRIMINANT_ASSOCIATION ::=
3313 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3316 -- This routine parses either an index or a discriminant constraint. As
3317 -- is clear from the above grammar, it is often possible to clearly
3318 -- determine which of the two possibilities we have, but there are
3319 -- cases (those in which we have a series of expressions of the same
3320 -- syntactic form as subtype indications), where we cannot tell. Since
3321 -- this means that in any case the semantic phase has to distinguish
3322 -- between the two, there is not much point in the parser trying to
3323 -- distinguish even those cases where the difference is clear. In any
3324 -- case, if we have a situation like:
3326 -- (A => 123, 235 .. 500)
3328 -- it is not clear which of the two items is the wrong one, better to
3329 -- let the semantic phase give a clear message. Consequently, this
3330 -- routine in general returns a list of items which can be either
3331 -- discrete ranges or discriminant associations.
3333 -- The caller has checked that the initial token is a left paren
3335 -- Error recovery: can raise Error_Resync
3337 function P_Index_Or_Discriminant_Constraint
return Node_Id
is
3338 Scan_State
: Saved_Scan_State
;
3339 Constr_Node
: Node_Id
;
3340 Constr_List
: List_Id
;
3341 Expr_Node
: Node_Id
;
3342 Result_Node
: Node_Id
;
3345 Result_Node
:= New_Node
(N_Index_Or_Discriminant_Constraint
, Token_Ptr
);
3347 Constr_List
:= New_List
;
3348 Set_Constraints
(Result_Node
, Constr_List
);
3350 -- The two syntactic forms are a little mixed up, so what we are doing
3351 -- here is looking at the first entry to determine which case we have
3353 -- A discriminant constraint is a list of discriminant associations,
3354 -- which have one of the following possible forms:
3358 -- Id | Id | .. | Id => Expression
3360 -- An index constraint is a list of discrete ranges which have one
3361 -- of the following possible forms:
3364 -- Subtype_Mark range Range
3366 -- Simple_Expression .. Simple_Expression
3368 -- Loop through discriminants in list
3371 -- Check cases of Id => Expression or Id | Id => Expression
3373 if Token
= Tok_Identifier
then
3374 Save_Scan_State
(Scan_State
); -- at Id
3377 if Token
in Tok_Arrow | Tok_Vertical_Bar
then
3378 Restore_Scan_State
(Scan_State
); -- to Id
3379 Append
(P_Discriminant_Association
, Constr_List
);
3382 Restore_Scan_State
(Scan_State
); -- to Id
3386 -- Otherwise scan out an expression and see what we have got
3388 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3390 if Expr_Form
= EF_Range_Attr
then
3391 Append
(Expr_Node
, Constr_List
);
3393 elsif Token
= Tok_Range
then
3394 if Expr_Form
/= EF_Simple_Name
then
3395 Error_Msg_SC
("subtype mark required before RANGE");
3398 Append
(P_Subtype_Indication
(Expr_Node
), Constr_List
);
3401 -- Check Simple_Expression .. Simple_Expression case
3403 elsif Token
= Tok_Dot_Dot
then
3404 Check_Simple_Expression
(Expr_Node
);
3405 Constr_Node
:= New_Node
(N_Range
, Token_Ptr
);
3406 Set_Low_Bound
(Constr_Node
, Expr_Node
);
3409 -- If the upper bound is given by "<>", this is an index for
3410 -- a fixed-lower-bound subtype, so set the expression to Empty
3411 -- for now (it will be set to the ranges maximum upper bound
3412 -- later during analysis), and scan to the next token.
3414 if Token
= Tok_Box
then
3415 Error_Msg_GNAT_Extension
("fixed-lower-bound array", Token_Ptr
);
3420 -- Otherwise parse the range's upper bound expression
3423 Expr_Node
:= P_Expression
;
3424 Check_Simple_Expression
(Expr_Node
);
3427 Set_High_Bound
(Constr_Node
, Expr_Node
);
3428 Append
(Constr_Node
, Constr_List
);
3431 -- Case of an expression which could be either form
3434 Append
(Expr_Node
, Constr_List
);
3438 -- Here with a single entry scanned
3441 exit when not Comma_Present
;
3447 end P_Index_Or_Discriminant_Constraint
;
3449 -------------------------------------
3450 -- 3.7.1 Discriminant Association --
3451 -------------------------------------
3453 -- DISCRIMINANT_ASSOCIATION ::=
3454 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3457 -- This routine is used only when the name list is present and the caller
3458 -- has already checked this (by scanning ahead and repositioning the
3461 -- Error_Recovery: cannot raise Error_Resync;
3463 function P_Discriminant_Association
return Node_Id
is
3464 Discr_Node
: Node_Id
;
3465 Names_List
: List_Id
;
3466 Ident_Sloc
: Source_Ptr
;
3469 Ident_Sloc
:= Token_Ptr
;
3470 Names_List
:= New_List
;
3473 Append
(P_Identifier
(C_Vertical_Bar_Arrow
), Names_List
);
3474 exit when Token
/= Tok_Vertical_Bar
;
3478 Discr_Node
:= New_Node
(N_Discriminant_Association
, Ident_Sloc
);
3479 Set_Selector_Names
(Discr_Node
, Names_List
);
3481 Set_Expression
(Discr_Node
, P_Expression
);
3483 end P_Discriminant_Association
;
3485 ---------------------------------
3486 -- 3.8 Record Type Definition --
3487 ---------------------------------
3489 -- RECORD_TYPE_DEFINITION ::=
3490 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3492 -- There is no node in the tree for a record type definition. Instead
3493 -- a record definition node appears, with possible Abstract_Present,
3494 -- Tagged_Present, and Limited_Present flags set appropriately.
3496 ----------------------------
3497 -- 3.8 Record Definition --
3498 ----------------------------
3500 -- RECORD_DEFINITION ::=
3506 -- Note: in the case where a record definition node is used to represent
3507 -- a record type definition, the caller sets the Tagged_Present and
3508 -- Limited_Present flags in the resulting N_Record_Definition node as
3511 -- Note that the RECORD token at the start may be missing in certain
3512 -- error situations, so this function is expected to post the error
3514 -- Error recovery: can raise Error_Resync
3516 function P_Record_Definition
return Node_Id
is
3518 procedure Catch_Out_Of_Order_Keywords
(Keyword
: String);
3519 -- Catch ouf-of-order keywords in a record definition
3521 ---------------------------------
3522 -- Catch_Out_Of_Order_Keywords --
3523 ---------------------------------
3525 procedure Catch_Out_Of_Order_Keywords
(Keyword
: String) is
3528 if Token
= Tok_Abstract
then
3529 Error_Msg_SC
-- CODEFIX
3530 ("ABSTRACT must come before " & Keyword
);
3531 Scan
; -- past ABSTRACT
3533 elsif Token
= Tok_Tagged
then
3534 Error_Msg_SC
-- CODEFIX
3535 ("TAGGED must come before " & Keyword
);
3536 Scan
; -- past TAGGED
3538 elsif Token
= Tok_Limited
then
3539 Error_Msg_SC
-- CODEFIX
3540 ("LIMITED must come before " & Keyword
);
3541 Scan
; -- past LIMITED
3547 end Catch_Out_Of_Order_Keywords
;
3551 -- Start of processing for P_Record_Definition
3554 Inside_Record_Definition
:= True;
3555 Rec_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3559 if Token
= Tok_Null
then
3562 Catch_Out_Of_Order_Keywords
("NULL");
3564 Set_Null_Present
(Rec_Node
, True);
3565 Catch_Out_Of_Order_Keywords
("RECORD");
3567 -- Catch incomplete declaration to prevent cascaded errors, see
3568 -- ACATS B393002 for an example.
3570 elsif Token
= Tok_Semicolon
then
3571 Error_Msg_AP
("missing record definition");
3573 -- Case starting with RECORD keyword. Build scope stack entry. For the
3574 -- column, we use the first non-blank character on the line, to deal
3575 -- with situations such as:
3581 -- which is not official RM indentation, but is not uncommon usage, and
3582 -- in particular is standard GNAT coding style, so handle it nicely.
3586 Scopes
(Scope
.Last
).Etyp
:= E_Record
;
3587 Scopes
(Scope
.Last
).Ecol
:= Start_Column
;
3588 Scopes
(Scope
.Last
).Sloc
:= Token_Ptr
;
3589 Scopes
(Scope
.Last
).Labl
:= Error
;
3590 Scopes
(Scope
.Last
).Junk
:= (Token
/= Tok_Record
);
3593 Catch_Out_Of_Order_Keywords
("RECORD");
3595 Set_Component_List
(Rec_Node
, P_Component_List
);
3598 exit when Check_End
;
3599 Discard_Junk_Node
(P_Component_List
);
3603 Inside_Record_Definition
:= False;
3605 end P_Record_Definition
;
3607 -------------------------
3608 -- 3.8 Component List --
3609 -------------------------
3611 -- COMPONENT_LIST ::=
3612 -- COMPONENT_ITEM {COMPONENT_ITEM}
3613 -- | {COMPONENT_ITEM} VARIANT_PART
3616 -- Error recovery: cannot raise Error_Resync
3618 function P_Component_List
return Node_Id
is
3619 Component_List_Node
: Node_Id
;
3620 Decls_List
: List_Id
;
3621 Scan_State
: Saved_Scan_State
;
3622 Null_Loc
: Source_Ptr
;
3625 Component_List_Node
:= New_Node
(N_Component_List
, Token_Ptr
);
3626 Decls_List
:= New_List
;
3630 if Token
= Tok_Null
then
3631 Null_Loc
:= Token_Ptr
;
3634 P_Pragmas_Opt
(Decls_List
);
3636 -- If we have an END or WHEN now, everything is fine, otherwise we
3637 -- complain about the null, ignore it, and scan for more components.
3639 if Token
in Tok_End | Tok_When
then
3640 Set_Null_Present
(Component_List_Node
, True);
3641 return Component_List_Node
;
3643 Error_Msg
("NULL component only allowed in null record", Null_Loc
);
3647 -- Scan components for non-null record
3649 P_Pragmas_Opt
(Decls_List
);
3651 if Token
/= Tok_Case
then
3653 P_Component_Items
(Decls_List
);
3654 P_Pragmas_Opt
(Decls_List
);
3656 exit when Token
in Tok_End | Tok_Case | Tok_When
;
3658 -- We are done if we do not have an identifier. However, if we
3659 -- have a misspelled reserved identifier that is in a column to
3660 -- the right of the record definition, we will treat it as an
3661 -- identifier. It turns out to be too dangerous in practice to
3662 -- accept such a mis-spelled identifier which does not have this
3663 -- additional clue that confirms the incorrect spelling.
3665 if Token
/= Tok_Identifier
then
3666 if Start_Column
> Scopes
(Scope
.Last
).Ecol
3667 and then Is_Reserved_Identifier
3669 Save_Scan_State
(Scan_State
); -- at reserved id
3670 Scan
; -- possible reserved id
3672 if Token
in Tok_Comma | Tok_Colon
then
3673 Restore_Scan_State
(Scan_State
);
3674 Scan_Reserved_Identifier
(Force_Msg
=> True);
3676 -- Note reserved identifier used as field name after all
3677 -- because not followed by colon or comma.
3680 Restore_Scan_State
(Scan_State
);
3684 -- Non-identifier that definitely was not reserved id
3693 if Token
= Tok_Case
then
3694 Set_Variant_Part
(Component_List_Node
, P_Variant_Part
);
3696 -- Check for junk after variant part
3698 if Token
= Tok_Identifier
then
3699 Save_Scan_State
(Scan_State
);
3700 Scan
; -- past identifier
3702 if Token
= Tok_Colon
then
3703 Restore_Scan_State
(Scan_State
);
3704 Error_Msg_SC
("component may not follow variant part");
3705 Discard_Junk_Node
(P_Component_List
);
3707 elsif Token
= Tok_Case
then
3708 Restore_Scan_State
(Scan_State
);
3709 Error_Msg_SC
("only one variant part allowed in a record");
3710 Discard_Junk_Node
(P_Component_List
);
3713 Restore_Scan_State
(Scan_State
);
3718 Set_Component_Items
(Component_List_Node
, Decls_List
);
3719 return Component_List_Node
;
3720 end P_Component_List
;
3722 -------------------------
3723 -- 3.8 Component Item --
3724 -------------------------
3726 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3728 -- COMPONENT_DECLARATION ::=
3729 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3730 -- [:= DEFAULT_EXPRESSION]
3731 -- [ASPECT_SPECIFICATIONS];
3733 -- COMPONENT_DEFINITION ::=
3734 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3736 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3737 -- the scan is positioned past the following semicolon.
3739 -- Note: we do not yet allow representation clauses to appear as component
3740 -- items, do we need to add this capability sometime in the future ???
3742 procedure P_Component_Items
(Decls
: List_Id
) is
3743 Aliased_Present
: Boolean := False;
3744 CompDef_Node
: Node_Id
;
3745 Decl_Node
: Node_Id
:= Empty
; -- initialize to prevent warning
3746 Scan_State
: Saved_Scan_State
;
3747 Not_Null_Present
: Boolean := False;
3750 Ident_Sloc
: Source_Ptr
;
3752 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3753 -- This array holds the list of defining identifiers. The upper bound
3754 -- of 4096 is intended to be essentially infinite, and we do not even
3755 -- bother to check for it being exceeded.
3758 if Token
/= Tok_Identifier
then
3759 Error_Msg_SC
("component declaration expected");
3760 Resync_Past_Semicolon
;
3764 Ident_Sloc
:= Token_Ptr
;
3766 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3769 while Comma_Present
loop
3770 Num_Idents
:= Num_Idents
+ 1;
3771 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3774 -- If there are multiple identifiers, we repeatedly scan the
3775 -- type and initialization expression information by resetting
3776 -- the scan pointer (so that we get completely separate trees
3777 -- for each occurrence).
3779 if Num_Idents
> 1 then
3780 Save_Scan_State
(Scan_State
);
3785 -- Loop through defining identifiers in list
3790 -- The following block is present to catch Error_Resync
3791 -- which causes the parse to be reset past the semicolon
3794 Decl_Node
:= New_Node
(N_Component_Declaration
, Ident_Sloc
);
3795 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
3797 if Token
= Tok_Constant
then
3798 Error_Msg_SC
("constant component not permitted");
3802 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
3804 if Token_Name
= Name_Aliased
then
3805 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
3808 if Token
= Tok_Aliased
then
3809 Aliased_Present
:= True;
3810 Scan
; -- past ALIASED
3813 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
3815 -- Ada 2005 (AI-230): Access Definition case
3817 if Token
= Tok_Access
then
3818 Error_Msg_Ada_2005_Extension
3819 ("generalized use of anonymous access types");
3821 -- AI95-406 makes "aliased" legal (and useless) here, so the
3822 -- following code which used to be required is commented out.
3824 -- if Aliased_Present then
3825 -- Error_Msg_SP ("ALIASED not allowed here");
3828 Set_Subtype_Indication
(CompDef_Node
, Empty
);
3829 Set_Aliased_Present
(CompDef_Node
, False);
3830 Set_Access_Definition
(CompDef_Node
,
3831 P_Access_Definition
(Not_Null_Present
));
3834 Set_Access_Definition
(CompDef_Node
, Empty
);
3835 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
3836 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
3838 if Token
= Tok_Array
then
3839 Error_Msg_SC
("anonymous array not allowed as component");
3843 Set_Subtype_Indication
(CompDef_Node
,
3844 P_Subtype_Indication
(Not_Null_Present
));
3847 Set_Component_Definition
(Decl_Node
, CompDef_Node
);
3848 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
3851 Set_Prev_Ids
(Decl_Node
, True);
3854 if Ident
< Num_Idents
then
3855 Set_More_Ids
(Decl_Node
, True);
3858 Append
(Decl_Node
, Decls
);
3861 when Error_Resync
=>
3862 if Token
/= Tok_End
then
3863 Resync_Past_Semicolon
;
3867 exit Ident_Loop
when Ident
= Num_Idents
;
3869 Restore_Scan_State
(Scan_State
);
3871 end loop Ident_Loop
;
3873 P_Aspect_Specifications
(Decl_Node
);
3874 end P_Component_Items
;
3876 --------------------------------
3877 -- 3.8 Component Declaration --
3878 --------------------------------
3880 -- Parsed by P_Component_Items (3.8)
3882 -------------------------
3883 -- 3.8.1 Variant Part --
3884 -------------------------
3887 -- case discriminant_DIRECT_NAME is
3892 -- The caller has checked that the initial token is CASE
3894 -- Error recovery: cannot raise Error_Resync
3896 function P_Variant_Part
return Node_Id
is
3897 Variant_Part_Node
: Node_Id
;
3898 Variants_List
: List_Id
;
3899 Case_Node
: Node_Id
;
3902 Variant_Part_Node
:= New_Node
(N_Variant_Part
, Token_Ptr
);
3904 Scopes
(Scope
.Last
).Etyp
:= E_Case
;
3905 Scopes
(Scope
.Last
).Sloc
:= Token_Ptr
;
3906 Scopes
(Scope
.Last
).Ecol
:= Start_Column
;
3909 Case_Node
:= P_Expression
;
3910 Set_Name
(Variant_Part_Node
, Case_Node
);
3912 if Nkind
(Case_Node
) /= N_Identifier
then
3913 Set_Name
(Variant_Part_Node
, Error
);
3914 Error_Msg
("discriminant name expected", Sloc
(Case_Node
));
3916 elsif Paren_Count
(Case_Node
) /= 0 then
3918 ("|discriminant name may not be parenthesized",
3920 Set_Paren_Count
(Case_Node
, 0);
3924 Variants_List
:= New_List
;
3925 P_Pragmas_Opt
(Variants_List
);
3927 -- Test missing variant
3929 if Token
= Tok_End
then
3930 Error_Msg_BC
("WHEN expected (must have at least one variant)");
3932 Append
(P_Variant
, Variants_List
);
3935 -- Loop through variants, note that we allow if in place of when,
3936 -- this error will be detected and handled in P_Variant.
3939 P_Pragmas_Opt
(Variants_List
);
3941 if Token
not in Tok_When | Tok_If | Tok_Others
then
3942 exit when Check_End
;
3945 Append
(P_Variant
, Variants_List
);
3948 Set_Variants
(Variant_Part_Node
, Variants_List
);
3949 return Variant_Part_Node
;
3952 --------------------
3954 --------------------
3957 -- when DISCRETE_CHOICE_LIST =>
3960 -- Error recovery: cannot raise Error_Resync
3962 -- The initial token on entry is either WHEN, IF or OTHERS
3964 function P_Variant
return Node_Id
is
3965 Variant_Node
: Node_Id
;
3968 -- Special check to recover nicely from use of IF in place of WHEN
3970 if Token
= Tok_If
then
3977 Variant_Node
:= New_Node
(N_Variant
, Prev_Token_Ptr
);
3978 Set_Discrete_Choices
(Variant_Node
, P_Discrete_Choice_List
);
3980 Set_Component_List
(Variant_Node
, P_Component_List
);
3981 return Variant_Node
;
3984 ---------------------------------
3985 -- 3.8.1 Discrete Choice List --
3986 ---------------------------------
3988 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3990 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3992 -- Note: in Ada 83, the expression must be a simple expression
3994 -- Error recovery: cannot raise Error_Resync
3996 function P_Discrete_Choice_List
return List_Id
is
3998 Expr_Node
: Node_Id
:= Empty
; -- initialize to prevent warning
3999 Choice_Node
: Node_Id
;
4002 Choices
:= New_List
;
4004 if Token
= Tok_Others
then
4005 Append
(New_Node
(N_Others_Choice
, Token_Ptr
), Choices
);
4006 Scan
; -- past OTHERS
4010 -- Scan out expression or range attribute
4012 Expr_Node
:= P_Expression_Or_Range_Attribute
;
4013 Ignore
(Tok_Right_Paren
);
4015 if Token
= Tok_Colon
4016 and then Nkind
(Expr_Node
) = N_Identifier
4018 Error_Msg_SP
("label not permitted in this context");
4023 elsif Expr_Form
= EF_Range_Attr
then
4024 Append
(Expr_Node
, Choices
);
4028 elsif Token
= Tok_Dot_Dot
then
4029 Check_Simple_Expression
(Expr_Node
);
4030 Choice_Node
:= New_Node
(N_Range
, Token_Ptr
);
4031 Set_Low_Bound
(Choice_Node
, Expr_Node
);
4033 Expr_Node
:= P_Expression_No_Right_Paren
;
4034 Check_Simple_Expression
(Expr_Node
);
4035 Set_High_Bound
(Choice_Node
, Expr_Node
);
4036 Append
(Choice_Node
, Choices
);
4038 -- Simple name, must be subtype, so range allowed
4040 elsif Expr_Form
= EF_Simple_Name
then
4041 if Token
= Tok_Range
then
4042 Append
(P_Subtype_Indication
(Expr_Node
), Choices
);
4044 elsif Token
in Token_Class_Consk
then
4046 ("the only constraint allowed here " &
4047 "is a range constraint");
4048 Discard_Junk_Node
(P_Constraint_Opt
);
4049 Append
(Expr_Node
, Choices
);
4052 Append
(Expr_Node
, Choices
);
4058 -- In Ada 2012 mode, the expression must be a simple
4059 -- expression. The reason for this restriction (i.e. going
4060 -- back to the Ada 83 rule) is to avoid ambiguities when set
4061 -- membership operations are allowed, consider the
4064 -- when A in 1 .. 10 | 12 =>
4066 -- This is ambiguous without parentheses, so we require one
4067 -- of the following two parenthesized forms to disambiguate:
4069 -- one of the following:
4071 -- when (A in 1 .. 10 | 12) =>
4072 -- when (A in 1 .. 10) | 12 =>
4074 -- To solve this, in Ada 2012 mode, we disallow the use of
4075 -- membership operations in expressions in choices.
4077 -- Technically in the grammar, the expression must match the
4078 -- grammar for restricted expression.
4080 if Ada_Version
>= Ada_2012
then
4081 Check_Restricted_Expression
(Expr_Node
);
4083 -- In Ada 83 mode, the syntax required a simple expression
4086 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
4089 Append
(Expr_Node
, Choices
);
4093 when Error_Resync
=>
4099 if Token
= Tok_Comma
then
4100 if Nkind
(Expr_Node
) = N_Iterated_Component_Association
then
4106 if Token
= Tok_Vertical_Bar
then
4107 Error_Msg_SP
-- CODEFIX
4108 ("|extra "","" ignored");
4112 Error_Msg_SP
-- CODEFIX
4113 (""","" should be ""'|""");
4117 exit when Token
/= Tok_Vertical_Bar
;
4124 end P_Discrete_Choice_List
;
4126 ----------------------------
4127 -- 3.8.1 Discrete Choice --
4128 ----------------------------
4130 -- Parsed by P_Discrete_Choice_List (3.8.1)
4132 ----------------------------------
4133 -- 3.9.1 Record Extension Part --
4134 ----------------------------------
4136 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
4138 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
4140 --------------------------------------
4141 -- 3.9.4 Interface Type Definition --
4142 --------------------------------------
4144 -- INTERFACE_TYPE_DEFINITION ::=
4145 -- [limited | task | protected | synchronized] interface
4146 -- [and INTERFACE_LIST]
4148 -- Error recovery: cannot raise Error_Resync
4150 function P_Interface_Type_Definition
4151 (Abstract_Present
: Boolean) return Node_Id
4153 Typedef_Node
: Node_Id
;
4156 Error_Msg_Ada_2005_Extension
("abstract interface");
4158 if Abstract_Present
then
4160 ("ABSTRACT not allowed in interface type definition " &
4164 Scan
; -- past INTERFACE
4166 -- Ada 2005 (AI-345): In case of interfaces with a null list of
4167 -- interfaces we build a record_definition node.
4169 if Token
= Tok_Semicolon
or else Aspect_Specifications_Present
then
4170 Typedef_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
4172 Set_Abstract_Present
(Typedef_Node
);
4173 Set_Tagged_Present
(Typedef_Node
);
4174 Set_Null_Present
(Typedef_Node
);
4175 Set_Interface_Present
(Typedef_Node
);
4177 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
4178 -- a list of interfaces we build a derived_type_definition node. This
4179 -- simplifies the semantic analysis (and hence further maintenance)
4182 if Token
/= Tok_And
then
4183 Error_Msg_AP
("AND expected");
4188 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
4190 Set_Abstract_Present
(Typedef_Node
);
4191 Set_Interface_Present
(Typedef_Node
);
4192 Set_Subtype_Indication
(Typedef_Node
, P_Qualified_Simple_Name
);
4194 Set_Record_Extension_Part
(Typedef_Node
,
4195 New_Node
(N_Record_Definition
, Token_Ptr
));
4196 Set_Null_Present
(Record_Extension_Part
(Typedef_Node
));
4198 if Token
= Tok_And
then
4199 Set_Interface_List
(Typedef_Node
, New_List
);
4203 Append
(P_Qualified_Simple_Name
,
4204 Interface_List
(Typedef_Node
));
4205 exit when Token
/= Tok_And
;
4211 return Typedef_Node
;
4212 end P_Interface_Type_Definition
;
4214 ----------------------------------
4215 -- 3.10 Access Type Definition --
4216 ----------------------------------
4218 -- ACCESS_TYPE_DEFINITION ::=
4219 -- ACCESS_TO_OBJECT_DEFINITION
4220 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
4222 -- ACCESS_TO_OBJECT_DEFINITION ::=
4223 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
4225 -- GENERAL_ACCESS_MODIFIER ::= all | constant
4227 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4228 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4229 -- | [NULL_EXCLUSION] access [protected] function
4230 -- PARAMETER_AND_RESULT_PROFILE
4232 -- PARAMETER_PROFILE ::= [FORMAL_PART]
4234 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
4236 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
4237 -- parsed the null_exclusion part and has also removed the ACCESS token;
4238 -- otherwise the caller has just checked that the initial token is ACCESS
4240 -- Error recovery: can raise Error_Resync
4242 function P_Access_Type_Definition
4243 (Header_Already_Parsed
: Boolean := False) return Node_Id
4245 procedure Check_Junk_Subprogram_Name
;
4246 -- Used in access to subprogram definition cases to check for an
4247 -- identifier or operator symbol that does not belong.
4249 --------------------------------
4250 -- Check_Junk_Subprogram_Name --
4251 --------------------------------
4253 procedure Check_Junk_Subprogram_Name
is
4254 Saved_State
: Saved_Scan_State
;
4257 if Token
in Tok_Identifier | Tok_Operator_Symbol
then
4258 Save_Scan_State
(Saved_State
);
4259 Scan
; -- past possible junk subprogram name
4261 if Token
in Tok_Left_Paren | Tok_Semicolon
then
4262 Error_Msg_SP
("unexpected subprogram name ignored");
4264 Restore_Scan_State
(Saved_State
);
4267 end Check_Junk_Subprogram_Name
;
4269 Access_Loc
: constant Source_Ptr
:= Token_Ptr
;
4270 Prot_Flag
: Boolean;
4271 Not_Null_Present
: Boolean := False;
4272 Not_Null_Subtype
: Boolean := False;
4273 Not_Null_Subtype_Loc
: Source_Ptr
; -- loc of second "not null"
4274 Type_Def_Node
: Node_Id
;
4275 Result_Not_Null
: Boolean;
4276 Result_Node
: Node_Id
;
4278 -- Start of processing for P_Access_Type_Definition
4281 if not Header_Already_Parsed
then
4282 -- NOT NULL ACCESS... is a common form of access definition. ACCESS
4283 -- NOT NULL... is certainly rare, but syntactically legal. NOT NULL
4284 -- ACCESS NOT NULL... is rarer yet, and also legal. The last two
4285 -- cases are only meaningful if the following subtype indication
4286 -- denotes an access type. We check below for "not null procedure"
4287 -- and "not null function"; in the access-to-object case it is a
4288 -- semantic check. The flag Not_Null_Subtype indicates that this
4289 -- second null exclusion is present in the access type definition.
4291 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4293 if Token
/= Tok_Access
then
4299 Scan
; -- past ACCESS
4301 Not_Null_Subtype_Loc
:= Token_Ptr
;
4302 Not_Null_Subtype
:= P_Null_Exclusion
; -- Might also appear
4305 if Token_Name
= Name_Protected
then
4306 Check_95_Keyword
(Tok_Protected
, Tok_Procedure
);
4307 Check_95_Keyword
(Tok_Protected
, Tok_Function
);
4310 Prot_Flag
:= (Token
= Tok_Protected
);
4313 Scan
; -- past PROTECTED
4315 if Token
not in Tok_Procedure | Tok_Function
then
4316 Error_Msg_SC
-- CODEFIX
4317 ("FUNCTION or PROCEDURE expected");
4321 -- Access-to-subprogram case
4323 if Token
in Tok_Procedure | Tok_Function
then
4325 -- Check for "not null [protected] procedure" and "not null
4326 -- [protected] function".
4328 if Not_Null_Subtype
then
4330 ("null exclusion must apply to access type",
4331 Not_Null_Subtype_Loc
);
4335 if Token
= Tok_Procedure
then
4336 if Ada_Version
= Ada_83
then
4337 Error_Msg_SC
("(Ada 83) access to procedure not allowed!");
4340 Type_Def_Node
:= New_Node
(N_Access_Procedure_Definition
, Access_Loc
);
4341 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4342 Scan
; -- past PROCEDURE
4343 Check_Junk_Subprogram_Name
;
4344 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4345 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4347 elsif Token
= Tok_Function
then
4348 if Ada_Version
= Ada_83
then
4349 Error_Msg_SC
("(Ada 83) access to function not allowed!");
4352 Type_Def_Node
:= New_Node
(N_Access_Function_Definition
, Access_Loc
);
4353 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4354 Scan
; -- past FUNCTION
4355 Check_Junk_Subprogram_Name
;
4356 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4357 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4360 Result_Not_Null
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4362 -- Ada 2005 (AI-318-02)
4364 if Token
= Tok_Access
then
4365 Error_Msg_Ada_2005_Extension
("anonymous access result type");
4367 Result_Node
:= P_Access_Definition
(Result_Not_Null
);
4370 Result_Node
:= P_Subtype_Mark
;
4373 -- A null exclusion on the result type must be recorded in a flag
4374 -- distinct from the one used for the access-to-subprogram type's
4377 Set_Null_Exclusion_In_Return_Present
4378 (Type_Def_Node
, Result_Not_Null
);
4381 Set_Result_Definition
(Type_Def_Node
, Result_Node
);
4383 -- Access-to-object case
4386 Type_Def_Node
:= New_Node
(N_Access_To_Object_Definition
, Access_Loc
);
4387 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4388 Set_Null_Excluding_Subtype
(Type_Def_Node
, Not_Null_Subtype
);
4390 if Token
in Tok_All | Tok_Constant
then
4391 if Ada_Version
= Ada_83
then
4392 Error_Msg_SC
("(Ada 83) access modifier not allowed!");
4395 if Token
= Tok_All
then
4396 Set_All_Present
(Type_Def_Node
, True);
4399 Set_Constant_Present
(Type_Def_Node
, True);
4402 Scan
; -- past ALL or CONSTANT
4405 Set_Subtype_Indication
(Type_Def_Node
,
4406 P_Subtype_Indication
(Not_Null_Present
));
4409 return Type_Def_Node
;
4410 end P_Access_Type_Definition
;
4412 ---------------------------------------
4413 -- 3.10 Access To Object Definition --
4414 ---------------------------------------
4416 -- Parsed by P_Access_Type_Definition (3.10)
4418 -----------------------------------
4419 -- 3.10 General Access Modifier --
4420 -----------------------------------
4422 -- Parsed by P_Access_Type_Definition (3.10)
4424 -------------------------------------------
4425 -- 3.10 Access To Subprogram Definition --
4426 -------------------------------------------
4428 -- Parsed by P_Access_Type_Definition (3.10)
4430 -----------------------------
4431 -- 3.10 Access Definition --
4432 -----------------------------
4434 -- ACCESS_DEFINITION ::=
4435 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4436 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
4438 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4439 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4440 -- | [NULL_EXCLUSION] access [protected] function
4441 -- PARAMETER_AND_RESULT_PROFILE
4443 -- The caller has parsed the null-exclusion part and it has also checked
4444 -- that the next token is ACCESS
4446 -- Error recovery: cannot raise Error_Resync
4448 function P_Access_Definition
4449 (Null_Exclusion_Present
: Boolean) return Node_Id
4452 Subp_Node
: Node_Id
;
4455 Def_Node
:= New_Node
(N_Access_Definition
, Token_Ptr
);
4456 Scan
; -- past ACCESS
4458 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
4460 if Token
in Tok_Protected | Tok_Procedure | Tok_Function
then
4461 Error_Msg_Ada_2005_Extension
("access-to-subprogram");
4463 Subp_Node
:= P_Access_Type_Definition
(Header_Already_Parsed
=> True);
4464 Set_Null_Exclusion_Present
(Subp_Node
, Null_Exclusion_Present
);
4465 Set_Access_To_Subprogram_Definition
(Def_Node
, Subp_Node
);
4467 -- Ada 2005 (AI-231)
4468 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4471 Set_Null_Exclusion_Present
(Def_Node
, Null_Exclusion_Present
);
4473 if Token
= Tok_All
then
4474 if Ada_Version
< Ada_2005
then
4476 ("ALL not permitted for anonymous access type");
4480 Set_All_Present
(Def_Node
);
4482 elsif Token
= Tok_Constant
then
4483 Error_Msg_Ada_2005_Extension
("access-to-constant");
4485 Scan
; -- past CONSTANT
4486 Set_Constant_Present
(Def_Node
);
4489 Set_Subtype_Mark
(Def_Node
, P_Subtype_Mark
);
4494 end P_Access_Definition
;
4496 -----------------------------------------
4497 -- 3.10.1 Incomplete Type Declaration --
4498 -----------------------------------------
4500 -- Parsed by P_Type_Declaration (3.2.1)
4502 ----------------------------
4503 -- 3.11 Declarative Part --
4504 ----------------------------
4506 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
4508 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Item
4509 -- handles errors, and returns cleanly after an error has occurred)
4511 function P_Declarative_Part
return List_Id
is
4512 Decls
: constant List_Id
:= New_List
;
4514 -- Indicate no bad declarations detected yet. This will be reset by
4515 -- P_Declarative_Items if a bad declaration is discovered.
4517 Missing_Begin_Msg
:= No_Error_Msg
;
4519 -- Get rid of active SIS entry from outer scope. This means we will
4520 -- miss some nested cases, but it doesn't seem worth the effort. See
4521 -- discussion in Par for further details
4523 SIS_Entry_Active
:= False;
4526 (Decls
, Declare_Expression
=> False,
4527 In_Spec
=> False, In_Statements
=> False);
4529 -- Get rid of active SIS entry which is left set only if we scanned a
4530 -- procedure declaration and have not found the body. We could give
4531 -- an error message, but that really would be usurping the role of
4532 -- semantic analysis (this really is a missing body case).
4534 SIS_Entry_Active
:= False;
4536 end P_Declarative_Part
;
4538 ----------------------------
4539 -- 3.11 Declarative Item --
4540 ----------------------------
4542 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4544 -- Can return Error if a junk declaration is found, or Empty if no
4545 -- declaration is found (i.e. a token ending declarations, such as
4546 -- BEGIN or END is encountered).
4548 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4549 -- then the scan is set past the next semicolon and Error is returned.
4551 procedure P_Declarative_Item
4554 Declare_Expression
: Boolean;
4556 In_Statements
: Boolean)
4558 Scan_State
: Saved_Scan_State
;
4563 -- In -gnatg mode, we don't want a "bad indentation" error inside a
4564 -- declare_expression.
4566 if Style_Check
and not Declare_Expression
then
4567 Style
.Check_Indentation
;
4577 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4582 -- Check for loop (premature statement)
4584 Save_Scan_State
(Scan_State
);
4588 Is_Statement
: Boolean := True;
4590 if Token
= Tok_Identifier
then
4591 Scan
; -- past identifier
4592 if Token
in Tok_Use | Tok_Apostrophe
then
4593 Is_Statement
:= False;
4594 elsif Token
= Tok_Dot
then
4596 if Token
= Tok_Identifier
then
4598 Is_Statement
:= Token
in Tok_In | Tok_Of
;
4602 Is_Statement
:= False;
4605 Restore_Scan_State
(Scan_State
);
4607 if Is_Statement
then
4608 if not In_Statements
then
4609 Statement_When_Declaration_Expected
4610 (Decls
, Done
, In_Spec
);
4615 Append
(P_Representation_Clause
, Decls
);
4621 Append
(P_Generic
, Decls
);
4623 when Tok_Identifier
=>
4626 -- Special check for misuse of overriding not in Ada 2005 mode
4628 if Token_Name
= Name_Overriding
4629 and then not Next_Token_Is
(Tok_Colon
)
4631 Error_Msg_SC
("overriding indicator is an Ada 2005 extension");
4632 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4634 Token
:= Tok_Overriding
;
4635 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4637 -- Normal case, no overriding, or overriding followed by colon
4640 P_Identifier_Declarations
(Decls
, Done
, In_Spec
, In_Statements
);
4645 Append
(P_Package
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4648 -- If we see a pragma and In_Statements is true, we want to let
4649 -- the statement-parser deal with it.
4651 if In_Statements
then
4654 Append
(P_Pragma
, Decls
);
4657 when Tok_Protected
=>
4659 Scan
; -- past PROTECTED
4660 Append
(P_Protected
, Decls
);
4664 Append
(P_Subtype_Declaration
, Decls
);
4669 Append
(P_Task
, Decls
);
4673 Append
(P_Type_Declaration
, Decls
);
4677 P_Use_Clause
(Decls
);
4682 if Aspect_Specifications_Present
then
4684 -- If we are after a semicolon, complain that it was ignored.
4685 -- But we don't really ignore it, since we dump the aspects,
4686 -- so we make the error message a normal fatal message which
4687 -- will inhibit semantic analysis anyway).
4689 if Prev_Token
= Tok_Semicolon
then
4690 Error_Msg_SP
-- CODEFIX
4691 ("extra "";"" ignored");
4693 -- If not just past semicolon, just complain that aspects are
4694 -- not allowed at this point.
4697 Error_Msg_SC
("aspect specifications not allowed here");
4700 -- Assume that this is a misplaced aspect specification within
4701 -- a declarative list. After discarding the misplaced aspects
4702 -- we can continue the scan.
4705 Dummy_Node
: constant Node_Id
:=
4706 New_Node
(N_Package_Specification
, Token_Ptr
);
4707 pragma Warnings
(Off
, Dummy_Node
);
4708 -- Dummy node to attach aspect specifications to. We will
4709 -- then throw them away.
4712 P_Aspect_Specifications
(Dummy_Node
, Semicolon
=> True);
4715 -- Here if not aspect specifications case
4718 Error_Msg_SC
("WITH can only appear in context clause");
4722 -- BEGIN terminates the scan of a sequence of declarations unless
4723 -- there is a missing subprogram body, see section on handling
4724 -- semicolon in place of IS. We only treat the begin as satisfying
4725 -- the subprogram declaration if it falls in the expected column
4729 if SIS_Entry_Active
and then Start_Column
>= SIS_Ecol
then
4731 -- Here we have the case where a BEGIN is encountered during
4732 -- declarations in a declarative part, or at the outer level,
4733 -- and there is a subprogram declaration outstanding for which
4734 -- no body has been supplied. This is the case where we assume
4735 -- that the semicolon in the subprogram declaration should
4736 -- really have been is. The active SIS entry describes the
4737 -- subprogram declaration. On return the declaration has been
4738 -- modified to become a body.
4741 Specification_Node
: Node_Id
;
4742 Decl_Node
: Node_Id
;
4743 Body_Node
: Node_Id
;
4746 -- First issue the error message. If we had a missing
4747 -- semicolon in the declaration, then change the message
4748 -- to <missing "is">
4750 if SIS_Missing_Semicolon_Message
/= No_Error_Msg
then
4751 Change_Error_Text
-- Replace: "missing "";"" "
4752 (SIS_Missing_Semicolon_Message
, "missing ""is""");
4754 -- Otherwise we saved the semicolon position, so complain
4757 Error_Msg
-- CODEFIX
4758 ("|"";"" should be IS", SIS_Semicolon_Sloc
);
4761 -- The next job is to fix up any declarations that occurred
4762 -- between the procedure header and the BEGIN. These got
4763 -- chained to the outer declarative region (immediately
4764 -- after the procedure declaration) and they should be
4765 -- chained to the subprogram itself, which is a body
4766 -- rather than a spec.
4768 Specification_Node
:= Specification
(SIS_Declaration_Node
);
4769 Change_Node
(SIS_Declaration_Node
, N_Subprogram_Body
);
4770 Body_Node
:= SIS_Declaration_Node
;
4771 Set_Specification
(Body_Node
, Specification_Node
);
4772 Set_Declarations
(Body_Node
, New_List
);
4775 Decl_Node
:= Remove_Next
(Body_Node
);
4776 exit when Decl_Node
= Empty
;
4777 Append
(Decl_Node
, Declarations
(Body_Node
));
4780 -- Now make the scope table entry for the Begin-End and
4784 Scopes
(Scope
.Last
).Sloc
:= SIS_Sloc
;
4785 Scopes
(Scope
.Last
).Etyp
:= E_Name
;
4786 Scopes
(Scope
.Last
).Ecol
:= SIS_Ecol
;
4787 Scopes
(Scope
.Last
).Labl
:= SIS_Labl
;
4788 Scopes
(Scope
.Last
).Lreq
:= False;
4789 SIS_Entry_Active
:= False;
4791 Set_Handled_Statement_Sequence
(Body_Node
,
4792 P_Handled_Sequence_Of_Statements
);
4793 End_Statements
(Handled_Statement_Sequence
(Body_Node
));
4800 -- Normally an END terminates the scan for basic declarative items.
4801 -- The one exception is END RECORD, which is probably left over from
4805 Save_Scan_State
(Scan_State
); -- at END
4808 if Token
= Tok_Record
then
4809 Error_Msg_SP
("no RECORD for this `end record`!");
4810 Scan
; -- past RECORD
4813 -- This might happen because of misplaced aspect specification.
4814 -- After discarding the misplaced aspects we can continue the
4818 Restore_Scan_State
(Scan_State
); -- to END
4822 -- The following tokens which can only be the start of a statement
4823 -- are considered to end a declarative part (i.e. we have a missing
4824 -- BEGIN situation). We are fairly conservative in making this
4825 -- judgment, because it is a real mess to go into statement mode
4826 -- prematurely in response to a junk declaration.
4841 -- If we parsing declarations in a sequence of statements, we want
4842 -- to let the caller continue parsing statements.
4844 if In_Statements
then
4847 -- Otherwise, give an error. But before we decide that it's a
4848 -- statement, check for a reserved word misused as an identifier.
4850 elsif Is_Reserved_Identifier
then
4851 Save_Scan_State
(Scan_State
);
4852 Scan
; -- past the token
4854 -- If reserved identifier not followed by colon or comma, then
4855 -- this is most likely an assignment statement to the bad id.
4857 if Token
not in Tok_Colon | Tok_Comma
then
4858 Restore_Scan_State
(Scan_State
);
4859 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4861 -- Otherwise we have a declaration of the bad id
4864 Restore_Scan_State
(Scan_State
);
4865 Scan_Reserved_Identifier
(Force_Msg
=> True);
4866 P_Identifier_Declarations
4867 (Decls
, Done
, In_Spec
, In_Statements
);
4870 -- If not reserved identifier, then it's an incorrectly placed a
4874 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4877 -- The token RETURN may well also signal a missing BEGIN situation,
4878 -- however, we never let it end the declarative part, because it
4879 -- might also be part of a half-baked function declaration. If we are
4880 -- In_Statements, then let the caller parse it; otherwise, it's an
4884 if In_Statements
then
4887 Error_Msg_SC
("misplaced RETURN statement");
4891 -- PRIVATE definitely terminates the declarations in a spec,
4892 -- and is an error in a body.
4898 Error_Msg_SC
("PRIVATE not allowed in body");
4899 Scan
; -- past PRIVATE
4902 -- An end of file definitely terminates the declarations
4907 -- The remaining tokens do not end the scan, but cannot start a
4908 -- valid declaration, so we signal an error and resynchronize.
4909 -- But first check for misuse of a reserved identifier.
4912 if In_Statements
then
4917 -- Here we check for a reserved identifier
4919 if Is_Reserved_Identifier
then
4920 Save_Scan_State
(Scan_State
);
4921 Scan
; -- past the token
4923 if Token
not in Tok_Colon | Tok_Comma
then
4924 Restore_Scan_State
(Scan_State
);
4925 Set_Declaration_Expected
;
4928 Restore_Scan_State
(Scan_State
);
4929 Scan_Reserved_Identifier
(Force_Msg
=> True);
4931 P_Identifier_Declarations
4932 (Decls
, Done
, In_Spec
, In_Statements
);
4936 Set_Declaration_Expected
;
4941 -- To resynchronize after an error, we scan to the next semicolon and
4942 -- return with Done = False, indicating that there may still be more
4943 -- valid declarations to come.
4946 when Error_Resync
=>
4947 Resync_Past_Semicolon
;
4948 end P_Declarative_Item
;
4950 procedure P_Declarative_Items
4952 Declare_Expression
: Boolean;
4954 In_Statements
: Boolean)
4960 (Decls
, Done
, Declare_Expression
, In_Spec
, In_Statements
);
4963 end P_Declarative_Items
;
4965 ----------------------------------
4966 -- 3.11 Basic Declarative Item --
4967 ----------------------------------
4969 -- BASIC_DECLARATIVE_ITEM ::=
4970 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4972 -- Scan zero or more basic declarative items
4974 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4975 -- the scan pointer is repositioned past the next semicolon, and the scan
4976 -- for declarative items continues.
4978 function P_Basic_Declarative_Items
4979 (Declare_Expression
: Boolean) return List_Id
4982 Decls
: constant List_Id
:= New_List
;
4986 -- Indicate no bad declarations detected yet in the current context:
4987 -- visible or private declarations of a package spec.
4989 Missing_Begin_Msg
:= No_Error_Msg
;
4991 -- Get rid of active SIS entry from outer scope. This means we will
4992 -- miss some nested cases, but it doesn't seem worth the effort. See
4993 -- discussion in Par for further details
4995 SIS_Entry_Active
:= False;
4998 (Decls
, Declare_Expression
, In_Spec
=> True, In_Statements
=> False);
5000 -- Get rid of active SIS entry. This is set only if we have scanned a
5001 -- procedure declaration and have not found the body. We could give
5002 -- an error message, but that really would be usurping the role of
5003 -- semantic analysis (this really is a case of a missing body).
5005 SIS_Entry_Active
:= False;
5007 -- Test for assorted illegal declarations not diagnosed elsewhere
5009 Decl
:= First
(Decls
);
5011 while Present
(Decl
) loop
5012 Kind
:= Nkind
(Decl
);
5014 -- Test for body scanned, not acceptable as basic decl item
5016 if Kind
= N_Subprogram_Body
or else
5017 Kind
= N_Package_Body
or else
5018 Kind
= N_Task_Body
or else
5019 Kind
= N_Protected_Body
5021 if Declare_Expression
then
5023 ("proper body not allowed in declare_expression",
5027 ("proper body not allowed in package spec",
5031 -- Complete declaration of mangled subprogram body, for better
5032 -- recovery if analysis is attempted.
5034 if Nkind
(Decl
) in N_Subprogram_Body | N_Package_Body | N_Task_Body
5035 and then No
(Handled_Statement_Sequence
(Decl
))
5037 Set_Handled_Statement_Sequence
(Decl
,
5038 Make_Handled_Sequence_Of_Statements
(Sloc
(Decl
),
5039 Statements
=> New_List
));
5042 -- Test for body stub scanned, not acceptable as basic decl item
5044 elsif Kind
in N_Body_Stub
then
5045 Error_Msg
("body stub not allowed in package spec", Sloc
(Decl
));
5047 elsif Kind
= N_Assignment_Statement
then
5049 ("assignment statement not allowed in package spec",
5057 end P_Basic_Declarative_Items
;
5063 -- For proper body, see below
5064 -- For body stub, see 10.1.3
5066 -----------------------
5067 -- 3.11 Proper Body --
5068 -----------------------
5070 -- Subprogram body is parsed by P_Subprogram (6.1)
5071 -- Package body is parsed by P_Package (7.1)
5072 -- Task body is parsed by P_Task (9.1)
5073 -- Protected body is parsed by P_Protected (9.4)
5075 ------------------------------
5076 -- Set_Declaration_Expected --
5077 ------------------------------
5079 procedure Set_Declaration_Expected
is
5081 Error_Msg_SC
("declaration expected");
5083 if Missing_Begin_Msg
= No_Error_Msg
then
5084 Missing_Begin_Msg
:= Get_Msg_Id
;
5086 end Set_Declaration_Expected
;
5088 ----------------------
5089 -- Skip_Declaration --
5090 ----------------------
5092 procedure Skip_Declaration
(S
: List_Id
) is
5093 Ignored_Done
: Boolean;
5096 (S
, Ignored_Done
, Declare_Expression
=> False, In_Spec
=> False,
5097 In_Statements
=> False);
5098 end Skip_Declaration
;
5100 -----------------------------------------
5101 -- Statement_When_Declaration_Expected --
5102 -----------------------------------------
5104 procedure Statement_When_Declaration_Expected
5110 -- Case of second occurrence of statement in one declaration sequence
5112 if Missing_Begin_Msg
/= No_Error_Msg
then
5114 -- In the procedure spec case, just ignore it, we only give one
5115 -- message for the first occurrence, since otherwise we may get
5116 -- horrible cascading if BODY was missing in the header line.
5121 -- Just ignore it if we are in -gnatd.2 (allow statements to appear
5122 -- in declaration sequences) mode.
5124 elsif Debug_Flag_Dot_2
then
5127 -- In the declarative part case, take a second statement as a sure
5128 -- sign that we really have a missing BEGIN, and end the declarative
5129 -- part now. Note that the caller will fix up the first message to
5130 -- say "missing BEGIN" so that's how the error will be signalled.
5137 -- Case of first occurrence of unexpected statement
5140 -- Do not give error message if we are operating in -gnatd.2 mode
5141 -- (alllow statements to appear in declarative parts).
5143 if not Debug_Flag_Dot_2
then
5145 -- If we are in a package spec, then give message of statement
5146 -- not allowed in package spec. This message never gets changed.
5149 Error_Msg_SC
("statement not allowed in package spec");
5151 -- If in declarative part, then we give the message complaining
5152 -- about finding a statement when a declaration is expected. This
5153 -- gets changed to a complaint about a missing BEGIN if we later
5154 -- find that no BEGIN is present.
5157 Error_Msg_SC
("statement not allowed in declarative part");
5160 -- Capture message Id. This is used for two purposes, first to
5161 -- stop multiple messages, see test above, and second, to allow
5162 -- the replacement of the message in the declarative part case.
5164 Missing_Begin_Msg
:= Get_Msg_Id
;
5168 -- In all cases except the case in which we decided to terminate the
5169 -- declaration sequence on a second error, we scan out the statement
5170 -- and append it to the list of declarations (note that the semantics
5171 -- can handle statements in a declaration list so if we proceed to
5172 -- call the semantic phase, all will be (reasonably) well.
5174 Append_List_To
(Decls
, P_Sequence_Of_Statements
(SS_Unco
));
5176 -- Done is set to False, since we want to continue the scan of
5177 -- declarations, hoping that this statement was a temporary glitch.
5178 -- If we indeed are now in the statement part (i.e. this was a missing
5179 -- BEGIN, then it's not terrible, we will simply keep calling this
5180 -- procedure to process the statements one by one, and then finally
5181 -- hit the missing BEGIN, which will clean up the error message.
5184 end Statement_When_Declaration_Expected
;