1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 pragma Style_Checks (All_Checks);
28 -- Turn off subprogram body ordering check. Subprograms are in order
29 -- by RM section rather than alphabetical
31 with Sinfo.CN; use Sinfo.CN;
37 -----------------------
38 -- Local Subprograms --
39 -----------------------
41 function P_Component_List return Node_Id;
42 function P_Defining_Character_Literal return Node_Id;
43 function P_Delta_Constraint return Node_Id;
44 function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id;
45 function P_Digits_Constraint return Node_Id;
46 function P_Discriminant_Association return Node_Id;
47 function P_Enumeration_Literal_Specification return Node_Id;
48 function P_Enumeration_Type_Definition return Node_Id;
49 function P_Fixed_Point_Definition return Node_Id;
50 function P_Floating_Point_Definition return Node_Id;
51 function P_Index_Or_Discriminant_Constraint return Node_Id;
52 function P_Real_Range_Specification_Opt return Node_Id;
53 function P_Subtype_Declaration return Node_Id;
54 function P_Type_Declaration return Node_Id;
55 function P_Modular_Type_Definition return Node_Id;
56 function P_Variant return Node_Id;
57 function P_Variant_Part return Node_Id;
59 procedure P_Declarative_Items
63 -- Scans out a single declarative item, or, in the case of a declaration
64 -- with a list of identifiers, a list of declarations, one for each of
65 -- the identifiers in the list. The declaration or declarations scanned
66 -- are appended to the given list. Done indicates whether or not there
67 -- may be additional declarative items to scan. If Done is True, then
68 -- a decision has been made that there are no more items to scan. If
69 -- Done is False, then there may be additional declarations to scan.
70 -- In_Spec is true if we are scanning a package declaration, and is used
71 -- to generate an appropriate message if a statement is encountered in
74 procedure P_Identifier_Declarations
78 -- Scans out a set of declarations for an identifier or list of
79 -- identifiers, and appends them to the given list. The parameters have
80 -- the same significance as for P_Declarative_Items.
82 procedure Statement_When_Declaration_Expected
86 -- Called when a statement is found at a point where a declaration was
87 -- expected. The parameters are as described for P_Declarative_Items.
89 procedure Set_Declaration_Expected;
90 -- Posts a "declaration expected" error messages at the start of the
91 -- current token, and if this is the first such message issued, saves
92 -- the message id in Missing_Begin_Msg, for possible later replacement.
98 function Init_Expr_Opt (P : Boolean := False) return Node_Id is
100 -- For colon, assume it means := unless it is at the end of
101 -- a line, in which case guess that it means a semicolon.
103 if Token = Tok_Colon then
104 if Token_Is_At_End_Of_Line then
109 -- Here if := or something that we will take as equivalent
111 elsif Token = Tok_Colon_Equal
112 or else Token = Tok_Equal
113 or else Token = Tok_Is
117 -- Another possibility. If we have a literal followed by a semicolon,
118 -- we assume that we have a missing colon-equal.
120 elsif Token in Token_Class_Literal then
122 Scan_State : Saved_Scan_State;
125 Save_Scan_State (Scan_State);
126 Scan; -- past literal or identifier
128 if Token = Tok_Semicolon then
129 Restore_Scan_State (Scan_State);
131 Restore_Scan_State (Scan_State);
136 -- Otherwise we definitely have no initialization expression
142 -- Merge here if we have an initialization expression
149 return P_Expression_No_Right_Paren;
153 ----------------------------
154 -- 3.1 Basic Declaration --
155 ----------------------------
157 -- Parsed by P_Basic_Declarative_Items (3.9)
159 ------------------------------
160 -- 3.1 Defining Identifier --
161 ------------------------------
163 -- DEFINING_IDENTIFIER ::= IDENTIFIER
165 -- Error recovery: can raise Error_Resync
167 function P_Defining_Identifier (C : Id_Check := None) return Node_Id is
168 Ident_Node : Node_Id;
171 -- Scan out the identifier. Note that this code is essentially identical
172 -- to P_Identifier, except that in the call to Scan_Reserved_Identifier
173 -- we set Force_Msg to True, since we want at least one message for each
174 -- separate declaration (but not use) of a reserved identifier.
176 if Token = Tok_Identifier then
179 -- If we have a reserved identifier, manufacture an identifier with
180 -- a corresponding name after posting an appropriate error message
182 elsif Is_Reserved_Identifier (C) then
183 Scan_Reserved_Identifier (Force_Msg => True);
185 -- Otherwise we have junk that cannot be interpreted as an identifier
188 T_Identifier; -- to give message
192 Ident_Node := Token_Node;
193 Scan; -- past the reserved identifier
195 if Ident_Node /= Error then
196 Change_Identifier_To_Defining_Identifier (Ident_Node);
200 end P_Defining_Identifier;
202 -----------------------------
203 -- 3.2.1 Type Declaration --
204 -----------------------------
206 -- TYPE_DECLARATION ::=
207 -- FULL_TYPE_DECLARATION
208 -- | INCOMPLETE_TYPE_DECLARATION
209 -- | PRIVATE_TYPE_DECLARATION
210 -- | PRIVATE_EXTENSION_DECLARATION
212 -- FULL_TYPE_DECLARATION ::=
213 -- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION;
214 -- | CONCURRENT_TYPE_DECLARATION
216 -- INCOMPLETE_TYPE_DECLARATION ::=
217 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART];
219 -- PRIVATE_TYPE_DECLARATION ::=
220 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
221 -- is [abstract] [tagged] [limited] private;
223 -- PRIVATE_EXTENSION_DECLARATION ::=
224 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
225 -- [abstract] new ancestor_SUBTYPE_INDICATION with private;
227 -- TYPE_DEFINITION ::=
228 -- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
229 -- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
230 -- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
231 -- | DERIVED_TYPE_DEFINITION
233 -- INTEGER_TYPE_DEFINITION ::=
234 -- SIGNED_INTEGER_TYPE_DEFINITION
235 -- MODULAR_TYPE_DEFINITION
237 -- Error recovery: can raise Error_Resync
239 -- Note: The processing for full type declaration, incomplete type
240 -- declaration, private type declaration and type definition is
241 -- included in this function. The processing for concurrent type
242 -- declarations is NOT here, but rather in chapter 9 (i.e. this
243 -- function handles only declarations starting with TYPE).
245 function P_Type_Declaration return Node_Id is
246 Type_Loc : Source_Ptr;
247 Type_Start_Col : Column_Number;
248 Ident_Node : Node_Id;
250 Discr_List : List_Id;
251 Unknown_Dis : Boolean;
252 Discr_Sloc : Source_Ptr;
253 Abstract_Present : Boolean;
254 Abstract_Loc : Source_Ptr;
257 Typedef_Node : Node_Id;
258 -- Normally holds type definition, except in the case of a private
259 -- extension declaration, in which case it holds the declaration itself
262 Type_Loc := Token_Ptr;
263 Type_Start_Col := Start_Column;
265 Ident_Node := P_Defining_Identifier (C_Is);
266 Discr_Sloc := Token_Ptr;
268 if P_Unknown_Discriminant_Part_Opt then
270 Discr_List := No_List;
272 Unknown_Dis := False;
273 Discr_List := P_Known_Discriminant_Part_Opt;
276 -- Incomplete type declaration. We complete the processing for this
277 -- case here and return the resulting incomplete type declaration node
279 if Token = Tok_Semicolon then
281 Decl_Node := New_Node (N_Incomplete_Type_Declaration, Type_Loc);
282 Set_Defining_Identifier (Decl_Node, Ident_Node);
283 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
284 Set_Discriminant_Specifications (Decl_Node, Discr_List);
291 -- Full type declaration or private type declaration, must have IS
293 if Token = Tok_Equal then
295 Scan; -- past = used in place of IS
297 elsif Token = Tok_Renames then
298 Error_Msg_SC ("RENAMES should be IS");
299 Scan; -- past RENAMES used in place of IS
305 -- First an error check, if we have two identifiers in a row, a likely
306 -- possibility is that the first of the identifiers is an incorrectly
309 if Token = Tok_Identifier then
311 SS : Saved_Scan_State;
315 Save_Scan_State (SS);
316 Scan; -- past initial identifier
317 I2 := (Token = Tok_Identifier);
318 Restore_Scan_State (SS);
322 (Bad_Spelling_Of (Tok_Abstract) or else
323 Bad_Spelling_Of (Tok_Access) or else
324 Bad_Spelling_Of (Tok_Aliased) or else
325 Bad_Spelling_Of (Tok_Constant))
332 -- Check for misuse of Ada 95 keyword abstract in Ada 83 mode
334 if Token_Name = Name_Abstract then
335 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
336 Check_95_Keyword (Tok_Abstract, Tok_New);
339 -- Check cases of misuse of ABSTRACT
341 if Token = Tok_Abstract then
342 Abstract_Present := True;
343 Abstract_Loc := Token_Ptr;
344 Scan; -- past ABSTRACT
346 if Token = Tok_Limited
347 or else Token = Tok_Private
348 or else Token = Tok_Record
349 or else Token = Tok_Null
351 Error_Msg_AP ("TAGGED expected");
355 Abstract_Present := False;
356 Abstract_Loc := No_Location;
359 -- Check for misuse of Ada 95 keyword Tagged
361 if Token_Name = Name_Tagged then
362 Check_95_Keyword (Tok_Tagged, Tok_Private);
363 Check_95_Keyword (Tok_Tagged, Tok_Limited);
364 Check_95_Keyword (Tok_Tagged, Tok_Record);
367 -- Special check for misuse of Aliased
369 if Token = Tok_Aliased or else Token_Name = Name_Aliased then
370 Error_Msg_SC ("ALIASED not allowed in type definition");
371 Scan; -- past ALIASED
374 -- The following procesing deals with either a private type declaration
375 -- or a full type declaration. In the private type case, we build the
376 -- N_Private_Type_Declaration node, setting its Tagged_Present and
377 -- Limited_Present flags, on encountering the Private keyword, and
378 -- leave Typedef_Node set to Empty. For the full type declaration
379 -- case, Typedef_Node gets set to the type definition.
381 Typedef_Node := Empty;
383 -- Switch on token following the IS. The loop normally runs once. It
384 -- only runs more than once if an error is detected, to try again after
385 -- detecting and fixing up the error.
391 Tok_Not => -- Ada 0Y (AI-231)
392 Typedef_Node := P_Access_Type_Definition;
397 Typedef_Node := P_Array_Type_Definition;
402 Typedef_Node := P_Fixed_Point_Definition;
407 Typedef_Node := P_Floating_Point_Definition;
414 when Tok_Integer_Literal =>
416 Typedef_Node := P_Signed_Integer_Type_Definition;
421 Typedef_Node := P_Record_Definition;
425 when Tok_Left_Paren =>
426 Typedef_Node := P_Enumeration_Type_Definition;
429 Make_Identifier (Token_Ptr,
430 Chars => Chars (Ident_Node));
431 Set_Comes_From_Source (End_Labl, False);
433 Set_End_Label (Typedef_Node, End_Labl);
438 Typedef_Node := P_Modular_Type_Definition;
443 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
445 if Nkind (Typedef_Node) = N_Derived_Type_Definition
446 and then Present (Record_Extension_Part (Typedef_Node))
449 Make_Identifier (Token_Ptr,
450 Chars => Chars (Ident_Node));
451 Set_Comes_From_Source (End_Labl, False);
454 (Record_Extension_Part (Typedef_Node), End_Labl);
461 Typedef_Node := P_Signed_Integer_Type_Definition;
466 Typedef_Node := P_Record_Definition;
469 Make_Identifier (Token_Ptr,
470 Chars => Chars (Ident_Node));
471 Set_Comes_From_Source (End_Labl, False);
473 Set_End_Label (Typedef_Node, End_Labl);
480 if Token = Tok_Abstract then
481 Error_Msg_SC ("ABSTRACT must come before TAGGED");
482 Abstract_Present := True;
483 Abstract_Loc := Token_Ptr;
484 Scan; -- past ABSTRACT
487 if Token = Tok_Limited then
488 Scan; -- past LIMITED
490 -- TAGGED LIMITED PRIVATE case
492 if Token = Tok_Private then
494 New_Node (N_Private_Type_Declaration, Type_Loc);
495 Set_Tagged_Present (Decl_Node, True);
496 Set_Limited_Present (Decl_Node, True);
497 Scan; -- past PRIVATE
499 -- TAGGED LIMITED RECORD
502 Typedef_Node := P_Record_Definition;
503 Set_Tagged_Present (Typedef_Node, True);
504 Set_Limited_Present (Typedef_Node, True);
507 Make_Identifier (Token_Ptr,
508 Chars => Chars (Ident_Node));
509 Set_Comes_From_Source (End_Labl, False);
511 Set_End_Label (Typedef_Node, End_Labl);
517 if Token = Tok_Private then
519 New_Node (N_Private_Type_Declaration, Type_Loc);
520 Set_Tagged_Present (Decl_Node, True);
521 Scan; -- past PRIVATE
526 Typedef_Node := P_Record_Definition;
527 Set_Tagged_Present (Typedef_Node, True);
530 Make_Identifier (Token_Ptr,
531 Chars => Chars (Ident_Node));
532 Set_Comes_From_Source (End_Labl, False);
534 Set_End_Label (Typedef_Node, End_Labl);
542 Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
543 Scan; -- past PRIVATE
548 Scan; -- past LIMITED
551 if Token = Tok_Tagged then
552 Error_Msg_SC ("TAGGED must come before LIMITED");
555 elsif Token = Tok_Abstract then
556 Error_Msg_SC ("ABSTRACT must come before LIMITED");
557 Scan; -- past ABSTRACT
564 -- LIMITED RECORD or LIMITED NULL RECORD
566 if Token = Tok_Record or else Token = Tok_Null then
569 ("(Ada 83) limited record declaration not allowed!");
572 Typedef_Node := P_Record_Definition;
573 Set_Limited_Present (Typedef_Node, True);
575 -- LIMITED PRIVATE is the only remaining possibility here
578 Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
579 Set_Limited_Present (Decl_Node, True);
580 T_Private; -- past PRIVATE (or complain if not there!)
586 -- Here we have an identifier after the IS, which is certainly
587 -- wrong and which might be one of several different mistakes.
589 when Tok_Identifier =>
591 -- First case, if identifier is on same line, then probably we
592 -- have something like "type X is Integer .." and the best
593 -- diagnosis is a missing NEW. Note: the missing new message
594 -- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl.
596 if not Token_Is_At_Start_Of_Line then
597 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
600 -- If the identifier is at the start of the line, and is in the
601 -- same column as the type declaration itself then we consider
602 -- that we had a missing type definition on the previous line
604 elsif Start_Column <= Type_Start_Col then
605 Error_Msg_AP ("type definition expected");
606 Typedef_Node := Error;
608 -- If the identifier is at the start of the line, and is in
609 -- a column to the right of the type declaration line, then we
610 -- may have something like:
615 -- and the best diagnosis is a missing record keyword
618 Typedef_Node := P_Record_Definition;
624 -- Anything else is an error
627 if Bad_Spelling_Of (Tok_Access)
629 Bad_Spelling_Of (Tok_Array)
631 Bad_Spelling_Of (Tok_Delta)
633 Bad_Spelling_Of (Tok_Digits)
635 Bad_Spelling_Of (Tok_Limited)
637 Bad_Spelling_Of (Tok_Private)
639 Bad_Spelling_Of (Tok_Range)
641 Bad_Spelling_Of (Tok_Record)
643 Bad_Spelling_Of (Tok_Tagged)
648 Error_Msg_AP ("type definition expected");
655 -- For the private type declaration case, the private type declaration
656 -- node has been built, with the Tagged_Present and Limited_Present
657 -- flags set as needed, and Typedef_Node is left set to Empty.
659 if No (Typedef_Node) then
660 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
661 Set_Abstract_Present (Decl_Node, Abstract_Present);
663 -- For a private extension declaration, Typedef_Node contains the
664 -- N_Private_Extension_Declaration node, which we now complete. Note
665 -- that the private extension declaration, unlike a full type
666 -- declaration, does permit unknown discriminants.
668 elsif Nkind (Typedef_Node) = N_Private_Extension_Declaration then
669 Decl_Node := Typedef_Node;
670 Set_Sloc (Decl_Node, Type_Loc);
671 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
672 Set_Abstract_Present (Typedef_Node, Abstract_Present);
674 -- In the full type declaration case, Typedef_Node has the type
675 -- definition and here is where we build the full type declaration
676 -- node. This is also where we check for improper use of an unknown
677 -- discriminant part (not allowed for full type declaration).
680 if Nkind (Typedef_Node) = N_Record_Definition
681 or else (Nkind (Typedef_Node) = N_Derived_Type_Definition
682 and then Present (Record_Extension_Part (Typedef_Node)))
684 Set_Abstract_Present (Typedef_Node, Abstract_Present);
686 elsif Abstract_Present then
687 Error_Msg ("ABSTRACT not allowed here, ignored", Abstract_Loc);
690 Decl_Node := New_Node (N_Full_Type_Declaration, Type_Loc);
691 Set_Type_Definition (Decl_Node, Typedef_Node);
695 ("Full type declaration cannot have unknown discriminants",
700 -- Remaining processing is common for all three cases
702 Set_Defining_Identifier (Decl_Node, Ident_Node);
703 Set_Discriminant_Specifications (Decl_Node, Discr_List);
705 end P_Type_Declaration;
707 ----------------------------------
708 -- 3.2.1 Full Type Declaration --
709 ----------------------------------
711 -- Parsed by P_Type_Declaration (3.2.1)
713 ----------------------------
714 -- 3.2.1 Type Definition --
715 ----------------------------
717 -- Parsed by P_Type_Declaration (3.2.1)
719 --------------------------------
720 -- 3.2.2 Subtype Declaration --
721 --------------------------------
723 -- SUBTYPE_DECLARATION ::=
724 -- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION;
726 -- The caller has checked that the initial token is SUBTYPE
728 -- Error recovery: can raise Error_Resync
730 function P_Subtype_Declaration return Node_Id is
732 Not_Null_Present : Boolean := False;
734 Decl_Node := New_Node (N_Subtype_Declaration, Token_Ptr);
735 Scan; -- past SUBTYPE
736 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier (C_Is));
739 if Token = Tok_New then
740 Error_Msg_SC ("NEW ignored (only allowed in type declaration)");
744 if Extensions_Allowed then -- Ada 0Y (AI-231)
745 Not_Null_Present := P_Null_Exclusion;
746 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
749 Set_Subtype_Indication
750 (Decl_Node, P_Subtype_Indication (Not_Null_Present));
753 end P_Subtype_Declaration;
755 -------------------------------
756 -- 3.2.2 Subtype Indication --
757 -------------------------------
759 -- SUBTYPE_INDICATION ::=
760 -- [NOT NULL] SUBTYPE_MARK [CONSTRAINT]
762 -- Error recovery: can raise Error_Resync
764 function P_Null_Exclusion return Boolean is
766 if Token /= Tok_Not then
770 if not Extensions_Allowed then
772 ("null-excluding access is an Ada 0Y extension");
773 Error_Msg_SP ("\unit must be compiled with -gnatX switch");
778 if Token = Tok_Null then
781 Error_Msg_SP ("(Ada 0Y) missing NULL");
786 end P_Null_Exclusion;
788 function P_Subtype_Indication
789 (Not_Null_Present : Boolean := False) return Node_Id is
793 if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then
794 Type_Node := P_Subtype_Mark;
795 return P_Subtype_Indication (Type_Node, Not_Null_Present);
798 -- Check for error of using record definition and treat it nicely,
799 -- otherwise things are really messed up, so resynchronize.
801 if Token = Tok_Record then
802 Error_Msg_SC ("anonymous record definitions are not permitted");
803 Discard_Junk_Node (P_Record_Definition);
807 Error_Msg_AP ("subtype indication expected");
811 end P_Subtype_Indication;
813 -- The following function is identical except that it is called with
814 -- the subtype mark already scanned out, and it scans out the constraint
816 -- Error recovery: can raise Error_Resync
818 function P_Subtype_Indication
819 (Subtype_Mark : Node_Id;
820 Not_Null_Present : Boolean := False) return Node_Id is
821 Indic_Node : Node_Id;
822 Constr_Node : Node_Id;
825 Constr_Node := P_Constraint_Opt;
827 if No (Constr_Node) then
830 if Not_Null_Present then
831 Error_Msg_SP ("(Ada 0Y) constrained null-exclusion not allowed");
834 Indic_Node := New_Node (N_Subtype_Indication, Sloc (Subtype_Mark));
835 Set_Subtype_Mark (Indic_Node, Check_Subtype_Mark (Subtype_Mark));
836 Set_Constraint (Indic_Node, Constr_Node);
839 end P_Subtype_Indication;
841 -------------------------
842 -- 3.2.2 Subtype Mark --
843 -------------------------
845 -- SUBTYPE_MARK ::= subtype_NAME;
847 -- Note: The subtype mark which appears after an IN or NOT IN
848 -- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
850 -- Error recovery: cannot raise Error_Resync
852 function P_Subtype_Mark return Node_Id is
854 return P_Subtype_Mark_Resync;
861 -- This routine differs from P_Subtype_Mark in that it insists that an
862 -- identifier be present, and if it is not, it raises Error_Resync.
864 -- Error recovery: can raise Error_Resync
866 function P_Subtype_Mark_Resync return Node_Id is
870 if Token = Tok_Access then
871 Error_Msg_SC ("anonymous access type definition not allowed here");
875 if Token = Tok_Array then
876 Error_Msg_SC ("anonymous array definition not allowed here");
877 Discard_Junk_Node (P_Array_Type_Definition);
881 Type_Node := P_Qualified_Simple_Name_Resync;
883 -- Check for a subtype mark attribute. The only valid possibilities
884 -- are 'CLASS and 'BASE. Anything else is a definite error. We may
885 -- as well catch it here.
887 if Token = Tok_Apostrophe then
888 return P_Subtype_Mark_Attribute (Type_Node);
893 end P_Subtype_Mark_Resync;
895 -- The following function is called to scan out a subtype mark attribute.
896 -- The caller has already scanned out the subtype mark, which is passed in
897 -- as the argument, and has checked that the current token is apostrophe.
899 -- Only a special subclass of attributes, called type attributes
900 -- (see Snames package) are allowed in this syntactic position.
902 -- Note: if the apostrophe is followed by other than an identifier, then
903 -- the input expression is returned unchanged, and the scan pointer is
904 -- left pointing to the apostrophe.
906 -- Error recovery: can raise Error_Resync
908 function P_Subtype_Mark_Attribute (Type_Node : Node_Id) return Node_Id is
909 Attr_Node : Node_Id := Empty;
910 Scan_State : Saved_Scan_State;
914 Prefix := Check_Subtype_Mark (Type_Node);
916 if Prefix = Error then
920 -- Loop through attributes appearing (more than one can appear as for
921 -- for example in X'Base'Class). We are at an apostrophe on entry to
922 -- this loop, and it runs once for each attribute parsed, with
923 -- Prefix being the current possible prefix if it is an attribute.
926 Save_Scan_State (Scan_State); -- at Apostrophe
927 Scan; -- past apostrophe
929 if Token /= Tok_Identifier then
930 Restore_Scan_State (Scan_State); -- to apostrophe
931 return Prefix; -- no attribute after all
933 elsif not Is_Type_Attribute_Name (Token_Name) then
935 ("attribute & may not be used in a subtype mark", Token_Node);
940 Make_Attribute_Reference (Prev_Token_Ptr,
942 Attribute_Name => Token_Name);
943 Delete_Node (Token_Node);
944 Scan; -- past type attribute identifier
947 exit when Token /= Tok_Apostrophe;
951 -- Fall through here after scanning type attribute
954 end P_Subtype_Mark_Attribute;
956 -----------------------
957 -- 3.2.2 Constraint --
958 -----------------------
960 -- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
962 -- SCALAR_CONSTRAINT ::=
963 -- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
965 -- COMPOSITE_CONSTRAINT ::=
966 -- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
968 -- If no constraint is present, this function returns Empty
970 -- Error recovery: can raise Error_Resync
972 function P_Constraint_Opt return Node_Id is
975 or else Bad_Spelling_Of (Tok_Range)
977 return P_Range_Constraint;
979 elsif Token = Tok_Digits
980 or else Bad_Spelling_Of (Tok_Digits)
982 return P_Digits_Constraint;
984 elsif Token = Tok_Delta
985 or else Bad_Spelling_Of (Tok_Delta)
987 return P_Delta_Constraint;
989 elsif Token = Tok_Left_Paren then
990 return P_Index_Or_Discriminant_Constraint;
992 elsif Token = Tok_In then
994 return P_Constraint_Opt;
999 end P_Constraint_Opt;
1001 ------------------------------
1002 -- 3.2.2 Scalar Constraint --
1003 ------------------------------
1005 -- Parsed by P_Constraint_Opt (3.2.2)
1007 ---------------------------------
1008 -- 3.2.2 Composite Constraint --
1009 ---------------------------------
1011 -- Parsed by P_Constraint_Opt (3.2.2)
1013 --------------------------------------------------------
1014 -- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
1015 --------------------------------------------------------
1017 -- This routine scans out a declaration starting with an identifier:
1019 -- OBJECT_DECLARATION ::=
1020 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1021 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION];
1022 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1023 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1025 -- NUMBER_DECLARATION ::=
1026 -- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
1028 -- OBJECT_RENAMING_DECLARATION ::=
1029 -- DEFINING_IDENTIFIER : SUBTYPE_MARK renames object_NAME;
1030 -- | DEFINING_IDENTIFIER : ACCESS_DEFINITION renames object_NAME;
1032 -- EXCEPTION_RENAMING_DECLARATION ::=
1033 -- DEFINING_IDENTIFIER : exception renames exception_NAME;
1035 -- EXCEPTION_DECLARATION ::=
1036 -- DEFINING_IDENTIFIER_LIST : exception;
1038 -- Note that the ALIASED indication in an object declaration is
1039 -- marked by a flag in the parent node.
1041 -- The caller has checked that the initial token is an identifier
1043 -- The value returned is a list of declarations, one for each identifier
1044 -- in the list (as described in Sinfo, we always split up multiple
1045 -- declarations into the equivalent sequence of single declarations
1046 -- using the More_Ids and Prev_Ids flags to preserve the source).
1048 -- If the identifier turns out to be a probable statement rather than
1049 -- an identifier, then the scan is left pointing to the identifier and
1050 -- No_List is returned.
1052 -- Error recovery: can raise Error_Resync
1054 procedure P_Identifier_Declarations
1060 Decl_Node : Node_Id;
1061 Type_Node : Node_Id;
1062 Ident_Sloc : Source_Ptr;
1063 Scan_State : Saved_Scan_State;
1064 List_OK : Boolean := True;
1066 Init_Expr : Node_Id;
1067 Init_Loc : Source_Ptr;
1068 Con_Loc : Source_Ptr;
1069 Not_Null_Present : Boolean := False;
1071 Idents : array (Int range 1 .. 4096) of Entity_Id;
1072 -- Used to save identifiers in the identifier list. The upper bound
1073 -- of 4096 is expected to be infinite in practice, and we do not even
1074 -- bother to check if this upper bound is exceeded.
1076 Num_Idents : Nat := 1;
1077 -- Number of identifiers stored in Idents
1080 -- This procedure is called in renames cases to make sure that we do
1081 -- not have more than one identifier. If we do have more than one
1082 -- then an error message is issued (and the declaration is split into
1083 -- multiple declarations)
1085 function Token_Is_Renames return Boolean;
1086 -- Checks if current token is RENAMES, and if so, scans past it and
1087 -- returns True, otherwise returns False. Includes checking for some
1088 -- common error cases.
1090 procedure No_List is
1092 if Num_Idents > 1 then
1093 Error_Msg ("identifier list not allowed for RENAMES",
1100 function Token_Is_Renames return Boolean is
1101 At_Colon : Saved_Scan_State;
1104 if Token = Tok_Colon then
1105 Save_Scan_State (At_Colon);
1107 Check_Misspelling_Of (Tok_Renames);
1109 if Token = Tok_Renames then
1110 Error_Msg_SP ("extra "":"" ignored");
1111 Scan; -- past RENAMES
1114 Restore_Scan_State (At_Colon);
1119 Check_Misspelling_Of (Tok_Renames);
1121 if Token = Tok_Renames then
1122 Scan; -- past RENAMES
1128 end Token_Is_Renames;
1130 -- Start of processing for P_Identifier_Declarations
1133 Ident_Sloc := Token_Ptr;
1134 Save_Scan_State (Scan_State); -- at first identifier
1135 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
1137 -- If we have a colon after the identifier, then we can assume that
1138 -- this is in fact a valid identifier declaration and can steam ahead.
1140 if Token = Tok_Colon then
1143 -- If we have a comma, then scan out the list of identifiers
1145 elsif Token = Tok_Comma then
1147 while Comma_Present loop
1148 Num_Idents := Num_Idents + 1;
1149 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
1152 Save_Scan_State (Scan_State); -- at colon
1155 -- If we have identifier followed by := then we assume that what is
1156 -- really meant is an assignment statement. The assignment statement
1157 -- is scanned out and added to the list of declarations. An exception
1158 -- occurs if the := is followed by the keyword constant, in which case
1159 -- we assume it was meant to be a colon.
1161 elsif Token = Tok_Colon_Equal then
1164 if Token = Tok_Constant then
1165 Error_Msg_SP ("colon expected");
1168 Restore_Scan_State (Scan_State);
1169 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
1173 -- If we have an IS keyword, then assume the TYPE keyword was missing
1175 elsif Token = Tok_Is then
1176 Restore_Scan_State (Scan_State);
1177 Append_To (Decls, P_Type_Declaration);
1181 -- Otherwise we have an error situation
1184 Restore_Scan_State (Scan_State);
1186 -- First case is possible misuse of PROTECTED in Ada 83 mode. If
1187 -- so, fix the keyword and return to scan the protected declaration.
1189 if Token_Name = Name_Protected then
1190 Check_95_Keyword (Tok_Protected, Tok_Identifier);
1191 Check_95_Keyword (Tok_Protected, Tok_Type);
1192 Check_95_Keyword (Tok_Protected, Tok_Body);
1194 if Token = Tok_Protected then
1199 -- Check misspelling possibilities. If so, correct the misspelling
1200 -- and return to scan out the resulting declaration.
1202 elsif Bad_Spelling_Of (Tok_Function)
1203 or else Bad_Spelling_Of (Tok_Procedure)
1204 or else Bad_Spelling_Of (Tok_Package)
1205 or else Bad_Spelling_Of (Tok_Pragma)
1206 or else Bad_Spelling_Of (Tok_Protected)
1207 or else Bad_Spelling_Of (Tok_Generic)
1208 or else Bad_Spelling_Of (Tok_Subtype)
1209 or else Bad_Spelling_Of (Tok_Type)
1210 or else Bad_Spelling_Of (Tok_Task)
1211 or else Bad_Spelling_Of (Tok_Use)
1212 or else Bad_Spelling_Of (Tok_For)
1217 -- Otherwise we definitely have an ordinary identifier with a junk
1218 -- token after it. Just complain that we expect a declaration, and
1219 -- skip to a semicolon
1222 Set_Declaration_Expected;
1223 Resync_Past_Semicolon;
1229 -- Come here with an identifier list and colon scanned out. We now
1230 -- build the nodes for the declarative items. One node is built for
1231 -- each identifier in the list, with the type information being
1232 -- repeated by rescanning the appropriate section of source.
1234 -- First an error check, if we have two identifiers in a row, a likely
1235 -- possibility is that the first of the identifiers is an incorrectly
1238 if Token = Tok_Identifier then
1240 SS : Saved_Scan_State;
1244 Save_Scan_State (SS);
1245 Scan; -- past initial identifier
1246 I2 := (Token = Tok_Identifier);
1247 Restore_Scan_State (SS);
1251 (Bad_Spelling_Of (Tok_Access) or else
1252 Bad_Spelling_Of (Tok_Aliased) or else
1253 Bad_Spelling_Of (Tok_Constant))
1260 -- Loop through identifiers
1265 -- Check for some cases of misused Ada 95 keywords
1267 if Token_Name = Name_Aliased then
1268 Check_95_Keyword (Tok_Aliased, Tok_Array);
1269 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
1270 Check_95_Keyword (Tok_Aliased, Tok_Constant);
1275 if Token = Tok_Constant then
1276 Con_Loc := Token_Ptr;
1277 Scan; -- past CONSTANT
1279 -- Number declaration, initialization required
1281 Init_Expr := Init_Expr_Opt;
1283 if Present (Init_Expr) then
1284 if Not_Null_Present then
1285 Error_Msg_SP ("(Ada 0Y) null-exclusion not allowed in "
1286 & "numeric expression");
1289 Decl_Node := New_Node (N_Number_Declaration, Ident_Sloc);
1290 Set_Expression (Decl_Node, Init_Expr);
1292 -- Constant object declaration
1295 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1296 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1297 Set_Constant_Present (Decl_Node, True);
1299 if Token_Name = Name_Aliased then
1300 Check_95_Keyword (Tok_Aliased, Tok_Array);
1301 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
1304 if Token = Tok_Aliased then
1305 Error_Msg_SC ("ALIASED should be before CONSTANT");
1306 Scan; -- past ALIASED
1307 Set_Aliased_Present (Decl_Node, True);
1310 if Token = Tok_Array then
1311 Set_Object_Definition
1312 (Decl_Node, P_Array_Type_Definition);
1315 if Extensions_Allowed then -- Ada 0Y (AI-231)
1316 Not_Null_Present := P_Null_Exclusion;
1317 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1320 Set_Object_Definition (Decl_Node,
1321 P_Subtype_Indication (Not_Null_Present));
1324 if Token = Tok_Renames then
1326 ("CONSTANT not permitted in renaming declaration",
1328 Scan; -- Past renames
1329 Discard_Junk_Node (P_Name);
1335 elsif Token = Tok_Exception then
1336 Scan; -- past EXCEPTION
1338 if Token_Is_Renames then
1341 New_Node (N_Exception_Renaming_Declaration, Ident_Sloc);
1342 Set_Name (Decl_Node, P_Qualified_Simple_Name_Resync);
1345 Decl_Node := New_Node (N_Exception_Declaration, Prev_Token_Ptr);
1348 -- Aliased case (note that an object definition is required)
1350 elsif Token = Tok_Aliased then
1351 Scan; -- past ALIASED
1352 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1353 Set_Aliased_Present (Decl_Node, True);
1354 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1356 if Token = Tok_Constant then
1357 Scan; -- past CONSTANT
1358 Set_Constant_Present (Decl_Node, True);
1361 if Token = Tok_Array then
1362 Set_Object_Definition
1363 (Decl_Node, P_Array_Type_Definition);
1366 if Extensions_Allowed then -- Ada 0Y (AI-231)
1367 Not_Null_Present := P_Null_Exclusion;
1368 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1371 Set_Object_Definition (Decl_Node,
1372 P_Subtype_Indication (Not_Null_Present));
1377 elsif Token = Tok_Array then
1378 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1379 Set_Object_Definition (Decl_Node, P_Array_Type_Definition);
1381 -- Ada 0Y (AI-230): Access Definition case
1383 elsif Token = Tok_Access then
1384 if not Extensions_Allowed then
1386 ("generalized use of anonymous access types " &
1387 "is an Ada 0Y extension");
1388 Error_Msg_SP ("\unit must be compiled with -gnatX switch");
1391 Acc_Node := P_Access_Definition;
1393 if Token /= Tok_Renames then
1394 Error_Msg_SC ("'RENAMES' expected");
1398 Scan; -- past renames
1401 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1402 Set_Access_Definition (Decl_Node, Acc_Node);
1403 Set_Name (Decl_Node, P_Name);
1405 -- Subtype indication case
1408 if Extensions_Allowed then -- Ada 0Y (AI-231)
1409 Not_Null_Present := P_Null_Exclusion;
1412 Type_Node := P_Subtype_Mark;
1414 -- Object renaming declaration
1416 if Token_Is_Renames then
1417 if Not_Null_Present then
1419 ("(Ada 0Y) null-exclusion not allowed in renamings");
1424 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1425 Set_Subtype_Mark (Decl_Node, Type_Node);
1426 Set_Name (Decl_Node, P_Name);
1428 -- Object declaration
1431 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1432 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1433 Set_Object_Definition
1435 P_Subtype_Indication (Type_Node, Not_Null_Present));
1437 -- RENAMES at this point means that we had the combination of
1438 -- a constraint on the Type_Node and renames, which is illegal
1440 if Token_Is_Renames then
1442 ("constraint not allowed in object renaming declaration",
1443 Constraint (Object_Definition (Decl_Node)));
1449 -- Scan out initialization, allowed only for object declaration
1451 Init_Loc := Token_Ptr;
1452 Init_Expr := Init_Expr_Opt;
1454 if Present (Init_Expr) then
1455 if Nkind (Decl_Node) = N_Object_Declaration then
1456 Set_Expression (Decl_Node, Init_Expr);
1458 Error_Msg ("initialization not allowed here", Init_Loc);
1463 Set_Defining_Identifier (Decl_Node, Idents (Ident));
1466 if Ident < Num_Idents then
1467 Set_More_Ids (Decl_Node, True);
1471 Set_Prev_Ids (Decl_Node, True);
1475 Append (Decl_Node, Decls);
1476 exit Ident_Loop when Ident = Num_Idents;
1477 Restore_Scan_State (Scan_State);
1480 end loop Ident_Loop;
1483 end P_Identifier_Declarations;
1485 -------------------------------
1486 -- 3.3.1 Object Declaration --
1487 -------------------------------
1489 -- OBJECT DECLARATION ::=
1490 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1491 -- SUBTYPE_INDICATION [:= EXPRESSION];
1492 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1493 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1494 -- | SINGLE_TASK_DECLARATION
1495 -- | SINGLE_PROTECTED_DECLARATION
1497 -- Cases starting with TASK are parsed by P_Task (9.1)
1498 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1499 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1501 -------------------------------------
1502 -- 3.3.1 Defining Identifier List --
1503 -------------------------------------
1505 -- DEFINING_IDENTIFIER_LIST ::=
1506 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1508 -- Always parsed by the construct in which it appears. See special
1509 -- section on "Handling of Defining Identifier Lists" in this unit.
1511 -------------------------------
1512 -- 3.3.2 Number Declaration --
1513 -------------------------------
1515 -- Parsed by P_Identifier_Declarations (3.3)
1517 -------------------------------------------------------------------------
1518 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
1519 -------------------------------------------------------------------------
1521 -- DERIVED_TYPE_DEFINITION ::=
1522 -- [abstract] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
1523 -- [RECORD_EXTENSION_PART]
1525 -- PRIVATE_EXTENSION_DECLARATION ::=
1526 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
1527 -- [abstract] new ancestor_SUBTYPE_INDICATION with PRIVATE;
1529 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
1531 -- The caller has already scanned out the part up to the NEW, and Token
1532 -- either contains Tok_New (or ought to, if it doesn't this procedure
1533 -- will post an appropriate "NEW expected" message).
1535 -- Note: the caller is responsible for filling in the Sloc field of
1536 -- the returned node in the private extension declaration case as
1537 -- well as the stuff relating to the discriminant part.
1539 -- Error recovery: can raise Error_Resync;
1541 function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id is
1542 Typedef_Node : Node_Id;
1543 Typedecl_Node : Node_Id;
1544 Not_Null_Present : Boolean := False;
1546 Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr);
1549 if Token = Tok_Abstract then
1550 Error_Msg_SC ("ABSTRACT must come before NEW, not after");
1554 if Extensions_Allowed then -- Ada 0Y (AI-231)
1555 Not_Null_Present := P_Null_Exclusion;
1556 Set_Null_Exclusion_Present (Typedef_Node, Not_Null_Present);
1559 Set_Subtype_Indication (Typedef_Node,
1560 P_Subtype_Indication (Not_Null_Present));
1562 -- Deal with record extension, note that we assume that a WITH is
1563 -- missing in the case of "type X is new Y record ..." or in the
1564 -- case of "type X is new Y null record".
1567 or else Token = Tok_Record
1568 or else Token = Tok_Null
1570 T_With; -- past WITH or give error message
1572 if Token = Tok_Limited then
1574 ("LIMITED keyword not allowed in private extension");
1575 Scan; -- ignore LIMITED
1578 -- Private extension declaration
1580 if Token = Tok_Private then
1581 Scan; -- past PRIVATE
1583 -- Throw away the type definition node and build the type
1584 -- declaration node. Note the caller must set the Sloc,
1585 -- Discriminant_Specifications, Unknown_Discriminants_Present,
1586 -- and Defined_Identifier fields in the returned node.
1589 Make_Private_Extension_Declaration (No_Location,
1590 Defining_Identifier => Empty,
1591 Subtype_Indication => Subtype_Indication (Typedef_Node),
1592 Abstract_Present => Abstract_Present (Typedef_Node));
1594 Delete_Node (Typedef_Node);
1595 return Typedecl_Node;
1597 -- Derived type definition with record extension part
1600 Set_Record_Extension_Part (Typedef_Node, P_Record_Definition);
1601 return Typedef_Node;
1604 -- Derived type definition with no record extension part
1607 return Typedef_Node;
1609 end P_Derived_Type_Def_Or_Private_Ext_Decl;
1611 ---------------------------
1612 -- 3.5 Range Constraint --
1613 ---------------------------
1615 -- RANGE_CONSTRAINT ::= range RANGE
1617 -- The caller has checked that the initial token is RANGE
1619 -- Error recovery: cannot raise Error_Resync
1621 function P_Range_Constraint return Node_Id is
1622 Range_Node : Node_Id;
1625 Range_Node := New_Node (N_Range_Constraint, Token_Ptr);
1627 Set_Range_Expression (Range_Node, P_Range);
1629 end P_Range_Constraint;
1636 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
1638 -- Note: the range that appears in a membership test is parsed by
1639 -- P_Range_Or_Subtype_Mark (3.5).
1641 -- Error recovery: cannot raise Error_Resync
1643 function P_Range return Node_Id is
1644 Expr_Node : Node_Id;
1645 Range_Node : Node_Id;
1648 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
1650 if Expr_Form = EF_Range_Attr then
1653 elsif Token = Tok_Dot_Dot then
1654 Range_Node := New_Node (N_Range, Token_Ptr);
1655 Set_Low_Bound (Range_Node, Expr_Node);
1657 Expr_Node := P_Expression;
1658 Check_Simple_Expression (Expr_Node);
1659 Set_High_Bound (Range_Node, Expr_Node);
1662 -- Anything else is an error
1665 T_Dot_Dot; -- force missing .. message
1670 ----------------------------------
1671 -- 3.5 P_Range_Or_Subtype_Mark --
1672 ----------------------------------
1675 -- RANGE_ATTRIBUTE_REFERENCE
1676 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
1678 -- This routine scans out the range or subtype mark that forms the right
1679 -- operand of a membership test.
1681 -- Note: as documented in the Sinfo interface, although the syntax only
1682 -- allows a subtype mark, we in fact allow any simple expression to be
1683 -- returned from this routine. The semantics is responsible for issuing
1684 -- an appropriate message complaining if the argument is not a name.
1685 -- This simplifies the coding and error recovery processing in the
1686 -- parser, and in any case it is preferable not to consider this a
1687 -- syntax error and to continue with the semantic analysis.
1689 -- Error recovery: cannot raise Error_Resync
1691 function P_Range_Or_Subtype_Mark return Node_Id is
1692 Expr_Node : Node_Id;
1693 Range_Node : Node_Id;
1696 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
1698 if Expr_Form = EF_Range_Attr then
1701 -- Simple_Expression .. Simple_Expression
1703 elsif Token = Tok_Dot_Dot then
1704 Check_Simple_Expression (Expr_Node);
1705 Range_Node := New_Node (N_Range, Token_Ptr);
1706 Set_Low_Bound (Range_Node, Expr_Node);
1708 Set_High_Bound (Range_Node, P_Simple_Expression);
1711 -- Case of subtype mark (optionally qualified simple name or an
1712 -- attribute whose prefix is an optionally qualifed simple name)
1714 elsif Expr_Form = EF_Simple_Name
1715 or else Nkind (Expr_Node) = N_Attribute_Reference
1717 -- Check for error of range constraint after a subtype mark
1719 if Token = Tok_Range then
1721 ("range constraint not allowed in membership test");
1725 -- Check for error of DIGITS or DELTA after a subtype mark
1727 elsif Token = Tok_Digits or else Token = Tok_Delta then
1729 ("accuracy definition not allowed in membership test");
1730 Scan; -- past DIGITS or DELTA
1733 elsif Token = Tok_Apostrophe then
1734 return P_Subtype_Mark_Attribute (Expr_Node);
1740 -- At this stage, we have some junk following the expression. We
1741 -- really can't tell what is wrong, might be a missing semicolon,
1742 -- or a missing THEN, or whatever. Our caller will figure it out!
1747 end P_Range_Or_Subtype_Mark;
1749 ----------------------------------------
1750 -- 3.5.1 Enumeration Type Definition --
1751 ----------------------------------------
1753 -- ENUMERATION_TYPE_DEFINITION ::=
1754 -- (ENUMERATION_LITERAL_SPECIFICATION
1755 -- {, ENUMERATION_LITERAL_SPECIFICATION})
1757 -- The caller has already scanned out the TYPE keyword
1759 -- Error recovery: can raise Error_Resync;
1761 function P_Enumeration_Type_Definition return Node_Id is
1762 Typedef_Node : Node_Id;
1765 Typedef_Node := New_Node (N_Enumeration_Type_Definition, Token_Ptr);
1766 Set_Literals (Typedef_Node, New_List);
1771 Append (P_Enumeration_Literal_Specification, Literals (Typedef_Node));
1772 exit when not Comma_Present;
1776 return Typedef_Node;
1777 end P_Enumeration_Type_Definition;
1779 ----------------------------------------------
1780 -- 3.5.1 Enumeration Literal Specification --
1781 ----------------------------------------------
1783 -- ENUMERATION_LITERAL_SPECIFICATION ::=
1784 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
1786 -- Error recovery: can raise Error_Resync
1788 function P_Enumeration_Literal_Specification return Node_Id is
1790 if Token = Tok_Char_Literal then
1791 return P_Defining_Character_Literal;
1793 return P_Defining_Identifier (C_Comma_Right_Paren);
1795 end P_Enumeration_Literal_Specification;
1797 ---------------------------------------
1798 -- 3.5.1 Defining_Character_Literal --
1799 ---------------------------------------
1801 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
1803 -- Error recovery: cannot raise Error_Resync
1805 -- The caller has checked that the current token is a character literal
1807 function P_Defining_Character_Literal return Node_Id is
1808 Literal_Node : Node_Id;
1811 Literal_Node := Token_Node;
1812 Change_Character_Literal_To_Defining_Character_Literal (Literal_Node);
1813 Scan; -- past character literal
1814 return Literal_Node;
1815 end P_Defining_Character_Literal;
1817 ------------------------------------
1818 -- 3.5.4 Integer Type Definition --
1819 ------------------------------------
1821 -- Parsed by P_Type_Declaration (3.2.1)
1823 -------------------------------------------
1824 -- 3.5.4 Signed Integer Type Definition --
1825 -------------------------------------------
1827 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
1828 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
1830 -- Normally the initial token on entry is RANGE, but in some
1831 -- error conditions, the range token was missing and control is
1832 -- passed with Token pointing to first token of the first expression.
1834 -- Error recovery: cannot raise Error_Resync
1836 function P_Signed_Integer_Type_Definition return Node_Id is
1837 Typedef_Node : Node_Id;
1838 Expr_Node : Node_Id;
1841 Typedef_Node := New_Node (N_Signed_Integer_Type_Definition, Token_Ptr);
1843 if Token = Tok_Range then
1847 Expr_Node := P_Expression;
1848 Check_Simple_Expression (Expr_Node);
1849 Set_Low_Bound (Typedef_Node, Expr_Node);
1851 Expr_Node := P_Expression;
1852 Check_Simple_Expression (Expr_Node);
1853 Set_High_Bound (Typedef_Node, Expr_Node);
1854 return Typedef_Node;
1855 end P_Signed_Integer_Type_Definition;
1857 ------------------------------------
1858 -- 3.5.4 Modular Type Definition --
1859 ------------------------------------
1861 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
1863 -- The caller has checked that the initial token is MOD
1865 -- Error recovery: cannot raise Error_Resync
1867 function P_Modular_Type_Definition return Node_Id is
1868 Typedef_Node : Node_Id;
1872 Error_Msg_SC ("(Ada 83): modular types not allowed");
1875 Typedef_Node := New_Node (N_Modular_Type_Definition, Token_Ptr);
1877 Set_Expression (Typedef_Node, P_Expression_No_Right_Paren);
1879 -- Handle mod L..R cleanly
1881 if Token = Tok_Dot_Dot then
1882 Error_Msg_SC ("range not allowed for modular type");
1884 Set_Expression (Typedef_Node, P_Expression_No_Right_Paren);
1887 return Typedef_Node;
1888 end P_Modular_Type_Definition;
1890 ---------------------------------
1891 -- 3.5.6 Real Type Definition --
1892 ---------------------------------
1894 -- Parsed by P_Type_Declaration (3.2.1)
1896 --------------------------------------
1897 -- 3.5.7 Floating Point Definition --
1898 --------------------------------------
1900 -- FLOATING_POINT_DEFINITION ::=
1901 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
1903 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
1905 -- The caller has checked that the initial token is DIGITS
1907 -- Error recovery: cannot raise Error_Resync
1909 function P_Floating_Point_Definition return Node_Id is
1910 Digits_Loc : constant Source_Ptr := Token_Ptr;
1912 Expr_Node : Node_Id;
1915 Scan; -- past DIGITS
1916 Expr_Node := P_Expression_No_Right_Paren;
1917 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1919 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
1921 if Token = Tok_Delta then
1922 Error_Msg_SC ("DELTA must come before DIGITS");
1923 Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Digits_Loc);
1925 Set_Delta_Expression (Def_Node, P_Expression_No_Right_Paren);
1927 -- OK floating-point definition
1930 Def_Node := New_Node (N_Floating_Point_Definition, Digits_Loc);
1933 Set_Digits_Expression (Def_Node, Expr_Node);
1934 Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt);
1936 end P_Floating_Point_Definition;
1938 -------------------------------------
1939 -- 3.5.7 Real Range Specification --
1940 -------------------------------------
1942 -- REAL_RANGE_SPECIFICATION ::=
1943 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
1945 -- Error recovery: cannot raise Error_Resync
1947 function P_Real_Range_Specification_Opt return Node_Id is
1948 Specification_Node : Node_Id;
1949 Expr_Node : Node_Id;
1952 if Token = Tok_Range then
1953 Specification_Node :=
1954 New_Node (N_Real_Range_Specification, Token_Ptr);
1956 Expr_Node := P_Expression_No_Right_Paren;
1957 Check_Simple_Expression (Expr_Node);
1958 Set_Low_Bound (Specification_Node, Expr_Node);
1960 Expr_Node := P_Expression_No_Right_Paren;
1961 Check_Simple_Expression (Expr_Node);
1962 Set_High_Bound (Specification_Node, Expr_Node);
1963 return Specification_Node;
1967 end P_Real_Range_Specification_Opt;
1969 -----------------------------------
1970 -- 3.5.9 Fixed Point Definition --
1971 -----------------------------------
1973 -- FIXED_POINT_DEFINITION ::=
1974 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
1976 -- ORDINARY_FIXED_POINT_DEFINITION ::=
1977 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
1979 -- DECIMAL_FIXED_POINT_DEFINITION ::=
1980 -- delta static_EXPRESSION
1981 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
1983 -- The caller has checked that the initial token is DELTA
1985 -- Error recovery: cannot raise Error_Resync
1987 function P_Fixed_Point_Definition return Node_Id is
1988 Delta_Node : Node_Id;
1989 Delta_Loc : Source_Ptr;
1991 Expr_Node : Node_Id;
1994 Delta_Loc := Token_Ptr;
1996 Delta_Node := P_Expression_No_Right_Paren;
1997 Check_Simple_Expression_In_Ada_83 (Delta_Node);
1999 if Token = Tok_Digits then
2001 Error_Msg_SC ("(Ada 83) decimal fixed type not allowed!");
2004 Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Delta_Loc);
2005 Scan; -- past DIGITS
2006 Expr_Node := P_Expression_No_Right_Paren;
2007 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2008 Set_Digits_Expression (Def_Node, Expr_Node);
2011 Def_Node := New_Node (N_Ordinary_Fixed_Point_Definition, Delta_Loc);
2013 -- Range is required in ordinary fixed point case
2015 if Token /= Tok_Range then
2016 Error_Msg_AP ("range must be given for fixed-point type");
2021 Set_Delta_Expression (Def_Node, Delta_Node);
2022 Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt);
2024 end P_Fixed_Point_Definition;
2026 --------------------------------------------
2027 -- 3.5.9 Ordinary Fixed Point Definition --
2028 --------------------------------------------
2030 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2032 -------------------------------------------
2033 -- 3.5.9 Decimal Fixed Point Definition --
2034 -------------------------------------------
2036 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2038 ------------------------------
2039 -- 3.5.9 Digits Constraint --
2040 ------------------------------
2042 -- DIGITS_CONSTRAINT ::=
2043 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2045 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2047 -- The caller has checked that the initial token is DIGITS
2049 function P_Digits_Constraint return Node_Id is
2050 Constraint_Node : Node_Id;
2051 Expr_Node : Node_Id;
2054 Constraint_Node := New_Node (N_Digits_Constraint, Token_Ptr);
2055 Scan; -- past DIGITS
2056 Expr_Node := P_Expression_No_Right_Paren;
2057 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2058 Set_Digits_Expression (Constraint_Node, Expr_Node);
2060 if Token = Tok_Range then
2061 Set_Range_Constraint (Constraint_Node, P_Range_Constraint);
2064 return Constraint_Node;
2065 end P_Digits_Constraint;
2067 -----------------------------
2068 -- 3.5.9 Delta Constraint --
2069 -----------------------------
2071 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2073 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2075 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2077 -- The caller has checked that the initial token is DELTA
2079 -- Error recovery: cannot raise Error_Resync
2081 function P_Delta_Constraint return Node_Id is
2082 Constraint_Node : Node_Id;
2083 Expr_Node : Node_Id;
2086 Constraint_Node := New_Node (N_Delta_Constraint, Token_Ptr);
2088 Expr_Node := P_Expression_No_Right_Paren;
2089 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2090 Set_Delta_Expression (Constraint_Node, Expr_Node);
2092 if Token = Tok_Range then
2093 Set_Range_Constraint (Constraint_Node, P_Range_Constraint);
2096 return Constraint_Node;
2097 end P_Delta_Constraint;
2099 --------------------------------
2100 -- 3.6 Array Type Definition --
2101 --------------------------------
2103 -- ARRAY_TYPE_DEFINITION ::=
2104 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2106 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2107 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2108 -- COMPONENT_DEFINITION
2110 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2112 -- CONSTRAINED_ARRAY_DEFINITION ::=
2113 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2114 -- COMPONENT_DEFINITION
2116 -- DISCRETE_SUBTYPE_DEFINITION ::=
2117 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2119 -- COMPONENT_DEFINITION ::=
2120 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2122 -- The caller has checked that the initial token is ARRAY
2124 -- Error recovery: can raise Error_Resync
2126 function P_Array_Type_Definition return Node_Id is
2127 Array_Loc : Source_Ptr;
2128 CompDef_Node : Node_Id;
2130 Not_Null_Present : Boolean := False;
2131 Subs_List : List_Id;
2132 Scan_State : Saved_Scan_State;
2135 Array_Loc := Token_Ptr;
2137 Subs_List := New_List;
2140 -- It's quite tricky to disentangle these two possibilities, so we do
2141 -- a prescan to determine which case we have and then reset the scan.
2142 -- The prescan skips past possible subtype mark tokens.
2144 Save_Scan_State (Scan_State); -- just after paren
2146 while Token in Token_Class_Desig or else
2147 Token = Tok_Dot or else
2148 Token = Tok_Apostrophe -- because of 'BASE, 'CLASS
2153 -- If we end up on RANGE <> then we have the unconstrained case. We
2154 -- will also allow the RANGE to be omitted, just to improve error
2155 -- handling for a case like array (integer <>) of integer;
2157 Scan; -- past possible RANGE or <>
2159 if (Prev_Token = Tok_Range and then Token = Tok_Box) or else
2160 Prev_Token = Tok_Box
2162 Def_Node := New_Node (N_Unconstrained_Array_Definition, Array_Loc);
2163 Restore_Scan_State (Scan_State); -- to first subtype mark
2166 Append (P_Subtype_Mark_Resync, Subs_List);
2169 exit when Token = Tok_Right_Paren or else Token = Tok_Of;
2173 Set_Subtype_Marks (Def_Node, Subs_List);
2176 Def_Node := New_Node (N_Constrained_Array_Definition, Array_Loc);
2177 Restore_Scan_State (Scan_State); -- to first discrete range
2180 Append (P_Discrete_Subtype_Definition, Subs_List);
2181 exit when not Comma_Present;
2184 Set_Discrete_Subtype_Definitions (Def_Node, Subs_List);
2190 CompDef_Node := New_Node (N_Component_Definition, Token_Ptr);
2192 -- Ada 0Y (AI-230): Access Definition case
2194 if Token = Tok_Access then
2195 if not Extensions_Allowed then
2197 ("generalized use of anonymous access types " &
2198 "is an Ada 0Y extension");
2199 Error_Msg_SP ("\unit must be compiled with -gnatX switch");
2202 Set_Subtype_Indication (CompDef_Node, Empty);
2203 Set_Aliased_Present (CompDef_Node, False);
2204 Set_Access_Definition (CompDef_Node, P_Access_Definition);
2206 Set_Access_Definition (CompDef_Node, Empty);
2208 if Token_Name = Name_Aliased then
2209 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
2212 if Token = Tok_Aliased then
2213 Set_Aliased_Present (CompDef_Node, True);
2214 Scan; -- past ALIASED
2217 if Extensions_Allowed then -- Ada 0Y (AI-231)
2218 Not_Null_Present := P_Null_Exclusion;
2219 Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present);
2222 Set_Subtype_Indication (CompDef_Node,
2223 P_Subtype_Indication (Not_Null_Present));
2226 Set_Component_Definition (Def_Node, CompDef_Node);
2229 end P_Array_Type_Definition;
2231 -----------------------------------------
2232 -- 3.6 Unconstrained Array Definition --
2233 -----------------------------------------
2235 -- Parsed by P_Array_Type_Definition (3.6)
2237 ---------------------------------------
2238 -- 3.6 Constrained Array Definition --
2239 ---------------------------------------
2241 -- Parsed by P_Array_Type_Definition (3.6)
2243 --------------------------------------
2244 -- 3.6 Discrete Subtype Definition --
2245 --------------------------------------
2247 -- DISCRETE_SUBTYPE_DEFINITION ::=
2248 -- discrete_SUBTYPE_INDICATION | RANGE
2250 -- Note: the discrete subtype definition appearing in a constrained
2251 -- array definition is parsed by P_Array_Type_Definition (3.6)
2253 -- Error recovery: cannot raise Error_Resync
2255 function P_Discrete_Subtype_Definition return Node_Id is
2257 -- The syntax of a discrete subtype definition is identical to that
2258 -- of a discrete range, so we simply share the same parsing code.
2260 return P_Discrete_Range;
2261 end P_Discrete_Subtype_Definition;
2263 -------------------------------
2264 -- 3.6 Component Definition --
2265 -------------------------------
2267 -- For the array case, parsed by P_Array_Type_Definition (3.6)
2268 -- For the record case, parsed by P_Component_Declaration (3.8)
2270 -----------------------------
2271 -- 3.6.1 Index Constraint --
2272 -----------------------------
2274 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2276 ---------------------------
2277 -- 3.6.1 Discrete Range --
2278 ---------------------------
2280 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
2282 -- The possible forms for a discrete range are:
2284 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
2285 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
2286 -- Range_Attribute (RANGE, 3.5)
2287 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
2289 -- Error recovery: cannot raise Error_Resync
2291 function P_Discrete_Range return Node_Id is
2292 Expr_Node : Node_Id;
2293 Range_Node : Node_Id;
2296 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
2298 if Expr_Form = EF_Range_Attr then
2301 elsif Token = Tok_Range then
2302 if Expr_Form /= EF_Simple_Name then
2303 Error_Msg_SC ("range must be preceded by subtype mark");
2306 return P_Subtype_Indication (Expr_Node);
2308 -- Check Expression .. Expression case
2310 elsif Token = Tok_Dot_Dot then
2311 Range_Node := New_Node (N_Range, Token_Ptr);
2312 Set_Low_Bound (Range_Node, Expr_Node);
2314 Expr_Node := P_Expression;
2315 Check_Simple_Expression (Expr_Node);
2316 Set_High_Bound (Range_Node, Expr_Node);
2319 -- Otherwise we must have a subtype mark
2321 elsif Expr_Form = EF_Simple_Name then
2324 -- If incorrect, complain that we expect ..
2330 end P_Discrete_Range;
2332 ----------------------------
2333 -- 3.7 Discriminant Part --
2334 ----------------------------
2336 -- DISCRIMINANT_PART ::=
2337 -- UNKNOWN_DISCRIMINANT_PART
2338 -- | KNOWN_DISCRIMINANT_PART
2340 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
2341 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
2343 ------------------------------------
2344 -- 3.7 Unknown Discriminant Part --
2345 ------------------------------------
2347 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
2349 -- If no unknown discriminant part is present, then False is returned,
2350 -- otherwise the unknown discriminant is scanned out and True is returned.
2352 -- Error recovery: cannot raise Error_Resync
2354 function P_Unknown_Discriminant_Part_Opt return Boolean is
2355 Scan_State : Saved_Scan_State;
2358 if Token /= Tok_Left_Paren then
2362 Save_Scan_State (Scan_State);
2363 Scan; -- past the left paren
2365 if Token = Tok_Box then
2367 Error_Msg_SC ("(Ada 83) unknown discriminant not allowed!");
2370 Scan; -- past the box
2371 T_Right_Paren; -- must be followed by right paren
2375 Restore_Scan_State (Scan_State);
2379 end P_Unknown_Discriminant_Part_Opt;
2381 ----------------------------------
2382 -- 3.7 Known Discriminant Part --
2383 ----------------------------------
2385 -- KNOWN_DISCRIMINANT_PART ::=
2386 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
2388 -- DISCRIMINANT_SPECIFICATION ::=
2389 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
2390 -- [:= DEFAULT_EXPRESSION]
2391 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
2392 -- [:= DEFAULT_EXPRESSION]
2394 -- If no known discriminant part is present, then No_List is returned
2396 -- Error recovery: cannot raise Error_Resync
2398 function P_Known_Discriminant_Part_Opt return List_Id is
2399 Specification_Node : Node_Id;
2400 Specification_List : List_Id;
2401 Ident_Sloc : Source_Ptr;
2402 Scan_State : Saved_Scan_State;
2404 Not_Null_Present : Boolean;
2407 Idents : array (Int range 1 .. 4096) of Entity_Id;
2408 -- This array holds the list of defining identifiers. The upper bound
2409 -- of 4096 is intended to be essentially infinite, and we do not even
2410 -- bother to check for it being exceeded.
2413 if Token = Tok_Left_Paren then
2414 Specification_List := New_List;
2416 P_Pragmas_Misplaced;
2418 Specification_Loop : loop
2420 Ident_Sloc := Token_Ptr;
2421 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
2424 while Comma_Present loop
2425 Num_Idents := Num_Idents + 1;
2426 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
2431 -- If there are multiple identifiers, we repeatedly scan the
2432 -- type and initialization expression information by resetting
2433 -- the scan pointer (so that we get completely separate trees
2434 -- for each occurrence).
2436 if Num_Idents > 1 then
2437 Save_Scan_State (Scan_State);
2440 -- Loop through defining identifiers in list
2444 Specification_Node :=
2445 New_Node (N_Discriminant_Specification, Ident_Sloc);
2446 Set_Defining_Identifier (Specification_Node, Idents (Ident));
2448 Not_Null_Present := P_Null_Exclusion; -- Ada 0Y (AI-231)
2450 if Token = Tok_Access then
2453 ("(Ada 83) access discriminant not allowed!");
2456 Set_Discriminant_Type
2457 (Specification_Node, P_Access_Definition);
2458 Set_Null_Exclusion_Present -- Ada 0Y (AI-231)
2459 (Discriminant_Type (Specification_Node),
2462 Set_Discriminant_Type
2463 (Specification_Node, P_Subtype_Mark);
2465 Set_Null_Exclusion_Present -- Ada 0Y (AI-231)
2466 (Specification_Node, Not_Null_Present);
2470 (Specification_Node, Init_Expr_Opt (True));
2473 Set_Prev_Ids (Specification_Node, True);
2476 if Ident < Num_Idents then
2477 Set_More_Ids (Specification_Node, True);
2480 Append (Specification_Node, Specification_List);
2481 exit Ident_Loop when Ident = Num_Idents;
2483 Restore_Scan_State (Scan_State);
2484 end loop Ident_Loop;
2486 exit Specification_Loop when Token /= Tok_Semicolon;
2488 P_Pragmas_Misplaced;
2489 end loop Specification_Loop;
2492 return Specification_List;
2497 end P_Known_Discriminant_Part_Opt;
2499 -------------------------------------
2500 -- 3.7 DIscriminant Specification --
2501 -------------------------------------
2503 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
2505 -----------------------------
2506 -- 3.7 Default Expression --
2507 -----------------------------
2509 -- Always parsed (simply as an Expression) by the parent construct
2511 ------------------------------------
2512 -- 3.7.1 Discriminant Constraint --
2513 ------------------------------------
2515 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2517 --------------------------------------------------------
2518 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
2519 --------------------------------------------------------
2521 -- DISCRIMINANT_CONSTRAINT ::=
2522 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
2524 -- DISCRIMINANT_ASSOCIATION ::=
2525 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
2528 -- This routine parses either an index or a discriminant constraint. As
2529 -- is clear from the above grammar, it is often possible to clearly
2530 -- determine which of the two possibilities we have, but there are
2531 -- cases (those in which we have a series of expressions of the same
2532 -- syntactic form as subtype indications), where we cannot tell. Since
2533 -- this means that in any case the semantic phase has to distinguish
2534 -- between the two, there is not much point in the parser trying to
2535 -- distinguish even those cases where the difference is clear. In any
2536 -- case, if we have a situation like:
2538 -- (A => 123, 235 .. 500)
2540 -- it is not clear which of the two items is the wrong one, better to
2541 -- let the semantic phase give a clear message. Consequently, this
2542 -- routine in general returns a list of items which can be either
2543 -- discrete ranges or discriminant associations.
2545 -- The caller has checked that the initial token is a left paren
2547 -- Error recovery: can raise Error_Resync
2549 function P_Index_Or_Discriminant_Constraint return Node_Id is
2550 Scan_State : Saved_Scan_State;
2551 Constr_Node : Node_Id;
2552 Constr_List : List_Id;
2553 Expr_Node : Node_Id;
2554 Result_Node : Node_Id;
2557 Result_Node := New_Node (N_Index_Or_Discriminant_Constraint, Token_Ptr);
2559 Constr_List := New_List;
2560 Set_Constraints (Result_Node, Constr_List);
2562 -- The two syntactic forms are a little mixed up, so what we are doing
2563 -- here is looking at the first entry to determine which case we have
2565 -- A discriminant constraint is a list of discriminant associations,
2566 -- which have one of the following possible forms:
2570 -- Id | Id | .. | Id => Expression
2572 -- An index constraint is a list of discrete ranges which have one
2573 -- of the following possible forms:
2576 -- Subtype_Mark range Range
2578 -- Simple_Expression .. Simple_Expression
2580 -- Loop through discriminants in list
2583 -- Check cases of Id => Expression or Id | Id => Expression
2585 if Token = Tok_Identifier then
2586 Save_Scan_State (Scan_State); -- at Id
2589 if Token = Tok_Arrow or else Token = Tok_Vertical_Bar then
2590 Restore_Scan_State (Scan_State); -- to Id
2591 Append (P_Discriminant_Association, Constr_List);
2594 Restore_Scan_State (Scan_State); -- to Id
2598 -- Otherwise scan out an expression and see what we have got
2600 Expr_Node := P_Expression_Or_Range_Attribute;
2602 if Expr_Form = EF_Range_Attr then
2603 Append (Expr_Node, Constr_List);
2605 elsif Token = Tok_Range then
2606 if Expr_Form /= EF_Simple_Name then
2607 Error_Msg_SC ("subtype mark required before RANGE");
2610 Append (P_Subtype_Indication (Expr_Node), Constr_List);
2613 -- Check Simple_Expression .. Simple_Expression case
2615 elsif Token = Tok_Dot_Dot then
2616 Check_Simple_Expression (Expr_Node);
2617 Constr_Node := New_Node (N_Range, Token_Ptr);
2618 Set_Low_Bound (Constr_Node, Expr_Node);
2620 Expr_Node := P_Expression;
2621 Check_Simple_Expression (Expr_Node);
2622 Set_High_Bound (Constr_Node, Expr_Node);
2623 Append (Constr_Node, Constr_List);
2626 -- Case of an expression which could be either form
2629 Append (Expr_Node, Constr_List);
2633 -- Here with a single entry scanned
2636 exit when not Comma_Present;
2642 end P_Index_Or_Discriminant_Constraint;
2644 -------------------------------------
2645 -- 3.7.1 Discriminant Association --
2646 -------------------------------------
2648 -- DISCRIMINANT_ASSOCIATION ::=
2649 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
2652 -- This routine is used only when the name list is present and the caller
2653 -- has already checked this (by scanning ahead and repositioning the
2656 -- Error_Recovery: cannot raise Error_Resync;
2658 function P_Discriminant_Association return Node_Id is
2659 Discr_Node : Node_Id;
2660 Names_List : List_Id;
2661 Ident_Sloc : Source_Ptr;
2664 Ident_Sloc := Token_Ptr;
2665 Names_List := New_List;
2668 Append (P_Identifier (C_Vertical_Bar_Arrow), Names_List);
2669 exit when Token /= Tok_Vertical_Bar;
2673 Discr_Node := New_Node (N_Discriminant_Association, Ident_Sloc);
2674 Set_Selector_Names (Discr_Node, Names_List);
2676 Set_Expression (Discr_Node, P_Expression);
2678 end P_Discriminant_Association;
2680 ---------------------------------
2681 -- 3.8 Record Type Definition --
2682 ---------------------------------
2684 -- RECORD_TYPE_DEFINITION ::=
2685 -- [[abstract] tagged] [limited] RECORD_DEFINITION
2687 -- There is no node in the tree for a record type definition. Instead
2688 -- a record definition node appears, with possible Abstract_Present,
2689 -- Tagged_Present, and Limited_Present flags set appropriately.
2691 ----------------------------
2692 -- 3.8 Record Definition --
2693 ----------------------------
2695 -- RECORD_DEFINITION ::=
2701 -- Note: in the case where a record definition node is used to represent
2702 -- a record type definition, the caller sets the Tagged_Present and
2703 -- Limited_Present flags in the resulting N_Record_Definition node as
2706 -- Note that the RECORD token at the start may be missing in certain
2707 -- error situations, so this function is expected to post the error
2709 -- Error recovery: can raise Error_Resync
2711 function P_Record_Definition return Node_Id is
2715 Rec_Node := New_Node (N_Record_Definition, Token_Ptr);
2719 if Token = Tok_Null then
2722 Set_Null_Present (Rec_Node, True);
2724 -- Case starting with RECORD keyword. Build scope stack entry. For the
2725 -- column, we use the first non-blank character on the line, to deal
2726 -- with situations such as:
2732 -- which is not official RM indentation, but is not uncommon usage
2736 Scope.Table (Scope.Last).Etyp := E_Record;
2737 Scope.Table (Scope.Last).Ecol := Start_Column;
2738 Scope.Table (Scope.Last).Sloc := Token_Ptr;
2739 Scope.Table (Scope.Last).Labl := Error;
2740 Scope.Table (Scope.Last).Junk := (Token /= Tok_Record);
2744 Set_Component_List (Rec_Node, P_Component_List);
2747 exit when Check_End;
2748 Discard_Junk_Node (P_Component_List);
2753 end P_Record_Definition;
2755 -------------------------
2756 -- 3.8 Component List --
2757 -------------------------
2759 -- COMPONENT_LIST ::=
2760 -- COMPONENT_ITEM {COMPONENT_ITEM}
2761 -- | {COMPONENT_ITEM} VARIANT_PART
2764 -- Error recovery: cannot raise Error_Resync
2766 function P_Component_List return Node_Id is
2767 Component_List_Node : Node_Id;
2768 Decls_List : List_Id;
2769 Scan_State : Saved_Scan_State;
2772 Component_List_Node := New_Node (N_Component_List, Token_Ptr);
2773 Decls_List := New_List;
2775 if Token = Tok_Null then
2778 P_Pragmas_Opt (Decls_List);
2779 Set_Null_Present (Component_List_Node, True);
2780 return Component_List_Node;
2783 P_Pragmas_Opt (Decls_List);
2785 if Token /= Tok_Case then
2786 Component_Scan_Loop : loop
2787 P_Component_Items (Decls_List);
2788 P_Pragmas_Opt (Decls_List);
2790 exit Component_Scan_Loop when Token = Tok_End
2791 or else Token = Tok_Case
2792 or else Token = Tok_When;
2794 -- We are done if we do not have an identifier. However, if
2795 -- we have a misspelled reserved identifier that is in a column
2796 -- to the right of the record definition, we will treat it as
2797 -- an identifier. It turns out to be too dangerous in practice
2798 -- to accept such a mis-spelled identifier which does not have
2799 -- this additional clue that confirms the incorrect spelling.
2801 if Token /= Tok_Identifier then
2802 if Start_Column > Scope.Table (Scope.Last).Ecol
2803 and then Is_Reserved_Identifier
2805 Save_Scan_State (Scan_State); -- at reserved id
2806 Scan; -- possible reserved id
2808 if Token = Tok_Comma or else Token = Tok_Colon then
2809 Restore_Scan_State (Scan_State);
2810 Scan_Reserved_Identifier (Force_Msg => True);
2812 -- Note reserved identifier used as field name after
2813 -- all because not followed by colon or comma
2816 Restore_Scan_State (Scan_State);
2817 exit Component_Scan_Loop;
2820 -- Non-identifier that definitely was not reserved id
2823 exit Component_Scan_Loop;
2826 end loop Component_Scan_Loop;
2829 if Token = Tok_Case then
2830 Set_Variant_Part (Component_List_Node, P_Variant_Part);
2832 -- Check for junk after variant part
2834 if Token = Tok_Identifier then
2835 Save_Scan_State (Scan_State);
2836 Scan; -- past identifier
2838 if Token = Tok_Colon then
2839 Restore_Scan_State (Scan_State);
2840 Error_Msg_SC ("component may not follow variant part");
2841 Discard_Junk_Node (P_Component_List);
2843 elsif Token = Tok_Case then
2844 Restore_Scan_State (Scan_State);
2845 Error_Msg_SC ("only one variant part allowed in a record");
2846 Discard_Junk_Node (P_Component_List);
2849 Restore_Scan_State (Scan_State);
2855 Set_Component_Items (Component_List_Node, Decls_List);
2856 return Component_List_Node;
2857 end P_Component_List;
2859 -------------------------
2860 -- 3.8 Component Item --
2861 -------------------------
2863 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
2865 -- COMPONENT_DECLARATION ::=
2866 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
2867 -- [:= DEFAULT_EXPRESSION];
2869 -- COMPONENT_DEFINITION ::=
2870 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2872 -- Error recovery: cannot raise Error_Resync, if an error occurs,
2873 -- the scan is positioned past the following semicolon.
2875 -- Note: we do not yet allow representation clauses to appear as component
2876 -- items, do we need to add this capability sometime in the future ???
2878 procedure P_Component_Items (Decls : List_Id) is
2879 CompDef_Node : Node_Id;
2880 Decl_Node : Node_Id;
2881 Scan_State : Saved_Scan_State;
2882 Not_Null_Present : Boolean := False;
2885 Ident_Sloc : Source_Ptr;
2887 Idents : array (Int range 1 .. 4096) of Entity_Id;
2888 -- This array holds the list of defining identifiers. The upper bound
2889 -- of 4096 is intended to be essentially infinite, and we do not even
2890 -- bother to check for it being exceeded.
2893 if Token /= Tok_Identifier then
2894 Error_Msg_SC ("component declaration expected");
2895 Resync_Past_Semicolon;
2899 Ident_Sloc := Token_Ptr;
2900 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
2903 while Comma_Present loop
2904 Num_Idents := Num_Idents + 1;
2905 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
2910 -- If there are multiple identifiers, we repeatedly scan the
2911 -- type and initialization expression information by resetting
2912 -- the scan pointer (so that we get completely separate trees
2913 -- for each occurrence).
2915 if Num_Idents > 1 then
2916 Save_Scan_State (Scan_State);
2919 -- Loop through defining identifiers in list
2924 -- The following block is present to catch Error_Resync
2925 -- which causes the parse to be reset past the semicolon
2928 Decl_Node := New_Node (N_Component_Declaration, Ident_Sloc);
2929 Set_Defining_Identifier (Decl_Node, Idents (Ident));
2931 if Token = Tok_Constant then
2932 Error_Msg_SC ("constant components are not permitted");
2936 CompDef_Node := New_Node (N_Component_Definition, Token_Ptr);
2938 if Token = Tok_Access then
2939 if not Extensions_Allowed then
2941 ("Generalized use of anonymous access types " &
2942 "is an Ada 0Y extension");
2943 Error_Msg_SP ("\unit must be compiled with -gnatX switch");
2946 Set_Subtype_Indication (CompDef_Node, Empty);
2947 Set_Aliased_Present (CompDef_Node, False);
2948 Set_Access_Definition (CompDef_Node, P_Access_Definition);
2951 Set_Access_Definition (CompDef_Node, Empty);
2953 if Token_Name = Name_Aliased then
2954 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
2957 if Token = Tok_Aliased then
2958 Scan; -- past ALIASED
2959 Set_Aliased_Present (CompDef_Node, True);
2962 if Token = Tok_Array then
2964 ("anonymous arrays not allowed as components");
2968 if Extensions_Allowed then -- Ada 0Y (AI-231)
2969 Not_Null_Present := P_Null_Exclusion;
2970 Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present);
2973 Set_Subtype_Indication (CompDef_Node,
2974 P_Subtype_Indication (Not_Null_Present));
2977 Set_Component_Definition (Decl_Node, CompDef_Node);
2978 Set_Expression (Decl_Node, Init_Expr_Opt);
2981 Set_Prev_Ids (Decl_Node, True);
2984 if Ident < Num_Idents then
2985 Set_More_Ids (Decl_Node, True);
2988 Append (Decl_Node, Decls);
2991 when Error_Resync =>
2992 if Token /= Tok_End then
2993 Resync_Past_Semicolon;
2997 exit Ident_Loop when Ident = Num_Idents;
2999 Restore_Scan_State (Scan_State);
3001 end loop Ident_Loop;
3004 end P_Component_Items;
3006 --------------------------------
3007 -- 3.8 Component Declaration --
3008 --------------------------------
3010 -- Parsed by P_Component_Items (3.8)
3012 -------------------------
3013 -- 3.8.1 Variant Part --
3014 -------------------------
3017 -- case discriminant_DIRECT_NAME is
3022 -- The caller has checked that the initial token is CASE
3024 -- Error recovery: cannot raise Error_Resync
3026 function P_Variant_Part return Node_Id is
3027 Variant_Part_Node : Node_Id;
3028 Variants_List : List_Id;
3029 Case_Node : Node_Id;
3032 Variant_Part_Node := New_Node (N_Variant_Part, Token_Ptr);
3034 Scope.Table (Scope.Last).Etyp := E_Case;
3035 Scope.Table (Scope.Last).Sloc := Token_Ptr;
3036 Scope.Table (Scope.Last).Ecol := Start_Column;
3039 Case_Node := P_Expression;
3040 Set_Name (Variant_Part_Node, Case_Node);
3042 if Nkind (Case_Node) /= N_Identifier then
3043 Set_Name (Variant_Part_Node, Error);
3044 Error_Msg ("discriminant name expected", Sloc (Case_Node));
3048 Variants_List := New_List;
3049 P_Pragmas_Opt (Variants_List);
3051 -- Test missing variant
3053 if Token = Tok_End then
3054 Error_Msg_BC ("WHEN expected (must have at least one variant)");
3056 Append (P_Variant, Variants_List);
3059 -- Loop through variants, note that we allow if in place of when,
3060 -- this error will be detected and handled in P_Variant.
3063 P_Pragmas_Opt (Variants_List);
3065 if Token /= Tok_When
3066 and then Token /= Tok_If
3067 and then Token /= Tok_Others
3069 exit when Check_End;
3072 Append (P_Variant, Variants_List);
3075 Set_Variants (Variant_Part_Node, Variants_List);
3076 return Variant_Part_Node;
3079 --------------------
3081 --------------------
3084 -- when DISCRETE_CHOICE_LIST =>
3087 -- Error recovery: cannot raise Error_Resync
3089 -- The initial token on entry is either WHEN, IF or OTHERS
3091 function P_Variant return Node_Id is
3092 Variant_Node : Node_Id;
3095 -- Special check to recover nicely from use of IF in place of WHEN
3097 if Token = Tok_If then
3104 Variant_Node := New_Node (N_Variant, Prev_Token_Ptr);
3105 Set_Discrete_Choices (Variant_Node, P_Discrete_Choice_List);
3107 Set_Component_List (Variant_Node, P_Component_List);
3108 return Variant_Node;
3111 ---------------------------------
3112 -- 3.8.1 Discrete Choice List --
3113 ---------------------------------
3115 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3117 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3119 -- Note: in Ada 83, the expression must be a simple expression
3121 -- Error recovery: cannot raise Error_Resync
3123 function P_Discrete_Choice_List return List_Id is
3125 Expr_Node : Node_Id;
3126 Choice_Node : Node_Id;
3129 Choices := New_List;
3132 if Token = Tok_Others then
3133 Append (New_Node (N_Others_Choice, Token_Ptr), Choices);
3134 Scan; -- past OTHERS
3138 Expr_Node := No_Right_Paren (P_Expression_Or_Range_Attribute);
3140 if Token = Tok_Colon
3141 and then Nkind (Expr_Node) = N_Identifier
3143 Error_Msg_SP ("label not permitted in this context");
3146 elsif Expr_Form = EF_Range_Attr then
3147 Append (Expr_Node, Choices);
3149 elsif Token = Tok_Dot_Dot then
3150 Check_Simple_Expression (Expr_Node);
3151 Choice_Node := New_Node (N_Range, Token_Ptr);
3152 Set_Low_Bound (Choice_Node, Expr_Node);
3154 Expr_Node := P_Expression_No_Right_Paren;
3155 Check_Simple_Expression (Expr_Node);
3156 Set_High_Bound (Choice_Node, Expr_Node);
3157 Append (Choice_Node, Choices);
3159 elsif Expr_Form = EF_Simple_Name then
3160 if Token = Tok_Range then
3161 Append (P_Subtype_Indication (Expr_Node), Choices);
3163 elsif Token in Token_Class_Consk then
3165 ("the only constraint allowed here " &
3166 "is a range constraint");
3167 Discard_Junk_Node (P_Constraint_Opt);
3168 Append (Expr_Node, Choices);
3171 Append (Expr_Node, Choices);
3175 Check_Simple_Expression_In_Ada_83 (Expr_Node);
3176 Append (Expr_Node, Choices);
3180 when Error_Resync =>
3186 if Token = Tok_Comma then
3187 Error_Msg_SC (""","" should be ""'|""");
3189 exit when Token /= Tok_Vertical_Bar;
3192 Scan; -- past | or comma
3196 end P_Discrete_Choice_List;
3198 ----------------------------
3199 -- 3.8.1 Discrete Choice --
3200 ----------------------------
3202 -- Parsed by P_Discrete_Choice_List (3.8.1)
3204 ----------------------------------
3205 -- 3.9.1 Record Extension Part --
3206 ----------------------------------
3208 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
3210 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
3212 ----------------------------------
3213 -- 3.10 Access Type Definition --
3214 ----------------------------------
3216 -- ACCESS_TYPE_DEFINITION ::=
3217 -- ACCESS_TO_OBJECT_DEFINITION
3218 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3220 -- ACCESS_TO_OBJECT_DEFINITION ::=
3221 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
3223 -- GENERAL_ACCESS_MODIFIER ::= all | constant
3225 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3226 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3227 -- | [NULL_EXCLUSION] access [protected] function
3228 -- PARAMETER_AND_RESULT_PROFILE
3230 -- PARAMETER_PROFILE ::= [FORMAL_PART]
3232 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
3234 -- The caller has checked that the initial token is ACCESS
3236 -- Error recovery: can raise Error_Resync
3238 function P_Access_Type_Definition return Node_Id is
3239 Prot_Flag : Boolean;
3240 Access_Loc : Source_Ptr;
3241 Not_Null_Present : Boolean := False;
3242 Type_Def_Node : Node_Id;
3244 procedure Check_Junk_Subprogram_Name;
3245 -- Used in access to subprogram definition cases to check for an
3246 -- identifier or operator symbol that does not belong.
3248 procedure Check_Junk_Subprogram_Name is
3249 Saved_State : Saved_Scan_State;
3252 if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then
3253 Save_Scan_State (Saved_State);
3254 Scan; -- past possible junk subprogram name
3256 if Token = Tok_Left_Paren or else Token = Tok_Semicolon then
3257 Error_Msg_SP ("unexpected subprogram name ignored");
3261 Restore_Scan_State (Saved_State);
3264 end Check_Junk_Subprogram_Name;
3266 -- Start of processing for P_Access_Type_Definition
3269 if Extensions_Allowed then -- Ada 0Y (AI-231)
3270 Not_Null_Present := P_Null_Exclusion;
3273 Access_Loc := Token_Ptr;
3274 Scan; -- past ACCESS
3276 if Token_Name = Name_Protected then
3277 Check_95_Keyword (Tok_Protected, Tok_Procedure);
3278 Check_95_Keyword (Tok_Protected, Tok_Function);
3281 Prot_Flag := (Token = Tok_Protected);
3284 Scan; -- past PROTECTED
3286 if Token /= Tok_Procedure and then Token /= Tok_Function then
3287 Error_Msg_SC ("FUNCTION or PROCEDURE expected");
3291 if Token = Tok_Procedure then
3293 Error_Msg_SC ("(Ada 83) access to procedure not allowed!");
3296 Type_Def_Node := New_Node (N_Access_Procedure_Definition, Access_Loc);
3297 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3298 Scan; -- past PROCEDURE
3299 Check_Junk_Subprogram_Name;
3300 Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile);
3301 Set_Protected_Present (Type_Def_Node, Prot_Flag);
3303 elsif Token = Tok_Function then
3305 Error_Msg_SC ("(Ada 83) access to function not allowed!");
3308 Type_Def_Node := New_Node (N_Access_Function_Definition, Access_Loc);
3309 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3310 Scan; -- past FUNCTION
3311 Check_Junk_Subprogram_Name;
3312 Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile);
3313 Set_Protected_Present (Type_Def_Node, Prot_Flag);
3315 Set_Subtype_Mark (Type_Def_Node, P_Subtype_Mark);
3320 New_Node (N_Access_To_Object_Definition, Access_Loc);
3321 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3323 if Token = Tok_All or else Token = Tok_Constant then
3325 Error_Msg_SC ("(Ada 83) access modifier not allowed!");
3328 if Token = Tok_All then
3329 Set_All_Present (Type_Def_Node, True);
3332 Set_Constant_Present (Type_Def_Node, True);
3335 Scan; -- past ALL or CONSTANT
3338 Set_Subtype_Indication (Type_Def_Node,
3339 P_Subtype_Indication (Not_Null_Present));
3342 return Type_Def_Node;
3343 end P_Access_Type_Definition;
3345 ---------------------------------------
3346 -- 3.10 Access To Object Definition --
3347 ---------------------------------------
3349 -- Parsed by P_Access_Type_Definition (3.10)
3351 -----------------------------------
3352 -- 3.10 General Access Modifier --
3353 -----------------------------------
3355 -- Parsed by P_Access_Type_Definition (3.10)
3357 -------------------------------------------
3358 -- 3.10 Access To Subprogram Definition --
3359 -------------------------------------------
3361 -- Parsed by P_Access_Type_Definition (3.10)
3363 -----------------------------
3364 -- 3.10 Access Definition --
3365 -----------------------------
3367 -- ACCESS_DEFINITION ::=
3368 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
3370 -- The caller has checked that the initial token is ACCESS
3372 -- Error recovery: cannot raise Error_Resync
3374 function P_Access_Definition return Node_Id is
3378 Def_Node := New_Node (N_Access_Definition, Token_Ptr);
3379 Scan; -- past ACCESS
3383 if Extensions_Allowed then
3384 if Token = Tok_All then
3386 Set_All_Present (Def_Node);
3388 elsif Token = Tok_Constant then
3389 Scan; -- past CONSTANT
3390 Set_Constant_Present (Def_Node);
3394 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
3397 end P_Access_Definition;
3399 -----------------------------------------
3400 -- 3.10.1 Incomplete Type Declaration --
3401 -----------------------------------------
3403 -- Parsed by P_Type_Declaration (3.2.1)
3405 ----------------------------
3406 -- 3.11 Declarative Part --
3407 ----------------------------
3409 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
3411 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Items
3412 -- handles errors, and returns cleanly after an error has occurred)
3414 function P_Declarative_Part return List_Id is
3419 -- Indicate no bad declarations detected yet. This will be reset by
3420 -- P_Declarative_Items if a bad declaration is discovered.
3422 Missing_Begin_Msg := No_Error_Msg;
3424 -- Get rid of active SIS entry from outer scope. This means we will
3425 -- miss some nested cases, but it doesn't seem worth the effort. See
3426 -- discussion in Par for further details
3428 SIS_Entry_Active := False;
3431 -- Loop to scan out the declarations
3434 P_Declarative_Items (Decls, Done, In_Spec => False);
3438 -- Get rid of active SIS entry which is left set only if we scanned a
3439 -- procedure declaration and have not found the body. We could give
3440 -- an error message, but that really would be usurping the role of
3441 -- semantic analysis (this really is a missing body case).
3443 SIS_Entry_Active := False;
3445 end P_Declarative_Part;
3447 ----------------------------
3448 -- 3.11 Declarative Item --
3449 ----------------------------
3451 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
3453 -- Can return Error if a junk declaration is found, or Empty if no
3454 -- declaration is found (i.e. a token ending declarations, such as
3455 -- BEGIN or END is encountered).
3457 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
3458 -- then the scan is set past the next semicolon and Error is returned.
3460 procedure P_Declarative_Items
3465 Scan_State : Saved_Scan_State;
3468 if Style_Check then Style.Check_Indentation; end if;
3472 when Tok_Function =>
3474 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
3480 -- Check for loop (premature statement)
3482 Save_Scan_State (Scan_State);
3485 if Token = Tok_Identifier then
3486 Scan; -- past identifier
3488 if Token = Tok_In then
3489 Restore_Scan_State (Scan_State);
3490 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
3495 -- Not a loop, so must be rep clause
3497 Restore_Scan_State (Scan_State);
3498 Append (P_Representation_Clause, Decls);
3503 Append (P_Generic, Decls);
3506 when Tok_Identifier =>
3508 P_Identifier_Declarations (Decls, Done, In_Spec);
3512 Append (P_Package (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
3516 Append (P_Pragma, Decls);
3519 when Tok_Procedure =>
3521 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
3524 when Tok_Protected =>
3526 Scan; -- past PROTECTED
3527 Append (P_Protected, Decls);
3532 Append (P_Subtype_Declaration, Decls);
3538 Append (P_Task, Decls);
3543 Append (P_Type_Declaration, Decls);
3548 Append (P_Use_Clause, Decls);
3553 Error_Msg_SC ("WITH can only appear in context clause");
3556 -- BEGIN terminates the scan of a sequence of declarations unless
3557 -- there is a missing subprogram body, see section on handling
3558 -- semicolon in place of IS. We only treat the begin as satisfying
3559 -- the subprogram declaration if it falls in the expected column
3563 if SIS_Entry_Active and then Start_Column >= SIS_Ecol then
3565 -- Here we have the case where a BEGIN is encountered during
3566 -- declarations in a declarative part, or at the outer level,
3567 -- and there is a subprogram declaration outstanding for which
3568 -- no body has been supplied. This is the case where we assume
3569 -- that the semicolon in the subprogram declaration should
3570 -- really have been is. The active SIS entry describes the
3571 -- subprogram declaration. On return the declaration has been
3572 -- modified to become a body.
3575 Specification_Node : Node_Id;
3576 Decl_Node : Node_Id;
3577 Body_Node : Node_Id;
3580 -- First issue the error message. If we had a missing
3581 -- semicolon in the declaration, then change the message
3582 -- to <missing "is">
3584 if SIS_Missing_Semicolon_Message /= No_Error_Msg then
3585 Change_Error_Text -- Replace: "missing "";"" "
3586 (SIS_Missing_Semicolon_Message, "missing ""is""");
3588 -- Otherwise we saved the semicolon position, so complain
3591 Error_Msg (""";"" should be IS", SIS_Semicolon_Sloc);
3594 -- The next job is to fix up any declarations that occurred
3595 -- between the procedure header and the BEGIN. These got
3596 -- chained to the outer declarative region (immediately
3597 -- after the procedure declaration) and they should be
3598 -- chained to the subprogram itself, which is a body
3599 -- rather than a spec.
3601 Specification_Node := Specification (SIS_Declaration_Node);
3602 Change_Node (SIS_Declaration_Node, N_Subprogram_Body);
3603 Body_Node := SIS_Declaration_Node;
3604 Set_Specification (Body_Node, Specification_Node);
3605 Set_Declarations (Body_Node, New_List);
3608 Decl_Node := Remove_Next (Body_Node);
3609 exit when Decl_Node = Empty;
3610 Append (Decl_Node, Declarations (Body_Node));
3613 -- Now make the scope table entry for the Begin-End and
3617 Scope.Table (Scope.Last).Sloc := SIS_Sloc;
3618 Scope.Table (Scope.Last).Etyp := E_Name;
3619 Scope.Table (Scope.Last).Ecol := SIS_Ecol;
3620 Scope.Table (Scope.Last).Labl := SIS_Labl;
3621 Scope.Table (Scope.Last).Lreq := False;
3622 SIS_Entry_Active := False;
3624 Set_Handled_Statement_Sequence (Body_Node,
3625 P_Handled_Sequence_Of_Statements);
3626 End_Statements (Handled_Statement_Sequence (Body_Node));
3635 -- Normally an END terminates the scan for basic declarative
3636 -- items. The one exception is END RECORD, which is probably
3637 -- left over from some other junk.
3640 Save_Scan_State (Scan_State); -- at END
3643 if Token = Tok_Record then
3644 Error_Msg_SP ("no RECORD for this `end record`!");
3645 Scan; -- past RECORD
3649 Restore_Scan_State (Scan_State); -- to END
3653 -- The following tokens which can only be the start of a statement
3654 -- are considered to end a declarative part (i.e. we have a missing
3655 -- BEGIN situation). We are fairly conservative in making this
3656 -- judgment, because it is a real mess to go into statement mode
3657 -- prematurely in response to a junk declaration.
3672 -- But before we decide that it's a statement, let's check for
3673 -- a reserved word misused as an identifier.
3675 if Is_Reserved_Identifier then
3676 Save_Scan_State (Scan_State);
3677 Scan; -- past the token
3679 -- If reserved identifier not followed by colon or comma, then
3680 -- this is most likely an assignment statement to the bad id.
3682 if Token /= Tok_Colon and then Token /= Tok_Comma then
3683 Restore_Scan_State (Scan_State);
3684 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
3687 -- Otherwise we have a declaration of the bad id
3690 Restore_Scan_State (Scan_State);
3691 Scan_Reserved_Identifier (Force_Msg => True);
3692 P_Identifier_Declarations (Decls, Done, In_Spec);
3695 -- If not reserved identifier, then it's definitely a statement
3698 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
3702 -- The token RETURN may well also signal a missing BEGIN situation,
3703 -- however, we never let it end the declarative part, because it may
3704 -- also be part of a half-baked function declaration.
3707 Error_Msg_SC ("misplaced RETURN statement");
3710 -- PRIVATE definitely terminates the declarations in a spec,
3711 -- and is an error in a body.
3717 Error_Msg_SC ("PRIVATE not allowed in body");
3718 Scan; -- past PRIVATE
3721 -- An end of file definitely terminates the declarations!
3726 -- The remaining tokens do not end the scan, but cannot start a
3727 -- valid declaration, so we signal an error and resynchronize.
3728 -- But first check for misuse of a reserved identifier.
3732 -- Here we check for a reserved identifier
3734 if Is_Reserved_Identifier then
3735 Save_Scan_State (Scan_State);
3736 Scan; -- past the token
3738 if Token /= Tok_Colon and then Token /= Tok_Comma then
3739 Restore_Scan_State (Scan_State);
3740 Set_Declaration_Expected;
3743 Restore_Scan_State (Scan_State);
3744 Scan_Reserved_Identifier (Force_Msg => True);
3746 P_Identifier_Declarations (Decls, Done, In_Spec);
3750 Set_Declaration_Expected;
3755 -- To resynchronize after an error, we scan to the next semicolon and
3756 -- return with Done = False, indicating that there may still be more
3757 -- valid declarations to come.
3760 when Error_Resync =>
3761 Resync_Past_Semicolon;
3763 end P_Declarative_Items;
3765 ----------------------------------
3766 -- 3.11 Basic Declarative Item --
3767 ----------------------------------
3769 -- BASIC_DECLARATIVE_ITEM ::=
3770 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
3772 -- Scan zero or more basic declarative items
3774 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
3775 -- the scan pointer is repositioned past the next semicolon, and the scan
3776 -- for declarative items continues.
3778 function P_Basic_Declarative_Items return List_Id is
3785 -- Indicate no bad declarations detected yet in the current context:
3786 -- visible or private declarations of a package spec.
3788 Missing_Begin_Msg := No_Error_Msg;
3790 -- Get rid of active SIS entry from outer scope. This means we will
3791 -- miss some nested cases, but it doesn't seem worth the effort. See
3792 -- discussion in Par for further details
3794 SIS_Entry_Active := False;
3796 -- Loop to scan out declarations
3801 P_Declarative_Items (Decls, Done, In_Spec => True);
3805 -- Get rid of active SIS entry. This is set only if we have scanned a
3806 -- procedure declaration and have not found the body. We could give
3807 -- an error message, but that really would be usurping the role of
3808 -- semantic analysis (this really is a case of a missing body).
3810 SIS_Entry_Active := False;
3812 -- Test for assorted illegal declarations not diagnosed elsewhere.
3814 Decl := First (Decls);
3816 while Present (Decl) loop
3817 Kind := Nkind (Decl);
3819 -- Test for body scanned, not acceptable as basic decl item
3821 if Kind = N_Subprogram_Body or else
3822 Kind = N_Package_Body or else
3823 Kind = N_Task_Body or else
3824 Kind = N_Protected_Body
3827 ("proper body not allowed in package spec", Sloc (Decl));
3829 -- Test for body stub scanned, not acceptable as basic decl item
3831 elsif Kind in N_Body_Stub then
3833 ("body stub not allowed in package spec", Sloc (Decl));
3835 elsif Kind = N_Assignment_Statement then
3837 ("assignment statement not allowed in package spec",
3845 end P_Basic_Declarative_Items;
3851 -- For proper body, see below
3852 -- For body stub, see 10.1.3
3854 -----------------------
3855 -- 3.11 Proper Body --
3856 -----------------------
3858 -- Subprogram body is parsed by P_Subprogram (6.1)
3859 -- Package body is parsed by P_Package (7.1)
3860 -- Task body is parsed by P_Task (9.1)
3861 -- Protected body is parsed by P_Protected (9.4)
3863 ------------------------------
3864 -- Set_Declaration_Expected --
3865 ------------------------------
3867 procedure Set_Declaration_Expected is
3869 Error_Msg_SC ("declaration expected");
3871 if Missing_Begin_Msg = No_Error_Msg then
3872 Missing_Begin_Msg := Get_Msg_Id;
3874 end Set_Declaration_Expected;
3876 ----------------------
3877 -- Skip_Declaration --
3878 ----------------------
3880 procedure Skip_Declaration (S : List_Id) is
3881 Dummy_Done : Boolean;
3884 P_Declarative_Items (S, Dummy_Done, False);
3885 end Skip_Declaration;
3887 -----------------------------------------
3888 -- Statement_When_Declaration_Expected --
3889 -----------------------------------------
3891 procedure Statement_When_Declaration_Expected
3897 -- Case of second occurrence of statement in one declaration sequence
3899 if Missing_Begin_Msg /= No_Error_Msg then
3901 -- In the procedure spec case, just ignore it, we only give one
3902 -- message for the first occurrence, since otherwise we may get
3903 -- horrible cascading if BODY was missing in the header line.
3908 -- In the declarative part case, take a second statement as a sure
3909 -- sign that we really have a missing BEGIN, and end the declarative
3910 -- part now. Note that the caller will fix up the first message to
3911 -- say "missing BEGIN" so that's how the error will be signalled.
3918 -- Case of first occurrence of unexpected statement
3921 -- If we are in a package spec, then give message of statement
3922 -- not allowed in package spec. This message never gets changed.
3925 Error_Msg_SC ("statement not allowed in package spec");
3927 -- If in declarative part, then we give the message complaining
3928 -- about finding a statement when a declaration is expected. This
3929 -- gets changed to a complaint about a missing BEGIN if we later
3930 -- find that no BEGIN is present.
3933 Error_Msg_SC ("statement not allowed in declarative part");
3936 -- Capture message Id. This is used for two purposes, first to
3937 -- stop multiple messages, see test above, and second, to allow
3938 -- the replacement of the message in the declarative part case.
3940 Missing_Begin_Msg := Get_Msg_Id;
3943 -- In all cases except the case in which we decided to terminate the
3944 -- declaration sequence on a second error, we scan out the statement
3945 -- and append it to the list of declarations (note that the semantics
3946 -- can handle statements in a declaration list so if we proceed to
3947 -- call the semantic phase, all will be (reasonably) well!
3949 Append_List_To (Decls, P_Sequence_Of_Statements (SS_Unco));
3951 -- Done is set to False, since we want to continue the scan of
3952 -- declarations, hoping that this statement was a temporary glitch.
3953 -- If we indeed are now in the statement part (i.e. this was a missing
3954 -- BEGIN, then it's not terrible, we will simply keep calling this
3955 -- procedure to process the statements one by one, and then finally
3956 -- hit the missing BEGIN, which will clean up the error message.
3959 end Statement_When_Declaration_Expected;