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 Ident_Node
/= Error
then
210 Change_Identifier_To_Defining_Identifier
(Ident_Node
);
214 end P_Defining_Identifier
;
216 -----------------------------
217 -- 3.2.1 Type Declaration --
218 -----------------------------
220 -- TYPE_DECLARATION ::=
221 -- FULL_TYPE_DECLARATION
222 -- | INCOMPLETE_TYPE_DECLARATION
223 -- | PRIVATE_TYPE_DECLARATION
224 -- | PRIVATE_EXTENSION_DECLARATION
226 -- FULL_TYPE_DECLARATION ::=
227 -- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION;
228 -- | CONCURRENT_TYPE_DECLARATION
230 -- INCOMPLETE_TYPE_DECLARATION ::=
231 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] [is tagged];
233 -- PRIVATE_TYPE_DECLARATION ::=
234 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
235 -- is [abstract] [tagged] [limited] private;
237 -- PRIVATE_EXTENSION_DECLARATION ::=
238 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
239 -- [abstract] [limited | synchronized]
240 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
243 -- TYPE_DEFINITION ::=
244 -- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
245 -- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
246 -- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
247 -- | DERIVED_TYPE_DEFINITION | INTERFACE_TYPE_DEFINITION
249 -- INTEGER_TYPE_DEFINITION ::=
250 -- SIGNED_INTEGER_TYPE_DEFINITION
251 -- MODULAR_TYPE_DEFINITION
253 -- INTERFACE_TYPE_DEFINITION ::=
254 -- [limited | task | protected | synchronized ] interface
255 -- [and INTERFACE_LIST]
257 -- Error recovery: can raise Error_Resync
259 -- Note: The processing for full type declaration, incomplete type
260 -- declaration, private type declaration and type definition is
261 -- included in this function. The processing for concurrent type
262 -- declarations is NOT here, but rather in chapter 9 (i.e. this
263 -- function handles only declarations starting with TYPE).
265 function P_Type_Declaration
return Node_Id
is
266 Abstract_Present
: Boolean := False;
267 Abstract_Loc
: Source_Ptr
:= No_Location
;
269 Discr_List
: List_Id
;
270 Discr_Sloc
: Source_Ptr
;
272 Ident_Node
: Node_Id
;
273 Is_Derived_Iface
: Boolean := False;
274 Type_Loc
: Source_Ptr
;
275 Type_Start_Col
: Column_Number
;
276 Unknown_Dis
: Boolean;
278 Typedef_Node
: Node_Id
;
279 -- Normally holds type definition, except in the case of a private
280 -- extension declaration, in which case it holds the declaration itself
283 Type_Loc
:= Token_Ptr
;
284 Type_Start_Col
:= Start_Column
;
286 -- If we have TYPE, then proceed ahead and scan identifier
288 if Token
= Tok_Type
then
289 Type_Token_Location
:= Type_Loc
;
291 Ident_Node
:= P_Defining_Identifier
(C_Is
);
293 -- Otherwise this is an error case, and we may already have converted
294 -- the current token to a defining identifier, so don't do it again!
299 if Token
= Tok_Identifier
300 and then Nkind
(Token_Node
) = N_Defining_Identifier
302 Ident_Node
:= Token_Node
;
303 Scan
; -- past defining identifier
305 Ident_Node
:= P_Defining_Identifier
(C_Is
);
309 Discr_Sloc
:= Token_Ptr
;
311 if P_Unknown_Discriminant_Part_Opt
then
313 Discr_List
:= No_List
;
315 Unknown_Dis
:= False;
316 Discr_List
:= P_Known_Discriminant_Part_Opt
;
319 -- Incomplete type declaration. We complete the processing for this
320 -- case here and return the resulting incomplete type declaration node
322 if Token
= Tok_Semicolon
then
324 Decl_Node
:= New_Node
(N_Incomplete_Type_Declaration
, Type_Loc
);
325 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
326 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
327 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
334 -- Full type declaration or private type declaration, must have IS
336 if Token
= Tok_Equal
then
338 Scan
; -- past = used in place of IS
340 elsif Token
= Tok_Renames
then
341 Error_Msg_SC
("RENAMES should be IS");
342 Scan
; -- past RENAMES used in place of IS
348 -- First an error check, if we have two identifiers in a row, a likely
349 -- possibility is that the first of the identifiers is an incorrectly
352 if Token
= Tok_Identifier
then
354 SS
: Saved_Scan_State
;
358 Save_Scan_State
(SS
);
359 Scan
; -- past initial identifier
360 I2
:= (Token
= Tok_Identifier
);
361 Restore_Scan_State
(SS
);
365 (Bad_Spelling_Of
(Tok_Abstract
) or else
366 Bad_Spelling_Of
(Tok_Access
) or else
367 Bad_Spelling_Of
(Tok_Aliased
) or else
368 Bad_Spelling_Of
(Tok_Constant
))
375 -- Check for misuse of Ada 95 keyword abstract in Ada 83 mode
377 if Token_Name
= Name_Abstract
then
378 Check_95_Keyword
(Tok_Abstract
, Tok_Tagged
);
379 Check_95_Keyword
(Tok_Abstract
, Tok_New
);
382 -- Check cases of misuse of ABSTRACT
384 if Token
= Tok_Abstract
then
385 Abstract_Present
:= True;
386 Abstract_Loc
:= Token_Ptr
;
387 Scan
; -- past ABSTRACT
389 -- Ada 2005 (AI-419): AARM 3.4 (2/2)
391 if (Ada_Version
< Ada_05
and then Token
= Tok_Limited
)
392 or else Token
= Tok_Private
393 or else Token
= Tok_Record
394 or else Token
= Tok_Null
396 Error_Msg_AP
("TAGGED expected");
400 -- Check for misuse of Ada 95 keyword Tagged
402 if Token_Name
= Name_Tagged
then
403 Check_95_Keyword
(Tok_Tagged
, Tok_Private
);
404 Check_95_Keyword
(Tok_Tagged
, Tok_Limited
);
405 Check_95_Keyword
(Tok_Tagged
, Tok_Record
);
408 -- Special check for misuse of Aliased
410 if Token
= Tok_Aliased
or else Token_Name
= Name_Aliased
then
411 Error_Msg_SC
("ALIASED not allowed in type definition");
412 Scan
; -- past ALIASED
415 -- The following processing deals with either a private type declaration
416 -- or a full type declaration. In the private type case, we build the
417 -- N_Private_Type_Declaration node, setting its Tagged_Present and
418 -- Limited_Present flags, on encountering the Private keyword, and
419 -- leave Typedef_Node set to Empty. For the full type declaration
420 -- case, Typedef_Node gets set to the type definition.
422 Typedef_Node
:= Empty
;
424 -- Switch on token following the IS. The loop normally runs once. It
425 -- only runs more than once if an error is detected, to try again after
426 -- detecting and fixing up the error.
432 Tok_Not
=> -- Ada 2005 (AI-231)
433 Typedef_Node
:= P_Access_Type_Definition
;
438 Typedef_Node
:= P_Array_Type_Definition
;
443 Typedef_Node
:= P_Fixed_Point_Definition
;
448 Typedef_Node
:= P_Floating_Point_Definition
;
455 when Tok_Integer_Literal
=>
457 Typedef_Node
:= P_Signed_Integer_Type_Definition
;
462 Typedef_Node
:= P_Record_Definition
;
466 when Tok_Left_Paren
=>
467 Typedef_Node
:= P_Enumeration_Type_Definition
;
470 Make_Identifier
(Token_Ptr
,
471 Chars
=> Chars
(Ident_Node
));
472 Set_Comes_From_Source
(End_Labl
, False);
474 Set_End_Label
(Typedef_Node
, End_Labl
);
479 Typedef_Node
:= P_Modular_Type_Definition
;
484 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
486 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
487 and then Present
(Record_Extension_Part
(Typedef_Node
))
490 Make_Identifier
(Token_Ptr
,
491 Chars
=> Chars
(Ident_Node
));
492 Set_Comes_From_Source
(End_Labl
, False);
495 (Record_Extension_Part
(Typedef_Node
), End_Labl
);
502 Typedef_Node
:= P_Signed_Integer_Type_Definition
;
507 Typedef_Node
:= P_Record_Definition
;
510 Make_Identifier
(Token_Ptr
,
511 Chars
=> Chars
(Ident_Node
));
512 Set_Comes_From_Source
(End_Labl
, False);
514 Set_End_Label
(Typedef_Node
, End_Labl
);
521 -- Ada 2005 (AI-326): If the words IS TAGGED appear, the type
522 -- is a tagged incomplete type.
524 if Ada_Version
>= Ada_05
525 and then Token
= Tok_Semicolon
530 New_Node
(N_Incomplete_Type_Declaration
, Type_Loc
);
531 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
532 Set_Tagged_Present
(Decl_Node
);
533 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
534 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
539 if Token
= Tok_Abstract
then
540 Error_Msg_SC
("ABSTRACT must come before TAGGED");
541 Abstract_Present
:= True;
542 Abstract_Loc
:= Token_Ptr
;
543 Scan
; -- past ABSTRACT
546 if Token
= Tok_Limited
then
547 Scan
; -- past LIMITED
549 -- TAGGED LIMITED PRIVATE case
551 if Token
= Tok_Private
then
553 New_Node
(N_Private_Type_Declaration
, Type_Loc
);
554 Set_Tagged_Present
(Decl_Node
, True);
555 Set_Limited_Present
(Decl_Node
, True);
556 Scan
; -- past PRIVATE
558 -- TAGGED LIMITED RECORD
561 Typedef_Node
:= P_Record_Definition
;
562 Set_Tagged_Present
(Typedef_Node
, True);
563 Set_Limited_Present
(Typedef_Node
, True);
566 Make_Identifier
(Token_Ptr
,
567 Chars
=> Chars
(Ident_Node
));
568 Set_Comes_From_Source
(End_Labl
, False);
570 Set_End_Label
(Typedef_Node
, End_Labl
);
576 if Token
= Tok_Private
then
578 New_Node
(N_Private_Type_Declaration
, Type_Loc
);
579 Set_Tagged_Present
(Decl_Node
, True);
580 Scan
; -- past PRIVATE
585 Typedef_Node
:= P_Record_Definition
;
586 Set_Tagged_Present
(Typedef_Node
, True);
589 Make_Identifier
(Token_Ptr
,
590 Chars
=> Chars
(Ident_Node
));
591 Set_Comes_From_Source
(End_Labl
, False);
593 Set_End_Label
(Typedef_Node
, End_Labl
);
601 Scan
; -- past LIMITED
604 if Token
= Tok_Tagged
then
605 Error_Msg_SC
("TAGGED must come before LIMITED");
608 elsif Token
= Tok_Abstract
then
609 Error_Msg_SC
("ABSTRACT must come before LIMITED");
610 Scan
; -- past ABSTRACT
617 -- LIMITED RECORD or LIMITED NULL RECORD
619 if Token
= Tok_Record
or else Token
= Tok_Null
then
620 if Ada_Version
= Ada_83
then
622 ("(Ada 83) limited record declaration not allowed!");
624 -- In Ada2005, "abstract limited" can appear before "new",
625 -- but it cannot be part of an untagged record declaration.
627 elsif Abstract_Present
628 and then Prev_Token
/= Tok_Tagged
630 Error_Msg_SP
("TAGGED expected");
633 Typedef_Node
:= P_Record_Definition
;
634 Set_Limited_Present
(Typedef_Node
, True);
636 -- Ada 2005 (AI-251): LIMITED INTERFACE
638 -- If we are compiling in Ada 83 or Ada 95 mode, "interface"
639 -- is not a reserved word but we force its analysis to
640 -- generate the corresponding usage error.
642 elsif Token
= Tok_Interface
643 or else (Token
= Tok_Identifier
644 and then Chars
(Token_Node
) = Name_Interface
)
647 P_Interface_Type_Definition
(Abstract_Present
);
648 Abstract_Present
:= True;
649 Set_Limited_Present
(Typedef_Node
);
651 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
then
652 Is_Derived_Iface
:= True;
655 -- Ada 2005 (AI-419): LIMITED NEW
657 elsif Token
= Tok_New
then
658 if Ada_Version
< Ada_05
then
660 ("LIMITED in derived type is an Ada 2005 extension");
662 ("\unit must be compiled with -gnat05 switch");
665 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
666 Set_Limited_Present
(Typedef_Node
);
668 if Nkind
(Typedef_Node
) = N_Derived_Type_Definition
669 and then Present
(Record_Extension_Part
(Typedef_Node
))
672 Make_Identifier
(Token_Ptr
,
673 Chars
=> Chars
(Ident_Node
));
674 Set_Comes_From_Source
(End_Labl
, False);
677 (Record_Extension_Part
(Typedef_Node
), End_Labl
);
680 -- LIMITED PRIVATE is the only remaining possibility here
683 Decl_Node
:= New_Node
(N_Private_Type_Declaration
, Type_Loc
);
684 Set_Limited_Present
(Decl_Node
, True);
685 T_Private
; -- past PRIVATE (or complain if not there!)
691 -- Here we have an identifier after the IS, which is certainly
692 -- wrong and which might be one of several different mistakes.
694 when Tok_Identifier
=>
696 -- First case, if identifier is on same line, then probably we
697 -- have something like "type X is Integer .." and the best
698 -- diagnosis is a missing NEW. Note: the missing new message
699 -- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl.
701 if not Token_Is_At_Start_Of_Line
then
702 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
705 -- If the identifier is at the start of the line, and is in the
706 -- same column as the type declaration itself then we consider
707 -- that we had a missing type definition on the previous line
709 elsif Start_Column
<= Type_Start_Col
then
710 Error_Msg_AP
("type definition expected");
711 Typedef_Node
:= Error
;
713 -- If the identifier is at the start of the line, and is in
714 -- a column to the right of the type declaration line, then we
715 -- may have something like:
720 -- and the best diagnosis is a missing record keyword
723 Typedef_Node
:= P_Record_Definition
;
729 -- Ada 2005 (AI-251): INTERFACE
731 when Tok_Interface
=>
732 Typedef_Node
:= P_Interface_Type_Definition
(Abstract_Present
);
733 Abstract_Present
:= True;
738 Decl_Node
:= New_Node
(N_Private_Type_Declaration
, Type_Loc
);
739 Scan
; -- past PRIVATE
743 -- Ada 2005 (AI-345): Protected, synchronized or task interface
744 -- or Ada 2005 (AI-443): Synchronized private extension.
751 Saved_Token
: constant Token_Type
:= Token
;
754 Scan
; -- past TASK, PROTECTED or SYNCHRONIZED
756 -- Synchronized private extension
758 if Token
= Tok_New
then
759 Typedef_Node
:= P_Derived_Type_Def_Or_Private_Ext_Decl
;
761 if Saved_Token
= Tok_Synchronized
then
762 Set_Synchronized_Present
(Typedef_Node
);
764 Error_Msg_SC
("invalid kind of private extension");
770 if Token
/= Tok_Interface
then
771 Error_Msg_SC
("NEW or INTERFACE expected");
775 P_Interface_Type_Definition
(Abstract_Present
);
776 Abstract_Present
:= True;
780 Set_Task_Present
(Typedef_Node
);
782 when Tok_Protected
=>
783 Set_Protected_Present
(Typedef_Node
);
785 when Tok_Synchronized
=>
786 Set_Synchronized_Present
(Typedef_Node
);
789 pragma Assert
(False);
798 -- Anything else is an error
801 if Bad_Spelling_Of
(Tok_Access
)
803 Bad_Spelling_Of
(Tok_Array
)
805 Bad_Spelling_Of
(Tok_Delta
)
807 Bad_Spelling_Of
(Tok_Digits
)
809 Bad_Spelling_Of
(Tok_Limited
)
811 Bad_Spelling_Of
(Tok_Private
)
813 Bad_Spelling_Of
(Tok_Range
)
815 Bad_Spelling_Of
(Tok_Record
)
817 Bad_Spelling_Of
(Tok_Tagged
)
822 Error_Msg_AP
("type definition expected");
829 -- For the private type declaration case, the private type declaration
830 -- node has been built, with the Tagged_Present and Limited_Present
831 -- flags set as needed, and Typedef_Node is left set to Empty.
833 if No
(Typedef_Node
) then
834 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
835 Set_Abstract_Present
(Decl_Node
, Abstract_Present
);
837 -- For a private extension declaration, Typedef_Node contains the
838 -- N_Private_Extension_Declaration node, which we now complete. Note
839 -- that the private extension declaration, unlike a full type
840 -- declaration, does permit unknown discriminants.
842 elsif Nkind
(Typedef_Node
) = N_Private_Extension_Declaration
then
843 Decl_Node
:= Typedef_Node
;
844 Set_Sloc
(Decl_Node
, Type_Loc
);
845 Set_Unknown_Discriminants_Present
(Decl_Node
, Unknown_Dis
);
846 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
848 -- In the full type declaration case, Typedef_Node has the type
849 -- definition and here is where we build the full type declaration
850 -- node. This is also where we check for improper use of an unknown
851 -- discriminant part (not allowed for full type declaration).
854 if Nkind
(Typedef_Node
) = N_Record_Definition
855 or else (Nkind
(Typedef_Node
) = N_Derived_Type_Definition
856 and then Present
(Record_Extension_Part
(Typedef_Node
)))
857 or else Is_Derived_Iface
859 Set_Abstract_Present
(Typedef_Node
, Abstract_Present
);
861 elsif Abstract_Present
then
862 Error_Msg
("ABSTRACT not allowed here, ignored", Abstract_Loc
);
865 Decl_Node
:= New_Node
(N_Full_Type_Declaration
, Type_Loc
);
866 Set_Type_Definition
(Decl_Node
, Typedef_Node
);
870 ("Full type declaration cannot have unknown discriminants",
875 -- Remaining processing is common for all three cases
877 Set_Defining_Identifier
(Decl_Node
, Ident_Node
);
878 Set_Discriminant_Specifications
(Decl_Node
, Discr_List
);
880 end P_Type_Declaration
;
882 ----------------------------------
883 -- 3.2.1 Full Type Declaration --
884 ----------------------------------
886 -- Parsed by P_Type_Declaration (3.2.1)
888 ----------------------------
889 -- 3.2.1 Type Definition --
890 ----------------------------
892 -- Parsed by P_Type_Declaration (3.2.1)
894 --------------------------------
895 -- 3.2.2 Subtype Declaration --
896 --------------------------------
898 -- SUBTYPE_DECLARATION ::=
899 -- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION;
901 -- The caller has checked that the initial token is SUBTYPE
903 -- Error recovery: can raise Error_Resync
905 function P_Subtype_Declaration
return Node_Id
is
907 Not_Null_Present
: Boolean := False;
910 Decl_Node
:= New_Node
(N_Subtype_Declaration
, Token_Ptr
);
911 Scan
; -- past SUBTYPE
912 Set_Defining_Identifier
(Decl_Node
, P_Defining_Identifier
(C_Is
));
915 if Token
= Tok_New
then
916 Error_Msg_SC
("NEW ignored (only allowed in type declaration)");
920 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
921 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
923 Set_Subtype_Indication
924 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
927 end P_Subtype_Declaration
;
929 -------------------------------
930 -- 3.2.2 Subtype Indication --
931 -------------------------------
933 -- SUBTYPE_INDICATION ::=
934 -- [not null] SUBTYPE_MARK [CONSTRAINT]
936 -- Error recovery: can raise Error_Resync
938 function P_Null_Exclusion
939 (Allow_Anonymous_In_95
: Boolean := False) return Boolean
941 Not_Loc
: constant Source_Ptr
:= Token_Ptr
;
942 -- Source position of "not", if present
945 if Token
/= Tok_Not
then
951 if Token
= Tok_Null
then
954 -- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95,
955 -- except in the case of anonymous access types.
957 -- Allow_Anonymous_In_95 will be True if we're parsing a formal
958 -- parameter or discriminant, which are the only places where
959 -- anonymous access types occur in Ada 95. "Formal : not null
960 -- access ..." is legal in Ada 95, whereas "Formal : not null
961 -- Named_Access_Type" is not.
963 if Ada_Version
>= Ada_05
964 or else (Ada_Version
>= Ada_95
965 and then Allow_Anonymous_In_95
966 and then Token
= Tok_Access
)
972 ("`NOT NULL` access type is an Ada 2005 extension", Not_Loc
);
974 ("\unit should be compiled with -gnat05 switch", Not_Loc
);
978 Error_Msg_SP
("NULL expected");
981 if Token
= Tok_New
then
982 Error_Msg
("`NOT NULL` comes after NEW, not before", Not_Loc
);
987 end P_Null_Exclusion
;
989 function P_Subtype_Indication
990 (Not_Null_Present
: Boolean := False) return Node_Id
995 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
996 Type_Node
:= P_Subtype_Mark
;
997 return P_Subtype_Indication
(Type_Node
, Not_Null_Present
);
1000 -- Check for error of using record definition and treat it nicely,
1001 -- otherwise things are really messed up, so resynchronize.
1003 if Token
= Tok_Record
then
1004 Error_Msg_SC
("anonymous record definitions are not permitted");
1005 Discard_Junk_Node
(P_Record_Definition
);
1009 Error_Msg_AP
("subtype indication expected");
1013 end P_Subtype_Indication
;
1015 -- The following function is identical except that it is called with
1016 -- the subtype mark already scanned out, and it scans out the constraint
1018 -- Error recovery: can raise Error_Resync
1020 function P_Subtype_Indication
1021 (Subtype_Mark
: Node_Id
;
1022 Not_Null_Present
: Boolean := False) return Node_Id
1024 Indic_Node
: Node_Id
;
1025 Constr_Node
: Node_Id
;
1028 Constr_Node
:= P_Constraint_Opt
;
1030 if No
(Constr_Node
) then
1031 return Subtype_Mark
;
1033 if Not_Null_Present
then
1034 Error_Msg_SP
("`NOT NULL` not allowed if constraint given");
1037 Indic_Node
:= New_Node
(N_Subtype_Indication
, Sloc
(Subtype_Mark
));
1038 Set_Subtype_Mark
(Indic_Node
, Check_Subtype_Mark
(Subtype_Mark
));
1039 Set_Constraint
(Indic_Node
, Constr_Node
);
1042 end P_Subtype_Indication
;
1044 -------------------------
1045 -- 3.2.2 Subtype Mark --
1046 -------------------------
1048 -- SUBTYPE_MARK ::= subtype_NAME;
1050 -- Note: The subtype mark which appears after an IN or NOT IN
1051 -- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
1053 -- Error recovery: cannot raise Error_Resync
1055 function P_Subtype_Mark
return Node_Id
is
1057 return P_Subtype_Mark_Resync
;
1059 when Error_Resync
=>
1063 -- This routine differs from P_Subtype_Mark in that it insists that an
1064 -- identifier be present, and if it is not, it raises Error_Resync.
1066 -- Error recovery: can raise Error_Resync
1068 function P_Subtype_Mark_Resync
return Node_Id
is
1069 Type_Node
: Node_Id
;
1072 if Token
= Tok_Access
then
1073 Error_Msg_SC
("anonymous access type definition not allowed here");
1074 Scan
; -- past ACCESS
1077 if Token
= Tok_Array
then
1078 Error_Msg_SC
("anonymous array definition not allowed here");
1079 Discard_Junk_Node
(P_Array_Type_Definition
);
1083 Type_Node
:= P_Qualified_Simple_Name_Resync
;
1085 -- Check for a subtype mark attribute. The only valid possibilities
1086 -- are 'CLASS and 'BASE. Anything else is a definite error. We may
1087 -- as well catch it here.
1089 if Token
= Tok_Apostrophe
then
1090 return P_Subtype_Mark_Attribute
(Type_Node
);
1095 end P_Subtype_Mark_Resync
;
1097 -- The following function is called to scan out a subtype mark attribute.
1098 -- The caller has already scanned out the subtype mark, which is passed in
1099 -- as the argument, and has checked that the current token is apostrophe.
1101 -- Only a special subclass of attributes, called type attributes
1102 -- (see Snames package) are allowed in this syntactic position.
1104 -- Note: if the apostrophe is followed by other than an identifier, then
1105 -- the input expression is returned unchanged, and the scan pointer is
1106 -- left pointing to the apostrophe.
1108 -- Error recovery: can raise Error_Resync
1110 function P_Subtype_Mark_Attribute
(Type_Node
: Node_Id
) return Node_Id
is
1111 Attr_Node
: Node_Id
:= Empty
;
1112 Scan_State
: Saved_Scan_State
;
1116 Prefix
:= Check_Subtype_Mark
(Type_Node
);
1118 if Prefix
= Error
then
1122 -- Loop through attributes appearing (more than one can appear as for
1123 -- for example in X'Base'Class). We are at an apostrophe on entry to
1124 -- this loop, and it runs once for each attribute parsed, with
1125 -- Prefix being the current possible prefix if it is an attribute.
1128 Save_Scan_State
(Scan_State
); -- at Apostrophe
1129 Scan
; -- past apostrophe
1131 if Token
/= Tok_Identifier
then
1132 Restore_Scan_State
(Scan_State
); -- to apostrophe
1133 return Prefix
; -- no attribute after all
1135 elsif not Is_Type_Attribute_Name
(Token_Name
) then
1137 ("attribute & may not be used in a subtype mark", Token_Node
);
1142 Make_Attribute_Reference
(Prev_Token_Ptr
,
1144 Attribute_Name
=> Token_Name
);
1145 Scan
; -- past type attribute identifier
1148 exit when Token
/= Tok_Apostrophe
;
1149 Prefix
:= Attr_Node
;
1152 -- Fall through here after scanning type attribute
1155 end P_Subtype_Mark_Attribute
;
1157 -----------------------
1158 -- 3.2.2 Constraint --
1159 -----------------------
1161 -- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
1163 -- SCALAR_CONSTRAINT ::=
1164 -- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
1166 -- COMPOSITE_CONSTRAINT ::=
1167 -- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
1169 -- If no constraint is present, this function returns Empty
1171 -- Error recovery: can raise Error_Resync
1173 function P_Constraint_Opt
return Node_Id
is
1175 if Token
= Tok_Range
1176 or else Bad_Spelling_Of
(Tok_Range
)
1178 return P_Range_Constraint
;
1180 elsif Token
= Tok_Digits
1181 or else Bad_Spelling_Of
(Tok_Digits
)
1183 return P_Digits_Constraint
;
1185 elsif Token
= Tok_Delta
1186 or else Bad_Spelling_Of
(Tok_Delta
)
1188 return P_Delta_Constraint
;
1190 elsif Token
= Tok_Left_Paren
then
1191 return P_Index_Or_Discriminant_Constraint
;
1193 elsif Token
= Tok_In
then
1195 return P_Constraint_Opt
;
1200 end P_Constraint_Opt
;
1202 ------------------------------
1203 -- 3.2.2 Scalar Constraint --
1204 ------------------------------
1206 -- Parsed by P_Constraint_Opt (3.2.2)
1208 ---------------------------------
1209 -- 3.2.2 Composite Constraint --
1210 ---------------------------------
1212 -- Parsed by P_Constraint_Opt (3.2.2)
1214 --------------------------------------------------------
1215 -- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
1216 --------------------------------------------------------
1218 -- This routine scans out a declaration starting with an identifier:
1220 -- OBJECT_DECLARATION ::=
1221 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1222 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION];
1223 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1224 -- ACCESS_DEFINITION [:= EXPRESSION];
1225 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1226 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1228 -- NUMBER_DECLARATION ::=
1229 -- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
1231 -- OBJECT_RENAMING_DECLARATION ::=
1232 -- DEFINING_IDENTIFIER :
1233 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME;
1234 -- | DEFINING_IDENTIFIER :
1235 -- ACCESS_DEFINITION renames object_NAME;
1237 -- EXCEPTION_RENAMING_DECLARATION ::=
1238 -- DEFINING_IDENTIFIER : exception renames exception_NAME;
1240 -- EXCEPTION_DECLARATION ::=
1241 -- DEFINING_IDENTIFIER_LIST : exception;
1243 -- Note that the ALIASED indication in an object declaration is
1244 -- marked by a flag in the parent node.
1246 -- The caller has checked that the initial token is an identifier
1248 -- The value returned is a list of declarations, one for each identifier
1249 -- in the list (as described in Sinfo, we always split up multiple
1250 -- declarations into the equivalent sequence of single declarations
1251 -- using the More_Ids and Prev_Ids flags to preserve the source).
1253 -- If the identifier turns out to be a probable statement rather than
1254 -- an identifier, then the scan is left pointing to the identifier and
1255 -- No_List is returned.
1257 -- Error recovery: can raise Error_Resync
1259 procedure P_Identifier_Declarations
1265 Decl_Node
: Node_Id
;
1266 Type_Node
: Node_Id
;
1267 Ident_Sloc
: Source_Ptr
;
1268 Scan_State
: Saved_Scan_State
;
1269 List_OK
: Boolean := True;
1271 Init_Expr
: Node_Id
;
1272 Init_Loc
: Source_Ptr
;
1273 Con_Loc
: Source_Ptr
;
1274 Not_Null_Present
: Boolean := False;
1276 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
1277 -- Used to save identifiers in the identifier list. The upper bound
1278 -- of 4096 is expected to be infinite in practice, and we do not even
1279 -- bother to check if this upper bound is exceeded.
1281 Num_Idents
: Nat
:= 1;
1282 -- Number of identifiers stored in Idents
1285 -- This procedure is called in renames cases to make sure that we do
1286 -- not have more than one identifier. If we do have more than one
1287 -- then an error message is issued (and the declaration is split into
1288 -- multiple declarations)
1290 function Token_Is_Renames
return Boolean;
1291 -- Checks if current token is RENAMES, and if so, scans past it and
1292 -- returns True, otherwise returns False. Includes checking for some
1293 -- common error cases.
1299 procedure No_List
is
1301 if Num_Idents
> 1 then
1302 Error_Msg
("identifier list not allowed for RENAMES",
1309 ----------------------
1310 -- Token_Is_Renames --
1311 ----------------------
1313 function Token_Is_Renames
return Boolean is
1314 At_Colon
: Saved_Scan_State
;
1317 if Token
= Tok_Colon
then
1318 Save_Scan_State
(At_Colon
);
1320 Check_Misspelling_Of
(Tok_Renames
);
1322 if Token
= Tok_Renames
then
1323 Error_Msg_SP
("|extra "":"" ignored");
1324 Scan
; -- past RENAMES
1327 Restore_Scan_State
(At_Colon
);
1332 Check_Misspelling_Of
(Tok_Renames
);
1334 if Token
= Tok_Renames
then
1335 Scan
; -- past RENAMES
1341 end Token_Is_Renames
;
1343 -- Start of processing for P_Identifier_Declarations
1346 Ident_Sloc
:= Token_Ptr
;
1347 Save_Scan_State
(Scan_State
); -- at first identifier
1348 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
1350 -- If we have a colon after the identifier, then we can assume that
1351 -- this is in fact a valid identifier declaration and can steam ahead.
1353 if Token
= Tok_Colon
then
1356 -- If we have a comma, then scan out the list of identifiers
1358 elsif Token
= Tok_Comma
then
1360 while Comma_Present
loop
1361 Num_Idents
:= Num_Idents
+ 1;
1362 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
1365 Save_Scan_State
(Scan_State
); -- at colon
1368 -- If we have identifier followed by := then we assume that what is
1369 -- really meant is an assignment statement. The assignment statement
1370 -- is scanned out and added to the list of declarations. An exception
1371 -- occurs if the := is followed by the keyword constant, in which case
1372 -- we assume it was meant to be a colon.
1374 elsif Token
= Tok_Colon_Equal
then
1377 if Token
= Tok_Constant
then
1378 Error_Msg_SP
("colon expected");
1381 Restore_Scan_State
(Scan_State
);
1382 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
1386 -- If we have an IS keyword, then assume the TYPE keyword was missing
1388 elsif Token
= Tok_Is
then
1389 Restore_Scan_State
(Scan_State
);
1390 Append_To
(Decls
, P_Type_Declaration
);
1394 -- Otherwise we have an error situation
1397 Restore_Scan_State
(Scan_State
);
1399 -- First case is possible misuse of PROTECTED in Ada 83 mode. If
1400 -- so, fix the keyword and return to scan the protected declaration.
1402 if Token_Name
= Name_Protected
then
1403 Check_95_Keyword
(Tok_Protected
, Tok_Identifier
);
1404 Check_95_Keyword
(Tok_Protected
, Tok_Type
);
1405 Check_95_Keyword
(Tok_Protected
, Tok_Body
);
1407 if Token
= Tok_Protected
then
1412 -- Check misspelling possibilities. If so, correct the misspelling
1413 -- and return to scan out the resulting declaration.
1415 elsif Bad_Spelling_Of
(Tok_Function
)
1416 or else Bad_Spelling_Of
(Tok_Procedure
)
1417 or else Bad_Spelling_Of
(Tok_Package
)
1418 or else Bad_Spelling_Of
(Tok_Pragma
)
1419 or else Bad_Spelling_Of
(Tok_Protected
)
1420 or else Bad_Spelling_Of
(Tok_Generic
)
1421 or else Bad_Spelling_Of
(Tok_Subtype
)
1422 or else Bad_Spelling_Of
(Tok_Type
)
1423 or else Bad_Spelling_Of
(Tok_Task
)
1424 or else Bad_Spelling_Of
(Tok_Use
)
1425 or else Bad_Spelling_Of
(Tok_For
)
1430 -- Otherwise we definitely have an ordinary identifier with a junk
1431 -- token after it. Just complain that we expect a declaration, and
1432 -- skip to a semicolon
1435 Set_Declaration_Expected
;
1436 Resync_Past_Semicolon
;
1442 -- Come here with an identifier list and colon scanned out. We now
1443 -- build the nodes for the declarative items. One node is built for
1444 -- each identifier in the list, with the type information being
1445 -- repeated by rescanning the appropriate section of source.
1447 -- First an error check, if we have two identifiers in a row, a likely
1448 -- possibility is that the first of the identifiers is an incorrectly
1451 if Token
= Tok_Identifier
then
1453 SS
: Saved_Scan_State
;
1457 Save_Scan_State
(SS
);
1458 Scan
; -- past initial identifier
1459 I2
:= (Token
= Tok_Identifier
);
1460 Restore_Scan_State
(SS
);
1464 (Bad_Spelling_Of
(Tok_Access
) or else
1465 Bad_Spelling_Of
(Tok_Aliased
) or else
1466 Bad_Spelling_Of
(Tok_Constant
))
1473 -- Loop through identifiers
1478 -- Check for some cases of misused Ada 95 keywords
1480 if Token_Name
= Name_Aliased
then
1481 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1482 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1483 Check_95_Keyword
(Tok_Aliased
, Tok_Constant
);
1488 if Token
= Tok_Constant
then
1489 Con_Loc
:= Token_Ptr
;
1490 Scan
; -- past CONSTANT
1492 -- Number declaration, initialization required
1494 Init_Expr
:= Init_Expr_Opt
;
1496 if Present
(Init_Expr
) then
1497 if Not_Null_Present
then
1499 ("`NOT NULL` not allowed in numeric expression");
1502 Decl_Node
:= New_Node
(N_Number_Declaration
, Ident_Sloc
);
1503 Set_Expression
(Decl_Node
, Init_Expr
);
1505 -- Constant object declaration
1508 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1509 Set_Constant_Present
(Decl_Node
, True);
1511 if Token_Name
= Name_Aliased
then
1512 Check_95_Keyword
(Tok_Aliased
, Tok_Array
);
1513 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
1516 if Token
= Tok_Aliased
then
1517 Error_Msg_SC
("ALIASED should be before CONSTANT");
1518 Scan
; -- past ALIASED
1519 Set_Aliased_Present
(Decl_Node
, True);
1522 if Token
= Tok_Array
then
1523 Set_Object_Definition
1524 (Decl_Node
, P_Array_Type_Definition
);
1527 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1528 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1530 if Token
= Tok_Access
then
1531 if Ada_Version
< Ada_05
then
1533 ("generalized use of anonymous access types " &
1534 "is an Ada 2005 extension");
1536 ("\unit must be compiled with -gnat05 switch");
1539 Set_Object_Definition
1540 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1542 Set_Object_Definition
1543 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1547 if Token
= Tok_Renames
then
1549 ("CONSTANT not permitted in renaming declaration",
1551 Scan
; -- Past renames
1552 Discard_Junk_Node
(P_Name
);
1558 elsif Token
= Tok_Exception
then
1559 Scan
; -- past EXCEPTION
1561 if Token_Is_Renames
then
1564 New_Node
(N_Exception_Renaming_Declaration
, Ident_Sloc
);
1565 Set_Name
(Decl_Node
, P_Qualified_Simple_Name_Resync
);
1568 Decl_Node
:= New_Node
(N_Exception_Declaration
, Prev_Token_Ptr
);
1571 -- Aliased case (note that an object definition is required)
1573 elsif Token
= Tok_Aliased
then
1574 Scan
; -- past ALIASED
1575 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1576 Set_Aliased_Present
(Decl_Node
, True);
1578 if Token
= Tok_Constant
then
1579 Scan
; -- past CONSTANT
1580 Set_Constant_Present
(Decl_Node
, True);
1583 if Token
= Tok_Array
then
1584 Set_Object_Definition
1585 (Decl_Node
, P_Array_Type_Definition
);
1588 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1589 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1591 -- Access definition (AI-406) or subtype indication
1593 if Token
= Tok_Access
then
1594 if Ada_Version
< Ada_05
then
1596 ("generalized use of anonymous access types " &
1597 "is an Ada 2005 extension");
1599 ("\unit must be compiled with -gnat05 switch");
1602 Set_Object_Definition
1603 (Decl_Node
, P_Access_Definition
(Not_Null_Present
));
1605 Set_Object_Definition
1606 (Decl_Node
, P_Subtype_Indication
(Not_Null_Present
));
1612 elsif Token
= Tok_Array
then
1613 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1614 Set_Object_Definition
(Decl_Node
, P_Array_Type_Definition
);
1616 -- Ada 2005 (AI-254, AI-406)
1618 elsif Token
= Tok_Not
then
1620 -- OBJECT_DECLARATION ::=
1621 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1622 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION];
1623 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1624 -- ACCESS_DEFINITION [:= EXPRESSION];
1626 -- OBJECT_RENAMING_DECLARATION ::=
1627 -- DEFINING_IDENTIFIER :
1628 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME;
1629 -- | DEFINING_IDENTIFIER :
1630 -- ACCESS_DEFINITION renames object_NAME;
1632 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/423)
1634 if Token
= Tok_Access
then
1635 if Ada_Version
< Ada_05
then
1637 ("generalized use of anonymous access types " &
1638 "is an Ada 2005 extension");
1639 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1642 Acc_Node
:= P_Access_Definition
(Not_Null_Present
);
1644 if Token
/= Tok_Renames
then
1645 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1646 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1649 Scan
; -- past renames
1652 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1653 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1654 Set_Name
(Decl_Node
, P_Name
);
1658 Type_Node
:= P_Subtype_Mark
;
1660 -- Object renaming declaration
1662 if Token_Is_Renames
then
1663 if Ada_Version
< Ada_05
then
1665 ("`NOT NULL` not allowed in object renaming");
1668 -- Ada 2005 (AI-423): Object renaming declaration with
1669 -- a null exclusion.
1674 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1675 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1676 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1677 Set_Name
(Decl_Node
, P_Name
);
1680 -- Object declaration
1683 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1684 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1685 Set_Object_Definition
1687 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1689 -- RENAMES at this point means that we had the combination
1690 -- of a constraint on the Type_Node and renames, which is
1693 if Token_Is_Renames
then
1694 Error_Msg_N
("constraint not allowed in object renaming "
1696 Constraint
(Object_Definition
(Decl_Node
)));
1702 -- Ada 2005 (AI-230): Access Definition case
1704 elsif Token
= Tok_Access
then
1705 if Ada_Version
< Ada_05
then
1707 ("generalized use of anonymous access types " &
1708 "is an Ada 2005 extension");
1709 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1712 Acc_Node
:= P_Access_Definition
(Null_Exclusion_Present
=> False);
1714 -- Object declaration with access definition, or renaming
1716 if Token
/= Tok_Renames
then
1717 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1718 Set_Object_Definition
(Decl_Node
, Acc_Node
);
1721 Scan
; -- past renames
1724 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1725 Set_Access_Definition
(Decl_Node
, Acc_Node
);
1726 Set_Name
(Decl_Node
, P_Name
);
1729 -- Subtype indication case
1732 Type_Node
:= P_Subtype_Mark
;
1734 -- Object renaming declaration
1736 if Token_Is_Renames
then
1739 New_Node
(N_Object_Renaming_Declaration
, Ident_Sloc
);
1740 Set_Subtype_Mark
(Decl_Node
, Type_Node
);
1741 Set_Name
(Decl_Node
, P_Name
);
1743 -- Object declaration
1746 Decl_Node
:= New_Node
(N_Object_Declaration
, Ident_Sloc
);
1747 Set_Null_Exclusion_Present
(Decl_Node
, Not_Null_Present
);
1748 Set_Object_Definition
1750 P_Subtype_Indication
(Type_Node
, Not_Null_Present
));
1752 -- RENAMES at this point means that we had the combination of
1753 -- a constraint on the Type_Node and renames, which is illegal
1755 if Token_Is_Renames
then
1757 ("constraint not allowed in object renaming declaration",
1758 Constraint
(Object_Definition
(Decl_Node
)));
1764 -- Scan out initialization, allowed only for object declaration
1766 Init_Loc
:= Token_Ptr
;
1767 Init_Expr
:= Init_Expr_Opt
;
1769 if Present
(Init_Expr
) then
1770 if Nkind
(Decl_Node
) = N_Object_Declaration
then
1771 Set_Expression
(Decl_Node
, Init_Expr
);
1772 Set_Has_Init_Expression
(Decl_Node
);
1774 Error_Msg
("initialization not allowed here", Init_Loc
);
1779 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
1782 if Ident
< Num_Idents
then
1783 Set_More_Ids
(Decl_Node
, True);
1787 Set_Prev_Ids
(Decl_Node
, True);
1791 Append
(Decl_Node
, Decls
);
1792 exit Ident_Loop
when Ident
= Num_Idents
;
1793 Restore_Scan_State
(Scan_State
);
1796 end loop Ident_Loop
;
1799 end P_Identifier_Declarations
;
1801 -------------------------------
1802 -- 3.3.1 Object Declaration --
1803 -------------------------------
1805 -- OBJECT DECLARATION ::=
1806 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1807 -- SUBTYPE_INDICATION [:= EXPRESSION];
1808 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1809 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1810 -- | SINGLE_TASK_DECLARATION
1811 -- | SINGLE_PROTECTED_DECLARATION
1813 -- Cases starting with TASK are parsed by P_Task (9.1)
1814 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1815 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1817 -------------------------------------
1818 -- 3.3.1 Defining Identifier List --
1819 -------------------------------------
1821 -- DEFINING_IDENTIFIER_LIST ::=
1822 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1824 -- Always parsed by the construct in which it appears. See special
1825 -- section on "Handling of Defining Identifier Lists" in this unit.
1827 -------------------------------
1828 -- 3.3.2 Number Declaration --
1829 -------------------------------
1831 -- Parsed by P_Identifier_Declarations (3.3)
1833 -------------------------------------------------------------------------
1834 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
1835 -------------------------------------------------------------------------
1837 -- DERIVED_TYPE_DEFINITION ::=
1838 -- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
1839 -- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
1841 -- PRIVATE_EXTENSION_DECLARATION ::=
1842 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
1843 -- [abstract] [limited | synchronized]
1844 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
1847 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
1849 -- The caller has already scanned out the part up to the NEW, and Token
1850 -- either contains Tok_New (or ought to, if it doesn't this procedure
1851 -- will post an appropriate "NEW expected" message).
1853 -- Note: the caller is responsible for filling in the Sloc field of
1854 -- the returned node in the private extension declaration case as
1855 -- well as the stuff relating to the discriminant part.
1857 -- Error recovery: can raise Error_Resync;
1859 function P_Derived_Type_Def_Or_Private_Ext_Decl
return Node_Id
is
1860 Typedef_Node
: Node_Id
;
1861 Typedecl_Node
: Node_Id
;
1862 Not_Null_Present
: Boolean := False;
1865 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
1867 if Ada_Version
< Ada_05
1868 and then Token
= Tok_Identifier
1869 and then Token_Name
= Name_Interface
1872 ("abstract interface is an Ada 2005 extension");
1873 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1878 if Token
= Tok_Abstract
then
1879 Error_Msg_SC
("ABSTRACT must come before NEW, not after");
1883 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
1884 Set_Null_Exclusion_Present
(Typedef_Node
, Not_Null_Present
);
1885 Set_Subtype_Indication
(Typedef_Node
,
1886 P_Subtype_Indication
(Not_Null_Present
));
1888 -- Ada 2005 (AI-251): Deal with interfaces
1890 if Token
= Tok_And
then
1893 if Ada_Version
< Ada_05
then
1895 ("abstract interface is an Ada 2005 extension");
1896 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1899 Set_Interface_List
(Typedef_Node
, New_List
);
1902 Append
(P_Qualified_Simple_Name
, Interface_List
(Typedef_Node
));
1903 exit when Token
/= Tok_And
;
1907 if Token
/= Tok_With
then
1908 Error_Msg_SC
("WITH expected");
1913 -- Deal with record extension, note that we assume that a WITH is
1914 -- missing in the case of "type X is new Y record ..." or in the
1915 -- case of "type X is new Y null record".
1918 or else Token
= Tok_Record
1919 or else Token
= Tok_Null
1921 T_With
; -- past WITH or give error message
1923 if Token
= Tok_Limited
then
1925 ("LIMITED keyword not allowed in private extension");
1926 Scan
; -- ignore LIMITED
1929 -- Private extension declaration
1931 if Token
= Tok_Private
then
1932 Scan
; -- past PRIVATE
1934 -- Throw away the type definition node and build the type
1935 -- declaration node. Note the caller must set the Sloc,
1936 -- Discriminant_Specifications, Unknown_Discriminants_Present,
1937 -- and Defined_Identifier fields in the returned node.
1940 Make_Private_Extension_Declaration
(No_Location
,
1941 Defining_Identifier
=> Empty
,
1942 Subtype_Indication
=> Subtype_Indication
(Typedef_Node
),
1943 Abstract_Present
=> Abstract_Present
(Typedef_Node
),
1944 Interface_List
=> Interface_List
(Typedef_Node
));
1946 return Typedecl_Node
;
1948 -- Derived type definition with record extension part
1951 Set_Record_Extension_Part
(Typedef_Node
, P_Record_Definition
);
1952 return Typedef_Node
;
1955 -- Derived type definition with no record extension part
1958 return Typedef_Node
;
1960 end P_Derived_Type_Def_Or_Private_Ext_Decl
;
1962 ---------------------------
1963 -- 3.5 Range Constraint --
1964 ---------------------------
1966 -- RANGE_CONSTRAINT ::= range RANGE
1968 -- The caller has checked that the initial token is RANGE
1970 -- Error recovery: cannot raise Error_Resync
1972 function P_Range_Constraint
return Node_Id
is
1973 Range_Node
: Node_Id
;
1976 Range_Node
:= New_Node
(N_Range_Constraint
, Token_Ptr
);
1978 Set_Range_Expression
(Range_Node
, P_Range
);
1980 end P_Range_Constraint
;
1987 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
1989 -- Note: the range that appears in a membership test is parsed by
1990 -- P_Range_Or_Subtype_Mark (3.5).
1992 -- Error recovery: cannot raise Error_Resync
1994 function P_Range
return Node_Id
is
1995 Expr_Node
: Node_Id
;
1996 Range_Node
: Node_Id
;
1999 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2001 if Expr_Form
= EF_Range_Attr
then
2004 elsif Token
= Tok_Dot_Dot
then
2005 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2006 Set_Low_Bound
(Range_Node
, Expr_Node
);
2008 Expr_Node
:= P_Expression
;
2009 Check_Simple_Expression
(Expr_Node
);
2010 Set_High_Bound
(Range_Node
, Expr_Node
);
2013 -- Anything else is an error
2016 T_Dot_Dot
; -- force missing .. message
2021 ----------------------------------
2022 -- 3.5 P_Range_Or_Subtype_Mark --
2023 ----------------------------------
2026 -- RANGE_ATTRIBUTE_REFERENCE
2027 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2029 -- This routine scans out the range or subtype mark that forms the right
2030 -- operand of a membership test (it is not used in any other contexts, and
2031 -- error messages are specialized with this knowledge in mind).
2033 -- Note: as documented in the Sinfo interface, although the syntax only
2034 -- allows a subtype mark, we in fact allow any simple expression to be
2035 -- returned from this routine. The semantics is responsible for issuing
2036 -- an appropriate message complaining if the argument is not a name.
2037 -- This simplifies the coding and error recovery processing in the
2038 -- parser, and in any case it is preferable not to consider this a
2039 -- syntax error and to continue with the semantic analysis.
2041 -- Error recovery: cannot raise Error_Resync
2043 function P_Range_Or_Subtype_Mark
return Node_Id
is
2044 Expr_Node
: Node_Id
;
2045 Range_Node
: Node_Id
;
2046 Save_Loc
: Source_Ptr
;
2048 -- Start of processing for P_Range_Or_Subtype_Mark
2051 -- Save location of possible junk parentheses
2053 Save_Loc
:= Token_Ptr
;
2055 -- Scan out either a simple expression or a range (this accepts more
2056 -- than is legal here, but as explained above, we like to allow more
2057 -- with a proper diagnostic.
2059 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2063 if Expr_Form
= EF_Range_Attr
then
2066 -- Simple_Expression .. Simple_Expression
2068 elsif Token
= Tok_Dot_Dot
then
2069 Check_Simple_Expression
(Expr_Node
);
2070 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2071 Set_Low_Bound
(Range_Node
, Expr_Node
);
2073 Set_High_Bound
(Range_Node
, P_Simple_Expression
);
2076 -- Case of subtype mark (optionally qualified simple name or an
2077 -- attribute whose prefix is an optionally qualified simple name)
2079 elsif Expr_Form
= EF_Simple_Name
2080 or else Nkind
(Expr_Node
) = N_Attribute_Reference
2082 -- Check for error of range constraint after a subtype mark
2084 if Token
= Tok_Range
then
2085 Error_Msg_SC
("range constraint not allowed in membership test");
2089 -- Check for error of DIGITS or DELTA after a subtype mark
2091 elsif Token
= Tok_Digits
or else Token
= Tok_Delta
then
2093 ("accuracy definition not allowed in membership test");
2094 Scan
; -- past DIGITS or DELTA
2097 -- Attribute reference, may or may not be OK, but in any case we
2100 elsif Token
= Tok_Apostrophe
then
2101 return P_Subtype_Mark_Attribute
(Expr_Node
);
2103 -- OK case of simple name, just return it
2109 -- Here we have some kind of error situation. Check for junk parens
2110 -- then return what we have, caller will deal with other errors.
2113 if Nkind
(Expr_Node
) in N_Subexpr
2114 and then Paren_Count
(Expr_Node
) /= 0
2116 Error_Msg
("|parentheses not allowed for subtype mark", Save_Loc
);
2117 Set_Paren_Count
(Expr_Node
, 0);
2122 end P_Range_Or_Subtype_Mark
;
2124 ----------------------------------------
2125 -- 3.5.1 Enumeration Type Definition --
2126 ----------------------------------------
2128 -- ENUMERATION_TYPE_DEFINITION ::=
2129 -- (ENUMERATION_LITERAL_SPECIFICATION
2130 -- {, ENUMERATION_LITERAL_SPECIFICATION})
2132 -- The caller has already scanned out the TYPE keyword
2134 -- Error recovery: can raise Error_Resync;
2136 function P_Enumeration_Type_Definition
return Node_Id
is
2137 Typedef_Node
: Node_Id
;
2140 Typedef_Node
:= New_Node
(N_Enumeration_Type_Definition
, Token_Ptr
);
2141 Set_Literals
(Typedef_Node
, New_List
);
2146 Append
(P_Enumeration_Literal_Specification
, Literals
(Typedef_Node
));
2147 exit when not Comma_Present
;
2151 return Typedef_Node
;
2152 end P_Enumeration_Type_Definition
;
2154 ----------------------------------------------
2155 -- 3.5.1 Enumeration Literal Specification --
2156 ----------------------------------------------
2158 -- ENUMERATION_LITERAL_SPECIFICATION ::=
2159 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
2161 -- Error recovery: can raise Error_Resync
2163 function P_Enumeration_Literal_Specification
return Node_Id
is
2165 if Token
= Tok_Char_Literal
then
2166 return P_Defining_Character_Literal
;
2168 return P_Defining_Identifier
(C_Comma_Right_Paren
);
2170 end P_Enumeration_Literal_Specification
;
2172 ---------------------------------------
2173 -- 3.5.1 Defining_Character_Literal --
2174 ---------------------------------------
2176 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
2178 -- Error recovery: cannot raise Error_Resync
2180 -- The caller has checked that the current token is a character literal
2182 function P_Defining_Character_Literal
return Node_Id
is
2183 Literal_Node
: Node_Id
;
2186 Literal_Node
:= Token_Node
;
2187 Change_Character_Literal_To_Defining_Character_Literal
(Literal_Node
);
2188 Scan
; -- past character literal
2189 return Literal_Node
;
2190 end P_Defining_Character_Literal
;
2192 ------------------------------------
2193 -- 3.5.4 Integer Type Definition --
2194 ------------------------------------
2196 -- Parsed by P_Type_Declaration (3.2.1)
2198 -------------------------------------------
2199 -- 3.5.4 Signed Integer Type Definition --
2200 -------------------------------------------
2202 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
2203 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2205 -- Normally the initial token on entry is RANGE, but in some
2206 -- error conditions, the range token was missing and control is
2207 -- passed with Token pointing to first token of the first expression.
2209 -- Error recovery: cannot raise Error_Resync
2211 function P_Signed_Integer_Type_Definition
return Node_Id
is
2212 Typedef_Node
: Node_Id
;
2213 Expr_Node
: Node_Id
;
2216 Typedef_Node
:= New_Node
(N_Signed_Integer_Type_Definition
, Token_Ptr
);
2218 if Token
= Tok_Range
then
2222 Expr_Node
:= P_Expression
;
2223 Check_Simple_Expression
(Expr_Node
);
2224 Set_Low_Bound
(Typedef_Node
, Expr_Node
);
2226 Expr_Node
:= P_Expression
;
2227 Check_Simple_Expression
(Expr_Node
);
2228 Set_High_Bound
(Typedef_Node
, Expr_Node
);
2229 return Typedef_Node
;
2230 end P_Signed_Integer_Type_Definition
;
2232 ------------------------------------
2233 -- 3.5.4 Modular Type Definition --
2234 ------------------------------------
2236 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
2238 -- The caller has checked that the initial token is MOD
2240 -- Error recovery: cannot raise Error_Resync
2242 function P_Modular_Type_Definition
return Node_Id
is
2243 Typedef_Node
: Node_Id
;
2246 if Ada_Version
= Ada_83
then
2247 Error_Msg_SC
("(Ada 83): modular types not allowed");
2250 Typedef_Node
:= New_Node
(N_Modular_Type_Definition
, Token_Ptr
);
2252 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2254 -- Handle mod L..R cleanly
2256 if Token
= Tok_Dot_Dot
then
2257 Error_Msg_SC
("range not allowed for modular type");
2259 Set_Expression
(Typedef_Node
, P_Expression_No_Right_Paren
);
2262 return Typedef_Node
;
2263 end P_Modular_Type_Definition
;
2265 ---------------------------------
2266 -- 3.5.6 Real Type Definition --
2267 ---------------------------------
2269 -- Parsed by P_Type_Declaration (3.2.1)
2271 --------------------------------------
2272 -- 3.5.7 Floating Point Definition --
2273 --------------------------------------
2275 -- FLOATING_POINT_DEFINITION ::=
2276 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2278 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
2280 -- The caller has checked that the initial token is DIGITS
2282 -- Error recovery: cannot raise Error_Resync
2284 function P_Floating_Point_Definition
return Node_Id
is
2285 Digits_Loc
: constant Source_Ptr
:= Token_Ptr
;
2287 Expr_Node
: Node_Id
;
2290 Scan
; -- past DIGITS
2291 Expr_Node
:= P_Expression_No_Right_Paren
;
2292 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2294 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
2296 if Token
= Tok_Delta
then
2297 Error_Msg_SC
("|DELTA must come before DIGITS");
2298 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Digits_Loc
);
2300 Set_Delta_Expression
(Def_Node
, P_Expression_No_Right_Paren
);
2302 -- OK floating-point definition
2305 Def_Node
:= New_Node
(N_Floating_Point_Definition
, Digits_Loc
);
2308 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2309 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2311 end P_Floating_Point_Definition
;
2313 -------------------------------------
2314 -- 3.5.7 Real Range Specification --
2315 -------------------------------------
2317 -- REAL_RANGE_SPECIFICATION ::=
2318 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2320 -- Error recovery: cannot raise Error_Resync
2322 function P_Real_Range_Specification_Opt
return Node_Id
is
2323 Specification_Node
: Node_Id
;
2324 Expr_Node
: Node_Id
;
2327 if Token
= Tok_Range
then
2328 Specification_Node
:=
2329 New_Node
(N_Real_Range_Specification
, Token_Ptr
);
2331 Expr_Node
:= P_Expression_No_Right_Paren
;
2332 Check_Simple_Expression
(Expr_Node
);
2333 Set_Low_Bound
(Specification_Node
, Expr_Node
);
2335 Expr_Node
:= P_Expression_No_Right_Paren
;
2336 Check_Simple_Expression
(Expr_Node
);
2337 Set_High_Bound
(Specification_Node
, Expr_Node
);
2338 return Specification_Node
;
2342 end P_Real_Range_Specification_Opt
;
2344 -----------------------------------
2345 -- 3.5.9 Fixed Point Definition --
2346 -----------------------------------
2348 -- FIXED_POINT_DEFINITION ::=
2349 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
2351 -- ORDINARY_FIXED_POINT_DEFINITION ::=
2352 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
2354 -- DECIMAL_FIXED_POINT_DEFINITION ::=
2355 -- delta static_EXPRESSION
2356 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2358 -- The caller has checked that the initial token is DELTA
2360 -- Error recovery: cannot raise Error_Resync
2362 function P_Fixed_Point_Definition
return Node_Id
is
2363 Delta_Node
: Node_Id
;
2364 Delta_Loc
: Source_Ptr
;
2366 Expr_Node
: Node_Id
;
2369 Delta_Loc
:= Token_Ptr
;
2371 Delta_Node
:= P_Expression_No_Right_Paren
;
2372 Check_Simple_Expression_In_Ada_83
(Delta_Node
);
2374 if Token
= Tok_Digits
then
2375 if Ada_Version
= Ada_83
then
2376 Error_Msg_SC
("(Ada 83) decimal fixed type not allowed!");
2379 Def_Node
:= New_Node
(N_Decimal_Fixed_Point_Definition
, Delta_Loc
);
2380 Scan
; -- past DIGITS
2381 Expr_Node
:= P_Expression_No_Right_Paren
;
2382 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2383 Set_Digits_Expression
(Def_Node
, Expr_Node
);
2386 Def_Node
:= New_Node
(N_Ordinary_Fixed_Point_Definition
, Delta_Loc
);
2388 -- Range is required in ordinary fixed point case
2390 if Token
/= Tok_Range
then
2391 Error_Msg_AP
("range must be given for fixed-point type");
2396 Set_Delta_Expression
(Def_Node
, Delta_Node
);
2397 Set_Real_Range_Specification
(Def_Node
, P_Real_Range_Specification_Opt
);
2399 end P_Fixed_Point_Definition
;
2401 --------------------------------------------
2402 -- 3.5.9 Ordinary Fixed Point Definition --
2403 --------------------------------------------
2405 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2407 -------------------------------------------
2408 -- 3.5.9 Decimal Fixed Point Definition --
2409 -------------------------------------------
2411 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2413 ------------------------------
2414 -- 3.5.9 Digits Constraint --
2415 ------------------------------
2417 -- DIGITS_CONSTRAINT ::=
2418 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2420 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2422 -- The caller has checked that the initial token is DIGITS
2424 function P_Digits_Constraint
return Node_Id
is
2425 Constraint_Node
: Node_Id
;
2426 Expr_Node
: Node_Id
;
2429 Constraint_Node
:= New_Node
(N_Digits_Constraint
, Token_Ptr
);
2430 Scan
; -- past DIGITS
2431 Expr_Node
:= P_Expression
;
2432 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2433 Set_Digits_Expression
(Constraint_Node
, Expr_Node
);
2435 if Token
= Tok_Range
then
2436 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2439 return Constraint_Node
;
2440 end P_Digits_Constraint
;
2442 -----------------------------
2443 -- 3.5.9 Delta Constraint --
2444 -----------------------------
2446 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2448 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2450 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2452 -- The caller has checked that the initial token is DELTA
2454 -- Error recovery: cannot raise Error_Resync
2456 function P_Delta_Constraint
return Node_Id
is
2457 Constraint_Node
: Node_Id
;
2458 Expr_Node
: Node_Id
;
2461 Constraint_Node
:= New_Node
(N_Delta_Constraint
, Token_Ptr
);
2463 Expr_Node
:= P_Expression
;
2464 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
2465 Set_Delta_Expression
(Constraint_Node
, Expr_Node
);
2467 if Token
= Tok_Range
then
2468 Set_Range_Constraint
(Constraint_Node
, P_Range_Constraint
);
2471 return Constraint_Node
;
2472 end P_Delta_Constraint
;
2474 --------------------------------
2475 -- 3.6 Array Type Definition --
2476 --------------------------------
2478 -- ARRAY_TYPE_DEFINITION ::=
2479 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2481 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2482 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2483 -- COMPONENT_DEFINITION
2485 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2487 -- CONSTRAINED_ARRAY_DEFINITION ::=
2488 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2489 -- COMPONENT_DEFINITION
2491 -- DISCRETE_SUBTYPE_DEFINITION ::=
2492 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2494 -- COMPONENT_DEFINITION ::=
2495 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2497 -- The caller has checked that the initial token is ARRAY
2499 -- Error recovery: can raise Error_Resync
2501 function P_Array_Type_Definition
return Node_Id
is
2502 Array_Loc
: Source_Ptr
;
2503 CompDef_Node
: Node_Id
;
2505 Not_Null_Present
: Boolean := False;
2506 Subs_List
: List_Id
;
2507 Scan_State
: Saved_Scan_State
;
2508 Aliased_Present
: Boolean := False;
2511 Array_Loc
:= Token_Ptr
;
2513 Subs_List
:= New_List
;
2516 -- It's quite tricky to disentangle these two possibilities, so we do
2517 -- a prescan to determine which case we have and then reset the scan.
2518 -- The prescan skips past possible subtype mark tokens.
2520 Save_Scan_State
(Scan_State
); -- just after paren
2522 while Token
in Token_Class_Desig
or else
2523 Token
= Tok_Dot
or else
2524 Token
= Tok_Apostrophe
-- because of 'BASE, 'CLASS
2529 -- If we end up on RANGE <> then we have the unconstrained case. We
2530 -- will also allow the RANGE to be omitted, just to improve error
2531 -- handling for a case like array (integer <>) of integer;
2533 Scan
; -- past possible RANGE or <>
2535 if (Prev_Token
= Tok_Range
and then Token
= Tok_Box
) or else
2536 Prev_Token
= Tok_Box
2538 Def_Node
:= New_Node
(N_Unconstrained_Array_Definition
, Array_Loc
);
2539 Restore_Scan_State
(Scan_State
); -- to first subtype mark
2542 Append
(P_Subtype_Mark_Resync
, Subs_List
);
2545 exit when Token
= Tok_Right_Paren
or else Token
= Tok_Of
;
2549 Set_Subtype_Marks
(Def_Node
, Subs_List
);
2552 Def_Node
:= New_Node
(N_Constrained_Array_Definition
, Array_Loc
);
2553 Restore_Scan_State
(Scan_State
); -- to first discrete range
2556 Append
(P_Discrete_Subtype_Definition
, Subs_List
);
2557 exit when not Comma_Present
;
2560 Set_Discrete_Subtype_Definitions
(Def_Node
, Subs_List
);
2566 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
2568 if Token_Name
= Name_Aliased
then
2569 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
2572 if Token
= Tok_Aliased
then
2573 Aliased_Present
:= True;
2574 Scan
; -- past ALIASED
2577 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
2579 -- Ada 2005 (AI-230): Access Definition case
2581 if Token
= Tok_Access
then
2582 if Ada_Version
< Ada_05
then
2584 ("generalized use of anonymous access types " &
2585 "is an Ada 2005 extension");
2586 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
2589 if Aliased_Present
then
2590 Error_Msg_SP
("ALIASED not allowed here");
2593 Set_Subtype_Indication
(CompDef_Node
, Empty
);
2594 Set_Aliased_Present
(CompDef_Node
, False);
2595 Set_Access_Definition
(CompDef_Node
,
2596 P_Access_Definition
(Not_Null_Present
));
2599 Set_Access_Definition
(CompDef_Node
, Empty
);
2600 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
2601 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
2602 Set_Subtype_Indication
(CompDef_Node
,
2603 P_Subtype_Indication
(Not_Null_Present
));
2606 Set_Component_Definition
(Def_Node
, CompDef_Node
);
2609 end P_Array_Type_Definition
;
2611 -----------------------------------------
2612 -- 3.6 Unconstrained Array Definition --
2613 -----------------------------------------
2615 -- Parsed by P_Array_Type_Definition (3.6)
2617 ---------------------------------------
2618 -- 3.6 Constrained Array Definition --
2619 ---------------------------------------
2621 -- Parsed by P_Array_Type_Definition (3.6)
2623 --------------------------------------
2624 -- 3.6 Discrete Subtype Definition --
2625 --------------------------------------
2627 -- DISCRETE_SUBTYPE_DEFINITION ::=
2628 -- discrete_SUBTYPE_INDICATION | RANGE
2630 -- Note: the discrete subtype definition appearing in a constrained
2631 -- array definition is parsed by P_Array_Type_Definition (3.6)
2633 -- Error recovery: cannot raise Error_Resync
2635 function P_Discrete_Subtype_Definition
return Node_Id
is
2637 -- The syntax of a discrete subtype definition is identical to that
2638 -- of a discrete range, so we simply share the same parsing code.
2640 return P_Discrete_Range
;
2641 end P_Discrete_Subtype_Definition
;
2643 -------------------------------
2644 -- 3.6 Component Definition --
2645 -------------------------------
2647 -- For the array case, parsed by P_Array_Type_Definition (3.6)
2648 -- For the record case, parsed by P_Component_Declaration (3.8)
2650 -----------------------------
2651 -- 3.6.1 Index Constraint --
2652 -----------------------------
2654 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2656 ---------------------------
2657 -- 3.6.1 Discrete Range --
2658 ---------------------------
2660 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
2662 -- The possible forms for a discrete range are:
2664 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
2665 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
2666 -- Range_Attribute (RANGE, 3.5)
2667 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
2669 -- Error recovery: cannot raise Error_Resync
2671 function P_Discrete_Range
return Node_Id
is
2672 Expr_Node
: Node_Id
;
2673 Range_Node
: Node_Id
;
2676 Expr_Node
:= P_Simple_Expression_Or_Range_Attribute
;
2678 if Expr_Form
= EF_Range_Attr
then
2681 elsif Token
= Tok_Range
then
2682 if Expr_Form
/= EF_Simple_Name
then
2683 Error_Msg_SC
("range must be preceded by subtype mark");
2686 return P_Subtype_Indication
(Expr_Node
);
2688 -- Check Expression .. Expression case
2690 elsif Token
= Tok_Dot_Dot
then
2691 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
2692 Set_Low_Bound
(Range_Node
, Expr_Node
);
2694 Expr_Node
:= P_Expression
;
2695 Check_Simple_Expression
(Expr_Node
);
2696 Set_High_Bound
(Range_Node
, Expr_Node
);
2699 -- Otherwise we must have a subtype mark
2701 elsif Expr_Form
= EF_Simple_Name
then
2704 -- If incorrect, complain that we expect ..
2710 end P_Discrete_Range
;
2712 ----------------------------
2713 -- 3.7 Discriminant Part --
2714 ----------------------------
2716 -- DISCRIMINANT_PART ::=
2717 -- UNKNOWN_DISCRIMINANT_PART
2718 -- | KNOWN_DISCRIMINANT_PART
2720 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
2721 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
2723 ------------------------------------
2724 -- 3.7 Unknown Discriminant Part --
2725 ------------------------------------
2727 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
2729 -- If no unknown discriminant part is present, then False is returned,
2730 -- otherwise the unknown discriminant is scanned out and True is returned.
2732 -- Error recovery: cannot raise Error_Resync
2734 function P_Unknown_Discriminant_Part_Opt
return Boolean is
2735 Scan_State
: Saved_Scan_State
;
2738 -- If <> right now, then this is missing left paren
2740 if Token
= Tok_Box
then
2743 -- If not <> or left paren, then definitely no box
2745 elsif Token
/= Tok_Left_Paren
then
2748 -- Left paren, so might be a box after it
2751 Save_Scan_State
(Scan_State
);
2752 Scan
; -- past the left paren
2754 if Token
/= Tok_Box
then
2755 Restore_Scan_State
(Scan_State
);
2760 -- We are now pointing to the box
2762 if Ada_Version
= Ada_83
then
2763 Error_Msg_SC
("(Ada 83) unknown discriminant not allowed!");
2766 Scan
; -- past the box
2767 U_Right_Paren
; -- must be followed by right paren
2769 end P_Unknown_Discriminant_Part_Opt
;
2771 ----------------------------------
2772 -- 3.7 Known Discriminant Part --
2773 ----------------------------------
2775 -- KNOWN_DISCRIMINANT_PART ::=
2776 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
2778 -- DISCRIMINANT_SPECIFICATION ::=
2779 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
2780 -- [:= DEFAULT_EXPRESSION]
2781 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
2782 -- [:= DEFAULT_EXPRESSION]
2784 -- If no known discriminant part is present, then No_List is returned
2786 -- Error recovery: cannot raise Error_Resync
2788 function P_Known_Discriminant_Part_Opt
return List_Id
is
2789 Specification_Node
: Node_Id
;
2790 Specification_List
: List_Id
;
2791 Ident_Sloc
: Source_Ptr
;
2792 Scan_State
: Saved_Scan_State
;
2794 Not_Null_Present
: Boolean;
2797 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
2798 -- This array holds the list of defining identifiers. The upper bound
2799 -- of 4096 is intended to be essentially infinite, and we do not even
2800 -- bother to check for it being exceeded.
2803 if Token
= Tok_Left_Paren
then
2804 Specification_List
:= New_List
;
2806 P_Pragmas_Misplaced
;
2808 Specification_Loop
: loop
2810 Ident_Sloc
:= Token_Ptr
;
2811 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
2814 while Comma_Present
loop
2815 Num_Idents
:= Num_Idents
+ 1;
2816 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
2819 -- If there are multiple identifiers, we repeatedly scan the
2820 -- type and initialization expression information by resetting
2821 -- the scan pointer (so that we get completely separate trees
2822 -- for each occurrence).
2824 if Num_Idents
> 1 then
2825 Save_Scan_State
(Scan_State
);
2830 -- Loop through defining identifiers in list
2834 Specification_Node
:=
2835 New_Node
(N_Discriminant_Specification
, Ident_Sloc
);
2836 Set_Defining_Identifier
(Specification_Node
, Idents
(Ident
));
2837 Not_Null_Present
:= -- Ada 2005 (AI-231, AI-447)
2838 P_Null_Exclusion
(Allow_Anonymous_In_95
=> True);
2840 if Token
= Tok_Access
then
2841 if Ada_Version
= Ada_83
then
2843 ("(Ada 83) access discriminant not allowed!");
2846 Set_Discriminant_Type
2847 (Specification_Node
,
2848 P_Access_Definition
(Not_Null_Present
));
2851 Set_Discriminant_Type
2852 (Specification_Node
, P_Subtype_Mark
);
2854 Set_Null_Exclusion_Present
-- Ada 2005 (AI-231)
2855 (Specification_Node
, Not_Null_Present
);
2859 (Specification_Node
, Init_Expr_Opt
(True));
2862 Set_Prev_Ids
(Specification_Node
, True);
2865 if Ident
< Num_Idents
then
2866 Set_More_Ids
(Specification_Node
, True);
2869 Append
(Specification_Node
, Specification_List
);
2870 exit Ident_Loop
when Ident
= Num_Idents
;
2872 Restore_Scan_State
(Scan_State
);
2874 end loop Ident_Loop
;
2876 exit Specification_Loop
when Token
/= Tok_Semicolon
;
2878 P_Pragmas_Misplaced
;
2879 end loop Specification_Loop
;
2882 return Specification_List
;
2887 end P_Known_Discriminant_Part_Opt
;
2889 -------------------------------------
2890 -- 3.7 Discriminant Specification --
2891 -------------------------------------
2893 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
2895 -----------------------------
2896 -- 3.7 Default Expression --
2897 -----------------------------
2899 -- Always parsed (simply as an Expression) by the parent construct
2901 ------------------------------------
2902 -- 3.7.1 Discriminant Constraint --
2903 ------------------------------------
2905 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2907 --------------------------------------------------------
2908 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
2909 --------------------------------------------------------
2911 -- DISCRIMINANT_CONSTRAINT ::=
2912 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
2914 -- DISCRIMINANT_ASSOCIATION ::=
2915 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
2918 -- This routine parses either an index or a discriminant constraint. As
2919 -- is clear from the above grammar, it is often possible to clearly
2920 -- determine which of the two possibilities we have, but there are
2921 -- cases (those in which we have a series of expressions of the same
2922 -- syntactic form as subtype indications), where we cannot tell. Since
2923 -- this means that in any case the semantic phase has to distinguish
2924 -- between the two, there is not much point in the parser trying to
2925 -- distinguish even those cases where the difference is clear. In any
2926 -- case, if we have a situation like:
2928 -- (A => 123, 235 .. 500)
2930 -- it is not clear which of the two items is the wrong one, better to
2931 -- let the semantic phase give a clear message. Consequently, this
2932 -- routine in general returns a list of items which can be either
2933 -- discrete ranges or discriminant associations.
2935 -- The caller has checked that the initial token is a left paren
2937 -- Error recovery: can raise Error_Resync
2939 function P_Index_Or_Discriminant_Constraint
return Node_Id
is
2940 Scan_State
: Saved_Scan_State
;
2941 Constr_Node
: Node_Id
;
2942 Constr_List
: List_Id
;
2943 Expr_Node
: Node_Id
;
2944 Result_Node
: Node_Id
;
2947 Result_Node
:= New_Node
(N_Index_Or_Discriminant_Constraint
, Token_Ptr
);
2949 Constr_List
:= New_List
;
2950 Set_Constraints
(Result_Node
, Constr_List
);
2952 -- The two syntactic forms are a little mixed up, so what we are doing
2953 -- here is looking at the first entry to determine which case we have
2955 -- A discriminant constraint is a list of discriminant associations,
2956 -- which have one of the following possible forms:
2960 -- Id | Id | .. | Id => Expression
2962 -- An index constraint is a list of discrete ranges which have one
2963 -- of the following possible forms:
2966 -- Subtype_Mark range Range
2968 -- Simple_Expression .. Simple_Expression
2970 -- Loop through discriminants in list
2973 -- Check cases of Id => Expression or Id | Id => Expression
2975 if Token
= Tok_Identifier
then
2976 Save_Scan_State
(Scan_State
); -- at Id
2979 if Token
= Tok_Arrow
or else Token
= Tok_Vertical_Bar
then
2980 Restore_Scan_State
(Scan_State
); -- to Id
2981 Append
(P_Discriminant_Association
, Constr_List
);
2984 Restore_Scan_State
(Scan_State
); -- to Id
2988 -- Otherwise scan out an expression and see what we have got
2990 Expr_Node
:= P_Expression_Or_Range_Attribute
;
2992 if Expr_Form
= EF_Range_Attr
then
2993 Append
(Expr_Node
, Constr_List
);
2995 elsif Token
= Tok_Range
then
2996 if Expr_Form
/= EF_Simple_Name
then
2997 Error_Msg_SC
("subtype mark required before RANGE");
3000 Append
(P_Subtype_Indication
(Expr_Node
), Constr_List
);
3003 -- Check Simple_Expression .. Simple_Expression case
3005 elsif Token
= Tok_Dot_Dot
then
3006 Check_Simple_Expression
(Expr_Node
);
3007 Constr_Node
:= New_Node
(N_Range
, Token_Ptr
);
3008 Set_Low_Bound
(Constr_Node
, Expr_Node
);
3010 Expr_Node
:= P_Expression
;
3011 Check_Simple_Expression
(Expr_Node
);
3012 Set_High_Bound
(Constr_Node
, Expr_Node
);
3013 Append
(Constr_Node
, Constr_List
);
3016 -- Case of an expression which could be either form
3019 Append
(Expr_Node
, Constr_List
);
3023 -- Here with a single entry scanned
3026 exit when not Comma_Present
;
3032 end P_Index_Or_Discriminant_Constraint
;
3034 -------------------------------------
3035 -- 3.7.1 Discriminant Association --
3036 -------------------------------------
3038 -- DISCRIMINANT_ASSOCIATION ::=
3039 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3042 -- This routine is used only when the name list is present and the caller
3043 -- has already checked this (by scanning ahead and repositioning the
3046 -- Error_Recovery: cannot raise Error_Resync;
3048 function P_Discriminant_Association
return Node_Id
is
3049 Discr_Node
: Node_Id
;
3050 Names_List
: List_Id
;
3051 Ident_Sloc
: Source_Ptr
;
3054 Ident_Sloc
:= Token_Ptr
;
3055 Names_List
:= New_List
;
3058 Append
(P_Identifier
(C_Vertical_Bar_Arrow
), Names_List
);
3059 exit when Token
/= Tok_Vertical_Bar
;
3063 Discr_Node
:= New_Node
(N_Discriminant_Association
, Ident_Sloc
);
3064 Set_Selector_Names
(Discr_Node
, Names_List
);
3066 Set_Expression
(Discr_Node
, P_Expression
);
3068 end P_Discriminant_Association
;
3070 ---------------------------------
3071 -- 3.8 Record Type Definition --
3072 ---------------------------------
3074 -- RECORD_TYPE_DEFINITION ::=
3075 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3077 -- There is no node in the tree for a record type definition. Instead
3078 -- a record definition node appears, with possible Abstract_Present,
3079 -- Tagged_Present, and Limited_Present flags set appropriately.
3081 ----------------------------
3082 -- 3.8 Record Definition --
3083 ----------------------------
3085 -- RECORD_DEFINITION ::=
3091 -- Note: in the case where a record definition node is used to represent
3092 -- a record type definition, the caller sets the Tagged_Present and
3093 -- Limited_Present flags in the resulting N_Record_Definition node as
3096 -- Note that the RECORD token at the start may be missing in certain
3097 -- error situations, so this function is expected to post the error
3099 -- Error recovery: can raise Error_Resync
3101 function P_Record_Definition
return Node_Id
is
3105 Rec_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3109 if Token
= Tok_Null
then
3112 Set_Null_Present
(Rec_Node
, True);
3114 -- Catch incomplete declaration to prevent cascaded errors, see
3115 -- ACATS B393002 for an example.
3117 elsif Token
= Tok_Semicolon
then
3118 Error_Msg_AP
("missing record definition");
3120 -- Case starting with RECORD keyword. Build scope stack entry. For the
3121 -- column, we use the first non-blank character on the line, to deal
3122 -- with situations such as:
3128 -- which is not official RM indentation, but is not uncommon usage, and
3129 -- in particular is standard GNAT coding style, so handle it nicely.
3133 Scope
.Table
(Scope
.Last
).Etyp
:= E_Record
;
3134 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3135 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3136 Scope
.Table
(Scope
.Last
).Labl
:= Error
;
3137 Scope
.Table
(Scope
.Last
).Junk
:= (Token
/= Tok_Record
);
3141 Set_Component_List
(Rec_Node
, P_Component_List
);
3144 exit when Check_End
;
3145 Discard_Junk_Node
(P_Component_List
);
3150 end P_Record_Definition
;
3152 -------------------------
3153 -- 3.8 Component List --
3154 -------------------------
3156 -- COMPONENT_LIST ::=
3157 -- COMPONENT_ITEM {COMPONENT_ITEM}
3158 -- | {COMPONENT_ITEM} VARIANT_PART
3161 -- Error recovery: cannot raise Error_Resync
3163 function P_Component_List
return Node_Id
is
3164 Component_List_Node
: Node_Id
;
3165 Decls_List
: List_Id
;
3166 Scan_State
: Saved_Scan_State
;
3169 Component_List_Node
:= New_Node
(N_Component_List
, Token_Ptr
);
3170 Decls_List
:= New_List
;
3172 if Token
= Tok_Null
then
3175 P_Pragmas_Opt
(Decls_List
);
3176 Set_Null_Present
(Component_List_Node
, True);
3177 return Component_List_Node
;
3180 P_Pragmas_Opt
(Decls_List
);
3182 if Token
/= Tok_Case
then
3183 Component_Scan_Loop
: loop
3184 P_Component_Items
(Decls_List
);
3185 P_Pragmas_Opt
(Decls_List
);
3187 exit Component_Scan_Loop
when Token
= Tok_End
3188 or else Token
= Tok_Case
3189 or else Token
= Tok_When
;
3191 -- We are done if we do not have an identifier. However, if
3192 -- we have a misspelled reserved identifier that is in a column
3193 -- to the right of the record definition, we will treat it as
3194 -- an identifier. It turns out to be too dangerous in practice
3195 -- to accept such a mis-spelled identifier which does not have
3196 -- this additional clue that confirms the incorrect spelling.
3198 if Token
/= Tok_Identifier
then
3199 if Start_Column
> Scope
.Table
(Scope
.Last
).Ecol
3200 and then Is_Reserved_Identifier
3202 Save_Scan_State
(Scan_State
); -- at reserved id
3203 Scan
; -- possible reserved id
3205 if Token
= Tok_Comma
or else Token
= Tok_Colon
then
3206 Restore_Scan_State
(Scan_State
);
3207 Scan_Reserved_Identifier
(Force_Msg
=> True);
3209 -- Note reserved identifier used as field name after
3210 -- all because not followed by colon or comma
3213 Restore_Scan_State
(Scan_State
);
3214 exit Component_Scan_Loop
;
3217 -- Non-identifier that definitely was not reserved id
3220 exit Component_Scan_Loop
;
3223 end loop Component_Scan_Loop
;
3226 if Token
= Tok_Case
then
3227 Set_Variant_Part
(Component_List_Node
, P_Variant_Part
);
3229 -- Check for junk after variant part
3231 if Token
= Tok_Identifier
then
3232 Save_Scan_State
(Scan_State
);
3233 Scan
; -- past identifier
3235 if Token
= Tok_Colon
then
3236 Restore_Scan_State
(Scan_State
);
3237 Error_Msg_SC
("component may not follow variant part");
3238 Discard_Junk_Node
(P_Component_List
);
3240 elsif Token
= Tok_Case
then
3241 Restore_Scan_State
(Scan_State
);
3242 Error_Msg_SC
("only one variant part allowed in a record");
3243 Discard_Junk_Node
(P_Component_List
);
3246 Restore_Scan_State
(Scan_State
);
3252 Set_Component_Items
(Component_List_Node
, Decls_List
);
3253 return Component_List_Node
;
3254 end P_Component_List
;
3256 -------------------------
3257 -- 3.8 Component Item --
3258 -------------------------
3260 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3262 -- COMPONENT_DECLARATION ::=
3263 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3264 -- [:= DEFAULT_EXPRESSION];
3266 -- COMPONENT_DEFINITION ::=
3267 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3269 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3270 -- the scan is positioned past the following semicolon.
3272 -- Note: we do not yet allow representation clauses to appear as component
3273 -- items, do we need to add this capability sometime in the future ???
3275 procedure P_Component_Items
(Decls
: List_Id
) is
3276 Aliased_Present
: Boolean := False;
3277 CompDef_Node
: Node_Id
;
3278 Decl_Node
: Node_Id
;
3279 Scan_State
: Saved_Scan_State
;
3280 Not_Null_Present
: Boolean := False;
3283 Ident_Sloc
: Source_Ptr
;
3285 Idents
: array (Int
range 1 .. 4096) of Entity_Id
;
3286 -- This array holds the list of defining identifiers. The upper bound
3287 -- of 4096 is intended to be essentially infinite, and we do not even
3288 -- bother to check for it being exceeded.
3291 if Token
/= Tok_Identifier
then
3292 Error_Msg_SC
("component declaration expected");
3293 Resync_Past_Semicolon
;
3297 Ident_Sloc
:= Token_Ptr
;
3298 Idents
(1) := P_Defining_Identifier
(C_Comma_Colon
);
3301 while Comma_Present
loop
3302 Num_Idents
:= Num_Idents
+ 1;
3303 Idents
(Num_Idents
) := P_Defining_Identifier
(C_Comma_Colon
);
3306 -- If there are multiple identifiers, we repeatedly scan the
3307 -- type and initialization expression information by resetting
3308 -- the scan pointer (so that we get completely separate trees
3309 -- for each occurrence).
3311 if Num_Idents
> 1 then
3312 Save_Scan_State
(Scan_State
);
3317 -- Loop through defining identifiers in list
3322 -- The following block is present to catch Error_Resync
3323 -- which causes the parse to be reset past the semicolon
3326 Decl_Node
:= New_Node
(N_Component_Declaration
, Ident_Sloc
);
3327 Set_Defining_Identifier
(Decl_Node
, Idents
(Ident
));
3329 if Token
= Tok_Constant
then
3330 Error_Msg_SC
("constant components are not permitted");
3334 CompDef_Node
:= New_Node
(N_Component_Definition
, Token_Ptr
);
3336 if Token_Name
= Name_Aliased
then
3337 Check_95_Keyword
(Tok_Aliased
, Tok_Identifier
);
3340 if Token
= Tok_Aliased
then
3341 Aliased_Present
:= True;
3342 Scan
; -- past ALIASED
3345 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231/AI-254)
3347 -- Ada 2005 (AI-230): Access Definition case
3349 if Token
= Tok_Access
then
3350 if Ada_Version
< Ada_05
then
3352 ("generalized use of anonymous access types " &
3353 "is an Ada 2005 extension");
3354 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3357 if Aliased_Present
then
3358 Error_Msg_SP
("ALIASED not allowed here");
3361 Set_Subtype_Indication
(CompDef_Node
, Empty
);
3362 Set_Aliased_Present
(CompDef_Node
, False);
3363 Set_Access_Definition
(CompDef_Node
,
3364 P_Access_Definition
(Not_Null_Present
));
3367 Set_Access_Definition
(CompDef_Node
, Empty
);
3368 Set_Aliased_Present
(CompDef_Node
, Aliased_Present
);
3369 Set_Null_Exclusion_Present
(CompDef_Node
, Not_Null_Present
);
3371 if Token
= Tok_Array
then
3373 ("anonymous arrays not allowed as components");
3377 Set_Subtype_Indication
(CompDef_Node
,
3378 P_Subtype_Indication
(Not_Null_Present
));
3381 Set_Component_Definition
(Decl_Node
, CompDef_Node
);
3382 Set_Expression
(Decl_Node
, Init_Expr_Opt
);
3385 Set_Prev_Ids
(Decl_Node
, True);
3388 if Ident
< Num_Idents
then
3389 Set_More_Ids
(Decl_Node
, True);
3392 Append
(Decl_Node
, Decls
);
3395 when Error_Resync
=>
3396 if Token
/= Tok_End
then
3397 Resync_Past_Semicolon
;
3401 exit Ident_Loop
when Ident
= Num_Idents
;
3403 Restore_Scan_State
(Scan_State
);
3406 end loop Ident_Loop
;
3409 end P_Component_Items
;
3411 --------------------------------
3412 -- 3.8 Component Declaration --
3413 --------------------------------
3415 -- Parsed by P_Component_Items (3.8)
3417 -------------------------
3418 -- 3.8.1 Variant Part --
3419 -------------------------
3422 -- case discriminant_DIRECT_NAME is
3427 -- The caller has checked that the initial token is CASE
3429 -- Error recovery: cannot raise Error_Resync
3431 function P_Variant_Part
return Node_Id
is
3432 Variant_Part_Node
: Node_Id
;
3433 Variants_List
: List_Id
;
3434 Case_Node
: Node_Id
;
3437 Variant_Part_Node
:= New_Node
(N_Variant_Part
, Token_Ptr
);
3439 Scope
.Table
(Scope
.Last
).Etyp
:= E_Case
;
3440 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
3441 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
3444 Case_Node
:= P_Expression
;
3445 Set_Name
(Variant_Part_Node
, Case_Node
);
3447 if Nkind
(Case_Node
) /= N_Identifier
then
3448 Set_Name
(Variant_Part_Node
, Error
);
3449 Error_Msg
("discriminant name expected", Sloc
(Case_Node
));
3451 elsif Paren_Count
(Case_Node
) /= 0 then
3452 Error_Msg
("|discriminant name may not be parenthesized",
3454 Set_Paren_Count
(Case_Node
, 0);
3458 Variants_List
:= New_List
;
3459 P_Pragmas_Opt
(Variants_List
);
3461 -- Test missing variant
3463 if Token
= Tok_End
then
3464 Error_Msg_BC
("WHEN expected (must have at least one variant)");
3466 Append
(P_Variant
, Variants_List
);
3469 -- Loop through variants, note that we allow if in place of when,
3470 -- this error will be detected and handled in P_Variant.
3473 P_Pragmas_Opt
(Variants_List
);
3475 if Token
/= Tok_When
3476 and then Token
/= Tok_If
3477 and then Token
/= Tok_Others
3479 exit when Check_End
;
3482 Append
(P_Variant
, Variants_List
);
3485 Set_Variants
(Variant_Part_Node
, Variants_List
);
3486 return Variant_Part_Node
;
3489 --------------------
3491 --------------------
3494 -- when DISCRETE_CHOICE_LIST =>
3497 -- Error recovery: cannot raise Error_Resync
3499 -- The initial token on entry is either WHEN, IF or OTHERS
3501 function P_Variant
return Node_Id
is
3502 Variant_Node
: Node_Id
;
3505 -- Special check to recover nicely from use of IF in place of WHEN
3507 if Token
= Tok_If
then
3514 Variant_Node
:= New_Node
(N_Variant
, Prev_Token_Ptr
);
3515 Set_Discrete_Choices
(Variant_Node
, P_Discrete_Choice_List
);
3517 Set_Component_List
(Variant_Node
, P_Component_List
);
3518 return Variant_Node
;
3521 ---------------------------------
3522 -- 3.8.1 Discrete Choice List --
3523 ---------------------------------
3525 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3527 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3529 -- Note: in Ada 83, the expression must be a simple expression
3531 -- Error recovery: cannot raise Error_Resync
3533 function P_Discrete_Choice_List
return List_Id
is
3535 Expr_Node
: Node_Id
;
3536 Choice_Node
: Node_Id
;
3539 Choices
:= New_List
;
3542 if Token
= Tok_Others
then
3543 Append
(New_Node
(N_Others_Choice
, Token_Ptr
), Choices
);
3544 Scan
; -- past OTHERS
3548 Expr_Node
:= P_Expression_Or_Range_Attribute
;
3549 Ignore
(Tok_Right_Paren
);
3551 if Token
= Tok_Colon
3552 and then Nkind
(Expr_Node
) = N_Identifier
3554 Error_Msg_SP
("label not permitted in this context");
3557 elsif Expr_Form
= EF_Range_Attr
then
3558 Append
(Expr_Node
, Choices
);
3560 elsif Token
= Tok_Dot_Dot
then
3561 Check_Simple_Expression
(Expr_Node
);
3562 Choice_Node
:= New_Node
(N_Range
, Token_Ptr
);
3563 Set_Low_Bound
(Choice_Node
, Expr_Node
);
3565 Expr_Node
:= P_Expression_No_Right_Paren
;
3566 Check_Simple_Expression
(Expr_Node
);
3567 Set_High_Bound
(Choice_Node
, Expr_Node
);
3568 Append
(Choice_Node
, Choices
);
3570 elsif Expr_Form
= EF_Simple_Name
then
3571 if Token
= Tok_Range
then
3572 Append
(P_Subtype_Indication
(Expr_Node
), Choices
);
3574 elsif Token
in Token_Class_Consk
then
3576 ("the only constraint allowed here " &
3577 "is a range constraint");
3578 Discard_Junk_Node
(P_Constraint_Opt
);
3579 Append
(Expr_Node
, Choices
);
3582 Append
(Expr_Node
, Choices
);
3586 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
3587 Append
(Expr_Node
, Choices
);
3591 when Error_Resync
=>
3597 if Token
= Tok_Comma
then
3598 Error_Msg_SC
(""","" should be ""'|""");
3600 exit when Token
/= Tok_Vertical_Bar
;
3603 Scan
; -- past | or comma
3607 end P_Discrete_Choice_List
;
3609 ----------------------------
3610 -- 3.8.1 Discrete Choice --
3611 ----------------------------
3613 -- Parsed by P_Discrete_Choice_List (3.8.1)
3615 ----------------------------------
3616 -- 3.9.1 Record Extension Part --
3617 ----------------------------------
3619 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
3621 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
3623 --------------------------------------
3624 -- 3.9.4 Interface Type Definition --
3625 --------------------------------------
3627 -- INTERFACE_TYPE_DEFINITION ::=
3628 -- [limited | task | protected | synchronized] interface
3629 -- [and INTERFACE_LIST]
3631 -- Error recovery: cannot raise Error_Resync
3633 function P_Interface_Type_Definition
3634 (Abstract_Present
: Boolean) return Node_Id
3636 Typedef_Node
: Node_Id
;
3639 if Ada_Version
< Ada_05
then
3640 Error_Msg_SP
("abstract interface is an Ada 2005 extension");
3641 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
3644 if Abstract_Present
then
3645 Error_Msg_SP
("ABSTRACT not allowed in interface type definition " &
3649 Scan
; -- past INTERFACE
3651 -- Ada 2005 (AI-345): In case of interfaces with a null list of
3652 -- interfaces we build a record_definition node.
3654 if Token
= Tok_Semicolon
then
3655 Typedef_Node
:= New_Node
(N_Record_Definition
, Token_Ptr
);
3657 Set_Abstract_Present
(Typedef_Node
);
3658 Set_Tagged_Present
(Typedef_Node
);
3659 Set_Null_Present
(Typedef_Node
);
3660 Set_Interface_Present
(Typedef_Node
);
3662 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
3663 -- a list of interfaces we build a derived_type_definition node. This
3664 -- simplifies the semantic analysis (and hence further maintenance)
3667 if Token
/= Tok_And
then
3668 Error_Msg_AP
("AND expected");
3673 Typedef_Node
:= New_Node
(N_Derived_Type_Definition
, Token_Ptr
);
3675 Set_Abstract_Present
(Typedef_Node
);
3676 Set_Interface_Present
(Typedef_Node
);
3677 Set_Subtype_Indication
(Typedef_Node
, P_Qualified_Simple_Name
);
3679 Set_Record_Extension_Part
(Typedef_Node
,
3680 New_Node
(N_Record_Definition
, Token_Ptr
));
3681 Set_Null_Present
(Record_Extension_Part
(Typedef_Node
));
3683 if Token
= Tok_And
then
3684 Set_Interface_List
(Typedef_Node
, New_List
);
3688 Append
(P_Qualified_Simple_Name
,
3689 Interface_List
(Typedef_Node
));
3690 exit when Token
/= Tok_And
;
3696 return Typedef_Node
;
3697 end P_Interface_Type_Definition
;
3699 ----------------------------------
3700 -- 3.10 Access Type Definition --
3701 ----------------------------------
3703 -- ACCESS_TYPE_DEFINITION ::=
3704 -- ACCESS_TO_OBJECT_DEFINITION
3705 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3707 -- ACCESS_TO_OBJECT_DEFINITION ::=
3708 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
3710 -- GENERAL_ACCESS_MODIFIER ::= all | constant
3712 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3713 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3714 -- | [NULL_EXCLUSION] access [protected] function
3715 -- PARAMETER_AND_RESULT_PROFILE
3717 -- PARAMETER_PROFILE ::= [FORMAL_PART]
3719 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
3721 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
3722 -- parsed the null_exclusion part and has also removed the ACCESS token;
3723 -- otherwise the caller has just checked that the initial token is ACCESS
3725 -- Error recovery: can raise Error_Resync
3727 function P_Access_Type_Definition
3728 (Header_Already_Parsed
: Boolean := False) return Node_Id
3730 Access_Loc
: constant Source_Ptr
:= Token_Ptr
;
3731 Prot_Flag
: Boolean;
3732 Not_Null_Present
: Boolean := False;
3733 Type_Def_Node
: Node_Id
;
3734 Result_Not_Null
: Boolean;
3735 Result_Node
: Node_Id
;
3737 procedure Check_Junk_Subprogram_Name
;
3738 -- Used in access to subprogram definition cases to check for an
3739 -- identifier or operator symbol that does not belong.
3741 --------------------------------
3742 -- Check_Junk_Subprogram_Name --
3743 --------------------------------
3745 procedure Check_Junk_Subprogram_Name
is
3746 Saved_State
: Saved_Scan_State
;
3749 if Token
= Tok_Identifier
or else Token
= Tok_Operator_Symbol
then
3750 Save_Scan_State
(Saved_State
);
3751 Scan
; -- past possible junk subprogram name
3753 if Token
= Tok_Left_Paren
or else Token
= Tok_Semicolon
then
3754 Error_Msg_SP
("unexpected subprogram name ignored");
3758 Restore_Scan_State
(Saved_State
);
3761 end Check_Junk_Subprogram_Name
;
3763 -- Start of processing for P_Access_Type_Definition
3766 if not Header_Already_Parsed
then
3767 Not_Null_Present
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
3768 Scan
; -- past ACCESS
3771 if Token_Name
= Name_Protected
then
3772 Check_95_Keyword
(Tok_Protected
, Tok_Procedure
);
3773 Check_95_Keyword
(Tok_Protected
, Tok_Function
);
3776 Prot_Flag
:= (Token
= Tok_Protected
);
3779 Scan
; -- past PROTECTED
3781 if Token
/= Tok_Procedure
and then Token
/= Tok_Function
then
3782 Error_Msg_SC
("FUNCTION or PROCEDURE expected");
3786 if Token
= Tok_Procedure
then
3787 if Ada_Version
= Ada_83
then
3788 Error_Msg_SC
("(Ada 83) access to procedure not allowed!");
3791 Type_Def_Node
:= New_Node
(N_Access_Procedure_Definition
, Access_Loc
);
3792 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
3793 Scan
; -- past PROCEDURE
3794 Check_Junk_Subprogram_Name
;
3795 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
3796 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
3798 elsif Token
= Tok_Function
then
3799 if Ada_Version
= Ada_83
then
3800 Error_Msg_SC
("(Ada 83) access to function not allowed!");
3803 Type_Def_Node
:= New_Node
(N_Access_Function_Definition
, Access_Loc
);
3804 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
3805 Scan
; -- past FUNCTION
3806 Check_Junk_Subprogram_Name
;
3807 Set_Parameter_Specifications
(Type_Def_Node
, P_Parameter_Profile
);
3808 Set_Protected_Present
(Type_Def_Node
, Prot_Flag
);
3811 Result_Not_Null
:= P_Null_Exclusion
; -- Ada 2005 (AI-231)
3813 -- Ada 2005 (AI-318-02)
3815 if Token
= Tok_Access
then
3816 if Ada_Version
< Ada_05
then
3818 ("anonymous access result type is an Ada 2005 extension");
3819 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
3822 Result_Node
:= P_Access_Definition
(Result_Not_Null
);
3825 Result_Node
:= P_Subtype_Mark
;
3829 -- Note: A null exclusion given on the result type needs to
3830 -- be coded by a distinct flag, since Null_Exclusion_Present
3831 -- on an access-to-function type pertains to a null exclusion
3832 -- on the access type itself (as set above). ???
3833 -- Set_Null_Exclusion_Present??? (Type_Def_Node, Result_Not_Null);
3835 Set_Result_Definition
(Type_Def_Node
, Result_Node
);
3839 New_Node
(N_Access_To_Object_Definition
, Access_Loc
);
3840 Set_Null_Exclusion_Present
(Type_Def_Node
, Not_Null_Present
);
3842 if Token
= Tok_All
or else Token
= Tok_Constant
then
3843 if Ada_Version
= Ada_83
then
3844 Error_Msg_SC
("(Ada 83) access modifier not allowed!");
3847 if Token
= Tok_All
then
3848 Set_All_Present
(Type_Def_Node
, True);
3851 Set_Constant_Present
(Type_Def_Node
, True);
3854 Scan
; -- past ALL or CONSTANT
3857 Set_Subtype_Indication
(Type_Def_Node
,
3858 P_Subtype_Indication
(Not_Null_Present
));
3861 return Type_Def_Node
;
3862 end P_Access_Type_Definition
;
3864 ---------------------------------------
3865 -- 3.10 Access To Object Definition --
3866 ---------------------------------------
3868 -- Parsed by P_Access_Type_Definition (3.10)
3870 -----------------------------------
3871 -- 3.10 General Access Modifier --
3872 -----------------------------------
3874 -- Parsed by P_Access_Type_Definition (3.10)
3876 -------------------------------------------
3877 -- 3.10 Access To Subprogram Definition --
3878 -------------------------------------------
3880 -- Parsed by P_Access_Type_Definition (3.10)
3882 -----------------------------
3883 -- 3.10 Access Definition --
3884 -----------------------------
3886 -- ACCESS_DEFINITION ::=
3887 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
3888 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3890 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3891 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3892 -- | [NULL_EXCLUSION] access [protected] function
3893 -- PARAMETER_AND_RESULT_PROFILE
3895 -- The caller has parsed the null-exclusion part and it has also checked
3896 -- that the next token is ACCESS
3898 -- Error recovery: cannot raise Error_Resync
3900 function P_Access_Definition
3901 (Null_Exclusion_Present
: Boolean) return Node_Id
3904 Subp_Node
: Node_Id
;
3907 Def_Node
:= New_Node
(N_Access_Definition
, Token_Ptr
);
3908 Scan
; -- past ACCESS
3910 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
3912 if Token
= Tok_Protected
3913 or else Token
= Tok_Procedure
3914 or else Token
= Tok_Function
3916 if Ada_Version
< Ada_05
then
3917 Error_Msg_SP
("access-to-subprogram is an Ada 2005 extension");
3918 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
3921 Subp_Node
:= P_Access_Type_Definition
(Header_Already_Parsed
=> True);
3922 Set_Null_Exclusion_Present
(Subp_Node
, Null_Exclusion_Present
);
3923 Set_Access_To_Subprogram_Definition
(Def_Node
, Subp_Node
);
3925 -- Ada 2005 (AI-231)
3926 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
3929 Set_Null_Exclusion_Present
(Def_Node
, Null_Exclusion_Present
);
3931 if Token
= Tok_All
then
3932 if Ada_Version
< Ada_05
then
3934 ("ALL is not permitted for anonymous access types");
3938 Set_All_Present
(Def_Node
);
3940 elsif Token
= Tok_Constant
then
3941 if Ada_Version
< Ada_05
then
3942 Error_Msg_SP
("access-to-constant is an Ada 2005 extension");
3943 Error_Msg_SP
("\unit should be compiled with -gnat05 switch");
3946 Scan
; -- past CONSTANT
3947 Set_Constant_Present
(Def_Node
);
3950 Set_Subtype_Mark
(Def_Node
, P_Subtype_Mark
);
3955 end P_Access_Definition
;
3957 -----------------------------------------
3958 -- 3.10.1 Incomplete Type Declaration --
3959 -----------------------------------------
3961 -- Parsed by P_Type_Declaration (3.2.1)
3963 ----------------------------
3964 -- 3.11 Declarative Part --
3965 ----------------------------
3967 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
3969 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Items
3970 -- handles errors, and returns cleanly after an error has occurred)
3972 function P_Declarative_Part
return List_Id
is
3977 -- Indicate no bad declarations detected yet. This will be reset by
3978 -- P_Declarative_Items if a bad declaration is discovered.
3980 Missing_Begin_Msg
:= No_Error_Msg
;
3982 -- Get rid of active SIS entry from outer scope. This means we will
3983 -- miss some nested cases, but it doesn't seem worth the effort. See
3984 -- discussion in Par for further details
3986 SIS_Entry_Active
:= False;
3989 -- Loop to scan out the declarations
3992 P_Declarative_Items
(Decls
, Done
, In_Spec
=> False);
3996 -- Get rid of active SIS entry which is left set only if we scanned a
3997 -- procedure declaration and have not found the body. We could give
3998 -- an error message, but that really would be usurping the role of
3999 -- semantic analysis (this really is a missing body case).
4001 SIS_Entry_Active
:= False;
4003 end P_Declarative_Part
;
4005 ----------------------------
4006 -- 3.11 Declarative Item --
4007 ----------------------------
4009 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4011 -- Can return Error if a junk declaration is found, or Empty if no
4012 -- declaration is found (i.e. a token ending declarations, such as
4013 -- BEGIN or END is encountered).
4015 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4016 -- then the scan is set past the next semicolon and Error is returned.
4018 procedure P_Declarative_Items
4023 Scan_State
: Saved_Scan_State
;
4027 Style
.Check_Indentation
;
4032 when Tok_Function
=>
4034 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4040 -- Check for loop (premature statement)
4042 Save_Scan_State
(Scan_State
);
4045 if Token
= Tok_Identifier
then
4046 Scan
; -- past identifier
4048 if Token
= Tok_In
then
4049 Restore_Scan_State
(Scan_State
);
4050 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4055 -- Not a loop, so must be rep clause
4057 Restore_Scan_State
(Scan_State
);
4058 Append
(P_Representation_Clause
, Decls
);
4063 Append
(P_Generic
, Decls
);
4066 when Tok_Identifier
=>
4069 -- Special check for misuse of overriding not in Ada 2005 mode
4071 if Token_Name
= Name_Overriding
4072 and then not Next_Token_Is
(Tok_Colon
)
4074 Error_Msg_SC
("overriding indicator is an Ada 2005 extension");
4075 Error_Msg_SC
("\unit must be compiled with -gnat05 switch");
4077 Token
:= Tok_Overriding
;
4078 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4081 -- Normal case, no overriding, or overriding followed by colon
4084 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4087 -- Ada2005: A subprogram declaration can start with "not" or
4088 -- "overriding". In older versions, "overriding" is handled
4089 -- like an identifier, with the appropriate messages.
4093 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4096 when Tok_Overriding
=>
4098 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4103 Append
(P_Package
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4107 Append
(P_Pragma
, Decls
);
4110 when Tok_Procedure
=>
4112 Append
(P_Subprogram
(Pf_Decl_Gins_Pbod_Rnam_Stub
), Decls
);
4115 when Tok_Protected
=>
4117 Scan
; -- past PROTECTED
4118 Append
(P_Protected
, Decls
);
4123 Append
(P_Subtype_Declaration
, Decls
);
4129 Append
(P_Task
, Decls
);
4134 Append
(P_Type_Declaration
, Decls
);
4139 Append
(P_Use_Clause
, Decls
);
4144 Error_Msg_SC
("WITH can only appear in context clause");
4147 -- BEGIN terminates the scan of a sequence of declarations unless
4148 -- there is a missing subprogram body, see section on handling
4149 -- semicolon in place of IS. We only treat the begin as satisfying
4150 -- the subprogram declaration if it falls in the expected column
4154 if SIS_Entry_Active
and then Start_Column
>= SIS_Ecol
then
4156 -- Here we have the case where a BEGIN is encountered during
4157 -- declarations in a declarative part, or at the outer level,
4158 -- and there is a subprogram declaration outstanding for which
4159 -- no body has been supplied. This is the case where we assume
4160 -- that the semicolon in the subprogram declaration should
4161 -- really have been is. The active SIS entry describes the
4162 -- subprogram declaration. On return the declaration has been
4163 -- modified to become a body.
4166 Specification_Node
: Node_Id
;
4167 Decl_Node
: Node_Id
;
4168 Body_Node
: Node_Id
;
4171 -- First issue the error message. If we had a missing
4172 -- semicolon in the declaration, then change the message
4173 -- to <missing "is">
4175 if SIS_Missing_Semicolon_Message
/= No_Error_Msg
then
4176 Change_Error_Text
-- Replace: "missing "";"" "
4177 (SIS_Missing_Semicolon_Message
, "missing ""is""");
4179 -- Otherwise we saved the semicolon position, so complain
4182 Error_Msg
("|"";"" should be IS", SIS_Semicolon_Sloc
);
4185 -- The next job is to fix up any declarations that occurred
4186 -- between the procedure header and the BEGIN. These got
4187 -- chained to the outer declarative region (immediately
4188 -- after the procedure declaration) and they should be
4189 -- chained to the subprogram itself, which is a body
4190 -- rather than a spec.
4192 Specification_Node
:= Specification
(SIS_Declaration_Node
);
4193 Change_Node
(SIS_Declaration_Node
, N_Subprogram_Body
);
4194 Body_Node
:= SIS_Declaration_Node
;
4195 Set_Specification
(Body_Node
, Specification_Node
);
4196 Set_Declarations
(Body_Node
, New_List
);
4199 Decl_Node
:= Remove_Next
(Body_Node
);
4200 exit when Decl_Node
= Empty
;
4201 Append
(Decl_Node
, Declarations
(Body_Node
));
4204 -- Now make the scope table entry for the Begin-End and
4208 Scope
.Table
(Scope
.Last
).Sloc
:= SIS_Sloc
;
4209 Scope
.Table
(Scope
.Last
).Etyp
:= E_Name
;
4210 Scope
.Table
(Scope
.Last
).Ecol
:= SIS_Ecol
;
4211 Scope
.Table
(Scope
.Last
).Labl
:= SIS_Labl
;
4212 Scope
.Table
(Scope
.Last
).Lreq
:= False;
4213 SIS_Entry_Active
:= False;
4215 Set_Handled_Statement_Sequence
(Body_Node
,
4216 P_Handled_Sequence_Of_Statements
);
4217 End_Statements
(Handled_Statement_Sequence
(Body_Node
));
4226 -- Normally an END terminates the scan for basic declarative
4227 -- items. The one exception is END RECORD, which is probably
4228 -- left over from some other junk.
4231 Save_Scan_State
(Scan_State
); -- at END
4234 if Token
= Tok_Record
then
4235 Error_Msg_SP
("no RECORD for this `end record`!");
4236 Scan
; -- past RECORD
4240 Restore_Scan_State
(Scan_State
); -- to END
4244 -- The following tokens which can only be the start of a statement
4245 -- are considered to end a declarative part (i.e. we have a missing
4246 -- BEGIN situation). We are fairly conservative in making this
4247 -- judgment, because it is a real mess to go into statement mode
4248 -- prematurely in response to a junk declaration.
4263 -- But before we decide that it's a statement, let's check for
4264 -- a reserved word misused as an identifier.
4266 if Is_Reserved_Identifier
then
4267 Save_Scan_State
(Scan_State
);
4268 Scan
; -- past the token
4270 -- If reserved identifier not followed by colon or comma, then
4271 -- this is most likely an assignment statement to the bad id.
4273 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4274 Restore_Scan_State
(Scan_State
);
4275 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4278 -- Otherwise we have a declaration of the bad id
4281 Restore_Scan_State
(Scan_State
);
4282 Scan_Reserved_Identifier
(Force_Msg
=> True);
4283 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4286 -- If not reserved identifier, then it's definitely a statement
4289 Statement_When_Declaration_Expected
(Decls
, Done
, In_Spec
);
4293 -- The token RETURN may well also signal a missing BEGIN situation,
4294 -- however, we never let it end the declarative part, because it may
4295 -- also be part of a half-baked function declaration.
4298 Error_Msg_SC
("misplaced RETURN statement");
4301 -- PRIVATE definitely terminates the declarations in a spec,
4302 -- and is an error in a body.
4308 Error_Msg_SC
("PRIVATE not allowed in body");
4309 Scan
; -- past PRIVATE
4312 -- An end of file definitely terminates the declarations!
4317 -- The remaining tokens do not end the scan, but cannot start a
4318 -- valid declaration, so we signal an error and resynchronize.
4319 -- But first check for misuse of a reserved identifier.
4323 -- Here we check for a reserved identifier
4325 if Is_Reserved_Identifier
then
4326 Save_Scan_State
(Scan_State
);
4327 Scan
; -- past the token
4329 if Token
/= Tok_Colon
and then Token
/= Tok_Comma
then
4330 Restore_Scan_State
(Scan_State
);
4331 Set_Declaration_Expected
;
4334 Restore_Scan_State
(Scan_State
);
4335 Scan_Reserved_Identifier
(Force_Msg
=> True);
4337 P_Identifier_Declarations
(Decls
, Done
, In_Spec
);
4341 Set_Declaration_Expected
;
4346 -- To resynchronize after an error, we scan to the next semicolon and
4347 -- return with Done = False, indicating that there may still be more
4348 -- valid declarations to come.
4351 when Error_Resync
=>
4352 Resync_Past_Semicolon
;
4354 end P_Declarative_Items
;
4356 ----------------------------------
4357 -- 3.11 Basic Declarative Item --
4358 ----------------------------------
4360 -- BASIC_DECLARATIVE_ITEM ::=
4361 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4363 -- Scan zero or more basic declarative items
4365 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4366 -- the scan pointer is repositioned past the next semicolon, and the scan
4367 -- for declarative items continues.
4369 function P_Basic_Declarative_Items
return List_Id
is
4376 -- Indicate no bad declarations detected yet in the current context:
4377 -- visible or private declarations of a package spec.
4379 Missing_Begin_Msg
:= No_Error_Msg
;
4381 -- Get rid of active SIS entry from outer scope. This means we will
4382 -- miss some nested cases, but it doesn't seem worth the effort. See
4383 -- discussion in Par for further details
4385 SIS_Entry_Active
:= False;
4387 -- Loop to scan out declarations
4392 P_Declarative_Items
(Decls
, Done
, In_Spec
=> True);
4396 -- Get rid of active SIS entry. This is set only if we have scanned a
4397 -- procedure declaration and have not found the body. We could give
4398 -- an error message, but that really would be usurping the role of
4399 -- semantic analysis (this really is a case of a missing body).
4401 SIS_Entry_Active
:= False;
4403 -- Test for assorted illegal declarations not diagnosed elsewhere
4405 Decl
:= First
(Decls
);
4407 while Present
(Decl
) loop
4408 Kind
:= Nkind
(Decl
);
4410 -- Test for body scanned, not acceptable as basic decl item
4412 if Kind
= N_Subprogram_Body
or else
4413 Kind
= N_Package_Body
or else
4414 Kind
= N_Task_Body
or else
4415 Kind
= N_Protected_Body
4418 ("proper body not allowed in package spec", Sloc
(Decl
));
4420 -- Test for body stub scanned, not acceptable as basic decl item
4422 elsif Kind
in N_Body_Stub
then
4424 ("body stub not allowed in package spec", Sloc
(Decl
));
4426 elsif Kind
= N_Assignment_Statement
then
4428 ("assignment statement not allowed in package spec",
4436 end P_Basic_Declarative_Items
;
4442 -- For proper body, see below
4443 -- For body stub, see 10.1.3
4445 -----------------------
4446 -- 3.11 Proper Body --
4447 -----------------------
4449 -- Subprogram body is parsed by P_Subprogram (6.1)
4450 -- Package body is parsed by P_Package (7.1)
4451 -- Task body is parsed by P_Task (9.1)
4452 -- Protected body is parsed by P_Protected (9.4)
4454 ------------------------------
4455 -- Set_Declaration_Expected --
4456 ------------------------------
4458 procedure Set_Declaration_Expected
is
4460 Error_Msg_SC
("declaration expected");
4462 if Missing_Begin_Msg
= No_Error_Msg
then
4463 Missing_Begin_Msg
:= Get_Msg_Id
;
4465 end Set_Declaration_Expected
;
4467 ----------------------
4468 -- Skip_Declaration --
4469 ----------------------
4471 procedure Skip_Declaration
(S
: List_Id
) is
4472 Dummy_Done
: Boolean;
4473 pragma Warnings
(Off
, Dummy_Done
);
4475 P_Declarative_Items
(S
, Dummy_Done
, False);
4476 end Skip_Declaration
;
4478 -----------------------------------------
4479 -- Statement_When_Declaration_Expected --
4480 -----------------------------------------
4482 procedure Statement_When_Declaration_Expected
4488 -- Case of second occurrence of statement in one declaration sequence
4490 if Missing_Begin_Msg
/= No_Error_Msg
then
4492 -- In the procedure spec case, just ignore it, we only give one
4493 -- message for the first occurrence, since otherwise we may get
4494 -- horrible cascading if BODY was missing in the header line.
4499 -- In the declarative part case, take a second statement as a sure
4500 -- sign that we really have a missing BEGIN, and end the declarative
4501 -- part now. Note that the caller will fix up the first message to
4502 -- say "missing BEGIN" so that's how the error will be signalled.
4509 -- Case of first occurrence of unexpected statement
4512 -- If we are in a package spec, then give message of statement
4513 -- not allowed in package spec. This message never gets changed.
4516 Error_Msg_SC
("statement not allowed in package spec");
4518 -- If in declarative part, then we give the message complaining
4519 -- about finding a statement when a declaration is expected. This
4520 -- gets changed to a complaint about a missing BEGIN if we later
4521 -- find that no BEGIN is present.
4524 Error_Msg_SC
("statement not allowed in declarative part");
4527 -- Capture message Id. This is used for two purposes, first to
4528 -- stop multiple messages, see test above, and second, to allow
4529 -- the replacement of the message in the declarative part case.
4531 Missing_Begin_Msg
:= Get_Msg_Id
;
4534 -- In all cases except the case in which we decided to terminate the
4535 -- declaration sequence on a second error, we scan out the statement
4536 -- and append it to the list of declarations (note that the semantics
4537 -- can handle statements in a declaration list so if we proceed to
4538 -- call the semantic phase, all will be (reasonably) well!
4540 Append_List_To
(Decls
, P_Sequence_Of_Statements
(SS_Unco
));
4542 -- Done is set to False, since we want to continue the scan of
4543 -- declarations, hoping that this statement was a temporary glitch.
4544 -- If we indeed are now in the statement part (i.e. this was a missing
4545 -- BEGIN, then it's not terrible, we will simply keep calling this
4546 -- procedure to process the statements one by one, and then finally
4547 -- hit the missing BEGIN, which will clean up the error message.
4550 end Statement_When_Declaration_Expected
;