1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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_Items
84 -- Scans out a single declarative item, or, in the case of a declaration
85 -- with a list of identifiers, a list of declarations, one for each of the
86 -- identifiers in the list. The declaration or declarations scanned are
87 -- appended to the given list. Done indicates whether or not there may be
88 -- additional declarative items to scan. If Done is True, then a decision
89 -- has been made that there are no more items to scan. If Done is False,
90 -- then there may be additional declarations to scan. In_Spec is true if
91 -- we are scanning a package declaration, and is used to generate an
92 -- appropriate message if a statement is encountered in such a context.
94 procedure P_Identifier_Declarations
98 -- Scans out a set of declarations for an identifier or list of
99 -- identifiers, and appends them to the given list. The parameters have
100 -- the same significance as for P_Declarative_Items.
102 procedure Statement_When_Declaration_Expected
106 -- Called when a statement is found at a point where a declaration was
107 -- expected. The parameters are as described for P_Declarative_Items.
109 procedure Set_Declaration_Expected
;
110 -- Posts a "declaration expected" error messages at the start of the
111 -- current token, and if this is the first such message issued, saves
112 -- the message id in Missing_Begin_Msg, for possible later replacement.
114 ---------------------------------
115 -- Check_Restricted_Expression --
116 ---------------------------------
118 procedure Check_Restricted_Expression
(N
: Node_Id
) is
120 if Nkind_In
(N
, N_Op_And
, N_Op_Or
, N_Op_Xor
, N_And_Then
, N_Or_Else
) then
121 Check_Restricted_Expression
(Left_Opnd
(N
));
122 Check_Restricted_Expression
(Right_Opnd
(N
));
124 elsif Nkind_In
(N
, 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
= Tok_Colon_Equal
149 or else Token
= Tok_Equal
150 or else Token
= Tok_Is
154 -- Another possibility. If we have a literal followed by a semicolon,
155 -- we assume that we have a missing colon-equal.
157 elsif Token
in Token_Class_Literal
then
159 Scan_State
: Saved_Scan_State
;
162 Save_Scan_State
(Scan_State
);
163 Scan
; -- past literal or identifier
165 if Token
= Tok_Semicolon
then
166 Restore_Scan_State
(Scan_State
);
168 Restore_Scan_State
(Scan_State
);
173 -- Otherwise we definitely have no initialization expression
179 -- Merge here if we have an initialization expression
186 return P_Expression_No_Right_Paren
;
190 ----------------------------
191 -- 3.1 Basic Declaration --
192 ----------------------------
194 -- Parsed by P_Basic_Declarative_Items (3.9)
196 ------------------------------
197 -- 3.1 Defining Identifier --
198 ------------------------------
200 -- DEFINING_IDENTIFIER ::= IDENTIFIER
202 -- Error recovery: can raise Error_Resync
204 function P_Defining_Identifier
(C
: Id_Check
:= None
) return Node_Id
is
205 Ident_Node
: Node_Id
;
208 -- Scan out the identifier. Note that this code is essentially identical
209 -- to P_Identifier, except that in the call to Scan_Reserved_Identifier
210 -- we set Force_Msg to True, since we want at least one message for each
211 -- separate declaration (but not use) of a reserved identifier.
213 -- Duplication should be removed, common code should be factored???
215 if Token
= Tok_Identifier
then
216 Check_Future_Keyword
;
218 -- If we have a reserved identifier, manufacture an identifier with
219 -- a corresponding name after posting an appropriate error message
221 elsif Is_Reserved_Identifier
(C
) then
222 Scan_Reserved_Identifier
(Force_Msg
=> True);
224 -- Otherwise we have junk that cannot be interpreted as an identifier
227 T_Identifier
; -- to give message
231 Ident_Node
:= Token_Node
;
232 Scan
; -- past the reserved identifier
234 -- If we already have a defining identifier, clean it out and make
235 -- a new clean identifier. This situation arises in some error cases
236 -- and we need to fix it.
238 if Nkind
(Ident_Node
) = N_Defining_Identifier
then
239 Ident_Node
:= Make_Identifier
(Sloc
(Ident_Node
), Chars
(Ident_Node
));
242 -- Change identifier to defining identifier if not in error
244 if Ident_Node
/= Error
then
245 Change_Identifier_To_Defining_Identifier
(Ident_Node
);
247 -- Warn if standard redefinition, except that we never warn on a
248 -- record field definition (since this is always a harmless case).
250 if not Inside_Record_Definition
then
251 Warn_If_Standard_Redefinition
(Ident_Node
);
256 end P_Defining_Identifier
;
258 -----------------------------
259 -- 3.2.1 Type Declaration --
260 -----------------------------
262 -- TYPE_DECLARATION ::=
263 -- FULL_TYPE_DECLARATION
264 -- | INCOMPLETE_TYPE_DECLARATION
265 -- | PRIVATE_TYPE_DECLARATION
266 -- | PRIVATE_EXTENSION_DECLARATION
268 -- FULL_TYPE_DECLARATION ::=
269 -- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION
270 -- [ASPECT_SPECIFICATIONS];
271 -- | CONCURRENT_TYPE_DECLARATION
273 -- INCOMPLETE_TYPE_DECLARATION ::=
274 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] [is tagged];
276 -- PRIVATE_TYPE_DECLARATION ::=
277 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
278 -- is [abstract] [tagged] [limited] private
279 -- [ASPECT_SPECIFICATIONS];
281 -- PRIVATE_EXTENSION_DECLARATION ::=
282 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
283 -- [abstract] [limited | synchronized]
284 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
285 -- with private [ASPECT_SPECIFICATIONS];
287 -- TYPE_DEFINITION ::=
288 -- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
289 -- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
290 -- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
291 -- | DERIVED_TYPE_DEFINITION | INTERFACE_TYPE_DEFINITION
293 -- INTEGER_TYPE_DEFINITION ::=
294 -- SIGNED_INTEGER_TYPE_DEFINITION
295 -- MODULAR_TYPE_DEFINITION
297 -- INTERFACE_TYPE_DEFINITION ::=
298 -- [limited | task | protected | synchronized ] interface
299 -- [and INTERFACE_LIST]
301 -- Error recovery: can raise Error_Resync
303 -- The processing for full type declarations, incomplete type declarations,
304 -- private type declarations and type definitions is included in this
305 -- function. The processing for concurrent type declarations is NOT here,
306 -- but rather in chapter 9 (this function handles only declarations
307 -- starting with TYPE).
309 function P_Type_Declaration
return Node_Id
is
310 Abstract_Present
: Boolean := False;
311 Abstract_Loc
: Source_Ptr
:= No_Location
;
313 Discr_List
: List_Id
;
314 Discr_Sloc
: Source_Ptr
;
316 Ident_Node
: Node_Id
;
317 Is_Derived_Iface
: Boolean := False;
318 Type_Loc
: Source_Ptr
;
319 Type_Start_Col
: Column_Number
;
320 Unknown_Dis
: Boolean;
322 Typedef_Node
: Node_Id
;
323 -- Normally holds type definition, except in the case of a private
324 -- extension declaration, in which case it holds the declaration itself
327 Type_Loc
:= Token_Ptr
;
328 Type_Start_Col
:= Start_Column
;
330 -- If we have TYPE, then proceed ahead and scan identifier
332 if Token
= Tok_Type
then
333 Type_Token_Location
:= Type_Loc
;
335 Ident_Node
:= P_Defining_Identifier
(C_Is
);
337 -- Otherwise this is an error case
341 Type_Token_Location
:= Type_Loc
;
342 Ident_Node
:= P_Defining_Identifier
(C_Is
);
345 Discr_Sloc
:= Token_Ptr
;
347 if P_Unknown_Discriminant_Part_Opt
then
349 Discr_List
:= No_List
;
351 Unknown_Dis
:= False;
352 Discr_List
:= P_Known_Discriminant_Part_Opt
;
355 -- Incomplete type declaration. We complete the processing for this
356 -- case here and return the resulting incomplete type declaration node
358 if Token
= Tok_Semicolon
then
360 Decl_Node
:= New_Node
(N_Incomplete_Type_Declaration
, Type_Loc
);
361 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
362 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
363 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
370 -- Full type declaration or private type declaration, must have IS
372 if Token
= Tok_Equal
then
374 Scan
; -- past = used in place of IS
376 elsif Token
= Tok_Renames
then
377 Error_Msg_SC
-- CODEFIX
378 ("RENAMES should be IS");
379 Scan
; -- past RENAMES used in place of IS
385 -- First an error check, if we have two identifiers in a row, a likely
386 -- possibility is that the first of the identifiers is an incorrectly
389 if Token
= Tok_Identifier
then
391 SS
: Saved_Scan_State
;
395 Save_Scan_State
(SS
);
396 Scan
; -- past initial identifier
397 I2
:= (Token
= Tok_Identifier
);
398 Restore_Scan_State
(SS
);
402 (Bad_Spelling_Of
(Tok_Abstract
) or else
403 Bad_Spelling_Of
(Tok_Access
) or else
404 Bad_Spelling_Of
(Tok_Aliased
) or else
405 Bad_Spelling_Of
(Tok_Constant
))
412 -- Check for misuse of Ada 95 keyword abstract in Ada 83 mode
414 if Token_Name
= Name_Abstract
then
415 Check_95_Keyword
(Tok_Abstract
, Tok_Tagged
);
416 Check_95_Keyword
(Tok_Abstract
, Tok_New
);
419 -- Check cases of misuse of ABSTRACT
421 if Token
= Tok_Abstract
then
422 Abstract_Present
:= True;
423 Abstract_Loc
:= Token_Ptr
;
424 Scan
; -- past ABSTRACT
426 -- Ada 2005 (AI-419): AARM 3.4 (2/2)
428 if (Ada_Version
< Ada_2005
and then Token
= Tok_Limited
)
429 or else Token
= Tok_Private
430 or else Token
= Tok_Record
431 or else Token
= Tok_Null
433 Error_Msg_AP
("TAGGED expected");
437 -- Check for misuse of Ada 95 keyword Tagged
439 if Token_Name
= Name_Tagged
then
440 Check_95_Keyword
(Tok_Tagged
, Tok_Private
);
441 Check_95_Keyword
(Tok_Tagged
, Tok_Limited
);
442 Check_95_Keyword
(Tok_Tagged
, Tok_Record
);
445 -- Special check for misuse of Aliased
447 if Token
= Tok_Aliased
or else Token_Name
= Name_Aliased
then
448 Error_Msg_SC
("ALIASED not allowed in type definition");
449 Scan
; -- past ALIASED
452 -- The following processing deals with either a private type declaration
453 -- or a full type declaration. In the private type case, we build the
454 -- N_Private_Type_Declaration node, setting its Tagged_Present and
455 -- Limited_Present flags, on encountering the Private keyword, and
456 -- leave Typedef_Node set to Empty. For the full type declaration
457 -- case, Typedef_Node gets set to the type definition.
459 Typedef_Node
:= Empty
;
461 -- Switch on token following the IS. The loop normally runs once. It
462 -- only runs more than once if an error is detected, to try again after
463 -- detecting and fixing up the error.
468 | Tok_Not
-- Ada 2005 (AI-231)
470 Typedef_Node
:= P_Access_Type_Definition
;
474 Typedef_Node
:= P_Array_Type_Definition
;
478 Typedef_Node
:= P_Fixed_Point_Definition
;
482 Typedef_Node
:= P_Floating_Point_Definition
;
488 when Tok_Integer_Literal
=>
490 Typedef_Node
:= P_Signed_Integer_Type_Definition
;
494 Typedef_Node
:= P_Record_Definition
;
497 when Tok_Left_Paren
=>
498 Typedef_Node
:= P_Enumeration_Type_Definition
;
500 End_Labl
:= Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
501 Set_Comes_From_Source
(End_Labl
, False);
503 Set_End_Label
(Typedef_Node
, End_Labl
);
507 Typedef_Node
:= P_Modular_Type_Definition
;
511 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
513 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
514 and then Present
(Record_Extension_Part
(Typedef_Node
))
516 End_Labl
:= Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
517 Set_Comes_From_Source
(End_Labl
, False);
520 (Record_Extension_Part
(Typedef_Node
), End_Labl
);
526 Typedef_Node
:= P_Signed_Integer_Type_Definition
;
530 Typedef_Node
:= P_Record_Definition
;
532 End_Labl
:= Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
533 Set_Comes_From_Source
(End_Labl
, False);
535 Set_End_Label
(Typedef_Node
, End_Labl
);
541 -- Ada 2005 (AI-326): If the words IS TAGGED appear, the type
542 -- is a tagged incomplete type.
544 if Ada_Version
>= Ada_2005
545 and then Token
= Tok_Semicolon
550 New_Node
(N_Incomplete_Type_Declaration
, Type_Loc
);
551 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
552 Set_Tagged_Present
(Decl_Node
);
553 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
554 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
559 if Token
= Tok_Abstract
then
560 Error_Msg_SC
-- CODEFIX
561 ("ABSTRACT must come before TAGGED");
562 Abstract_Present
:= True;
563 Abstract_Loc
:= Token_Ptr
;
564 Scan
; -- past ABSTRACT
567 if Token
= Tok_Limited
then
568 Scan
; -- past LIMITED
570 -- TAGGED LIMITED PRIVATE case
572 if Token
= Tok_Private
then
574 New_Node
(N_Private_Type_Declaration
, Type_Loc
);
575 Set_Tagged_Present
(Decl_Node
, True);
576 Set_Limited_Present
(Decl_Node
, True);
577 Scan
; -- past PRIVATE
579 -- TAGGED LIMITED RECORD
582 Typedef_Node
:= P_Record_Definition
;
583 Set_Tagged_Present
(Typedef_Node
, True);
584 Set_Limited_Present
(Typedef_Node
, True);
587 Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
588 Set_Comes_From_Source
(End_Labl
, False);
590 Set_End_Label
(Typedef_Node
, End_Labl
);
596 if Token
= Tok_Private
then
598 New_Node
(N_Private_Type_Declaration
, Type_Loc
);
599 Set_Tagged_Present
(Decl_Node
, True);
600 Scan
; -- past PRIVATE
605 Typedef_Node
:= P_Record_Definition
;
606 Set_Tagged_Present
(Typedef_Node
, True);
609 Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
610 Set_Comes_From_Source
(End_Labl
, False);
612 Set_End_Label
(Typedef_Node
, End_Labl
);
619 Scan
; -- past LIMITED
622 if Token
= Tok_Tagged
then
623 Error_Msg_SC
-- CODEFIX
624 ("TAGGED must come before LIMITED");
627 elsif Token
= Tok_Abstract
then
628 Error_Msg_SC
-- CODEFIX
629 ("ABSTRACT must come before LIMITED");
630 Scan
; -- past ABSTRACT
637 -- LIMITED RECORD or LIMITED NULL RECORD
639 if Token
= Tok_Record
or else Token
= Tok_Null
then
640 if Ada_Version
= Ada_83
then
642 ("(Ada 83) limited record declaration not allowed!");
644 -- In Ada 2005, "abstract limited" can appear before "new",
645 -- but it cannot be part of an untagged record declaration.
647 elsif Abstract_Present
648 and then Prev_Token
/= Tok_Tagged
650 Error_Msg_SP
("TAGGED expected");
653 Typedef_Node
:= P_Record_Definition
;
654 Set_Limited_Present
(Typedef_Node
, True);
655 End_Labl
:= Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
656 Set_Comes_From_Source
(End_Labl
, False);
658 Set_End_Label
(Typedef_Node
, End_Labl
);
660 -- Ada 2005 (AI-251): LIMITED INTERFACE
662 -- If we are compiling in Ada 83 or Ada 95 mode, "interface"
663 -- is not a reserved word but we force its analysis to
664 -- generate the corresponding usage error.
666 elsif Token
= Tok_Interface
667 or else (Token
= Tok_Identifier
668 and then Chars
(Token_Node
) = Name_Interface
)
671 P_Interface_Type_Definition
(Abstract_Present
);
672 Abstract_Present
:= True;
673 Set_Limited_Present
(Typedef_Node
);
675 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
then
676 Is_Derived_Iface
:= True;
679 -- Ada 2005 (AI-419): LIMITED NEW
681 elsif Token
= Tok_New
then
682 if Ada_Version
< Ada_2005
then
684 ("LIMITED in derived type is an Ada 2005 extension");
686 ("\unit must be compiled with -gnat05 switch");
689 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
690 Set_Limited_Present
(Typedef_Node
);
692 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
693 and then Present
(Record_Extension_Part
(Typedef_Node
))
696 Make_Identifier
(Token_Ptr
, Chars
(Ident_Node
));
697 Set_Comes_From_Source
(End_Labl
, False);
700 (Record_Extension_Part
(Typedef_Node
), End_Labl
);
703 -- LIMITED PRIVATE is the only remaining possibility here
706 Decl_Node
:= New_Node
(N_Private_Type_Declaration
, Type_Loc
);
707 Set_Limited_Present
(Decl_Node
, True);
708 T_Private
; -- past PRIVATE (or complain if not there)
713 -- Here we have an identifier after the IS, which is certainly
714 -- wrong and which might be one of several different mistakes.
716 when Tok_Identifier
=>
718 -- First case, if identifier is on same line, then probably we
719 -- have something like "type X is Integer .." and the best
720 -- diagnosis is a missing NEW. Note: the missing new message
721 -- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl.
723 if not Token_Is_At_Start_Of_Line
then
724 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
726 -- If the identifier is at the start of the line, and is in the
727 -- same column as the type declaration itself then we consider
728 -- that we had a missing type definition on the previous line
730 elsif Start_Column
<= Type_Start_Col
then
731 Error_Msg_AP
("type definition expected");
732 Typedef_Node
:= Error
;
734 -- If the identifier is at the start of the line, and is in
735 -- a column to the right of the type declaration line, then we
736 -- may have something like:
741 -- and the best diagnosis is a missing record keyword
744 Typedef_Node
:= P_Record_Definition
;
749 -- Ada 2005 (AI-251): INTERFACE
751 when Tok_Interface
=>
752 Typedef_Node
:= P_Interface_Type_Definition
(Abstract_Present
);
753 Abstract_Present
:= True;
757 Decl_Node
:= New_Node
(N_Private_Type_Declaration
, Type_Loc
);
758 Scan
; -- past PRIVATE
760 -- Check error cases of private [abstract] tagged
762 if Token
= Tok_Abstract
then
763 Error_Msg_SC
("`ABSTRACT TAGGED` must come before PRIVATE");
764 Scan
; -- past ABSTRACT
766 if Token
= Tok_Tagged
then
770 elsif Token
= Tok_Tagged
then
771 Error_Msg_SC
("TAGGED must come before PRIVATE");
777 -- Ada 2005 (AI-345): Protected, synchronized or task interface
778 -- or Ada 2005 (AI-443): Synchronized private extension.
785 Saved_Token
: constant Token_Type
:= Token
;
788 Scan
; -- past TASK, PROTECTED or SYNCHRONIZED
790 -- Synchronized private extension
792 if Token
= Tok_New
then
793 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
795 if Saved_Token
= Tok_Synchronized
then
796 if Nkind
(Typedef_Node
) =
797 N_Derived_Type_Definition
800 ("SYNCHRONIZED not allowed for record extension",
803 Set_Synchronized_Present
(Typedef_Node
);
807 Error_Msg_SC
("invalid kind of private extension");
813 if Token
/= Tok_Interface
then
814 Error_Msg_SC
("NEW or INTERFACE expected");
818 P_Interface_Type_Definition
(Abstract_Present
);
819 Abstract_Present
:= True;
823 Set_Task_Present
(Typedef_Node
);
825 when Tok_Protected
=>
826 Set_Protected_Present
(Typedef_Node
);
828 when Tok_Synchronized
=>
829 Set_Synchronized_Present
(Typedef_Node
);
832 pragma Assert
(False);
840 -- Anything else is an error
843 if Bad_Spelling_Of
(Tok_Access
)
845 Bad_Spelling_Of
(Tok_Array
)
847 Bad_Spelling_Of
(Tok_Delta
)
849 Bad_Spelling_Of
(Tok_Digits
)
851 Bad_Spelling_Of
(Tok_Limited
)
853 Bad_Spelling_Of
(Tok_Private
)
855 Bad_Spelling_Of
(Tok_Range
)
857 Bad_Spelling_Of
(Tok_Record
)
859 Bad_Spelling_Of
(Tok_Tagged
)
864 Error_Msg_AP
("type definition expected");
870 -- For the private type declaration case, the private type declaration
871 -- node has been built, with the Tagged_Present and Limited_Present
872 -- flags set as needed, and Typedef_Node is left set to Empty.
874 if No
(Typedef_Node
) then
875 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
876 Set_Abstract_Present
(Decl_Node
, Abstract_Present
);
878 -- For a private extension declaration, Typedef_Node contains the
879 -- N_Private_Extension_Declaration node, which we now complete. Note
880 -- that the private extension declaration, unlike a full type
881 -- declaration, does permit unknown discriminants.
883 elsif Nkind
(Typedef_Node
) = N_Private_Extension_Declaration
then
884 Decl_Node
:= Typedef_Node
;
885 Set_Sloc
(Decl_Node
, Type_Loc
);
886 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
887 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
889 -- In the full type declaration case, Typedef_Node has the type
890 -- definition and here is where we build the full type declaration
891 -- node. This is also where we check for improper use of an unknown
892 -- discriminant part (not allowed for full type declaration).
895 if Nkind
(Typedef_Node
) = N_Record_Definition
896 or else (Nkind
(Typedef_Node
) = N_Derived_Type_Definition
897 and then Present
(Record_Extension_Part
(Typedef_Node
)))
898 or else Is_Derived_Iface
900 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
902 elsif Abstract_Present
then
903 Error_Msg
("ABSTRACT not allowed here, ignored", Abstract_Loc
);
906 Decl_Node
:= New_Node
(N_Full_Type_Declaration
, Type_Loc
);
907 Set_Type_Definition
(Decl_Node
, Typedef_Node
);
911 ("Full type declaration cannot have unknown discriminants",
916 -- Remaining processing is common for all three cases
918 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
919 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
920 P_Aspect_Specifications
(Decl_Node
);
922 end P_Type_Declaration
;
924 ----------------------------------
925 -- 3.2.1 Full Type Declaration --
926 ----------------------------------
928 -- Parsed by P_Type_Declaration (3.2.1)
930 ----------------------------
931 -- 3.2.1 Type Definition --
932 ----------------------------
934 -- Parsed by P_Type_Declaration (3.2.1)
936 --------------------------------
937 -- 3.2.2 Subtype Declaration --
938 --------------------------------
940 -- SUBTYPE_DECLARATION ::=
941 -- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION
942 -- [ASPECT_SPECIFICATIONS];
944 -- The caller has checked that the initial token is SUBTYPE
946 -- Error recovery: can raise Error_Resync
948 function P_Subtype_Declaration
return Node_Id
is
950 Not_Null_Present
: Boolean := False;
953 Decl_Node
:= New_Node
(N_Subtype_Declaration
, Token_Ptr
);
954 Scan
; -- past SUBTYPE
955 Set_Defining_Identifier
(Decl_Node
, P_Defining_Identifier
(C_Is
));
958 if Token
= Tok_New
then
959 Error_Msg_SC
-- CODEFIX
960 ("NEW ignored (only allowed in type declaration)");
964 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
965 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
967 Set_Subtype_Indication
968 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
969 P_Aspect_Specifications
(Decl_Node
);
971 end P_Subtype_Declaration
;
973 -------------------------------
974 -- 3.2.2 Subtype Indication --
975 -------------------------------
977 -- SUBTYPE_INDICATION ::=
978 -- [not null] SUBTYPE_MARK [CONSTRAINT]
980 -- Error recovery: can raise Error_Resync
982 function P_Null_Exclusion
983 (Allow_Anonymous_In_95
: Boolean := False) return Boolean
985 Not_Loc
: constant Source_Ptr
:= Token_Ptr
;
986 -- Source position of "not", if present
989 if Token
/= Tok_Not
then
995 if Token
= Tok_Null
then
998 -- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95,
999 -- except in the case of anonymous access types.
1001 -- Allow_Anonymous_In_95 will be True if we're parsing a formal
1002 -- parameter or discriminant, which are the only places where
1003 -- anonymous access types occur in Ada 95. "Formal : not null
1004 -- access ..." is legal in Ada 95, whereas "Formal : not null
1005 -- Named_Access_Type" is not.
1007 if Ada_Version
>= Ada_2005
1008 or else (Ada_Version
>= Ada_95
1009 and then Allow_Anonymous_In_95
1010 and then Token
= Tok_Access
)
1016 ("`NOT NULL` access type is an Ada 2005 extension", Not_Loc
);
1018 ("\unit should be compiled with -gnat05 switch", Not_Loc
);
1022 Error_Msg_SP
("NULL expected");
1025 if Token
= Tok_New
then
1026 Error_Msg
("`NOT NULL` comes after NEW, not before", Not_Loc
);
1031 end P_Null_Exclusion
;
1033 function P_Subtype_Indication
1034 (Not_Null_Present
: Boolean := False) return Node_Id
1036 Type_Node
: Node_Id
;
1039 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
1040 Type_Node
:= P_Subtype_Mark
;
1041 return P_Subtype_Indication
(Type_Node
, Not_Null_Present
);
1044 -- Check for error of using record definition and treat it nicely,
1045 -- otherwise things are really messed up, so resynchronize.
1047 if Token
= Tok_Record
then
1048 Error_Msg_SC
("anonymous record definitions are not permitted");
1049 Discard_Junk_Node
(P_Record_Definition
);
1053 Error_Msg_AP
("subtype indication expected");
1057 end P_Subtype_Indication
;
1059 -- The following function is identical except that it is called with
1060 -- the subtype mark already scanned out, and it scans out the constraint
1062 -- Error recovery: can raise Error_Resync
1064 function P_Subtype_Indication
1065 (Subtype_Mark
: Node_Id
;
1066 Not_Null_Present
: Boolean := False) return Node_Id
1068 Indic_Node
: Node_Id
;
1069 Constr_Node
: Node_Id
;
1072 Constr_Node
:= P_Constraint_Opt
;
1076 (Nkind
(Constr_Node
) = N_Range_Constraint
1077 and then Nkind
(Range_Expression
(Constr_Node
)) = N_Error
)
1079 return Subtype_Mark
;
1081 if Not_Null_Present
then
1082 Error_Msg_SP
("`NOT NULL` not allowed if constraint given");
1085 Indic_Node
:= New_Node
(N_Subtype_Indication
, Sloc
(Subtype_Mark
));
1086 Set_Subtype_Mark
(Indic_Node
, Check_Subtype_Mark
(Subtype_Mark
));
1087 Set_Constraint
(Indic_Node
, Constr_Node
);
1090 end P_Subtype_Indication
;
1092 -------------------------
1093 -- 3.2.2 Subtype Mark --
1094 -------------------------
1096 -- SUBTYPE_MARK ::= subtype_NAME;
1098 -- Note: The subtype mark which appears after an IN or NOT IN
1099 -- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
1101 -- Error recovery: cannot raise Error_Resync
1103 function P_Subtype_Mark
return Node_Id
is
1105 return P_Subtype_Mark_Resync
;
1107 when Error_Resync
=>
1111 -- This routine differs from P_Subtype_Mark in that it insists that an
1112 -- identifier be present, and if it is not, it raises Error_Resync.
1114 -- Error recovery: can raise Error_Resync
1116 function P_Subtype_Mark_Resync
return Node_Id
is
1117 Type_Node
: Node_Id
;
1120 if Token
= Tok_Access
then
1121 Error_Msg_SC
("anonymous access type definition not allowed here");
1122 Scan
; -- past ACCESS
1125 if Token
= Tok_Array
then
1126 Error_Msg_SC
("anonymous array definition not allowed here");
1127 Discard_Junk_Node
(P_Array_Type_Definition
);
1131 Type_Node
:= P_Qualified_Simple_Name_Resync
;
1133 -- Check for a subtype mark attribute. The only valid possibilities
1134 -- are 'CLASS and 'BASE. Anything else is a definite error. We may
1135 -- as well catch it here.
1137 if Token
= Tok_Apostrophe
then
1138 return P_Subtype_Mark_Attribute
(Type_Node
);
1143 end P_Subtype_Mark_Resync
;
1145 -- The following function is called to scan out a subtype mark attribute.
1146 -- The caller has already scanned out the subtype mark, which is passed in
1147 -- as the argument, and has checked that the current token is apostrophe.
1149 -- Only a special subclass of attributes, called type attributes
1150 -- (see Snames package) are allowed in this syntactic position.
1152 -- Note: if the apostrophe is followed by other than an identifier, then
1153 -- the input expression is returned unchanged, and the scan pointer is
1154 -- left pointing to the apostrophe.
1156 -- Error recovery: can raise Error_Resync
1158 function P_Subtype_Mark_Attribute
(Type_Node
: Node_Id
) return Node_Id
is
1159 Attr_Node
: Node_Id
:= Empty
;
1160 Scan_State
: Saved_Scan_State
;
1164 Prefix
:= Check_Subtype_Mark
(Type_Node
);
1166 if Prefix
= Error
then
1170 -- Loop through attributes appearing (more than one can appear as for
1171 -- for example in X'Base'Class). We are at an apostrophe on entry to
1172 -- this loop, and it runs once for each attribute parsed, with
1173 -- Prefix being the current possible prefix if it is an attribute.
1176 Save_Scan_State
(Scan_State
); -- at Apostrophe
1177 Scan
; -- past apostrophe
1179 if Token
/= Tok_Identifier
then
1180 Restore_Scan_State
(Scan_State
); -- to apostrophe
1181 return Prefix
; -- no attribute after all
1183 elsif not Is_Type_Attribute_Name
(Token_Name
) then
1185 ("attribute & may not be used in a subtype mark", Token_Node
);
1190 Make_Attribute_Reference
(Prev_Token_Ptr
,
1192 Attribute_Name
=> Token_Name
);
1193 Scan
; -- past type attribute identifier
1196 exit when Token
/= Tok_Apostrophe
;
1197 Prefix
:= Attr_Node
;
1200 -- Fall through here after scanning type attribute
1203 end P_Subtype_Mark_Attribute
;
1205 -----------------------
1206 -- 3.2.2 Constraint --
1207 -----------------------
1209 -- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
1211 -- SCALAR_CONSTRAINT ::=
1212 -- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
1214 -- COMPOSITE_CONSTRAINT ::=
1215 -- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
1217 -- If no constraint is present, this function returns Empty
1219 -- Error recovery: can raise Error_Resync
1221 function P_Constraint_Opt
return Node_Id
is
1223 if Token
= Tok_Range
or else Bad_Spelling_Of
(Tok_Range
) then
1224 return P_Range_Constraint
;
1226 elsif Token
= Tok_Digits
or else Bad_Spelling_Of
(Tok_Digits
) then
1227 return P_Digits_Constraint
;
1229 elsif Token
= Tok_Delta
or else Bad_Spelling_Of
(Tok_Delta
) then
1230 return P_Delta_Constraint
;
1232 elsif Token
= Tok_Left_Paren
then
1233 return P_Index_Or_Discriminant_Constraint
;
1235 elsif Token
= Tok_In
then
1237 return P_Constraint_Opt
;
1239 -- One more possibility is e.g. 1 .. 10 (i.e. missing RANGE keyword)
1241 elsif Token
= Tok_Identifier
or else
1242 Token
= Tok_Integer_Literal
or else
1243 Token
= Tok_Real_Literal
1246 Scan_State
: Saved_Scan_State
;
1249 Save_Scan_State
(Scan_State
); -- at identifier or literal
1250 Scan
; -- past identifier or literal
1252 if Token
= Tok_Dot_Dot
then
1253 Restore_Scan_State
(Scan_State
);
1254 Error_Msg_BC
("missing RANGE keyword");
1255 return P_Range_Constraint
;
1257 Restore_Scan_State
(Scan_State
);
1262 -- Nothing worked, no constraint there
1267 end P_Constraint_Opt
;
1269 ------------------------------
1270 -- 3.2.2 Scalar Constraint --
1271 ------------------------------
1273 -- Parsed by P_Constraint_Opt (3.2.2)
1275 ---------------------------------
1276 -- 3.2.2 Composite Constraint --
1277 ---------------------------------
1279 -- Parsed by P_Constraint_Opt (3.2.2)
1281 --------------------------------------------------------
1282 -- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
1283 --------------------------------------------------------
1285 -- This routine scans out a declaration starting with an identifier:
1287 -- OBJECT_DECLARATION ::=
1288 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1289 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
1290 -- [ASPECT_SPECIFICATIONS];
1291 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1292 -- ACCESS_DEFINITION [:= EXPRESSION]
1293 -- [ASPECT_SPECIFICATIONS];
1294 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1295 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION]
1296 -- [ASPECT_SPECIFICATIONS];
1298 -- NUMBER_DECLARATION ::=
1299 -- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
1301 -- OBJECT_RENAMING_DECLARATION ::=
1302 -- DEFINING_IDENTIFIER :
1303 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME
1304 -- [ASPECT_SPECIFICATIONS];
1305 -- | DEFINING_IDENTIFIER :
1306 -- ACCESS_DEFINITION renames object_NAME
1307 -- [ASPECT_SPECIFICATIONS];
1309 -- EXCEPTION_RENAMING_DECLARATION ::=
1310 -- DEFINING_IDENTIFIER : exception renames exception_NAME
1311 -- [ASPECT_SPECIFICATIONS];
1313 -- EXCEPTION_DECLARATION ::=
1314 -- DEFINING_IDENTIFIER_LIST : exception
1315 -- [ASPECT_SPECIFICATIONS];
1317 -- Note that the ALIASED indication in an object declaration is
1318 -- marked by a flag in the parent node.
1320 -- The caller has checked that the initial token is an identifier
1322 -- The value returned is a list of declarations, one for each identifier
1323 -- in the list (as described in Sinfo, we always split up multiple
1324 -- declarations into the equivalent sequence of single declarations
1325 -- using the More_Ids and Prev_Ids flags to preserve the source).
1327 -- If the identifier turns out to be a probable statement rather than
1328 -- an identifier, then the scan is left pointing to the identifier and
1329 -- No_List is returned.
1331 -- Error recovery: can raise Error_Resync
1333 procedure P_Identifier_Declarations
1339 Decl_Node
: Node_Id
;
1340 Type_Node
: Node_Id
;
1341 Ident_Sloc
: Source_Ptr
;
1342 Scan_State
: Saved_Scan_State
;
1343 List_OK
: Boolean := True;
1345 Init_Expr
: Node_Id
;
1346 Init_Loc
: Source_Ptr
;
1347 Con_Loc
: Source_Ptr
;
1348 Not_Null_Present
: Boolean := False;
1350 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
1351 -- Used to save identifiers in the identifier list. The upper bound
1352 -- of 4096 is expected to be infinite in practice, and we do not even
1353 -- bother to check if this upper bound is exceeded.
1355 Num_Idents
: Nat
:= 1;
1356 -- Number of identifiers stored in Idents
1359 -- This procedure is called in renames cases to make sure that we do
1360 -- not have more than one identifier. If we do have more than one
1361 -- then an error message is issued (and the declaration is split into
1362 -- multiple declarations)
1364 function Token_Is_Renames
return Boolean;
1365 -- Checks if current token is RENAMES, and if so, scans past it and
1366 -- returns True, otherwise returns False. Includes checking for some
1367 -- common error cases.
1373 procedure No_List
is
1375 if Num_Idents
> 1 then
1377 ("identifier list not allowed for RENAMES",
1384 ----------------------
1385 -- Token_Is_Renames --
1386 ----------------------
1388 function Token_Is_Renames
return Boolean is
1389 At_Colon
: Saved_Scan_State
;
1392 if Token
= Tok_Colon
then
1393 Save_Scan_State
(At_Colon
);
1395 Check_Misspelling_Of
(Tok_Renames
);
1397 if Token
= Tok_Renames
then
1398 Error_Msg_SP
-- CODEFIX
1399 ("|extra "":"" ignored");
1400 Scan
; -- past RENAMES
1403 Restore_Scan_State
(At_Colon
);
1408 Check_Misspelling_Of
(Tok_Renames
);
1410 if Token
= Tok_Renames
then
1411 Scan
; -- past RENAMES
1417 end Token_Is_Renames
;
1419 -- Start of processing for P_Identifier_Declarations
1422 Ident_Sloc
:= Token_Ptr
;
1423 Save_Scan_State
(Scan_State
); -- at first identifier
1424 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
1426 -- If we have a colon after the identifier, then we can assume that
1427 -- this is in fact a valid identifier declaration and can steam ahead.
1429 if Token
= Tok_Colon
then
1432 -- If we have a comma, then scan out the list of identifiers
1434 elsif Token
= Tok_Comma
then
1435 while Comma_Present
loop
1436 Num_Idents
:= Num_Idents
+ 1;
1437 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
1440 Save_Scan_State
(Scan_State
); -- at colon
1443 -- If we have identifier followed by := then we assume that what is
1444 -- really meant is an assignment statement. The assignment statement
1445 -- is scanned out and added to the list of declarations. An exception
1446 -- occurs if the := is followed by the keyword constant, in which case
1447 -- we assume it was meant to be a colon.
1449 elsif Token
= Tok_Colon_Equal
then
1452 if Token
= Tok_Constant
then
1453 Error_Msg_SP
("colon expected");
1456 Restore_Scan_State
(Scan_State
);
1458 -- Reset Token_Node, because it already got changed from an
1459 -- Identifier to a Defining_Identifier, and we don't want that
1463 Make_Identifier
(Sloc
(Token_Node
), Chars
(Token_Node
));
1465 -- And now scan out one or more statements
1467 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
1471 -- If we have an IS keyword, then assume the TYPE keyword was missing
1473 elsif Token
= Tok_Is
then
1474 Restore_Scan_State
(Scan_State
);
1475 Append_To
(Decls
, P_Type_Declaration
);
1479 -- Otherwise we have an error situation
1482 Restore_Scan_State
(Scan_State
);
1484 -- First case is possible misuse of PROTECTED in Ada 83 mode. If
1485 -- so, fix the keyword and return to scan the protected declaration.
1487 if Token_Name
= Name_Protected
then
1488 Check_95_Keyword
(Tok_Protected
, Tok_Identifier
);
1489 Check_95_Keyword
(Tok_Protected
, Tok_Type
);
1490 Check_95_Keyword
(Tok_Protected
, Tok_Body
);
1492 if Token
= Tok_Protected
then
1497 -- Check misspelling possibilities. If so, correct the misspelling
1498 -- and return to scan out the resulting declaration.
1500 elsif Bad_Spelling_Of
(Tok_Function
)
1501 or else Bad_Spelling_Of
(Tok_Procedure
)
1502 or else Bad_Spelling_Of
(Tok_Package
)
1503 or else Bad_Spelling_Of
(Tok_Pragma
)
1504 or else Bad_Spelling_Of
(Tok_Protected
)
1505 or else Bad_Spelling_Of
(Tok_Generic
)
1506 or else Bad_Spelling_Of
(Tok_Subtype
)
1507 or else Bad_Spelling_Of
(Tok_Type
)
1508 or else Bad_Spelling_Of
(Tok_Task
)
1509 or else Bad_Spelling_Of
(Tok_Use
)
1510 or else Bad_Spelling_Of
(Tok_For
)
1515 -- Otherwise we definitely have an ordinary identifier with a junk
1519 -- If in -gnatd.2 mode, try for statements
1521 if Debug_Flag_Dot_2
then
1522 Restore_Scan_State
(Scan_State
);
1524 -- Reset Token_Node, because it already got changed from an
1525 -- Identifier to a Defining_Identifier, and we don't want that
1529 Make_Identifier
(Sloc
(Token_Node
), Chars
(Token_Node
));
1531 -- And now scan out one or more statements
1533 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
1536 -- Normal case, just complain and skip to semicolon
1539 Set_Declaration_Expected
;
1540 Resync_Past_Semicolon
;
1547 -- Come here with an identifier list and colon scanned out. We now
1548 -- build the nodes for the declarative items. One node is built for
1549 -- each identifier in the list, with the type information being
1550 -- repeated by rescanning the appropriate section of source.
1552 -- First an error check, if we have two identifiers in a row, a likely
1553 -- possibility is that the first of the identifiers is an incorrectly
1556 if Token
= Tok_Identifier
then
1558 SS
: Saved_Scan_State
;
1562 Save_Scan_State
(SS
);
1563 Scan
; -- past initial identifier
1564 I2
:= (Token
= Tok_Identifier
);
1565 Restore_Scan_State
(SS
);
1569 (Bad_Spelling_Of
(Tok_Access
) or else
1570 Bad_Spelling_Of
(Tok_Aliased
) or else
1571 Bad_Spelling_Of
(Tok_Constant
))
1578 -- Loop through identifiers
1583 -- Check for some cases of misused Ada 95 keywords
1585 if Token_Name
= Name_Aliased
then
1586 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1587 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1588 Check_95_Keyword
(Tok_Aliased
, Tok_Constant
);
1593 if Token
= Tok_Constant
then
1594 Con_Loc
:= Token_Ptr
;
1595 Scan
; -- past CONSTANT
1597 -- Number declaration, initialization required
1599 Init_Expr
:= Init_Expr_Opt
;
1601 if Present
(Init_Expr
) then
1602 if Not_Null_Present
then
1604 ("`NOT NULL` not allowed in numeric expression");
1607 Decl_Node
:= New_Node
(N_Number_Declaration
, Ident_Sloc
);
1608 Set_Expression
(Decl_Node
, Init_Expr
);
1610 -- Constant object declaration
1613 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1614 Set_Constant_Present
(Decl_Node
, True);
1616 if Token_Name
= Name_Aliased
then
1617 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1618 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1621 if Token
= Tok_Aliased
then
1622 Error_Msg_SC
-- CODEFIX
1623 ("ALIASED should be before CONSTANT");
1624 Scan
; -- past ALIASED
1625 Set_Aliased_Present
(Decl_Node
, True);
1628 if Token
= Tok_Array
then
1629 Set_Object_Definition
1630 (Decl_Node
, P_Array_Type_Definition
);
1633 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1634 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1636 if Token
= Tok_Access
then
1637 if Ada_Version
< Ada_2005
then
1639 ("generalized use of anonymous access types " &
1640 "is an Ada 2005 extension");
1642 ("\unit must be compiled with -gnat05 switch");
1645 Set_Object_Definition
1646 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1648 Set_Object_Definition
1649 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1653 if Token
= Tok_Renames
then
1655 ("CONSTANT not permitted in renaming declaration",
1657 Scan
; -- Past renames
1658 Discard_Junk_Node
(P_Name
);
1664 elsif Token
= Tok_Exception
then
1665 Scan
; -- past EXCEPTION
1667 if Token_Is_Renames
then
1670 New_Node
(N_Exception_Renaming_Declaration
, Ident_Sloc
);
1671 Set_Name
(Decl_Node
, P_Qualified_Simple_Name_Resync
);
1674 Decl_Node
:= New_Node
(N_Exception_Declaration
, Prev_Token_Ptr
);
1677 -- Aliased case (note that an object definition is required)
1679 elsif Token
= Tok_Aliased
then
1680 Scan
; -- past ALIASED
1681 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1682 Set_Aliased_Present
(Decl_Node
, True);
1684 if Token
= Tok_Constant
then
1685 Scan
; -- past CONSTANT
1686 Set_Constant_Present
(Decl_Node
, True);
1689 if Token
= Tok_Array
then
1690 Set_Object_Definition
1691 (Decl_Node
, P_Array_Type_Definition
);
1694 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1695 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1697 -- Access definition (AI-406) or subtype indication
1699 if Token
= Tok_Access
then
1700 if Ada_Version
< Ada_2005
then
1702 ("generalized use of anonymous access types " &
1703 "is an Ada 2005 extension");
1705 ("\unit must be compiled with -gnat05 switch");
1708 Set_Object_Definition
1709 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1711 Set_Object_Definition
1712 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1718 elsif Token
= Tok_Array
then
1719 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1720 Set_Object_Definition
(Decl_Node
, P_Array_Type_Definition
);
1722 -- Ada 2005 (AI-254, AI-406)
1724 elsif Token
= Tok_Not
then
1726 -- OBJECT_DECLARATION ::=
1727 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1728 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
1729 -- [ASPECT_SPECIFICATIONS];
1730 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1731 -- ACCESS_DEFINITION [:= EXPRESSION]
1732 -- [ASPECT_SPECIFICATIONS];
1734 -- OBJECT_RENAMING_DECLARATION ::=
1735 -- DEFINING_IDENTIFIER :
1736 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME
1737 -- [ASPECT_SPECIFICATIONS];
1738 -- | DEFINING_IDENTIFIER :
1739 -- ACCESS_DEFINITION renames object_NAME
1740 -- [ASPECT_SPECIFICATIONS];
1742 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/423)
1744 if Token
= Tok_Access
then
1745 if Ada_Version
< Ada_2005
then
1747 ("generalized use of anonymous access types " &
1748 "is an Ada 2005 extension");
1749 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1752 Acc_Node
:= P_Access_Definition
(Not_Null_Present
);
1754 if Token
/= Tok_Renames
then
1755 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1756 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1759 Scan
; -- past renames
1762 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1763 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1764 Set_Name
(Decl_Node
, P_Name
);
1768 Type_Node
:= P_Subtype_Mark
;
1770 -- Object renaming declaration
1772 if Token_Is_Renames
then
1773 if Ada_Version
< Ada_2005
then
1775 ("`NOT NULL` not allowed in object renaming");
1778 -- Ada 2005 (AI-423): Object renaming declaration with
1779 -- a null exclusion.
1784 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1785 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1786 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1787 Set_Name
(Decl_Node
, P_Name
);
1790 -- Object declaration
1793 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1794 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1795 Set_Object_Definition
1797 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1799 -- RENAMES at this point means that we had the combination
1800 -- of a constraint on the Type_Node and renames, which is
1803 if Token_Is_Renames
then
1805 ("constraint not allowed in object renaming "
1807 Constraint
(Object_Definition
(Decl_Node
)));
1813 -- Ada 2005 (AI-230): Access Definition case
1815 elsif Token
= Tok_Access
then
1816 if Ada_Version
< Ada_2005
then
1818 ("generalized use of anonymous access types " &
1819 "is an Ada 2005 extension");
1820 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1823 Acc_Node
:= P_Access_Definition
(Null_Exclusion_Present
=> False);
1825 -- Object declaration with access definition, or renaming
1827 if Token
/= Tok_Renames
then
1828 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1829 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1832 Scan
; -- past renames
1835 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1836 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1837 Set_Name
(Decl_Node
, P_Name
);
1840 -- Subtype indication case
1843 Type_Node
:= P_Subtype_Mark
;
1845 -- Object renaming declaration
1847 if Token_Is_Renames
then
1850 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1851 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1852 Set_Name
(Decl_Node
, P_Name
);
1854 -- Object declaration
1857 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1858 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1859 Set_Object_Definition
1861 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1863 -- RENAMES at this point means that we had the combination of
1864 -- a constraint on the Type_Node and renames, which is illegal
1866 if Token_Is_Renames
then
1868 ("constraint not allowed in object renaming declaration",
1869 Constraint
(Object_Definition
(Decl_Node
)));
1875 -- Scan out initialization, allowed only for object declaration
1877 Init_Loc
:= Token_Ptr
;
1878 Init_Expr
:= Init_Expr_Opt
;
1880 if Present
(Init_Expr
) then
1881 if Nkind
(Decl_Node
) = N_Object_Declaration
then
1882 Set_Expression
(Decl_Node
, Init_Expr
);
1883 Set_Has_Init_Expression
(Decl_Node
);
1885 Error_Msg
("initialization not allowed here", Init_Loc
);
1889 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
1890 P_Aspect_Specifications
(Decl_Node
, Semicolon
=> False);
1892 -- Allow initialization expression to follow aspects (note that in
1893 -- this case P_Aspect_Specifications already issued an error msg).
1895 if Token
= Tok_Colon_Equal
then
1896 if Is_Non_Empty_List
(Aspect_Specifications
(Decl_Node
)) then
1898 ("aspect specifications must come after initialization "
1900 Sloc
(First
(Aspect_Specifications
(Decl_Node
))));
1903 -- In any case, the assignment symbol doesn't belong.
1905 Error_Msg
("misplaced assignment symbol", Scan_Ptr
);
1908 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
1909 Set_Has_Init_Expression
(Decl_Node
);
1912 -- Now scan out the semicolon, which we deferred above
1917 if Ident
< Num_Idents
then
1918 Set_More_Ids
(Decl_Node
, True);
1922 Set_Prev_Ids
(Decl_Node
, True);
1926 Append
(Decl_Node
, Decls
);
1927 exit Ident_Loop
when Ident
= Num_Idents
;
1928 Restore_Scan_State
(Scan_State
);
1931 end loop Ident_Loop
;
1934 end P_Identifier_Declarations
;
1936 -------------------------------
1937 -- 3.3.1 Object Declaration --
1938 -------------------------------
1940 -- OBJECT DECLARATION ::=
1941 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1942 -- SUBTYPE_INDICATION [:= EXPRESSION];
1943 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1944 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1945 -- | SINGLE_TASK_DECLARATION
1946 -- | SINGLE_PROTECTED_DECLARATION
1948 -- Cases starting with TASK are parsed by P_Task (9.1)
1949 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1950 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1952 -------------------------------------
1953 -- 3.3.1 Defining Identifier List --
1954 -------------------------------------
1956 -- DEFINING_IDENTIFIER_LIST ::=
1957 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1959 -- Always parsed by the construct in which it appears. See special
1960 -- section on "Handling of Defining Identifier Lists" in this unit.
1962 -------------------------------
1963 -- 3.3.2 Number Declaration --
1964 -------------------------------
1966 -- Parsed by P_Identifier_Declarations (3.3)
1968 -------------------------------------------------------------------------
1969 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
1970 -------------------------------------------------------------------------
1972 -- DERIVED_TYPE_DEFINITION ::=
1973 -- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
1974 -- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
1976 -- PRIVATE_EXTENSION_DECLARATION ::=
1977 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
1978 -- [abstract] [limited | synchronized]
1979 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
1980 -- with private [ASPECT_SPECIFICATIONS];
1982 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
1984 -- The caller has already scanned out the part up to the NEW, and Token
1985 -- either contains Tok_New (or ought to, if it doesn't this procedure
1986 -- will post an appropriate "NEW expected" message).
1988 -- Note: the caller is responsible for filling in the Sloc field of
1989 -- the returned node in the private extension declaration case as
1990 -- well as the stuff relating to the discriminant part.
1992 -- Error recovery: can raise Error_Resync;
1994 function P_Derived_Type_Def_Or_Private_Ext_Decl
return Node_Id
is
1995 Typedef_Node
: Node_Id
;
1996 Typedecl_Node
: Node_Id
;
1997 Not_Null_Present
: Boolean := False;
2000 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
2002 if Ada_Version
< Ada_2005
2003 and then Token
= Tok_Identifier
2004 and then Token_Name
= Name_Interface
2007 ("abstract interface is an Ada 2005 extension");
2008 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2013 if Token
= Tok_Abstract
then
2014 Error_Msg_SC
-- CODEFIX
2015 ("ABSTRACT must come before NEW, not after");
2019 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
2020 Set_Null_Exclusion_Present
(Typedef_Node
, Not_Null_Present
);
2021 Set_Subtype_Indication
(Typedef_Node
,
2022 P_Subtype_Indication
(Not_Null_Present
));
2024 -- Ada 2005 (AI-251): Deal with interfaces
2026 if Token
= Tok_And
then
2029 if Ada_Version
< Ada_2005
then
2031 ("abstract interface is an Ada 2005 extension");
2032 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2035 Set_Interface_List
(Typedef_Node
, New_List
);
2038 Append
(P_Qualified_Simple_Name
, Interface_List
(Typedef_Node
));
2039 exit when Token
/= Tok_And
;
2043 if Token
/= Tok_With
then
2044 Error_Msg_SC
("WITH expected");
2049 -- Deal with record extension, note that we assume that a WITH is
2050 -- missing in the case of "type X is new Y record ..." or in the
2051 -- case of "type X is new Y null record".
2053 -- First make sure we don't have an aspect specification. If we do
2054 -- return now, so that our caller can check it (the WITH here is not
2055 -- part of a type extension).
2057 if Aspect_Specifications_Present
then
2058 return Typedef_Node
;
2060 -- OK, not an aspect specification, so continue test for extension
2062 elsif Token
= Tok_With
2063 or else Token
= Tok_Record
2064 or else Token
= Tok_Null
2066 T_With
; -- past WITH or give error message
2068 if Token
= Tok_Limited
then
2069 Error_Msg_SC
("LIMITED keyword not allowed in private extension");
2070 Scan
; -- ignore LIMITED
2073 -- Private extension declaration
2075 if Token
= Tok_Private
then
2076 Scan
; -- past PRIVATE
2078 -- Throw away the type definition node and build the type
2079 -- declaration node. Note the caller must set the Sloc,
2080 -- Discriminant_Specifications, Unknown_Discriminants_Present,
2081 -- and Defined_Identifier fields in the returned node.
2084 Make_Private_Extension_Declaration
(No_Location
,
2085 Defining_Identifier
=> Empty
,
2086 Subtype_Indication
=> Subtype_Indication
(Typedef_Node
),
2087 Abstract_Present
=> Abstract_Present
(Typedef_Node
),
2088 Interface_List
=> Interface_List
(Typedef_Node
));
2090 return Typedecl_Node
;
2092 -- Derived type definition with record extension part
2095 Set_Record_Extension_Part
(Typedef_Node
, P_Record_Definition
);
2096 return Typedef_Node
;
2099 -- Derived type definition with no record extension part
2102 return Typedef_Node
;
2104 end P_Derived_Type_Def_Or_Private_Ext_Decl
;
2106 ---------------------------
2107 -- 3.5 Range Constraint --
2108 ---------------------------
2110 -- RANGE_CONSTRAINT ::= range RANGE
2112 -- The caller has checked that the initial token is RANGE or some
2113 -- misspelling of it, or it may be absent completely (and a message
2114 -- has already been issued).
2116 -- Error recovery: cannot raise Error_Resync
2118 function P_Range_Constraint
return Node_Id
is
2119 Range_Node
: Node_Id
;
2122 Range_Node
:= New_Node
(N_Range_Constraint
, Token_Ptr
);
2124 -- Skip range keyword if present
2126 if Token
= Tok_Range
or else Bad_Spelling_Of
(Tok_Range
) then
2130 Set_Range_Expression
(Range_Node
, P_Range
);
2132 end P_Range_Constraint
;
2139 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2141 -- Note: the range that appears in a membership test is parsed by
2142 -- P_Range_Or_Subtype_Mark (3.5).
2144 -- Error recovery: cannot raise Error_Resync
2146 function P_Range
return Node_Id
is
2147 Expr_Node
: Node_Id
;
2148 Range_Node
: Node_Id
;
2151 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2153 if Expr_Form
= EF_Range_Attr
then
2156 elsif Token
= Tok_Dot_Dot
then
2157 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2158 Set_Low_Bound
(Range_Node
, Expr_Node
);
2160 Expr_Node
:= P_Expression
;
2161 Check_Simple_Expression
(Expr_Node
);
2162 Set_High_Bound
(Range_Node
, Expr_Node
);
2165 -- Anything else is an error
2168 T_Dot_Dot
; -- force missing .. message
2173 ----------------------------------
2174 -- 3.5 P_Range_Or_Subtype_Mark --
2175 ----------------------------------
2178 -- RANGE_ATTRIBUTE_REFERENCE
2179 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2181 -- This routine scans out the range or subtype mark that forms the right
2182 -- operand of a membership test (it is not used in any other contexts, and
2183 -- error messages are specialized with this knowledge in mind).
2185 -- Note: as documented in the Sinfo interface, although the syntax only
2186 -- allows a subtype mark, we in fact allow any simple expression to be
2187 -- returned from this routine. The semantics is responsible for issuing
2188 -- an appropriate message complaining if the argument is not a name.
2189 -- This simplifies the coding and error recovery processing in the
2190 -- parser, and in any case it is preferable not to consider this a
2191 -- syntax error and to continue with the semantic analysis.
2193 -- Error recovery: cannot raise Error_Resync
2195 function P_Range_Or_Subtype_Mark
2196 (Allow_Simple_Expression
: Boolean := False) return Node_Id
2198 Expr_Node
: Node_Id
;
2199 Range_Node
: Node_Id
;
2200 Save_Loc
: Source_Ptr
;
2202 -- Start of processing for P_Range_Or_Subtype_Mark
2205 -- Save location of possible junk parentheses
2207 Save_Loc
:= Token_Ptr
;
2209 -- Scan out either a simple expression or a range (this accepts more
2210 -- than is legal here, but as explained above, we like to allow more
2211 -- with a proper diagnostic, and in the case of a membership operation
2212 -- where sets are allowed, a simple expression is permissible anyway.
2214 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2218 if Expr_Form
= EF_Range_Attr
then
2221 -- Simple_Expression .. Simple_Expression
2223 elsif Token
= Tok_Dot_Dot
then
2224 Check_Simple_Expression
(Expr_Node
);
2225 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2226 Set_Low_Bound
(Range_Node
, Expr_Node
);
2228 Set_High_Bound
(Range_Node
, P_Simple_Expression
);
2231 -- Case of subtype mark (optionally qualified simple name or an
2232 -- attribute whose prefix is an optionally qualified simple name)
2234 elsif Expr_Form
= EF_Simple_Name
2235 or else Nkind
(Expr_Node
) = N_Attribute_Reference
2237 -- Check for error of range constraint after a subtype mark
2239 if Token
= Tok_Range
then
2240 Error_Msg_SC
("range constraint not allowed in membership test");
2244 -- Check for error of DIGITS or DELTA after a subtype mark
2246 elsif Token
= Tok_Digits
or else Token
= Tok_Delta
then
2248 ("accuracy definition not allowed in membership test");
2249 Scan
; -- past DIGITS or DELTA
2252 -- Attribute reference, may or may not be OK, but in any case we
2255 elsif Token
= Tok_Apostrophe
then
2256 return P_Subtype_Mark_Attribute
(Expr_Node
);
2258 -- OK case of simple name, just return it
2264 -- Simple expression case
2266 elsif Expr_Form
= EF_Simple
and then Allow_Simple_Expression
then
2269 -- Here we have some kind of error situation. Check for junk parens
2270 -- then return what we have, caller will deal with other errors.
2273 if Nkind
(Expr_Node
) in N_Subexpr
2274 and then Paren_Count
(Expr_Node
) /= 0
2276 Error_Msg
("|parentheses not allowed for subtype mark", Save_Loc
);
2277 Set_Paren_Count
(Expr_Node
, 0);
2282 end P_Range_Or_Subtype_Mark
;
2284 ----------------------------------------
2285 -- 3.5.1 Enumeration Type Definition --
2286 ----------------------------------------
2288 -- ENUMERATION_TYPE_DEFINITION ::=
2289 -- (ENUMERATION_LITERAL_SPECIFICATION
2290 -- {, ENUMERATION_LITERAL_SPECIFICATION})
2292 -- The caller has already scanned out the TYPE keyword
2294 -- Error recovery: can raise Error_Resync;
2296 function P_Enumeration_Type_Definition
return Node_Id
is
2297 Typedef_Node
: Node_Id
;
2300 Typedef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Token_Ptr
);
2301 Set_Literals
(Typedef_Node
, New_List
);
2306 Append
(P_Enumeration_Literal_Specification
, Literals
(Typedef_Node
));
2307 exit when not Comma_Present
;
2311 return Typedef_Node
;
2312 end P_Enumeration_Type_Definition
;
2314 ----------------------------------------------
2315 -- 3.5.1 Enumeration Literal Specification --
2316 ----------------------------------------------
2318 -- ENUMERATION_LITERAL_SPECIFICATION ::=
2319 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
2321 -- Error recovery: can raise Error_Resync
2323 function P_Enumeration_Literal_Specification
return Node_Id
is
2325 if Token
= Tok_Char_Literal
then
2326 return P_Defining_Character_Literal
;
2328 return P_Defining_Identifier
(C_Comma_Right_Paren
);
2330 end P_Enumeration_Literal_Specification
;
2332 ---------------------------------------
2333 -- 3.5.1 Defining_Character_Literal --
2334 ---------------------------------------
2336 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
2338 -- Error recovery: cannot raise Error_Resync
2340 -- The caller has checked that the current token is a character literal
2342 function P_Defining_Character_Literal
return Node_Id
is
2343 Literal_Node
: Node_Id
;
2345 Literal_Node
:= Token_Node
;
2346 Change_Character_Literal_To_Defining_Character_Literal
(Literal_Node
);
2347 Scan
; -- past character literal
2348 return Literal_Node
;
2349 end P_Defining_Character_Literal
;
2351 ------------------------------------
2352 -- 3.5.4 Integer Type Definition --
2353 ------------------------------------
2355 -- Parsed by P_Type_Declaration (3.2.1)
2357 -------------------------------------------
2358 -- 3.5.4 Signed Integer Type Definition --
2359 -------------------------------------------
2361 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
2362 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2364 -- Normally the initial token on entry is RANGE, but in some
2365 -- error conditions, the range token was missing and control is
2366 -- passed with Token pointing to first token of the first expression.
2368 -- Error recovery: cannot raise Error_Resync
2370 function P_Signed_Integer_Type_Definition
return Node_Id
is
2371 Typedef_Node
: Node_Id
;
2372 Expr_Node
: Node_Id
;
2375 Typedef_Node
:= New_Node
(N_Signed_Integer_Type_Definition
, Token_Ptr
);
2377 if Token
= Tok_Range
then
2381 Expr_Node
:= P_Expression_Or_Range_Attribute
;
2383 -- Range case (not permitted by the grammar, this is surprising but
2384 -- the grammar in the RM is as quoted above, and does not allow Range).
2386 if Expr_Form
= EF_Range_Attr
then
2388 ("Range attribute not allowed here, use First .. Last", Expr_Node
);
2389 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2390 Set_Attribute_Name
(Expr_Node
, Name_First
);
2391 Set_High_Bound
(Typedef_Node
, Copy_Separate_Tree
(Expr_Node
));
2392 Set_Attribute_Name
(High_Bound
(Typedef_Node
), Name_Last
);
2394 -- Normal case of explicit range
2397 Check_Simple_Expression
(Expr_Node
);
2398 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2400 Expr_Node
:= P_Expression
;
2401 Check_Simple_Expression
(Expr_Node
);
2402 Set_High_Bound
(Typedef_Node
, Expr_Node
);
2405 return Typedef_Node
;
2406 end P_Signed_Integer_Type_Definition
;
2408 ------------------------------------
2409 -- 3.5.4 Modular Type Definition --
2410 ------------------------------------
2412 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
2414 -- The caller has checked that the initial token is MOD
2416 -- Error recovery: cannot raise Error_Resync
2418 function P_Modular_Type_Definition
return Node_Id
is
2419 Typedef_Node
: Node_Id
;
2422 if Ada_Version
= Ada_83
then
2423 Error_Msg_SC
("(Ada 83): modular types not allowed");
2426 Typedef_Node
:= New_Node
(N_Modular_Type_Definition
, Token_Ptr
);
2428 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2430 -- Handle mod L..R cleanly
2432 if Token
= Tok_Dot_Dot
then
2433 Error_Msg_SC
("range not allowed for modular type");
2435 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2438 return Typedef_Node
;
2439 end P_Modular_Type_Definition
;
2441 ---------------------------------
2442 -- 3.5.6 Real Type Definition --
2443 ---------------------------------
2445 -- Parsed by P_Type_Declaration (3.2.1)
2447 --------------------------------------
2448 -- 3.5.7 Floating Point Definition --
2449 --------------------------------------
2451 -- FLOATING_POINT_DEFINITION ::=
2452 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2454 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
2456 -- The caller has checked that the initial token is DIGITS
2458 -- Error recovery: cannot raise Error_Resync
2460 function P_Floating_Point_Definition
return Node_Id
is
2461 Digits_Loc
: constant Source_Ptr
:= Token_Ptr
;
2463 Expr_Node
: Node_Id
;
2466 Scan
; -- past DIGITS
2467 Expr_Node
:= P_Expression_No_Right_Paren
;
2468 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2470 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
2472 if Token
= Tok_Delta
then
2473 Error_Msg_SC
-- CODEFIX
2474 ("|DELTA must come before DIGITS");
2475 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Digits_Loc
);
2477 Set_Delta_Expression
(Def_Node
, P_Expression_No_Right_Paren
);
2479 -- OK floating-point definition
2482 Def_Node
:= New_Node
(N_Floating_Point_Definition
, Digits_Loc
);
2485 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2486 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2488 end P_Floating_Point_Definition
;
2490 -------------------------------------
2491 -- 3.5.7 Real Range Specification --
2492 -------------------------------------
2494 -- REAL_RANGE_SPECIFICATION ::=
2495 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2497 -- Error recovery: cannot raise Error_Resync
2499 function P_Real_Range_Specification_Opt
return Node_Id
is
2500 Specification_Node
: Node_Id
;
2501 Expr_Node
: Node_Id
;
2504 if Token
= Tok_Range
then
2505 Specification_Node
:=
2506 New_Node
(N_Real_Range_Specification
, Token_Ptr
);
2508 Expr_Node
:= P_Expression_No_Right_Paren
;
2509 Check_Simple_Expression
(Expr_Node
);
2510 Set_Low_Bound
(Specification_Node
, Expr_Node
);
2512 Expr_Node
:= P_Expression_No_Right_Paren
;
2513 Check_Simple_Expression
(Expr_Node
);
2514 Set_High_Bound
(Specification_Node
, Expr_Node
);
2515 return Specification_Node
;
2519 end P_Real_Range_Specification_Opt
;
2521 -----------------------------------
2522 -- 3.5.9 Fixed Point Definition --
2523 -----------------------------------
2525 -- FIXED_POINT_DEFINITION ::=
2526 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
2528 -- ORDINARY_FIXED_POINT_DEFINITION ::=
2529 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
2531 -- DECIMAL_FIXED_POINT_DEFINITION ::=
2532 -- delta static_EXPRESSION
2533 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2535 -- The caller has checked that the initial token is DELTA
2537 -- Error recovery: cannot raise Error_Resync
2539 function P_Fixed_Point_Definition
return Node_Id
is
2540 Delta_Node
: Node_Id
;
2541 Delta_Loc
: Source_Ptr
;
2543 Expr_Node
: Node_Id
;
2546 Delta_Loc
:= Token_Ptr
;
2548 Delta_Node
:= P_Expression_No_Right_Paren
;
2549 Check_Simple_Expression_In_Ada_83
(Delta_Node
);
2551 if Token
= Tok_Digits
then
2552 if Ada_Version
= Ada_83
then
2553 Error_Msg_SC
("(Ada 83) decimal fixed type not allowed!");
2556 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Delta_Loc
);
2557 Scan
; -- past DIGITS
2558 Expr_Node
:= P_Expression_No_Right_Paren
;
2559 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2560 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2563 Def_Node
:= New_Node
(N_Ordinary_Fixed_Point_Definition
, Delta_Loc
);
2565 -- Range is required in ordinary fixed point case
2567 if Token
/= Tok_Range
then
2568 Error_Msg_AP
("range must be given for fixed-point type");
2573 Set_Delta_Expression
(Def_Node
, Delta_Node
);
2574 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2576 end P_Fixed_Point_Definition
;
2578 --------------------------------------------
2579 -- 3.5.9 Ordinary Fixed Point Definition --
2580 --------------------------------------------
2582 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2584 -------------------------------------------
2585 -- 3.5.9 Decimal Fixed Point Definition --
2586 -------------------------------------------
2588 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2590 ------------------------------
2591 -- 3.5.9 Digits Constraint --
2592 ------------------------------
2594 -- DIGITS_CONSTRAINT ::=
2595 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2597 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2599 -- The caller has checked that the initial token is DIGITS
2601 function P_Digits_Constraint
return Node_Id
is
2602 Constraint_Node
: Node_Id
;
2603 Expr_Node
: Node_Id
;
2606 Constraint_Node
:= New_Node
(N_Digits_Constraint
, Token_Ptr
);
2607 Scan
; -- past DIGITS
2608 Expr_Node
:= P_Expression
;
2609 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2610 Set_Digits_Expression
(Constraint_Node
, Expr_Node
);
2612 if Token
= Tok_Range
then
2613 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2616 return Constraint_Node
;
2617 end P_Digits_Constraint
;
2619 -----------------------------
2620 -- 3.5.9 Delta Constraint --
2621 -----------------------------
2623 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2625 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2627 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2628 -- (also true in formal modes).
2630 -- The caller has checked that the initial token is DELTA
2632 -- Error recovery: cannot raise Error_Resync
2634 function P_Delta_Constraint
return Node_Id
is
2635 Constraint_Node
: Node_Id
;
2636 Expr_Node
: Node_Id
;
2639 Constraint_Node
:= New_Node
(N_Delta_Constraint
, Token_Ptr
);
2641 Expr_Node
:= P_Expression
;
2642 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2644 Set_Delta_Expression
(Constraint_Node
, Expr_Node
);
2646 if Token
= Tok_Range
then
2647 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2650 return Constraint_Node
;
2651 end P_Delta_Constraint
;
2653 --------------------------------
2654 -- 3.6 Array Type Definition --
2655 --------------------------------
2657 -- ARRAY_TYPE_DEFINITION ::=
2658 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2660 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2661 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2662 -- COMPONENT_DEFINITION
2664 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2666 -- CONSTRAINED_ARRAY_DEFINITION ::=
2667 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2668 -- COMPONENT_DEFINITION
2670 -- DISCRETE_SUBTYPE_DEFINITION ::=
2671 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2673 -- COMPONENT_DEFINITION ::=
2674 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2676 -- The caller has checked that the initial token is ARRAY
2678 -- Error recovery: can raise Error_Resync
2680 function P_Array_Type_Definition
return Node_Id
is
2681 Array_Loc
: Source_Ptr
;
2682 CompDef_Node
: Node_Id
;
2684 Not_Null_Present
: Boolean := False;
2685 Subs_List
: List_Id
;
2686 Scan_State
: Saved_Scan_State
;
2687 Aliased_Present
: Boolean := False;
2690 Array_Loc
:= Token_Ptr
;
2692 Subs_List
:= New_List
;
2695 -- It's quite tricky to disentangle these two possibilities, so we do
2696 -- a prescan to determine which case we have and then reset the scan.
2697 -- The prescan skips past possible subtype mark tokens.
2699 Save_Scan_State
(Scan_State
); -- just after paren
2701 while Token
in Token_Class_Desig
or else
2702 Token
= Tok_Dot
or else
2703 Token
= Tok_Apostrophe
-- because of 'BASE, 'CLASS
2708 -- If we end up on RANGE <> then we have the unconstrained case. We
2709 -- will also allow the RANGE to be omitted, just to improve error
2710 -- handling for a case like array (integer <>) of integer;
2712 Scan
; -- past possible RANGE or <>
2714 if (Prev_Token
= Tok_Range
and then Token
= Tok_Box
) or else
2715 Prev_Token
= Tok_Box
2717 Def_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Array_Loc
);
2718 Restore_Scan_State
(Scan_State
); -- to first subtype mark
2721 Append
(P_Subtype_Mark_Resync
, Subs_List
);
2724 exit when Token
= Tok_Right_Paren
or else Token
= Tok_Of
;
2728 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2731 Def_Node
:= New_Node
(N_Constrained_Array_Definition
, Array_Loc
);
2732 Restore_Scan_State
(Scan_State
); -- to first discrete range
2735 Append
(P_Discrete_Subtype_Definition
, Subs_List
);
2736 exit when not Comma_Present
;
2739 Set_Discrete_Subtype_Definitions
(Def_Node
, Subs_List
);
2745 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
2747 if Token_Name
= Name_Aliased
then
2748 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
2751 if Token
= Tok_Aliased
then
2752 Aliased_Present
:= True;
2753 Scan
; -- past ALIASED
2756 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
2758 -- Ada 2005 (AI-230): Access Definition case
2760 if Token
= Tok_Access
then
2761 if Ada_Version
< Ada_2005
then
2763 ("generalized use of anonymous access types " &
2764 "is an Ada 2005 extension");
2765 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2768 -- AI95-406 makes "aliased" legal (and useless) in this context so
2769 -- followintg code which used to be needed is commented out.
2771 -- if Aliased_Present then
2772 -- Error_Msg_SP ("ALIASED not allowed here");
2775 Set_Subtype_Indication
(CompDef_Node
, Empty
);
2776 Set_Aliased_Present
(CompDef_Node
, False);
2777 Set_Access_Definition
(CompDef_Node
,
2778 P_Access_Definition
(Not_Null_Present
));
2781 Set_Access_Definition
(CompDef_Node
, Empty
);
2782 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2783 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
2784 Set_Subtype_Indication
(CompDef_Node
,
2785 P_Subtype_Indication
(Not_Null_Present
));
2788 Set_Component_Definition
(Def_Node
, CompDef_Node
);
2791 end P_Array_Type_Definition
;
2793 -----------------------------------------
2794 -- 3.6 Unconstrained Array Definition --
2795 -----------------------------------------
2797 -- Parsed by P_Array_Type_Definition (3.6)
2799 ---------------------------------------
2800 -- 3.6 Constrained Array Definition --
2801 ---------------------------------------
2803 -- Parsed by P_Array_Type_Definition (3.6)
2805 --------------------------------------
2806 -- 3.6 Discrete Subtype Definition --
2807 --------------------------------------
2809 -- DISCRETE_SUBTYPE_DEFINITION ::=
2810 -- discrete_SUBTYPE_INDICATION | RANGE
2812 -- Note: the discrete subtype definition appearing in a constrained
2813 -- array definition is parsed by P_Array_Type_Definition (3.6)
2815 -- Error recovery: cannot raise Error_Resync
2817 function P_Discrete_Subtype_Definition
return Node_Id
is
2819 -- The syntax of a discrete subtype definition is identical to that
2820 -- of a discrete range, so we simply share the same parsing code.
2822 return P_Discrete_Range
;
2823 end P_Discrete_Subtype_Definition
;
2825 -------------------------------
2826 -- 3.6 Component Definition --
2827 -------------------------------
2829 -- For the array case, parsed by P_Array_Type_Definition (3.6)
2830 -- For the record case, parsed by P_Component_Declaration (3.8)
2832 -----------------------------
2833 -- 3.6.1 Index Constraint --
2834 -----------------------------
2836 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2838 ---------------------------
2839 -- 3.6.1 Discrete Range --
2840 ---------------------------
2842 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
2844 -- The possible forms for a discrete range are:
2846 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
2847 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
2848 -- Range_Attribute (RANGE, 3.5)
2849 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
2851 -- Error recovery: cannot raise Error_Resync
2853 function P_Discrete_Range
return Node_Id
is
2854 Expr_Node
: Node_Id
;
2855 Range_Node
: Node_Id
;
2858 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2860 if Expr_Form
= EF_Range_Attr
then
2863 elsif Token
= Tok_Range
then
2864 if Expr_Form
/= EF_Simple_Name
then
2865 Error_Msg_SC
("range must be preceded by subtype mark");
2868 return P_Subtype_Indication
(Expr_Node
);
2870 -- Check Expression .. Expression case
2872 elsif Token
= Tok_Dot_Dot
then
2873 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2874 Set_Low_Bound
(Range_Node
, Expr_Node
);
2876 Expr_Node
:= P_Expression
;
2877 Check_Simple_Expression
(Expr_Node
);
2878 Set_High_Bound
(Range_Node
, Expr_Node
);
2881 -- Otherwise we must have a subtype mark, or an Ada 2012 iterator
2883 elsif Expr_Form
= EF_Simple_Name
then
2886 -- The domain of iteration must be a name. Semantics will determine that
2887 -- the expression has the proper form.
2889 elsif Ada_Version
>= Ada_2012
then
2892 -- If incorrect, complain that we expect ..
2898 end P_Discrete_Range
;
2900 ----------------------------
2901 -- 3.7 Discriminant Part --
2902 ----------------------------
2904 -- DISCRIMINANT_PART ::=
2905 -- UNKNOWN_DISCRIMINANT_PART
2906 -- | KNOWN_DISCRIMINANT_PART
2908 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
2909 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
2911 ------------------------------------
2912 -- 3.7 Unknown Discriminant Part --
2913 ------------------------------------
2915 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
2917 -- If no unknown discriminant part is present, then False is returned,
2918 -- otherwise the unknown discriminant is scanned out and True is returned.
2920 -- Error recovery: cannot raise Error_Resync
2922 function P_Unknown_Discriminant_Part_Opt
return Boolean is
2923 Scan_State
: Saved_Scan_State
;
2926 -- If <> right now, then this is missing left paren
2928 if Token
= Tok_Box
then
2931 -- If not <> or left paren, then definitely no box
2933 elsif Token
/= Tok_Left_Paren
then
2936 -- Left paren, so might be a box after it
2939 Save_Scan_State
(Scan_State
);
2940 Scan
; -- past the left paren
2942 if Token
/= Tok_Box
then
2943 Restore_Scan_State
(Scan_State
);
2948 -- We are now pointing to the box
2950 if Ada_Version
= Ada_83
then
2951 Error_Msg_SC
("(Ada 83) unknown discriminant not allowed!");
2954 Scan
; -- past the box
2955 U_Right_Paren
; -- must be followed by right paren
2957 end P_Unknown_Discriminant_Part_Opt
;
2959 ----------------------------------
2960 -- 3.7 Known Discriminant Part --
2961 ----------------------------------
2963 -- KNOWN_DISCRIMINANT_PART ::=
2964 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
2966 -- DISCRIMINANT_SPECIFICATION ::=
2967 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
2968 -- [:= DEFAULT_EXPRESSION]
2969 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
2970 -- [:= DEFAULT_EXPRESSION]
2972 -- If no known discriminant part is present, then No_List is returned
2974 -- Error recovery: cannot raise Error_Resync
2976 function P_Known_Discriminant_Part_Opt
return List_Id
is
2977 Specification_Node
: Node_Id
;
2978 Specification_List
: List_Id
;
2979 Ident_Sloc
: Source_Ptr
;
2980 Scan_State
: Saved_Scan_State
;
2982 Not_Null_Present
: Boolean;
2985 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
2986 -- This array holds the list of defining identifiers. The upper bound
2987 -- of 4096 is intended to be essentially infinite, and we do not even
2988 -- bother to check for it being exceeded.
2991 if Token
= Tok_Left_Paren
then
2992 Specification_List
:= New_List
;
2994 P_Pragmas_Misplaced
;
2996 Specification_Loop
: loop
2998 Ident_Sloc
:= Token_Ptr
;
2999 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3002 while Comma_Present
loop
3003 Num_Idents
:= Num_Idents
+ 1;
3004 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3007 -- If there are multiple identifiers, we repeatedly scan the
3008 -- type and initialization expression information by resetting
3009 -- the scan pointer (so that we get completely separate trees
3010 -- for each occurrence).
3012 if Num_Idents
> 1 then
3013 Save_Scan_State
(Scan_State
);
3018 -- Loop through defining identifiers in list
3022 Specification_Node
:=
3023 New_Node
(N_Discriminant_Specification
, Ident_Sloc
);
3024 Set_Defining_Identifier
(Specification_Node
, Idents
(Ident
));
3025 Not_Null_Present
:= -- Ada 2005 (AI-231, AI-447)
3026 P_Null_Exclusion
(Allow_Anonymous_In_95
=> True);
3028 if Token
= Tok_Access
then
3029 if Ada_Version
= Ada_83
then
3031 ("(Ada 83) access discriminant not allowed!");
3034 Set_Discriminant_Type
3035 (Specification_Node
,
3036 P_Access_Definition
(Not_Null_Present
));
3038 -- Catch ouf-of-order keywords
3040 elsif Token
= Tok_Constant
then
3043 if Token
= Tok_Access
then
3044 Error_Msg_SC
("CONSTANT must appear after ACCESS");
3045 Set_Discriminant_Type
3046 (Specification_Node
,
3047 P_Access_Definition
(Not_Null_Present
));
3050 Error_Msg_SC
("misplaced CONSTANT");
3054 Set_Discriminant_Type
3055 (Specification_Node
, P_Subtype_Mark
);
3057 Set_Null_Exclusion_Present
-- Ada 2005 (AI-231)
3058 (Specification_Node
, Not_Null_Present
);
3062 (Specification_Node
, Init_Expr_Opt
(True));
3065 Set_Prev_Ids
(Specification_Node
, True);
3068 if Ident
< Num_Idents
then
3069 Set_More_Ids
(Specification_Node
, True);
3072 Append
(Specification_Node
, Specification_List
);
3073 exit Ident_Loop
when Ident
= Num_Idents
;
3075 Restore_Scan_State
(Scan_State
);
3077 end loop Ident_Loop
;
3079 exit Specification_Loop
when Token
/= Tok_Semicolon
;
3081 P_Pragmas_Misplaced
;
3082 end loop Specification_Loop
;
3085 return Specification_List
;
3090 end P_Known_Discriminant_Part_Opt
;
3092 -------------------------------------
3093 -- 3.7 Discriminant Specification --
3094 -------------------------------------
3096 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
3098 -----------------------------
3099 -- 3.7 Default Expression --
3100 -----------------------------
3102 -- Always parsed (simply as an Expression) by the parent construct
3104 ------------------------------------
3105 -- 3.7.1 Discriminant Constraint --
3106 ------------------------------------
3108 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
3110 --------------------------------------------------------
3111 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
3112 --------------------------------------------------------
3114 -- DISCRIMINANT_CONSTRAINT ::=
3115 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
3117 -- DISCRIMINANT_ASSOCIATION ::=
3118 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3121 -- This routine parses either an index or a discriminant constraint. As
3122 -- is clear from the above grammar, it is often possible to clearly
3123 -- determine which of the two possibilities we have, but there are
3124 -- cases (those in which we have a series of expressions of the same
3125 -- syntactic form as subtype indications), where we cannot tell. Since
3126 -- this means that in any case the semantic phase has to distinguish
3127 -- between the two, there is not much point in the parser trying to
3128 -- distinguish even those cases where the difference is clear. In any
3129 -- case, if we have a situation like:
3131 -- (A => 123, 235 .. 500)
3133 -- it is not clear which of the two items is the wrong one, better to
3134 -- let the semantic phase give a clear message. Consequently, this
3135 -- routine in general returns a list of items which can be either
3136 -- discrete ranges or discriminant associations.
3138 -- The caller has checked that the initial token is a left paren
3140 -- Error recovery: can raise Error_Resync
3142 function P_Index_Or_Discriminant_Constraint
return Node_Id
is
3143 Scan_State
: Saved_Scan_State
;
3144 Constr_Node
: Node_Id
;
3145 Constr_List
: List_Id
;
3146 Expr_Node
: Node_Id
;
3147 Result_Node
: Node_Id
;
3150 Result_Node
:= New_Node
(N_Index_Or_Discriminant_Constraint
, Token_Ptr
);
3152 Constr_List
:= New_List
;
3153 Set_Constraints
(Result_Node
, Constr_List
);
3155 -- The two syntactic forms are a little mixed up, so what we are doing
3156 -- here is looking at the first entry to determine which case we have
3158 -- A discriminant constraint is a list of discriminant associations,
3159 -- which have one of the following possible forms:
3163 -- Id | Id | .. | Id => Expression
3165 -- An index constraint is a list of discrete ranges which have one
3166 -- of the following possible forms:
3169 -- Subtype_Mark range Range
3171 -- Simple_Expression .. Simple_Expression
3173 -- Loop through discriminants in list
3176 -- Check cases of Id => Expression or Id | Id => Expression
3178 if Token
= Tok_Identifier
then
3179 Save_Scan_State
(Scan_State
); -- at Id
3182 if Token
= Tok_Arrow
or else Token
= Tok_Vertical_Bar
then
3183 Restore_Scan_State
(Scan_State
); -- to Id
3184 Append
(P_Discriminant_Association
, Constr_List
);
3187 Restore_Scan_State
(Scan_State
); -- to Id
3191 -- Otherwise scan out an expression and see what we have got
3193 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3195 if Expr_Form
= EF_Range_Attr
then
3196 Append
(Expr_Node
, Constr_List
);
3198 elsif Token
= Tok_Range
then
3199 if Expr_Form
/= EF_Simple_Name
then
3200 Error_Msg_SC
("subtype mark required before RANGE");
3203 Append
(P_Subtype_Indication
(Expr_Node
), Constr_List
);
3206 -- Check Simple_Expression .. Simple_Expression case
3208 elsif Token
= Tok_Dot_Dot
then
3209 Check_Simple_Expression
(Expr_Node
);
3210 Constr_Node
:= New_Node
(N_Range
, Token_Ptr
);
3211 Set_Low_Bound
(Constr_Node
, Expr_Node
);
3213 Expr_Node
:= P_Expression
;
3214 Check_Simple_Expression
(Expr_Node
);
3215 Set_High_Bound
(Constr_Node
, Expr_Node
);
3216 Append
(Constr_Node
, Constr_List
);
3219 -- Case of an expression which could be either form
3222 Append
(Expr_Node
, Constr_List
);
3226 -- Here with a single entry scanned
3229 exit when not Comma_Present
;
3235 end P_Index_Or_Discriminant_Constraint
;
3237 -------------------------------------
3238 -- 3.7.1 Discriminant Association --
3239 -------------------------------------
3241 -- DISCRIMINANT_ASSOCIATION ::=
3242 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3245 -- This routine is used only when the name list is present and the caller
3246 -- has already checked this (by scanning ahead and repositioning the
3249 -- Error_Recovery: cannot raise Error_Resync;
3251 function P_Discriminant_Association
return Node_Id
is
3252 Discr_Node
: Node_Id
;
3253 Names_List
: List_Id
;
3254 Ident_Sloc
: Source_Ptr
;
3257 Ident_Sloc
:= Token_Ptr
;
3258 Names_List
:= New_List
;
3261 Append
(P_Identifier
(C_Vertical_Bar_Arrow
), Names_List
);
3262 exit when Token
/= Tok_Vertical_Bar
;
3266 Discr_Node
:= New_Node
(N_Discriminant_Association
, Ident_Sloc
);
3267 Set_Selector_Names
(Discr_Node
, Names_List
);
3269 Set_Expression
(Discr_Node
, P_Expression
);
3271 end P_Discriminant_Association
;
3273 ---------------------------------
3274 -- 3.8 Record Type Definition --
3275 ---------------------------------
3277 -- RECORD_TYPE_DEFINITION ::=
3278 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3280 -- There is no node in the tree for a record type definition. Instead
3281 -- a record definition node appears, with possible Abstract_Present,
3282 -- Tagged_Present, and Limited_Present flags set appropriately.
3284 ----------------------------
3285 -- 3.8 Record Definition --
3286 ----------------------------
3288 -- RECORD_DEFINITION ::=
3294 -- Note: in the case where a record definition node is used to represent
3295 -- a record type definition, the caller sets the Tagged_Present and
3296 -- Limited_Present flags in the resulting N_Record_Definition node as
3299 -- Note that the RECORD token at the start may be missing in certain
3300 -- error situations, so this function is expected to post the error
3302 -- Error recovery: can raise Error_Resync
3304 function P_Record_Definition
return Node_Id
is
3308 Inside_Record_Definition
:= True;
3309 Rec_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3313 if Token
= Tok_Null
then
3316 Set_Null_Present
(Rec_Node
, True);
3318 -- Catch incomplete declaration to prevent cascaded errors, see
3319 -- ACATS B393002 for an example.
3321 elsif Token
= Tok_Semicolon
then
3322 Error_Msg_AP
("missing record definition");
3324 -- Case starting with RECORD keyword. Build scope stack entry. For the
3325 -- column, we use the first non-blank character on the line, to deal
3326 -- with situations such as:
3332 -- which is not official RM indentation, but is not uncommon usage, and
3333 -- in particular is standard GNAT coding style, so handle it nicely.
3337 Scope
.Table
(Scope
.Last
).Etyp
:= E_Record
;
3338 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3339 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3340 Scope
.Table
(Scope
.Last
).Labl
:= Error
;
3341 Scope
.Table
(Scope
.Last
).Junk
:= (Token
/= Tok_Record
);
3345 Set_Component_List
(Rec_Node
, P_Component_List
);
3348 exit when Check_End
;
3349 Discard_Junk_Node
(P_Component_List
);
3353 Inside_Record_Definition
:= False;
3355 end P_Record_Definition
;
3357 -------------------------
3358 -- 3.8 Component List --
3359 -------------------------
3361 -- COMPONENT_LIST ::=
3362 -- COMPONENT_ITEM {COMPONENT_ITEM}
3363 -- | {COMPONENT_ITEM} VARIANT_PART
3366 -- Error recovery: cannot raise Error_Resync
3368 function P_Component_List
return Node_Id
is
3369 Component_List_Node
: Node_Id
;
3370 Decls_List
: List_Id
;
3371 Scan_State
: Saved_Scan_State
;
3372 Null_Loc
: Source_Ptr
;
3375 Component_List_Node
:= New_Node
(N_Component_List
, Token_Ptr
);
3376 Decls_List
:= New_List
;
3380 if Token
= Tok_Null
then
3381 Null_Loc
:= Token_Ptr
;
3384 P_Pragmas_Opt
(Decls_List
);
3386 -- If we have an END or WHEN now, everything is fine, otherwise we
3387 -- complain about the null, ignore it, and scan for more components.
3389 if Token
= Tok_End
or else Token
= Tok_When
then
3390 Set_Null_Present
(Component_List_Node
, True);
3391 return Component_List_Node
;
3393 Error_Msg
("NULL component only allowed in null record", Null_Loc
);
3397 -- Scan components for non-null record
3399 P_Pragmas_Opt
(Decls_List
);
3401 if Token
/= Tok_Case
then
3402 Component_Scan_Loop
: loop
3403 P_Component_Items
(Decls_List
);
3404 P_Pragmas_Opt
(Decls_List
);
3406 exit Component_Scan_Loop
when Token
= Tok_End
3407 or else Token
= Tok_Case
3408 or else Token
= Tok_When
;
3410 -- We are done if we do not have an identifier. However, if we
3411 -- have a misspelled reserved identifier that is in a column to
3412 -- the right of the record definition, we will treat it as an
3413 -- identifier. It turns out to be too dangerous in practice to
3414 -- accept such a mis-spelled identifier which does not have this
3415 -- additional clue that confirms the incorrect spelling.
3417 if Token
/= Tok_Identifier
then
3418 if Start_Column
> Scope
.Table
(Scope
.Last
).Ecol
3419 and then Is_Reserved_Identifier
3421 Save_Scan_State
(Scan_State
); -- at reserved id
3422 Scan
; -- possible reserved id
3424 if Token
= Tok_Comma
or else Token
= Tok_Colon
then
3425 Restore_Scan_State
(Scan_State
);
3426 Scan_Reserved_Identifier
(Force_Msg
=> True);
3428 -- Note reserved identifier used as field name after all
3429 -- because not followed by colon or comma.
3432 Restore_Scan_State
(Scan_State
);
3433 exit Component_Scan_Loop
;
3436 -- Non-identifier that definitely was not reserved id
3439 exit Component_Scan_Loop
;
3442 end loop Component_Scan_Loop
;
3445 if Token
= Tok_Case
then
3446 Set_Variant_Part
(Component_List_Node
, P_Variant_Part
);
3448 -- Check for junk after variant part
3450 if Token
= Tok_Identifier
then
3451 Save_Scan_State
(Scan_State
);
3452 Scan
; -- past identifier
3454 if Token
= Tok_Colon
then
3455 Restore_Scan_State
(Scan_State
);
3456 Error_Msg_SC
("component may not follow variant part");
3457 Discard_Junk_Node
(P_Component_List
);
3459 elsif Token
= Tok_Case
then
3460 Restore_Scan_State
(Scan_State
);
3461 Error_Msg_SC
("only one variant part allowed in a record");
3462 Discard_Junk_Node
(P_Component_List
);
3465 Restore_Scan_State
(Scan_State
);
3470 Set_Component_Items
(Component_List_Node
, Decls_List
);
3471 return Component_List_Node
;
3472 end P_Component_List
;
3474 -------------------------
3475 -- 3.8 Component Item --
3476 -------------------------
3478 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3480 -- COMPONENT_DECLARATION ::=
3481 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3482 -- [:= DEFAULT_EXPRESSION]
3483 -- [ASPECT_SPECIFICATIONS];
3485 -- COMPONENT_DEFINITION ::=
3486 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3488 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3489 -- the scan is positioned past the following semicolon.
3491 -- Note: we do not yet allow representation clauses to appear as component
3492 -- items, do we need to add this capability sometime in the future ???
3494 procedure P_Component_Items
(Decls
: List_Id
) is
3495 Aliased_Present
: Boolean := False;
3496 CompDef_Node
: Node_Id
;
3497 Decl_Node
: Node_Id
:= Empty
; -- initialize to prevent warning
3498 Scan_State
: Saved_Scan_State
;
3499 Not_Null_Present
: Boolean := False;
3502 Ident_Sloc
: Source_Ptr
;
3504 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3505 -- This array holds the list of defining identifiers. The upper bound
3506 -- of 4096 is intended to be essentially infinite, and we do not even
3507 -- bother to check for it being exceeded.
3510 if Token
/= Tok_Identifier
then
3511 Error_Msg_SC
("component declaration expected");
3512 Resync_Past_Semicolon
;
3516 Ident_Sloc
:= Token_Ptr
;
3518 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3521 while Comma_Present
loop
3522 Num_Idents
:= Num_Idents
+ 1;
3523 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3526 -- If there are multiple identifiers, we repeatedly scan the
3527 -- type and initialization expression information by resetting
3528 -- the scan pointer (so that we get completely separate trees
3529 -- for each occurrence).
3531 if Num_Idents
> 1 then
3532 Save_Scan_State
(Scan_State
);
3537 -- Loop through defining identifiers in list
3542 -- The following block is present to catch Error_Resync
3543 -- which causes the parse to be reset past the semicolon
3546 Decl_Node
:= New_Node
(N_Component_Declaration
, Ident_Sloc
);
3547 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
3549 if Token
= Tok_Constant
then
3550 Error_Msg_SC
("constant components are not permitted");
3554 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
3556 if Token_Name
= Name_Aliased
then
3557 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
3560 if Token
= Tok_Aliased
then
3561 Aliased_Present
:= True;
3562 Scan
; -- past ALIASED
3565 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
3567 -- Ada 2005 (AI-230): Access Definition case
3569 if Token
= Tok_Access
then
3570 if Ada_Version
< Ada_2005
then
3572 ("generalized use of anonymous access types " &
3573 "is an Ada 2005 extension");
3574 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3577 -- AI95-406 makes "aliased" legal (and useless) here, so the
3578 -- following code which used to be required is commented out.
3580 -- if Aliased_Present then
3581 -- Error_Msg_SP ("ALIASED not allowed here");
3584 Set_Subtype_Indication
(CompDef_Node
, Empty
);
3585 Set_Aliased_Present
(CompDef_Node
, False);
3586 Set_Access_Definition
(CompDef_Node
,
3587 P_Access_Definition
(Not_Null_Present
));
3590 Set_Access_Definition
(CompDef_Node
, Empty
);
3591 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
3592 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
3594 if Token
= Tok_Array
then
3595 Error_Msg_SC
("anonymous arrays not allowed as components");
3599 Set_Subtype_Indication
(CompDef_Node
,
3600 P_Subtype_Indication
(Not_Null_Present
));
3603 Set_Component_Definition
(Decl_Node
, CompDef_Node
);
3604 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
3607 Set_Prev_Ids
(Decl_Node
, True);
3610 if Ident
< Num_Idents
then
3611 Set_More_Ids
(Decl_Node
, True);
3614 Append
(Decl_Node
, Decls
);
3617 when Error_Resync
=>
3618 if Token
/= Tok_End
then
3619 Resync_Past_Semicolon
;
3623 exit Ident_Loop
when Ident
= Num_Idents
;
3625 Restore_Scan_State
(Scan_State
);
3627 end loop Ident_Loop
;
3629 P_Aspect_Specifications
(Decl_Node
);
3630 end P_Component_Items
;
3632 --------------------------------
3633 -- 3.8 Component Declaration --
3634 --------------------------------
3636 -- Parsed by P_Component_Items (3.8)
3638 -------------------------
3639 -- 3.8.1 Variant Part --
3640 -------------------------
3643 -- case discriminant_DIRECT_NAME is
3648 -- The caller has checked that the initial token is CASE
3650 -- Error recovery: cannot raise Error_Resync
3652 function P_Variant_Part
return Node_Id
is
3653 Variant_Part_Node
: Node_Id
;
3654 Variants_List
: List_Id
;
3655 Case_Node
: Node_Id
;
3658 Variant_Part_Node
:= New_Node
(N_Variant_Part
, Token_Ptr
);
3660 Scope
.Table
(Scope
.Last
).Etyp
:= E_Case
;
3661 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3662 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3665 Case_Node
:= P_Expression
;
3666 Set_Name
(Variant_Part_Node
, Case_Node
);
3668 if Nkind
(Case_Node
) /= N_Identifier
then
3669 Set_Name
(Variant_Part_Node
, Error
);
3670 Error_Msg
("discriminant name expected", Sloc
(Case_Node
));
3672 elsif Paren_Count
(Case_Node
) /= 0 then
3674 ("|discriminant name may not be parenthesized",
3676 Set_Paren_Count
(Case_Node
, 0);
3680 Variants_List
:= New_List
;
3681 P_Pragmas_Opt
(Variants_List
);
3683 -- Test missing variant
3685 if Token
= Tok_End
then
3686 Error_Msg_BC
("WHEN expected (must have at least one variant)");
3688 Append
(P_Variant
, Variants_List
);
3691 -- Loop through variants, note that we allow if in place of when,
3692 -- this error will be detected and handled in P_Variant.
3695 P_Pragmas_Opt
(Variants_List
);
3697 if Token
/= Tok_When
3698 and then Token
/= Tok_If
3699 and then Token
/= Tok_Others
3701 exit when Check_End
;
3704 Append
(P_Variant
, Variants_List
);
3707 Set_Variants
(Variant_Part_Node
, Variants_List
);
3708 return Variant_Part_Node
;
3711 --------------------
3713 --------------------
3716 -- when DISCRETE_CHOICE_LIST =>
3719 -- Error recovery: cannot raise Error_Resync
3721 -- The initial token on entry is either WHEN, IF or OTHERS
3723 function P_Variant
return Node_Id
is
3724 Variant_Node
: Node_Id
;
3727 -- Special check to recover nicely from use of IF in place of WHEN
3729 if Token
= Tok_If
then
3736 Variant_Node
:= New_Node
(N_Variant
, Prev_Token_Ptr
);
3737 Set_Discrete_Choices
(Variant_Node
, P_Discrete_Choice_List
);
3739 Set_Component_List
(Variant_Node
, P_Component_List
);
3740 return Variant_Node
;
3743 ---------------------------------
3744 -- 3.8.1 Discrete Choice List --
3745 ---------------------------------
3747 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3749 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3751 -- Note: in Ada 83, the expression must be a simple expression
3753 -- Error recovery: cannot raise Error_Resync
3755 function P_Discrete_Choice_List
return List_Id
is
3757 Expr_Node
: Node_Id
:= Empty
; -- initialize to prevent warning
3758 Choice_Node
: Node_Id
;
3761 Choices
:= New_List
;
3763 if Token
= Tok_Others
then
3764 Append
(New_Node
(N_Others_Choice
, Token_Ptr
), Choices
);
3765 Scan
; -- past OTHERS
3769 -- Scan out expression or range attribute
3771 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3772 Ignore
(Tok_Right_Paren
);
3774 if Token
= Tok_Colon
3775 and then Nkind
(Expr_Node
) = N_Identifier
3777 Error_Msg_SP
("label not permitted in this context");
3782 elsif Expr_Form
= EF_Range_Attr
then
3783 Append
(Expr_Node
, Choices
);
3787 elsif Token
= Tok_Dot_Dot
then
3788 Check_Simple_Expression
(Expr_Node
);
3789 Choice_Node
:= New_Node
(N_Range
, Token_Ptr
);
3790 Set_Low_Bound
(Choice_Node
, Expr_Node
);
3792 Expr_Node
:= P_Expression_No_Right_Paren
;
3793 Check_Simple_Expression
(Expr_Node
);
3794 Set_High_Bound
(Choice_Node
, Expr_Node
);
3795 Append
(Choice_Node
, Choices
);
3797 -- Simple name, must be subtype, so range allowed
3799 elsif Expr_Form
= EF_Simple_Name
then
3800 if Token
= Tok_Range
then
3801 Append
(P_Subtype_Indication
(Expr_Node
), Choices
);
3803 elsif Token
in Token_Class_Consk
then
3805 ("the only constraint allowed here " &
3806 "is a range constraint");
3807 Discard_Junk_Node
(P_Constraint_Opt
);
3808 Append
(Expr_Node
, Choices
);
3811 Append
(Expr_Node
, Choices
);
3817 -- In Ada 2012 mode, the expression must be a simple
3818 -- expression. The reason for this restriction (i.e. going
3819 -- back to the Ada 83 rule) is to avoid ambiguities when set
3820 -- membership operations are allowed, consider the
3823 -- when A in 1 .. 10 | 12 =>
3825 -- This is ambiguous without parentheses, so we require one
3826 -- of the following two parenthesized forms to disambiguate:
3828 -- one of the following:
3830 -- when (A in 1 .. 10 | 12) =>
3831 -- when (A in 1 .. 10) | 12 =>
3833 -- To solve this, in Ada 2012 mode, we disallow the use of
3834 -- membership operations in expressions in choices.
3836 -- Technically in the grammar, the expression must match the
3837 -- grammar for restricted expression.
3839 if Ada_Version
>= Ada_2012
then
3840 Check_Restricted_Expression
(Expr_Node
);
3842 -- In Ada 83 mode, the syntax required a simple expression
3845 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
3848 Append
(Expr_Node
, Choices
);
3852 when Error_Resync
=>
3858 if Token
= Tok_Comma
then
3859 if Nkind
(Expr_Node
) = N_Iterated_Component_Association
then
3865 if Token
= Tok_Vertical_Bar
then
3866 Error_Msg_SP
-- CODEFIX
3867 ("|extra "","" ignored");
3871 Error_Msg_SP
-- CODEFIX
3872 (""","" should be ""'|""");
3876 exit when Token
/= Tok_Vertical_Bar
;
3883 end P_Discrete_Choice_List
;
3885 ----------------------------
3886 -- 3.8.1 Discrete Choice --
3887 ----------------------------
3889 -- Parsed by P_Discrete_Choice_List (3.8.1)
3891 ----------------------------------
3892 -- 3.9.1 Record Extension Part --
3893 ----------------------------------
3895 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
3897 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
3899 --------------------------------------
3900 -- 3.9.4 Interface Type Definition --
3901 --------------------------------------
3903 -- INTERFACE_TYPE_DEFINITION ::=
3904 -- [limited | task | protected | synchronized] interface
3905 -- [and INTERFACE_LIST]
3907 -- Error recovery: cannot raise Error_Resync
3909 function P_Interface_Type_Definition
3910 (Abstract_Present
: Boolean) return Node_Id
3912 Typedef_Node
: Node_Id
;
3915 if Ada_Version
< Ada_2005
then
3916 Error_Msg_SP
("abstract interface is an Ada 2005 extension");
3917 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3920 if Abstract_Present
then
3922 ("ABSTRACT not allowed in interface type definition " &
3926 Scan
; -- past INTERFACE
3928 -- Ada 2005 (AI-345): In case of interfaces with a null list of
3929 -- interfaces we build a record_definition node.
3931 if Token
= Tok_Semicolon
or else Aspect_Specifications_Present
then
3932 Typedef_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3934 Set_Abstract_Present
(Typedef_Node
);
3935 Set_Tagged_Present
(Typedef_Node
);
3936 Set_Null_Present
(Typedef_Node
);
3937 Set_Interface_Present
(Typedef_Node
);
3939 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
3940 -- a list of interfaces we build a derived_type_definition node. This
3941 -- simplifies the semantic analysis (and hence further maintenance)
3944 if Token
/= Tok_And
then
3945 Error_Msg_AP
("AND expected");
3950 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
3952 Set_Abstract_Present
(Typedef_Node
);
3953 Set_Interface_Present
(Typedef_Node
);
3954 Set_Subtype_Indication
(Typedef_Node
, P_Qualified_Simple_Name
);
3956 Set_Record_Extension_Part
(Typedef_Node
,
3957 New_Node
(N_Record_Definition
, Token_Ptr
));
3958 Set_Null_Present
(Record_Extension_Part
(Typedef_Node
));
3960 if Token
= Tok_And
then
3961 Set_Interface_List
(Typedef_Node
, New_List
);
3965 Append
(P_Qualified_Simple_Name
,
3966 Interface_List
(Typedef_Node
));
3967 exit when Token
/= Tok_And
;
3973 return Typedef_Node
;
3974 end P_Interface_Type_Definition
;
3976 ----------------------------------
3977 -- 3.10 Access Type Definition --
3978 ----------------------------------
3980 -- ACCESS_TYPE_DEFINITION ::=
3981 -- ACCESS_TO_OBJECT_DEFINITION
3982 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3984 -- ACCESS_TO_OBJECT_DEFINITION ::=
3985 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
3987 -- GENERAL_ACCESS_MODIFIER ::= all | constant
3989 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3990 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3991 -- | [NULL_EXCLUSION] access [protected] function
3992 -- PARAMETER_AND_RESULT_PROFILE
3994 -- PARAMETER_PROFILE ::= [FORMAL_PART]
3996 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
3998 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
3999 -- parsed the null_exclusion part and has also removed the ACCESS token;
4000 -- otherwise the caller has just checked that the initial token is ACCESS
4002 -- Error recovery: can raise Error_Resync
4004 function P_Access_Type_Definition
4005 (Header_Already_Parsed
: Boolean := False) return Node_Id
4007 Access_Loc
: constant Source_Ptr
:= Token_Ptr
;
4008 Prot_Flag
: Boolean;
4009 Not_Null_Present
: Boolean := False;
4010 Not_Null_Subtype
: Boolean := False;
4011 Type_Def_Node
: Node_Id
;
4012 Result_Not_Null
: Boolean;
4013 Result_Node
: Node_Id
;
4015 procedure Check_Junk_Subprogram_Name
;
4016 -- Used in access to subprogram definition cases to check for an
4017 -- identifier or operator symbol that does not belong.
4019 --------------------------------
4020 -- Check_Junk_Subprogram_Name --
4021 --------------------------------
4023 procedure Check_Junk_Subprogram_Name
is
4024 Saved_State
: Saved_Scan_State
;
4027 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
4028 Save_Scan_State
(Saved_State
);
4029 Scan
; -- past possible junk subprogram name
4031 if Token
= Tok_Left_Paren
or else Token
= Tok_Semicolon
then
4032 Error_Msg_SP
("unexpected subprogram name ignored");
4036 Restore_Scan_State
(Saved_State
);
4039 end Check_Junk_Subprogram_Name
;
4041 -- Start of processing for P_Access_Type_Definition
4044 if not Header_Already_Parsed
then
4046 -- NOT NULL ACCESS .. is a common form of access definition.
4047 -- ACCESS NOT NULL .. is certainly rare, but syntactically legal.
4048 -- NOT NULL ACCESS NOT NULL .. is rarer yet, and also legal.
4049 -- The last two cases are only meaningful if the following subtype
4050 -- indication denotes an access type (semantic check). The flag
4051 -- Not_Null_Subtype indicates that this second null exclusion is
4052 -- present in the access type definition.
4054 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4055 Scan
; -- past ACCESS
4056 Not_Null_Subtype
:= P_Null_Exclusion
; -- Might also appear
4059 if Token_Name
= Name_Protected
then
4060 Check_95_Keyword
(Tok_Protected
, Tok_Procedure
);
4061 Check_95_Keyword
(Tok_Protected
, Tok_Function
);
4064 Prot_Flag
:= (Token
= Tok_Protected
);
4067 Scan
; -- past PROTECTED
4069 if Token
/= Tok_Procedure
and then Token
/= Tok_Function
then
4070 Error_Msg_SC
-- CODEFIX
4071 ("FUNCTION or PROCEDURE expected");
4075 if Token
= Tok_Procedure
then
4076 if Ada_Version
= Ada_83
then
4077 Error_Msg_SC
("(Ada 83) access to procedure not allowed!");
4080 Type_Def_Node
:= New_Node
(N_Access_Procedure_Definition
, Access_Loc
);
4081 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4082 Scan
; -- past PROCEDURE
4083 Check_Junk_Subprogram_Name
;
4084 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4085 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4087 elsif Token
= Tok_Function
then
4088 if Ada_Version
= Ada_83
then
4089 Error_Msg_SC
("(Ada 83) access to function not allowed!");
4092 Type_Def_Node
:= New_Node
(N_Access_Function_Definition
, Access_Loc
);
4093 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4094 Scan
; -- past FUNCTION
4095 Check_Junk_Subprogram_Name
;
4096 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4097 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4100 Result_Not_Null
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4102 -- Ada 2005 (AI-318-02)
4104 if Token
= Tok_Access
then
4105 if Ada_Version
< Ada_2005
then
4107 ("anonymous access result type is an Ada 2005 extension");
4108 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4111 Result_Node
:= P_Access_Definition
(Result_Not_Null
);
4114 Result_Node
:= P_Subtype_Mark
;
4117 -- A null exclusion on the result type must be recorded in a flag
4118 -- distinct from the one used for the access-to-subprogram type's
4121 Set_Null_Exclusion_In_Return_Present
4122 (Type_Def_Node
, Result_Not_Null
);
4125 Set_Result_Definition
(Type_Def_Node
, Result_Node
);
4129 New_Node
(N_Access_To_Object_Definition
, Access_Loc
);
4130 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4131 Set_Null_Excluding_Subtype
(Type_Def_Node
, Not_Null_Subtype
);
4133 if Token
= Tok_All
or else Token
= Tok_Constant
then
4134 if Ada_Version
= Ada_83
then
4135 Error_Msg_SC
("(Ada 83) access modifier not allowed!");
4138 if Token
= Tok_All
then
4139 Set_All_Present
(Type_Def_Node
, True);
4142 Set_Constant_Present
(Type_Def_Node
, True);
4145 Scan
; -- past ALL or CONSTANT
4148 Set_Subtype_Indication
(Type_Def_Node
,
4149 P_Subtype_Indication
(Not_Null_Present
));
4152 return Type_Def_Node
;
4153 end P_Access_Type_Definition
;
4155 ---------------------------------------
4156 -- 3.10 Access To Object Definition --
4157 ---------------------------------------
4159 -- Parsed by P_Access_Type_Definition (3.10)
4161 -----------------------------------
4162 -- 3.10 General Access Modifier --
4163 -----------------------------------
4165 -- Parsed by P_Access_Type_Definition (3.10)
4167 -------------------------------------------
4168 -- 3.10 Access To Subprogram Definition --
4169 -------------------------------------------
4171 -- Parsed by P_Access_Type_Definition (3.10)
4173 -----------------------------
4174 -- 3.10 Access Definition --
4175 -----------------------------
4177 -- ACCESS_DEFINITION ::=
4178 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4179 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
4181 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4182 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4183 -- | [NULL_EXCLUSION] access [protected] function
4184 -- PARAMETER_AND_RESULT_PROFILE
4186 -- The caller has parsed the null-exclusion part and it has also checked
4187 -- that the next token is ACCESS
4189 -- Error recovery: cannot raise Error_Resync
4191 function P_Access_Definition
4192 (Null_Exclusion_Present
: Boolean) return Node_Id
4195 Subp_Node
: Node_Id
;
4198 Def_Node
:= New_Node
(N_Access_Definition
, Token_Ptr
);
4199 Scan
; -- past ACCESS
4201 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
4203 if Token
= Tok_Protected
4204 or else Token
= Tok_Procedure
4205 or else Token
= Tok_Function
4207 if Ada_Version
< Ada_2005
then
4208 Error_Msg_SP
("access-to-subprogram is an Ada 2005 extension");
4209 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
4212 Subp_Node
:= P_Access_Type_Definition
(Header_Already_Parsed
=> True);
4213 Set_Null_Exclusion_Present
(Subp_Node
, Null_Exclusion_Present
);
4214 Set_Access_To_Subprogram_Definition
(Def_Node
, Subp_Node
);
4216 -- Ada 2005 (AI-231)
4217 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4220 Set_Null_Exclusion_Present
(Def_Node
, Null_Exclusion_Present
);
4222 if Token
= Tok_All
then
4223 if Ada_Version
< Ada_2005
then
4225 ("ALL is not permitted for anonymous access types");
4229 Set_All_Present
(Def_Node
);
4231 elsif Token
= Tok_Constant
then
4232 if Ada_Version
< Ada_2005
then
4233 Error_Msg_SP
("access-to-constant is an Ada 2005 extension");
4234 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
4237 Scan
; -- past CONSTANT
4238 Set_Constant_Present
(Def_Node
);
4241 Set_Subtype_Mark
(Def_Node
, P_Subtype_Mark
);
4246 end P_Access_Definition
;
4248 -----------------------------------------
4249 -- 3.10.1 Incomplete Type Declaration --
4250 -----------------------------------------
4252 -- Parsed by P_Type_Declaration (3.2.1)
4254 ----------------------------
4255 -- 3.11 Declarative Part --
4256 ----------------------------
4258 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
4260 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Items
4261 -- handles errors, and returns cleanly after an error has occurred)
4263 function P_Declarative_Part
return List_Id
is
4268 -- Indicate no bad declarations detected yet. This will be reset by
4269 -- P_Declarative_Items if a bad declaration is discovered.
4271 Missing_Begin_Msg
:= No_Error_Msg
;
4273 -- Get rid of active SIS entry from outer scope. This means we will
4274 -- miss some nested cases, but it doesn't seem worth the effort. See
4275 -- discussion in Par for further details
4277 SIS_Entry_Active
:= False;
4280 -- Loop to scan out the declarations
4283 P_Declarative_Items
(Decls
, Done
, In_Spec
=> False);
4287 -- Get rid of active SIS entry which is left set only if we scanned a
4288 -- procedure declaration and have not found the body. We could give
4289 -- an error message, but that really would be usurping the role of
4290 -- semantic analysis (this really is a missing body case).
4292 SIS_Entry_Active
:= False;
4294 end P_Declarative_Part
;
4296 ----------------------------
4297 -- 3.11 Declarative Item --
4298 ----------------------------
4300 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4302 -- Can return Error if a junk declaration is found, or Empty if no
4303 -- declaration is found (i.e. a token ending declarations, such as
4304 -- BEGIN or END is encountered).
4306 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4307 -- then the scan is set past the next semicolon and Error is returned.
4309 procedure P_Declarative_Items
4314 Scan_State
: Saved_Scan_State
;
4318 Style
.Check_Indentation
;
4328 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4334 -- Check for loop (premature statement)
4336 Save_Scan_State
(Scan_State
);
4339 if Token
= Tok_Identifier
then
4340 Scan
; -- past identifier
4342 if Token
= Tok_In
then
4343 Restore_Scan_State
(Scan_State
);
4344 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4349 -- Not a loop, so must be rep clause
4351 Restore_Scan_State
(Scan_State
);
4352 Append
(P_Representation_Clause
, Decls
);
4357 Append
(P_Generic
, Decls
);
4360 when Tok_Identifier
=>
4363 -- Special check for misuse of overriding not in Ada 2005 mode
4365 if Token_Name
= Name_Overriding
4366 and then not Next_Token_Is
(Tok_Colon
)
4368 Error_Msg_SC
("overriding indicator is an Ada 2005 extension");
4369 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4371 Token
:= Tok_Overriding
;
4372 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4375 -- Normal case, no overriding, or overriding followed by colon
4378 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4383 Append
(P_Package
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4387 Append
(P_Pragma
, Decls
);
4390 when Tok_Protected
=>
4392 Scan
; -- past PROTECTED
4393 Append
(P_Protected
, Decls
);
4398 Append
(P_Subtype_Declaration
, Decls
);
4404 Append
(P_Task
, Decls
);
4409 Append
(P_Type_Declaration
, Decls
);
4414 Append
(P_Use_Clause
, Decls
);
4420 if Aspect_Specifications_Present
then
4422 -- If we are after a semicolon, complain that it was ignored.
4423 -- But we don't really ignore it, since we dump the aspects,
4424 -- so we make the error message a normal fatal message which
4425 -- will inhibit semantic analysis anyway).
4427 if Prev_Token
= Tok_Semicolon
then
4428 Error_Msg_SP
-- CODEFIX
4429 ("extra "";"" ignored");
4431 -- If not just past semicolon, just complain that aspects are
4432 -- not allowed at this point.
4435 Error_Msg_SC
("aspect specifications not allowed here");
4438 -- Assume that this is a misplaced aspect specification within
4439 -- a declarative list. After discarding the misplaced aspects
4440 -- we can continue the scan.
4445 Dummy_Node
: constant Node_Id
:=
4446 New_Node
(N_Package_Specification
, Token_Ptr
);
4447 pragma Warnings
(Off
, Dummy_Node
);
4448 -- Dummy node to attach aspect specifications to. We will
4449 -- then throw them away.
4452 P_Aspect_Specifications
(Dummy_Node
, Semicolon
=> True);
4455 -- Here if not aspect specifications case
4458 Error_Msg_SC
("WITH can only appear in context clause");
4462 -- BEGIN terminates the scan of a sequence of declarations unless
4463 -- there is a missing subprogram body, see section on handling
4464 -- semicolon in place of IS. We only treat the begin as satisfying
4465 -- the subprogram declaration if it falls in the expected column
4469 if SIS_Entry_Active
and then Start_Column
>= SIS_Ecol
then
4471 -- Here we have the case where a BEGIN is encountered during
4472 -- declarations in a declarative part, or at the outer level,
4473 -- and there is a subprogram declaration outstanding for which
4474 -- no body has been supplied. This is the case where we assume
4475 -- that the semicolon in the subprogram declaration should
4476 -- really have been is. The active SIS entry describes the
4477 -- subprogram declaration. On return the declaration has been
4478 -- modified to become a body.
4481 Specification_Node
: Node_Id
;
4482 Decl_Node
: Node_Id
;
4483 Body_Node
: Node_Id
;
4486 -- First issue the error message. If we had a missing
4487 -- semicolon in the declaration, then change the message
4488 -- to <missing "is">
4490 if SIS_Missing_Semicolon_Message
/= No_Error_Msg
then
4491 Change_Error_Text
-- Replace: "missing "";"" "
4492 (SIS_Missing_Semicolon_Message
, "missing ""is""");
4494 -- Otherwise we saved the semicolon position, so complain
4497 Error_Msg
-- CODEFIX
4498 ("|"";"" should be IS", SIS_Semicolon_Sloc
);
4501 -- The next job is to fix up any declarations that occurred
4502 -- between the procedure header and the BEGIN. These got
4503 -- chained to the outer declarative region (immediately
4504 -- after the procedure declaration) and they should be
4505 -- chained to the subprogram itself, which is a body
4506 -- rather than a spec.
4508 Specification_Node
:= Specification
(SIS_Declaration_Node
);
4509 Change_Node
(SIS_Declaration_Node
, N_Subprogram_Body
);
4510 Body_Node
:= SIS_Declaration_Node
;
4511 Set_Specification
(Body_Node
, Specification_Node
);
4512 Set_Declarations
(Body_Node
, New_List
);
4515 Decl_Node
:= Remove_Next
(Body_Node
);
4516 exit when Decl_Node
= Empty
;
4517 Append
(Decl_Node
, Declarations
(Body_Node
));
4520 -- Now make the scope table entry for the Begin-End and
4524 Scope
.Table
(Scope
.Last
).Sloc
:= SIS_Sloc
;
4525 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
4526 Scope
.Table
(Scope
.Last
).Ecol
:= SIS_Ecol
;
4527 Scope
.Table
(Scope
.Last
).Labl
:= SIS_Labl
;
4528 Scope
.Table
(Scope
.Last
).Lreq
:= False;
4529 SIS_Entry_Active
:= False;
4531 Set_Handled_Statement_Sequence
(Body_Node
,
4532 P_Handled_Sequence_Of_Statements
);
4533 End_Statements
(Handled_Statement_Sequence
(Body_Node
));
4542 -- Normally an END terminates the scan for basic declarative items.
4543 -- The one exception is END RECORD, which is probably left over from
4547 Save_Scan_State
(Scan_State
); -- at END
4550 if Token
= Tok_Record
then
4551 Error_Msg_SP
("no RECORD for this `end record`!");
4552 Scan
; -- past RECORD
4555 -- This might happen because of misplaced aspect specification.
4556 -- After discarding the misplaced aspects we can continue the
4561 Restore_Scan_State
(Scan_State
); -- to END
4565 -- The following tokens which can only be the start of a statement
4566 -- are considered to end a declarative part (i.e. we have a missing
4567 -- BEGIN situation). We are fairly conservative in making this
4568 -- judgment, because it is a real mess to go into statement mode
4569 -- prematurely in response to a junk declaration.
4584 -- But before we decide that it's a statement, let's check for
4585 -- a reserved word misused as an identifier.
4587 if Is_Reserved_Identifier
then
4588 Save_Scan_State
(Scan_State
);
4589 Scan
; -- past the token
4591 -- If reserved identifier not followed by colon or comma, then
4592 -- this is most likely an assignment statement to the bad id.
4594 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4595 Restore_Scan_State
(Scan_State
);
4596 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4599 -- Otherwise we have a declaration of the bad id
4602 Restore_Scan_State
(Scan_State
);
4603 Scan_Reserved_Identifier
(Force_Msg
=> True);
4604 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4607 -- If not reserved identifier, then it's definitely a statement
4610 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4614 -- The token RETURN may well also signal a missing BEGIN situation,
4615 -- however, we never let it end the declarative part, because it may
4616 -- also be part of a half-baked function declaration.
4619 Error_Msg_SC
("misplaced RETURN statement");
4622 -- PRIVATE definitely terminates the declarations in a spec,
4623 -- and is an error in a body.
4629 Error_Msg_SC
("PRIVATE not allowed in body");
4630 Scan
; -- past PRIVATE
4633 -- An end of file definitely terminates the declarations
4638 -- The remaining tokens do not end the scan, but cannot start a
4639 -- valid declaration, so we signal an error and resynchronize.
4640 -- But first check for misuse of a reserved identifier.
4644 -- Here we check for a reserved identifier
4646 if Is_Reserved_Identifier
then
4647 Save_Scan_State
(Scan_State
);
4648 Scan
; -- past the token
4650 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4651 Restore_Scan_State
(Scan_State
);
4652 Set_Declaration_Expected
;
4655 Restore_Scan_State
(Scan_State
);
4656 Scan_Reserved_Identifier
(Force_Msg
=> True);
4658 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4662 Set_Declaration_Expected
;
4667 -- To resynchronize after an error, we scan to the next semicolon and
4668 -- return with Done = False, indicating that there may still be more
4669 -- valid declarations to come.
4672 when Error_Resync
=>
4673 Resync_Past_Semicolon
;
4675 end P_Declarative_Items
;
4677 ----------------------------------
4678 -- 3.11 Basic Declarative Item --
4679 ----------------------------------
4681 -- BASIC_DECLARATIVE_ITEM ::=
4682 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4684 -- Scan zero or more basic declarative items
4686 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4687 -- the scan pointer is repositioned past the next semicolon, and the scan
4688 -- for declarative items continues.
4690 function P_Basic_Declarative_Items
return List_Id
is
4697 -- Indicate no bad declarations detected yet in the current context:
4698 -- visible or private declarations of a package spec.
4700 Missing_Begin_Msg
:= No_Error_Msg
;
4702 -- Get rid of active SIS entry from outer scope. This means we will
4703 -- miss some nested cases, but it doesn't seem worth the effort. See
4704 -- discussion in Par for further details
4706 SIS_Entry_Active
:= False;
4708 -- Loop to scan out declarations
4713 P_Declarative_Items
(Decls
, Done
, In_Spec
=> True);
4717 -- Get rid of active SIS entry. This is set only if we have scanned a
4718 -- procedure declaration and have not found the body. We could give
4719 -- an error message, but that really would be usurping the role of
4720 -- semantic analysis (this really is a case of a missing body).
4722 SIS_Entry_Active
:= False;
4724 -- Test for assorted illegal declarations not diagnosed elsewhere
4726 Decl
:= First
(Decls
);
4728 while Present
(Decl
) loop
4729 Kind
:= Nkind
(Decl
);
4731 -- Test for body scanned, not acceptable as basic decl item
4733 if Kind
= N_Subprogram_Body
or else
4734 Kind
= N_Package_Body
or else
4735 Kind
= N_Task_Body
or else
4736 Kind
= N_Protected_Body
4738 Error_Msg
("proper body not allowed in package spec", Sloc
(Decl
));
4740 -- Complete declaration of mangled subprogram body, for better
4741 -- recovery if analysis is attempted.
4743 if Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
4744 and then No
(Handled_Statement_Sequence
(Decl
))
4746 Set_Handled_Statement_Sequence
(Decl
,
4747 Make_Handled_Sequence_Of_Statements
(Sloc
(Decl
),
4748 Statements
=> New_List
));
4751 -- Test for body stub scanned, not acceptable as basic decl item
4753 elsif Kind
in N_Body_Stub
then
4754 Error_Msg
("body stub not allowed in package spec", Sloc
(Decl
));
4756 elsif Kind
= N_Assignment_Statement
then
4758 ("assignment statement not allowed in package spec",
4766 end P_Basic_Declarative_Items
;
4772 -- For proper body, see below
4773 -- For body stub, see 10.1.3
4775 -----------------------
4776 -- 3.11 Proper Body --
4777 -----------------------
4779 -- Subprogram body is parsed by P_Subprogram (6.1)
4780 -- Package body is parsed by P_Package (7.1)
4781 -- Task body is parsed by P_Task (9.1)
4782 -- Protected body is parsed by P_Protected (9.4)
4784 ------------------------------
4785 -- Set_Declaration_Expected --
4786 ------------------------------
4788 procedure Set_Declaration_Expected
is
4790 Error_Msg_SC
("declaration expected");
4792 if Missing_Begin_Msg
= No_Error_Msg
then
4793 Missing_Begin_Msg
:= Get_Msg_Id
;
4795 end Set_Declaration_Expected
;
4797 ----------------------
4798 -- Skip_Declaration --
4799 ----------------------
4801 procedure Skip_Declaration
(S
: List_Id
) is
4802 Dummy_Done
: Boolean;
4803 pragma Warnings
(Off
, Dummy_Done
);
4805 P_Declarative_Items
(S
, Dummy_Done
, False);
4806 end Skip_Declaration
;
4808 -----------------------------------------
4809 -- Statement_When_Declaration_Expected --
4810 -----------------------------------------
4812 procedure Statement_When_Declaration_Expected
4818 -- Case of second occurrence of statement in one declaration sequence
4820 if Missing_Begin_Msg
/= No_Error_Msg
then
4822 -- In the procedure spec case, just ignore it, we only give one
4823 -- message for the first occurrence, since otherwise we may get
4824 -- horrible cascading if BODY was missing in the header line.
4829 -- Just ignore it if we are in -gnatd.2 (allow statements to appear
4830 -- in declaration sequences) mode.
4832 elsif Debug_Flag_Dot_2
then
4835 -- In the declarative part case, take a second statement as a sure
4836 -- sign that we really have a missing BEGIN, and end the declarative
4837 -- part now. Note that the caller will fix up the first message to
4838 -- say "missing BEGIN" so that's how the error will be signalled.
4845 -- Case of first occurrence of unexpected statement
4848 -- Do not give error message if we are operating in -gnatd.2 mode
4849 -- (alllow statements to appear in declarative parts).
4851 if not Debug_Flag_Dot_2
then
4853 -- If we are in a package spec, then give message of statement
4854 -- not allowed in package spec. This message never gets changed.
4857 Error_Msg_SC
("statement not allowed in package spec");
4859 -- If in declarative part, then we give the message complaining
4860 -- about finding a statement when a declaration is expected. This
4861 -- gets changed to a complaint about a missing BEGIN if we later
4862 -- find that no BEGIN is present.
4865 Error_Msg_SC
("statement not allowed in declarative part");
4868 -- Capture message Id. This is used for two purposes, first to
4869 -- stop multiple messages, see test above, and second, to allow
4870 -- the replacement of the message in the declarative part case.
4872 Missing_Begin_Msg
:= Get_Msg_Id
;
4876 -- In all cases except the case in which we decided to terminate the
4877 -- declaration sequence on a second error, we scan out the statement
4878 -- and append it to the list of declarations (note that the semantics
4879 -- can handle statements in a declaration list so if we proceed to
4880 -- call the semantic phase, all will be (reasonably) well.
4882 Append_List_To
(Decls
, P_Sequence_Of_Statements
(SS_Unco
));
4884 -- Done is set to False, since we want to continue the scan of
4885 -- declarations, hoping that this statement was a temporary glitch.
4886 -- If we indeed are now in the statement part (i.e. this was a missing
4887 -- BEGIN, then it's not terrible, we will simply keep calling this
4888 -- procedure to process the statements one by one, and then finally
4889 -- hit the missing BEGIN, which will clean up the error message.
4892 end Statement_When_Declaration_Expected
;