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
);
1864 if Ident
< Num_Idents
then
1865 Set_More_Ids
(Decl_Node
, True);
1869 Set_Prev_Ids
(Decl_Node
, True);
1873 Append
(Decl_Node
, Decls
);
1874 exit Ident_Loop
when Ident
= Num_Idents
;
1875 Restore_Scan_State
(Scan_State
);
1878 end loop Ident_Loop
;
1881 end P_Identifier_Declarations
;
1883 -------------------------------
1884 -- 3.3.1 Object Declaration --
1885 -------------------------------
1887 -- OBJECT DECLARATION ::=
1888 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1889 -- SUBTYPE_INDICATION [:= EXPRESSION];
1890 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1891 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1892 -- | SINGLE_TASK_DECLARATION
1893 -- | SINGLE_PROTECTED_DECLARATION
1895 -- Cases starting with TASK are parsed by P_Task (9.1)
1896 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1897 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1899 -------------------------------------
1900 -- 3.3.1 Defining Identifier List --
1901 -------------------------------------
1903 -- DEFINING_IDENTIFIER_LIST ::=
1904 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1906 -- Always parsed by the construct in which it appears. See special
1907 -- section on "Handling of Defining Identifier Lists" in this unit.
1909 -------------------------------
1910 -- 3.3.2 Number Declaration --
1911 -------------------------------
1913 -- Parsed by P_Identifier_Declarations (3.3)
1915 -------------------------------------------------------------------------
1916 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
1917 -------------------------------------------------------------------------
1919 -- DERIVED_TYPE_DEFINITION ::=
1920 -- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
1921 -- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
1923 -- PRIVATE_EXTENSION_DECLARATION ::=
1924 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
1925 -- [abstract] [limited | synchronized]
1926 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
1927 -- with private [ASPECT_SPECIFICATIONS];
1929 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
1931 -- The caller has already scanned out the part up to the NEW, and Token
1932 -- either contains Tok_New (or ought to, if it doesn't this procedure
1933 -- will post an appropriate "NEW expected" message).
1935 -- Note: the caller is responsible for filling in the Sloc field of
1936 -- the returned node in the private extension declaration case as
1937 -- well as the stuff relating to the discriminant part.
1939 -- Error recovery: can raise Error_Resync;
1941 function P_Derived_Type_Def_Or_Private_Ext_Decl
return Node_Id
is
1942 Typedef_Node
: Node_Id
;
1943 Typedecl_Node
: Node_Id
;
1944 Not_Null_Present
: Boolean := False;
1947 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
1949 if Ada_Version
< Ada_2005
1950 and then Token
= Tok_Identifier
1951 and then Token_Name
= Name_Interface
1954 ("abstract interface is an Ada 2005 extension");
1955 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1960 if Token
= Tok_Abstract
then
1961 Error_Msg_SC
-- CODEFIX
1962 ("ABSTRACT must come before NEW, not after");
1966 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1967 Set_Null_Exclusion_Present
(Typedef_Node
, Not_Null_Present
);
1968 Set_Subtype_Indication
(Typedef_Node
,
1969 P_Subtype_Indication
(Not_Null_Present
));
1971 -- Ada 2005 (AI-251): Deal with interfaces
1973 if Token
= Tok_And
then
1976 if Ada_Version
< Ada_2005
then
1978 ("abstract interface is an Ada 2005 extension");
1979 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1982 Set_Interface_List
(Typedef_Node
, New_List
);
1985 Append
(P_Qualified_Simple_Name
, Interface_List
(Typedef_Node
));
1986 exit when Token
/= Tok_And
;
1990 if Token
/= Tok_With
then
1991 Error_Msg_SC
("WITH expected");
1996 -- Deal with record extension, note that we assume that a WITH is
1997 -- missing in the case of "type X is new Y record ..." or in the
1998 -- case of "type X is new Y null record".
2000 -- First make sure we don't have an aspect specification. If we do
2001 -- return now, so that our caller can check it (the WITH here is not
2002 -- part of a type extension).
2004 if Aspect_Specifications_Present
then
2005 return Typedef_Node
;
2007 -- OK, not an aspect specification, so continue test for extension
2009 elsif Token
= Tok_With
2010 or else Token
= Tok_Record
2011 or else Token
= Tok_Null
2013 T_With
; -- past WITH or give error message
2015 if Token
= Tok_Limited
then
2016 Error_Msg_SC
("LIMITED keyword not allowed in private extension");
2017 Scan
; -- ignore LIMITED
2020 -- Private extension declaration
2022 if Token
= Tok_Private
then
2023 Scan
; -- past PRIVATE
2025 -- Throw away the type definition node and build the type
2026 -- declaration node. Note the caller must set the Sloc,
2027 -- Discriminant_Specifications, Unknown_Discriminants_Present,
2028 -- and Defined_Identifier fields in the returned node.
2031 Make_Private_Extension_Declaration
(No_Location
,
2032 Defining_Identifier
=> Empty
,
2033 Subtype_Indication
=> Subtype_Indication
(Typedef_Node
),
2034 Abstract_Present
=> Abstract_Present
(Typedef_Node
),
2035 Interface_List
=> Interface_List
(Typedef_Node
));
2037 return Typedecl_Node
;
2039 -- Derived type definition with record extension part
2042 Set_Record_Extension_Part
(Typedef_Node
, P_Record_Definition
);
2043 return Typedef_Node
;
2046 -- Derived type definition with no record extension part
2049 return Typedef_Node
;
2051 end P_Derived_Type_Def_Or_Private_Ext_Decl
;
2053 ---------------------------
2054 -- 3.5 Range Constraint --
2055 ---------------------------
2057 -- RANGE_CONSTRAINT ::= range RANGE
2059 -- The caller has checked that the initial token is RANGE or some
2060 -- misspelling of it, or it may be absent completely (and a message
2061 -- has already been issued).
2063 -- Error recovery: cannot raise Error_Resync
2065 function P_Range_Constraint
return Node_Id
is
2066 Range_Node
: Node_Id
;
2069 Range_Node
:= New_Node
(N_Range_Constraint
, Token_Ptr
);
2071 -- Skip range keyword if present
2073 if Token
= Tok_Range
or else Bad_Spelling_Of
(Tok_Range
) then
2077 Set_Range_Expression
(Range_Node
, P_Range
);
2079 end P_Range_Constraint
;
2086 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2088 -- Note: the range that appears in a membership test is parsed by
2089 -- P_Range_Or_Subtype_Mark (3.5).
2091 -- Error recovery: cannot raise Error_Resync
2093 function P_Range
return Node_Id
is
2094 Expr_Node
: Node_Id
;
2095 Range_Node
: Node_Id
;
2098 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2100 if Expr_Form
= EF_Range_Attr
then
2103 elsif Token
= Tok_Dot_Dot
then
2104 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2105 Set_Low_Bound
(Range_Node
, Expr_Node
);
2107 Expr_Node
:= P_Expression
;
2108 Check_Simple_Expression
(Expr_Node
);
2109 Set_High_Bound
(Range_Node
, Expr_Node
);
2112 -- Anything else is an error
2115 T_Dot_Dot
; -- force missing .. message
2120 ----------------------------------
2121 -- 3.5 P_Range_Or_Subtype_Mark --
2122 ----------------------------------
2125 -- RANGE_ATTRIBUTE_REFERENCE
2126 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2128 -- This routine scans out the range or subtype mark that forms the right
2129 -- operand of a membership test (it is not used in any other contexts, and
2130 -- error messages are specialized with this knowledge in mind).
2132 -- Note: as documented in the Sinfo interface, although the syntax only
2133 -- allows a subtype mark, we in fact allow any simple expression to be
2134 -- returned from this routine. The semantics is responsible for issuing
2135 -- an appropriate message complaining if the argument is not a name.
2136 -- This simplifies the coding and error recovery processing in the
2137 -- parser, and in any case it is preferable not to consider this a
2138 -- syntax error and to continue with the semantic analysis.
2140 -- Error recovery: cannot raise Error_Resync
2142 function P_Range_Or_Subtype_Mark
2143 (Allow_Simple_Expression
: Boolean := False) return Node_Id
2145 Expr_Node
: Node_Id
;
2146 Range_Node
: Node_Id
;
2147 Save_Loc
: Source_Ptr
;
2149 -- Start of processing for P_Range_Or_Subtype_Mark
2152 -- Save location of possible junk parentheses
2154 Save_Loc
:= Token_Ptr
;
2156 -- Scan out either a simple expression or a range (this accepts more
2157 -- than is legal here, but as explained above, we like to allow more
2158 -- with a proper diagnostic, and in the case of a membership operation
2159 -- where sets are allowed, a simple expression is permissible anyway.
2161 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2165 if Expr_Form
= EF_Range_Attr
then
2168 -- Simple_Expression .. Simple_Expression
2170 elsif Token
= Tok_Dot_Dot
then
2171 Check_Simple_Expression
(Expr_Node
);
2172 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2173 Set_Low_Bound
(Range_Node
, Expr_Node
);
2175 Set_High_Bound
(Range_Node
, P_Simple_Expression
);
2178 -- Case of subtype mark (optionally qualified simple name or an
2179 -- attribute whose prefix is an optionally qualified simple name)
2181 elsif Expr_Form
= EF_Simple_Name
2182 or else Nkind
(Expr_Node
) = N_Attribute_Reference
2184 -- Check for error of range constraint after a subtype mark
2186 if Token
= Tok_Range
then
2187 Error_Msg_SC
("range constraint not allowed in membership test");
2191 -- Check for error of DIGITS or DELTA after a subtype mark
2193 elsif Token
= Tok_Digits
or else Token
= Tok_Delta
then
2195 ("accuracy definition not allowed in membership test");
2196 Scan
; -- past DIGITS or DELTA
2199 -- Attribute reference, may or may not be OK, but in any case we
2202 elsif Token
= Tok_Apostrophe
then
2203 return P_Subtype_Mark_Attribute
(Expr_Node
);
2205 -- OK case of simple name, just return it
2211 -- Simple expression case
2213 elsif Expr_Form
= EF_Simple
and then Allow_Simple_Expression
then
2216 -- Here we have some kind of error situation. Check for junk parens
2217 -- then return what we have, caller will deal with other errors.
2220 if Nkind
(Expr_Node
) in N_Subexpr
2221 and then Paren_Count
(Expr_Node
) /= 0
2223 Error_Msg
("|parentheses not allowed for subtype mark", Save_Loc
);
2224 Set_Paren_Count
(Expr_Node
, 0);
2229 end P_Range_Or_Subtype_Mark
;
2231 ----------------------------------------
2232 -- 3.5.1 Enumeration Type Definition --
2233 ----------------------------------------
2235 -- ENUMERATION_TYPE_DEFINITION ::=
2236 -- (ENUMERATION_LITERAL_SPECIFICATION
2237 -- {, ENUMERATION_LITERAL_SPECIFICATION})
2239 -- The caller has already scanned out the TYPE keyword
2241 -- Error recovery: can raise Error_Resync;
2243 function P_Enumeration_Type_Definition
return Node_Id
is
2244 Typedef_Node
: Node_Id
;
2247 Typedef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Token_Ptr
);
2248 Set_Literals
(Typedef_Node
, New_List
);
2253 Append
(P_Enumeration_Literal_Specification
, Literals
(Typedef_Node
));
2254 exit when not Comma_Present
;
2258 return Typedef_Node
;
2259 end P_Enumeration_Type_Definition
;
2261 ----------------------------------------------
2262 -- 3.5.1 Enumeration Literal Specification --
2263 ----------------------------------------------
2265 -- ENUMERATION_LITERAL_SPECIFICATION ::=
2266 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
2268 -- Error recovery: can raise Error_Resync
2270 function P_Enumeration_Literal_Specification
return Node_Id
is
2272 if Token
= Tok_Char_Literal
then
2273 return P_Defining_Character_Literal
;
2275 return P_Defining_Identifier
(C_Comma_Right_Paren
);
2277 end P_Enumeration_Literal_Specification
;
2279 ---------------------------------------
2280 -- 3.5.1 Defining_Character_Literal --
2281 ---------------------------------------
2283 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
2285 -- Error recovery: cannot raise Error_Resync
2287 -- The caller has checked that the current token is a character literal
2289 function P_Defining_Character_Literal
return Node_Id
is
2290 Literal_Node
: Node_Id
;
2292 Literal_Node
:= Token_Node
;
2293 Change_Character_Literal_To_Defining_Character_Literal
(Literal_Node
);
2294 Scan
; -- past character literal
2295 return Literal_Node
;
2296 end P_Defining_Character_Literal
;
2298 ------------------------------------
2299 -- 3.5.4 Integer Type Definition --
2300 ------------------------------------
2302 -- Parsed by P_Type_Declaration (3.2.1)
2304 -------------------------------------------
2305 -- 3.5.4 Signed Integer Type Definition --
2306 -------------------------------------------
2308 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
2309 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2311 -- Normally the initial token on entry is RANGE, but in some
2312 -- error conditions, the range token was missing and control is
2313 -- passed with Token pointing to first token of the first expression.
2315 -- Error recovery: cannot raise Error_Resync
2317 function P_Signed_Integer_Type_Definition
return Node_Id
is
2318 Typedef_Node
: Node_Id
;
2319 Expr_Node
: Node_Id
;
2322 Typedef_Node
:= New_Node
(N_Signed_Integer_Type_Definition
, Token_Ptr
);
2324 if Token
= Tok_Range
then
2328 Expr_Node
:= P_Expression_Or_Range_Attribute
;
2330 -- Range case (not permitted by the grammar, this is surprising but
2331 -- the grammar in the RM is as quoted above, and does not allow Range).
2333 if Expr_Form
= EF_Range_Attr
then
2335 ("Range attribute not allowed here, use First .. Last", Expr_Node
);
2336 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2337 Set_Attribute_Name
(Expr_Node
, Name_First
);
2338 Set_High_Bound
(Typedef_Node
, Copy_Separate_Tree
(Expr_Node
));
2339 Set_Attribute_Name
(High_Bound
(Typedef_Node
), Name_Last
);
2341 -- Normal case of explicit range
2344 Check_Simple_Expression
(Expr_Node
);
2345 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2347 Expr_Node
:= P_Expression
;
2348 Check_Simple_Expression
(Expr_Node
);
2349 Set_High_Bound
(Typedef_Node
, Expr_Node
);
2352 return Typedef_Node
;
2353 end P_Signed_Integer_Type_Definition
;
2355 ------------------------------------
2356 -- 3.5.4 Modular Type Definition --
2357 ------------------------------------
2359 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
2361 -- The caller has checked that the initial token is MOD
2363 -- Error recovery: cannot raise Error_Resync
2365 function P_Modular_Type_Definition
return Node_Id
is
2366 Typedef_Node
: Node_Id
;
2369 if Ada_Version
= Ada_83
then
2370 Error_Msg_SC
("(Ada 83): modular types not allowed");
2373 Typedef_Node
:= New_Node
(N_Modular_Type_Definition
, Token_Ptr
);
2375 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2377 -- Handle mod L..R cleanly
2379 if Token
= Tok_Dot_Dot
then
2380 Error_Msg_SC
("range not allowed for modular type");
2382 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2385 return Typedef_Node
;
2386 end P_Modular_Type_Definition
;
2388 ---------------------------------
2389 -- 3.5.6 Real Type Definition --
2390 ---------------------------------
2392 -- Parsed by P_Type_Declaration (3.2.1)
2394 --------------------------------------
2395 -- 3.5.7 Floating Point Definition --
2396 --------------------------------------
2398 -- FLOATING_POINT_DEFINITION ::=
2399 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2401 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
2403 -- The caller has checked that the initial token is DIGITS
2405 -- Error recovery: cannot raise Error_Resync
2407 function P_Floating_Point_Definition
return Node_Id
is
2408 Digits_Loc
: constant Source_Ptr
:= Token_Ptr
;
2410 Expr_Node
: Node_Id
;
2413 Scan
; -- past DIGITS
2414 Expr_Node
:= P_Expression_No_Right_Paren
;
2415 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2417 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
2419 if Token
= Tok_Delta
then
2420 Error_Msg_SC
-- CODEFIX
2421 ("|DELTA must come before DIGITS");
2422 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Digits_Loc
);
2424 Set_Delta_Expression
(Def_Node
, P_Expression_No_Right_Paren
);
2426 -- OK floating-point definition
2429 Def_Node
:= New_Node
(N_Floating_Point_Definition
, Digits_Loc
);
2432 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2433 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2435 end P_Floating_Point_Definition
;
2437 -------------------------------------
2438 -- 3.5.7 Real Range Specification --
2439 -------------------------------------
2441 -- REAL_RANGE_SPECIFICATION ::=
2442 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2444 -- Error recovery: cannot raise Error_Resync
2446 function P_Real_Range_Specification_Opt
return Node_Id
is
2447 Specification_Node
: Node_Id
;
2448 Expr_Node
: Node_Id
;
2451 if Token
= Tok_Range
then
2452 Specification_Node
:=
2453 New_Node
(N_Real_Range_Specification
, Token_Ptr
);
2455 Expr_Node
:= P_Expression_No_Right_Paren
;
2456 Check_Simple_Expression
(Expr_Node
);
2457 Set_Low_Bound
(Specification_Node
, Expr_Node
);
2459 Expr_Node
:= P_Expression_No_Right_Paren
;
2460 Check_Simple_Expression
(Expr_Node
);
2461 Set_High_Bound
(Specification_Node
, Expr_Node
);
2462 return Specification_Node
;
2466 end P_Real_Range_Specification_Opt
;
2468 -----------------------------------
2469 -- 3.5.9 Fixed Point Definition --
2470 -----------------------------------
2472 -- FIXED_POINT_DEFINITION ::=
2473 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
2475 -- ORDINARY_FIXED_POINT_DEFINITION ::=
2476 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
2478 -- DECIMAL_FIXED_POINT_DEFINITION ::=
2479 -- delta static_EXPRESSION
2480 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2482 -- The caller has checked that the initial token is DELTA
2484 -- Error recovery: cannot raise Error_Resync
2486 function P_Fixed_Point_Definition
return Node_Id
is
2487 Delta_Node
: Node_Id
;
2488 Delta_Loc
: Source_Ptr
;
2490 Expr_Node
: Node_Id
;
2493 Delta_Loc
:= Token_Ptr
;
2495 Delta_Node
:= P_Expression_No_Right_Paren
;
2496 Check_Simple_Expression_In_Ada_83
(Delta_Node
);
2498 if Token
= Tok_Digits
then
2499 if Ada_Version
= Ada_83
then
2500 Error_Msg_SC
("(Ada 83) decimal fixed type not allowed!");
2503 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Delta_Loc
);
2504 Scan
; -- past DIGITS
2505 Expr_Node
:= P_Expression_No_Right_Paren
;
2506 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2507 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2510 Def_Node
:= New_Node
(N_Ordinary_Fixed_Point_Definition
, Delta_Loc
);
2512 -- Range is required in ordinary fixed point case
2514 if Token
/= Tok_Range
then
2515 Error_Msg_AP
("range must be given for fixed-point type");
2520 Set_Delta_Expression
(Def_Node
, Delta_Node
);
2521 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2523 end P_Fixed_Point_Definition
;
2525 --------------------------------------------
2526 -- 3.5.9 Ordinary Fixed Point Definition --
2527 --------------------------------------------
2529 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2531 -------------------------------------------
2532 -- 3.5.9 Decimal Fixed Point Definition --
2533 -------------------------------------------
2535 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2537 ------------------------------
2538 -- 3.5.9 Digits Constraint --
2539 ------------------------------
2541 -- DIGITS_CONSTRAINT ::=
2542 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2544 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2546 -- The caller has checked that the initial token is DIGITS
2548 function P_Digits_Constraint
return Node_Id
is
2549 Constraint_Node
: Node_Id
;
2550 Expr_Node
: Node_Id
;
2553 Constraint_Node
:= New_Node
(N_Digits_Constraint
, Token_Ptr
);
2554 Scan
; -- past DIGITS
2555 Expr_Node
:= P_Expression
;
2556 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2557 Set_Digits_Expression
(Constraint_Node
, Expr_Node
);
2559 if Token
= Tok_Range
then
2560 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2563 return Constraint_Node
;
2564 end P_Digits_Constraint
;
2566 -----------------------------
2567 -- 3.5.9 Delta Constraint --
2568 -----------------------------
2570 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2572 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2574 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2575 -- (also true in formal modes).
2577 -- The caller has checked that the initial token is DELTA
2579 -- Error recovery: cannot raise Error_Resync
2581 function P_Delta_Constraint
return Node_Id
is
2582 Constraint_Node
: Node_Id
;
2583 Expr_Node
: Node_Id
;
2586 Constraint_Node
:= New_Node
(N_Delta_Constraint
, Token_Ptr
);
2588 Expr_Node
:= P_Expression
;
2589 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2591 Set_Delta_Expression
(Constraint_Node
, Expr_Node
);
2593 if Token
= Tok_Range
then
2594 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2597 return Constraint_Node
;
2598 end P_Delta_Constraint
;
2600 --------------------------------
2601 -- 3.6 Array Type Definition --
2602 --------------------------------
2604 -- ARRAY_TYPE_DEFINITION ::=
2605 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2607 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2608 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2609 -- COMPONENT_DEFINITION
2611 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2613 -- CONSTRAINED_ARRAY_DEFINITION ::=
2614 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2615 -- COMPONENT_DEFINITION
2617 -- DISCRETE_SUBTYPE_DEFINITION ::=
2618 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2620 -- COMPONENT_DEFINITION ::=
2621 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2623 -- The caller has checked that the initial token is ARRAY
2625 -- Error recovery: can raise Error_Resync
2627 function P_Array_Type_Definition
return Node_Id
is
2628 Array_Loc
: Source_Ptr
;
2629 CompDef_Node
: Node_Id
;
2631 Not_Null_Present
: Boolean := False;
2632 Subs_List
: List_Id
;
2633 Scan_State
: Saved_Scan_State
;
2634 Aliased_Present
: Boolean := False;
2637 Array_Loc
:= Token_Ptr
;
2639 Subs_List
:= New_List
;
2642 -- It's quite tricky to disentangle these two possibilities, so we do
2643 -- a prescan to determine which case we have and then reset the scan.
2644 -- The prescan skips past possible subtype mark tokens.
2646 Save_Scan_State
(Scan_State
); -- just after paren
2648 while Token
in Token_Class_Desig
or else
2649 Token
= Tok_Dot
or else
2650 Token
= Tok_Apostrophe
-- because of 'BASE, 'CLASS
2655 -- If we end up on RANGE <> then we have the unconstrained case. We
2656 -- will also allow the RANGE to be omitted, just to improve error
2657 -- handling for a case like array (integer <>) of integer;
2659 Scan
; -- past possible RANGE or <>
2661 if (Prev_Token
= Tok_Range
and then Token
= Tok_Box
) or else
2662 Prev_Token
= Tok_Box
2664 Def_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Array_Loc
);
2665 Restore_Scan_State
(Scan_State
); -- to first subtype mark
2668 Append
(P_Subtype_Mark_Resync
, Subs_List
);
2671 exit when Token
= Tok_Right_Paren
or else Token
= Tok_Of
;
2675 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2678 Def_Node
:= New_Node
(N_Constrained_Array_Definition
, Array_Loc
);
2679 Restore_Scan_State
(Scan_State
); -- to first discrete range
2682 Append
(P_Discrete_Subtype_Definition
, Subs_List
);
2683 exit when not Comma_Present
;
2686 Set_Discrete_Subtype_Definitions
(Def_Node
, Subs_List
);
2692 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
2694 if Token_Name
= Name_Aliased
then
2695 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
2698 if Token
= Tok_Aliased
then
2699 Aliased_Present
:= True;
2700 Scan
; -- past ALIASED
2703 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
2705 -- Ada 2005 (AI-230): Access Definition case
2707 if Token
= Tok_Access
then
2708 if Ada_Version
< Ada_2005
then
2710 ("generalized use of anonymous access types " &
2711 "is an Ada 2005 extension");
2712 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2715 -- AI95-406 makes "aliased" legal (and useless) in this context so
2716 -- followintg code which used to be needed is commented out.
2718 -- if Aliased_Present then
2719 -- Error_Msg_SP ("ALIASED not allowed here");
2722 Set_Subtype_Indication
(CompDef_Node
, Empty
);
2723 Set_Aliased_Present
(CompDef_Node
, False);
2724 Set_Access_Definition
(CompDef_Node
,
2725 P_Access_Definition
(Not_Null_Present
));
2728 Set_Access_Definition
(CompDef_Node
, Empty
);
2729 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2730 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
2731 Set_Subtype_Indication
(CompDef_Node
,
2732 P_Subtype_Indication
(Not_Null_Present
));
2735 Set_Component_Definition
(Def_Node
, CompDef_Node
);
2738 end P_Array_Type_Definition
;
2740 -----------------------------------------
2741 -- 3.6 Unconstrained Array Definition --
2742 -----------------------------------------
2744 -- Parsed by P_Array_Type_Definition (3.6)
2746 ---------------------------------------
2747 -- 3.6 Constrained Array Definition --
2748 ---------------------------------------
2750 -- Parsed by P_Array_Type_Definition (3.6)
2752 --------------------------------------
2753 -- 3.6 Discrete Subtype Definition --
2754 --------------------------------------
2756 -- DISCRETE_SUBTYPE_DEFINITION ::=
2757 -- discrete_SUBTYPE_INDICATION | RANGE
2759 -- Note: the discrete subtype definition appearing in a constrained
2760 -- array definition is parsed by P_Array_Type_Definition (3.6)
2762 -- Error recovery: cannot raise Error_Resync
2764 function P_Discrete_Subtype_Definition
return Node_Id
is
2766 -- The syntax of a discrete subtype definition is identical to that
2767 -- of a discrete range, so we simply share the same parsing code.
2769 return P_Discrete_Range
;
2770 end P_Discrete_Subtype_Definition
;
2772 -------------------------------
2773 -- 3.6 Component Definition --
2774 -------------------------------
2776 -- For the array case, parsed by P_Array_Type_Definition (3.6)
2777 -- For the record case, parsed by P_Component_Declaration (3.8)
2779 -----------------------------
2780 -- 3.6.1 Index Constraint --
2781 -----------------------------
2783 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2785 ---------------------------
2786 -- 3.6.1 Discrete Range --
2787 ---------------------------
2789 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
2791 -- The possible forms for a discrete range are:
2793 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
2794 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
2795 -- Range_Attribute (RANGE, 3.5)
2796 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
2798 -- Error recovery: cannot raise Error_Resync
2800 function P_Discrete_Range
return Node_Id
is
2801 Expr_Node
: Node_Id
;
2802 Range_Node
: Node_Id
;
2805 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2807 if Expr_Form
= EF_Range_Attr
then
2810 elsif Token
= Tok_Range
then
2811 if Expr_Form
/= EF_Simple_Name
then
2812 Error_Msg_SC
("range must be preceded by subtype mark");
2815 return P_Subtype_Indication
(Expr_Node
);
2817 -- Check Expression .. Expression case
2819 elsif Token
= Tok_Dot_Dot
then
2820 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2821 Set_Low_Bound
(Range_Node
, Expr_Node
);
2823 Expr_Node
:= P_Expression
;
2824 Check_Simple_Expression
(Expr_Node
);
2825 Set_High_Bound
(Range_Node
, Expr_Node
);
2828 -- Otherwise we must have a subtype mark, or an Ada 2012 iterator
2830 elsif Expr_Form
= EF_Simple_Name
then
2833 -- The domain of iteration must be a name. Semantics will determine that
2834 -- the expression has the proper form.
2836 elsif Ada_Version
>= Ada_2012
then
2839 -- If incorrect, complain that we expect ..
2845 end P_Discrete_Range
;
2847 ----------------------------
2848 -- 3.7 Discriminant Part --
2849 ----------------------------
2851 -- DISCRIMINANT_PART ::=
2852 -- UNKNOWN_DISCRIMINANT_PART
2853 -- | KNOWN_DISCRIMINANT_PART
2855 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
2856 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
2858 ------------------------------------
2859 -- 3.7 Unknown Discriminant Part --
2860 ------------------------------------
2862 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
2864 -- If no unknown discriminant part is present, then False is returned,
2865 -- otherwise the unknown discriminant is scanned out and True is returned.
2867 -- Error recovery: cannot raise Error_Resync
2869 function P_Unknown_Discriminant_Part_Opt
return Boolean is
2870 Scan_State
: Saved_Scan_State
;
2873 -- If <> right now, then this is missing left paren
2875 if Token
= Tok_Box
then
2878 -- If not <> or left paren, then definitely no box
2880 elsif Token
/= Tok_Left_Paren
then
2883 -- Left paren, so might be a box after it
2886 Save_Scan_State
(Scan_State
);
2887 Scan
; -- past the left paren
2889 if Token
/= Tok_Box
then
2890 Restore_Scan_State
(Scan_State
);
2895 -- We are now pointing to the box
2897 if Ada_Version
= Ada_83
then
2898 Error_Msg_SC
("(Ada 83) unknown discriminant not allowed!");
2901 Scan
; -- past the box
2902 U_Right_Paren
; -- must be followed by right paren
2904 end P_Unknown_Discriminant_Part_Opt
;
2906 ----------------------------------
2907 -- 3.7 Known Discriminant Part --
2908 ----------------------------------
2910 -- KNOWN_DISCRIMINANT_PART ::=
2911 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
2913 -- DISCRIMINANT_SPECIFICATION ::=
2914 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
2915 -- [:= DEFAULT_EXPRESSION]
2916 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
2917 -- [:= DEFAULT_EXPRESSION]
2919 -- If no known discriminant part is present, then No_List is returned
2921 -- Error recovery: cannot raise Error_Resync
2923 function P_Known_Discriminant_Part_Opt
return List_Id
is
2924 Specification_Node
: Node_Id
;
2925 Specification_List
: List_Id
;
2926 Ident_Sloc
: Source_Ptr
;
2927 Scan_State
: Saved_Scan_State
;
2929 Not_Null_Present
: Boolean;
2932 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
2933 -- This array holds the list of defining identifiers. The upper bound
2934 -- of 4096 is intended to be essentially infinite, and we do not even
2935 -- bother to check for it being exceeded.
2938 if Token
= Tok_Left_Paren
then
2939 Specification_List
:= New_List
;
2941 P_Pragmas_Misplaced
;
2943 Specification_Loop
: loop
2945 Ident_Sloc
:= Token_Ptr
;
2946 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
2949 while Comma_Present
loop
2950 Num_Idents
:= Num_Idents
+ 1;
2951 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
2954 -- If there are multiple identifiers, we repeatedly scan the
2955 -- type and initialization expression information by resetting
2956 -- the scan pointer (so that we get completely separate trees
2957 -- for each occurrence).
2959 if Num_Idents
> 1 then
2960 Save_Scan_State
(Scan_State
);
2965 -- Loop through defining identifiers in list
2969 Specification_Node
:=
2970 New_Node
(N_Discriminant_Specification
, Ident_Sloc
);
2971 Set_Defining_Identifier
(Specification_Node
, Idents
(Ident
));
2972 Not_Null_Present
:= -- Ada 2005 (AI-231, AI-447)
2973 P_Null_Exclusion
(Allow_Anonymous_In_95
=> True);
2975 if Token
= Tok_Access
then
2976 if Ada_Version
= Ada_83
then
2978 ("(Ada 83) access discriminant not allowed!");
2981 Set_Discriminant_Type
2982 (Specification_Node
,
2983 P_Access_Definition
(Not_Null_Present
));
2986 Set_Discriminant_Type
2987 (Specification_Node
, P_Subtype_Mark
);
2989 Set_Null_Exclusion_Present
-- Ada 2005 (AI-231)
2990 (Specification_Node
, Not_Null_Present
);
2994 (Specification_Node
, Init_Expr_Opt
(True));
2997 Set_Prev_Ids
(Specification_Node
, True);
3000 if Ident
< Num_Idents
then
3001 Set_More_Ids
(Specification_Node
, True);
3004 Append
(Specification_Node
, Specification_List
);
3005 exit Ident_Loop
when Ident
= Num_Idents
;
3007 Restore_Scan_State
(Scan_State
);
3009 end loop Ident_Loop
;
3011 exit Specification_Loop
when Token
/= Tok_Semicolon
;
3013 P_Pragmas_Misplaced
;
3014 end loop Specification_Loop
;
3017 return Specification_List
;
3022 end P_Known_Discriminant_Part_Opt
;
3024 -------------------------------------
3025 -- 3.7 Discriminant Specification --
3026 -------------------------------------
3028 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
3030 -----------------------------
3031 -- 3.7 Default Expression --
3032 -----------------------------
3034 -- Always parsed (simply as an Expression) by the parent construct
3036 ------------------------------------
3037 -- 3.7.1 Discriminant Constraint --
3038 ------------------------------------
3040 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
3042 --------------------------------------------------------
3043 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
3044 --------------------------------------------------------
3046 -- DISCRIMINANT_CONSTRAINT ::=
3047 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
3049 -- DISCRIMINANT_ASSOCIATION ::=
3050 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3053 -- This routine parses either an index or a discriminant constraint. As
3054 -- is clear from the above grammar, it is often possible to clearly
3055 -- determine which of the two possibilities we have, but there are
3056 -- cases (those in which we have a series of expressions of the same
3057 -- syntactic form as subtype indications), where we cannot tell. Since
3058 -- this means that in any case the semantic phase has to distinguish
3059 -- between the two, there is not much point in the parser trying to
3060 -- distinguish even those cases where the difference is clear. In any
3061 -- case, if we have a situation like:
3063 -- (A => 123, 235 .. 500)
3065 -- it is not clear which of the two items is the wrong one, better to
3066 -- let the semantic phase give a clear message. Consequently, this
3067 -- routine in general returns a list of items which can be either
3068 -- discrete ranges or discriminant associations.
3070 -- The caller has checked that the initial token is a left paren
3072 -- Error recovery: can raise Error_Resync
3074 function P_Index_Or_Discriminant_Constraint
return Node_Id
is
3075 Scan_State
: Saved_Scan_State
;
3076 Constr_Node
: Node_Id
;
3077 Constr_List
: List_Id
;
3078 Expr_Node
: Node_Id
;
3079 Result_Node
: Node_Id
;
3082 Result_Node
:= New_Node
(N_Index_Or_Discriminant_Constraint
, Token_Ptr
);
3084 Constr_List
:= New_List
;
3085 Set_Constraints
(Result_Node
, Constr_List
);
3087 -- The two syntactic forms are a little mixed up, so what we are doing
3088 -- here is looking at the first entry to determine which case we have
3090 -- A discriminant constraint is a list of discriminant associations,
3091 -- which have one of the following possible forms:
3095 -- Id | Id | .. | Id => Expression
3097 -- An index constraint is a list of discrete ranges which have one
3098 -- of the following possible forms:
3101 -- Subtype_Mark range Range
3103 -- Simple_Expression .. Simple_Expression
3105 -- Loop through discriminants in list
3108 -- Check cases of Id => Expression or Id | Id => Expression
3110 if Token
= Tok_Identifier
then
3111 Save_Scan_State
(Scan_State
); -- at Id
3114 if Token
= Tok_Arrow
or else Token
= Tok_Vertical_Bar
then
3115 Restore_Scan_State
(Scan_State
); -- to Id
3116 Append
(P_Discriminant_Association
, Constr_List
);
3119 Restore_Scan_State
(Scan_State
); -- to Id
3123 -- Otherwise scan out an expression and see what we have got
3125 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3127 if Expr_Form
= EF_Range_Attr
then
3128 Append
(Expr_Node
, Constr_List
);
3130 elsif Token
= Tok_Range
then
3131 if Expr_Form
/= EF_Simple_Name
then
3132 Error_Msg_SC
("subtype mark required before RANGE");
3135 Append
(P_Subtype_Indication
(Expr_Node
), Constr_List
);
3138 -- Check Simple_Expression .. Simple_Expression case
3140 elsif Token
= Tok_Dot_Dot
then
3141 Check_Simple_Expression
(Expr_Node
);
3142 Constr_Node
:= New_Node
(N_Range
, Token_Ptr
);
3143 Set_Low_Bound
(Constr_Node
, Expr_Node
);
3145 Expr_Node
:= P_Expression
;
3146 Check_Simple_Expression
(Expr_Node
);
3147 Set_High_Bound
(Constr_Node
, Expr_Node
);
3148 Append
(Constr_Node
, Constr_List
);
3151 -- Case of an expression which could be either form
3154 Append
(Expr_Node
, Constr_List
);
3158 -- Here with a single entry scanned
3161 exit when not Comma_Present
;
3167 end P_Index_Or_Discriminant_Constraint
;
3169 -------------------------------------
3170 -- 3.7.1 Discriminant Association --
3171 -------------------------------------
3173 -- DISCRIMINANT_ASSOCIATION ::=
3174 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3177 -- This routine is used only when the name list is present and the caller
3178 -- has already checked this (by scanning ahead and repositioning the
3181 -- Error_Recovery: cannot raise Error_Resync;
3183 function P_Discriminant_Association
return Node_Id
is
3184 Discr_Node
: Node_Id
;
3185 Names_List
: List_Id
;
3186 Ident_Sloc
: Source_Ptr
;
3189 Ident_Sloc
:= Token_Ptr
;
3190 Names_List
:= New_List
;
3193 Append
(P_Identifier
(C_Vertical_Bar_Arrow
), Names_List
);
3194 exit when Token
/= Tok_Vertical_Bar
;
3198 Discr_Node
:= New_Node
(N_Discriminant_Association
, Ident_Sloc
);
3199 Set_Selector_Names
(Discr_Node
, Names_List
);
3201 Set_Expression
(Discr_Node
, P_Expression
);
3203 end P_Discriminant_Association
;
3205 ---------------------------------
3206 -- 3.8 Record Type Definition --
3207 ---------------------------------
3209 -- RECORD_TYPE_DEFINITION ::=
3210 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3212 -- There is no node in the tree for a record type definition. Instead
3213 -- a record definition node appears, with possible Abstract_Present,
3214 -- Tagged_Present, and Limited_Present flags set appropriately.
3216 ----------------------------
3217 -- 3.8 Record Definition --
3218 ----------------------------
3220 -- RECORD_DEFINITION ::=
3226 -- Note: in the case where a record definition node is used to represent
3227 -- a record type definition, the caller sets the Tagged_Present and
3228 -- Limited_Present flags in the resulting N_Record_Definition node as
3231 -- Note that the RECORD token at the start may be missing in certain
3232 -- error situations, so this function is expected to post the error
3234 -- Error recovery: can raise Error_Resync
3236 function P_Record_Definition
return Node_Id
is
3240 Inside_Record_Definition
:= True;
3241 Rec_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3245 if Token
= Tok_Null
then
3248 Set_Null_Present
(Rec_Node
, True);
3250 -- Catch incomplete declaration to prevent cascaded errors, see
3251 -- ACATS B393002 for an example.
3253 elsif Token
= Tok_Semicolon
then
3254 Error_Msg_AP
("missing record definition");
3256 -- Case starting with RECORD keyword. Build scope stack entry. For the
3257 -- column, we use the first non-blank character on the line, to deal
3258 -- with situations such as:
3264 -- which is not official RM indentation, but is not uncommon usage, and
3265 -- in particular is standard GNAT coding style, so handle it nicely.
3269 Scope
.Table
(Scope
.Last
).Etyp
:= E_Record
;
3270 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3271 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3272 Scope
.Table
(Scope
.Last
).Labl
:= Error
;
3273 Scope
.Table
(Scope
.Last
).Junk
:= (Token
/= Tok_Record
);
3277 Set_Component_List
(Rec_Node
, P_Component_List
);
3280 exit when Check_End
;
3281 Discard_Junk_Node
(P_Component_List
);
3285 Inside_Record_Definition
:= False;
3287 end P_Record_Definition
;
3289 -------------------------
3290 -- 3.8 Component List --
3291 -------------------------
3293 -- COMPONENT_LIST ::=
3294 -- COMPONENT_ITEM {COMPONENT_ITEM}
3295 -- | {COMPONENT_ITEM} VARIANT_PART
3298 -- Error recovery: cannot raise Error_Resync
3300 function P_Component_List
return Node_Id
is
3301 Component_List_Node
: Node_Id
;
3302 Decls_List
: List_Id
;
3303 Scan_State
: Saved_Scan_State
;
3304 Null_Loc
: Source_Ptr
;
3307 Component_List_Node
:= New_Node
(N_Component_List
, Token_Ptr
);
3308 Decls_List
:= New_List
;
3312 if Token
= Tok_Null
then
3313 Null_Loc
:= Token_Ptr
;
3316 P_Pragmas_Opt
(Decls_List
);
3318 -- If we have an END or WHEN now, everything is fine, otherwise we
3319 -- complain about the null, ignore it, and scan for more components.
3321 if Token
= Tok_End
or else Token
= Tok_When
then
3322 Set_Null_Present
(Component_List_Node
, True);
3323 return Component_List_Node
;
3325 Error_Msg
("NULL component only allowed in null record", Null_Loc
);
3329 -- Scan components for non-null record
3331 P_Pragmas_Opt
(Decls_List
);
3333 if Token
/= Tok_Case
then
3334 Component_Scan_Loop
: loop
3335 P_Component_Items
(Decls_List
);
3336 P_Pragmas_Opt
(Decls_List
);
3338 exit Component_Scan_Loop
when Token
= Tok_End
3339 or else Token
= Tok_Case
3340 or else Token
= Tok_When
;
3342 -- We are done if we do not have an identifier. However, if we
3343 -- have a misspelled reserved identifier that is in a column to
3344 -- the right of the record definition, we will treat it as an
3345 -- identifier. It turns out to be too dangerous in practice to
3346 -- accept such a mis-spelled identifier which does not have this
3347 -- additional clue that confirms the incorrect spelling.
3349 if Token
/= Tok_Identifier
then
3350 if Start_Column
> Scope
.Table
(Scope
.Last
).Ecol
3351 and then Is_Reserved_Identifier
3353 Save_Scan_State
(Scan_State
); -- at reserved id
3354 Scan
; -- possible reserved id
3356 if Token
= Tok_Comma
or else Token
= Tok_Colon
then
3357 Restore_Scan_State
(Scan_State
);
3358 Scan_Reserved_Identifier
(Force_Msg
=> True);
3360 -- Note reserved identifier used as field name after all
3361 -- because not followed by colon or comma.
3364 Restore_Scan_State
(Scan_State
);
3365 exit Component_Scan_Loop
;
3368 -- Non-identifier that definitely was not reserved id
3371 exit Component_Scan_Loop
;
3374 end loop Component_Scan_Loop
;
3377 if Token
= Tok_Case
then
3378 Set_Variant_Part
(Component_List_Node
, P_Variant_Part
);
3380 -- Check for junk after variant part
3382 if Token
= Tok_Identifier
then
3383 Save_Scan_State
(Scan_State
);
3384 Scan
; -- past identifier
3386 if Token
= Tok_Colon
then
3387 Restore_Scan_State
(Scan_State
);
3388 Error_Msg_SC
("component may not follow variant part");
3389 Discard_Junk_Node
(P_Component_List
);
3391 elsif Token
= Tok_Case
then
3392 Restore_Scan_State
(Scan_State
);
3393 Error_Msg_SC
("only one variant part allowed in a record");
3394 Discard_Junk_Node
(P_Component_List
);
3397 Restore_Scan_State
(Scan_State
);
3402 Set_Component_Items
(Component_List_Node
, Decls_List
);
3403 return Component_List_Node
;
3404 end P_Component_List
;
3406 -------------------------
3407 -- 3.8 Component Item --
3408 -------------------------
3410 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3412 -- COMPONENT_DECLARATION ::=
3413 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3414 -- [:= DEFAULT_EXPRESSION]
3415 -- [ASPECT_SPECIFICATIONS];
3417 -- COMPONENT_DEFINITION ::=
3418 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3420 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3421 -- the scan is positioned past the following semicolon.
3423 -- Note: we do not yet allow representation clauses to appear as component
3424 -- items, do we need to add this capability sometime in the future ???
3426 procedure P_Component_Items
(Decls
: List_Id
) is
3427 Aliased_Present
: Boolean := False;
3428 CompDef_Node
: Node_Id
;
3429 Decl_Node
: Node_Id
;
3430 Scan_State
: Saved_Scan_State
;
3431 Not_Null_Present
: Boolean := False;
3434 Ident_Sloc
: Source_Ptr
;
3436 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3437 -- This array holds the list of defining identifiers. The upper bound
3438 -- of 4096 is intended to be essentially infinite, and we do not even
3439 -- bother to check for it being exceeded.
3442 if Token
/= Tok_Identifier
then
3443 Error_Msg_SC
("component declaration expected");
3444 Resync_Past_Semicolon
;
3448 Ident_Sloc
:= Token_Ptr
;
3449 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3452 while Comma_Present
loop
3453 Num_Idents
:= Num_Idents
+ 1;
3454 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3457 -- If there are multiple identifiers, we repeatedly scan the
3458 -- type and initialization expression information by resetting
3459 -- the scan pointer (so that we get completely separate trees
3460 -- for each occurrence).
3462 if Num_Idents
> 1 then
3463 Save_Scan_State
(Scan_State
);
3468 -- Loop through defining identifiers in list
3473 -- The following block is present to catch Error_Resync
3474 -- which causes the parse to be reset past the semicolon
3477 Decl_Node
:= New_Node
(N_Component_Declaration
, Ident_Sloc
);
3478 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
3480 if Token
= Tok_Constant
then
3481 Error_Msg_SC
("constant components are not permitted");
3485 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
3487 if Token_Name
= Name_Aliased
then
3488 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
3491 if Token
= Tok_Aliased
then
3492 Aliased_Present
:= True;
3493 Scan
; -- past ALIASED
3496 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
3498 -- Ada 2005 (AI-230): Access Definition case
3500 if Token
= Tok_Access
then
3501 if Ada_Version
< Ada_2005
then
3503 ("generalized use of anonymous access types " &
3504 "is an Ada 2005 extension");
3505 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3508 -- AI95-406 makes "aliased" legal (and useless) here, so the
3509 -- following code which used to be required is commented out.
3511 -- if Aliased_Present then
3512 -- Error_Msg_SP ("ALIASED not allowed here");
3515 Set_Subtype_Indication
(CompDef_Node
, Empty
);
3516 Set_Aliased_Present
(CompDef_Node
, False);
3517 Set_Access_Definition
(CompDef_Node
,
3518 P_Access_Definition
(Not_Null_Present
));
3521 Set_Access_Definition
(CompDef_Node
, Empty
);
3522 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
3523 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
3525 if Token
= Tok_Array
then
3526 Error_Msg_SC
("anonymous arrays not allowed as components");
3530 Set_Subtype_Indication
(CompDef_Node
,
3531 P_Subtype_Indication
(Not_Null_Present
));
3534 Set_Component_Definition
(Decl_Node
, CompDef_Node
);
3535 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
3538 Set_Prev_Ids
(Decl_Node
, True);
3541 if Ident
< Num_Idents
then
3542 Set_More_Ids
(Decl_Node
, True);
3545 Append
(Decl_Node
, Decls
);
3548 when Error_Resync
=>
3549 if Token
/= Tok_End
then
3550 Resync_Past_Semicolon
;
3554 exit Ident_Loop
when Ident
= Num_Idents
;
3556 Restore_Scan_State
(Scan_State
);
3558 end loop Ident_Loop
;
3560 P_Aspect_Specifications
(Decl_Node
);
3561 end P_Component_Items
;
3563 --------------------------------
3564 -- 3.8 Component Declaration --
3565 --------------------------------
3567 -- Parsed by P_Component_Items (3.8)
3569 -------------------------
3570 -- 3.8.1 Variant Part --
3571 -------------------------
3574 -- case discriminant_DIRECT_NAME is
3579 -- The caller has checked that the initial token is CASE
3581 -- Error recovery: cannot raise Error_Resync
3583 function P_Variant_Part
return Node_Id
is
3584 Variant_Part_Node
: Node_Id
;
3585 Variants_List
: List_Id
;
3586 Case_Node
: Node_Id
;
3589 Variant_Part_Node
:= New_Node
(N_Variant_Part
, Token_Ptr
);
3591 Scope
.Table
(Scope
.Last
).Etyp
:= E_Case
;
3592 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3593 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3596 Case_Node
:= P_Expression
;
3597 Set_Name
(Variant_Part_Node
, Case_Node
);
3599 if Nkind
(Case_Node
) /= N_Identifier
then
3600 Set_Name
(Variant_Part_Node
, Error
);
3601 Error_Msg
("discriminant name expected", Sloc
(Case_Node
));
3603 elsif Paren_Count
(Case_Node
) /= 0 then
3605 ("|discriminant name may not be parenthesized",
3607 Set_Paren_Count
(Case_Node
, 0);
3611 Variants_List
:= New_List
;
3612 P_Pragmas_Opt
(Variants_List
);
3614 -- Test missing variant
3616 if Token
= Tok_End
then
3617 Error_Msg_BC
("WHEN expected (must have at least one variant)");
3619 Append
(P_Variant
, Variants_List
);
3622 -- Loop through variants, note that we allow if in place of when,
3623 -- this error will be detected and handled in P_Variant.
3626 P_Pragmas_Opt
(Variants_List
);
3628 if Token
/= Tok_When
3629 and then Token
/= Tok_If
3630 and then Token
/= Tok_Others
3632 exit when Check_End
;
3635 Append
(P_Variant
, Variants_List
);
3638 Set_Variants
(Variant_Part_Node
, Variants_List
);
3639 return Variant_Part_Node
;
3642 --------------------
3644 --------------------
3647 -- when DISCRETE_CHOICE_LIST =>
3650 -- Error recovery: cannot raise Error_Resync
3652 -- The initial token on entry is either WHEN, IF or OTHERS
3654 function P_Variant
return Node_Id
is
3655 Variant_Node
: Node_Id
;
3658 -- Special check to recover nicely from use of IF in place of WHEN
3660 if Token
= Tok_If
then
3667 Variant_Node
:= New_Node
(N_Variant
, Prev_Token_Ptr
);
3668 Set_Discrete_Choices
(Variant_Node
, P_Discrete_Choice_List
);
3670 Set_Component_List
(Variant_Node
, P_Component_List
);
3671 return Variant_Node
;
3674 ---------------------------------
3675 -- 3.8.1 Discrete Choice List --
3676 ---------------------------------
3678 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3680 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3682 -- Note: in Ada 83, the expression must be a simple expression
3684 -- Error recovery: cannot raise Error_Resync
3686 function P_Discrete_Choice_List
return List_Id
is
3688 Expr_Node
: Node_Id
;
3689 Choice_Node
: Node_Id
;
3692 Choices
:= New_List
;
3694 if Token
= Tok_Others
then
3695 Append
(New_Node
(N_Others_Choice
, Token_Ptr
), Choices
);
3696 Scan
; -- past OTHERS
3700 -- Scan out expression or range attribute
3702 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3703 Ignore
(Tok_Right_Paren
);
3705 if Token
= Tok_Colon
3706 and then Nkind
(Expr_Node
) = N_Identifier
3708 Error_Msg_SP
("label not permitted in this context");
3713 elsif Expr_Form
= EF_Range_Attr
then
3714 Append
(Expr_Node
, Choices
);
3718 elsif Token
= Tok_Dot_Dot
then
3719 Check_Simple_Expression
(Expr_Node
);
3720 Choice_Node
:= New_Node
(N_Range
, Token_Ptr
);
3721 Set_Low_Bound
(Choice_Node
, Expr_Node
);
3723 Expr_Node
:= P_Expression_No_Right_Paren
;
3724 Check_Simple_Expression
(Expr_Node
);
3725 Set_High_Bound
(Choice_Node
, Expr_Node
);
3726 Append
(Choice_Node
, Choices
);
3728 -- Simple name, must be subtype, so range allowed
3730 elsif Expr_Form
= EF_Simple_Name
then
3731 if Token
= Tok_Range
then
3732 Append
(P_Subtype_Indication
(Expr_Node
), Choices
);
3734 elsif Token
in Token_Class_Consk
then
3736 ("the only constraint allowed here " &
3737 "is a range constraint");
3738 Discard_Junk_Node
(P_Constraint_Opt
);
3739 Append
(Expr_Node
, Choices
);
3742 Append
(Expr_Node
, Choices
);
3748 -- In Ada 2012 mode, the expression must be a simple
3749 -- expression. The reason for this restriction (i.e. going
3750 -- back to the Ada 83 rule) is to avoid ambiguities when set
3751 -- membership operations are allowed, consider the
3754 -- when A in 1 .. 10 | 12 =>
3756 -- This is ambiguous without parentheses, so we require one
3757 -- of the following two parenthesized forms to disambiguate:
3759 -- one of the following:
3761 -- when (A in 1 .. 10 | 12) =>
3762 -- when (A in 1 .. 10) | 12 =>
3764 -- To solve this, in Ada 2012 mode, we disallow the use of
3765 -- membership operations in expressions in choices.
3767 -- Technically in the grammar, the expression must match the
3768 -- grammar for restricted expression.
3770 if Ada_Version
>= Ada_2012
then
3771 Check_Restricted_Expression
(Expr_Node
);
3773 -- In Ada 83 mode, the syntax required a simple expression
3776 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
3779 Append
(Expr_Node
, Choices
);
3783 when Error_Resync
=>
3789 if Token
= Tok_Comma
then
3792 if Token
= Tok_Vertical_Bar
then
3793 Error_Msg_SP
-- CODEFIX
3794 ("|extra "","" ignored");
3798 Error_Msg_SP
-- CODEFIX
3799 (""","" should be ""'|""");
3803 exit when Token
/= Tok_Vertical_Bar
;
3810 end P_Discrete_Choice_List
;
3812 ----------------------------
3813 -- 3.8.1 Discrete Choice --
3814 ----------------------------
3816 -- Parsed by P_Discrete_Choice_List (3.8.1)
3818 ----------------------------------
3819 -- 3.9.1 Record Extension Part --
3820 ----------------------------------
3822 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
3824 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
3826 --------------------------------------
3827 -- 3.9.4 Interface Type Definition --
3828 --------------------------------------
3830 -- INTERFACE_TYPE_DEFINITION ::=
3831 -- [limited | task | protected | synchronized] interface
3832 -- [and INTERFACE_LIST]
3834 -- Error recovery: cannot raise Error_Resync
3836 function P_Interface_Type_Definition
3837 (Abstract_Present
: Boolean) return Node_Id
3839 Typedef_Node
: Node_Id
;
3842 if Ada_Version
< Ada_2005
then
3843 Error_Msg_SP
("abstract interface is an Ada 2005 extension");
3844 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3847 if Abstract_Present
then
3849 ("ABSTRACT not allowed in interface type definition " &
3853 Scan
; -- past INTERFACE
3855 -- Ada 2005 (AI-345): In case of interfaces with a null list of
3856 -- interfaces we build a record_definition node.
3858 if Token
= Tok_Semicolon
or else Aspect_Specifications_Present
then
3859 Typedef_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3861 Set_Abstract_Present
(Typedef_Node
);
3862 Set_Tagged_Present
(Typedef_Node
);
3863 Set_Null_Present
(Typedef_Node
);
3864 Set_Interface_Present
(Typedef_Node
);
3866 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
3867 -- a list of interfaces we build a derived_type_definition node. This
3868 -- simplifies the semantic analysis (and hence further maintenance)
3871 if Token
/= Tok_And
then
3872 Error_Msg_AP
("AND expected");
3877 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
3879 Set_Abstract_Present
(Typedef_Node
);
3880 Set_Interface_Present
(Typedef_Node
);
3881 Set_Subtype_Indication
(Typedef_Node
, P_Qualified_Simple_Name
);
3883 Set_Record_Extension_Part
(Typedef_Node
,
3884 New_Node
(N_Record_Definition
, Token_Ptr
));
3885 Set_Null_Present
(Record_Extension_Part
(Typedef_Node
));
3887 if Token
= Tok_And
then
3888 Set_Interface_List
(Typedef_Node
, New_List
);
3892 Append
(P_Qualified_Simple_Name
,
3893 Interface_List
(Typedef_Node
));
3894 exit when Token
/= Tok_And
;
3900 return Typedef_Node
;
3901 end P_Interface_Type_Definition
;
3903 ----------------------------------
3904 -- 3.10 Access Type Definition --
3905 ----------------------------------
3907 -- ACCESS_TYPE_DEFINITION ::=
3908 -- ACCESS_TO_OBJECT_DEFINITION
3909 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3911 -- ACCESS_TO_OBJECT_DEFINITION ::=
3912 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
3914 -- GENERAL_ACCESS_MODIFIER ::= all | constant
3916 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3917 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3918 -- | [NULL_EXCLUSION] access [protected] function
3919 -- PARAMETER_AND_RESULT_PROFILE
3921 -- PARAMETER_PROFILE ::= [FORMAL_PART]
3923 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
3925 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
3926 -- parsed the null_exclusion part and has also removed the ACCESS token;
3927 -- otherwise the caller has just checked that the initial token is ACCESS
3929 -- Error recovery: can raise Error_Resync
3931 function P_Access_Type_Definition
3932 (Header_Already_Parsed
: Boolean := False) return Node_Id
3934 Access_Loc
: constant Source_Ptr
:= Token_Ptr
;
3935 Prot_Flag
: Boolean;
3936 Not_Null_Present
: Boolean := False;
3937 Not_Null_Subtype
: Boolean := False;
3938 Type_Def_Node
: Node_Id
;
3939 Result_Not_Null
: Boolean;
3940 Result_Node
: Node_Id
;
3942 procedure Check_Junk_Subprogram_Name
;
3943 -- Used in access to subprogram definition cases to check for an
3944 -- identifier or operator symbol that does not belong.
3946 --------------------------------
3947 -- Check_Junk_Subprogram_Name --
3948 --------------------------------
3950 procedure Check_Junk_Subprogram_Name
is
3951 Saved_State
: Saved_Scan_State
;
3954 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
3955 Save_Scan_State
(Saved_State
);
3956 Scan
; -- past possible junk subprogram name
3958 if Token
= Tok_Left_Paren
or else Token
= Tok_Semicolon
then
3959 Error_Msg_SP
("unexpected subprogram name ignored");
3963 Restore_Scan_State
(Saved_State
);
3966 end Check_Junk_Subprogram_Name
;
3968 -- Start of processing for P_Access_Type_Definition
3971 if not Header_Already_Parsed
then
3973 -- NOT NULL ACCESS .. is a common form of access definition.
3974 -- ACCESS NOT NULL .. is certainly rare, but syntactically legal.
3975 -- NOT NULL ACCESS NOT NULL .. is rarer yet, and also legal.
3976 -- The last two cases are only meaningful if the following subtype
3977 -- indication denotes an access type (semantic check). The flag
3978 -- Not_Null_Subtype indicates that this second null exclusion is
3979 -- present in the access type definition.
3981 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
3982 Scan
; -- past ACCESS
3983 Not_Null_Subtype
:= P_Null_Exclusion
; -- Might also appear
3986 if Token_Name
= Name_Protected
then
3987 Check_95_Keyword
(Tok_Protected
, Tok_Procedure
);
3988 Check_95_Keyword
(Tok_Protected
, Tok_Function
);
3991 Prot_Flag
:= (Token
= Tok_Protected
);
3994 Scan
; -- past PROTECTED
3996 if Token
/= Tok_Procedure
and then Token
/= Tok_Function
then
3997 Error_Msg_SC
-- CODEFIX
3998 ("FUNCTION or PROCEDURE expected");
4002 if Token
= Tok_Procedure
then
4003 if Ada_Version
= Ada_83
then
4004 Error_Msg_SC
("(Ada 83) access to procedure not allowed!");
4007 Type_Def_Node
:= New_Node
(N_Access_Procedure_Definition
, Access_Loc
);
4008 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4009 Scan
; -- past PROCEDURE
4010 Check_Junk_Subprogram_Name
;
4011 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4012 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4014 elsif Token
= Tok_Function
then
4015 if Ada_Version
= Ada_83
then
4016 Error_Msg_SC
("(Ada 83) access to function not allowed!");
4019 Type_Def_Node
:= New_Node
(N_Access_Function_Definition
, Access_Loc
);
4020 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4021 Scan
; -- past FUNCTION
4022 Check_Junk_Subprogram_Name
;
4023 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
4024 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
4027 Result_Not_Null
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
4029 -- Ada 2005 (AI-318-02)
4031 if Token
= Tok_Access
then
4032 if Ada_Version
< Ada_2005
then
4034 ("anonymous access result type is an Ada 2005 extension");
4035 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4038 Result_Node
:= P_Access_Definition
(Result_Not_Null
);
4041 Result_Node
:= P_Subtype_Mark
;
4044 -- A null exclusion on the result type must be recorded in a flag
4045 -- distinct from the one used for the access-to-subprogram type's
4048 Set_Null_Exclusion_In_Return_Present
4049 (Type_Def_Node
, Result_Not_Null
);
4052 Set_Result_Definition
(Type_Def_Node
, Result_Node
);
4056 New_Node
(N_Access_To_Object_Definition
, Access_Loc
);
4057 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
4058 Set_Null_Excluding_Subtype
(Type_Def_Node
, Not_Null_Subtype
);
4060 if Token
= Tok_All
or else Token
= Tok_Constant
then
4061 if Ada_Version
= Ada_83
then
4062 Error_Msg_SC
("(Ada 83) access modifier not allowed!");
4065 if Token
= Tok_All
then
4066 Set_All_Present
(Type_Def_Node
, True);
4069 Set_Constant_Present
(Type_Def_Node
, True);
4072 Scan
; -- past ALL or CONSTANT
4075 Set_Subtype_Indication
(Type_Def_Node
,
4076 P_Subtype_Indication
(Not_Null_Present
));
4079 return Type_Def_Node
;
4080 end P_Access_Type_Definition
;
4082 ---------------------------------------
4083 -- 3.10 Access To Object Definition --
4084 ---------------------------------------
4086 -- Parsed by P_Access_Type_Definition (3.10)
4088 -----------------------------------
4089 -- 3.10 General Access Modifier --
4090 -----------------------------------
4092 -- Parsed by P_Access_Type_Definition (3.10)
4094 -------------------------------------------
4095 -- 3.10 Access To Subprogram Definition --
4096 -------------------------------------------
4098 -- Parsed by P_Access_Type_Definition (3.10)
4100 -----------------------------
4101 -- 3.10 Access Definition --
4102 -----------------------------
4104 -- ACCESS_DEFINITION ::=
4105 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4106 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
4108 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4109 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4110 -- | [NULL_EXCLUSION] access [protected] function
4111 -- PARAMETER_AND_RESULT_PROFILE
4113 -- The caller has parsed the null-exclusion part and it has also checked
4114 -- that the next token is ACCESS
4116 -- Error recovery: cannot raise Error_Resync
4118 function P_Access_Definition
4119 (Null_Exclusion_Present
: Boolean) return Node_Id
4122 Subp_Node
: Node_Id
;
4125 Def_Node
:= New_Node
(N_Access_Definition
, Token_Ptr
);
4126 Scan
; -- past ACCESS
4128 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
4130 if Token
= Tok_Protected
4131 or else Token
= Tok_Procedure
4132 or else Token
= Tok_Function
4134 if Ada_Version
< Ada_2005
then
4135 Error_Msg_SP
("access-to-subprogram is an Ada 2005 extension");
4136 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
4139 Subp_Node
:= P_Access_Type_Definition
(Header_Already_Parsed
=> True);
4140 Set_Null_Exclusion_Present
(Subp_Node
, Null_Exclusion_Present
);
4141 Set_Access_To_Subprogram_Definition
(Def_Node
, Subp_Node
);
4143 -- Ada 2005 (AI-231)
4144 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4147 Set_Null_Exclusion_Present
(Def_Node
, Null_Exclusion_Present
);
4149 if Token
= Tok_All
then
4150 if Ada_Version
< Ada_2005
then
4152 ("ALL is not permitted for anonymous access types");
4156 Set_All_Present
(Def_Node
);
4158 elsif Token
= Tok_Constant
then
4159 if Ada_Version
< Ada_2005
then
4160 Error_Msg_SP
("access-to-constant is an Ada 2005 extension");
4161 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
4164 Scan
; -- past CONSTANT
4165 Set_Constant_Present
(Def_Node
);
4168 Set_Subtype_Mark
(Def_Node
, P_Subtype_Mark
);
4173 end P_Access_Definition
;
4175 -----------------------------------------
4176 -- 3.10.1 Incomplete Type Declaration --
4177 -----------------------------------------
4179 -- Parsed by P_Type_Declaration (3.2.1)
4181 ----------------------------
4182 -- 3.11 Declarative Part --
4183 ----------------------------
4185 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
4187 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Items
4188 -- handles errors, and returns cleanly after an error has occurred)
4190 function P_Declarative_Part
return List_Id
is
4195 -- Indicate no bad declarations detected yet. This will be reset by
4196 -- P_Declarative_Items if a bad declaration is discovered.
4198 Missing_Begin_Msg
:= No_Error_Msg
;
4200 -- Get rid of active SIS entry from outer scope. This means we will
4201 -- miss some nested cases, but it doesn't seem worth the effort. See
4202 -- discussion in Par for further details
4204 SIS_Entry_Active
:= False;
4207 -- Loop to scan out the declarations
4210 P_Declarative_Items
(Decls
, Done
, In_Spec
=> False);
4214 -- Get rid of active SIS entry which is left set only if we scanned a
4215 -- procedure declaration and have not found the body. We could give
4216 -- an error message, but that really would be usurping the role of
4217 -- semantic analysis (this really is a missing body case).
4219 SIS_Entry_Active
:= False;
4221 end P_Declarative_Part
;
4223 ----------------------------
4224 -- 3.11 Declarative Item --
4225 ----------------------------
4227 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4229 -- Can return Error if a junk declaration is found, or Empty if no
4230 -- declaration is found (i.e. a token ending declarations, such as
4231 -- BEGIN or END is encountered).
4233 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4234 -- then the scan is set past the next semicolon and Error is returned.
4236 procedure P_Declarative_Items
4241 Scan_State
: Saved_Scan_State
;
4245 Style
.Check_Indentation
;
4250 when Tok_Function
=>
4252 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4258 -- Check for loop (premature statement)
4260 Save_Scan_State
(Scan_State
);
4263 if Token
= Tok_Identifier
then
4264 Scan
; -- past identifier
4266 if Token
= Tok_In
then
4267 Restore_Scan_State
(Scan_State
);
4268 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4273 -- Not a loop, so must be rep clause
4275 Restore_Scan_State
(Scan_State
);
4276 Append
(P_Representation_Clause
, Decls
);
4281 Append
(P_Generic
, Decls
);
4284 when Tok_Identifier
=>
4287 -- Special check for misuse of overriding not in Ada 2005 mode
4289 if Token_Name
= Name_Overriding
4290 and then not Next_Token_Is
(Tok_Colon
)
4292 Error_Msg_SC
("overriding indicator is an Ada 2005 extension");
4293 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4295 Token
:= Tok_Overriding
;
4296 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4299 -- Normal case, no overriding, or overriding followed by colon
4302 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4305 -- Ada 2005: A subprogram declaration can start with "not" or
4306 -- "overriding". In older versions, "overriding" is handled
4307 -- like an identifier, with the appropriate messages.
4311 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4314 when Tok_Overriding
=>
4316 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4321 Append
(P_Package
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4325 Append
(P_Pragma
, Decls
);
4328 when Tok_Procedure
=>
4330 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
), Decls
);
4333 when Tok_Protected
=>
4335 Scan
; -- past PROTECTED
4336 Append
(P_Protected
, Decls
);
4341 Append
(P_Subtype_Declaration
, Decls
);
4347 Append
(P_Task
, Decls
);
4352 Append
(P_Type_Declaration
, Decls
);
4357 Append
(P_Use_Clause
, Decls
);
4363 if Aspect_Specifications_Present
then
4365 -- If we are after a semicolon, complain that it was ignored.
4366 -- But we don't really ignore it, since we dump the aspects,
4367 -- so we make the error message a normal fatal message which
4368 -- will inhibit semantic analysis anyway).
4370 if Prev_Token
= Tok_Semicolon
then
4371 Error_Msg_SP
-- CODEFIX
4372 ("extra "";"" ignored");
4374 -- If not just past semicolon, just complain that aspects are
4375 -- not allowed at this point.
4378 Error_Msg_SC
("aspect specifications not allowed here");
4382 Dummy_Node
: constant Node_Id
:=
4383 New_Node
(N_Package_Specification
, Token_Ptr
);
4384 pragma Warnings
(Off
, Dummy_Node
);
4385 -- Dummy node to attach aspect specifications to. We will
4386 -- then throw them away.
4389 P_Aspect_Specifications
(Dummy_Node
, Semicolon
=> True);
4392 -- Here if not aspect specifications case
4395 Error_Msg_SC
("WITH can only appear in context clause");
4399 -- BEGIN terminates the scan of a sequence of declarations unless
4400 -- there is a missing subprogram body, see section on handling
4401 -- semicolon in place of IS. We only treat the begin as satisfying
4402 -- the subprogram declaration if it falls in the expected column
4406 if SIS_Entry_Active
and then Start_Column
>= SIS_Ecol
then
4408 -- Here we have the case where a BEGIN is encountered during
4409 -- declarations in a declarative part, or at the outer level,
4410 -- and there is a subprogram declaration outstanding for which
4411 -- no body has been supplied. This is the case where we assume
4412 -- that the semicolon in the subprogram declaration should
4413 -- really have been is. The active SIS entry describes the
4414 -- subprogram declaration. On return the declaration has been
4415 -- modified to become a body.
4418 Specification_Node
: Node_Id
;
4419 Decl_Node
: Node_Id
;
4420 Body_Node
: Node_Id
;
4423 -- First issue the error message. If we had a missing
4424 -- semicolon in the declaration, then change the message
4425 -- to <missing "is">
4427 if SIS_Missing_Semicolon_Message
/= No_Error_Msg
then
4428 Change_Error_Text
-- Replace: "missing "";"" "
4429 (SIS_Missing_Semicolon_Message
, "missing ""is""");
4431 -- Otherwise we saved the semicolon position, so complain
4434 Error_Msg
-- CODEFIX
4435 ("|"";"" should be IS", SIS_Semicolon_Sloc
);
4438 -- The next job is to fix up any declarations that occurred
4439 -- between the procedure header and the BEGIN. These got
4440 -- chained to the outer declarative region (immediately
4441 -- after the procedure declaration) and they should be
4442 -- chained to the subprogram itself, which is a body
4443 -- rather than a spec.
4445 Specification_Node
:= Specification
(SIS_Declaration_Node
);
4446 Change_Node
(SIS_Declaration_Node
, N_Subprogram_Body
);
4447 Body_Node
:= SIS_Declaration_Node
;
4448 Set_Specification
(Body_Node
, Specification_Node
);
4449 Set_Declarations
(Body_Node
, New_List
);
4452 Decl_Node
:= Remove_Next
(Body_Node
);
4453 exit when Decl_Node
= Empty
;
4454 Append
(Decl_Node
, Declarations
(Body_Node
));
4457 -- Now make the scope table entry for the Begin-End and
4461 Scope
.Table
(Scope
.Last
).Sloc
:= SIS_Sloc
;
4462 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
4463 Scope
.Table
(Scope
.Last
).Ecol
:= SIS_Ecol
;
4464 Scope
.Table
(Scope
.Last
).Labl
:= SIS_Labl
;
4465 Scope
.Table
(Scope
.Last
).Lreq
:= False;
4466 SIS_Entry_Active
:= False;
4468 Set_Handled_Statement_Sequence
(Body_Node
,
4469 P_Handled_Sequence_Of_Statements
);
4470 End_Statements
(Handled_Statement_Sequence
(Body_Node
));
4479 -- Normally an END terminates the scan for basic declarative items.
4480 -- The one exception is END RECORD, which is probably left over from
4484 Save_Scan_State
(Scan_State
); -- at END
4487 if Token
= Tok_Record
then
4488 Error_Msg_SP
("no RECORD for this `end record`!");
4489 Scan
; -- past RECORD
4493 Restore_Scan_State
(Scan_State
); -- to END
4497 -- The following tokens which can only be the start of a statement
4498 -- are considered to end a declarative part (i.e. we have a missing
4499 -- BEGIN situation). We are fairly conservative in making this
4500 -- judgment, because it is a real mess to go into statement mode
4501 -- prematurely in response to a junk declaration.
4516 -- But before we decide that it's a statement, let's check for
4517 -- a reserved word misused as an identifier.
4519 if Is_Reserved_Identifier
then
4520 Save_Scan_State
(Scan_State
);
4521 Scan
; -- past the token
4523 -- If reserved identifier not followed by colon or comma, then
4524 -- this is most likely an assignment statement to the bad id.
4526 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4527 Restore_Scan_State
(Scan_State
);
4528 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4531 -- Otherwise we have a declaration of the bad id
4534 Restore_Scan_State
(Scan_State
);
4535 Scan_Reserved_Identifier
(Force_Msg
=> True);
4536 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4539 -- If not reserved identifier, then it's definitely a statement
4542 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4546 -- The token RETURN may well also signal a missing BEGIN situation,
4547 -- however, we never let it end the declarative part, because it may
4548 -- also be part of a half-baked function declaration.
4551 Error_Msg_SC
("misplaced RETURN statement");
4554 -- PRIVATE definitely terminates the declarations in a spec,
4555 -- and is an error in a body.
4561 Error_Msg_SC
("PRIVATE not allowed in body");
4562 Scan
; -- past PRIVATE
4565 -- An end of file definitely terminates the declarations
4570 -- The remaining tokens do not end the scan, but cannot start a
4571 -- valid declaration, so we signal an error and resynchronize.
4572 -- But first check for misuse of a reserved identifier.
4576 -- Here we check for a reserved identifier
4578 if Is_Reserved_Identifier
then
4579 Save_Scan_State
(Scan_State
);
4580 Scan
; -- past the token
4582 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4583 Restore_Scan_State
(Scan_State
);
4584 Set_Declaration_Expected
;
4587 Restore_Scan_State
(Scan_State
);
4588 Scan_Reserved_Identifier
(Force_Msg
=> True);
4590 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4594 Set_Declaration_Expected
;
4599 -- To resynchronize after an error, we scan to the next semicolon and
4600 -- return with Done = False, indicating that there may still be more
4601 -- valid declarations to come.
4604 when Error_Resync
=>
4605 Resync_Past_Semicolon
;
4607 end P_Declarative_Items
;
4609 ----------------------------------
4610 -- 3.11 Basic Declarative Item --
4611 ----------------------------------
4613 -- BASIC_DECLARATIVE_ITEM ::=
4614 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4616 -- Scan zero or more basic declarative items
4618 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4619 -- the scan pointer is repositioned past the next semicolon, and the scan
4620 -- for declarative items continues.
4622 function P_Basic_Declarative_Items
return List_Id
is
4629 -- Indicate no bad declarations detected yet in the current context:
4630 -- visible or private declarations of a package spec.
4632 Missing_Begin_Msg
:= No_Error_Msg
;
4634 -- Get rid of active SIS entry from outer scope. This means we will
4635 -- miss some nested cases, but it doesn't seem worth the effort. See
4636 -- discussion in Par for further details
4638 SIS_Entry_Active
:= False;
4640 -- Loop to scan out declarations
4645 P_Declarative_Items
(Decls
, Done
, In_Spec
=> True);
4649 -- Get rid of active SIS entry. This is set only if we have scanned a
4650 -- procedure declaration and have not found the body. We could give
4651 -- an error message, but that really would be usurping the role of
4652 -- semantic analysis (this really is a case of a missing body).
4654 SIS_Entry_Active
:= False;
4656 -- Test for assorted illegal declarations not diagnosed elsewhere
4658 Decl
:= First
(Decls
);
4660 while Present
(Decl
) loop
4661 Kind
:= Nkind
(Decl
);
4663 -- Test for body scanned, not acceptable as basic decl item
4665 if Kind
= N_Subprogram_Body
or else
4666 Kind
= N_Package_Body
or else
4667 Kind
= N_Task_Body
or else
4668 Kind
= N_Protected_Body
4670 Error_Msg
("proper body not allowed in package spec", Sloc
(Decl
));
4672 -- Complete declaration of mangled subprogram body, for better
4673 -- recovery if analysis is attempted.
4675 if Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
4676 and then No
(Handled_Statement_Sequence
(Decl
))
4678 Set_Handled_Statement_Sequence
(Decl
,
4679 Make_Handled_Sequence_Of_Statements
(Sloc
(Decl
),
4680 Statements
=> New_List
));
4683 -- Test for body stub scanned, not acceptable as basic decl item
4685 elsif Kind
in N_Body_Stub
then
4686 Error_Msg
("body stub not allowed in package spec", Sloc
(Decl
));
4688 elsif Kind
= N_Assignment_Statement
then
4690 ("assignment statement not allowed in package spec",
4698 end P_Basic_Declarative_Items
;
4704 -- For proper body, see below
4705 -- For body stub, see 10.1.3
4707 -----------------------
4708 -- 3.11 Proper Body --
4709 -----------------------
4711 -- Subprogram body is parsed by P_Subprogram (6.1)
4712 -- Package body is parsed by P_Package (7.1)
4713 -- Task body is parsed by P_Task (9.1)
4714 -- Protected body is parsed by P_Protected (9.4)
4716 ------------------------------
4717 -- Set_Declaration_Expected --
4718 ------------------------------
4720 procedure Set_Declaration_Expected
is
4722 Error_Msg_SC
("declaration expected");
4724 if Missing_Begin_Msg
= No_Error_Msg
then
4725 Missing_Begin_Msg
:= Get_Msg_Id
;
4727 end Set_Declaration_Expected
;
4729 ----------------------
4730 -- Skip_Declaration --
4731 ----------------------
4733 procedure Skip_Declaration
(S
: List_Id
) is
4734 Dummy_Done
: Boolean;
4735 pragma Warnings
(Off
, Dummy_Done
);
4737 P_Declarative_Items
(S
, Dummy_Done
, False);
4738 end Skip_Declaration
;
4740 -----------------------------------------
4741 -- Statement_When_Declaration_Expected --
4742 -----------------------------------------
4744 procedure Statement_When_Declaration_Expected
4750 -- Case of second occurrence of statement in one declaration sequence
4752 if Missing_Begin_Msg
/= No_Error_Msg
then
4754 -- In the procedure spec case, just ignore it, we only give one
4755 -- message for the first occurrence, since otherwise we may get
4756 -- horrible cascading if BODY was missing in the header line.
4761 -- In the declarative part case, take a second statement as a sure
4762 -- sign that we really have a missing BEGIN, and end the declarative
4763 -- part now. Note that the caller will fix up the first message to
4764 -- say "missing BEGIN" so that's how the error will be signalled.
4771 -- Case of first occurrence of unexpected statement
4774 -- If we are in a package spec, then give message of statement
4775 -- not allowed in package spec. This message never gets changed.
4778 Error_Msg_SC
("statement not allowed in package spec");
4780 -- If in declarative part, then we give the message complaining
4781 -- about finding a statement when a declaration is expected. This
4782 -- gets changed to a complaint about a missing BEGIN if we later
4783 -- find that no BEGIN is present.
4786 Error_Msg_SC
("statement not allowed in declarative part");
4789 -- Capture message Id. This is used for two purposes, first to
4790 -- stop multiple messages, see test above, and second, to allow
4791 -- the replacement of the message in the declarative part case.
4793 Missing_Begin_Msg
:= Get_Msg_Id
;
4796 -- In all cases except the case in which we decided to terminate the
4797 -- declaration sequence on a second error, we scan out the statement
4798 -- and append it to the list of declarations (note that the semantics
4799 -- can handle statements in a declaration list so if we proceed to
4800 -- call the semantic phase, all will be (reasonably) well.
4802 Append_List_To
(Decls
, P_Sequence_Of_Statements
(SS_Unco
));
4804 -- Done is set to False, since we want to continue the scan of
4805 -- declarations, hoping that this statement was a temporary glitch.
4806 -- If we indeed are now in the statement part (i.e. this was a missing
4807 -- BEGIN, then it's not terrible, we will simply keep calling this
4808 -- procedure to process the statements one by one, and then finally
4809 -- hit the missing BEGIN, which will clean up the error message.
4812 end Statement_When_Declaration_Expected
;