1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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
;
36 -----------------------
37 -- Local Subprograms --
38 -----------------------
40 function P_Component_List
return Node_Id
;
41 function P_Defining_Character_Literal
return Node_Id
;
42 function P_Delta_Constraint
return Node_Id
;
43 function P_Derived_Type_Def_Or_Private_Ext_Decl
return Node_Id
;
44 function P_Digits_Constraint
return Node_Id
;
45 function P_Discriminant_Association
return Node_Id
;
46 function P_Enumeration_Literal_Specification
return Node_Id
;
47 function P_Enumeration_Type_Definition
return Node_Id
;
48 function P_Fixed_Point_Definition
return Node_Id
;
49 function P_Floating_Point_Definition
return Node_Id
;
50 function P_Index_Or_Discriminant_Constraint
return Node_Id
;
51 function P_Real_Range_Specification_Opt
return Node_Id
;
52 function P_Subtype_Declaration
return Node_Id
;
53 function P_Type_Declaration
return Node_Id
;
54 function P_Modular_Type_Definition
return Node_Id
;
55 function P_Variant
return Node_Id
;
56 function P_Variant_Part
return Node_Id
;
58 procedure P_Declarative_Items
62 -- Scans out a single declarative item, or, in the case of a declaration
63 -- with a list of identifiers, a list of declarations, one for each of the
64 -- identifiers in the list. The declaration or declarations scanned are
65 -- appended to the given list. Done indicates whether or not there may be
66 -- additional declarative items to scan. If Done is True, then a decision
67 -- has been made that there are no more items to scan. If Done is False,
68 -- then there may be additional declarations to scan. In_Spec is true if
69 -- we are scanning a package declaration, and is used to generate an
70 -- appropriate message if a statement is encountered in such a context.
72 procedure P_Identifier_Declarations
76 -- Scans out a set of declarations for an identifier or list of
77 -- identifiers, and appends them to the given list. The parameters have
78 -- the same significance as for P_Declarative_Items.
80 procedure Statement_When_Declaration_Expected
84 -- Called when a statement is found at a point where a declaration was
85 -- expected. The parameters are as described for P_Declarative_Items.
87 procedure Set_Declaration_Expected
;
88 -- Posts a "declaration expected" error messages at the start of the
89 -- current token, and if this is the first such message issued, saves
90 -- the message id in Missing_Begin_Msg, for possible later replacement.
96 function Init_Expr_Opt
(P
: Boolean := False) return Node_Id
is
98 -- For colon, assume it means := unless it is at the end of
99 -- a line, in which case guess that it means a semicolon.
101 if Token
= Tok_Colon
then
102 if Token_Is_At_End_Of_Line
then
107 -- Here if := or something that we will take as equivalent
109 elsif Token
= Tok_Colon_Equal
110 or else Token
= Tok_Equal
111 or else Token
= Tok_Is
115 -- Another possibility. If we have a literal followed by a semicolon,
116 -- we assume that we have a missing colon-equal.
118 elsif Token
in Token_Class_Literal
then
120 Scan_State
: Saved_Scan_State
;
123 Save_Scan_State
(Scan_State
);
124 Scan
; -- past literal or identifier
126 if Token
= Tok_Semicolon
then
127 Restore_Scan_State
(Scan_State
);
129 Restore_Scan_State
(Scan_State
);
134 -- Otherwise we definitely have no initialization expression
140 -- Merge here if we have an initialization expression
147 return P_Expression_No_Right_Paren
;
151 ----------------------------
152 -- 3.1 Basic Declaration --
153 ----------------------------
155 -- Parsed by P_Basic_Declarative_Items (3.9)
157 ------------------------------
158 -- 3.1 Defining Identifier --
159 ------------------------------
161 -- DEFINING_IDENTIFIER ::= IDENTIFIER
163 -- Error recovery: can raise Error_Resync
165 function P_Defining_Identifier
(C
: Id_Check
:= None
) return Node_Id
is
166 Ident_Node
: Node_Id
;
169 -- Scan out the identifier. Note that this code is essentially identical
170 -- to P_Identifier, except that in the call to Scan_Reserved_Identifier
171 -- we set Force_Msg to True, since we want at least one message for each
172 -- separate declaration (but not use) of a reserved identifier.
174 if Token
= Tok_Identifier
then
176 -- Ada 2005 (AI-284): Compiling in Ada95 mode we warn that INTERFACE,
177 -- OVERRIDING, and SYNCHRONIZED are new reserved words. Note that
178 -- in the case where these keywords are misused in Ada 95 mode,
179 -- this routine will generally not be called at all.
181 if Ada_Version
= Ada_95
182 and then Warn_On_Ada_2005_Compatibility
184 if Token_Name
= Name_Overriding
185 or else Token_Name
= Name_Synchronized
186 or else (Token_Name
= Name_Interface
187 and then Prev_Token
/= Tok_Pragma
)
189 Error_Msg_N
("& is a reserved word in Ada 2005?", Token_Node
);
193 -- If we have a reserved identifier, manufacture an identifier with
194 -- a corresponding name after posting an appropriate error message
196 elsif Is_Reserved_Identifier
(C
) then
197 Scan_Reserved_Identifier
(Force_Msg
=> True);
199 -- Otherwise we have junk that cannot be interpreted as an identifier
202 T_Identifier
; -- to give message
206 Ident_Node
:= Token_Node
;
207 Scan
; -- past the reserved identifier
209 -- If we already have a defining identifier, clean it out and make
210 -- a new clean identifier. This situation arises in some error cases
211 -- and we need to fix it.
213 if Nkind
(Ident_Node
) = N_Defining_Identifier
then
215 Make_Identifier
(Sloc
(Ident_Node
),
216 Chars
=> Chars
(Ident_Node
));
219 -- Change identifier to defining identifier if not in error
221 if Ident_Node
/= Error
then
222 Change_Identifier_To_Defining_Identifier
(Ident_Node
);
226 end P_Defining_Identifier
;
228 -----------------------------
229 -- 3.2.1 Type Declaration --
230 -----------------------------
232 -- TYPE_DECLARATION ::=
233 -- FULL_TYPE_DECLARATION
234 -- | INCOMPLETE_TYPE_DECLARATION
235 -- | PRIVATE_TYPE_DECLARATION
236 -- | PRIVATE_EXTENSION_DECLARATION
238 -- FULL_TYPE_DECLARATION ::=
239 -- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION;
240 -- | CONCURRENT_TYPE_DECLARATION
242 -- INCOMPLETE_TYPE_DECLARATION ::=
243 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] [is tagged];
245 -- PRIVATE_TYPE_DECLARATION ::=
246 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
247 -- is [abstract] [tagged] [limited] private;
249 -- PRIVATE_EXTENSION_DECLARATION ::=
250 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
251 -- [abstract] [limited | synchronized]
252 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
255 -- TYPE_DEFINITION ::=
256 -- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
257 -- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
258 -- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
259 -- | DERIVED_TYPE_DEFINITION | INTERFACE_TYPE_DEFINITION
261 -- INTEGER_TYPE_DEFINITION ::=
262 -- SIGNED_INTEGER_TYPE_DEFINITION
263 -- MODULAR_TYPE_DEFINITION
265 -- INTERFACE_TYPE_DEFINITION ::=
266 -- [limited | task | protected | synchronized ] interface
267 -- [and INTERFACE_LIST]
269 -- Error recovery: can raise Error_Resync
271 -- Note: The processing for full type declaration, incomplete type
272 -- declaration, private type declaration and type definition is
273 -- included in this function. The processing for concurrent type
274 -- declarations is NOT here, but rather in chapter 9 (i.e. this
275 -- function handles only declarations starting with TYPE).
277 function P_Type_Declaration
return Node_Id
is
278 Abstract_Present
: Boolean := False;
279 Abstract_Loc
: Source_Ptr
:= No_Location
;
281 Discr_List
: List_Id
;
282 Discr_Sloc
: Source_Ptr
;
284 Ident_Node
: Node_Id
;
285 Is_Derived_Iface
: Boolean := False;
286 Type_Loc
: Source_Ptr
;
287 Type_Start_Col
: Column_Number
;
288 Unknown_Dis
: Boolean;
290 Typedef_Node
: Node_Id
;
291 -- Normally holds type definition, except in the case of a private
292 -- extension declaration, in which case it holds the declaration itself
295 Type_Loc
:= Token_Ptr
;
296 Type_Start_Col
:= Start_Column
;
298 -- If we have TYPE, then proceed ahead and scan identifier
300 if Token
= Tok_Type
then
301 Type_Token_Location
:= Type_Loc
;
303 Ident_Node
:= P_Defining_Identifier
(C_Is
);
305 -- Otherwise this is an error case
309 Type_Token_Location
:= Type_Loc
;
310 Ident_Node
:= P_Defining_Identifier
(C_Is
);
313 Discr_Sloc
:= Token_Ptr
;
315 if P_Unknown_Discriminant_Part_Opt
then
317 Discr_List
:= No_List
;
319 Unknown_Dis
:= False;
320 Discr_List
:= P_Known_Discriminant_Part_Opt
;
323 -- Incomplete type declaration. We complete the processing for this
324 -- case here and return the resulting incomplete type declaration node
326 if Token
= Tok_Semicolon
then
328 Decl_Node
:= New_Node
(N_Incomplete_Type_Declaration
, Type_Loc
);
329 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
330 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
331 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
338 -- Full type declaration or private type declaration, must have IS
340 if Token
= Tok_Equal
then
342 Scan
; -- past = used in place of IS
344 elsif Token
= Tok_Renames
then
345 Error_Msg_SC
("RENAMES should be IS");
346 Scan
; -- past RENAMES used in place of IS
352 -- First an error check, if we have two identifiers in a row, a likely
353 -- possibility is that the first of the identifiers is an incorrectly
356 if Token
= Tok_Identifier
then
358 SS
: Saved_Scan_State
;
362 Save_Scan_State
(SS
);
363 Scan
; -- past initial identifier
364 I2
:= (Token
= Tok_Identifier
);
365 Restore_Scan_State
(SS
);
369 (Bad_Spelling_Of
(Tok_Abstract
) or else
370 Bad_Spelling_Of
(Tok_Access
) or else
371 Bad_Spelling_Of
(Tok_Aliased
) or else
372 Bad_Spelling_Of
(Tok_Constant
))
379 -- Check for misuse of Ada 95 keyword abstract in Ada 83 mode
381 if Token_Name
= Name_Abstract
then
382 Check_95_Keyword
(Tok_Abstract
, Tok_Tagged
);
383 Check_95_Keyword
(Tok_Abstract
, Tok_New
);
386 -- Check cases of misuse of ABSTRACT
388 if Token
= Tok_Abstract
then
389 Abstract_Present
:= True;
390 Abstract_Loc
:= Token_Ptr
;
391 Scan
; -- past ABSTRACT
393 -- Ada 2005 (AI-419): AARM 3.4 (2/2)
395 if (Ada_Version
< Ada_05
and then Token
= Tok_Limited
)
396 or else Token
= Tok_Private
397 or else Token
= Tok_Record
398 or else Token
= Tok_Null
400 Error_Msg_AP
("TAGGED expected");
404 -- Check for misuse of Ada 95 keyword Tagged
406 if Token_Name
= Name_Tagged
then
407 Check_95_Keyword
(Tok_Tagged
, Tok_Private
);
408 Check_95_Keyword
(Tok_Tagged
, Tok_Limited
);
409 Check_95_Keyword
(Tok_Tagged
, Tok_Record
);
412 -- Special check for misuse of Aliased
414 if Token
= Tok_Aliased
or else Token_Name
= Name_Aliased
then
415 Error_Msg_SC
("ALIASED not allowed in type definition");
416 Scan
; -- past ALIASED
419 -- The following processing deals with either a private type declaration
420 -- or a full type declaration. In the private type case, we build the
421 -- N_Private_Type_Declaration node, setting its Tagged_Present and
422 -- Limited_Present flags, on encountering the Private keyword, and
423 -- leave Typedef_Node set to Empty. For the full type declaration
424 -- case, Typedef_Node gets set to the type definition.
426 Typedef_Node
:= Empty
;
428 -- Switch on token following the IS. The loop normally runs once. It
429 -- only runs more than once if an error is detected, to try again after
430 -- detecting and fixing up the error.
436 Tok_Not
=> -- Ada 2005 (AI-231)
437 Typedef_Node
:= P_Access_Type_Definition
;
442 Typedef_Node
:= P_Array_Type_Definition
;
447 Typedef_Node
:= P_Fixed_Point_Definition
;
452 Typedef_Node
:= P_Floating_Point_Definition
;
459 when Tok_Integer_Literal
=>
461 Typedef_Node
:= P_Signed_Integer_Type_Definition
;
466 Typedef_Node
:= P_Record_Definition
;
470 when Tok_Left_Paren
=>
471 Typedef_Node
:= P_Enumeration_Type_Definition
;
474 Make_Identifier
(Token_Ptr
,
475 Chars
=> Chars
(Ident_Node
));
476 Set_Comes_From_Source
(End_Labl
, False);
478 Set_End_Label
(Typedef_Node
, End_Labl
);
483 Typedef_Node
:= P_Modular_Type_Definition
;
488 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
490 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
491 and then Present
(Record_Extension_Part
(Typedef_Node
))
494 Make_Identifier
(Token_Ptr
,
495 Chars
=> Chars
(Ident_Node
));
496 Set_Comes_From_Source
(End_Labl
, False);
499 (Record_Extension_Part
(Typedef_Node
), End_Labl
);
506 Typedef_Node
:= P_Signed_Integer_Type_Definition
;
511 Typedef_Node
:= P_Record_Definition
;
514 Make_Identifier
(Token_Ptr
,
515 Chars
=> Chars
(Ident_Node
));
516 Set_Comes_From_Source
(End_Labl
, False);
518 Set_End_Label
(Typedef_Node
, End_Labl
);
525 -- Ada 2005 (AI-326): If the words IS TAGGED appear, the type
526 -- is a tagged incomplete type.
528 if Ada_Version
>= Ada_05
529 and then Token
= Tok_Semicolon
534 New_Node
(N_Incomplete_Type_Declaration
, Type_Loc
);
535 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
536 Set_Tagged_Present
(Decl_Node
);
537 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
538 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
543 if Token
= Tok_Abstract
then
544 Error_Msg_SC
("ABSTRACT must come before TAGGED");
545 Abstract_Present
:= True;
546 Abstract_Loc
:= Token_Ptr
;
547 Scan
; -- past ABSTRACT
550 if Token
= Tok_Limited
then
551 Scan
; -- past LIMITED
553 -- TAGGED LIMITED PRIVATE case
555 if Token
= Tok_Private
then
557 New_Node
(N_Private_Type_Declaration
, Type_Loc
);
558 Set_Tagged_Present
(Decl_Node
, True);
559 Set_Limited_Present
(Decl_Node
, True);
560 Scan
; -- past PRIVATE
562 -- TAGGED LIMITED RECORD
565 Typedef_Node
:= P_Record_Definition
;
566 Set_Tagged_Present
(Typedef_Node
, True);
567 Set_Limited_Present
(Typedef_Node
, True);
570 Make_Identifier
(Token_Ptr
,
571 Chars
=> Chars
(Ident_Node
));
572 Set_Comes_From_Source
(End_Labl
, False);
574 Set_End_Label
(Typedef_Node
, End_Labl
);
580 if Token
= Tok_Private
then
582 New_Node
(N_Private_Type_Declaration
, Type_Loc
);
583 Set_Tagged_Present
(Decl_Node
, True);
584 Scan
; -- past PRIVATE
589 Typedef_Node
:= P_Record_Definition
;
590 Set_Tagged_Present
(Typedef_Node
, True);
593 Make_Identifier
(Token_Ptr
,
594 Chars
=> Chars
(Ident_Node
));
595 Set_Comes_From_Source
(End_Labl
, False);
597 Set_End_Label
(Typedef_Node
, End_Labl
);
605 Scan
; -- past LIMITED
608 if Token
= Tok_Tagged
then
609 Error_Msg_SC
("TAGGED must come before LIMITED");
612 elsif Token
= Tok_Abstract
then
613 Error_Msg_SC
("ABSTRACT must come before LIMITED");
614 Scan
; -- past ABSTRACT
621 -- LIMITED RECORD or LIMITED NULL RECORD
623 if Token
= Tok_Record
or else Token
= Tok_Null
then
624 if Ada_Version
= Ada_83
then
626 ("(Ada 83) limited record declaration not allowed!");
628 -- In Ada2005, "abstract limited" can appear before "new",
629 -- but it cannot be part of an untagged record declaration.
631 elsif Abstract_Present
632 and then Prev_Token
/= Tok_Tagged
634 Error_Msg_SP
("TAGGED expected");
637 Typedef_Node
:= P_Record_Definition
;
638 Set_Limited_Present
(Typedef_Node
, True);
640 -- Ada 2005 (AI-251): LIMITED INTERFACE
642 -- If we are compiling in Ada 83 or Ada 95 mode, "interface"
643 -- is not a reserved word but we force its analysis to
644 -- generate the corresponding usage error.
646 elsif Token
= Tok_Interface
647 or else (Token
= Tok_Identifier
648 and then Chars
(Token_Node
) = Name_Interface
)
651 P_Interface_Type_Definition
(Abstract_Present
);
652 Abstract_Present
:= True;
653 Set_Limited_Present
(Typedef_Node
);
655 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
then
656 Is_Derived_Iface
:= True;
659 -- Ada 2005 (AI-419): LIMITED NEW
661 elsif Token
= Tok_New
then
662 if Ada_Version
< Ada_05
then
664 ("LIMITED in derived type is an Ada 2005 extension");
666 ("\unit must be compiled with -gnat05 switch");
669 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
670 Set_Limited_Present
(Typedef_Node
);
672 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
673 and then Present
(Record_Extension_Part
(Typedef_Node
))
676 Make_Identifier
(Token_Ptr
,
677 Chars
=> Chars
(Ident_Node
));
678 Set_Comes_From_Source
(End_Labl
, False);
681 (Record_Extension_Part
(Typedef_Node
), End_Labl
);
684 -- LIMITED PRIVATE is the only remaining possibility here
687 Decl_Node
:= New_Node
(N_Private_Type_Declaration
, Type_Loc
);
688 Set_Limited_Present
(Decl_Node
, True);
689 T_Private
; -- past PRIVATE (or complain if not there!)
695 -- Here we have an identifier after the IS, which is certainly
696 -- wrong and which might be one of several different mistakes.
698 when Tok_Identifier
=>
700 -- First case, if identifier is on same line, then probably we
701 -- have something like "type X is Integer .." and the best
702 -- diagnosis is a missing NEW. Note: the missing new message
703 -- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl.
705 if not Token_Is_At_Start_Of_Line
then
706 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
709 -- If the identifier is at the start of the line, and is in the
710 -- same column as the type declaration itself then we consider
711 -- that we had a missing type definition on the previous line
713 elsif Start_Column
<= Type_Start_Col
then
714 Error_Msg_AP
("type definition expected");
715 Typedef_Node
:= Error
;
717 -- If the identifier is at the start of the line, and is in
718 -- a column to the right of the type declaration line, then we
719 -- may have something like:
724 -- and the best diagnosis is a missing record keyword
727 Typedef_Node
:= P_Record_Definition
;
733 -- Ada 2005 (AI-251): INTERFACE
735 when Tok_Interface
=>
736 Typedef_Node
:= P_Interface_Type_Definition
(Abstract_Present
);
737 Abstract_Present
:= True;
742 Decl_Node
:= New_Node
(N_Private_Type_Declaration
, Type_Loc
);
743 Scan
; -- past PRIVATE
747 -- Ada 2005 (AI-345): Protected, synchronized or task interface
748 -- or Ada 2005 (AI-443): Synchronized private extension.
755 Saved_Token
: constant Token_Type
:= Token
;
758 Scan
; -- past TASK, PROTECTED or SYNCHRONIZED
760 -- Synchronized private extension
762 if Token
= Tok_New
then
763 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
765 if Saved_Token
= Tok_Synchronized
then
766 Set_Synchronized_Present
(Typedef_Node
);
768 Error_Msg_SC
("invalid kind of private extension");
774 if Token
/= Tok_Interface
then
775 Error_Msg_SC
("NEW or INTERFACE expected");
779 P_Interface_Type_Definition
(Abstract_Present
);
780 Abstract_Present
:= True;
784 Set_Task_Present
(Typedef_Node
);
786 when Tok_Protected
=>
787 Set_Protected_Present
(Typedef_Node
);
789 when Tok_Synchronized
=>
790 Set_Synchronized_Present
(Typedef_Node
);
793 pragma Assert
(False);
802 -- Anything else is an error
805 if Bad_Spelling_Of
(Tok_Access
)
807 Bad_Spelling_Of
(Tok_Array
)
809 Bad_Spelling_Of
(Tok_Delta
)
811 Bad_Spelling_Of
(Tok_Digits
)
813 Bad_Spelling_Of
(Tok_Limited
)
815 Bad_Spelling_Of
(Tok_Private
)
817 Bad_Spelling_Of
(Tok_Range
)
819 Bad_Spelling_Of
(Tok_Record
)
821 Bad_Spelling_Of
(Tok_Tagged
)
826 Error_Msg_AP
("type definition expected");
833 -- For the private type declaration case, the private type declaration
834 -- node has been built, with the Tagged_Present and Limited_Present
835 -- flags set as needed, and Typedef_Node is left set to Empty.
837 if No
(Typedef_Node
) then
838 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
839 Set_Abstract_Present
(Decl_Node
, Abstract_Present
);
841 -- For a private extension declaration, Typedef_Node contains the
842 -- N_Private_Extension_Declaration node, which we now complete. Note
843 -- that the private extension declaration, unlike a full type
844 -- declaration, does permit unknown discriminants.
846 elsif Nkind
(Typedef_Node
) = N_Private_Extension_Declaration
then
847 Decl_Node
:= Typedef_Node
;
848 Set_Sloc
(Decl_Node
, Type_Loc
);
849 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
850 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
852 -- In the full type declaration case, Typedef_Node has the type
853 -- definition and here is where we build the full type declaration
854 -- node. This is also where we check for improper use of an unknown
855 -- discriminant part (not allowed for full type declaration).
858 if Nkind
(Typedef_Node
) = N_Record_Definition
859 or else (Nkind
(Typedef_Node
) = N_Derived_Type_Definition
860 and then Present
(Record_Extension_Part
(Typedef_Node
)))
861 or else Is_Derived_Iface
863 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
865 elsif Abstract_Present
then
866 Error_Msg
("ABSTRACT not allowed here, ignored", Abstract_Loc
);
869 Decl_Node
:= New_Node
(N_Full_Type_Declaration
, Type_Loc
);
870 Set_Type_Definition
(Decl_Node
, Typedef_Node
);
874 ("Full type declaration cannot have unknown discriminants",
879 -- Remaining processing is common for all three cases
881 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
882 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
884 end P_Type_Declaration
;
886 ----------------------------------
887 -- 3.2.1 Full Type Declaration --
888 ----------------------------------
890 -- Parsed by P_Type_Declaration (3.2.1)
892 ----------------------------
893 -- 3.2.1 Type Definition --
894 ----------------------------
896 -- Parsed by P_Type_Declaration (3.2.1)
898 --------------------------------
899 -- 3.2.2 Subtype Declaration --
900 --------------------------------
902 -- SUBTYPE_DECLARATION ::=
903 -- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION;
905 -- The caller has checked that the initial token is SUBTYPE
907 -- Error recovery: can raise Error_Resync
909 function P_Subtype_Declaration
return Node_Id
is
911 Not_Null_Present
: Boolean := False;
914 Decl_Node
:= New_Node
(N_Subtype_Declaration
, Token_Ptr
);
915 Scan
; -- past SUBTYPE
916 Set_Defining_Identifier
(Decl_Node
, P_Defining_Identifier
(C_Is
));
919 if Token
= Tok_New
then
920 Error_Msg_SC
("NEW ignored (only allowed in type declaration)");
924 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
925 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
927 Set_Subtype_Indication
928 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
931 end P_Subtype_Declaration
;
933 -------------------------------
934 -- 3.2.2 Subtype Indication --
935 -------------------------------
937 -- SUBTYPE_INDICATION ::=
938 -- [not null] SUBTYPE_MARK [CONSTRAINT]
940 -- Error recovery: can raise Error_Resync
942 function P_Null_Exclusion
943 (Allow_Anonymous_In_95
: Boolean := False) return Boolean
945 Not_Loc
: constant Source_Ptr
:= Token_Ptr
;
946 -- Source position of "not", if present
949 if Token
/= Tok_Not
then
955 if Token
= Tok_Null
then
958 -- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95,
959 -- except in the case of anonymous access types.
961 -- Allow_Anonymous_In_95 will be True if we're parsing a formal
962 -- parameter or discriminant, which are the only places where
963 -- anonymous access types occur in Ada 95. "Formal : not null
964 -- access ..." is legal in Ada 95, whereas "Formal : not null
965 -- Named_Access_Type" is not.
967 if Ada_Version
>= Ada_05
968 or else (Ada_Version
>= Ada_95
969 and then Allow_Anonymous_In_95
970 and then Token
= Tok_Access
)
976 ("`NOT NULL` access type is an Ada 2005 extension", Not_Loc
);
978 ("\unit should be compiled with -gnat05 switch", Not_Loc
);
982 Error_Msg_SP
("NULL expected");
985 if Token
= Tok_New
then
986 Error_Msg
("`NOT NULL` comes after NEW, not before", Not_Loc
);
991 end P_Null_Exclusion
;
993 function P_Subtype_Indication
994 (Not_Null_Present
: Boolean := False) return Node_Id
999 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
1000 Type_Node
:= P_Subtype_Mark
;
1001 return P_Subtype_Indication
(Type_Node
, Not_Null_Present
);
1004 -- Check for error of using record definition and treat it nicely,
1005 -- otherwise things are really messed up, so resynchronize.
1007 if Token
= Tok_Record
then
1008 Error_Msg_SC
("anonymous record definitions are not permitted");
1009 Discard_Junk_Node
(P_Record_Definition
);
1013 Error_Msg_AP
("subtype indication expected");
1017 end P_Subtype_Indication
;
1019 -- The following function is identical except that it is called with
1020 -- the subtype mark already scanned out, and it scans out the constraint
1022 -- Error recovery: can raise Error_Resync
1024 function P_Subtype_Indication
1025 (Subtype_Mark
: Node_Id
;
1026 Not_Null_Present
: Boolean := False) return Node_Id
1028 Indic_Node
: Node_Id
;
1029 Constr_Node
: Node_Id
;
1032 Constr_Node
:= P_Constraint_Opt
;
1034 if No
(Constr_Node
) then
1035 return Subtype_Mark
;
1037 if Not_Null_Present
then
1038 Error_Msg_SP
("`NOT NULL` not allowed if constraint given");
1041 Indic_Node
:= New_Node
(N_Subtype_Indication
, Sloc
(Subtype_Mark
));
1042 Set_Subtype_Mark
(Indic_Node
, Check_Subtype_Mark
(Subtype_Mark
));
1043 Set_Constraint
(Indic_Node
, Constr_Node
);
1046 end P_Subtype_Indication
;
1048 -------------------------
1049 -- 3.2.2 Subtype Mark --
1050 -------------------------
1052 -- SUBTYPE_MARK ::= subtype_NAME;
1054 -- Note: The subtype mark which appears after an IN or NOT IN
1055 -- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
1057 -- Error recovery: cannot raise Error_Resync
1059 function P_Subtype_Mark
return Node_Id
is
1061 return P_Subtype_Mark_Resync
;
1063 when Error_Resync
=>
1067 -- This routine differs from P_Subtype_Mark in that it insists that an
1068 -- identifier be present, and if it is not, it raises Error_Resync.
1070 -- Error recovery: can raise Error_Resync
1072 function P_Subtype_Mark_Resync
return Node_Id
is
1073 Type_Node
: Node_Id
;
1076 if Token
= Tok_Access
then
1077 Error_Msg_SC
("anonymous access type definition not allowed here");
1078 Scan
; -- past ACCESS
1081 if Token
= Tok_Array
then
1082 Error_Msg_SC
("anonymous array definition not allowed here");
1083 Discard_Junk_Node
(P_Array_Type_Definition
);
1087 Type_Node
:= P_Qualified_Simple_Name_Resync
;
1089 -- Check for a subtype mark attribute. The only valid possibilities
1090 -- are 'CLASS and 'BASE. Anything else is a definite error. We may
1091 -- as well catch it here.
1093 if Token
= Tok_Apostrophe
then
1094 return P_Subtype_Mark_Attribute
(Type_Node
);
1099 end P_Subtype_Mark_Resync
;
1101 -- The following function is called to scan out a subtype mark attribute.
1102 -- The caller has already scanned out the subtype mark, which is passed in
1103 -- as the argument, and has checked that the current token is apostrophe.
1105 -- Only a special subclass of attributes, called type attributes
1106 -- (see Snames package) are allowed in this syntactic position.
1108 -- Note: if the apostrophe is followed by other than an identifier, then
1109 -- the input expression is returned unchanged, and the scan pointer is
1110 -- left pointing to the apostrophe.
1112 -- Error recovery: can raise Error_Resync
1114 function P_Subtype_Mark_Attribute
(Type_Node
: Node_Id
) return Node_Id
is
1115 Attr_Node
: Node_Id
:= Empty
;
1116 Scan_State
: Saved_Scan_State
;
1120 Prefix
:= Check_Subtype_Mark
(Type_Node
);
1122 if Prefix
= Error
then
1126 -- Loop through attributes appearing (more than one can appear as for
1127 -- for example in X'Base'Class). We are at an apostrophe on entry to
1128 -- this loop, and it runs once for each attribute parsed, with
1129 -- Prefix being the current possible prefix if it is an attribute.
1132 Save_Scan_State
(Scan_State
); -- at Apostrophe
1133 Scan
; -- past apostrophe
1135 if Token
/= Tok_Identifier
then
1136 Restore_Scan_State
(Scan_State
); -- to apostrophe
1137 return Prefix
; -- no attribute after all
1139 elsif not Is_Type_Attribute_Name
(Token_Name
) then
1141 ("attribute & may not be used in a subtype mark", Token_Node
);
1146 Make_Attribute_Reference
(Prev_Token_Ptr
,
1148 Attribute_Name
=> Token_Name
);
1149 Scan
; -- past type attribute identifier
1152 exit when Token
/= Tok_Apostrophe
;
1153 Prefix
:= Attr_Node
;
1156 -- Fall through here after scanning type attribute
1159 end P_Subtype_Mark_Attribute
;
1161 -----------------------
1162 -- 3.2.2 Constraint --
1163 -----------------------
1165 -- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
1167 -- SCALAR_CONSTRAINT ::=
1168 -- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
1170 -- COMPOSITE_CONSTRAINT ::=
1171 -- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
1173 -- If no constraint is present, this function returns Empty
1175 -- Error recovery: can raise Error_Resync
1177 function P_Constraint_Opt
return Node_Id
is
1179 if Token
= Tok_Range
1180 or else Bad_Spelling_Of
(Tok_Range
)
1182 return P_Range_Constraint
;
1184 elsif Token
= Tok_Digits
1185 or else Bad_Spelling_Of
(Tok_Digits
)
1187 return P_Digits_Constraint
;
1189 elsif Token
= Tok_Delta
1190 or else Bad_Spelling_Of
(Tok_Delta
)
1192 return P_Delta_Constraint
;
1194 elsif Token
= Tok_Left_Paren
then
1195 return P_Index_Or_Discriminant_Constraint
;
1197 elsif Token
= Tok_In
then
1199 return P_Constraint_Opt
;
1204 end P_Constraint_Opt
;
1206 ------------------------------
1207 -- 3.2.2 Scalar Constraint --
1208 ------------------------------
1210 -- Parsed by P_Constraint_Opt (3.2.2)
1212 ---------------------------------
1213 -- 3.2.2 Composite Constraint --
1214 ---------------------------------
1216 -- Parsed by P_Constraint_Opt (3.2.2)
1218 --------------------------------------------------------
1219 -- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
1220 --------------------------------------------------------
1222 -- This routine scans out a declaration starting with an identifier:
1224 -- OBJECT_DECLARATION ::=
1225 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1226 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION];
1227 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1228 -- ACCESS_DEFINITION [:= EXPRESSION];
1229 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1230 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1232 -- NUMBER_DECLARATION ::=
1233 -- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
1235 -- OBJECT_RENAMING_DECLARATION ::=
1236 -- DEFINING_IDENTIFIER :
1237 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME;
1238 -- | DEFINING_IDENTIFIER :
1239 -- ACCESS_DEFINITION renames object_NAME;
1241 -- EXCEPTION_RENAMING_DECLARATION ::=
1242 -- DEFINING_IDENTIFIER : exception renames exception_NAME;
1244 -- EXCEPTION_DECLARATION ::=
1245 -- DEFINING_IDENTIFIER_LIST : exception;
1247 -- Note that the ALIASED indication in an object declaration is
1248 -- marked by a flag in the parent node.
1250 -- The caller has checked that the initial token is an identifier
1252 -- The value returned is a list of declarations, one for each identifier
1253 -- in the list (as described in Sinfo, we always split up multiple
1254 -- declarations into the equivalent sequence of single declarations
1255 -- using the More_Ids and Prev_Ids flags to preserve the source).
1257 -- If the identifier turns out to be a probable statement rather than
1258 -- an identifier, then the scan is left pointing to the identifier and
1259 -- No_List is returned.
1261 -- Error recovery: can raise Error_Resync
1263 procedure P_Identifier_Declarations
1269 Decl_Node
: Node_Id
;
1270 Type_Node
: Node_Id
;
1271 Ident_Sloc
: Source_Ptr
;
1272 Scan_State
: Saved_Scan_State
;
1273 List_OK
: Boolean := True;
1275 Init_Expr
: Node_Id
;
1276 Init_Loc
: Source_Ptr
;
1277 Con_Loc
: Source_Ptr
;
1278 Not_Null_Present
: Boolean := False;
1280 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
1281 -- Used to save identifiers in the identifier list. The upper bound
1282 -- of 4096 is expected to be infinite in practice, and we do not even
1283 -- bother to check if this upper bound is exceeded.
1285 Num_Idents
: Nat
:= 1;
1286 -- Number of identifiers stored in Idents
1289 -- This procedure is called in renames cases to make sure that we do
1290 -- not have more than one identifier. If we do have more than one
1291 -- then an error message is issued (and the declaration is split into
1292 -- multiple declarations)
1294 function Token_Is_Renames
return Boolean;
1295 -- Checks if current token is RENAMES, and if so, scans past it and
1296 -- returns True, otherwise returns False. Includes checking for some
1297 -- common error cases.
1303 procedure No_List
is
1305 if Num_Idents
> 1 then
1306 Error_Msg
("identifier list not allowed for RENAMES",
1313 ----------------------
1314 -- Token_Is_Renames --
1315 ----------------------
1317 function Token_Is_Renames
return Boolean is
1318 At_Colon
: Saved_Scan_State
;
1321 if Token
= Tok_Colon
then
1322 Save_Scan_State
(At_Colon
);
1324 Check_Misspelling_Of
(Tok_Renames
);
1326 if Token
= Tok_Renames
then
1327 Error_Msg_SP
("|extra "":"" ignored");
1328 Scan
; -- past RENAMES
1331 Restore_Scan_State
(At_Colon
);
1336 Check_Misspelling_Of
(Tok_Renames
);
1338 if Token
= Tok_Renames
then
1339 Scan
; -- past RENAMES
1345 end Token_Is_Renames
;
1347 -- Start of processing for P_Identifier_Declarations
1350 Ident_Sloc
:= Token_Ptr
;
1351 Save_Scan_State
(Scan_State
); -- at first identifier
1352 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
1354 -- If we have a colon after the identifier, then we can assume that
1355 -- this is in fact a valid identifier declaration and can steam ahead.
1357 if Token
= Tok_Colon
then
1360 -- If we have a comma, then scan out the list of identifiers
1362 elsif Token
= Tok_Comma
then
1363 while Comma_Present
loop
1364 Num_Idents
:= Num_Idents
+ 1;
1365 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
1368 Save_Scan_State
(Scan_State
); -- at colon
1371 -- If we have identifier followed by := then we assume that what is
1372 -- really meant is an assignment statement. The assignment statement
1373 -- is scanned out and added to the list of declarations. An exception
1374 -- occurs if the := is followed by the keyword constant, in which case
1375 -- we assume it was meant to be a colon.
1377 elsif Token
= Tok_Colon_Equal
then
1380 if Token
= Tok_Constant
then
1381 Error_Msg_SP
("colon expected");
1384 Restore_Scan_State
(Scan_State
);
1385 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
1389 -- If we have an IS keyword, then assume the TYPE keyword was missing
1391 elsif Token
= Tok_Is
then
1392 Restore_Scan_State
(Scan_State
);
1393 Append_To
(Decls
, P_Type_Declaration
);
1397 -- Otherwise we have an error situation
1400 Restore_Scan_State
(Scan_State
);
1402 -- First case is possible misuse of PROTECTED in Ada 83 mode. If
1403 -- so, fix the keyword and return to scan the protected declaration.
1405 if Token_Name
= Name_Protected
then
1406 Check_95_Keyword
(Tok_Protected
, Tok_Identifier
);
1407 Check_95_Keyword
(Tok_Protected
, Tok_Type
);
1408 Check_95_Keyword
(Tok_Protected
, Tok_Body
);
1410 if Token
= Tok_Protected
then
1415 -- Check misspelling possibilities. If so, correct the misspelling
1416 -- and return to scan out the resulting declaration.
1418 elsif Bad_Spelling_Of
(Tok_Function
)
1419 or else Bad_Spelling_Of
(Tok_Procedure
)
1420 or else Bad_Spelling_Of
(Tok_Package
)
1421 or else Bad_Spelling_Of
(Tok_Pragma
)
1422 or else Bad_Spelling_Of
(Tok_Protected
)
1423 or else Bad_Spelling_Of
(Tok_Generic
)
1424 or else Bad_Spelling_Of
(Tok_Subtype
)
1425 or else Bad_Spelling_Of
(Tok_Type
)
1426 or else Bad_Spelling_Of
(Tok_Task
)
1427 or else Bad_Spelling_Of
(Tok_Use
)
1428 or else Bad_Spelling_Of
(Tok_For
)
1433 -- Otherwise we definitely have an ordinary identifier with a junk
1434 -- token after it. Just complain that we expect a declaration, and
1435 -- skip to a semicolon
1438 Set_Declaration_Expected
;
1439 Resync_Past_Semicolon
;
1445 -- Come here with an identifier list and colon scanned out. We now
1446 -- build the nodes for the declarative items. One node is built for
1447 -- each identifier in the list, with the type information being
1448 -- repeated by rescanning the appropriate section of source.
1450 -- First an error check, if we have two identifiers in a row, a likely
1451 -- possibility is that the first of the identifiers is an incorrectly
1454 if Token
= Tok_Identifier
then
1456 SS
: Saved_Scan_State
;
1460 Save_Scan_State
(SS
);
1461 Scan
; -- past initial identifier
1462 I2
:= (Token
= Tok_Identifier
);
1463 Restore_Scan_State
(SS
);
1467 (Bad_Spelling_Of
(Tok_Access
) or else
1468 Bad_Spelling_Of
(Tok_Aliased
) or else
1469 Bad_Spelling_Of
(Tok_Constant
))
1476 -- Loop through identifiers
1481 -- Check for some cases of misused Ada 95 keywords
1483 if Token_Name
= Name_Aliased
then
1484 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1485 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1486 Check_95_Keyword
(Tok_Aliased
, Tok_Constant
);
1491 if Token
= Tok_Constant
then
1492 Con_Loc
:= Token_Ptr
;
1493 Scan
; -- past CONSTANT
1495 -- Number declaration, initialization required
1497 Init_Expr
:= Init_Expr_Opt
;
1499 if Present
(Init_Expr
) then
1500 if Not_Null_Present
then
1502 ("`NOT NULL` not allowed in numeric expression");
1505 Decl_Node
:= New_Node
(N_Number_Declaration
, Ident_Sloc
);
1506 Set_Expression
(Decl_Node
, Init_Expr
);
1508 -- Constant object declaration
1511 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1512 Set_Constant_Present
(Decl_Node
, True);
1514 if Token_Name
= Name_Aliased
then
1515 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1516 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1519 if Token
= Tok_Aliased
then
1520 Error_Msg_SC
("ALIASED should be before CONSTANT");
1521 Scan
; -- past ALIASED
1522 Set_Aliased_Present
(Decl_Node
, True);
1525 if Token
= Tok_Array
then
1526 Set_Object_Definition
1527 (Decl_Node
, P_Array_Type_Definition
);
1530 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1531 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1533 if Token
= Tok_Access
then
1534 if Ada_Version
< Ada_05
then
1536 ("generalized use of anonymous access types " &
1537 "is an Ada 2005 extension");
1539 ("\unit must be compiled with -gnat05 switch");
1542 Set_Object_Definition
1543 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1545 Set_Object_Definition
1546 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1550 if Token
= Tok_Renames
then
1552 ("CONSTANT not permitted in renaming declaration",
1554 Scan
; -- Past renames
1555 Discard_Junk_Node
(P_Name
);
1561 elsif Token
= Tok_Exception
then
1562 Scan
; -- past EXCEPTION
1564 if Token_Is_Renames
then
1567 New_Node
(N_Exception_Renaming_Declaration
, Ident_Sloc
);
1568 Set_Name
(Decl_Node
, P_Qualified_Simple_Name_Resync
);
1571 Decl_Node
:= New_Node
(N_Exception_Declaration
, Prev_Token_Ptr
);
1574 -- Aliased case (note that an object definition is required)
1576 elsif Token
= Tok_Aliased
then
1577 Scan
; -- past ALIASED
1578 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1579 Set_Aliased_Present
(Decl_Node
, True);
1581 if Token
= Tok_Constant
then
1582 Scan
; -- past CONSTANT
1583 Set_Constant_Present
(Decl_Node
, True);
1586 if Token
= Tok_Array
then
1587 Set_Object_Definition
1588 (Decl_Node
, P_Array_Type_Definition
);
1591 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1592 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1594 -- Access definition (AI-406) or subtype indication
1596 if Token
= Tok_Access
then
1597 if Ada_Version
< Ada_05
then
1599 ("generalized use of anonymous access types " &
1600 "is an Ada 2005 extension");
1602 ("\unit must be compiled with -gnat05 switch");
1605 Set_Object_Definition
1606 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1608 Set_Object_Definition
1609 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1615 elsif Token
= Tok_Array
then
1616 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1617 Set_Object_Definition
(Decl_Node
, P_Array_Type_Definition
);
1619 -- Ada 2005 (AI-254, AI-406)
1621 elsif Token
= Tok_Not
then
1623 -- OBJECT_DECLARATION ::=
1624 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1625 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION];
1626 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1627 -- ACCESS_DEFINITION [:= EXPRESSION];
1629 -- OBJECT_RENAMING_DECLARATION ::=
1630 -- DEFINING_IDENTIFIER :
1631 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME;
1632 -- | DEFINING_IDENTIFIER :
1633 -- ACCESS_DEFINITION renames object_NAME;
1635 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/423)
1637 if Token
= Tok_Access
then
1638 if Ada_Version
< Ada_05
then
1640 ("generalized use of anonymous access types " &
1641 "is an Ada 2005 extension");
1642 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1645 Acc_Node
:= P_Access_Definition
(Not_Null_Present
);
1647 if Token
/= Tok_Renames
then
1648 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1649 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1652 Scan
; -- past renames
1655 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1656 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1657 Set_Name
(Decl_Node
, P_Name
);
1661 Type_Node
:= P_Subtype_Mark
;
1663 -- Object renaming declaration
1665 if Token_Is_Renames
then
1666 if Ada_Version
< Ada_05
then
1668 ("`NOT NULL` not allowed in object renaming");
1671 -- Ada 2005 (AI-423): Object renaming declaration with
1672 -- a null exclusion.
1677 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1678 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1679 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1680 Set_Name
(Decl_Node
, P_Name
);
1683 -- Object declaration
1686 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1687 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1688 Set_Object_Definition
1690 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1692 -- RENAMES at this point means that we had the combination
1693 -- of a constraint on the Type_Node and renames, which is
1696 if Token_Is_Renames
then
1697 Error_Msg_N
("constraint not allowed in object renaming "
1699 Constraint
(Object_Definition
(Decl_Node
)));
1705 -- Ada 2005 (AI-230): Access Definition case
1707 elsif Token
= Tok_Access
then
1708 if Ada_Version
< Ada_05
then
1710 ("generalized use of anonymous access types " &
1711 "is an Ada 2005 extension");
1712 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1715 Acc_Node
:= P_Access_Definition
(Null_Exclusion_Present
=> False);
1717 -- Object declaration with access definition, or renaming
1719 if Token
/= Tok_Renames
then
1720 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1721 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1724 Scan
; -- past renames
1727 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1728 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1729 Set_Name
(Decl_Node
, P_Name
);
1732 -- Subtype indication case
1735 Type_Node
:= P_Subtype_Mark
;
1737 -- Object renaming declaration
1739 if Token_Is_Renames
then
1742 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1743 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1744 Set_Name
(Decl_Node
, P_Name
);
1746 -- Object declaration
1749 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1750 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1751 Set_Object_Definition
1753 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1755 -- RENAMES at this point means that we had the combination of
1756 -- a constraint on the Type_Node and renames, which is illegal
1758 if Token_Is_Renames
then
1760 ("constraint not allowed in object renaming declaration",
1761 Constraint
(Object_Definition
(Decl_Node
)));
1767 -- Scan out initialization, allowed only for object declaration
1769 Init_Loc
:= Token_Ptr
;
1770 Init_Expr
:= Init_Expr_Opt
;
1772 if Present
(Init_Expr
) then
1773 if Nkind
(Decl_Node
) = N_Object_Declaration
then
1774 Set_Expression
(Decl_Node
, Init_Expr
);
1775 Set_Has_Init_Expression
(Decl_Node
);
1777 Error_Msg
("initialization not allowed here", Init_Loc
);
1782 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
1785 if Ident
< Num_Idents
then
1786 Set_More_Ids
(Decl_Node
, True);
1790 Set_Prev_Ids
(Decl_Node
, True);
1794 Append
(Decl_Node
, Decls
);
1795 exit Ident_Loop
when Ident
= Num_Idents
;
1796 Restore_Scan_State
(Scan_State
);
1799 end loop Ident_Loop
;
1802 end P_Identifier_Declarations
;
1804 -------------------------------
1805 -- 3.3.1 Object Declaration --
1806 -------------------------------
1808 -- OBJECT DECLARATION ::=
1809 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1810 -- SUBTYPE_INDICATION [:= EXPRESSION];
1811 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1812 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1813 -- | SINGLE_TASK_DECLARATION
1814 -- | SINGLE_PROTECTED_DECLARATION
1816 -- Cases starting with TASK are parsed by P_Task (9.1)
1817 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1818 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1820 -------------------------------------
1821 -- 3.3.1 Defining Identifier List --
1822 -------------------------------------
1824 -- DEFINING_IDENTIFIER_LIST ::=
1825 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1827 -- Always parsed by the construct in which it appears. See special
1828 -- section on "Handling of Defining Identifier Lists" in this unit.
1830 -------------------------------
1831 -- 3.3.2 Number Declaration --
1832 -------------------------------
1834 -- Parsed by P_Identifier_Declarations (3.3)
1836 -------------------------------------------------------------------------
1837 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
1838 -------------------------------------------------------------------------
1840 -- DERIVED_TYPE_DEFINITION ::=
1841 -- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
1842 -- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
1844 -- PRIVATE_EXTENSION_DECLARATION ::=
1845 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
1846 -- [abstract] [limited | synchronized]
1847 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
1850 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
1852 -- The caller has already scanned out the part up to the NEW, and Token
1853 -- either contains Tok_New (or ought to, if it doesn't this procedure
1854 -- will post an appropriate "NEW expected" message).
1856 -- Note: the caller is responsible for filling in the Sloc field of
1857 -- the returned node in the private extension declaration case as
1858 -- well as the stuff relating to the discriminant part.
1860 -- Error recovery: can raise Error_Resync;
1862 function P_Derived_Type_Def_Or_Private_Ext_Decl
return Node_Id
is
1863 Typedef_Node
: Node_Id
;
1864 Typedecl_Node
: Node_Id
;
1865 Not_Null_Present
: Boolean := False;
1868 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
1870 if Ada_Version
< Ada_05
1871 and then Token
= Tok_Identifier
1872 and then Token_Name
= Name_Interface
1875 ("abstract interface is an Ada 2005 extension");
1876 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1881 if Token
= Tok_Abstract
then
1882 Error_Msg_SC
("ABSTRACT must come before NEW, not after");
1886 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1887 Set_Null_Exclusion_Present
(Typedef_Node
, Not_Null_Present
);
1888 Set_Subtype_Indication
(Typedef_Node
,
1889 P_Subtype_Indication
(Not_Null_Present
));
1891 -- Ada 2005 (AI-251): Deal with interfaces
1893 if Token
= Tok_And
then
1896 if Ada_Version
< Ada_05
then
1898 ("abstract interface is an Ada 2005 extension");
1899 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1902 Set_Interface_List
(Typedef_Node
, New_List
);
1905 Append
(P_Qualified_Simple_Name
, Interface_List
(Typedef_Node
));
1906 exit when Token
/= Tok_And
;
1910 if Token
/= Tok_With
then
1911 Error_Msg_SC
("WITH expected");
1916 -- Deal with record extension, note that we assume that a WITH is
1917 -- missing in the case of "type X is new Y record ..." or in the
1918 -- case of "type X is new Y null record".
1921 or else Token
= Tok_Record
1922 or else Token
= Tok_Null
1924 T_With
; -- past WITH or give error message
1926 if Token
= Tok_Limited
then
1928 ("LIMITED keyword not allowed in private extension");
1929 Scan
; -- ignore LIMITED
1932 -- Private extension declaration
1934 if Token
= Tok_Private
then
1935 Scan
; -- past PRIVATE
1937 -- Throw away the type definition node and build the type
1938 -- declaration node. Note the caller must set the Sloc,
1939 -- Discriminant_Specifications, Unknown_Discriminants_Present,
1940 -- and Defined_Identifier fields in the returned node.
1943 Make_Private_Extension_Declaration
(No_Location
,
1944 Defining_Identifier
=> Empty
,
1945 Subtype_Indication
=> Subtype_Indication
(Typedef_Node
),
1946 Abstract_Present
=> Abstract_Present
(Typedef_Node
),
1947 Interface_List
=> Interface_List
(Typedef_Node
));
1949 return Typedecl_Node
;
1951 -- Derived type definition with record extension part
1954 Set_Record_Extension_Part
(Typedef_Node
, P_Record_Definition
);
1955 return Typedef_Node
;
1958 -- Derived type definition with no record extension part
1961 return Typedef_Node
;
1963 end P_Derived_Type_Def_Or_Private_Ext_Decl
;
1965 ---------------------------
1966 -- 3.5 Range Constraint --
1967 ---------------------------
1969 -- RANGE_CONSTRAINT ::= range RANGE
1971 -- The caller has checked that the initial token is RANGE
1973 -- Error recovery: cannot raise Error_Resync
1975 function P_Range_Constraint
return Node_Id
is
1976 Range_Node
: Node_Id
;
1979 Range_Node
:= New_Node
(N_Range_Constraint
, Token_Ptr
);
1981 Set_Range_Expression
(Range_Node
, P_Range
);
1983 end P_Range_Constraint
;
1990 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
1992 -- Note: the range that appears in a membership test is parsed by
1993 -- P_Range_Or_Subtype_Mark (3.5).
1995 -- Error recovery: cannot raise Error_Resync
1997 function P_Range
return Node_Id
is
1998 Expr_Node
: Node_Id
;
1999 Range_Node
: Node_Id
;
2002 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2004 if Expr_Form
= EF_Range_Attr
then
2007 elsif Token
= Tok_Dot_Dot
then
2008 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2009 Set_Low_Bound
(Range_Node
, Expr_Node
);
2011 Expr_Node
:= P_Expression
;
2012 Check_Simple_Expression
(Expr_Node
);
2013 Set_High_Bound
(Range_Node
, Expr_Node
);
2016 -- Anything else is an error
2019 T_Dot_Dot
; -- force missing .. message
2024 ----------------------------------
2025 -- 3.5 P_Range_Or_Subtype_Mark --
2026 ----------------------------------
2029 -- RANGE_ATTRIBUTE_REFERENCE
2030 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2032 -- This routine scans out the range or subtype mark that forms the right
2033 -- operand of a membership test (it is not used in any other contexts, and
2034 -- error messages are specialized with this knowledge in mind).
2036 -- Note: as documented in the Sinfo interface, although the syntax only
2037 -- allows a subtype mark, we in fact allow any simple expression to be
2038 -- returned from this routine. The semantics is responsible for issuing
2039 -- an appropriate message complaining if the argument is not a name.
2040 -- This simplifies the coding and error recovery processing in the
2041 -- parser, and in any case it is preferable not to consider this a
2042 -- syntax error and to continue with the semantic analysis.
2044 -- Error recovery: cannot raise Error_Resync
2046 function P_Range_Or_Subtype_Mark
return Node_Id
is
2047 Expr_Node
: Node_Id
;
2048 Range_Node
: Node_Id
;
2049 Save_Loc
: Source_Ptr
;
2051 -- Start of processing for P_Range_Or_Subtype_Mark
2054 -- Save location of possible junk parentheses
2056 Save_Loc
:= Token_Ptr
;
2058 -- Scan out either a simple expression or a range (this accepts more
2059 -- than is legal here, but as explained above, we like to allow more
2060 -- with a proper diagnostic.
2062 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2066 if Expr_Form
= EF_Range_Attr
then
2069 -- Simple_Expression .. Simple_Expression
2071 elsif Token
= Tok_Dot_Dot
then
2072 Check_Simple_Expression
(Expr_Node
);
2073 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2074 Set_Low_Bound
(Range_Node
, Expr_Node
);
2076 Set_High_Bound
(Range_Node
, P_Simple_Expression
);
2079 -- Case of subtype mark (optionally qualified simple name or an
2080 -- attribute whose prefix is an optionally qualified simple name)
2082 elsif Expr_Form
= EF_Simple_Name
2083 or else Nkind
(Expr_Node
) = N_Attribute_Reference
2085 -- Check for error of range constraint after a subtype mark
2087 if Token
= Tok_Range
then
2088 Error_Msg_SC
("range constraint not allowed in membership test");
2092 -- Check for error of DIGITS or DELTA after a subtype mark
2094 elsif Token
= Tok_Digits
or else Token
= Tok_Delta
then
2096 ("accuracy definition not allowed in membership test");
2097 Scan
; -- past DIGITS or DELTA
2100 -- Attribute reference, may or may not be OK, but in any case we
2103 elsif Token
= Tok_Apostrophe
then
2104 return P_Subtype_Mark_Attribute
(Expr_Node
);
2106 -- OK case of simple name, just return it
2112 -- Here we have some kind of error situation. Check for junk parens
2113 -- then return what we have, caller will deal with other errors.
2116 if Nkind
(Expr_Node
) in N_Subexpr
2117 and then Paren_Count
(Expr_Node
) /= 0
2119 Error_Msg
("|parentheses not allowed for subtype mark", Save_Loc
);
2120 Set_Paren_Count
(Expr_Node
, 0);
2125 end P_Range_Or_Subtype_Mark
;
2127 ----------------------------------------
2128 -- 3.5.1 Enumeration Type Definition --
2129 ----------------------------------------
2131 -- ENUMERATION_TYPE_DEFINITION ::=
2132 -- (ENUMERATION_LITERAL_SPECIFICATION
2133 -- {, ENUMERATION_LITERAL_SPECIFICATION})
2135 -- The caller has already scanned out the TYPE keyword
2137 -- Error recovery: can raise Error_Resync;
2139 function P_Enumeration_Type_Definition
return Node_Id
is
2140 Typedef_Node
: Node_Id
;
2143 Typedef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Token_Ptr
);
2144 Set_Literals
(Typedef_Node
, New_List
);
2149 Append
(P_Enumeration_Literal_Specification
, Literals
(Typedef_Node
));
2150 exit when not Comma_Present
;
2154 return Typedef_Node
;
2155 end P_Enumeration_Type_Definition
;
2157 ----------------------------------------------
2158 -- 3.5.1 Enumeration Literal Specification --
2159 ----------------------------------------------
2161 -- ENUMERATION_LITERAL_SPECIFICATION ::=
2162 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
2164 -- Error recovery: can raise Error_Resync
2166 function P_Enumeration_Literal_Specification
return Node_Id
is
2168 if Token
= Tok_Char_Literal
then
2169 return P_Defining_Character_Literal
;
2171 return P_Defining_Identifier
(C_Comma_Right_Paren
);
2173 end P_Enumeration_Literal_Specification
;
2175 ---------------------------------------
2176 -- 3.5.1 Defining_Character_Literal --
2177 ---------------------------------------
2179 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
2181 -- Error recovery: cannot raise Error_Resync
2183 -- The caller has checked that the current token is a character literal
2185 function P_Defining_Character_Literal
return Node_Id
is
2186 Literal_Node
: Node_Id
;
2189 Literal_Node
:= Token_Node
;
2190 Change_Character_Literal_To_Defining_Character_Literal
(Literal_Node
);
2191 Scan
; -- past character literal
2192 return Literal_Node
;
2193 end P_Defining_Character_Literal
;
2195 ------------------------------------
2196 -- 3.5.4 Integer Type Definition --
2197 ------------------------------------
2199 -- Parsed by P_Type_Declaration (3.2.1)
2201 -------------------------------------------
2202 -- 3.5.4 Signed Integer Type Definition --
2203 -------------------------------------------
2205 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
2206 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2208 -- Normally the initial token on entry is RANGE, but in some
2209 -- error conditions, the range token was missing and control is
2210 -- passed with Token pointing to first token of the first expression.
2212 -- Error recovery: cannot raise Error_Resync
2214 function P_Signed_Integer_Type_Definition
return Node_Id
is
2215 Typedef_Node
: Node_Id
;
2216 Expr_Node
: Node_Id
;
2219 Typedef_Node
:= New_Node
(N_Signed_Integer_Type_Definition
, Token_Ptr
);
2221 if Token
= Tok_Range
then
2225 Expr_Node
:= P_Expression
;
2226 Check_Simple_Expression
(Expr_Node
);
2227 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2229 Expr_Node
:= P_Expression
;
2230 Check_Simple_Expression
(Expr_Node
);
2231 Set_High_Bound
(Typedef_Node
, Expr_Node
);
2232 return Typedef_Node
;
2233 end P_Signed_Integer_Type_Definition
;
2235 ------------------------------------
2236 -- 3.5.4 Modular Type Definition --
2237 ------------------------------------
2239 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
2241 -- The caller has checked that the initial token is MOD
2243 -- Error recovery: cannot raise Error_Resync
2245 function P_Modular_Type_Definition
return Node_Id
is
2246 Typedef_Node
: Node_Id
;
2249 if Ada_Version
= Ada_83
then
2250 Error_Msg_SC
("(Ada 83): modular types not allowed");
2253 Typedef_Node
:= New_Node
(N_Modular_Type_Definition
, Token_Ptr
);
2255 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2257 -- Handle mod L..R cleanly
2259 if Token
= Tok_Dot_Dot
then
2260 Error_Msg_SC
("range not allowed for modular type");
2262 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2265 return Typedef_Node
;
2266 end P_Modular_Type_Definition
;
2268 ---------------------------------
2269 -- 3.5.6 Real Type Definition --
2270 ---------------------------------
2272 -- Parsed by P_Type_Declaration (3.2.1)
2274 --------------------------------------
2275 -- 3.5.7 Floating Point Definition --
2276 --------------------------------------
2278 -- FLOATING_POINT_DEFINITION ::=
2279 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2281 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
2283 -- The caller has checked that the initial token is DIGITS
2285 -- Error recovery: cannot raise Error_Resync
2287 function P_Floating_Point_Definition
return Node_Id
is
2288 Digits_Loc
: constant Source_Ptr
:= Token_Ptr
;
2290 Expr_Node
: Node_Id
;
2293 Scan
; -- past DIGITS
2294 Expr_Node
:= P_Expression_No_Right_Paren
;
2295 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2297 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
2299 if Token
= Tok_Delta
then
2300 Error_Msg_SC
("|DELTA must come before DIGITS");
2301 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Digits_Loc
);
2303 Set_Delta_Expression
(Def_Node
, P_Expression_No_Right_Paren
);
2305 -- OK floating-point definition
2308 Def_Node
:= New_Node
(N_Floating_Point_Definition
, Digits_Loc
);
2311 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2312 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2314 end P_Floating_Point_Definition
;
2316 -------------------------------------
2317 -- 3.5.7 Real Range Specification --
2318 -------------------------------------
2320 -- REAL_RANGE_SPECIFICATION ::=
2321 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2323 -- Error recovery: cannot raise Error_Resync
2325 function P_Real_Range_Specification_Opt
return Node_Id
is
2326 Specification_Node
: Node_Id
;
2327 Expr_Node
: Node_Id
;
2330 if Token
= Tok_Range
then
2331 Specification_Node
:=
2332 New_Node
(N_Real_Range_Specification
, Token_Ptr
);
2334 Expr_Node
:= P_Expression_No_Right_Paren
;
2335 Check_Simple_Expression
(Expr_Node
);
2336 Set_Low_Bound
(Specification_Node
, Expr_Node
);
2338 Expr_Node
:= P_Expression_No_Right_Paren
;
2339 Check_Simple_Expression
(Expr_Node
);
2340 Set_High_Bound
(Specification_Node
, Expr_Node
);
2341 return Specification_Node
;
2345 end P_Real_Range_Specification_Opt
;
2347 -----------------------------------
2348 -- 3.5.9 Fixed Point Definition --
2349 -----------------------------------
2351 -- FIXED_POINT_DEFINITION ::=
2352 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
2354 -- ORDINARY_FIXED_POINT_DEFINITION ::=
2355 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
2357 -- DECIMAL_FIXED_POINT_DEFINITION ::=
2358 -- delta static_EXPRESSION
2359 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2361 -- The caller has checked that the initial token is DELTA
2363 -- Error recovery: cannot raise Error_Resync
2365 function P_Fixed_Point_Definition
return Node_Id
is
2366 Delta_Node
: Node_Id
;
2367 Delta_Loc
: Source_Ptr
;
2369 Expr_Node
: Node_Id
;
2372 Delta_Loc
:= Token_Ptr
;
2374 Delta_Node
:= P_Expression_No_Right_Paren
;
2375 Check_Simple_Expression_In_Ada_83
(Delta_Node
);
2377 if Token
= Tok_Digits
then
2378 if Ada_Version
= Ada_83
then
2379 Error_Msg_SC
("(Ada 83) decimal fixed type not allowed!");
2382 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Delta_Loc
);
2383 Scan
; -- past DIGITS
2384 Expr_Node
:= P_Expression_No_Right_Paren
;
2385 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2386 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2389 Def_Node
:= New_Node
(N_Ordinary_Fixed_Point_Definition
, Delta_Loc
);
2391 -- Range is required in ordinary fixed point case
2393 if Token
/= Tok_Range
then
2394 Error_Msg_AP
("range must be given for fixed-point type");
2399 Set_Delta_Expression
(Def_Node
, Delta_Node
);
2400 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2402 end P_Fixed_Point_Definition
;
2404 --------------------------------------------
2405 -- 3.5.9 Ordinary Fixed Point Definition --
2406 --------------------------------------------
2408 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2410 -------------------------------------------
2411 -- 3.5.9 Decimal Fixed Point Definition --
2412 -------------------------------------------
2414 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2416 ------------------------------
2417 -- 3.5.9 Digits Constraint --
2418 ------------------------------
2420 -- DIGITS_CONSTRAINT ::=
2421 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2423 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2425 -- The caller has checked that the initial token is DIGITS
2427 function P_Digits_Constraint
return Node_Id
is
2428 Constraint_Node
: Node_Id
;
2429 Expr_Node
: Node_Id
;
2432 Constraint_Node
:= New_Node
(N_Digits_Constraint
, Token_Ptr
);
2433 Scan
; -- past DIGITS
2434 Expr_Node
:= P_Expression
;
2435 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2436 Set_Digits_Expression
(Constraint_Node
, Expr_Node
);
2438 if Token
= Tok_Range
then
2439 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2442 return Constraint_Node
;
2443 end P_Digits_Constraint
;
2445 -----------------------------
2446 -- 3.5.9 Delta Constraint --
2447 -----------------------------
2449 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2451 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2453 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2455 -- The caller has checked that the initial token is DELTA
2457 -- Error recovery: cannot raise Error_Resync
2459 function P_Delta_Constraint
return Node_Id
is
2460 Constraint_Node
: Node_Id
;
2461 Expr_Node
: Node_Id
;
2464 Constraint_Node
:= New_Node
(N_Delta_Constraint
, Token_Ptr
);
2466 Expr_Node
:= P_Expression
;
2467 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2468 Set_Delta_Expression
(Constraint_Node
, Expr_Node
);
2470 if Token
= Tok_Range
then
2471 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2474 return Constraint_Node
;
2475 end P_Delta_Constraint
;
2477 --------------------------------
2478 -- 3.6 Array Type Definition --
2479 --------------------------------
2481 -- ARRAY_TYPE_DEFINITION ::=
2482 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2484 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2485 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2486 -- COMPONENT_DEFINITION
2488 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2490 -- CONSTRAINED_ARRAY_DEFINITION ::=
2491 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2492 -- COMPONENT_DEFINITION
2494 -- DISCRETE_SUBTYPE_DEFINITION ::=
2495 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2497 -- COMPONENT_DEFINITION ::=
2498 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2500 -- The caller has checked that the initial token is ARRAY
2502 -- Error recovery: can raise Error_Resync
2504 function P_Array_Type_Definition
return Node_Id
is
2505 Array_Loc
: Source_Ptr
;
2506 CompDef_Node
: Node_Id
;
2508 Not_Null_Present
: Boolean := False;
2509 Subs_List
: List_Id
;
2510 Scan_State
: Saved_Scan_State
;
2511 Aliased_Present
: Boolean := False;
2514 Array_Loc
:= Token_Ptr
;
2516 Subs_List
:= New_List
;
2519 -- It's quite tricky to disentangle these two possibilities, so we do
2520 -- a prescan to determine which case we have and then reset the scan.
2521 -- The prescan skips past possible subtype mark tokens.
2523 Save_Scan_State
(Scan_State
); -- just after paren
2525 while Token
in Token_Class_Desig
or else
2526 Token
= Tok_Dot
or else
2527 Token
= Tok_Apostrophe
-- because of 'BASE, 'CLASS
2532 -- If we end up on RANGE <> then we have the unconstrained case. We
2533 -- will also allow the RANGE to be omitted, just to improve error
2534 -- handling for a case like array (integer <>) of integer;
2536 Scan
; -- past possible RANGE or <>
2538 if (Prev_Token
= Tok_Range
and then Token
= Tok_Box
) or else
2539 Prev_Token
= Tok_Box
2541 Def_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Array_Loc
);
2542 Restore_Scan_State
(Scan_State
); -- to first subtype mark
2545 Append
(P_Subtype_Mark_Resync
, Subs_List
);
2548 exit when Token
= Tok_Right_Paren
or else Token
= Tok_Of
;
2552 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2555 Def_Node
:= New_Node
(N_Constrained_Array_Definition
, Array_Loc
);
2556 Restore_Scan_State
(Scan_State
); -- to first discrete range
2559 Append
(P_Discrete_Subtype_Definition
, Subs_List
);
2560 exit when not Comma_Present
;
2563 Set_Discrete_Subtype_Definitions
(Def_Node
, Subs_List
);
2569 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
2571 if Token_Name
= Name_Aliased
then
2572 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
2575 if Token
= Tok_Aliased
then
2576 Aliased_Present
:= True;
2577 Scan
; -- past ALIASED
2580 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
2582 -- Ada 2005 (AI-230): Access Definition case
2584 if Token
= Tok_Access
then
2585 if Ada_Version
< Ada_05
then
2587 ("generalized use of anonymous access types " &
2588 "is an Ada 2005 extension");
2589 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2592 if Aliased_Present
then
2593 Error_Msg_SP
("ALIASED not allowed here");
2596 Set_Subtype_Indication
(CompDef_Node
, Empty
);
2597 Set_Aliased_Present
(CompDef_Node
, False);
2598 Set_Access_Definition
(CompDef_Node
,
2599 P_Access_Definition
(Not_Null_Present
));
2602 Set_Access_Definition
(CompDef_Node
, Empty
);
2603 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2604 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
2605 Set_Subtype_Indication
(CompDef_Node
,
2606 P_Subtype_Indication
(Not_Null_Present
));
2609 Set_Component_Definition
(Def_Node
, CompDef_Node
);
2612 end P_Array_Type_Definition
;
2614 -----------------------------------------
2615 -- 3.6 Unconstrained Array Definition --
2616 -----------------------------------------
2618 -- Parsed by P_Array_Type_Definition (3.6)
2620 ---------------------------------------
2621 -- 3.6 Constrained Array Definition --
2622 ---------------------------------------
2624 -- Parsed by P_Array_Type_Definition (3.6)
2626 --------------------------------------
2627 -- 3.6 Discrete Subtype Definition --
2628 --------------------------------------
2630 -- DISCRETE_SUBTYPE_DEFINITION ::=
2631 -- discrete_SUBTYPE_INDICATION | RANGE
2633 -- Note: the discrete subtype definition appearing in a constrained
2634 -- array definition is parsed by P_Array_Type_Definition (3.6)
2636 -- Error recovery: cannot raise Error_Resync
2638 function P_Discrete_Subtype_Definition
return Node_Id
is
2640 -- The syntax of a discrete subtype definition is identical to that
2641 -- of a discrete range, so we simply share the same parsing code.
2643 return P_Discrete_Range
;
2644 end P_Discrete_Subtype_Definition
;
2646 -------------------------------
2647 -- 3.6 Component Definition --
2648 -------------------------------
2650 -- For the array case, parsed by P_Array_Type_Definition (3.6)
2651 -- For the record case, parsed by P_Component_Declaration (3.8)
2653 -----------------------------
2654 -- 3.6.1 Index Constraint --
2655 -----------------------------
2657 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2659 ---------------------------
2660 -- 3.6.1 Discrete Range --
2661 ---------------------------
2663 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
2665 -- The possible forms for a discrete range are:
2667 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
2668 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
2669 -- Range_Attribute (RANGE, 3.5)
2670 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
2672 -- Error recovery: cannot raise Error_Resync
2674 function P_Discrete_Range
return Node_Id
is
2675 Expr_Node
: Node_Id
;
2676 Range_Node
: Node_Id
;
2679 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2681 if Expr_Form
= EF_Range_Attr
then
2684 elsif Token
= Tok_Range
then
2685 if Expr_Form
/= EF_Simple_Name
then
2686 Error_Msg_SC
("range must be preceded by subtype mark");
2689 return P_Subtype_Indication
(Expr_Node
);
2691 -- Check Expression .. Expression case
2693 elsif Token
= Tok_Dot_Dot
then
2694 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2695 Set_Low_Bound
(Range_Node
, Expr_Node
);
2697 Expr_Node
:= P_Expression
;
2698 Check_Simple_Expression
(Expr_Node
);
2699 Set_High_Bound
(Range_Node
, Expr_Node
);
2702 -- Otherwise we must have a subtype mark
2704 elsif Expr_Form
= EF_Simple_Name
then
2707 -- If incorrect, complain that we expect ..
2713 end P_Discrete_Range
;
2715 ----------------------------
2716 -- 3.7 Discriminant Part --
2717 ----------------------------
2719 -- DISCRIMINANT_PART ::=
2720 -- UNKNOWN_DISCRIMINANT_PART
2721 -- | KNOWN_DISCRIMINANT_PART
2723 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
2724 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
2726 ------------------------------------
2727 -- 3.7 Unknown Discriminant Part --
2728 ------------------------------------
2730 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
2732 -- If no unknown discriminant part is present, then False is returned,
2733 -- otherwise the unknown discriminant is scanned out and True is returned.
2735 -- Error recovery: cannot raise Error_Resync
2737 function P_Unknown_Discriminant_Part_Opt
return Boolean is
2738 Scan_State
: Saved_Scan_State
;
2741 -- If <> right now, then this is missing left paren
2743 if Token
= Tok_Box
then
2746 -- If not <> or left paren, then definitely no box
2748 elsif Token
/= Tok_Left_Paren
then
2751 -- Left paren, so might be a box after it
2754 Save_Scan_State
(Scan_State
);
2755 Scan
; -- past the left paren
2757 if Token
/= Tok_Box
then
2758 Restore_Scan_State
(Scan_State
);
2763 -- We are now pointing to the box
2765 if Ada_Version
= Ada_83
then
2766 Error_Msg_SC
("(Ada 83) unknown discriminant not allowed!");
2769 Scan
; -- past the box
2770 U_Right_Paren
; -- must be followed by right paren
2772 end P_Unknown_Discriminant_Part_Opt
;
2774 ----------------------------------
2775 -- 3.7 Known Discriminant Part --
2776 ----------------------------------
2778 -- KNOWN_DISCRIMINANT_PART ::=
2779 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
2781 -- DISCRIMINANT_SPECIFICATION ::=
2782 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
2783 -- [:= DEFAULT_EXPRESSION]
2784 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
2785 -- [:= DEFAULT_EXPRESSION]
2787 -- If no known discriminant part is present, then No_List is returned
2789 -- Error recovery: cannot raise Error_Resync
2791 function P_Known_Discriminant_Part_Opt
return List_Id
is
2792 Specification_Node
: Node_Id
;
2793 Specification_List
: List_Id
;
2794 Ident_Sloc
: Source_Ptr
;
2795 Scan_State
: Saved_Scan_State
;
2797 Not_Null_Present
: Boolean;
2800 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
2801 -- This array holds the list of defining identifiers. The upper bound
2802 -- of 4096 is intended to be essentially infinite, and we do not even
2803 -- bother to check for it being exceeded.
2806 if Token
= Tok_Left_Paren
then
2807 Specification_List
:= New_List
;
2809 P_Pragmas_Misplaced
;
2811 Specification_Loop
: loop
2813 Ident_Sloc
:= Token_Ptr
;
2814 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
2817 while Comma_Present
loop
2818 Num_Idents
:= Num_Idents
+ 1;
2819 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
2822 -- If there are multiple identifiers, we repeatedly scan the
2823 -- type and initialization expression information by resetting
2824 -- the scan pointer (so that we get completely separate trees
2825 -- for each occurrence).
2827 if Num_Idents
> 1 then
2828 Save_Scan_State
(Scan_State
);
2833 -- Loop through defining identifiers in list
2837 Specification_Node
:=
2838 New_Node
(N_Discriminant_Specification
, Ident_Sloc
);
2839 Set_Defining_Identifier
(Specification_Node
, Idents
(Ident
));
2840 Not_Null_Present
:= -- Ada 2005 (AI-231, AI-447)
2841 P_Null_Exclusion
(Allow_Anonymous_In_95
=> True);
2843 if Token
= Tok_Access
then
2844 if Ada_Version
= Ada_83
then
2846 ("(Ada 83) access discriminant not allowed!");
2849 Set_Discriminant_Type
2850 (Specification_Node
,
2851 P_Access_Definition
(Not_Null_Present
));
2854 Set_Discriminant_Type
2855 (Specification_Node
, P_Subtype_Mark
);
2857 Set_Null_Exclusion_Present
-- Ada 2005 (AI-231)
2858 (Specification_Node
, Not_Null_Present
);
2862 (Specification_Node
, Init_Expr_Opt
(True));
2865 Set_Prev_Ids
(Specification_Node
, True);
2868 if Ident
< Num_Idents
then
2869 Set_More_Ids
(Specification_Node
, True);
2872 Append
(Specification_Node
, Specification_List
);
2873 exit Ident_Loop
when Ident
= Num_Idents
;
2875 Restore_Scan_State
(Scan_State
);
2877 end loop Ident_Loop
;
2879 exit Specification_Loop
when Token
/= Tok_Semicolon
;
2881 P_Pragmas_Misplaced
;
2882 end loop Specification_Loop
;
2885 return Specification_List
;
2890 end P_Known_Discriminant_Part_Opt
;
2892 -------------------------------------
2893 -- 3.7 Discriminant Specification --
2894 -------------------------------------
2896 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
2898 -----------------------------
2899 -- 3.7 Default Expression --
2900 -----------------------------
2902 -- Always parsed (simply as an Expression) by the parent construct
2904 ------------------------------------
2905 -- 3.7.1 Discriminant Constraint --
2906 ------------------------------------
2908 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2910 --------------------------------------------------------
2911 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
2912 --------------------------------------------------------
2914 -- DISCRIMINANT_CONSTRAINT ::=
2915 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
2917 -- DISCRIMINANT_ASSOCIATION ::=
2918 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
2921 -- This routine parses either an index or a discriminant constraint. As
2922 -- is clear from the above grammar, it is often possible to clearly
2923 -- determine which of the two possibilities we have, but there are
2924 -- cases (those in which we have a series of expressions of the same
2925 -- syntactic form as subtype indications), where we cannot tell. Since
2926 -- this means that in any case the semantic phase has to distinguish
2927 -- between the two, there is not much point in the parser trying to
2928 -- distinguish even those cases where the difference is clear. In any
2929 -- case, if we have a situation like:
2931 -- (A => 123, 235 .. 500)
2933 -- it is not clear which of the two items is the wrong one, better to
2934 -- let the semantic phase give a clear message. Consequently, this
2935 -- routine in general returns a list of items which can be either
2936 -- discrete ranges or discriminant associations.
2938 -- The caller has checked that the initial token is a left paren
2940 -- Error recovery: can raise Error_Resync
2942 function P_Index_Or_Discriminant_Constraint
return Node_Id
is
2943 Scan_State
: Saved_Scan_State
;
2944 Constr_Node
: Node_Id
;
2945 Constr_List
: List_Id
;
2946 Expr_Node
: Node_Id
;
2947 Result_Node
: Node_Id
;
2950 Result_Node
:= New_Node
(N_Index_Or_Discriminant_Constraint
, Token_Ptr
);
2952 Constr_List
:= New_List
;
2953 Set_Constraints
(Result_Node
, Constr_List
);
2955 -- The two syntactic forms are a little mixed up, so what we are doing
2956 -- here is looking at the first entry to determine which case we have
2958 -- A discriminant constraint is a list of discriminant associations,
2959 -- which have one of the following possible forms:
2963 -- Id | Id | .. | Id => Expression
2965 -- An index constraint is a list of discrete ranges which have one
2966 -- of the following possible forms:
2969 -- Subtype_Mark range Range
2971 -- Simple_Expression .. Simple_Expression
2973 -- Loop through discriminants in list
2976 -- Check cases of Id => Expression or Id | Id => Expression
2978 if Token
= Tok_Identifier
then
2979 Save_Scan_State
(Scan_State
); -- at Id
2982 if Token
= Tok_Arrow
or else Token
= Tok_Vertical_Bar
then
2983 Restore_Scan_State
(Scan_State
); -- to Id
2984 Append
(P_Discriminant_Association
, Constr_List
);
2987 Restore_Scan_State
(Scan_State
); -- to Id
2991 -- Otherwise scan out an expression and see what we have got
2993 Expr_Node
:= P_Expression_Or_Range_Attribute
;
2995 if Expr_Form
= EF_Range_Attr
then
2996 Append
(Expr_Node
, Constr_List
);
2998 elsif Token
= Tok_Range
then
2999 if Expr_Form
/= EF_Simple_Name
then
3000 Error_Msg_SC
("subtype mark required before RANGE");
3003 Append
(P_Subtype_Indication
(Expr_Node
), Constr_List
);
3006 -- Check Simple_Expression .. Simple_Expression case
3008 elsif Token
= Tok_Dot_Dot
then
3009 Check_Simple_Expression
(Expr_Node
);
3010 Constr_Node
:= New_Node
(N_Range
, Token_Ptr
);
3011 Set_Low_Bound
(Constr_Node
, Expr_Node
);
3013 Expr_Node
:= P_Expression
;
3014 Check_Simple_Expression
(Expr_Node
);
3015 Set_High_Bound
(Constr_Node
, Expr_Node
);
3016 Append
(Constr_Node
, Constr_List
);
3019 -- Case of an expression which could be either form
3022 Append
(Expr_Node
, Constr_List
);
3026 -- Here with a single entry scanned
3029 exit when not Comma_Present
;
3035 end P_Index_Or_Discriminant_Constraint
;
3037 -------------------------------------
3038 -- 3.7.1 Discriminant Association --
3039 -------------------------------------
3041 -- DISCRIMINANT_ASSOCIATION ::=
3042 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3045 -- This routine is used only when the name list is present and the caller
3046 -- has already checked this (by scanning ahead and repositioning the
3049 -- Error_Recovery: cannot raise Error_Resync;
3051 function P_Discriminant_Association
return Node_Id
is
3052 Discr_Node
: Node_Id
;
3053 Names_List
: List_Id
;
3054 Ident_Sloc
: Source_Ptr
;
3057 Ident_Sloc
:= Token_Ptr
;
3058 Names_List
:= New_List
;
3061 Append
(P_Identifier
(C_Vertical_Bar_Arrow
), Names_List
);
3062 exit when Token
/= Tok_Vertical_Bar
;
3066 Discr_Node
:= New_Node
(N_Discriminant_Association
, Ident_Sloc
);
3067 Set_Selector_Names
(Discr_Node
, Names_List
);
3069 Set_Expression
(Discr_Node
, P_Expression
);
3071 end P_Discriminant_Association
;
3073 ---------------------------------
3074 -- 3.8 Record Type Definition --
3075 ---------------------------------
3077 -- RECORD_TYPE_DEFINITION ::=
3078 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3080 -- There is no node in the tree for a record type definition. Instead
3081 -- a record definition node appears, with possible Abstract_Present,
3082 -- Tagged_Present, and Limited_Present flags set appropriately.
3084 ----------------------------
3085 -- 3.8 Record Definition --
3086 ----------------------------
3088 -- RECORD_DEFINITION ::=
3094 -- Note: in the case where a record definition node is used to represent
3095 -- a record type definition, the caller sets the Tagged_Present and
3096 -- Limited_Present flags in the resulting N_Record_Definition node as
3099 -- Note that the RECORD token at the start may be missing in certain
3100 -- error situations, so this function is expected to post the error
3102 -- Error recovery: can raise Error_Resync
3104 function P_Record_Definition
return Node_Id
is
3108 Rec_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3112 if Token
= Tok_Null
then
3115 Set_Null_Present
(Rec_Node
, True);
3117 -- Catch incomplete declaration to prevent cascaded errors, see
3118 -- ACATS B393002 for an example.
3120 elsif Token
= Tok_Semicolon
then
3121 Error_Msg_AP
("missing record definition");
3123 -- Case starting with RECORD keyword. Build scope stack entry. For the
3124 -- column, we use the first non-blank character on the line, to deal
3125 -- with situations such as:
3131 -- which is not official RM indentation, but is not uncommon usage, and
3132 -- in particular is standard GNAT coding style, so handle it nicely.
3136 Scope
.Table
(Scope
.Last
).Etyp
:= E_Record
;
3137 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3138 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3139 Scope
.Table
(Scope
.Last
).Labl
:= Error
;
3140 Scope
.Table
(Scope
.Last
).Junk
:= (Token
/= Tok_Record
);
3144 Set_Component_List
(Rec_Node
, P_Component_List
);
3147 exit when Check_End
;
3148 Discard_Junk_Node
(P_Component_List
);
3153 end P_Record_Definition
;
3155 -------------------------
3156 -- 3.8 Component List --
3157 -------------------------
3159 -- COMPONENT_LIST ::=
3160 -- COMPONENT_ITEM {COMPONENT_ITEM}
3161 -- | {COMPONENT_ITEM} VARIANT_PART
3164 -- Error recovery: cannot raise Error_Resync
3166 function P_Component_List
return Node_Id
is
3167 Component_List_Node
: Node_Id
;
3168 Decls_List
: List_Id
;
3169 Scan_State
: Saved_Scan_State
;
3172 Component_List_Node
:= New_Node
(N_Component_List
, Token_Ptr
);
3173 Decls_List
:= New_List
;
3175 if Token
= Tok_Null
then
3178 P_Pragmas_Opt
(Decls_List
);
3179 Set_Null_Present
(Component_List_Node
, True);
3180 return Component_List_Node
;
3183 P_Pragmas_Opt
(Decls_List
);
3185 if Token
/= Tok_Case
then
3186 Component_Scan_Loop
: loop
3187 P_Component_Items
(Decls_List
);
3188 P_Pragmas_Opt
(Decls_List
);
3190 exit Component_Scan_Loop
when Token
= Tok_End
3191 or else Token
= Tok_Case
3192 or else Token
= Tok_When
;
3194 -- We are done if we do not have an identifier. However, if
3195 -- we have a misspelled reserved identifier that is in a column
3196 -- to the right of the record definition, we will treat it as
3197 -- an identifier. It turns out to be too dangerous in practice
3198 -- to accept such a mis-spelled identifier which does not have
3199 -- this additional clue that confirms the incorrect spelling.
3201 if Token
/= Tok_Identifier
then
3202 if Start_Column
> Scope
.Table
(Scope
.Last
).Ecol
3203 and then Is_Reserved_Identifier
3205 Save_Scan_State
(Scan_State
); -- at reserved id
3206 Scan
; -- possible reserved id
3208 if Token
= Tok_Comma
or else Token
= Tok_Colon
then
3209 Restore_Scan_State
(Scan_State
);
3210 Scan_Reserved_Identifier
(Force_Msg
=> True);
3212 -- Note reserved identifier used as field name after
3213 -- all because not followed by colon or comma
3216 Restore_Scan_State
(Scan_State
);
3217 exit Component_Scan_Loop
;
3220 -- Non-identifier that definitely was not reserved id
3223 exit Component_Scan_Loop
;
3226 end loop Component_Scan_Loop
;
3229 if Token
= Tok_Case
then
3230 Set_Variant_Part
(Component_List_Node
, P_Variant_Part
);
3232 -- Check for junk after variant part
3234 if Token
= Tok_Identifier
then
3235 Save_Scan_State
(Scan_State
);
3236 Scan
; -- past identifier
3238 if Token
= Tok_Colon
then
3239 Restore_Scan_State
(Scan_State
);
3240 Error_Msg_SC
("component may not follow variant part");
3241 Discard_Junk_Node
(P_Component_List
);
3243 elsif Token
= Tok_Case
then
3244 Restore_Scan_State
(Scan_State
);
3245 Error_Msg_SC
("only one variant part allowed in a record");
3246 Discard_Junk_Node
(P_Component_List
);
3249 Restore_Scan_State
(Scan_State
);
3255 Set_Component_Items
(Component_List_Node
, Decls_List
);
3256 return Component_List_Node
;
3257 end P_Component_List
;
3259 -------------------------
3260 -- 3.8 Component Item --
3261 -------------------------
3263 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3265 -- COMPONENT_DECLARATION ::=
3266 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3267 -- [:= DEFAULT_EXPRESSION];
3269 -- COMPONENT_DEFINITION ::=
3270 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3272 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3273 -- the scan is positioned past the following semicolon.
3275 -- Note: we do not yet allow representation clauses to appear as component
3276 -- items, do we need to add this capability sometime in the future ???
3278 procedure P_Component_Items
(Decls
: List_Id
) is
3279 Aliased_Present
: Boolean := False;
3280 CompDef_Node
: Node_Id
;
3281 Decl_Node
: Node_Id
;
3282 Scan_State
: Saved_Scan_State
;
3283 Not_Null_Present
: Boolean := False;
3286 Ident_Sloc
: Source_Ptr
;
3288 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3289 -- This array holds the list of defining identifiers. The upper bound
3290 -- of 4096 is intended to be essentially infinite, and we do not even
3291 -- bother to check for it being exceeded.
3294 if Token
/= Tok_Identifier
then
3295 Error_Msg_SC
("component declaration expected");
3296 Resync_Past_Semicolon
;
3300 Ident_Sloc
:= Token_Ptr
;
3301 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3304 while Comma_Present
loop
3305 Num_Idents
:= Num_Idents
+ 1;
3306 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3309 -- If there are multiple identifiers, we repeatedly scan the
3310 -- type and initialization expression information by resetting
3311 -- the scan pointer (so that we get completely separate trees
3312 -- for each occurrence).
3314 if Num_Idents
> 1 then
3315 Save_Scan_State
(Scan_State
);
3320 -- Loop through defining identifiers in list
3325 -- The following block is present to catch Error_Resync
3326 -- which causes the parse to be reset past the semicolon
3329 Decl_Node
:= New_Node
(N_Component_Declaration
, Ident_Sloc
);
3330 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
3332 if Token
= Tok_Constant
then
3333 Error_Msg_SC
("constant components are not permitted");
3337 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
3339 if Token_Name
= Name_Aliased
then
3340 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
3343 if Token
= Tok_Aliased
then
3344 Aliased_Present
:= True;
3345 Scan
; -- past ALIASED
3348 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
3350 -- Ada 2005 (AI-230): Access Definition case
3352 if Token
= Tok_Access
then
3353 if Ada_Version
< Ada_05
then
3355 ("generalized use of anonymous access types " &
3356 "is an Ada 2005 extension");
3357 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3360 if Aliased_Present
then
3361 Error_Msg_SP
("ALIASED not allowed here");
3364 Set_Subtype_Indication
(CompDef_Node
, Empty
);
3365 Set_Aliased_Present
(CompDef_Node
, False);
3366 Set_Access_Definition
(CompDef_Node
,
3367 P_Access_Definition
(Not_Null_Present
));
3370 Set_Access_Definition
(CompDef_Node
, Empty
);
3371 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
3372 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
3374 if Token
= Tok_Array
then
3376 ("anonymous arrays not allowed as components");
3380 Set_Subtype_Indication
(CompDef_Node
,
3381 P_Subtype_Indication
(Not_Null_Present
));
3384 Set_Component_Definition
(Decl_Node
, CompDef_Node
);
3385 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
3388 Set_Prev_Ids
(Decl_Node
, True);
3391 if Ident
< Num_Idents
then
3392 Set_More_Ids
(Decl_Node
, True);
3395 Append
(Decl_Node
, Decls
);
3398 when Error_Resync
=>
3399 if Token
/= Tok_End
then
3400 Resync_Past_Semicolon
;
3404 exit Ident_Loop
when Ident
= Num_Idents
;
3406 Restore_Scan_State
(Scan_State
);
3409 end loop Ident_Loop
;
3412 end P_Component_Items
;
3414 --------------------------------
3415 -- 3.8 Component Declaration --
3416 --------------------------------
3418 -- Parsed by P_Component_Items (3.8)
3420 -------------------------
3421 -- 3.8.1 Variant Part --
3422 -------------------------
3425 -- case discriminant_DIRECT_NAME is
3430 -- The caller has checked that the initial token is CASE
3432 -- Error recovery: cannot raise Error_Resync
3434 function P_Variant_Part
return Node_Id
is
3435 Variant_Part_Node
: Node_Id
;
3436 Variants_List
: List_Id
;
3437 Case_Node
: Node_Id
;
3440 Variant_Part_Node
:= New_Node
(N_Variant_Part
, Token_Ptr
);
3442 Scope
.Table
(Scope
.Last
).Etyp
:= E_Case
;
3443 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3444 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3447 Case_Node
:= P_Expression
;
3448 Set_Name
(Variant_Part_Node
, Case_Node
);
3450 if Nkind
(Case_Node
) /= N_Identifier
then
3451 Set_Name
(Variant_Part_Node
, Error
);
3452 Error_Msg
("discriminant name expected", Sloc
(Case_Node
));
3454 elsif Paren_Count
(Case_Node
) /= 0 then
3455 Error_Msg
("|discriminant name may not be parenthesized",
3457 Set_Paren_Count
(Case_Node
, 0);
3461 Variants_List
:= New_List
;
3462 P_Pragmas_Opt
(Variants_List
);
3464 -- Test missing variant
3466 if Token
= Tok_End
then
3467 Error_Msg_BC
("WHEN expected (must have at least one variant)");
3469 Append
(P_Variant
, Variants_List
);
3472 -- Loop through variants, note that we allow if in place of when,
3473 -- this error will be detected and handled in P_Variant.
3476 P_Pragmas_Opt
(Variants_List
);
3478 if Token
/= Tok_When
3479 and then Token
/= Tok_If
3480 and then Token
/= Tok_Others
3482 exit when Check_End
;
3485 Append
(P_Variant
, Variants_List
);
3488 Set_Variants
(Variant_Part_Node
, Variants_List
);
3489 return Variant_Part_Node
;
3492 --------------------
3494 --------------------
3497 -- when DISCRETE_CHOICE_LIST =>
3500 -- Error recovery: cannot raise Error_Resync
3502 -- The initial token on entry is either WHEN, IF or OTHERS
3504 function P_Variant
return Node_Id
is
3505 Variant_Node
: Node_Id
;
3508 -- Special check to recover nicely from use of IF in place of WHEN
3510 if Token
= Tok_If
then
3517 Variant_Node
:= New_Node
(N_Variant
, Prev_Token_Ptr
);
3518 Set_Discrete_Choices
(Variant_Node
, P_Discrete_Choice_List
);
3520 Set_Component_List
(Variant_Node
, P_Component_List
);
3521 return Variant_Node
;
3524 ---------------------------------
3525 -- 3.8.1 Discrete Choice List --
3526 ---------------------------------
3528 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3530 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3532 -- Note: in Ada 83, the expression must be a simple expression
3534 -- Error recovery: cannot raise Error_Resync
3536 function P_Discrete_Choice_List
return List_Id
is
3538 Expr_Node
: Node_Id
;
3539 Choice_Node
: Node_Id
;
3542 Choices
:= New_List
;
3545 if Token
= Tok_Others
then
3546 Append
(New_Node
(N_Others_Choice
, Token_Ptr
), Choices
);
3547 Scan
; -- past OTHERS
3551 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3552 Ignore
(Tok_Right_Paren
);
3554 if Token
= Tok_Colon
3555 and then Nkind
(Expr_Node
) = N_Identifier
3557 Error_Msg_SP
("label not permitted in this context");
3560 elsif Expr_Form
= EF_Range_Attr
then
3561 Append
(Expr_Node
, Choices
);
3563 elsif Token
= Tok_Dot_Dot
then
3564 Check_Simple_Expression
(Expr_Node
);
3565 Choice_Node
:= New_Node
(N_Range
, Token_Ptr
);
3566 Set_Low_Bound
(Choice_Node
, Expr_Node
);
3568 Expr_Node
:= P_Expression_No_Right_Paren
;
3569 Check_Simple_Expression
(Expr_Node
);
3570 Set_High_Bound
(Choice_Node
, Expr_Node
);
3571 Append
(Choice_Node
, Choices
);
3573 elsif Expr_Form
= EF_Simple_Name
then
3574 if Token
= Tok_Range
then
3575 Append
(P_Subtype_Indication
(Expr_Node
), Choices
);
3577 elsif Token
in Token_Class_Consk
then
3579 ("the only constraint allowed here " &
3580 "is a range constraint");
3581 Discard_Junk_Node
(P_Constraint_Opt
);
3582 Append
(Expr_Node
, Choices
);
3585 Append
(Expr_Node
, Choices
);
3589 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
3590 Append
(Expr_Node
, Choices
);
3594 when Error_Resync
=>
3600 if Token
= Tok_Comma
then
3601 Error_Msg_SC
(""","" should be ""'|""");
3603 exit when Token
/= Tok_Vertical_Bar
;
3606 Scan
; -- past | or comma
3610 end P_Discrete_Choice_List
;
3612 ----------------------------
3613 -- 3.8.1 Discrete Choice --
3614 ----------------------------
3616 -- Parsed by P_Discrete_Choice_List (3.8.1)
3618 ----------------------------------
3619 -- 3.9.1 Record Extension Part --
3620 ----------------------------------
3622 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
3624 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
3626 --------------------------------------
3627 -- 3.9.4 Interface Type Definition --
3628 --------------------------------------
3630 -- INTERFACE_TYPE_DEFINITION ::=
3631 -- [limited | task | protected | synchronized] interface
3632 -- [and INTERFACE_LIST]
3634 -- Error recovery: cannot raise Error_Resync
3636 function P_Interface_Type_Definition
3637 (Abstract_Present
: Boolean) return Node_Id
3639 Typedef_Node
: Node_Id
;
3642 if Ada_Version
< Ada_05
then
3643 Error_Msg_SP
("abstract interface is an Ada 2005 extension");
3644 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3647 if Abstract_Present
then
3648 Error_Msg_SP
("ABSTRACT not allowed in interface type definition " &
3652 Scan
; -- past INTERFACE
3654 -- Ada 2005 (AI-345): In case of interfaces with a null list of
3655 -- interfaces we build a record_definition node.
3657 if Token
= Tok_Semicolon
then
3658 Typedef_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3660 Set_Abstract_Present
(Typedef_Node
);
3661 Set_Tagged_Present
(Typedef_Node
);
3662 Set_Null_Present
(Typedef_Node
);
3663 Set_Interface_Present
(Typedef_Node
);
3665 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
3666 -- a list of interfaces we build a derived_type_definition node. This
3667 -- simplifies the semantic analysis (and hence further maintenance)
3670 if Token
/= Tok_And
then
3671 Error_Msg_AP
("AND expected");
3676 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
3678 Set_Abstract_Present
(Typedef_Node
);
3679 Set_Interface_Present
(Typedef_Node
);
3680 Set_Subtype_Indication
(Typedef_Node
, P_Qualified_Simple_Name
);
3682 Set_Record_Extension_Part
(Typedef_Node
,
3683 New_Node
(N_Record_Definition
, Token_Ptr
));
3684 Set_Null_Present
(Record_Extension_Part
(Typedef_Node
));
3686 if Token
= Tok_And
then
3687 Set_Interface_List
(Typedef_Node
, New_List
);
3691 Append
(P_Qualified_Simple_Name
,
3692 Interface_List
(Typedef_Node
));
3693 exit when Token
/= Tok_And
;
3699 return Typedef_Node
;
3700 end P_Interface_Type_Definition
;
3702 ----------------------------------
3703 -- 3.10 Access Type Definition --
3704 ----------------------------------
3706 -- ACCESS_TYPE_DEFINITION ::=
3707 -- ACCESS_TO_OBJECT_DEFINITION
3708 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3710 -- ACCESS_TO_OBJECT_DEFINITION ::=
3711 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
3713 -- GENERAL_ACCESS_MODIFIER ::= all | constant
3715 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3716 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3717 -- | [NULL_EXCLUSION] access [protected] function
3718 -- PARAMETER_AND_RESULT_PROFILE
3720 -- PARAMETER_PROFILE ::= [FORMAL_PART]
3722 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
3724 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
3725 -- parsed the null_exclusion part and has also removed the ACCESS token;
3726 -- otherwise the caller has just checked that the initial token is ACCESS
3728 -- Error recovery: can raise Error_Resync
3730 function P_Access_Type_Definition
3731 (Header_Already_Parsed
: Boolean := False) return Node_Id
3733 Access_Loc
: constant Source_Ptr
:= Token_Ptr
;
3734 Prot_Flag
: Boolean;
3735 Not_Null_Present
: Boolean := False;
3736 Type_Def_Node
: Node_Id
;
3737 Result_Not_Null
: Boolean;
3738 Result_Node
: Node_Id
;
3740 procedure Check_Junk_Subprogram_Name
;
3741 -- Used in access to subprogram definition cases to check for an
3742 -- identifier or operator symbol that does not belong.
3744 --------------------------------
3745 -- Check_Junk_Subprogram_Name --
3746 --------------------------------
3748 procedure Check_Junk_Subprogram_Name
is
3749 Saved_State
: Saved_Scan_State
;
3752 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
3753 Save_Scan_State
(Saved_State
);
3754 Scan
; -- past possible junk subprogram name
3756 if Token
= Tok_Left_Paren
or else Token
= Tok_Semicolon
then
3757 Error_Msg_SP
("unexpected subprogram name ignored");
3761 Restore_Scan_State
(Saved_State
);
3764 end Check_Junk_Subprogram_Name
;
3766 -- Start of processing for P_Access_Type_Definition
3769 if not Header_Already_Parsed
then
3770 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
3771 Scan
; -- past ACCESS
3774 if Token_Name
= Name_Protected
then
3775 Check_95_Keyword
(Tok_Protected
, Tok_Procedure
);
3776 Check_95_Keyword
(Tok_Protected
, Tok_Function
);
3779 Prot_Flag
:= (Token
= Tok_Protected
);
3782 Scan
; -- past PROTECTED
3784 if Token
/= Tok_Procedure
and then Token
/= Tok_Function
then
3785 Error_Msg_SC
("FUNCTION or PROCEDURE expected");
3789 if Token
= Tok_Procedure
then
3790 if Ada_Version
= Ada_83
then
3791 Error_Msg_SC
("(Ada 83) access to procedure not allowed!");
3794 Type_Def_Node
:= New_Node
(N_Access_Procedure_Definition
, Access_Loc
);
3795 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
3796 Scan
; -- past PROCEDURE
3797 Check_Junk_Subprogram_Name
;
3798 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
3799 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
3801 elsif Token
= Tok_Function
then
3802 if Ada_Version
= Ada_83
then
3803 Error_Msg_SC
("(Ada 83) access to function not allowed!");
3806 Type_Def_Node
:= New_Node
(N_Access_Function_Definition
, Access_Loc
);
3807 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
3808 Scan
; -- past FUNCTION
3809 Check_Junk_Subprogram_Name
;
3810 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
3811 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
3814 Result_Not_Null
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
3816 -- Ada 2005 (AI-318-02)
3818 if Token
= Tok_Access
then
3819 if Ada_Version
< Ada_05
then
3821 ("anonymous access result type is an Ada 2005 extension");
3822 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
3825 Result_Node
:= P_Access_Definition
(Result_Not_Null
);
3828 Result_Node
:= P_Subtype_Mark
;
3832 -- Note: A null exclusion given on the result type needs to
3833 -- be coded by a distinct flag, since Null_Exclusion_Present
3834 -- on an access-to-function type pertains to a null exclusion
3835 -- on the access type itself (as set above). ???
3836 -- Set_Null_Exclusion_Present??? (Type_Def_Node, Result_Not_Null);
3838 Set_Result_Definition
(Type_Def_Node
, Result_Node
);
3842 New_Node
(N_Access_To_Object_Definition
, Access_Loc
);
3843 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
3845 if Token
= Tok_All
or else Token
= Tok_Constant
then
3846 if Ada_Version
= Ada_83
then
3847 Error_Msg_SC
("(Ada 83) access modifier not allowed!");
3850 if Token
= Tok_All
then
3851 Set_All_Present
(Type_Def_Node
, True);
3854 Set_Constant_Present
(Type_Def_Node
, True);
3857 Scan
; -- past ALL or CONSTANT
3860 Set_Subtype_Indication
(Type_Def_Node
,
3861 P_Subtype_Indication
(Not_Null_Present
));
3864 return Type_Def_Node
;
3865 end P_Access_Type_Definition
;
3867 ---------------------------------------
3868 -- 3.10 Access To Object Definition --
3869 ---------------------------------------
3871 -- Parsed by P_Access_Type_Definition (3.10)
3873 -----------------------------------
3874 -- 3.10 General Access Modifier --
3875 -----------------------------------
3877 -- Parsed by P_Access_Type_Definition (3.10)
3879 -------------------------------------------
3880 -- 3.10 Access To Subprogram Definition --
3881 -------------------------------------------
3883 -- Parsed by P_Access_Type_Definition (3.10)
3885 -----------------------------
3886 -- 3.10 Access Definition --
3887 -----------------------------
3889 -- ACCESS_DEFINITION ::=
3890 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
3891 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3893 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3894 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3895 -- | [NULL_EXCLUSION] access [protected] function
3896 -- PARAMETER_AND_RESULT_PROFILE
3898 -- The caller has parsed the null-exclusion part and it has also checked
3899 -- that the next token is ACCESS
3901 -- Error recovery: cannot raise Error_Resync
3903 function P_Access_Definition
3904 (Null_Exclusion_Present
: Boolean) return Node_Id
3907 Subp_Node
: Node_Id
;
3910 Def_Node
:= New_Node
(N_Access_Definition
, Token_Ptr
);
3911 Scan
; -- past ACCESS
3913 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
3915 if Token
= Tok_Protected
3916 or else Token
= Tok_Procedure
3917 or else Token
= Tok_Function
3919 if Ada_Version
< Ada_05
then
3920 Error_Msg_SP
("access-to-subprogram is an Ada 2005 extension");
3921 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
3924 Subp_Node
:= P_Access_Type_Definition
(Header_Already_Parsed
=> True);
3925 Set_Null_Exclusion_Present
(Subp_Node
, Null_Exclusion_Present
);
3926 Set_Access_To_Subprogram_Definition
(Def_Node
, Subp_Node
);
3928 -- Ada 2005 (AI-231)
3929 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
3932 Set_Null_Exclusion_Present
(Def_Node
, Null_Exclusion_Present
);
3934 if Token
= Tok_All
then
3935 if Ada_Version
< Ada_05
then
3937 ("ALL is not permitted for anonymous access types");
3941 Set_All_Present
(Def_Node
);
3943 elsif Token
= Tok_Constant
then
3944 if Ada_Version
< Ada_05
then
3945 Error_Msg_SP
("access-to-constant is an Ada 2005 extension");
3946 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
3949 Scan
; -- past CONSTANT
3950 Set_Constant_Present
(Def_Node
);
3953 Set_Subtype_Mark
(Def_Node
, P_Subtype_Mark
);
3958 end P_Access_Definition
;
3960 -----------------------------------------
3961 -- 3.10.1 Incomplete Type Declaration --
3962 -----------------------------------------
3964 -- Parsed by P_Type_Declaration (3.2.1)
3966 ----------------------------
3967 -- 3.11 Declarative Part --
3968 ----------------------------
3970 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
3972 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Items
3973 -- handles errors, and returns cleanly after an error has occurred)
3975 function P_Declarative_Part
return List_Id
is
3980 -- Indicate no bad declarations detected yet. This will be reset by
3981 -- P_Declarative_Items if a bad declaration is discovered.
3983 Missing_Begin_Msg
:= No_Error_Msg
;
3985 -- Get rid of active SIS entry from outer scope. This means we will
3986 -- miss some nested cases, but it doesn't seem worth the effort. See
3987 -- discussion in Par for further details
3989 SIS_Entry_Active
:= False;
3992 -- Loop to scan out the declarations
3995 P_Declarative_Items
(Decls
, Done
, In_Spec
=> False);
3999 -- Get rid of active SIS entry which is left set only if we scanned a
4000 -- procedure declaration and have not found the body. We could give
4001 -- an error message, but that really would be usurping the role of
4002 -- semantic analysis (this really is a missing body case).
4004 SIS_Entry_Active
:= False;
4006 end P_Declarative_Part
;
4008 ----------------------------
4009 -- 3.11 Declarative Item --
4010 ----------------------------
4012 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4014 -- Can return Error if a junk declaration is found, or Empty if no
4015 -- declaration is found (i.e. a token ending declarations, such as
4016 -- BEGIN or END is encountered).
4018 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4019 -- then the scan is set past the next semicolon and Error is returned.
4021 procedure P_Declarative_Items
4026 Scan_State
: Saved_Scan_State
;
4030 Style
.Check_Indentation
;
4035 when Tok_Function
=>
4037 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4043 -- Check for loop (premature statement)
4045 Save_Scan_State
(Scan_State
);
4048 if Token
= Tok_Identifier
then
4049 Scan
; -- past identifier
4051 if Token
= Tok_In
then
4052 Restore_Scan_State
(Scan_State
);
4053 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4058 -- Not a loop, so must be rep clause
4060 Restore_Scan_State
(Scan_State
);
4061 Append
(P_Representation_Clause
, Decls
);
4066 Append
(P_Generic
, Decls
);
4069 when Tok_Identifier
=>
4072 -- Special check for misuse of overriding not in Ada 2005 mode
4074 if Token_Name
= Name_Overriding
4075 and then not Next_Token_Is
(Tok_Colon
)
4077 Error_Msg_SC
("overriding indicator is an Ada 2005 extension");
4078 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4080 Token
:= Tok_Overriding
;
4081 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4084 -- Normal case, no overriding, or overriding followed by colon
4087 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4090 -- Ada2005: A subprogram declaration can start with "not" or
4091 -- "overriding". In older versions, "overriding" is handled
4092 -- like an identifier, with the appropriate messages.
4096 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4099 when Tok_Overriding
=>
4101 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4106 Append
(P_Package
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4110 Append
(P_Pragma
, Decls
);
4113 when Tok_Procedure
=>
4115 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4118 when Tok_Protected
=>
4120 Scan
; -- past PROTECTED
4121 Append
(P_Protected
, Decls
);
4126 Append
(P_Subtype_Declaration
, Decls
);
4132 Append
(P_Task
, Decls
);
4137 Append
(P_Type_Declaration
, Decls
);
4142 Append
(P_Use_Clause
, Decls
);
4147 Error_Msg_SC
("WITH can only appear in context clause");
4150 -- BEGIN terminates the scan of a sequence of declarations unless
4151 -- there is a missing subprogram body, see section on handling
4152 -- semicolon in place of IS. We only treat the begin as satisfying
4153 -- the subprogram declaration if it falls in the expected column
4157 if SIS_Entry_Active
and then Start_Column
>= SIS_Ecol
then
4159 -- Here we have the case where a BEGIN is encountered during
4160 -- declarations in a declarative part, or at the outer level,
4161 -- and there is a subprogram declaration outstanding for which
4162 -- no body has been supplied. This is the case where we assume
4163 -- that the semicolon in the subprogram declaration should
4164 -- really have been is. The active SIS entry describes the
4165 -- subprogram declaration. On return the declaration has been
4166 -- modified to become a body.
4169 Specification_Node
: Node_Id
;
4170 Decl_Node
: Node_Id
;
4171 Body_Node
: Node_Id
;
4174 -- First issue the error message. If we had a missing
4175 -- semicolon in the declaration, then change the message
4176 -- to <missing "is">
4178 if SIS_Missing_Semicolon_Message
/= No_Error_Msg
then
4179 Change_Error_Text
-- Replace: "missing "";"" "
4180 (SIS_Missing_Semicolon_Message
, "missing ""is""");
4182 -- Otherwise we saved the semicolon position, so complain
4185 Error_Msg
("|"";"" should be IS", SIS_Semicolon_Sloc
);
4188 -- The next job is to fix up any declarations that occurred
4189 -- between the procedure header and the BEGIN. These got
4190 -- chained to the outer declarative region (immediately
4191 -- after the procedure declaration) and they should be
4192 -- chained to the subprogram itself, which is a body
4193 -- rather than a spec.
4195 Specification_Node
:= Specification
(SIS_Declaration_Node
);
4196 Change_Node
(SIS_Declaration_Node
, N_Subprogram_Body
);
4197 Body_Node
:= SIS_Declaration_Node
;
4198 Set_Specification
(Body_Node
, Specification_Node
);
4199 Set_Declarations
(Body_Node
, New_List
);
4202 Decl_Node
:= Remove_Next
(Body_Node
);
4203 exit when Decl_Node
= Empty
;
4204 Append
(Decl_Node
, Declarations
(Body_Node
));
4207 -- Now make the scope table entry for the Begin-End and
4211 Scope
.Table
(Scope
.Last
).Sloc
:= SIS_Sloc
;
4212 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
4213 Scope
.Table
(Scope
.Last
).Ecol
:= SIS_Ecol
;
4214 Scope
.Table
(Scope
.Last
).Labl
:= SIS_Labl
;
4215 Scope
.Table
(Scope
.Last
).Lreq
:= False;
4216 SIS_Entry_Active
:= False;
4218 Set_Handled_Statement_Sequence
(Body_Node
,
4219 P_Handled_Sequence_Of_Statements
);
4220 End_Statements
(Handled_Statement_Sequence
(Body_Node
));
4229 -- Normally an END terminates the scan for basic declarative
4230 -- items. The one exception is END RECORD, which is probably
4231 -- left over from some other junk.
4234 Save_Scan_State
(Scan_State
); -- at END
4237 if Token
= Tok_Record
then
4238 Error_Msg_SP
("no RECORD for this `end record`!");
4239 Scan
; -- past RECORD
4243 Restore_Scan_State
(Scan_State
); -- to END
4247 -- The following tokens which can only be the start of a statement
4248 -- are considered to end a declarative part (i.e. we have a missing
4249 -- BEGIN situation). We are fairly conservative in making this
4250 -- judgment, because it is a real mess to go into statement mode
4251 -- prematurely in response to a junk declaration.
4266 -- But before we decide that it's a statement, let's check for
4267 -- a reserved word misused as an identifier.
4269 if Is_Reserved_Identifier
then
4270 Save_Scan_State
(Scan_State
);
4271 Scan
; -- past the token
4273 -- If reserved identifier not followed by colon or comma, then
4274 -- this is most likely an assignment statement to the bad id.
4276 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4277 Restore_Scan_State
(Scan_State
);
4278 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4281 -- Otherwise we have a declaration of the bad id
4284 Restore_Scan_State
(Scan_State
);
4285 Scan_Reserved_Identifier
(Force_Msg
=> True);
4286 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4289 -- If not reserved identifier, then it's definitely a statement
4292 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4296 -- The token RETURN may well also signal a missing BEGIN situation,
4297 -- however, we never let it end the declarative part, because it may
4298 -- also be part of a half-baked function declaration.
4301 Error_Msg_SC
("misplaced RETURN statement");
4304 -- PRIVATE definitely terminates the declarations in a spec,
4305 -- and is an error in a body.
4311 Error_Msg_SC
("PRIVATE not allowed in body");
4312 Scan
; -- past PRIVATE
4315 -- An end of file definitely terminates the declarations!
4320 -- The remaining tokens do not end the scan, but cannot start a
4321 -- valid declaration, so we signal an error and resynchronize.
4322 -- But first check for misuse of a reserved identifier.
4326 -- Here we check for a reserved identifier
4328 if Is_Reserved_Identifier
then
4329 Save_Scan_State
(Scan_State
);
4330 Scan
; -- past the token
4332 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4333 Restore_Scan_State
(Scan_State
);
4334 Set_Declaration_Expected
;
4337 Restore_Scan_State
(Scan_State
);
4338 Scan_Reserved_Identifier
(Force_Msg
=> True);
4340 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4344 Set_Declaration_Expected
;
4349 -- To resynchronize after an error, we scan to the next semicolon and
4350 -- return with Done = False, indicating that there may still be more
4351 -- valid declarations to come.
4354 when Error_Resync
=>
4355 Resync_Past_Semicolon
;
4357 end P_Declarative_Items
;
4359 ----------------------------------
4360 -- 3.11 Basic Declarative Item --
4361 ----------------------------------
4363 -- BASIC_DECLARATIVE_ITEM ::=
4364 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4366 -- Scan zero or more basic declarative items
4368 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4369 -- the scan pointer is repositioned past the next semicolon, and the scan
4370 -- for declarative items continues.
4372 function P_Basic_Declarative_Items
return List_Id
is
4379 -- Indicate no bad declarations detected yet in the current context:
4380 -- visible or private declarations of a package spec.
4382 Missing_Begin_Msg
:= No_Error_Msg
;
4384 -- Get rid of active SIS entry from outer scope. This means we will
4385 -- miss some nested cases, but it doesn't seem worth the effort. See
4386 -- discussion in Par for further details
4388 SIS_Entry_Active
:= False;
4390 -- Loop to scan out declarations
4395 P_Declarative_Items
(Decls
, Done
, In_Spec
=> True);
4399 -- Get rid of active SIS entry. This is set only if we have scanned a
4400 -- procedure declaration and have not found the body. We could give
4401 -- an error message, but that really would be usurping the role of
4402 -- semantic analysis (this really is a case of a missing body).
4404 SIS_Entry_Active
:= False;
4406 -- Test for assorted illegal declarations not diagnosed elsewhere
4408 Decl
:= First
(Decls
);
4410 while Present
(Decl
) loop
4411 Kind
:= Nkind
(Decl
);
4413 -- Test for body scanned, not acceptable as basic decl item
4415 if Kind
= N_Subprogram_Body
or else
4416 Kind
= N_Package_Body
or else
4417 Kind
= N_Task_Body
or else
4418 Kind
= N_Protected_Body
4421 ("proper body not allowed in package spec", Sloc
(Decl
));
4423 -- Test for body stub scanned, not acceptable as basic decl item
4425 elsif Kind
in N_Body_Stub
then
4427 ("body stub not allowed in package spec", Sloc
(Decl
));
4429 elsif Kind
= N_Assignment_Statement
then
4431 ("assignment statement not allowed in package spec",
4439 end P_Basic_Declarative_Items
;
4445 -- For proper body, see below
4446 -- For body stub, see 10.1.3
4448 -----------------------
4449 -- 3.11 Proper Body --
4450 -----------------------
4452 -- Subprogram body is parsed by P_Subprogram (6.1)
4453 -- Package body is parsed by P_Package (7.1)
4454 -- Task body is parsed by P_Task (9.1)
4455 -- Protected body is parsed by P_Protected (9.4)
4457 ------------------------------
4458 -- Set_Declaration_Expected --
4459 ------------------------------
4461 procedure Set_Declaration_Expected
is
4463 Error_Msg_SC
("declaration expected");
4465 if Missing_Begin_Msg
= No_Error_Msg
then
4466 Missing_Begin_Msg
:= Get_Msg_Id
;
4468 end Set_Declaration_Expected
;
4470 ----------------------
4471 -- Skip_Declaration --
4472 ----------------------
4474 procedure Skip_Declaration
(S
: List_Id
) is
4475 Dummy_Done
: Boolean;
4476 pragma Warnings
(Off
, Dummy_Done
);
4478 P_Declarative_Items
(S
, Dummy_Done
, False);
4479 end Skip_Declaration
;
4481 -----------------------------------------
4482 -- Statement_When_Declaration_Expected --
4483 -----------------------------------------
4485 procedure Statement_When_Declaration_Expected
4491 -- Case of second occurrence of statement in one declaration sequence
4493 if Missing_Begin_Msg
/= No_Error_Msg
then
4495 -- In the procedure spec case, just ignore it, we only give one
4496 -- message for the first occurrence, since otherwise we may get
4497 -- horrible cascading if BODY was missing in the header line.
4502 -- In the declarative part case, take a second statement as a sure
4503 -- sign that we really have a missing BEGIN, and end the declarative
4504 -- part now. Note that the caller will fix up the first message to
4505 -- say "missing BEGIN" so that's how the error will be signalled.
4512 -- Case of first occurrence of unexpected statement
4515 -- If we are in a package spec, then give message of statement
4516 -- not allowed in package spec. This message never gets changed.
4519 Error_Msg_SC
("statement not allowed in package spec");
4521 -- If in declarative part, then we give the message complaining
4522 -- about finding a statement when a declaration is expected. This
4523 -- gets changed to a complaint about a missing BEGIN if we later
4524 -- find that no BEGIN is present.
4527 Error_Msg_SC
("statement not allowed in declarative part");
4530 -- Capture message Id. This is used for two purposes, first to
4531 -- stop multiple messages, see test above, and second, to allow
4532 -- the replacement of the message in the declarative part case.
4534 Missing_Begin_Msg
:= Get_Msg_Id
;
4537 -- In all cases except the case in which we decided to terminate the
4538 -- declaration sequence on a second error, we scan out the statement
4539 -- and append it to the list of declarations (note that the semantics
4540 -- can handle statements in a declaration list so if we proceed to
4541 -- call the semantic phase, all will be (reasonably) well!
4543 Append_List_To
(Decls
, P_Sequence_Of_Statements
(SS_Unco
));
4545 -- Done is set to False, since we want to continue the scan of
4546 -- declarations, hoping that this statement was a temporary glitch.
4547 -- If we indeed are now in the statement part (i.e. this was a missing
4548 -- BEGIN, then it's not terrible, we will simply keep calling this
4549 -- procedure to process the statements one by one, and then finally
4550 -- hit the missing BEGIN, which will clean up the error message.
4553 end Statement_When_Declaration_Expected
;