1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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.
469 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");
871 -- For the private type declaration case, the private type declaration
872 -- node has been built, with the Tagged_Present and Limited_Present
873 -- flags set as needed, and Typedef_Node is left set to Empty.
875 if No
(Typedef_Node
) then
876 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
877 Set_Abstract_Present
(Decl_Node
, Abstract_Present
);
879 -- For a private extension declaration, Typedef_Node contains the
880 -- N_Private_Extension_Declaration node, which we now complete. Note
881 -- that the private extension declaration, unlike a full type
882 -- declaration, does permit unknown discriminants.
884 elsif Nkind
(Typedef_Node
) = N_Private_Extension_Declaration
then
885 Decl_Node
:= Typedef_Node
;
886 Set_Sloc
(Decl_Node
, Type_Loc
);
887 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
888 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
890 -- In the full type declaration case, Typedef_Node has the type
891 -- definition and here is where we build the full type declaration
892 -- node. This is also where we check for improper use of an unknown
893 -- discriminant part (not allowed for full type declaration).
896 if Nkind
(Typedef_Node
) = N_Record_Definition
897 or else (Nkind
(Typedef_Node
) = N_Derived_Type_Definition
898 and then Present
(Record_Extension_Part
(Typedef_Node
)))
899 or else Is_Derived_Iface
901 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
903 elsif Abstract_Present
then
904 Error_Msg
("ABSTRACT not allowed here, ignored", Abstract_Loc
);
907 Decl_Node
:= New_Node
(N_Full_Type_Declaration
, Type_Loc
);
908 Set_Type_Definition
(Decl_Node
, Typedef_Node
);
912 ("Full type declaration cannot have unknown discriminants",
917 -- Remaining processing is common for all three cases
919 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
920 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
921 P_Aspect_Specifications
(Decl_Node
);
923 end P_Type_Declaration
;
925 ----------------------------------
926 -- 3.2.1 Full Type Declaration --
927 ----------------------------------
929 -- Parsed by P_Type_Declaration (3.2.1)
931 ----------------------------
932 -- 3.2.1 Type Definition --
933 ----------------------------
935 -- Parsed by P_Type_Declaration (3.2.1)
937 --------------------------------
938 -- 3.2.2 Subtype Declaration --
939 --------------------------------
941 -- SUBTYPE_DECLARATION ::=
942 -- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION
943 -- [ASPECT_SPECIFICATIONS];
945 -- The caller has checked that the initial token is SUBTYPE
947 -- Error recovery: can raise Error_Resync
949 function P_Subtype_Declaration
return Node_Id
is
951 Not_Null_Present
: Boolean := False;
954 Decl_Node
:= New_Node
(N_Subtype_Declaration
, Token_Ptr
);
955 Scan
; -- past SUBTYPE
956 Set_Defining_Identifier
(Decl_Node
, P_Defining_Identifier
(C_Is
));
959 if Token
= Tok_New
then
960 Error_Msg_SC
-- CODEFIX
961 ("NEW ignored (only allowed in type declaration)");
965 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
966 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
968 Set_Subtype_Indication
969 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
970 P_Aspect_Specifications
(Decl_Node
);
972 end P_Subtype_Declaration
;
974 -------------------------------
975 -- 3.2.2 Subtype Indication --
976 -------------------------------
978 -- SUBTYPE_INDICATION ::=
979 -- [not null] SUBTYPE_MARK [CONSTRAINT]
981 -- Error recovery: can raise Error_Resync
983 function P_Null_Exclusion
984 (Allow_Anonymous_In_95
: Boolean := False) return Boolean
986 Not_Loc
: constant Source_Ptr
:= Token_Ptr
;
987 -- Source position of "not", if present
990 if Token
/= Tok_Not
then
996 if Token
= Tok_Null
then
999 -- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95,
1000 -- except in the case of anonymous access types.
1002 -- Allow_Anonymous_In_95 will be True if we're parsing a formal
1003 -- parameter or discriminant, which are the only places where
1004 -- anonymous access types occur in Ada 95. "Formal : not null
1005 -- access ..." is legal in Ada 95, whereas "Formal : not null
1006 -- Named_Access_Type" is not.
1008 if Ada_Version
>= Ada_2005
1009 or else (Ada_Version
>= Ada_95
1010 and then Allow_Anonymous_In_95
1011 and then Token
= Tok_Access
)
1017 ("`NOT NULL` access type is an Ada 2005 extension", Not_Loc
);
1019 ("\unit should be compiled with -gnat05 switch", Not_Loc
);
1023 Error_Msg_SP
("NULL expected");
1026 if Token
= Tok_New
then
1027 Error_Msg
("`NOT NULL` comes after NEW, not before", Not_Loc
);
1032 end P_Null_Exclusion
;
1034 function P_Subtype_Indication
1035 (Not_Null_Present
: Boolean := False) return Node_Id
1037 Type_Node
: Node_Id
;
1040 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
1041 Type_Node
:= P_Subtype_Mark
;
1042 return P_Subtype_Indication
(Type_Node
, Not_Null_Present
);
1045 -- Check for error of using record definition and treat it nicely,
1046 -- otherwise things are really messed up, so resynchronize.
1048 if Token
= Tok_Record
then
1049 Error_Msg_SC
("anonymous record definitions are not permitted");
1050 Discard_Junk_Node
(P_Record_Definition
);
1054 Error_Msg_AP
("subtype indication expected");
1058 end P_Subtype_Indication
;
1060 -- The following function is identical except that it is called with
1061 -- the subtype mark already scanned out, and it scans out the constraint
1063 -- Error recovery: can raise Error_Resync
1065 function P_Subtype_Indication
1066 (Subtype_Mark
: Node_Id
;
1067 Not_Null_Present
: Boolean := False) return Node_Id
1069 Indic_Node
: Node_Id
;
1070 Constr_Node
: Node_Id
;
1073 Constr_Node
:= P_Constraint_Opt
;
1077 (Nkind
(Constr_Node
) = N_Range_Constraint
1078 and then Nkind
(Range_Expression
(Constr_Node
)) = N_Error
)
1080 return Subtype_Mark
;
1082 if Not_Null_Present
then
1083 Error_Msg_SP
("`NOT NULL` not allowed if constraint given");
1086 Indic_Node
:= New_Node
(N_Subtype_Indication
, Sloc
(Subtype_Mark
));
1087 Set_Subtype_Mark
(Indic_Node
, Check_Subtype_Mark
(Subtype_Mark
));
1088 Set_Constraint
(Indic_Node
, Constr_Node
);
1091 end P_Subtype_Indication
;
1093 -------------------------
1094 -- 3.2.2 Subtype Mark --
1095 -------------------------
1097 -- SUBTYPE_MARK ::= subtype_NAME;
1099 -- Note: The subtype mark which appears after an IN or NOT IN
1100 -- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
1102 -- Error recovery: cannot raise Error_Resync
1104 function P_Subtype_Mark
return Node_Id
is
1106 return P_Subtype_Mark_Resync
;
1108 when Error_Resync
=>
1112 -- This routine differs from P_Subtype_Mark in that it insists that an
1113 -- identifier be present, and if it is not, it raises Error_Resync.
1115 -- Error recovery: can raise Error_Resync
1117 function P_Subtype_Mark_Resync
return Node_Id
is
1118 Type_Node
: Node_Id
;
1121 if Token
= Tok_Access
then
1122 Error_Msg_SC
("anonymous access type definition not allowed here");
1123 Scan
; -- past ACCESS
1126 if Token
= Tok_Array
then
1127 Error_Msg_SC
("anonymous array definition not allowed here");
1128 Discard_Junk_Node
(P_Array_Type_Definition
);
1132 Type_Node
:= P_Qualified_Simple_Name_Resync
;
1134 -- Check for a subtype mark attribute. The only valid possibilities
1135 -- are 'CLASS and 'BASE. Anything else is a definite error. We may
1136 -- as well catch it here.
1138 if Token
= Tok_Apostrophe
then
1139 return P_Subtype_Mark_Attribute
(Type_Node
);
1144 end P_Subtype_Mark_Resync
;
1146 -- The following function is called to scan out a subtype mark attribute.
1147 -- The caller has already scanned out the subtype mark, which is passed in
1148 -- as the argument, and has checked that the current token is apostrophe.
1150 -- Only a special subclass of attributes, called type attributes
1151 -- (see Snames package) are allowed in this syntactic position.
1153 -- Note: if the apostrophe is followed by other than an identifier, then
1154 -- the input expression is returned unchanged, and the scan pointer is
1155 -- left pointing to the apostrophe.
1157 -- Error recovery: can raise Error_Resync
1159 function P_Subtype_Mark_Attribute
(Type_Node
: Node_Id
) return Node_Id
is
1160 Attr_Node
: Node_Id
:= Empty
;
1161 Scan_State
: Saved_Scan_State
;
1165 Prefix
:= Check_Subtype_Mark
(Type_Node
);
1167 if Prefix
= Error
then
1171 -- Loop through attributes appearing (more than one can appear as for
1172 -- for example in X'Base'Class). We are at an apostrophe on entry to
1173 -- this loop, and it runs once for each attribute parsed, with
1174 -- Prefix being the current possible prefix if it is an attribute.
1177 Save_Scan_State
(Scan_State
); -- at Apostrophe
1178 Scan
; -- past apostrophe
1180 if Token
/= Tok_Identifier
then
1181 Restore_Scan_State
(Scan_State
); -- to apostrophe
1182 return Prefix
; -- no attribute after all
1184 elsif not Is_Type_Attribute_Name
(Token_Name
) then
1186 ("attribute & may not be used in a subtype mark", Token_Node
);
1191 Make_Attribute_Reference
(Prev_Token_Ptr
,
1193 Attribute_Name
=> Token_Name
);
1194 Scan
; -- past type attribute identifier
1197 exit when Token
/= Tok_Apostrophe
;
1198 Prefix
:= Attr_Node
;
1201 -- Fall through here after scanning type attribute
1204 end P_Subtype_Mark_Attribute
;
1206 -----------------------
1207 -- 3.2.2 Constraint --
1208 -----------------------
1210 -- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
1212 -- SCALAR_CONSTRAINT ::=
1213 -- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
1215 -- COMPOSITE_CONSTRAINT ::=
1216 -- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
1218 -- If no constraint is present, this function returns Empty
1220 -- Error recovery: can raise Error_Resync
1222 function P_Constraint_Opt
return Node_Id
is
1224 if Token
= Tok_Range
or else Bad_Spelling_Of
(Tok_Range
) then
1225 return P_Range_Constraint
;
1227 elsif Token
= Tok_Digits
or else Bad_Spelling_Of
(Tok_Digits
) then
1228 return P_Digits_Constraint
;
1230 elsif Token
= Tok_Delta
or else Bad_Spelling_Of
(Tok_Delta
) then
1231 return P_Delta_Constraint
;
1233 elsif Token
= Tok_Left_Paren
then
1234 return P_Index_Or_Discriminant_Constraint
;
1236 elsif Token
= Tok_In
then
1238 return P_Constraint_Opt
;
1240 -- One more possibility is e.g. 1 .. 10 (i.e. missing RANGE keyword)
1242 elsif Token
= Tok_Identifier
or else
1243 Token
= Tok_Integer_Literal
or else
1244 Token
= Tok_Real_Literal
1247 Scan_State
: Saved_Scan_State
;
1250 Save_Scan_State
(Scan_State
); -- at identifier or literal
1251 Scan
; -- past identifier or literal
1253 if Token
= Tok_Dot_Dot
then
1254 Restore_Scan_State
(Scan_State
);
1255 Error_Msg_BC
("missing RANGE keyword");
1256 return P_Range_Constraint
;
1258 Restore_Scan_State
(Scan_State
);
1263 -- Nothing worked, no constraint there
1268 end P_Constraint_Opt
;
1270 ------------------------------
1271 -- 3.2.2 Scalar Constraint --
1272 ------------------------------
1274 -- Parsed by P_Constraint_Opt (3.2.2)
1276 ---------------------------------
1277 -- 3.2.2 Composite Constraint --
1278 ---------------------------------
1280 -- Parsed by P_Constraint_Opt (3.2.2)
1282 --------------------------------------------------------
1283 -- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
1284 --------------------------------------------------------
1286 -- This routine scans out a declaration starting with an identifier:
1288 -- OBJECT_DECLARATION ::=
1289 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1290 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
1291 -- [ASPECT_SPECIFICATIONS];
1292 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1293 -- ACCESS_DEFINITION [:= EXPRESSION]
1294 -- [ASPECT_SPECIFICATIONS];
1295 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1296 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION]
1297 -- [ASPECT_SPECIFICATIONS];
1299 -- NUMBER_DECLARATION ::=
1300 -- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
1302 -- OBJECT_RENAMING_DECLARATION ::=
1303 -- DEFINING_IDENTIFIER :
1304 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME
1305 -- [ASPECT_SPECIFICATIONS];
1306 -- | DEFINING_IDENTIFIER :
1307 -- ACCESS_DEFINITION renames object_NAME
1308 -- [ASPECT_SPECIFICATIONS];
1310 -- EXCEPTION_RENAMING_DECLARATION ::=
1311 -- DEFINING_IDENTIFIER : exception renames exception_NAME
1312 -- [ASPECT_SPECIFICATIONS];
1314 -- EXCEPTION_DECLARATION ::=
1315 -- DEFINING_IDENTIFIER_LIST : exception
1316 -- [ASPECT_SPECIFICATIONS];
1318 -- Note that the ALIASED indication in an object declaration is
1319 -- marked by a flag in the parent node.
1321 -- The caller has checked that the initial token is an identifier
1323 -- The value returned is a list of declarations, one for each identifier
1324 -- in the list (as described in Sinfo, we always split up multiple
1325 -- declarations into the equivalent sequence of single declarations
1326 -- using the More_Ids and Prev_Ids flags to preserve the source).
1328 -- If the identifier turns out to be a probable statement rather than
1329 -- an identifier, then the scan is left pointing to the identifier and
1330 -- No_List is returned.
1332 -- Error recovery: can raise Error_Resync
1334 procedure P_Identifier_Declarations
1340 Decl_Node
: Node_Id
;
1341 Type_Node
: Node_Id
;
1342 Ident_Sloc
: Source_Ptr
;
1343 Scan_State
: Saved_Scan_State
;
1344 List_OK
: Boolean := True;
1346 Init_Expr
: Node_Id
;
1347 Init_Loc
: Source_Ptr
;
1348 Con_Loc
: Source_Ptr
;
1349 Not_Null_Present
: Boolean := False;
1351 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
1352 -- Used to save identifiers in the identifier list. The upper bound
1353 -- of 4096 is expected to be infinite in practice, and we do not even
1354 -- bother to check if this upper bound is exceeded.
1356 Num_Idents
: Nat
:= 1;
1357 -- Number of identifiers stored in Idents
1360 -- This procedure is called in renames cases to make sure that we do
1361 -- not have more than one identifier. If we do have more than one
1362 -- then an error message is issued (and the declaration is split into
1363 -- multiple declarations)
1365 function Token_Is_Renames
return Boolean;
1366 -- Checks if current token is RENAMES, and if so, scans past it and
1367 -- returns True, otherwise returns False. Includes checking for some
1368 -- common error cases.
1374 procedure No_List
is
1376 if Num_Idents
> 1 then
1378 ("identifier list not allowed for RENAMES",
1385 ----------------------
1386 -- Token_Is_Renames --
1387 ----------------------
1389 function Token_Is_Renames
return Boolean is
1390 At_Colon
: Saved_Scan_State
;
1393 if Token
= Tok_Colon
then
1394 Save_Scan_State
(At_Colon
);
1396 Check_Misspelling_Of
(Tok_Renames
);
1398 if Token
= Tok_Renames
then
1399 Error_Msg_SP
-- CODEFIX
1400 ("|extra "":"" ignored");
1401 Scan
; -- past RENAMES
1404 Restore_Scan_State
(At_Colon
);
1409 Check_Misspelling_Of
(Tok_Renames
);
1411 if Token
= Tok_Renames
then
1412 Scan
; -- past RENAMES
1418 end Token_Is_Renames
;
1420 -- Start of processing for P_Identifier_Declarations
1423 Ident_Sloc
:= Token_Ptr
;
1424 Save_Scan_State
(Scan_State
); -- at first identifier
1425 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
1427 -- If we have a colon after the identifier, then we can assume that
1428 -- this is in fact a valid identifier declaration and can steam ahead.
1430 if Token
= Tok_Colon
then
1433 -- If we have a comma, then scan out the list of identifiers
1435 elsif Token
= Tok_Comma
then
1436 while Comma_Present
loop
1437 Num_Idents
:= Num_Idents
+ 1;
1438 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
1441 Save_Scan_State
(Scan_State
); -- at colon
1444 -- If we have identifier followed by := then we assume that what is
1445 -- really meant is an assignment statement. The assignment statement
1446 -- is scanned out and added to the list of declarations. An exception
1447 -- occurs if the := is followed by the keyword constant, in which case
1448 -- we assume it was meant to be a colon.
1450 elsif Token
= Tok_Colon_Equal
then
1453 if Token
= Tok_Constant
then
1454 Error_Msg_SP
("colon expected");
1457 Restore_Scan_State
(Scan_State
);
1458 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
1462 -- If we have an IS keyword, then assume the TYPE keyword was missing
1464 elsif Token
= Tok_Is
then
1465 Restore_Scan_State
(Scan_State
);
1466 Append_To
(Decls
, P_Type_Declaration
);
1470 -- Otherwise we have an error situation
1473 Restore_Scan_State
(Scan_State
);
1475 -- First case is possible misuse of PROTECTED in Ada 83 mode. If
1476 -- so, fix the keyword and return to scan the protected declaration.
1478 if Token_Name
= Name_Protected
then
1479 Check_95_Keyword
(Tok_Protected
, Tok_Identifier
);
1480 Check_95_Keyword
(Tok_Protected
, Tok_Type
);
1481 Check_95_Keyword
(Tok_Protected
, Tok_Body
);
1483 if Token
= Tok_Protected
then
1488 -- Check misspelling possibilities. If so, correct the misspelling
1489 -- and return to scan out the resulting declaration.
1491 elsif Bad_Spelling_Of
(Tok_Function
)
1492 or else Bad_Spelling_Of
(Tok_Procedure
)
1493 or else Bad_Spelling_Of
(Tok_Package
)
1494 or else Bad_Spelling_Of
(Tok_Pragma
)
1495 or else Bad_Spelling_Of
(Tok_Protected
)
1496 or else Bad_Spelling_Of
(Tok_Generic
)
1497 or else Bad_Spelling_Of
(Tok_Subtype
)
1498 or else Bad_Spelling_Of
(Tok_Type
)
1499 or else Bad_Spelling_Of
(Tok_Task
)
1500 or else Bad_Spelling_Of
(Tok_Use
)
1501 or else Bad_Spelling_Of
(Tok_For
)
1506 -- Otherwise we definitely have an ordinary identifier with a junk
1507 -- token after it. Just complain that we expect a declaration, and
1508 -- skip to a semicolon
1511 Set_Declaration_Expected
;
1512 Resync_Past_Semicolon
;
1518 -- Come here with an identifier list and colon scanned out. We now
1519 -- build the nodes for the declarative items. One node is built for
1520 -- each identifier in the list, with the type information being
1521 -- repeated by rescanning the appropriate section of source.
1523 -- First an error check, if we have two identifiers in a row, a likely
1524 -- possibility is that the first of the identifiers is an incorrectly
1527 if Token
= Tok_Identifier
then
1529 SS
: Saved_Scan_State
;
1533 Save_Scan_State
(SS
);
1534 Scan
; -- past initial identifier
1535 I2
:= (Token
= Tok_Identifier
);
1536 Restore_Scan_State
(SS
);
1540 (Bad_Spelling_Of
(Tok_Access
) or else
1541 Bad_Spelling_Of
(Tok_Aliased
) or else
1542 Bad_Spelling_Of
(Tok_Constant
))
1549 -- Loop through identifiers
1554 -- Check for some cases of misused Ada 95 keywords
1556 if Token_Name
= Name_Aliased
then
1557 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1558 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1559 Check_95_Keyword
(Tok_Aliased
, Tok_Constant
);
1564 if Token
= Tok_Constant
then
1565 Con_Loc
:= Token_Ptr
;
1566 Scan
; -- past CONSTANT
1568 -- Number declaration, initialization required
1570 Init_Expr
:= Init_Expr_Opt
;
1572 if Present
(Init_Expr
) then
1573 if Not_Null_Present
then
1575 ("`NOT NULL` not allowed in numeric expression");
1578 Decl_Node
:= New_Node
(N_Number_Declaration
, Ident_Sloc
);
1579 Set_Expression
(Decl_Node
, Init_Expr
);
1581 -- Constant object declaration
1584 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1585 Set_Constant_Present
(Decl_Node
, True);
1587 if Token_Name
= Name_Aliased
then
1588 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1589 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1592 if Token
= Tok_Aliased
then
1593 Error_Msg_SC
-- CODEFIX
1594 ("ALIASED should be before CONSTANT");
1595 Scan
; -- past ALIASED
1596 Set_Aliased_Present
(Decl_Node
, True);
1599 if Token
= Tok_Array
then
1600 Set_Object_Definition
1601 (Decl_Node
, P_Array_Type_Definition
);
1604 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1605 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1607 if Token
= Tok_Access
then
1608 if Ada_Version
< Ada_2005
then
1610 ("generalized use of anonymous access types " &
1611 "is an Ada 2005 extension");
1613 ("\unit must be compiled with -gnat05 switch");
1616 Set_Object_Definition
1617 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1619 Set_Object_Definition
1620 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1624 if Token
= Tok_Renames
then
1626 ("CONSTANT not permitted in renaming declaration",
1628 Scan
; -- Past renames
1629 Discard_Junk_Node
(P_Name
);
1635 elsif Token
= Tok_Exception
then
1636 Scan
; -- past EXCEPTION
1638 if Token_Is_Renames
then
1641 New_Node
(N_Exception_Renaming_Declaration
, Ident_Sloc
);
1642 Set_Name
(Decl_Node
, P_Qualified_Simple_Name_Resync
);
1645 Decl_Node
:= New_Node
(N_Exception_Declaration
, Prev_Token_Ptr
);
1648 -- Aliased case (note that an object definition is required)
1650 elsif Token
= Tok_Aliased
then
1651 Scan
; -- past ALIASED
1652 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1653 Set_Aliased_Present
(Decl_Node
, True);
1655 if Token
= Tok_Constant
then
1656 Scan
; -- past CONSTANT
1657 Set_Constant_Present
(Decl_Node
, True);
1660 if Token
= Tok_Array
then
1661 Set_Object_Definition
1662 (Decl_Node
, P_Array_Type_Definition
);
1665 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1666 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1668 -- Access definition (AI-406) or subtype indication
1670 if Token
= Tok_Access
then
1671 if Ada_Version
< Ada_2005
then
1673 ("generalized use of anonymous access types " &
1674 "is an Ada 2005 extension");
1676 ("\unit must be compiled with -gnat05 switch");
1679 Set_Object_Definition
1680 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1682 Set_Object_Definition
1683 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1689 elsif Token
= Tok_Array
then
1690 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1691 Set_Object_Definition
(Decl_Node
, P_Array_Type_Definition
);
1693 -- Ada 2005 (AI-254, AI-406)
1695 elsif Token
= Tok_Not
then
1697 -- OBJECT_DECLARATION ::=
1698 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1699 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
1700 -- [ASPECT_SPECIFICATIONS];
1701 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1702 -- ACCESS_DEFINITION [:= EXPRESSION]
1703 -- [ASPECT_SPECIFICATIONS];
1705 -- OBJECT_RENAMING_DECLARATION ::=
1706 -- DEFINING_IDENTIFIER :
1707 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME
1708 -- [ASPECT_SPECIFICATIONS];
1709 -- | DEFINING_IDENTIFIER :
1710 -- ACCESS_DEFINITION renames object_NAME
1711 -- [ASPECT_SPECIFICATIONS];
1713 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/423)
1715 if Token
= Tok_Access
then
1716 if Ada_Version
< Ada_2005
then
1718 ("generalized use of anonymous access types " &
1719 "is an Ada 2005 extension");
1720 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1723 Acc_Node
:= P_Access_Definition
(Not_Null_Present
);
1725 if Token
/= Tok_Renames
then
1726 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1727 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1730 Scan
; -- past renames
1733 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1734 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1735 Set_Name
(Decl_Node
, P_Name
);
1739 Type_Node
:= P_Subtype_Mark
;
1741 -- Object renaming declaration
1743 if Token_Is_Renames
then
1744 if Ada_Version
< Ada_2005
then
1746 ("`NOT NULL` not allowed in object renaming");
1749 -- Ada 2005 (AI-423): Object renaming declaration with
1750 -- a null exclusion.
1755 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1756 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1757 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1758 Set_Name
(Decl_Node
, P_Name
);
1761 -- Object declaration
1764 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1765 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1766 Set_Object_Definition
1768 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1770 -- RENAMES at this point means that we had the combination
1771 -- of a constraint on the Type_Node and renames, which is
1774 if Token_Is_Renames
then
1776 ("constraint not allowed in object renaming "
1778 Constraint
(Object_Definition
(Decl_Node
)));
1784 -- Ada 2005 (AI-230): Access Definition case
1786 elsif Token
= Tok_Access
then
1787 if Ada_Version
< Ada_2005
then
1789 ("generalized use of anonymous access types " &
1790 "is an Ada 2005 extension");
1791 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1794 Acc_Node
:= P_Access_Definition
(Null_Exclusion_Present
=> False);
1796 -- Object declaration with access definition, or renaming
1798 if Token
/= Tok_Renames
then
1799 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1800 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1803 Scan
; -- past renames
1806 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1807 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1808 Set_Name
(Decl_Node
, P_Name
);
1811 -- Subtype indication case
1814 Type_Node
:= P_Subtype_Mark
;
1816 -- Object renaming declaration
1818 if Token_Is_Renames
then
1821 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1822 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1823 Set_Name
(Decl_Node
, P_Name
);
1825 -- Object declaration
1828 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1829 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1830 Set_Object_Definition
1832 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1834 -- RENAMES at this point means that we had the combination of
1835 -- a constraint on the Type_Node and renames, which is illegal
1837 if Token_Is_Renames
then
1839 ("constraint not allowed in object renaming declaration",
1840 Constraint
(Object_Definition
(Decl_Node
)));
1846 -- Scan out initialization, allowed only for object declaration
1848 Init_Loc
:= Token_Ptr
;
1849 Init_Expr
:= Init_Expr_Opt
;
1851 if Present
(Init_Expr
) then
1852 if Nkind
(Decl_Node
) = N_Object_Declaration
then
1853 Set_Expression
(Decl_Node
, Init_Expr
);
1854 Set_Has_Init_Expression
(Decl_Node
);
1856 Error_Msg
("initialization not allowed here", Init_Loc
);
1860 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
1861 P_Aspect_Specifications
(Decl_Node
, Semicolon
=> False);
1863 -- Allow initialization expression to follow aspects (note that in
1864 -- this case P_Aspect_Specifications already issued an error msg).
1866 if Token
= Tok_Colon_Equal
then
1867 if Is_Non_Empty_List
(Aspect_Specifications
(Decl_Node
)) then
1869 ("aspect specifications must come after initialization "
1871 Sloc
(First
(Aspect_Specifications
(Decl_Node
))));
1874 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
1875 Set_Has_Init_Expression
(Decl_Node
);
1878 -- Now scan out the semicolon, which we deferred above
1883 if Ident
< Num_Idents
then
1884 Set_More_Ids
(Decl_Node
, True);
1888 Set_Prev_Ids
(Decl_Node
, True);
1892 Append
(Decl_Node
, Decls
);
1893 exit Ident_Loop
when Ident
= Num_Idents
;
1894 Restore_Scan_State
(Scan_State
);
1897 end loop Ident_Loop
;
1900 end P_Identifier_Declarations
;
1902 -------------------------------
1903 -- 3.3.1 Object Declaration --
1904 -------------------------------
1906 -- OBJECT DECLARATION ::=
1907 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1908 -- SUBTYPE_INDICATION [:= EXPRESSION];
1909 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1910 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1911 -- | SINGLE_TASK_DECLARATION
1912 -- | SINGLE_PROTECTED_DECLARATION
1914 -- Cases starting with TASK are parsed by P_Task (9.1)
1915 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1916 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1918 -------------------------------------
1919 -- 3.3.1 Defining Identifier List --
1920 -------------------------------------
1922 -- DEFINING_IDENTIFIER_LIST ::=
1923 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1925 -- Always parsed by the construct in which it appears. See special
1926 -- section on "Handling of Defining Identifier Lists" in this unit.
1928 -------------------------------
1929 -- 3.3.2 Number Declaration --
1930 -------------------------------
1932 -- Parsed by P_Identifier_Declarations (3.3)
1934 -------------------------------------------------------------------------
1935 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
1936 -------------------------------------------------------------------------
1938 -- DERIVED_TYPE_DEFINITION ::=
1939 -- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
1940 -- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
1942 -- PRIVATE_EXTENSION_DECLARATION ::=
1943 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
1944 -- [abstract] [limited | synchronized]
1945 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
1946 -- with private [ASPECT_SPECIFICATIONS];
1948 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
1950 -- The caller has already scanned out the part up to the NEW, and Token
1951 -- either contains Tok_New (or ought to, if it doesn't this procedure
1952 -- will post an appropriate "NEW expected" message).
1954 -- Note: the caller is responsible for filling in the Sloc field of
1955 -- the returned node in the private extension declaration case as
1956 -- well as the stuff relating to the discriminant part.
1958 -- Error recovery: can raise Error_Resync;
1960 function P_Derived_Type_Def_Or_Private_Ext_Decl
return Node_Id
is
1961 Typedef_Node
: Node_Id
;
1962 Typedecl_Node
: Node_Id
;
1963 Not_Null_Present
: Boolean := False;
1966 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
1968 if Ada_Version
< Ada_2005
1969 and then Token
= Tok_Identifier
1970 and then Token_Name
= Name_Interface
1973 ("abstract interface is an Ada 2005 extension");
1974 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1979 if Token
= Tok_Abstract
then
1980 Error_Msg_SC
-- CODEFIX
1981 ("ABSTRACT must come before NEW, not after");
1985 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1986 Set_Null_Exclusion_Present
(Typedef_Node
, Not_Null_Present
);
1987 Set_Subtype_Indication
(Typedef_Node
,
1988 P_Subtype_Indication
(Not_Null_Present
));
1990 -- Ada 2005 (AI-251): Deal with interfaces
1992 if Token
= Tok_And
then
1995 if Ada_Version
< Ada_2005
then
1997 ("abstract interface is an Ada 2005 extension");
1998 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2001 Set_Interface_List
(Typedef_Node
, New_List
);
2004 Append
(P_Qualified_Simple_Name
, Interface_List
(Typedef_Node
));
2005 exit when Token
/= Tok_And
;
2009 if Token
/= Tok_With
then
2010 Error_Msg_SC
("WITH expected");
2015 -- Deal with record extension, note that we assume that a WITH is
2016 -- missing in the case of "type X is new Y record ..." or in the
2017 -- case of "type X is new Y null record".
2019 -- First make sure we don't have an aspect specification. If we do
2020 -- return now, so that our caller can check it (the WITH here is not
2021 -- part of a type extension).
2023 if Aspect_Specifications_Present
then
2024 return Typedef_Node
;
2026 -- OK, not an aspect specification, so continue test for extension
2028 elsif Token
= Tok_With
2029 or else Token
= Tok_Record
2030 or else Token
= Tok_Null
2032 T_With
; -- past WITH or give error message
2034 if Token
= Tok_Limited
then
2035 Error_Msg_SC
("LIMITED keyword not allowed in private extension");
2036 Scan
; -- ignore LIMITED
2039 -- Private extension declaration
2041 if Token
= Tok_Private
then
2042 Scan
; -- past PRIVATE
2044 -- Throw away the type definition node and build the type
2045 -- declaration node. Note the caller must set the Sloc,
2046 -- Discriminant_Specifications, Unknown_Discriminants_Present,
2047 -- and Defined_Identifier fields in the returned node.
2050 Make_Private_Extension_Declaration
(No_Location
,
2051 Defining_Identifier
=> Empty
,
2052 Subtype_Indication
=> Subtype_Indication
(Typedef_Node
),
2053 Abstract_Present
=> Abstract_Present
(Typedef_Node
),
2054 Interface_List
=> Interface_List
(Typedef_Node
));
2056 return Typedecl_Node
;
2058 -- Derived type definition with record extension part
2061 Set_Record_Extension_Part
(Typedef_Node
, P_Record_Definition
);
2062 return Typedef_Node
;
2065 -- Derived type definition with no record extension part
2068 return Typedef_Node
;
2070 end P_Derived_Type_Def_Or_Private_Ext_Decl
;
2072 ---------------------------
2073 -- 3.5 Range Constraint --
2074 ---------------------------
2076 -- RANGE_CONSTRAINT ::= range RANGE
2078 -- The caller has checked that the initial token is RANGE or some
2079 -- misspelling of it, or it may be absent completely (and a message
2080 -- has already been issued).
2082 -- Error recovery: cannot raise Error_Resync
2084 function P_Range_Constraint
return Node_Id
is
2085 Range_Node
: Node_Id
;
2088 Range_Node
:= New_Node
(N_Range_Constraint
, Token_Ptr
);
2090 -- Skip range keyword if present
2092 if Token
= Tok_Range
or else Bad_Spelling_Of
(Tok_Range
) then
2096 Set_Range_Expression
(Range_Node
, P_Range
);
2098 end P_Range_Constraint
;
2105 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2107 -- Note: the range that appears in a membership test is parsed by
2108 -- P_Range_Or_Subtype_Mark (3.5).
2110 -- Error recovery: cannot raise Error_Resync
2112 function P_Range
return Node_Id
is
2113 Expr_Node
: Node_Id
;
2114 Range_Node
: Node_Id
;
2117 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2119 if Expr_Form
= EF_Range_Attr
then
2122 elsif Token
= Tok_Dot_Dot
then
2123 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2124 Set_Low_Bound
(Range_Node
, Expr_Node
);
2126 Expr_Node
:= P_Expression
;
2127 Check_Simple_Expression
(Expr_Node
);
2128 Set_High_Bound
(Range_Node
, Expr_Node
);
2131 -- Anything else is an error
2134 T_Dot_Dot
; -- force missing .. message
2139 ----------------------------------
2140 -- 3.5 P_Range_Or_Subtype_Mark --
2141 ----------------------------------
2144 -- RANGE_ATTRIBUTE_REFERENCE
2145 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2147 -- This routine scans out the range or subtype mark that forms the right
2148 -- operand of a membership test (it is not used in any other contexts, and
2149 -- error messages are specialized with this knowledge in mind).
2151 -- Note: as documented in the Sinfo interface, although the syntax only
2152 -- allows a subtype mark, we in fact allow any simple expression to be
2153 -- returned from this routine. The semantics is responsible for issuing
2154 -- an appropriate message complaining if the argument is not a name.
2155 -- This simplifies the coding and error recovery processing in the
2156 -- parser, and in any case it is preferable not to consider this a
2157 -- syntax error and to continue with the semantic analysis.
2159 -- Error recovery: cannot raise Error_Resync
2161 function P_Range_Or_Subtype_Mark
2162 (Allow_Simple_Expression
: Boolean := False) return Node_Id
2164 Expr_Node
: Node_Id
;
2165 Range_Node
: Node_Id
;
2166 Save_Loc
: Source_Ptr
;
2168 -- Start of processing for P_Range_Or_Subtype_Mark
2171 -- Save location of possible junk parentheses
2173 Save_Loc
:= Token_Ptr
;
2175 -- Scan out either a simple expression or a range (this accepts more
2176 -- than is legal here, but as explained above, we like to allow more
2177 -- with a proper diagnostic, and in the case of a membership operation
2178 -- where sets are allowed, a simple expression is permissible anyway.
2180 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2184 if Expr_Form
= EF_Range_Attr
then
2187 -- Simple_Expression .. Simple_Expression
2189 elsif Token
= Tok_Dot_Dot
then
2190 Check_Simple_Expression
(Expr_Node
);
2191 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2192 Set_Low_Bound
(Range_Node
, Expr_Node
);
2194 Set_High_Bound
(Range_Node
, P_Simple_Expression
);
2197 -- Case of subtype mark (optionally qualified simple name or an
2198 -- attribute whose prefix is an optionally qualified simple name)
2200 elsif Expr_Form
= EF_Simple_Name
2201 or else Nkind
(Expr_Node
) = N_Attribute_Reference
2203 -- Check for error of range constraint after a subtype mark
2205 if Token
= Tok_Range
then
2206 Error_Msg_SC
("range constraint not allowed in membership test");
2210 -- Check for error of DIGITS or DELTA after a subtype mark
2212 elsif Token
= Tok_Digits
or else Token
= Tok_Delta
then
2214 ("accuracy definition not allowed in membership test");
2215 Scan
; -- past DIGITS or DELTA
2218 -- Attribute reference, may or may not be OK, but in any case we
2221 elsif Token
= Tok_Apostrophe
then
2222 return P_Subtype_Mark_Attribute
(Expr_Node
);
2224 -- OK case of simple name, just return it
2230 -- Simple expression case
2232 elsif Expr_Form
= EF_Simple
and then Allow_Simple_Expression
then
2235 -- Here we have some kind of error situation. Check for junk parens
2236 -- then return what we have, caller will deal with other errors.
2239 if Nkind
(Expr_Node
) in N_Subexpr
2240 and then Paren_Count
(Expr_Node
) /= 0
2242 Error_Msg
("|parentheses not allowed for subtype mark", Save_Loc
);
2243 Set_Paren_Count
(Expr_Node
, 0);
2248 end P_Range_Or_Subtype_Mark
;
2250 ----------------------------------------
2251 -- 3.5.1 Enumeration Type Definition --
2252 ----------------------------------------
2254 -- ENUMERATION_TYPE_DEFINITION ::=
2255 -- (ENUMERATION_LITERAL_SPECIFICATION
2256 -- {, ENUMERATION_LITERAL_SPECIFICATION})
2258 -- The caller has already scanned out the TYPE keyword
2260 -- Error recovery: can raise Error_Resync;
2262 function P_Enumeration_Type_Definition
return Node_Id
is
2263 Typedef_Node
: Node_Id
;
2266 Typedef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Token_Ptr
);
2267 Set_Literals
(Typedef_Node
, New_List
);
2272 Append
(P_Enumeration_Literal_Specification
, Literals
(Typedef_Node
));
2273 exit when not Comma_Present
;
2277 return Typedef_Node
;
2278 end P_Enumeration_Type_Definition
;
2280 ----------------------------------------------
2281 -- 3.5.1 Enumeration Literal Specification --
2282 ----------------------------------------------
2284 -- ENUMERATION_LITERAL_SPECIFICATION ::=
2285 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
2287 -- Error recovery: can raise Error_Resync
2289 function P_Enumeration_Literal_Specification
return Node_Id
is
2291 if Token
= Tok_Char_Literal
then
2292 return P_Defining_Character_Literal
;
2294 return P_Defining_Identifier
(C_Comma_Right_Paren
);
2296 end P_Enumeration_Literal_Specification
;
2298 ---------------------------------------
2299 -- 3.5.1 Defining_Character_Literal --
2300 ---------------------------------------
2302 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
2304 -- Error recovery: cannot raise Error_Resync
2306 -- The caller has checked that the current token is a character literal
2308 function P_Defining_Character_Literal
return Node_Id
is
2309 Literal_Node
: Node_Id
;
2311 Literal_Node
:= Token_Node
;
2312 Change_Character_Literal_To_Defining_Character_Literal
(Literal_Node
);
2313 Scan
; -- past character literal
2314 return Literal_Node
;
2315 end P_Defining_Character_Literal
;
2317 ------------------------------------
2318 -- 3.5.4 Integer Type Definition --
2319 ------------------------------------
2321 -- Parsed by P_Type_Declaration (3.2.1)
2323 -------------------------------------------
2324 -- 3.5.4 Signed Integer Type Definition --
2325 -------------------------------------------
2327 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
2328 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2330 -- Normally the initial token on entry is RANGE, but in some
2331 -- error conditions, the range token was missing and control is
2332 -- passed with Token pointing to first token of the first expression.
2334 -- Error recovery: cannot raise Error_Resync
2336 function P_Signed_Integer_Type_Definition
return Node_Id
is
2337 Typedef_Node
: Node_Id
;
2338 Expr_Node
: Node_Id
;
2341 Typedef_Node
:= New_Node
(N_Signed_Integer_Type_Definition
, Token_Ptr
);
2343 if Token
= Tok_Range
then
2347 Expr_Node
:= P_Expression_Or_Range_Attribute
;
2349 -- Range case (not permitted by the grammar, this is surprising but
2350 -- the grammar in the RM is as quoted above, and does not allow Range).
2352 if Expr_Form
= EF_Range_Attr
then
2354 ("Range attribute not allowed here, use First .. Last", Expr_Node
);
2355 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2356 Set_Attribute_Name
(Expr_Node
, Name_First
);
2357 Set_High_Bound
(Typedef_Node
, Copy_Separate_Tree
(Expr_Node
));
2358 Set_Attribute_Name
(High_Bound
(Typedef_Node
), Name_Last
);
2360 -- Normal case of explicit range
2363 Check_Simple_Expression
(Expr_Node
);
2364 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2366 Expr_Node
:= P_Expression
;
2367 Check_Simple_Expression
(Expr_Node
);
2368 Set_High_Bound
(Typedef_Node
, Expr_Node
);
2371 return Typedef_Node
;
2372 end P_Signed_Integer_Type_Definition
;
2374 ------------------------------------
2375 -- 3.5.4 Modular Type Definition --
2376 ------------------------------------
2378 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
2380 -- The caller has checked that the initial token is MOD
2382 -- Error recovery: cannot raise Error_Resync
2384 function P_Modular_Type_Definition
return Node_Id
is
2385 Typedef_Node
: Node_Id
;
2388 if Ada_Version
= Ada_83
then
2389 Error_Msg_SC
("(Ada 83): modular types not allowed");
2392 Typedef_Node
:= New_Node
(N_Modular_Type_Definition
, Token_Ptr
);
2394 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2396 -- Handle mod L..R cleanly
2398 if Token
= Tok_Dot_Dot
then
2399 Error_Msg_SC
("range not allowed for modular type");
2401 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2404 return Typedef_Node
;
2405 end P_Modular_Type_Definition
;
2407 ---------------------------------
2408 -- 3.5.6 Real Type Definition --
2409 ---------------------------------
2411 -- Parsed by P_Type_Declaration (3.2.1)
2413 --------------------------------------
2414 -- 3.5.7 Floating Point Definition --
2415 --------------------------------------
2417 -- FLOATING_POINT_DEFINITION ::=
2418 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2420 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
2422 -- The caller has checked that the initial token is DIGITS
2424 -- Error recovery: cannot raise Error_Resync
2426 function P_Floating_Point_Definition
return Node_Id
is
2427 Digits_Loc
: constant Source_Ptr
:= Token_Ptr
;
2429 Expr_Node
: Node_Id
;
2432 Scan
; -- past DIGITS
2433 Expr_Node
:= P_Expression_No_Right_Paren
;
2434 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2436 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
2438 if Token
= Tok_Delta
then
2439 Error_Msg_SC
-- CODEFIX
2440 ("|DELTA must come before DIGITS");
2441 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Digits_Loc
);
2443 Set_Delta_Expression
(Def_Node
, P_Expression_No_Right_Paren
);
2445 -- OK floating-point definition
2448 Def_Node
:= New_Node
(N_Floating_Point_Definition
, Digits_Loc
);
2451 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2452 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2454 end P_Floating_Point_Definition
;
2456 -------------------------------------
2457 -- 3.5.7 Real Range Specification --
2458 -------------------------------------
2460 -- REAL_RANGE_SPECIFICATION ::=
2461 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2463 -- Error recovery: cannot raise Error_Resync
2465 function P_Real_Range_Specification_Opt
return Node_Id
is
2466 Specification_Node
: Node_Id
;
2467 Expr_Node
: Node_Id
;
2470 if Token
= Tok_Range
then
2471 Specification_Node
:=
2472 New_Node
(N_Real_Range_Specification
, Token_Ptr
);
2474 Expr_Node
:= P_Expression_No_Right_Paren
;
2475 Check_Simple_Expression
(Expr_Node
);
2476 Set_Low_Bound
(Specification_Node
, Expr_Node
);
2478 Expr_Node
:= P_Expression_No_Right_Paren
;
2479 Check_Simple_Expression
(Expr_Node
);
2480 Set_High_Bound
(Specification_Node
, Expr_Node
);
2481 return Specification_Node
;
2485 end P_Real_Range_Specification_Opt
;
2487 -----------------------------------
2488 -- 3.5.9 Fixed Point Definition --
2489 -----------------------------------
2491 -- FIXED_POINT_DEFINITION ::=
2492 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
2494 -- ORDINARY_FIXED_POINT_DEFINITION ::=
2495 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
2497 -- DECIMAL_FIXED_POINT_DEFINITION ::=
2498 -- delta static_EXPRESSION
2499 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2501 -- The caller has checked that the initial token is DELTA
2503 -- Error recovery: cannot raise Error_Resync
2505 function P_Fixed_Point_Definition
return Node_Id
is
2506 Delta_Node
: Node_Id
;
2507 Delta_Loc
: Source_Ptr
;
2509 Expr_Node
: Node_Id
;
2512 Delta_Loc
:= Token_Ptr
;
2514 Delta_Node
:= P_Expression_No_Right_Paren
;
2515 Check_Simple_Expression_In_Ada_83
(Delta_Node
);
2517 if Token
= Tok_Digits
then
2518 if Ada_Version
= Ada_83
then
2519 Error_Msg_SC
("(Ada 83) decimal fixed type not allowed!");
2522 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Delta_Loc
);
2523 Scan
; -- past DIGITS
2524 Expr_Node
:= P_Expression_No_Right_Paren
;
2525 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2526 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2529 Def_Node
:= New_Node
(N_Ordinary_Fixed_Point_Definition
, Delta_Loc
);
2531 -- Range is required in ordinary fixed point case
2533 if Token
/= Tok_Range
then
2534 Error_Msg_AP
("range must be given for fixed-point type");
2539 Set_Delta_Expression
(Def_Node
, Delta_Node
);
2540 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2542 end P_Fixed_Point_Definition
;
2544 --------------------------------------------
2545 -- 3.5.9 Ordinary Fixed Point Definition --
2546 --------------------------------------------
2548 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2550 -------------------------------------------
2551 -- 3.5.9 Decimal Fixed Point Definition --
2552 -------------------------------------------
2554 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2556 ------------------------------
2557 -- 3.5.9 Digits Constraint --
2558 ------------------------------
2560 -- DIGITS_CONSTRAINT ::=
2561 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2563 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2565 -- The caller has checked that the initial token is DIGITS
2567 function P_Digits_Constraint
return Node_Id
is
2568 Constraint_Node
: Node_Id
;
2569 Expr_Node
: Node_Id
;
2572 Constraint_Node
:= New_Node
(N_Digits_Constraint
, Token_Ptr
);
2573 Scan
; -- past DIGITS
2574 Expr_Node
:= P_Expression
;
2575 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2576 Set_Digits_Expression
(Constraint_Node
, Expr_Node
);
2578 if Token
= Tok_Range
then
2579 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2582 return Constraint_Node
;
2583 end P_Digits_Constraint
;
2585 -----------------------------
2586 -- 3.5.9 Delta Constraint --
2587 -----------------------------
2589 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2591 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2593 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2594 -- (also true in formal modes).
2596 -- The caller has checked that the initial token is DELTA
2598 -- Error recovery: cannot raise Error_Resync
2600 function P_Delta_Constraint
return Node_Id
is
2601 Constraint_Node
: Node_Id
;
2602 Expr_Node
: Node_Id
;
2605 Constraint_Node
:= New_Node
(N_Delta_Constraint
, Token_Ptr
);
2607 Expr_Node
:= P_Expression
;
2608 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2610 Set_Delta_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_Delta_Constraint
;
2619 --------------------------------
2620 -- 3.6 Array Type Definition --
2621 --------------------------------
2623 -- ARRAY_TYPE_DEFINITION ::=
2624 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2626 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2627 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2628 -- COMPONENT_DEFINITION
2630 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2632 -- CONSTRAINED_ARRAY_DEFINITION ::=
2633 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2634 -- COMPONENT_DEFINITION
2636 -- DISCRETE_SUBTYPE_DEFINITION ::=
2637 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2639 -- COMPONENT_DEFINITION ::=
2640 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2642 -- The caller has checked that the initial token is ARRAY
2644 -- Error recovery: can raise Error_Resync
2646 function P_Array_Type_Definition
return Node_Id
is
2647 Array_Loc
: Source_Ptr
;
2648 CompDef_Node
: Node_Id
;
2650 Not_Null_Present
: Boolean := False;
2651 Subs_List
: List_Id
;
2652 Scan_State
: Saved_Scan_State
;
2653 Aliased_Present
: Boolean := False;
2656 Array_Loc
:= Token_Ptr
;
2658 Subs_List
:= New_List
;
2661 -- It's quite tricky to disentangle these two possibilities, so we do
2662 -- a prescan to determine which case we have and then reset the scan.
2663 -- The prescan skips past possible subtype mark tokens.
2665 Save_Scan_State
(Scan_State
); -- just after paren
2667 while Token
in Token_Class_Desig
or else
2668 Token
= Tok_Dot
or else
2669 Token
= Tok_Apostrophe
-- because of 'BASE, 'CLASS
2674 -- If we end up on RANGE <> then we have the unconstrained case. We
2675 -- will also allow the RANGE to be omitted, just to improve error
2676 -- handling for a case like array (integer <>) of integer;
2678 Scan
; -- past possible RANGE or <>
2680 if (Prev_Token
= Tok_Range
and then Token
= Tok_Box
) or else
2681 Prev_Token
= Tok_Box
2683 Def_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Array_Loc
);
2684 Restore_Scan_State
(Scan_State
); -- to first subtype mark
2687 Append
(P_Subtype_Mark_Resync
, Subs_List
);
2690 exit when Token
= Tok_Right_Paren
or else Token
= Tok_Of
;
2694 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2697 Def_Node
:= New_Node
(N_Constrained_Array_Definition
, Array_Loc
);
2698 Restore_Scan_State
(Scan_State
); -- to first discrete range
2701 Append
(P_Discrete_Subtype_Definition
, Subs_List
);
2702 exit when not Comma_Present
;
2705 Set_Discrete_Subtype_Definitions
(Def_Node
, Subs_List
);
2711 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
2713 if Token_Name
= Name_Aliased
then
2714 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
2717 if Token
= Tok_Aliased
then
2718 Aliased_Present
:= True;
2719 Scan
; -- past ALIASED
2722 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
2724 -- Ada 2005 (AI-230): Access Definition case
2726 if Token
= Tok_Access
then
2727 if Ada_Version
< Ada_2005
then
2729 ("generalized use of anonymous access types " &
2730 "is an Ada 2005 extension");
2731 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2734 -- AI95-406 makes "aliased" legal (and useless) in this context so
2735 -- followintg code which used to be needed is commented out.
2737 -- if Aliased_Present then
2738 -- Error_Msg_SP ("ALIASED not allowed here");
2741 Set_Subtype_Indication
(CompDef_Node
, Empty
);
2742 Set_Aliased_Present
(CompDef_Node
, False);
2743 Set_Access_Definition
(CompDef_Node
,
2744 P_Access_Definition
(Not_Null_Present
));
2747 Set_Access_Definition
(CompDef_Node
, Empty
);
2748 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2749 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
2750 Set_Subtype_Indication
(CompDef_Node
,
2751 P_Subtype_Indication
(Not_Null_Present
));
2754 Set_Component_Definition
(Def_Node
, CompDef_Node
);
2757 end P_Array_Type_Definition
;
2759 -----------------------------------------
2760 -- 3.6 Unconstrained Array Definition --
2761 -----------------------------------------
2763 -- Parsed by P_Array_Type_Definition (3.6)
2765 ---------------------------------------
2766 -- 3.6 Constrained Array Definition --
2767 ---------------------------------------
2769 -- Parsed by P_Array_Type_Definition (3.6)
2771 --------------------------------------
2772 -- 3.6 Discrete Subtype Definition --
2773 --------------------------------------
2775 -- DISCRETE_SUBTYPE_DEFINITION ::=
2776 -- discrete_SUBTYPE_INDICATION | RANGE
2778 -- Note: the discrete subtype definition appearing in a constrained
2779 -- array definition is parsed by P_Array_Type_Definition (3.6)
2781 -- Error recovery: cannot raise Error_Resync
2783 function P_Discrete_Subtype_Definition
return Node_Id
is
2785 -- The syntax of a discrete subtype definition is identical to that
2786 -- of a discrete range, so we simply share the same parsing code.
2788 return P_Discrete_Range
;
2789 end P_Discrete_Subtype_Definition
;
2791 -------------------------------
2792 -- 3.6 Component Definition --
2793 -------------------------------
2795 -- For the array case, parsed by P_Array_Type_Definition (3.6)
2796 -- For the record case, parsed by P_Component_Declaration (3.8)
2798 -----------------------------
2799 -- 3.6.1 Index Constraint --
2800 -----------------------------
2802 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2804 ---------------------------
2805 -- 3.6.1 Discrete Range --
2806 ---------------------------
2808 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
2810 -- The possible forms for a discrete range are:
2812 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
2813 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
2814 -- Range_Attribute (RANGE, 3.5)
2815 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
2817 -- Error recovery: cannot raise Error_Resync
2819 function P_Discrete_Range
return Node_Id
is
2820 Expr_Node
: Node_Id
;
2821 Range_Node
: Node_Id
;
2824 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2826 if Expr_Form
= EF_Range_Attr
then
2829 elsif Token
= Tok_Range
then
2830 if Expr_Form
/= EF_Simple_Name
then
2831 Error_Msg_SC
("range must be preceded by subtype mark");
2834 return P_Subtype_Indication
(Expr_Node
);
2836 -- Check Expression .. Expression case
2838 elsif Token
= Tok_Dot_Dot
then
2839 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2840 Set_Low_Bound
(Range_Node
, Expr_Node
);
2842 Expr_Node
:= P_Expression
;
2843 Check_Simple_Expression
(Expr_Node
);
2844 Set_High_Bound
(Range_Node
, Expr_Node
);
2847 -- Otherwise we must have a subtype mark, or an Ada 2012 iterator
2849 elsif Expr_Form
= EF_Simple_Name
then
2852 -- The domain of iteration must be a name. Semantics will determine that
2853 -- the expression has the proper form.
2855 elsif Ada_Version
>= Ada_2012
then
2858 -- If incorrect, complain that we expect ..
2864 end P_Discrete_Range
;
2866 ----------------------------
2867 -- 3.7 Discriminant Part --
2868 ----------------------------
2870 -- DISCRIMINANT_PART ::=
2871 -- UNKNOWN_DISCRIMINANT_PART
2872 -- | KNOWN_DISCRIMINANT_PART
2874 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
2875 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
2877 ------------------------------------
2878 -- 3.7 Unknown Discriminant Part --
2879 ------------------------------------
2881 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
2883 -- If no unknown discriminant part is present, then False is returned,
2884 -- otherwise the unknown discriminant is scanned out and True is returned.
2886 -- Error recovery: cannot raise Error_Resync
2888 function P_Unknown_Discriminant_Part_Opt
return Boolean is
2889 Scan_State
: Saved_Scan_State
;
2892 -- If <> right now, then this is missing left paren
2894 if Token
= Tok_Box
then
2897 -- If not <> or left paren, then definitely no box
2899 elsif Token
/= Tok_Left_Paren
then
2902 -- Left paren, so might be a box after it
2905 Save_Scan_State
(Scan_State
);
2906 Scan
; -- past the left paren
2908 if Token
/= Tok_Box
then
2909 Restore_Scan_State
(Scan_State
);
2914 -- We are now pointing to the box
2916 if Ada_Version
= Ada_83
then
2917 Error_Msg_SC
("(Ada 83) unknown discriminant not allowed!");
2920 Scan
; -- past the box
2921 U_Right_Paren
; -- must be followed by right paren
2923 end P_Unknown_Discriminant_Part_Opt
;
2925 ----------------------------------
2926 -- 3.7 Known Discriminant Part --
2927 ----------------------------------
2929 -- KNOWN_DISCRIMINANT_PART ::=
2930 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
2932 -- DISCRIMINANT_SPECIFICATION ::=
2933 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
2934 -- [:= DEFAULT_EXPRESSION]
2935 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
2936 -- [:= DEFAULT_EXPRESSION]
2938 -- If no known discriminant part is present, then No_List is returned
2940 -- Error recovery: cannot raise Error_Resync
2942 function P_Known_Discriminant_Part_Opt
return List_Id
is
2943 Specification_Node
: Node_Id
;
2944 Specification_List
: List_Id
;
2945 Ident_Sloc
: Source_Ptr
;
2946 Scan_State
: Saved_Scan_State
;
2948 Not_Null_Present
: Boolean;
2951 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
2952 -- This array holds the list of defining identifiers. The upper bound
2953 -- of 4096 is intended to be essentially infinite, and we do not even
2954 -- bother to check for it being exceeded.
2957 if Token
= Tok_Left_Paren
then
2958 Specification_List
:= New_List
;
2960 P_Pragmas_Misplaced
;
2962 Specification_Loop
: loop
2964 Ident_Sloc
:= Token_Ptr
;
2965 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
2968 while Comma_Present
loop
2969 Num_Idents
:= Num_Idents
+ 1;
2970 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
2973 -- If there are multiple identifiers, we repeatedly scan the
2974 -- type and initialization expression information by resetting
2975 -- the scan pointer (so that we get completely separate trees
2976 -- for each occurrence).
2978 if Num_Idents
> 1 then
2979 Save_Scan_State
(Scan_State
);
2984 -- Loop through defining identifiers in list
2988 Specification_Node
:=
2989 New_Node
(N_Discriminant_Specification
, Ident_Sloc
);
2990 Set_Defining_Identifier
(Specification_Node
, Idents
(Ident
));
2991 Not_Null_Present
:= -- Ada 2005 (AI-231, AI-447)
2992 P_Null_Exclusion
(Allow_Anonymous_In_95
=> True);
2994 if Token
= Tok_Access
then
2995 if Ada_Version
= Ada_83
then
2997 ("(Ada 83) access discriminant not allowed!");
3000 Set_Discriminant_Type
3001 (Specification_Node
,
3002 P_Access_Definition
(Not_Null_Present
));
3005 Set_Discriminant_Type
3006 (Specification_Node
, P_Subtype_Mark
);
3008 Set_Null_Exclusion_Present
-- Ada 2005 (AI-231)
3009 (Specification_Node
, Not_Null_Present
);
3013 (Specification_Node
, Init_Expr_Opt
(True));
3016 Set_Prev_Ids
(Specification_Node
, True);
3019 if Ident
< Num_Idents
then
3020 Set_More_Ids
(Specification_Node
, True);
3023 Append
(Specification_Node
, Specification_List
);
3024 exit Ident_Loop
when Ident
= Num_Idents
;
3026 Restore_Scan_State
(Scan_State
);
3028 end loop Ident_Loop
;
3030 exit Specification_Loop
when Token
/= Tok_Semicolon
;
3032 P_Pragmas_Misplaced
;
3033 end loop Specification_Loop
;
3036 return Specification_List
;
3041 end P_Known_Discriminant_Part_Opt
;
3043 -------------------------------------
3044 -- 3.7 Discriminant Specification --
3045 -------------------------------------
3047 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
3049 -----------------------------
3050 -- 3.7 Default Expression --
3051 -----------------------------
3053 -- Always parsed (simply as an Expression) by the parent construct
3055 ------------------------------------
3056 -- 3.7.1 Discriminant Constraint --
3057 ------------------------------------
3059 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
3061 --------------------------------------------------------
3062 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
3063 --------------------------------------------------------
3065 -- DISCRIMINANT_CONSTRAINT ::=
3066 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
3068 -- DISCRIMINANT_ASSOCIATION ::=
3069 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3072 -- This routine parses either an index or a discriminant constraint. As
3073 -- is clear from the above grammar, it is often possible to clearly
3074 -- determine which of the two possibilities we have, but there are
3075 -- cases (those in which we have a series of expressions of the same
3076 -- syntactic form as subtype indications), where we cannot tell. Since
3077 -- this means that in any case the semantic phase has to distinguish
3078 -- between the two, there is not much point in the parser trying to
3079 -- distinguish even those cases where the difference is clear. In any
3080 -- case, if we have a situation like:
3082 -- (A => 123, 235 .. 500)
3084 -- it is not clear which of the two items is the wrong one, better to
3085 -- let the semantic phase give a clear message. Consequently, this
3086 -- routine in general returns a list of items which can be either
3087 -- discrete ranges or discriminant associations.
3089 -- The caller has checked that the initial token is a left paren
3091 -- Error recovery: can raise Error_Resync
3093 function P_Index_Or_Discriminant_Constraint
return Node_Id
is
3094 Scan_State
: Saved_Scan_State
;
3095 Constr_Node
: Node_Id
;
3096 Constr_List
: List_Id
;
3097 Expr_Node
: Node_Id
;
3098 Result_Node
: Node_Id
;
3101 Result_Node
:= New_Node
(N_Index_Or_Discriminant_Constraint
, Token_Ptr
);
3103 Constr_List
:= New_List
;
3104 Set_Constraints
(Result_Node
, Constr_List
);
3106 -- The two syntactic forms are a little mixed up, so what we are doing
3107 -- here is looking at the first entry to determine which case we have
3109 -- A discriminant constraint is a list of discriminant associations,
3110 -- which have one of the following possible forms:
3114 -- Id | Id | .. | Id => Expression
3116 -- An index constraint is a list of discrete ranges which have one
3117 -- of the following possible forms:
3120 -- Subtype_Mark range Range
3122 -- Simple_Expression .. Simple_Expression
3124 -- Loop through discriminants in list
3127 -- Check cases of Id => Expression or Id | Id => Expression
3129 if Token
= Tok_Identifier
then
3130 Save_Scan_State
(Scan_State
); -- at Id
3133 if Token
= Tok_Arrow
or else Token
= Tok_Vertical_Bar
then
3134 Restore_Scan_State
(Scan_State
); -- to Id
3135 Append
(P_Discriminant_Association
, Constr_List
);
3138 Restore_Scan_State
(Scan_State
); -- to Id
3142 -- Otherwise scan out an expression and see what we have got
3144 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3146 if Expr_Form
= EF_Range_Attr
then
3147 Append
(Expr_Node
, Constr_List
);
3149 elsif Token
= Tok_Range
then
3150 if Expr_Form
/= EF_Simple_Name
then
3151 Error_Msg_SC
("subtype mark required before RANGE");
3154 Append
(P_Subtype_Indication
(Expr_Node
), Constr_List
);
3157 -- Check Simple_Expression .. Simple_Expression case
3159 elsif Token
= Tok_Dot_Dot
then
3160 Check_Simple_Expression
(Expr_Node
);
3161 Constr_Node
:= New_Node
(N_Range
, Token_Ptr
);
3162 Set_Low_Bound
(Constr_Node
, Expr_Node
);
3164 Expr_Node
:= P_Expression
;
3165 Check_Simple_Expression
(Expr_Node
);
3166 Set_High_Bound
(Constr_Node
, Expr_Node
);
3167 Append
(Constr_Node
, Constr_List
);
3170 -- Case of an expression which could be either form
3173 Append
(Expr_Node
, Constr_List
);
3177 -- Here with a single entry scanned
3180 exit when not Comma_Present
;
3186 end P_Index_Or_Discriminant_Constraint
;
3188 -------------------------------------
3189 -- 3.7.1 Discriminant Association --
3190 -------------------------------------
3192 -- DISCRIMINANT_ASSOCIATION ::=
3193 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3196 -- This routine is used only when the name list is present and the caller
3197 -- has already checked this (by scanning ahead and repositioning the
3200 -- Error_Recovery: cannot raise Error_Resync;
3202 function P_Discriminant_Association
return Node_Id
is
3203 Discr_Node
: Node_Id
;
3204 Names_List
: List_Id
;
3205 Ident_Sloc
: Source_Ptr
;
3208 Ident_Sloc
:= Token_Ptr
;
3209 Names_List
:= New_List
;
3212 Append
(P_Identifier
(C_Vertical_Bar_Arrow
), Names_List
);
3213 exit when Token
/= Tok_Vertical_Bar
;
3217 Discr_Node
:= New_Node
(N_Discriminant_Association
, Ident_Sloc
);
3218 Set_Selector_Names
(Discr_Node
, Names_List
);
3220 Set_Expression
(Discr_Node
, P_Expression
);
3222 end P_Discriminant_Association
;
3224 ---------------------------------
3225 -- 3.8 Record Type Definition --
3226 ---------------------------------
3228 -- RECORD_TYPE_DEFINITION ::=
3229 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3231 -- There is no node in the tree for a record type definition. Instead
3232 -- a record definition node appears, with possible Abstract_Present,
3233 -- Tagged_Present, and Limited_Present flags set appropriately.
3235 ----------------------------
3236 -- 3.8 Record Definition --
3237 ----------------------------
3239 -- RECORD_DEFINITION ::=
3245 -- Note: in the case where a record definition node is used to represent
3246 -- a record type definition, the caller sets the Tagged_Present and
3247 -- Limited_Present flags in the resulting N_Record_Definition node as
3250 -- Note that the RECORD token at the start may be missing in certain
3251 -- error situations, so this function is expected to post the error
3253 -- Error recovery: can raise Error_Resync
3255 function P_Record_Definition
return Node_Id
is
3259 Inside_Record_Definition
:= True;
3260 Rec_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3264 if Token
= Tok_Null
then
3267 Set_Null_Present
(Rec_Node
, True);
3269 -- Catch incomplete declaration to prevent cascaded errors, see
3270 -- ACATS B393002 for an example.
3272 elsif Token
= Tok_Semicolon
then
3273 Error_Msg_AP
("missing record definition");
3275 -- Case starting with RECORD keyword. Build scope stack entry. For the
3276 -- column, we use the first non-blank character on the line, to deal
3277 -- with situations such as:
3283 -- which is not official RM indentation, but is not uncommon usage, and
3284 -- in particular is standard GNAT coding style, so handle it nicely.
3288 Scope
.Table
(Scope
.Last
).Etyp
:= E_Record
;
3289 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3290 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3291 Scope
.Table
(Scope
.Last
).Labl
:= Error
;
3292 Scope
.Table
(Scope
.Last
).Junk
:= (Token
/= Tok_Record
);
3296 Set_Component_List
(Rec_Node
, P_Component_List
);
3299 exit when Check_End
;
3300 Discard_Junk_Node
(P_Component_List
);
3304 Inside_Record_Definition
:= False;
3306 end P_Record_Definition
;
3308 -------------------------
3309 -- 3.8 Component List --
3310 -------------------------
3312 -- COMPONENT_LIST ::=
3313 -- COMPONENT_ITEM {COMPONENT_ITEM}
3314 -- | {COMPONENT_ITEM} VARIANT_PART
3317 -- Error recovery: cannot raise Error_Resync
3319 function P_Component_List
return Node_Id
is
3320 Component_List_Node
: Node_Id
;
3321 Decls_List
: List_Id
;
3322 Scan_State
: Saved_Scan_State
;
3323 Null_Loc
: Source_Ptr
;
3326 Component_List_Node
:= New_Node
(N_Component_List
, Token_Ptr
);
3327 Decls_List
:= New_List
;
3331 if Token
= Tok_Null
then
3332 Null_Loc
:= Token_Ptr
;
3335 P_Pragmas_Opt
(Decls_List
);
3337 -- If we have an END or WHEN now, everything is fine, otherwise we
3338 -- complain about the null, ignore it, and scan for more components.
3340 if Token
= Tok_End
or else Token
= Tok_When
then
3341 Set_Null_Present
(Component_List_Node
, True);
3342 return Component_List_Node
;
3344 Error_Msg
("NULL component only allowed in null record", Null_Loc
);
3348 -- Scan components for non-null record
3350 P_Pragmas_Opt
(Decls_List
);
3352 if Token
/= Tok_Case
then
3353 Component_Scan_Loop
: loop
3354 P_Component_Items
(Decls_List
);
3355 P_Pragmas_Opt
(Decls_List
);
3357 exit Component_Scan_Loop
when Token
= Tok_End
3358 or else Token
= Tok_Case
3359 or else Token
= Tok_When
;
3361 -- We are done if we do not have an identifier. However, if we
3362 -- have a misspelled reserved identifier that is in a column to
3363 -- the right of the record definition, we will treat it as an
3364 -- identifier. It turns out to be too dangerous in practice to
3365 -- accept such a mis-spelled identifier which does not have this
3366 -- additional clue that confirms the incorrect spelling.
3368 if Token
/= Tok_Identifier
then
3369 if Start_Column
> Scope
.Table
(Scope
.Last
).Ecol
3370 and then Is_Reserved_Identifier
3372 Save_Scan_State
(Scan_State
); -- at reserved id
3373 Scan
; -- possible reserved id
3375 if Token
= Tok_Comma
or else Token
= Tok_Colon
then
3376 Restore_Scan_State
(Scan_State
);
3377 Scan_Reserved_Identifier
(Force_Msg
=> True);
3379 -- Note reserved identifier used as field name after all
3380 -- because not followed by colon or comma.
3383 Restore_Scan_State
(Scan_State
);
3384 exit Component_Scan_Loop
;
3387 -- Non-identifier that definitely was not reserved id
3390 exit Component_Scan_Loop
;
3393 end loop Component_Scan_Loop
;
3396 if Token
= Tok_Case
then
3397 Set_Variant_Part
(Component_List_Node
, P_Variant_Part
);
3399 -- Check for junk after variant part
3401 if Token
= Tok_Identifier
then
3402 Save_Scan_State
(Scan_State
);
3403 Scan
; -- past identifier
3405 if Token
= Tok_Colon
then
3406 Restore_Scan_State
(Scan_State
);
3407 Error_Msg_SC
("component may not follow variant part");
3408 Discard_Junk_Node
(P_Component_List
);
3410 elsif Token
= Tok_Case
then
3411 Restore_Scan_State
(Scan_State
);
3412 Error_Msg_SC
("only one variant part allowed in a record");
3413 Discard_Junk_Node
(P_Component_List
);
3416 Restore_Scan_State
(Scan_State
);
3421 Set_Component_Items
(Component_List_Node
, Decls_List
);
3422 return Component_List_Node
;
3423 end P_Component_List
;
3425 -------------------------
3426 -- 3.8 Component Item --
3427 -------------------------
3429 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3431 -- COMPONENT_DECLARATION ::=
3432 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3433 -- [:= DEFAULT_EXPRESSION]
3434 -- [ASPECT_SPECIFICATIONS];
3436 -- COMPONENT_DEFINITION ::=
3437 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3439 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3440 -- the scan is positioned past the following semicolon.
3442 -- Note: we do not yet allow representation clauses to appear as component
3443 -- items, do we need to add this capability sometime in the future ???
3445 procedure P_Component_Items
(Decls
: List_Id
) is
3446 Aliased_Present
: Boolean := False;
3447 CompDef_Node
: Node_Id
;
3448 Decl_Node
: Node_Id
;
3449 Scan_State
: Saved_Scan_State
;
3450 Not_Null_Present
: Boolean := False;
3453 Ident_Sloc
: Source_Ptr
;
3455 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3456 -- This array holds the list of defining identifiers. The upper bound
3457 -- of 4096 is intended to be essentially infinite, and we do not even
3458 -- bother to check for it being exceeded.
3461 if Token
/= Tok_Identifier
then
3462 Error_Msg_SC
("component declaration expected");
3463 Resync_Past_Semicolon
;
3467 Ident_Sloc
:= Token_Ptr
;
3468 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3471 while Comma_Present
loop
3472 Num_Idents
:= Num_Idents
+ 1;
3473 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3476 -- If there are multiple identifiers, we repeatedly scan the
3477 -- type and initialization expression information by resetting
3478 -- the scan pointer (so that we get completely separate trees
3479 -- for each occurrence).
3481 if Num_Idents
> 1 then
3482 Save_Scan_State
(Scan_State
);
3487 -- Loop through defining identifiers in list
3492 -- The following block is present to catch Error_Resync
3493 -- which causes the parse to be reset past the semicolon
3496 Decl_Node
:= New_Node
(N_Component_Declaration
, Ident_Sloc
);
3497 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
3499 if Token
= Tok_Constant
then
3500 Error_Msg_SC
("constant components are not permitted");
3504 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
3506 if Token_Name
= Name_Aliased
then
3507 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
3510 if Token
= Tok_Aliased
then
3511 Aliased_Present
:= True;
3512 Scan
; -- past ALIASED
3515 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
3517 -- Ada 2005 (AI-230): Access Definition case
3519 if Token
= Tok_Access
then
3520 if Ada_Version
< Ada_2005
then
3522 ("generalized use of anonymous access types " &
3523 "is an Ada 2005 extension");
3524 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3527 -- AI95-406 makes "aliased" legal (and useless) here, so the
3528 -- following code which used to be required is commented out.
3530 -- if Aliased_Present then
3531 -- Error_Msg_SP ("ALIASED not allowed here");
3534 Set_Subtype_Indication
(CompDef_Node
, Empty
);
3535 Set_Aliased_Present
(CompDef_Node
, False);
3536 Set_Access_Definition
(CompDef_Node
,
3537 P_Access_Definition
(Not_Null_Present
));
3540 Set_Access_Definition
(CompDef_Node
, Empty
);
3541 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
3542 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
3544 if Token
= Tok_Array
then
3545 Error_Msg_SC
("anonymous arrays not allowed as components");
3549 Set_Subtype_Indication
(CompDef_Node
,
3550 P_Subtype_Indication
(Not_Null_Present
));
3553 Set_Component_Definition
(Decl_Node
, CompDef_Node
);
3554 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
3557 Set_Prev_Ids
(Decl_Node
, True);
3560 if Ident
< Num_Idents
then
3561 Set_More_Ids
(Decl_Node
, True);
3564 Append
(Decl_Node
, Decls
);
3567 when Error_Resync
=>
3568 if Token
/= Tok_End
then
3569 Resync_Past_Semicolon
;
3573 exit Ident_Loop
when Ident
= Num_Idents
;
3575 Restore_Scan_State
(Scan_State
);
3577 end loop Ident_Loop
;
3579 P_Aspect_Specifications
(Decl_Node
);
3580 end P_Component_Items
;
3582 --------------------------------
3583 -- 3.8 Component Declaration --
3584 --------------------------------
3586 -- Parsed by P_Component_Items (3.8)
3588 -------------------------
3589 -- 3.8.1 Variant Part --
3590 -------------------------
3593 -- case discriminant_DIRECT_NAME is
3598 -- The caller has checked that the initial token is CASE
3600 -- Error recovery: cannot raise Error_Resync
3602 function P_Variant_Part
return Node_Id
is
3603 Variant_Part_Node
: Node_Id
;
3604 Variants_List
: List_Id
;
3605 Case_Node
: Node_Id
;
3608 Variant_Part_Node
:= New_Node
(N_Variant_Part
, Token_Ptr
);
3610 Scope
.Table
(Scope
.Last
).Etyp
:= E_Case
;
3611 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3612 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3615 Case_Node
:= P_Expression
;
3616 Set_Name
(Variant_Part_Node
, Case_Node
);
3618 if Nkind
(Case_Node
) /= N_Identifier
then
3619 Set_Name
(Variant_Part_Node
, Error
);
3620 Error_Msg
("discriminant name expected", Sloc
(Case_Node
));
3622 elsif Paren_Count
(Case_Node
) /= 0 then
3624 ("|discriminant name may not be parenthesized",
3626 Set_Paren_Count
(Case_Node
, 0);
3630 Variants_List
:= New_List
;
3631 P_Pragmas_Opt
(Variants_List
);
3633 -- Test missing variant
3635 if Token
= Tok_End
then
3636 Error_Msg_BC
("WHEN expected (must have at least one variant)");
3638 Append
(P_Variant
, Variants_List
);
3641 -- Loop through variants, note that we allow if in place of when,
3642 -- this error will be detected and handled in P_Variant.
3645 P_Pragmas_Opt
(Variants_List
);
3647 if Token
/= Tok_When
3648 and then Token
/= Tok_If
3649 and then Token
/= Tok_Others
3651 exit when Check_End
;
3654 Append
(P_Variant
, Variants_List
);
3657 Set_Variants
(Variant_Part_Node
, Variants_List
);
3658 return Variant_Part_Node
;
3661 --------------------
3663 --------------------
3666 -- when DISCRETE_CHOICE_LIST =>
3669 -- Error recovery: cannot raise Error_Resync
3671 -- The initial token on entry is either WHEN, IF or OTHERS
3673 function P_Variant
return Node_Id
is
3674 Variant_Node
: Node_Id
;
3677 -- Special check to recover nicely from use of IF in place of WHEN
3679 if Token
= Tok_If
then
3686 Variant_Node
:= New_Node
(N_Variant
, Prev_Token_Ptr
);
3687 Set_Discrete_Choices
(Variant_Node
, P_Discrete_Choice_List
);
3689 Set_Component_List
(Variant_Node
, P_Component_List
);
3690 return Variant_Node
;
3693 ---------------------------------
3694 -- 3.8.1 Discrete Choice List --
3695 ---------------------------------
3697 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3699 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3701 -- Note: in Ada 83, the expression must be a simple expression
3703 -- Error recovery: cannot raise Error_Resync
3705 function P_Discrete_Choice_List
return List_Id
is
3707 Expr_Node
: Node_Id
;
3708 Choice_Node
: Node_Id
;
3711 Choices
:= New_List
;
3713 if Token
= Tok_Others
then
3714 Append
(New_Node
(N_Others_Choice
, Token_Ptr
), Choices
);
3715 Scan
; -- past OTHERS
3719 -- Scan out expression or range attribute
3721 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3722 Ignore
(Tok_Right_Paren
);
3724 if Token
= Tok_Colon
3725 and then Nkind
(Expr_Node
) = N_Identifier
3727 Error_Msg_SP
("label not permitted in this context");
3732 elsif Expr_Form
= EF_Range_Attr
then
3733 Append
(Expr_Node
, Choices
);
3737 elsif Token
= Tok_Dot_Dot
then
3738 Check_Simple_Expression
(Expr_Node
);
3739 Choice_Node
:= New_Node
(N_Range
, Token_Ptr
);
3740 Set_Low_Bound
(Choice_Node
, Expr_Node
);
3742 Expr_Node
:= P_Expression_No_Right_Paren
;
3743 Check_Simple_Expression
(Expr_Node
);
3744 Set_High_Bound
(Choice_Node
, Expr_Node
);
3745 Append
(Choice_Node
, Choices
);
3747 -- Simple name, must be subtype, so range allowed
3749 elsif Expr_Form
= EF_Simple_Name
then
3750 if Token
= Tok_Range
then
3751 Append
(P_Subtype_Indication
(Expr_Node
), Choices
);
3753 elsif Token
in Token_Class_Consk
then
3755 ("the only constraint allowed here " &
3756 "is a range constraint");
3757 Discard_Junk_Node
(P_Constraint_Opt
);
3758 Append
(Expr_Node
, Choices
);
3761 Append
(Expr_Node
, Choices
);
3767 -- In Ada 2012 mode, the expression must be a simple
3768 -- expression. The reason for this restriction (i.e. going
3769 -- back to the Ada 83 rule) is to avoid ambiguities when set
3770 -- membership operations are allowed, consider the
3773 -- when A in 1 .. 10 | 12 =>
3775 -- This is ambiguous without parentheses, so we require one
3776 -- of the following two parenthesized forms to disambiguate:
3778 -- one of the following:
3780 -- when (A in 1 .. 10 | 12) =>
3781 -- when (A in 1 .. 10) | 12 =>
3783 -- To solve this, in Ada 2012 mode, we disallow the use of
3784 -- membership operations in expressions in choices.
3786 -- Technically in the grammar, the expression must match the
3787 -- grammar for restricted expression.
3789 if Ada_Version
>= Ada_2012
then
3790 Check_Restricted_Expression
(Expr_Node
);
3792 -- In Ada 83 mode, the syntax required a simple expression
3795 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
3798 Append
(Expr_Node
, Choices
);
3802 when Error_Resync
=>
3808 if Token
= Tok_Comma
then
3811 if Token
= Tok_Vertical_Bar
then
3812 Error_Msg_SP
-- CODEFIX
3813 ("|extra "","" ignored");
3817 Error_Msg_SP
-- CODEFIX
3818 (""","" should be ""'|""");
3822 exit when Token
/= Tok_Vertical_Bar
;
3829 end P_Discrete_Choice_List
;
3831 ----------------------------
3832 -- 3.8.1 Discrete Choice --
3833 ----------------------------
3835 -- Parsed by P_Discrete_Choice_List (3.8.1)
3837 ----------------------------------
3838 -- 3.9.1 Record Extension Part --
3839 ----------------------------------
3841 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
3843 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
3845 --------------------------------------
3846 -- 3.9.4 Interface Type Definition --
3847 --------------------------------------
3849 -- INTERFACE_TYPE_DEFINITION ::=
3850 -- [limited | task | protected | synchronized] interface
3851 -- [and INTERFACE_LIST]
3853 -- Error recovery: cannot raise Error_Resync
3855 function P_Interface_Type_Definition
3856 (Abstract_Present
: Boolean) return Node_Id
3858 Typedef_Node
: Node_Id
;
3861 if Ada_Version
< Ada_2005
then
3862 Error_Msg_SP
("abstract interface is an Ada 2005 extension");
3863 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3866 if Abstract_Present
then
3868 ("ABSTRACT not allowed in interface type definition " &
3872 Scan
; -- past INTERFACE
3874 -- Ada 2005 (AI-345): In case of interfaces with a null list of
3875 -- interfaces we build a record_definition node.
3877 if Token
= Tok_Semicolon
or else Aspect_Specifications_Present
then
3878 Typedef_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3880 Set_Abstract_Present
(Typedef_Node
);
3881 Set_Tagged_Present
(Typedef_Node
);
3882 Set_Null_Present
(Typedef_Node
);
3883 Set_Interface_Present
(Typedef_Node
);
3885 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
3886 -- a list of interfaces we build a derived_type_definition node. This
3887 -- simplifies the semantic analysis (and hence further maintenance)
3890 if Token
/= Tok_And
then
3891 Error_Msg_AP
("AND expected");
3896 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
3898 Set_Abstract_Present
(Typedef_Node
);
3899 Set_Interface_Present
(Typedef_Node
);
3900 Set_Subtype_Indication
(Typedef_Node
, P_Qualified_Simple_Name
);
3902 Set_Record_Extension_Part
(Typedef_Node
,
3903 New_Node
(N_Record_Definition
, Token_Ptr
));
3904 Set_Null_Present
(Record_Extension_Part
(Typedef_Node
));
3906 if Token
= Tok_And
then
3907 Set_Interface_List
(Typedef_Node
, New_List
);
3911 Append
(P_Qualified_Simple_Name
,
3912 Interface_List
(Typedef_Node
));
3913 exit when Token
/= Tok_And
;
3919 return Typedef_Node
;
3920 end P_Interface_Type_Definition
;
3922 ----------------------------------
3923 -- 3.10 Access Type Definition --
3924 ----------------------------------
3926 -- ACCESS_TYPE_DEFINITION ::=
3927 -- ACCESS_TO_OBJECT_DEFINITION
3928 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3930 -- ACCESS_TO_OBJECT_DEFINITION ::=
3931 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
3933 -- GENERAL_ACCESS_MODIFIER ::= all | constant
3935 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3936 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3937 -- | [NULL_EXCLUSION] access [protected] function
3938 -- PARAMETER_AND_RESULT_PROFILE
3940 -- PARAMETER_PROFILE ::= [FORMAL_PART]
3942 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
3944 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
3945 -- parsed the null_exclusion part and has also removed the ACCESS token;
3946 -- otherwise the caller has just checked that the initial token is ACCESS
3948 -- Error recovery: can raise Error_Resync
3950 function P_Access_Type_Definition
3951 (Header_Already_Parsed
: Boolean := False) return Node_Id
3953 Access_Loc
: constant Source_Ptr
:= Token_Ptr
;
3954 Prot_Flag
: Boolean;
3955 Not_Null_Present
: Boolean := False;
3956 Not_Null_Subtype
: Boolean := False;
3957 Type_Def_Node
: Node_Id
;
3958 Result_Not_Null
: Boolean;
3959 Result_Node
: Node_Id
;
3961 procedure Check_Junk_Subprogram_Name
;
3962 -- Used in access to subprogram definition cases to check for an
3963 -- identifier or operator symbol that does not belong.
3965 --------------------------------
3966 -- Check_Junk_Subprogram_Name --
3967 --------------------------------
3969 procedure Check_Junk_Subprogram_Name
is
3970 Saved_State
: Saved_Scan_State
;
3973 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
3974 Save_Scan_State
(Saved_State
);
3975 Scan
; -- past possible junk subprogram name
3977 if Token
= Tok_Left_Paren
or else Token
= Tok_Semicolon
then
3978 Error_Msg_SP
("unexpected subprogram name ignored");
3982 Restore_Scan_State
(Saved_State
);
3985 end Check_Junk_Subprogram_Name
;
3987 -- Start of processing for P_Access_Type_Definition
3990 if not Header_Already_Parsed
then
3992 -- NOT NULL ACCESS .. is a common form of access definition.
3993 -- ACCESS NOT NULL .. is certainly rare, but syntactically legal.
3994 -- NOT NULL ACCESS NOT NULL .. is rarer yet, and also legal.
3995 -- The last two cases are only meaningful if the following subtype
3996 -- indication denotes an access type (semantic check). The flag
3997 -- Not_Null_Subtype indicates that this second null exclusion is
3998 -- present in the access type definition.
4000 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4001 Scan
; -- past ACCESS
4002 Not_Null_Subtype
:= P_Null_Exclusion
; -- Might also appear
4005 if Token_Name
= Name_Protected
then
4006 Check_95_Keyword
(Tok_Protected
, Tok_Procedure
);
4007 Check_95_Keyword
(Tok_Protected
, Tok_Function
);
4010 Prot_Flag
:= (Token
= Tok_Protected
);
4013 Scan
; -- past PROTECTED
4015 if Token
/= Tok_Procedure
and then Token
/= Tok_Function
then
4016 Error_Msg_SC
-- CODEFIX
4017 ("FUNCTION or PROCEDURE expected");
4021 if Token
= Tok_Procedure
then
4022 if Ada_Version
= Ada_83
then
4023 Error_Msg_SC
("(Ada 83) access to procedure not allowed!");
4026 Type_Def_Node
:= New_Node
(N_Access_Procedure_Definition
, Access_Loc
);
4027 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4028 Scan
; -- past PROCEDURE
4029 Check_Junk_Subprogram_Name
;
4030 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4031 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4033 elsif Token
= Tok_Function
then
4034 if Ada_Version
= Ada_83
then
4035 Error_Msg_SC
("(Ada 83) access to function not allowed!");
4038 Type_Def_Node
:= New_Node
(N_Access_Function_Definition
, Access_Loc
);
4039 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4040 Scan
; -- past FUNCTION
4041 Check_Junk_Subprogram_Name
;
4042 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4043 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4046 Result_Not_Null
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4048 -- Ada 2005 (AI-318-02)
4050 if Token
= Tok_Access
then
4051 if Ada_Version
< Ada_2005
then
4053 ("anonymous access result type is an Ada 2005 extension");
4054 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4057 Result_Node
:= P_Access_Definition
(Result_Not_Null
);
4060 Result_Node
:= P_Subtype_Mark
;
4063 -- A null exclusion on the result type must be recorded in a flag
4064 -- distinct from the one used for the access-to-subprogram type's
4067 Set_Null_Exclusion_In_Return_Present
4068 (Type_Def_Node
, Result_Not_Null
);
4071 Set_Result_Definition
(Type_Def_Node
, Result_Node
);
4075 New_Node
(N_Access_To_Object_Definition
, Access_Loc
);
4076 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4077 Set_Null_Excluding_Subtype
(Type_Def_Node
, Not_Null_Subtype
);
4079 if Token
= Tok_All
or else Token
= Tok_Constant
then
4080 if Ada_Version
= Ada_83
then
4081 Error_Msg_SC
("(Ada 83) access modifier not allowed!");
4084 if Token
= Tok_All
then
4085 Set_All_Present
(Type_Def_Node
, True);
4088 Set_Constant_Present
(Type_Def_Node
, True);
4091 Scan
; -- past ALL or CONSTANT
4094 Set_Subtype_Indication
(Type_Def_Node
,
4095 P_Subtype_Indication
(Not_Null_Present
));
4098 return Type_Def_Node
;
4099 end P_Access_Type_Definition
;
4101 ---------------------------------------
4102 -- 3.10 Access To Object Definition --
4103 ---------------------------------------
4105 -- Parsed by P_Access_Type_Definition (3.10)
4107 -----------------------------------
4108 -- 3.10 General Access Modifier --
4109 -----------------------------------
4111 -- Parsed by P_Access_Type_Definition (3.10)
4113 -------------------------------------------
4114 -- 3.10 Access To Subprogram Definition --
4115 -------------------------------------------
4117 -- Parsed by P_Access_Type_Definition (3.10)
4119 -----------------------------
4120 -- 3.10 Access Definition --
4121 -----------------------------
4123 -- ACCESS_DEFINITION ::=
4124 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4125 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
4127 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4128 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4129 -- | [NULL_EXCLUSION] access [protected] function
4130 -- PARAMETER_AND_RESULT_PROFILE
4132 -- The caller has parsed the null-exclusion part and it has also checked
4133 -- that the next token is ACCESS
4135 -- Error recovery: cannot raise Error_Resync
4137 function P_Access_Definition
4138 (Null_Exclusion_Present
: Boolean) return Node_Id
4141 Subp_Node
: Node_Id
;
4144 Def_Node
:= New_Node
(N_Access_Definition
, Token_Ptr
);
4145 Scan
; -- past ACCESS
4147 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
4149 if Token
= Tok_Protected
4150 or else Token
= Tok_Procedure
4151 or else Token
= Tok_Function
4153 if Ada_Version
< Ada_2005
then
4154 Error_Msg_SP
("access-to-subprogram is an Ada 2005 extension");
4155 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
4158 Subp_Node
:= P_Access_Type_Definition
(Header_Already_Parsed
=> True);
4159 Set_Null_Exclusion_Present
(Subp_Node
, Null_Exclusion_Present
);
4160 Set_Access_To_Subprogram_Definition
(Def_Node
, Subp_Node
);
4162 -- Ada 2005 (AI-231)
4163 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4166 Set_Null_Exclusion_Present
(Def_Node
, Null_Exclusion_Present
);
4168 if Token
= Tok_All
then
4169 if Ada_Version
< Ada_2005
then
4171 ("ALL is not permitted for anonymous access types");
4175 Set_All_Present
(Def_Node
);
4177 elsif Token
= Tok_Constant
then
4178 if Ada_Version
< Ada_2005
then
4179 Error_Msg_SP
("access-to-constant is an Ada 2005 extension");
4180 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
4183 Scan
; -- past CONSTANT
4184 Set_Constant_Present
(Def_Node
);
4187 Set_Subtype_Mark
(Def_Node
, P_Subtype_Mark
);
4192 end P_Access_Definition
;
4194 -----------------------------------------
4195 -- 3.10.1 Incomplete Type Declaration --
4196 -----------------------------------------
4198 -- Parsed by P_Type_Declaration (3.2.1)
4200 ----------------------------
4201 -- 3.11 Declarative Part --
4202 ----------------------------
4204 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
4206 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Items
4207 -- handles errors, and returns cleanly after an error has occurred)
4209 function P_Declarative_Part
return List_Id
is
4214 -- Indicate no bad declarations detected yet. This will be reset by
4215 -- P_Declarative_Items if a bad declaration is discovered.
4217 Missing_Begin_Msg
:= No_Error_Msg
;
4219 -- Get rid of active SIS entry from outer scope. This means we will
4220 -- miss some nested cases, but it doesn't seem worth the effort. See
4221 -- discussion in Par for further details
4223 SIS_Entry_Active
:= False;
4226 -- Loop to scan out the declarations
4229 P_Declarative_Items
(Decls
, Done
, In_Spec
=> False);
4233 -- Get rid of active SIS entry which is left set only if we scanned a
4234 -- procedure declaration and have not found the body. We could give
4235 -- an error message, but that really would be usurping the role of
4236 -- semantic analysis (this really is a missing body case).
4238 SIS_Entry_Active
:= False;
4240 end P_Declarative_Part
;
4242 ----------------------------
4243 -- 3.11 Declarative Item --
4244 ----------------------------
4246 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4248 -- Can return Error if a junk declaration is found, or Empty if no
4249 -- declaration is found (i.e. a token ending declarations, such as
4250 -- BEGIN or END is encountered).
4252 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4253 -- then the scan is set past the next semicolon and Error is returned.
4255 procedure P_Declarative_Items
4260 Scan_State
: Saved_Scan_State
;
4264 Style
.Check_Indentation
;
4269 when Tok_Function
=>
4271 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4277 -- Check for loop (premature statement)
4279 Save_Scan_State
(Scan_State
);
4282 if Token
= Tok_Identifier
then
4283 Scan
; -- past identifier
4285 if Token
= Tok_In
then
4286 Restore_Scan_State
(Scan_State
);
4287 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4292 -- Not a loop, so must be rep clause
4294 Restore_Scan_State
(Scan_State
);
4295 Append
(P_Representation_Clause
, Decls
);
4300 Append
(P_Generic
, Decls
);
4303 when Tok_Identifier
=>
4306 -- Special check for misuse of overriding not in Ada 2005 mode
4308 if Token_Name
= Name_Overriding
4309 and then not Next_Token_Is
(Tok_Colon
)
4311 Error_Msg_SC
("overriding indicator is an Ada 2005 extension");
4312 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4314 Token
:= Tok_Overriding
;
4315 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4318 -- Normal case, no overriding, or overriding followed by colon
4321 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4324 -- Ada 2005: A subprogram declaration can start with "not" or
4325 -- "overriding". In older versions, "overriding" is handled
4326 -- like an identifier, with the appropriate messages.
4330 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4333 when Tok_Overriding
=>
4335 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4340 Append
(P_Package
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4344 Append
(P_Pragma
, Decls
);
4347 when Tok_Procedure
=>
4349 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4352 when Tok_Protected
=>
4354 Scan
; -- past PROTECTED
4355 Append
(P_Protected
, Decls
);
4360 Append
(P_Subtype_Declaration
, Decls
);
4366 Append
(P_Task
, Decls
);
4371 Append
(P_Type_Declaration
, Decls
);
4376 Append
(P_Use_Clause
, Decls
);
4382 if Aspect_Specifications_Present
then
4384 -- If we are after a semicolon, complain that it was ignored.
4385 -- But we don't really ignore it, since we dump the aspects,
4386 -- so we make the error message a normal fatal message which
4387 -- will inhibit semantic analysis anyway).
4389 if Prev_Token
= Tok_Semicolon
then
4390 Error_Msg_SP
-- CODEFIX
4391 ("extra "";"" ignored");
4393 -- If not just past semicolon, just complain that aspects are
4394 -- not allowed at this point.
4397 Error_Msg_SC
("aspect specifications not allowed here");
4401 Dummy_Node
: constant Node_Id
:=
4402 New_Node
(N_Package_Specification
, Token_Ptr
);
4403 pragma Warnings
(Off
, Dummy_Node
);
4404 -- Dummy node to attach aspect specifications to. We will
4405 -- then throw them away.
4408 P_Aspect_Specifications
(Dummy_Node
, Semicolon
=> True);
4411 -- Here if not aspect specifications case
4414 Error_Msg_SC
("WITH can only appear in context clause");
4418 -- BEGIN terminates the scan of a sequence of declarations unless
4419 -- there is a missing subprogram body, see section on handling
4420 -- semicolon in place of IS. We only treat the begin as satisfying
4421 -- the subprogram declaration if it falls in the expected column
4425 if SIS_Entry_Active
and then Start_Column
>= SIS_Ecol
then
4427 -- Here we have the case where a BEGIN is encountered during
4428 -- declarations in a declarative part, or at the outer level,
4429 -- and there is a subprogram declaration outstanding for which
4430 -- no body has been supplied. This is the case where we assume
4431 -- that the semicolon in the subprogram declaration should
4432 -- really have been is. The active SIS entry describes the
4433 -- subprogram declaration. On return the declaration has been
4434 -- modified to become a body.
4437 Specification_Node
: Node_Id
;
4438 Decl_Node
: Node_Id
;
4439 Body_Node
: Node_Id
;
4442 -- First issue the error message. If we had a missing
4443 -- semicolon in the declaration, then change the message
4444 -- to <missing "is">
4446 if SIS_Missing_Semicolon_Message
/= No_Error_Msg
then
4447 Change_Error_Text
-- Replace: "missing "";"" "
4448 (SIS_Missing_Semicolon_Message
, "missing ""is""");
4450 -- Otherwise we saved the semicolon position, so complain
4453 Error_Msg
-- CODEFIX
4454 ("|"";"" should be IS", SIS_Semicolon_Sloc
);
4457 -- The next job is to fix up any declarations that occurred
4458 -- between the procedure header and the BEGIN. These got
4459 -- chained to the outer declarative region (immediately
4460 -- after the procedure declaration) and they should be
4461 -- chained to the subprogram itself, which is a body
4462 -- rather than a spec.
4464 Specification_Node
:= Specification
(SIS_Declaration_Node
);
4465 Change_Node
(SIS_Declaration_Node
, N_Subprogram_Body
);
4466 Body_Node
:= SIS_Declaration_Node
;
4467 Set_Specification
(Body_Node
, Specification_Node
);
4468 Set_Declarations
(Body_Node
, New_List
);
4471 Decl_Node
:= Remove_Next
(Body_Node
);
4472 exit when Decl_Node
= Empty
;
4473 Append
(Decl_Node
, Declarations
(Body_Node
));
4476 -- Now make the scope table entry for the Begin-End and
4480 Scope
.Table
(Scope
.Last
).Sloc
:= SIS_Sloc
;
4481 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
4482 Scope
.Table
(Scope
.Last
).Ecol
:= SIS_Ecol
;
4483 Scope
.Table
(Scope
.Last
).Labl
:= SIS_Labl
;
4484 Scope
.Table
(Scope
.Last
).Lreq
:= False;
4485 SIS_Entry_Active
:= False;
4487 Set_Handled_Statement_Sequence
(Body_Node
,
4488 P_Handled_Sequence_Of_Statements
);
4489 End_Statements
(Handled_Statement_Sequence
(Body_Node
));
4498 -- Normally an END terminates the scan for basic declarative items.
4499 -- The one exception is END RECORD, which is probably left over from
4503 Save_Scan_State
(Scan_State
); -- at END
4506 if Token
= Tok_Record
then
4507 Error_Msg_SP
("no RECORD for this `end record`!");
4508 Scan
; -- past RECORD
4512 Restore_Scan_State
(Scan_State
); -- to END
4516 -- The following tokens which can only be the start of a statement
4517 -- are considered to end a declarative part (i.e. we have a missing
4518 -- BEGIN situation). We are fairly conservative in making this
4519 -- judgment, because it is a real mess to go into statement mode
4520 -- prematurely in response to a junk declaration.
4535 -- But before we decide that it's a statement, let's check for
4536 -- a reserved word misused as an identifier.
4538 if Is_Reserved_Identifier
then
4539 Save_Scan_State
(Scan_State
);
4540 Scan
; -- past the token
4542 -- If reserved identifier not followed by colon or comma, then
4543 -- this is most likely an assignment statement to the bad id.
4545 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4546 Restore_Scan_State
(Scan_State
);
4547 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4550 -- Otherwise we have a declaration of the bad id
4553 Restore_Scan_State
(Scan_State
);
4554 Scan_Reserved_Identifier
(Force_Msg
=> True);
4555 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4558 -- If not reserved identifier, then it's definitely a statement
4561 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4565 -- The token RETURN may well also signal a missing BEGIN situation,
4566 -- however, we never let it end the declarative part, because it may
4567 -- also be part of a half-baked function declaration.
4570 Error_Msg_SC
("misplaced RETURN statement");
4573 -- PRIVATE definitely terminates the declarations in a spec,
4574 -- and is an error in a body.
4580 Error_Msg_SC
("PRIVATE not allowed in body");
4581 Scan
; -- past PRIVATE
4584 -- An end of file definitely terminates the declarations
4589 -- The remaining tokens do not end the scan, but cannot start a
4590 -- valid declaration, so we signal an error and resynchronize.
4591 -- But first check for misuse of a reserved identifier.
4595 -- Here we check for a reserved identifier
4597 if Is_Reserved_Identifier
then
4598 Save_Scan_State
(Scan_State
);
4599 Scan
; -- past the token
4601 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4602 Restore_Scan_State
(Scan_State
);
4603 Set_Declaration_Expected
;
4606 Restore_Scan_State
(Scan_State
);
4607 Scan_Reserved_Identifier
(Force_Msg
=> True);
4609 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4613 Set_Declaration_Expected
;
4618 -- To resynchronize after an error, we scan to the next semicolon and
4619 -- return with Done = False, indicating that there may still be more
4620 -- valid declarations to come.
4623 when Error_Resync
=>
4624 Resync_Past_Semicolon
;
4626 end P_Declarative_Items
;
4628 ----------------------------------
4629 -- 3.11 Basic Declarative Item --
4630 ----------------------------------
4632 -- BASIC_DECLARATIVE_ITEM ::=
4633 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4635 -- Scan zero or more basic declarative items
4637 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4638 -- the scan pointer is repositioned past the next semicolon, and the scan
4639 -- for declarative items continues.
4641 function P_Basic_Declarative_Items
return List_Id
is
4648 -- Indicate no bad declarations detected yet in the current context:
4649 -- visible or private declarations of a package spec.
4651 Missing_Begin_Msg
:= No_Error_Msg
;
4653 -- Get rid of active SIS entry from outer scope. This means we will
4654 -- miss some nested cases, but it doesn't seem worth the effort. See
4655 -- discussion in Par for further details
4657 SIS_Entry_Active
:= False;
4659 -- Loop to scan out declarations
4664 P_Declarative_Items
(Decls
, Done
, In_Spec
=> True);
4668 -- Get rid of active SIS entry. This is set only if we have scanned a
4669 -- procedure declaration and have not found the body. We could give
4670 -- an error message, but that really would be usurping the role of
4671 -- semantic analysis (this really is a case of a missing body).
4673 SIS_Entry_Active
:= False;
4675 -- Test for assorted illegal declarations not diagnosed elsewhere
4677 Decl
:= First
(Decls
);
4679 while Present
(Decl
) loop
4680 Kind
:= Nkind
(Decl
);
4682 -- Test for body scanned, not acceptable as basic decl item
4684 if Kind
= N_Subprogram_Body
or else
4685 Kind
= N_Package_Body
or else
4686 Kind
= N_Task_Body
or else
4687 Kind
= N_Protected_Body
4689 Error_Msg
("proper body not allowed in package spec", Sloc
(Decl
));
4691 -- Complete declaration of mangled subprogram body, for better
4692 -- recovery if analysis is attempted.
4694 if Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
4695 and then No
(Handled_Statement_Sequence
(Decl
))
4697 Set_Handled_Statement_Sequence
(Decl
,
4698 Make_Handled_Sequence_Of_Statements
(Sloc
(Decl
),
4699 Statements
=> New_List
));
4702 -- Test for body stub scanned, not acceptable as basic decl item
4704 elsif Kind
in N_Body_Stub
then
4705 Error_Msg
("body stub not allowed in package spec", Sloc
(Decl
));
4707 elsif Kind
= N_Assignment_Statement
then
4709 ("assignment statement not allowed in package spec",
4717 end P_Basic_Declarative_Items
;
4723 -- For proper body, see below
4724 -- For body stub, see 10.1.3
4726 -----------------------
4727 -- 3.11 Proper Body --
4728 -----------------------
4730 -- Subprogram body is parsed by P_Subprogram (6.1)
4731 -- Package body is parsed by P_Package (7.1)
4732 -- Task body is parsed by P_Task (9.1)
4733 -- Protected body is parsed by P_Protected (9.4)
4735 ------------------------------
4736 -- Set_Declaration_Expected --
4737 ------------------------------
4739 procedure Set_Declaration_Expected
is
4741 Error_Msg_SC
("declaration expected");
4743 if Missing_Begin_Msg
= No_Error_Msg
then
4744 Missing_Begin_Msg
:= Get_Msg_Id
;
4746 end Set_Declaration_Expected
;
4748 ----------------------
4749 -- Skip_Declaration --
4750 ----------------------
4752 procedure Skip_Declaration
(S
: List_Id
) is
4753 Dummy_Done
: Boolean;
4754 pragma Warnings
(Off
, Dummy_Done
);
4756 P_Declarative_Items
(S
, Dummy_Done
, False);
4757 end Skip_Declaration
;
4759 -----------------------------------------
4760 -- Statement_When_Declaration_Expected --
4761 -----------------------------------------
4763 procedure Statement_When_Declaration_Expected
4769 -- Case of second occurrence of statement in one declaration sequence
4771 if Missing_Begin_Msg
/= No_Error_Msg
then
4773 -- In the procedure spec case, just ignore it, we only give one
4774 -- message for the first occurrence, since otherwise we may get
4775 -- horrible cascading if BODY was missing in the header line.
4780 -- In the declarative part case, take a second statement as a sure
4781 -- sign that we really have a missing BEGIN, and end the declarative
4782 -- part now. Note that the caller will fix up the first message to
4783 -- say "missing BEGIN" so that's how the error will be signalled.
4790 -- Case of first occurrence of unexpected statement
4793 -- If we are in a package spec, then give message of statement
4794 -- not allowed in package spec. This message never gets changed.
4797 Error_Msg_SC
("statement not allowed in package spec");
4799 -- If in declarative part, then we give the message complaining
4800 -- about finding a statement when a declaration is expected. This
4801 -- gets changed to a complaint about a missing BEGIN if we later
4802 -- find that no BEGIN is present.
4805 Error_Msg_SC
("statement not allowed in declarative part");
4808 -- Capture message Id. This is used for two purposes, first to
4809 -- stop multiple messages, see test above, and second, to allow
4810 -- the replacement of the message in the declarative part case.
4812 Missing_Begin_Msg
:= Get_Msg_Id
;
4815 -- In all cases except the case in which we decided to terminate the
4816 -- declaration sequence on a second error, we scan out the statement
4817 -- and append it to the list of declarations (note that the semantics
4818 -- can handle statements in a declaration list so if we proceed to
4819 -- call the semantic phase, all will be (reasonably) well.
4821 Append_List_To
(Decls
, P_Sequence_Of_Statements
(SS_Unco
));
4823 -- Done is set to False, since we want to continue the scan of
4824 -- declarations, hoping that this statement was a temporary glitch.
4825 -- If we indeed are now in the statement part (i.e. this was a missing
4826 -- BEGIN, then it's not terrible, we will simply keep calling this
4827 -- procedure to process the statements one by one, and then finally
4828 -- hit the missing BEGIN, which will clean up the error message.
4831 end Statement_When_Declaration_Expected
;