1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 pragma Style_Checks (All_Checks);
27 -- Turn off subprogram body ordering check. Subprograms are in order
28 -- by RM section rather than alphabetical.
30 with Sinfo.CN; use Sinfo.CN;
40 -----------------------
41 -- Local Subprograms --
42 -----------------------
44 function P_Component_List return Node_Id;
45 function P_Defining_Character_Literal return Node_Id;
46 function P_Delta_Constraint return Node_Id;
47 function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id;
48 function P_Digits_Constraint return Node_Id;
49 function P_Discriminant_Association return Node_Id;
50 function P_Enumeration_Literal_Specification return Node_Id;
51 function P_Enumeration_Type_Definition return Node_Id;
52 function P_Fixed_Point_Definition return Node_Id;
53 function P_Floating_Point_Definition return Node_Id;
54 function P_Index_Or_Discriminant_Constraint return Node_Id;
55 function P_Real_Range_Specification_Opt return Node_Id;
56 function P_Subtype_Declaration return Node_Id;
57 function P_Type_Declaration return Node_Id;
58 function P_Modular_Type_Definition return Node_Id;
59 function P_Variant return Node_Id;
60 function P_Variant_Part return Node_Id;
62 procedure Check_Restricted_Expression (N : Node_Id);
63 -- Check that the expression N meets the Restricted_Expression syntax.
64 -- The syntax is as follows:
66 -- RESTRICTED_EXPRESSION ::=
67 -- RESTRICTED_RELATION {and RESTRICTED_RELATION}
68 -- | RESTRICTED_RELATION {and then RESTRICTED_RELATION}
69 -- | RESTRICTED_RELATION {or RESTRICTED_RELATION}
70 -- | RESTRICTED_RELATION {or else RESTRICTED_RELATION}
71 -- | RESTRICTED_RELATION {xor RESTRICTED_RELATION}
73 -- RESTRICTED_RELATION ::=
74 -- SIMPLE_EXPRESSION [RELATIONAL_OPERATOR SIMPLE_EXPRESSION]
76 -- This syntax is used for choices when extensions (and set notations)
77 -- are enabled, to remove the ambiguity of "when X in A | B". We consider
78 -- it very unlikely that this will ever arise in practice.
80 procedure P_Declarative_Items
84 -- Scans out a single declarative item, or, in the case of a declaration
85 -- with a list of identifiers, a list of declarations, one for each of the
86 -- identifiers in the list. The declaration or declarations scanned are
87 -- appended to the given list. Done indicates whether or not there may be
88 -- additional declarative items to scan. If Done is True, then a decision
89 -- has been made that there are no more items to scan. If Done is False,
90 -- then there may be additional declarations to scan. In_Spec is true if
91 -- we are scanning a package declaration, and is used to generate an
92 -- appropriate message if a statement is encountered in such a context.
94 procedure P_Identifier_Declarations
98 -- Scans out a set of declarations for an identifier or list of
99 -- identifiers, and appends them to the given list. The parameters have
100 -- the same significance as for P_Declarative_Items.
102 procedure Statement_When_Declaration_Expected
106 -- Called when a statement is found at a point where a declaration was
107 -- expected. The parameters are as described for P_Declarative_Items.
109 procedure Set_Declaration_Expected;
110 -- Posts a "declaration expected" error messages at the start of the
111 -- current token, and if this is the first such message issued, saves
112 -- the message id in Missing_Begin_Msg, for possible later replacement.
115 ---------------------------------
116 -- Check_Restricted_Expression --
117 ---------------------------------
119 procedure Check_Restricted_Expression (N : Node_Id) is
121 if Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor, N_And_Then, N_Or_Else) then
122 Check_Restricted_Expression (Left_Opnd (N));
123 Check_Restricted_Expression (Right_Opnd (N));
125 elsif Nkind_In (N, N_In, N_Not_In)
126 and then Paren_Count (N) = 0
128 Error_Msg_N -- CODEFIX???
129 ("|this expression must be parenthesized!", N);
131 ("\|since extensions (and set notation) are allowed", N);
133 end Check_Restricted_Expression;
139 function Init_Expr_Opt (P : Boolean := False) return Node_Id is
141 -- For colon, assume it means := unless it is at the end of
142 -- a line, in which case guess that it means a semicolon.
144 if Token = Tok_Colon then
145 if Token_Is_At_End_Of_Line then
150 -- Here if := or something that we will take as equivalent
152 elsif Token = Tok_Colon_Equal
153 or else Token = Tok_Equal
154 or else Token = Tok_Is
158 -- Another possibility. If we have a literal followed by a semicolon,
159 -- we assume that we have a missing colon-equal.
161 elsif Token in Token_Class_Literal then
163 Scan_State : Saved_Scan_State;
166 Save_Scan_State (Scan_State);
167 Scan; -- past literal or identifier
169 if Token = Tok_Semicolon then
170 Restore_Scan_State (Scan_State);
172 Restore_Scan_State (Scan_State);
177 -- Otherwise we definitely have no initialization expression
183 -- Merge here if we have an initialization expression
190 return P_Expression_No_Right_Paren;
194 ----------------------------
195 -- 3.1 Basic Declaration --
196 ----------------------------
198 -- Parsed by P_Basic_Declarative_Items (3.9)
200 ------------------------------
201 -- 3.1 Defining Identifier --
202 ------------------------------
204 -- DEFINING_IDENTIFIER ::= IDENTIFIER
206 -- Error recovery: can raise Error_Resync
208 function P_Defining_Identifier (C : Id_Check := None) return Node_Id is
209 Ident_Node : Node_Id;
212 -- Scan out the identifier. Note that this code is essentially identical
213 -- to P_Identifier, except that in the call to Scan_Reserved_Identifier
214 -- we set Force_Msg to True, since we want at least one message for each
215 -- separate declaration (but not use) of a reserved identifier.
217 if Token = Tok_Identifier then
219 -- Ada 2005 (AI-284): Compiling in Ada95 mode we warn that INTERFACE,
220 -- OVERRIDING, and SYNCHRONIZED are new reserved words. Note that
221 -- in the case where these keywords are misused in Ada 95 mode,
222 -- this routine will generally not be called at all.
224 if Ada_Version = Ada_95
225 and then Warn_On_Ada_2005_Compatibility
227 if Token_Name = Name_Overriding
228 or else Token_Name = Name_Synchronized
229 or else (Token_Name = Name_Interface
230 and then Prev_Token /= Tok_Pragma)
232 Error_Msg_N ("& is a reserved word in Ada 2005?", Token_Node);
236 -- If we have a reserved identifier, manufacture an identifier with
237 -- a corresponding name after posting an appropriate error message
239 elsif Is_Reserved_Identifier (C) then
240 Scan_Reserved_Identifier (Force_Msg => True);
242 -- Otherwise we have junk that cannot be interpreted as an identifier
245 T_Identifier; -- to give message
249 Ident_Node := Token_Node;
250 Scan; -- past the reserved identifier
252 -- If we already have a defining identifier, clean it out and make
253 -- a new clean identifier. This situation arises in some error cases
254 -- and we need to fix it.
256 if Nkind (Ident_Node) = N_Defining_Identifier then
258 Make_Identifier (Sloc (Ident_Node),
259 Chars => Chars (Ident_Node));
262 -- Change identifier to defining identifier if not in error
264 if Ident_Node /= Error then
265 Change_Identifier_To_Defining_Identifier (Ident_Node);
269 end P_Defining_Identifier;
271 -----------------------------
272 -- 3.2.1 Type Declaration --
273 -----------------------------
275 -- TYPE_DECLARATION ::=
276 -- FULL_TYPE_DECLARATION
277 -- | INCOMPLETE_TYPE_DECLARATION
278 -- | PRIVATE_TYPE_DECLARATION
279 -- | PRIVATE_EXTENSION_DECLARATION
281 -- FULL_TYPE_DECLARATION ::=
282 -- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION;
283 -- | CONCURRENT_TYPE_DECLARATION
285 -- INCOMPLETE_TYPE_DECLARATION ::=
286 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] [is tagged];
288 -- PRIVATE_TYPE_DECLARATION ::=
289 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
290 -- is [abstract] [tagged] [limited] private;
292 -- PRIVATE_EXTENSION_DECLARATION ::=
293 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
294 -- [abstract] [limited | synchronized]
295 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
298 -- TYPE_DEFINITION ::=
299 -- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
300 -- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
301 -- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
302 -- | DERIVED_TYPE_DEFINITION | INTERFACE_TYPE_DEFINITION
304 -- INTEGER_TYPE_DEFINITION ::=
305 -- SIGNED_INTEGER_TYPE_DEFINITION
306 -- MODULAR_TYPE_DEFINITION
308 -- INTERFACE_TYPE_DEFINITION ::=
309 -- [limited | task | protected | synchronized ] interface
310 -- [and INTERFACE_LIST]
312 -- Error recovery: can raise Error_Resync
314 -- Note: The processing for full type declaration, incomplete type
315 -- declaration, private type declaration and type definition is
316 -- included in this function. The processing for concurrent type
317 -- declarations is NOT here, but rather in chapter 9 (i.e. this
318 -- function handles only declarations starting with TYPE).
320 function P_Type_Declaration return Node_Id is
321 Abstract_Present : Boolean := False;
322 Abstract_Loc : Source_Ptr := No_Location;
324 Discr_List : List_Id;
325 Discr_Sloc : Source_Ptr;
327 Ident_Node : Node_Id;
328 Is_Derived_Iface : Boolean := False;
329 Type_Loc : Source_Ptr;
330 Type_Start_Col : Column_Number;
331 Unknown_Dis : Boolean;
333 Typedef_Node : Node_Id;
334 -- Normally holds type definition, except in the case of a private
335 -- extension declaration, in which case it holds the declaration itself
338 Type_Loc := Token_Ptr;
339 Type_Start_Col := Start_Column;
341 -- If we have TYPE, then proceed ahead and scan identifier
343 if Token = Tok_Type then
344 Type_Token_Location := Type_Loc;
346 Ident_Node := P_Defining_Identifier (C_Is);
348 -- Otherwise this is an error case
352 Type_Token_Location := Type_Loc;
353 Ident_Node := P_Defining_Identifier (C_Is);
356 Discr_Sloc := Token_Ptr;
358 if P_Unknown_Discriminant_Part_Opt then
360 Discr_List := No_List;
362 Unknown_Dis := False;
363 Discr_List := P_Known_Discriminant_Part_Opt;
366 -- Incomplete type declaration. We complete the processing for this
367 -- case here and return the resulting incomplete type declaration node
369 if Token = Tok_Semicolon then
371 Decl_Node := New_Node (N_Incomplete_Type_Declaration, Type_Loc);
372 Set_Defining_Identifier (Decl_Node, Ident_Node);
373 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
374 Set_Discriminant_Specifications (Decl_Node, Discr_List);
381 -- Full type declaration or private type declaration, must have IS
383 if Token = Tok_Equal then
385 Scan; -- past = used in place of IS
387 elsif Token = Tok_Renames then
388 Error_Msg_SC -- CODEFIX
389 ("RENAMES should be IS");
390 Scan; -- past RENAMES used in place of IS
396 -- First an error check, if we have two identifiers in a row, a likely
397 -- possibility is that the first of the identifiers is an incorrectly
400 if Token = Tok_Identifier then
402 SS : Saved_Scan_State;
406 Save_Scan_State (SS);
407 Scan; -- past initial identifier
408 I2 := (Token = Tok_Identifier);
409 Restore_Scan_State (SS);
413 (Bad_Spelling_Of (Tok_Abstract) or else
414 Bad_Spelling_Of (Tok_Access) or else
415 Bad_Spelling_Of (Tok_Aliased) or else
416 Bad_Spelling_Of (Tok_Constant))
423 -- Check for misuse of Ada 95 keyword abstract in Ada 83 mode
425 if Token_Name = Name_Abstract then
426 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
427 Check_95_Keyword (Tok_Abstract, Tok_New);
430 -- Check cases of misuse of ABSTRACT
432 if Token = Tok_Abstract then
433 Abstract_Present := True;
434 Abstract_Loc := Token_Ptr;
435 Scan; -- past ABSTRACT
437 -- Ada 2005 (AI-419): AARM 3.4 (2/2)
439 if (Ada_Version < Ada_05 and then Token = Tok_Limited)
440 or else Token = Tok_Private
441 or else Token = Tok_Record
442 or else Token = Tok_Null
444 Error_Msg_AP -- CODEFIX???
449 -- Check for misuse of Ada 95 keyword Tagged
451 if Token_Name = Name_Tagged then
452 Check_95_Keyword (Tok_Tagged, Tok_Private);
453 Check_95_Keyword (Tok_Tagged, Tok_Limited);
454 Check_95_Keyword (Tok_Tagged, Tok_Record);
457 -- Special check for misuse of Aliased
459 if Token = Tok_Aliased or else Token_Name = Name_Aliased then
460 Error_Msg_SC -- CODEFIX???
461 ("ALIASED not allowed in type definition");
462 Scan; -- past ALIASED
465 -- The following processing deals with either a private type declaration
466 -- or a full type declaration. In the private type case, we build the
467 -- N_Private_Type_Declaration node, setting its Tagged_Present and
468 -- Limited_Present flags, on encountering the Private keyword, and
469 -- leave Typedef_Node set to Empty. For the full type declaration
470 -- case, Typedef_Node gets set to the type definition.
472 Typedef_Node := Empty;
474 -- Switch on token following the IS. The loop normally runs once. It
475 -- only runs more than once if an error is detected, to try again after
476 -- detecting and fixing up the error.
482 Tok_Not => -- Ada 2005 (AI-231)
483 Typedef_Node := P_Access_Type_Definition;
488 Typedef_Node := P_Array_Type_Definition;
493 Typedef_Node := P_Fixed_Point_Definition;
498 Typedef_Node := P_Floating_Point_Definition;
505 when Tok_Integer_Literal =>
507 Typedef_Node := P_Signed_Integer_Type_Definition;
512 Typedef_Node := P_Record_Definition;
516 when Tok_Left_Paren =>
517 Typedef_Node := P_Enumeration_Type_Definition;
520 Make_Identifier (Token_Ptr,
521 Chars => Chars (Ident_Node));
522 Set_Comes_From_Source (End_Labl, False);
524 Set_End_Label (Typedef_Node, End_Labl);
529 Typedef_Node := P_Modular_Type_Definition;
534 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
536 if Nkind (Typedef_Node) = N_Derived_Type_Definition
537 and then Present (Record_Extension_Part (Typedef_Node))
540 Make_Identifier (Token_Ptr,
541 Chars => Chars (Ident_Node));
542 Set_Comes_From_Source (End_Labl, False);
545 (Record_Extension_Part (Typedef_Node), End_Labl);
552 Typedef_Node := P_Signed_Integer_Type_Definition;
557 Typedef_Node := P_Record_Definition;
560 Make_Identifier (Token_Ptr,
561 Chars => Chars (Ident_Node));
562 Set_Comes_From_Source (End_Labl, False);
564 Set_End_Label (Typedef_Node, End_Labl);
571 -- Ada 2005 (AI-326): If the words IS TAGGED appear, the type
572 -- is a tagged incomplete type.
574 if Ada_Version >= Ada_05
575 and then Token = Tok_Semicolon
580 New_Node (N_Incomplete_Type_Declaration, Type_Loc);
581 Set_Defining_Identifier (Decl_Node, Ident_Node);
582 Set_Tagged_Present (Decl_Node);
583 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
584 Set_Discriminant_Specifications (Decl_Node, Discr_List);
589 if Token = Tok_Abstract then
590 Error_Msg_SC -- CODEFIX
591 ("ABSTRACT must come before TAGGED");
592 Abstract_Present := True;
593 Abstract_Loc := Token_Ptr;
594 Scan; -- past ABSTRACT
597 if Token = Tok_Limited then
598 Scan; -- past LIMITED
600 -- TAGGED LIMITED PRIVATE case
602 if Token = Tok_Private then
604 New_Node (N_Private_Type_Declaration, Type_Loc);
605 Set_Tagged_Present (Decl_Node, True);
606 Set_Limited_Present (Decl_Node, True);
607 Scan; -- past PRIVATE
609 -- TAGGED LIMITED RECORD
612 Typedef_Node := P_Record_Definition;
613 Set_Tagged_Present (Typedef_Node, True);
614 Set_Limited_Present (Typedef_Node, True);
617 Make_Identifier (Token_Ptr,
618 Chars => Chars (Ident_Node));
619 Set_Comes_From_Source (End_Labl, False);
621 Set_End_Label (Typedef_Node, End_Labl);
627 if Token = Tok_Private then
629 New_Node (N_Private_Type_Declaration, Type_Loc);
630 Set_Tagged_Present (Decl_Node, True);
631 Scan; -- past PRIVATE
636 Typedef_Node := P_Record_Definition;
637 Set_Tagged_Present (Typedef_Node, True);
640 Make_Identifier (Token_Ptr,
641 Chars => Chars (Ident_Node));
642 Set_Comes_From_Source (End_Labl, False);
644 Set_End_Label (Typedef_Node, End_Labl);
652 Scan; -- past LIMITED
655 if Token = Tok_Tagged then
656 Error_Msg_SC -- CODEFIX
657 ("TAGGED must come before LIMITED");
660 elsif Token = Tok_Abstract then
661 Error_Msg_SC -- CODEFIX
662 ("ABSTRACT must come before LIMITED");
663 Scan; -- past ABSTRACT
670 -- LIMITED RECORD or LIMITED NULL RECORD
672 if Token = Tok_Record or else Token = Tok_Null then
673 if Ada_Version = Ada_83 then
675 ("(Ada 83) limited record declaration not allowed!");
677 -- In Ada2005, "abstract limited" can appear before "new",
678 -- but it cannot be part of an untagged record declaration.
680 elsif Abstract_Present
681 and then Prev_Token /= Tok_Tagged
683 Error_Msg_SP -- CODEFIX???
687 Typedef_Node := P_Record_Definition;
688 Set_Limited_Present (Typedef_Node, True);
690 -- Ada 2005 (AI-251): LIMITED INTERFACE
692 -- If we are compiling in Ada 83 or Ada 95 mode, "interface"
693 -- is not a reserved word but we force its analysis to
694 -- generate the corresponding usage error.
696 elsif Token = Tok_Interface
697 or else (Token = Tok_Identifier
698 and then Chars (Token_Node) = Name_Interface)
701 P_Interface_Type_Definition (Abstract_Present);
702 Abstract_Present := True;
703 Set_Limited_Present (Typedef_Node);
705 if Nkind (Typedef_Node) = N_Derived_Type_Definition then
706 Is_Derived_Iface := True;
709 -- Ada 2005 (AI-419): LIMITED NEW
711 elsif Token = Tok_New then
712 if Ada_Version < Ada_05 then
714 ("LIMITED in derived type is an Ada 2005 extension");
716 ("\unit must be compiled with -gnat05 switch");
719 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
720 Set_Limited_Present (Typedef_Node);
722 if Nkind (Typedef_Node) = N_Derived_Type_Definition
723 and then Present (Record_Extension_Part (Typedef_Node))
726 Make_Identifier (Token_Ptr,
727 Chars => Chars (Ident_Node));
728 Set_Comes_From_Source (End_Labl, False);
731 (Record_Extension_Part (Typedef_Node), End_Labl);
734 -- LIMITED PRIVATE is the only remaining possibility here
737 Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
738 Set_Limited_Present (Decl_Node, True);
739 T_Private; -- past PRIVATE (or complain if not there!)
745 -- Here we have an identifier after the IS, which is certainly
746 -- wrong and which might be one of several different mistakes.
748 when Tok_Identifier =>
750 -- First case, if identifier is on same line, then probably we
751 -- have something like "type X is Integer .." and the best
752 -- diagnosis is a missing NEW. Note: the missing new message
753 -- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl.
755 if not Token_Is_At_Start_Of_Line then
756 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
759 -- If the identifier is at the start of the line, and is in the
760 -- same column as the type declaration itself then we consider
761 -- that we had a missing type definition on the previous line
763 elsif Start_Column <= Type_Start_Col then
764 Error_Msg_AP ("type definition expected");
765 Typedef_Node := Error;
767 -- If the identifier is at the start of the line, and is in
768 -- a column to the right of the type declaration line, then we
769 -- may have something like:
774 -- and the best diagnosis is a missing record keyword
777 Typedef_Node := P_Record_Definition;
783 -- Ada 2005 (AI-251): INTERFACE
785 when Tok_Interface =>
786 Typedef_Node := P_Interface_Type_Definition (Abstract_Present);
787 Abstract_Present := True;
792 Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
793 Scan; -- past PRIVATE
797 -- Ada 2005 (AI-345): Protected, synchronized or task interface
798 -- or Ada 2005 (AI-443): Synchronized private extension.
805 Saved_Token : constant Token_Type := Token;
808 Scan; -- past TASK, PROTECTED or SYNCHRONIZED
810 -- Synchronized private extension
812 if Token = Tok_New then
813 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
815 if Saved_Token = Tok_Synchronized then
816 if Nkind (Typedef_Node) =
817 N_Derived_Type_Definition
819 Error_Msg_N -- CODEFIX???
820 ("SYNCHRONIZED not allowed for record extension",
823 Set_Synchronized_Present (Typedef_Node);
827 Error_Msg_SC ("invalid kind of private extension");
833 if Token /= Tok_Interface then
834 Error_Msg_SC -- CODEFIX???
835 ("NEW or INTERFACE expected");
839 P_Interface_Type_Definition (Abstract_Present);
840 Abstract_Present := True;
844 Set_Task_Present (Typedef_Node);
846 when Tok_Protected =>
847 Set_Protected_Present (Typedef_Node);
849 when Tok_Synchronized =>
850 Set_Synchronized_Present (Typedef_Node);
853 pragma Assert (False);
862 -- Anything else is an error
865 if Bad_Spelling_Of (Tok_Access)
867 Bad_Spelling_Of (Tok_Array)
869 Bad_Spelling_Of (Tok_Delta)
871 Bad_Spelling_Of (Tok_Digits)
873 Bad_Spelling_Of (Tok_Limited)
875 Bad_Spelling_Of (Tok_Private)
877 Bad_Spelling_Of (Tok_Range)
879 Bad_Spelling_Of (Tok_Record)
881 Bad_Spelling_Of (Tok_Tagged)
886 Error_Msg_AP ("type definition expected");
893 -- For the private type declaration case, the private type declaration
894 -- node has been built, with the Tagged_Present and Limited_Present
895 -- flags set as needed, and Typedef_Node is left set to Empty.
897 if No (Typedef_Node) then
898 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
899 Set_Abstract_Present (Decl_Node, Abstract_Present);
901 -- For a private extension declaration, Typedef_Node contains the
902 -- N_Private_Extension_Declaration node, which we now complete. Note
903 -- that the private extension declaration, unlike a full type
904 -- declaration, does permit unknown discriminants.
906 elsif Nkind (Typedef_Node) = N_Private_Extension_Declaration then
907 Decl_Node := Typedef_Node;
908 Set_Sloc (Decl_Node, Type_Loc);
909 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
910 Set_Abstract_Present (Typedef_Node, Abstract_Present);
912 -- In the full type declaration case, Typedef_Node has the type
913 -- definition and here is where we build the full type declaration
914 -- node. This is also where we check for improper use of an unknown
915 -- discriminant part (not allowed for full type declaration).
918 if Nkind (Typedef_Node) = N_Record_Definition
919 or else (Nkind (Typedef_Node) = N_Derived_Type_Definition
920 and then Present (Record_Extension_Part (Typedef_Node)))
921 or else Is_Derived_Iface
923 Set_Abstract_Present (Typedef_Node, Abstract_Present);
925 elsif Abstract_Present then
926 Error_Msg -- CODEFIX???
927 ("ABSTRACT not allowed here, ignored", Abstract_Loc);
930 Decl_Node := New_Node (N_Full_Type_Declaration, Type_Loc);
931 Set_Type_Definition (Decl_Node, Typedef_Node);
935 ("Full type declaration cannot have unknown discriminants",
940 -- Remaining processing is common for all three cases
942 Set_Defining_Identifier (Decl_Node, Ident_Node);
943 Set_Discriminant_Specifications (Decl_Node, Discr_List);
945 end P_Type_Declaration;
947 ----------------------------------
948 -- 3.2.1 Full Type Declaration --
949 ----------------------------------
951 -- Parsed by P_Type_Declaration (3.2.1)
953 ----------------------------
954 -- 3.2.1 Type Definition --
955 ----------------------------
957 -- Parsed by P_Type_Declaration (3.2.1)
959 --------------------------------
960 -- 3.2.2 Subtype Declaration --
961 --------------------------------
963 -- SUBTYPE_DECLARATION ::=
964 -- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION;
966 -- The caller has checked that the initial token is SUBTYPE
968 -- Error recovery: can raise Error_Resync
970 function P_Subtype_Declaration return Node_Id is
972 Not_Null_Present : Boolean := False;
975 Decl_Node := New_Node (N_Subtype_Declaration, Token_Ptr);
976 Scan; -- past SUBTYPE
977 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier (C_Is));
980 if Token = Tok_New then
981 Error_Msg_SC -- CODEFIX
982 ("NEW ignored (only allowed in type declaration)");
986 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
987 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
989 Set_Subtype_Indication
990 (Decl_Node, P_Subtype_Indication (Not_Null_Present));
993 end P_Subtype_Declaration;
995 -------------------------------
996 -- 3.2.2 Subtype Indication --
997 -------------------------------
999 -- SUBTYPE_INDICATION ::=
1000 -- [not null] SUBTYPE_MARK [CONSTRAINT]
1002 -- Error recovery: can raise Error_Resync
1004 function P_Null_Exclusion
1005 (Allow_Anonymous_In_95 : Boolean := False) return Boolean
1007 Not_Loc : constant Source_Ptr := Token_Ptr;
1008 -- Source position of "not", if present
1011 if Token /= Tok_Not then
1017 if Token = Tok_Null then
1020 -- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95,
1021 -- except in the case of anonymous access types.
1023 -- Allow_Anonymous_In_95 will be True if we're parsing a formal
1024 -- parameter or discriminant, which are the only places where
1025 -- anonymous access types occur in Ada 95. "Formal : not null
1026 -- access ..." is legal in Ada 95, whereas "Formal : not null
1027 -- Named_Access_Type" is not.
1029 if Ada_Version >= Ada_05
1030 or else (Ada_Version >= Ada_95
1031 and then Allow_Anonymous_In_95
1032 and then Token = Tok_Access)
1038 ("`NOT NULL` access type is an Ada 2005 extension", Not_Loc);
1040 ("\unit should be compiled with -gnat05 switch", Not_Loc);
1044 Error_Msg_SP -- CODEFIX???
1048 if Token = Tok_New then
1049 Error_Msg -- CODEFIX???
1050 ("`NOT NULL` comes after NEW, not before", Not_Loc);
1055 end P_Null_Exclusion;
1057 function P_Subtype_Indication
1058 (Not_Null_Present : Boolean := False) return Node_Id
1060 Type_Node : Node_Id;
1063 if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then
1064 Type_Node := P_Subtype_Mark;
1065 return P_Subtype_Indication (Type_Node, Not_Null_Present);
1068 -- Check for error of using record definition and treat it nicely,
1069 -- otherwise things are really messed up, so resynchronize.
1071 if Token = Tok_Record then
1072 Error_Msg_SC ("anonymous record definitions are not permitted");
1073 Discard_Junk_Node (P_Record_Definition);
1077 Error_Msg_AP ("subtype indication expected");
1081 end P_Subtype_Indication;
1083 -- The following function is identical except that it is called with
1084 -- the subtype mark already scanned out, and it scans out the constraint
1086 -- Error recovery: can raise Error_Resync
1088 function P_Subtype_Indication
1089 (Subtype_Mark : Node_Id;
1090 Not_Null_Present : Boolean := False) return Node_Id
1092 Indic_Node : Node_Id;
1093 Constr_Node : Node_Id;
1096 Constr_Node := P_Constraint_Opt;
1098 if No (Constr_Node) then
1099 return Subtype_Mark;
1101 if Not_Null_Present then
1102 Error_Msg_SP -- CODEFIX???
1103 ("`NOT NULL` not allowed if constraint given");
1106 Indic_Node := New_Node (N_Subtype_Indication, Sloc (Subtype_Mark));
1107 Set_Subtype_Mark (Indic_Node, Check_Subtype_Mark (Subtype_Mark));
1108 Set_Constraint (Indic_Node, Constr_Node);
1111 end P_Subtype_Indication;
1113 -------------------------
1114 -- 3.2.2 Subtype Mark --
1115 -------------------------
1117 -- SUBTYPE_MARK ::= subtype_NAME;
1119 -- Note: The subtype mark which appears after an IN or NOT IN
1120 -- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
1122 -- Error recovery: cannot raise Error_Resync
1124 function P_Subtype_Mark return Node_Id is
1126 return P_Subtype_Mark_Resync;
1128 when Error_Resync =>
1132 -- This routine differs from P_Subtype_Mark in that it insists that an
1133 -- identifier be present, and if it is not, it raises Error_Resync.
1135 -- Error recovery: can raise Error_Resync
1137 function P_Subtype_Mark_Resync return Node_Id is
1138 Type_Node : Node_Id;
1141 if Token = Tok_Access then
1142 Error_Msg_SC ("anonymous access type definition not allowed here");
1143 Scan; -- past ACCESS
1146 if Token = Tok_Array then
1147 Error_Msg_SC ("anonymous array definition not allowed here");
1148 Discard_Junk_Node (P_Array_Type_Definition);
1152 Type_Node := P_Qualified_Simple_Name_Resync;
1154 -- Check for a subtype mark attribute. The only valid possibilities
1155 -- are 'CLASS and 'BASE. Anything else is a definite error. We may
1156 -- as well catch it here.
1158 if Token = Tok_Apostrophe then
1159 return P_Subtype_Mark_Attribute (Type_Node);
1164 end P_Subtype_Mark_Resync;
1166 -- The following function is called to scan out a subtype mark attribute.
1167 -- The caller has already scanned out the subtype mark, which is passed in
1168 -- as the argument, and has checked that the current token is apostrophe.
1170 -- Only a special subclass of attributes, called type attributes
1171 -- (see Snames package) are allowed in this syntactic position.
1173 -- Note: if the apostrophe is followed by other than an identifier, then
1174 -- the input expression is returned unchanged, and the scan pointer is
1175 -- left pointing to the apostrophe.
1177 -- Error recovery: can raise Error_Resync
1179 function P_Subtype_Mark_Attribute (Type_Node : Node_Id) return Node_Id is
1180 Attr_Node : Node_Id := Empty;
1181 Scan_State : Saved_Scan_State;
1185 Prefix := Check_Subtype_Mark (Type_Node);
1187 if Prefix = Error then
1191 -- Loop through attributes appearing (more than one can appear as for
1192 -- for example in X'Base'Class). We are at an apostrophe on entry to
1193 -- this loop, and it runs once for each attribute parsed, with
1194 -- Prefix being the current possible prefix if it is an attribute.
1197 Save_Scan_State (Scan_State); -- at Apostrophe
1198 Scan; -- past apostrophe
1200 if Token /= Tok_Identifier then
1201 Restore_Scan_State (Scan_State); -- to apostrophe
1202 return Prefix; -- no attribute after all
1204 elsif not Is_Type_Attribute_Name (Token_Name) then
1206 ("attribute & may not be used in a subtype mark", Token_Node);
1211 Make_Attribute_Reference (Prev_Token_Ptr,
1213 Attribute_Name => Token_Name);
1214 Scan; -- past type attribute identifier
1217 exit when Token /= Tok_Apostrophe;
1218 Prefix := Attr_Node;
1221 -- Fall through here after scanning type attribute
1224 end P_Subtype_Mark_Attribute;
1226 -----------------------
1227 -- 3.2.2 Constraint --
1228 -----------------------
1230 -- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
1232 -- SCALAR_CONSTRAINT ::=
1233 -- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
1235 -- COMPOSITE_CONSTRAINT ::=
1236 -- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
1238 -- If no constraint is present, this function returns Empty
1240 -- Error recovery: can raise Error_Resync
1242 function P_Constraint_Opt return Node_Id is
1244 if Token = Tok_Range
1245 or else Bad_Spelling_Of (Tok_Range)
1247 return P_Range_Constraint;
1249 elsif Token = Tok_Digits
1250 or else Bad_Spelling_Of (Tok_Digits)
1252 return P_Digits_Constraint;
1254 elsif Token = Tok_Delta
1255 or else Bad_Spelling_Of (Tok_Delta)
1257 return P_Delta_Constraint;
1259 elsif Token = Tok_Left_Paren then
1260 return P_Index_Or_Discriminant_Constraint;
1262 elsif Token = Tok_In then
1264 return P_Constraint_Opt;
1269 end P_Constraint_Opt;
1271 ------------------------------
1272 -- 3.2.2 Scalar Constraint --
1273 ------------------------------
1275 -- Parsed by P_Constraint_Opt (3.2.2)
1277 ---------------------------------
1278 -- 3.2.2 Composite Constraint --
1279 ---------------------------------
1281 -- Parsed by P_Constraint_Opt (3.2.2)
1283 --------------------------------------------------------
1284 -- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
1285 --------------------------------------------------------
1287 -- This routine scans out a declaration starting with an identifier:
1289 -- OBJECT_DECLARATION ::=
1290 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1291 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION];
1292 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1293 -- ACCESS_DEFINITION [:= EXPRESSION];
1294 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1295 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1297 -- NUMBER_DECLARATION ::=
1298 -- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
1300 -- OBJECT_RENAMING_DECLARATION ::=
1301 -- DEFINING_IDENTIFIER :
1302 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME;
1303 -- | DEFINING_IDENTIFIER :
1304 -- ACCESS_DEFINITION renames object_NAME;
1306 -- EXCEPTION_RENAMING_DECLARATION ::=
1307 -- DEFINING_IDENTIFIER : exception renames exception_NAME;
1309 -- EXCEPTION_DECLARATION ::=
1310 -- DEFINING_IDENTIFIER_LIST : exception;
1312 -- Note that the ALIASED indication in an object declaration is
1313 -- marked by a flag in the parent node.
1315 -- The caller has checked that the initial token is an identifier
1317 -- The value returned is a list of declarations, one for each identifier
1318 -- in the list (as described in Sinfo, we always split up multiple
1319 -- declarations into the equivalent sequence of single declarations
1320 -- using the More_Ids and Prev_Ids flags to preserve the source).
1322 -- If the identifier turns out to be a probable statement rather than
1323 -- an identifier, then the scan is left pointing to the identifier and
1324 -- No_List is returned.
1326 -- Error recovery: can raise Error_Resync
1328 procedure P_Identifier_Declarations
1334 Decl_Node : Node_Id;
1335 Type_Node : Node_Id;
1336 Ident_Sloc : Source_Ptr;
1337 Scan_State : Saved_Scan_State;
1338 List_OK : Boolean := True;
1340 Init_Expr : Node_Id;
1341 Init_Loc : Source_Ptr;
1342 Con_Loc : Source_Ptr;
1343 Not_Null_Present : Boolean := False;
1345 Idents : array (Int range 1 .. 4096) of Entity_Id;
1346 -- Used to save identifiers in the identifier list. The upper bound
1347 -- of 4096 is expected to be infinite in practice, and we do not even
1348 -- bother to check if this upper bound is exceeded.
1350 Num_Idents : Nat := 1;
1351 -- Number of identifiers stored in Idents
1354 -- This procedure is called in renames cases to make sure that we do
1355 -- not have more than one identifier. If we do have more than one
1356 -- then an error message is issued (and the declaration is split into
1357 -- multiple declarations)
1359 function Token_Is_Renames return Boolean;
1360 -- Checks if current token is RENAMES, and if so, scans past it and
1361 -- returns True, otherwise returns False. Includes checking for some
1362 -- common error cases.
1368 procedure No_List is
1370 if Num_Idents > 1 then
1371 Error_Msg -- CODEFIX???
1372 ("identifier list not allowed for RENAMES",
1379 ----------------------
1380 -- Token_Is_Renames --
1381 ----------------------
1383 function Token_Is_Renames return Boolean is
1384 At_Colon : Saved_Scan_State;
1387 if Token = Tok_Colon then
1388 Save_Scan_State (At_Colon);
1390 Check_Misspelling_Of (Tok_Renames);
1392 if Token = Tok_Renames then
1393 Error_Msg_SP -- CODEFIX
1394 ("|extra "":"" ignored");
1395 Scan; -- past RENAMES
1398 Restore_Scan_State (At_Colon);
1403 Check_Misspelling_Of (Tok_Renames);
1405 if Token = Tok_Renames then
1406 Scan; -- past RENAMES
1412 end Token_Is_Renames;
1414 -- Start of processing for P_Identifier_Declarations
1417 Ident_Sloc := Token_Ptr;
1418 Save_Scan_State (Scan_State); -- at first identifier
1419 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
1421 -- If we have a colon after the identifier, then we can assume that
1422 -- this is in fact a valid identifier declaration and can steam ahead.
1424 if Token = Tok_Colon then
1427 -- If we have a comma, then scan out the list of identifiers
1429 elsif Token = Tok_Comma then
1430 while Comma_Present loop
1431 Num_Idents := Num_Idents + 1;
1432 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
1435 Save_Scan_State (Scan_State); -- at colon
1438 -- If we have identifier followed by := then we assume that what is
1439 -- really meant is an assignment statement. The assignment statement
1440 -- is scanned out and added to the list of declarations. An exception
1441 -- occurs if the := is followed by the keyword constant, in which case
1442 -- we assume it was meant to be a colon.
1444 elsif Token = Tok_Colon_Equal then
1447 if Token = Tok_Constant then
1448 Error_Msg_SP -- CODEFIX???
1452 Restore_Scan_State (Scan_State);
1453 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
1457 -- If we have an IS keyword, then assume the TYPE keyword was missing
1459 elsif Token = Tok_Is then
1460 Restore_Scan_State (Scan_State);
1461 Append_To (Decls, P_Type_Declaration);
1465 -- Otherwise we have an error situation
1468 Restore_Scan_State (Scan_State);
1470 -- First case is possible misuse of PROTECTED in Ada 83 mode. If
1471 -- so, fix the keyword and return to scan the protected declaration.
1473 if Token_Name = Name_Protected then
1474 Check_95_Keyword (Tok_Protected, Tok_Identifier);
1475 Check_95_Keyword (Tok_Protected, Tok_Type);
1476 Check_95_Keyword (Tok_Protected, Tok_Body);
1478 if Token = Tok_Protected then
1483 -- Check misspelling possibilities. If so, correct the misspelling
1484 -- and return to scan out the resulting declaration.
1486 elsif Bad_Spelling_Of (Tok_Function)
1487 or else Bad_Spelling_Of (Tok_Procedure)
1488 or else Bad_Spelling_Of (Tok_Package)
1489 or else Bad_Spelling_Of (Tok_Pragma)
1490 or else Bad_Spelling_Of (Tok_Protected)
1491 or else Bad_Spelling_Of (Tok_Generic)
1492 or else Bad_Spelling_Of (Tok_Subtype)
1493 or else Bad_Spelling_Of (Tok_Type)
1494 or else Bad_Spelling_Of (Tok_Task)
1495 or else Bad_Spelling_Of (Tok_Use)
1496 or else Bad_Spelling_Of (Tok_For)
1501 -- Otherwise we definitely have an ordinary identifier with a junk
1502 -- token after it. Just complain that we expect a declaration, and
1503 -- skip to a semicolon
1506 Set_Declaration_Expected;
1507 Resync_Past_Semicolon;
1513 -- Come here with an identifier list and colon scanned out. We now
1514 -- build the nodes for the declarative items. One node is built for
1515 -- each identifier in the list, with the type information being
1516 -- repeated by rescanning the appropriate section of source.
1518 -- First an error check, if we have two identifiers in a row, a likely
1519 -- possibility is that the first of the identifiers is an incorrectly
1522 if Token = Tok_Identifier then
1524 SS : Saved_Scan_State;
1528 Save_Scan_State (SS);
1529 Scan; -- past initial identifier
1530 I2 := (Token = Tok_Identifier);
1531 Restore_Scan_State (SS);
1535 (Bad_Spelling_Of (Tok_Access) or else
1536 Bad_Spelling_Of (Tok_Aliased) or else
1537 Bad_Spelling_Of (Tok_Constant))
1544 -- Loop through identifiers
1549 -- Check for some cases of misused Ada 95 keywords
1551 if Token_Name = Name_Aliased then
1552 Check_95_Keyword (Tok_Aliased, Tok_Array);
1553 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
1554 Check_95_Keyword (Tok_Aliased, Tok_Constant);
1559 if Token = Tok_Constant then
1560 Con_Loc := Token_Ptr;
1561 Scan; -- past CONSTANT
1563 -- Number declaration, initialization required
1565 Init_Expr := Init_Expr_Opt;
1567 if Present (Init_Expr) then
1568 if Not_Null_Present then
1569 Error_Msg_SP -- CODEFIX???
1570 ("`NOT NULL` not allowed in numeric expression");
1573 Decl_Node := New_Node (N_Number_Declaration, Ident_Sloc);
1574 Set_Expression (Decl_Node, Init_Expr);
1576 -- Constant object declaration
1579 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1580 Set_Constant_Present (Decl_Node, True);
1582 if Token_Name = Name_Aliased then
1583 Check_95_Keyword (Tok_Aliased, Tok_Array);
1584 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
1587 if Token = Tok_Aliased then
1588 Error_Msg_SC -- CODEFIX
1589 ("ALIASED should be before CONSTANT");
1590 Scan; -- past ALIASED
1591 Set_Aliased_Present (Decl_Node, True);
1594 if Token = Tok_Array then
1595 Set_Object_Definition
1596 (Decl_Node, P_Array_Type_Definition);
1599 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
1600 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1602 if Token = Tok_Access then
1603 if Ada_Version < Ada_05 then
1605 ("generalized use of anonymous access types " &
1606 "is an Ada 2005 extension");
1608 ("\unit must be compiled with -gnat05 switch");
1611 Set_Object_Definition
1612 (Decl_Node, P_Access_Definition (Not_Null_Present));
1614 Set_Object_Definition
1615 (Decl_Node, P_Subtype_Indication (Not_Null_Present));
1619 if Token = Tok_Renames then
1620 Error_Msg -- CODEFIX???
1621 ("CONSTANT not permitted in renaming declaration",
1623 Scan; -- Past renames
1624 Discard_Junk_Node (P_Name);
1630 elsif Token = Tok_Exception then
1631 Scan; -- past EXCEPTION
1633 if Token_Is_Renames then
1636 New_Node (N_Exception_Renaming_Declaration, Ident_Sloc);
1637 Set_Name (Decl_Node, P_Qualified_Simple_Name_Resync);
1640 Decl_Node := New_Node (N_Exception_Declaration, Prev_Token_Ptr);
1643 -- Aliased case (note that an object definition is required)
1645 elsif Token = Tok_Aliased then
1646 Scan; -- past ALIASED
1647 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1648 Set_Aliased_Present (Decl_Node, True);
1650 if Token = Tok_Constant then
1651 Scan; -- past CONSTANT
1652 Set_Constant_Present (Decl_Node, True);
1655 if Token = Tok_Array then
1656 Set_Object_Definition
1657 (Decl_Node, P_Array_Type_Definition);
1660 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
1661 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1663 -- Access definition (AI-406) or subtype indication
1665 if Token = Tok_Access then
1666 if Ada_Version < Ada_05 then
1668 ("generalized use of anonymous access types " &
1669 "is an Ada 2005 extension");
1671 ("\unit must be compiled with -gnat05 switch");
1674 Set_Object_Definition
1675 (Decl_Node, P_Access_Definition (Not_Null_Present));
1677 Set_Object_Definition
1678 (Decl_Node, P_Subtype_Indication (Not_Null_Present));
1684 elsif Token = Tok_Array then
1685 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1686 Set_Object_Definition (Decl_Node, P_Array_Type_Definition);
1688 -- Ada 2005 (AI-254, AI-406)
1690 elsif Token = Tok_Not then
1692 -- OBJECT_DECLARATION ::=
1693 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1694 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION];
1695 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1696 -- ACCESS_DEFINITION [:= EXPRESSION];
1698 -- OBJECT_RENAMING_DECLARATION ::=
1699 -- DEFINING_IDENTIFIER :
1700 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME;
1701 -- | DEFINING_IDENTIFIER :
1702 -- ACCESS_DEFINITION renames object_NAME;
1704 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/423)
1706 if Token = Tok_Access then
1707 if Ada_Version < Ada_05 then
1709 ("generalized use of anonymous access types " &
1710 "is an Ada 2005 extension");
1711 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1714 Acc_Node := P_Access_Definition (Not_Null_Present);
1716 if Token /= Tok_Renames then
1717 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1718 Set_Object_Definition (Decl_Node, Acc_Node);
1721 Scan; -- past renames
1724 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1725 Set_Access_Definition (Decl_Node, Acc_Node);
1726 Set_Name (Decl_Node, P_Name);
1730 Type_Node := P_Subtype_Mark;
1732 -- Object renaming declaration
1734 if Token_Is_Renames then
1735 if Ada_Version < Ada_05 then
1736 Error_Msg_SP -- CODEFIX???
1737 ("`NOT NULL` not allowed in object renaming");
1740 -- Ada 2005 (AI-423): Object renaming declaration with
1741 -- a null exclusion.
1746 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1747 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1748 Set_Subtype_Mark (Decl_Node, Type_Node);
1749 Set_Name (Decl_Node, P_Name);
1752 -- Object declaration
1755 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1756 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1757 Set_Object_Definition
1759 P_Subtype_Indication (Type_Node, Not_Null_Present));
1761 -- RENAMES at this point means that we had the combination
1762 -- of a constraint on the Type_Node and renames, which is
1765 if Token_Is_Renames then
1766 Error_Msg_N -- CODEFIX???
1767 ("constraint not allowed in object renaming "
1769 Constraint (Object_Definition (Decl_Node)));
1775 -- Ada 2005 (AI-230): Access Definition case
1777 elsif Token = Tok_Access then
1778 if Ada_Version < Ada_05 then
1780 ("generalized use of anonymous access types " &
1781 "is an Ada 2005 extension");
1782 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1785 Acc_Node := P_Access_Definition (Null_Exclusion_Present => False);
1787 -- Object declaration with access definition, or renaming
1789 if Token /= Tok_Renames then
1790 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1791 Set_Object_Definition (Decl_Node, Acc_Node);
1794 Scan; -- past renames
1797 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1798 Set_Access_Definition (Decl_Node, Acc_Node);
1799 Set_Name (Decl_Node, P_Name);
1802 -- Subtype indication case
1805 Type_Node := P_Subtype_Mark;
1807 -- Object renaming declaration
1809 if Token_Is_Renames then
1812 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1813 Set_Subtype_Mark (Decl_Node, Type_Node);
1814 Set_Name (Decl_Node, P_Name);
1816 -- Object declaration
1819 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1820 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1821 Set_Object_Definition
1823 P_Subtype_Indication (Type_Node, Not_Null_Present));
1825 -- RENAMES at this point means that we had the combination of
1826 -- a constraint on the Type_Node and renames, which is illegal
1828 if Token_Is_Renames then
1829 Error_Msg_N -- CODEFIX???
1830 ("constraint not allowed in object renaming declaration",
1831 Constraint (Object_Definition (Decl_Node)));
1837 -- Scan out initialization, allowed only for object declaration
1839 Init_Loc := Token_Ptr;
1840 Init_Expr := Init_Expr_Opt;
1842 if Present (Init_Expr) then
1843 if Nkind (Decl_Node) = N_Object_Declaration then
1844 Set_Expression (Decl_Node, Init_Expr);
1845 Set_Has_Init_Expression (Decl_Node);
1847 Error_Msg ("initialization not allowed here", Init_Loc);
1852 Set_Defining_Identifier (Decl_Node, Idents (Ident));
1855 if Ident < Num_Idents then
1856 Set_More_Ids (Decl_Node, True);
1860 Set_Prev_Ids (Decl_Node, True);
1864 Append (Decl_Node, Decls);
1865 exit Ident_Loop when Ident = Num_Idents;
1866 Restore_Scan_State (Scan_State);
1869 end loop Ident_Loop;
1872 end P_Identifier_Declarations;
1874 -------------------------------
1875 -- 3.3.1 Object Declaration --
1876 -------------------------------
1878 -- OBJECT DECLARATION ::=
1879 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1880 -- SUBTYPE_INDICATION [:= EXPRESSION];
1881 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1882 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1883 -- | SINGLE_TASK_DECLARATION
1884 -- | SINGLE_PROTECTED_DECLARATION
1886 -- Cases starting with TASK are parsed by P_Task (9.1)
1887 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1888 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1890 -------------------------------------
1891 -- 3.3.1 Defining Identifier List --
1892 -------------------------------------
1894 -- DEFINING_IDENTIFIER_LIST ::=
1895 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1897 -- Always parsed by the construct in which it appears. See special
1898 -- section on "Handling of Defining Identifier Lists" in this unit.
1900 -------------------------------
1901 -- 3.3.2 Number Declaration --
1902 -------------------------------
1904 -- Parsed by P_Identifier_Declarations (3.3)
1906 -------------------------------------------------------------------------
1907 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
1908 -------------------------------------------------------------------------
1910 -- DERIVED_TYPE_DEFINITION ::=
1911 -- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
1912 -- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
1914 -- PRIVATE_EXTENSION_DECLARATION ::=
1915 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
1916 -- [abstract] [limited | synchronized]
1917 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
1920 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
1922 -- The caller has already scanned out the part up to the NEW, and Token
1923 -- either contains Tok_New (or ought to, if it doesn't this procedure
1924 -- will post an appropriate "NEW expected" message).
1926 -- Note: the caller is responsible for filling in the Sloc field of
1927 -- the returned node in the private extension declaration case as
1928 -- well as the stuff relating to the discriminant part.
1930 -- Error recovery: can raise Error_Resync;
1932 function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id is
1933 Typedef_Node : Node_Id;
1934 Typedecl_Node : Node_Id;
1935 Not_Null_Present : Boolean := False;
1938 Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr);
1940 if Ada_Version < Ada_05
1941 and then Token = Tok_Identifier
1942 and then Token_Name = Name_Interface
1945 ("abstract interface is an Ada 2005 extension");
1946 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1951 if Token = Tok_Abstract then
1952 Error_Msg_SC -- CODEFIX
1953 ("ABSTRACT must come before NEW, not after");
1957 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
1958 Set_Null_Exclusion_Present (Typedef_Node, Not_Null_Present);
1959 Set_Subtype_Indication (Typedef_Node,
1960 P_Subtype_Indication (Not_Null_Present));
1962 -- Ada 2005 (AI-251): Deal with interfaces
1964 if Token = Tok_And then
1967 if Ada_Version < Ada_05 then
1969 ("abstract interface is an Ada 2005 extension");
1970 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1973 Set_Interface_List (Typedef_Node, New_List);
1976 Append (P_Qualified_Simple_Name, Interface_List (Typedef_Node));
1977 exit when Token /= Tok_And;
1981 if Token /= Tok_With then
1982 Error_Msg_SC -- CODEFIX???
1988 -- Deal with record extension, note that we assume that a WITH is
1989 -- missing in the case of "type X is new Y record ..." or in the
1990 -- case of "type X is new Y null record".
1993 or else Token = Tok_Record
1994 or else Token = Tok_Null
1996 T_With; -- past WITH or give error message
1998 if Token = Tok_Limited then
1999 Error_Msg_SC -- CODEFIX???
2000 ("LIMITED keyword not allowed in private extension");
2001 Scan; -- ignore LIMITED
2004 -- Private extension declaration
2006 if Token = Tok_Private then
2007 Scan; -- past PRIVATE
2009 -- Throw away the type definition node and build the type
2010 -- declaration node. Note the caller must set the Sloc,
2011 -- Discriminant_Specifications, Unknown_Discriminants_Present,
2012 -- and Defined_Identifier fields in the returned node.
2015 Make_Private_Extension_Declaration (No_Location,
2016 Defining_Identifier => Empty,
2017 Subtype_Indication => Subtype_Indication (Typedef_Node),
2018 Abstract_Present => Abstract_Present (Typedef_Node),
2019 Interface_List => Interface_List (Typedef_Node));
2021 return Typedecl_Node;
2023 -- Derived type definition with record extension part
2026 Set_Record_Extension_Part (Typedef_Node, P_Record_Definition);
2027 return Typedef_Node;
2030 -- Derived type definition with no record extension part
2033 return Typedef_Node;
2035 end P_Derived_Type_Def_Or_Private_Ext_Decl;
2037 ---------------------------
2038 -- 3.5 Range Constraint --
2039 ---------------------------
2041 -- RANGE_CONSTRAINT ::= range RANGE
2043 -- The caller has checked that the initial token is RANGE
2045 -- Error recovery: cannot raise Error_Resync
2047 function P_Range_Constraint return Node_Id is
2048 Range_Node : Node_Id;
2051 Range_Node := New_Node (N_Range_Constraint, Token_Ptr);
2053 Set_Range_Expression (Range_Node, P_Range);
2055 end P_Range_Constraint;
2062 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2064 -- Note: the range that appears in a membership test is parsed by
2065 -- P_Range_Or_Subtype_Mark (3.5).
2067 -- Error recovery: cannot raise Error_Resync
2069 function P_Range return Node_Id is
2070 Expr_Node : Node_Id;
2071 Range_Node : Node_Id;
2074 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
2076 if Expr_Form = EF_Range_Attr then
2079 elsif Token = Tok_Dot_Dot then
2080 Range_Node := New_Node (N_Range, Token_Ptr);
2081 Set_Low_Bound (Range_Node, Expr_Node);
2083 Expr_Node := P_Expression;
2084 Check_Simple_Expression (Expr_Node);
2085 Set_High_Bound (Range_Node, Expr_Node);
2088 -- Anything else is an error
2091 T_Dot_Dot; -- force missing .. message
2096 ----------------------------------
2097 -- 3.5 P_Range_Or_Subtype_Mark --
2098 ----------------------------------
2101 -- RANGE_ATTRIBUTE_REFERENCE
2102 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2104 -- This routine scans out the range or subtype mark that forms the right
2105 -- operand of a membership test (it is not used in any other contexts, and
2106 -- error messages are specialized with this knowledge in mind).
2108 -- Note: as documented in the Sinfo interface, although the syntax only
2109 -- allows a subtype mark, we in fact allow any simple expression to be
2110 -- returned from this routine. The semantics is responsible for issuing
2111 -- an appropriate message complaining if the argument is not a name.
2112 -- This simplifies the coding and error recovery processing in the
2113 -- parser, and in any case it is preferable not to consider this a
2114 -- syntax error and to continue with the semantic analysis.
2116 -- Error recovery: cannot raise Error_Resync
2118 function P_Range_Or_Subtype_Mark
2119 (Allow_Simple_Expression : Boolean := False) return Node_Id
2121 Expr_Node : Node_Id;
2122 Range_Node : Node_Id;
2123 Save_Loc : Source_Ptr;
2125 -- Start of processing for P_Range_Or_Subtype_Mark
2128 -- Save location of possible junk parentheses
2130 Save_Loc := Token_Ptr;
2132 -- Scan out either a simple expression or a range (this accepts more
2133 -- than is legal here, but as explained above, we like to allow more
2134 -- with a proper diagnostic, and in the case of a membership operation
2135 -- where sets are allowed, a simple expression is permissible anyway.
2137 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
2141 if Expr_Form = EF_Range_Attr then
2144 -- Simple_Expression .. Simple_Expression
2146 elsif Token = Tok_Dot_Dot then
2147 Check_Simple_Expression (Expr_Node);
2148 Range_Node := New_Node (N_Range, Token_Ptr);
2149 Set_Low_Bound (Range_Node, Expr_Node);
2151 Set_High_Bound (Range_Node, P_Simple_Expression);
2154 -- Case of subtype mark (optionally qualified simple name or an
2155 -- attribute whose prefix is an optionally qualified simple name)
2157 elsif Expr_Form = EF_Simple_Name
2158 or else Nkind (Expr_Node) = N_Attribute_Reference
2160 -- Check for error of range constraint after a subtype mark
2162 if Token = Tok_Range then
2163 Error_Msg_SC ("range constraint not allowed in membership test");
2167 -- Check for error of DIGITS or DELTA after a subtype mark
2169 elsif Token = Tok_Digits or else Token = Tok_Delta then
2171 ("accuracy definition not allowed in membership test");
2172 Scan; -- past DIGITS or DELTA
2175 -- Attribute reference, may or may not be OK, but in any case we
2178 elsif Token = Tok_Apostrophe then
2179 return P_Subtype_Mark_Attribute (Expr_Node);
2181 -- OK case of simple name, just return it
2187 -- Simple expression case
2189 elsif Expr_Form = EF_Simple and then Allow_Simple_Expression then
2192 -- Here we have some kind of error situation. Check for junk parens
2193 -- then return what we have, caller will deal with other errors.
2196 if Nkind (Expr_Node) in N_Subexpr
2197 and then Paren_Count (Expr_Node) /= 0
2199 Error_Msg -- CODEFIX???
2200 ("|parentheses not allowed for subtype mark", Save_Loc);
2201 Set_Paren_Count (Expr_Node, 0);
2206 end P_Range_Or_Subtype_Mark;
2208 ----------------------------------------
2209 -- 3.5.1 Enumeration Type Definition --
2210 ----------------------------------------
2212 -- ENUMERATION_TYPE_DEFINITION ::=
2213 -- (ENUMERATION_LITERAL_SPECIFICATION
2214 -- {, ENUMERATION_LITERAL_SPECIFICATION})
2216 -- The caller has already scanned out the TYPE keyword
2218 -- Error recovery: can raise Error_Resync;
2220 function P_Enumeration_Type_Definition return Node_Id is
2221 Typedef_Node : Node_Id;
2224 Typedef_Node := New_Node (N_Enumeration_Type_Definition, Token_Ptr);
2225 Set_Literals (Typedef_Node, New_List);
2230 Append (P_Enumeration_Literal_Specification, Literals (Typedef_Node));
2231 exit when not Comma_Present;
2235 return Typedef_Node;
2236 end P_Enumeration_Type_Definition;
2238 ----------------------------------------------
2239 -- 3.5.1 Enumeration Literal Specification --
2240 ----------------------------------------------
2242 -- ENUMERATION_LITERAL_SPECIFICATION ::=
2243 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
2245 -- Error recovery: can raise Error_Resync
2247 function P_Enumeration_Literal_Specification return Node_Id is
2249 if Token = Tok_Char_Literal then
2250 return P_Defining_Character_Literal;
2252 return P_Defining_Identifier (C_Comma_Right_Paren);
2254 end P_Enumeration_Literal_Specification;
2256 ---------------------------------------
2257 -- 3.5.1 Defining_Character_Literal --
2258 ---------------------------------------
2260 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
2262 -- Error recovery: cannot raise Error_Resync
2264 -- The caller has checked that the current token is a character literal
2266 function P_Defining_Character_Literal return Node_Id is
2267 Literal_Node : Node_Id;
2270 Literal_Node := Token_Node;
2271 Change_Character_Literal_To_Defining_Character_Literal (Literal_Node);
2272 Scan; -- past character literal
2273 return Literal_Node;
2274 end P_Defining_Character_Literal;
2276 ------------------------------------
2277 -- 3.5.4 Integer Type Definition --
2278 ------------------------------------
2280 -- Parsed by P_Type_Declaration (3.2.1)
2282 -------------------------------------------
2283 -- 3.5.4 Signed Integer Type Definition --
2284 -------------------------------------------
2286 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
2287 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2289 -- Normally the initial token on entry is RANGE, but in some
2290 -- error conditions, the range token was missing and control is
2291 -- passed with Token pointing to first token of the first expression.
2293 -- Error recovery: cannot raise Error_Resync
2295 function P_Signed_Integer_Type_Definition return Node_Id is
2296 Typedef_Node : Node_Id;
2297 Expr_Node : Node_Id;
2300 Typedef_Node := New_Node (N_Signed_Integer_Type_Definition, Token_Ptr);
2302 if Token = Tok_Range then
2306 Expr_Node := P_Expression;
2307 Check_Simple_Expression (Expr_Node);
2308 Set_Low_Bound (Typedef_Node, Expr_Node);
2310 Expr_Node := P_Expression;
2311 Check_Simple_Expression (Expr_Node);
2312 Set_High_Bound (Typedef_Node, Expr_Node);
2313 return Typedef_Node;
2314 end P_Signed_Integer_Type_Definition;
2316 ------------------------------------
2317 -- 3.5.4 Modular Type Definition --
2318 ------------------------------------
2320 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
2322 -- The caller has checked that the initial token is MOD
2324 -- Error recovery: cannot raise Error_Resync
2326 function P_Modular_Type_Definition return Node_Id is
2327 Typedef_Node : Node_Id;
2330 if Ada_Version = Ada_83 then
2331 Error_Msg_SC ("(Ada 83): modular types not allowed");
2334 Typedef_Node := New_Node (N_Modular_Type_Definition, Token_Ptr);
2336 Set_Expression (Typedef_Node, P_Expression_No_Right_Paren);
2338 -- Handle mod L..R cleanly
2340 if Token = Tok_Dot_Dot then
2341 Error_Msg_SC ("range not allowed for modular type");
2343 Set_Expression (Typedef_Node, P_Expression_No_Right_Paren);
2346 return Typedef_Node;
2347 end P_Modular_Type_Definition;
2349 ---------------------------------
2350 -- 3.5.6 Real Type Definition --
2351 ---------------------------------
2353 -- Parsed by P_Type_Declaration (3.2.1)
2355 --------------------------------------
2356 -- 3.5.7 Floating Point Definition --
2357 --------------------------------------
2359 -- FLOATING_POINT_DEFINITION ::=
2360 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2362 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
2364 -- The caller has checked that the initial token is DIGITS
2366 -- Error recovery: cannot raise Error_Resync
2368 function P_Floating_Point_Definition return Node_Id is
2369 Digits_Loc : constant Source_Ptr := Token_Ptr;
2371 Expr_Node : Node_Id;
2374 Scan; -- past DIGITS
2375 Expr_Node := P_Expression_No_Right_Paren;
2376 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2378 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
2380 if Token = Tok_Delta then
2381 Error_Msg_SC -- CODEFIX
2382 ("|DELTA must come before DIGITS");
2383 Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Digits_Loc);
2385 Set_Delta_Expression (Def_Node, P_Expression_No_Right_Paren);
2387 -- OK floating-point definition
2390 Def_Node := New_Node (N_Floating_Point_Definition, Digits_Loc);
2393 Set_Digits_Expression (Def_Node, Expr_Node);
2394 Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt);
2396 end P_Floating_Point_Definition;
2398 -------------------------------------
2399 -- 3.5.7 Real Range Specification --
2400 -------------------------------------
2402 -- REAL_RANGE_SPECIFICATION ::=
2403 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2405 -- Error recovery: cannot raise Error_Resync
2407 function P_Real_Range_Specification_Opt return Node_Id is
2408 Specification_Node : Node_Id;
2409 Expr_Node : Node_Id;
2412 if Token = Tok_Range then
2413 Specification_Node :=
2414 New_Node (N_Real_Range_Specification, Token_Ptr);
2416 Expr_Node := P_Expression_No_Right_Paren;
2417 Check_Simple_Expression (Expr_Node);
2418 Set_Low_Bound (Specification_Node, Expr_Node);
2420 Expr_Node := P_Expression_No_Right_Paren;
2421 Check_Simple_Expression (Expr_Node);
2422 Set_High_Bound (Specification_Node, Expr_Node);
2423 return Specification_Node;
2427 end P_Real_Range_Specification_Opt;
2429 -----------------------------------
2430 -- 3.5.9 Fixed Point Definition --
2431 -----------------------------------
2433 -- FIXED_POINT_DEFINITION ::=
2434 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
2436 -- ORDINARY_FIXED_POINT_DEFINITION ::=
2437 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
2439 -- DECIMAL_FIXED_POINT_DEFINITION ::=
2440 -- delta static_EXPRESSION
2441 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2443 -- The caller has checked that the initial token is DELTA
2445 -- Error recovery: cannot raise Error_Resync
2447 function P_Fixed_Point_Definition return Node_Id is
2448 Delta_Node : Node_Id;
2449 Delta_Loc : Source_Ptr;
2451 Expr_Node : Node_Id;
2454 Delta_Loc := Token_Ptr;
2456 Delta_Node := P_Expression_No_Right_Paren;
2457 Check_Simple_Expression_In_Ada_83 (Delta_Node);
2459 if Token = Tok_Digits then
2460 if Ada_Version = Ada_83 then
2461 Error_Msg_SC ("(Ada 83) decimal fixed type not allowed!");
2464 Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Delta_Loc);
2465 Scan; -- past DIGITS
2466 Expr_Node := P_Expression_No_Right_Paren;
2467 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2468 Set_Digits_Expression (Def_Node, Expr_Node);
2471 Def_Node := New_Node (N_Ordinary_Fixed_Point_Definition, Delta_Loc);
2473 -- Range is required in ordinary fixed point case
2475 if Token /= Tok_Range then
2476 Error_Msg_AP ("range must be given for fixed-point type");
2481 Set_Delta_Expression (Def_Node, Delta_Node);
2482 Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt);
2484 end P_Fixed_Point_Definition;
2486 --------------------------------------------
2487 -- 3.5.9 Ordinary Fixed Point Definition --
2488 --------------------------------------------
2490 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2492 -------------------------------------------
2493 -- 3.5.9 Decimal Fixed Point Definition --
2494 -------------------------------------------
2496 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2498 ------------------------------
2499 -- 3.5.9 Digits Constraint --
2500 ------------------------------
2502 -- DIGITS_CONSTRAINT ::=
2503 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2505 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2507 -- The caller has checked that the initial token is DIGITS
2509 function P_Digits_Constraint return Node_Id is
2510 Constraint_Node : Node_Id;
2511 Expr_Node : Node_Id;
2514 Constraint_Node := New_Node (N_Digits_Constraint, Token_Ptr);
2515 Scan; -- past DIGITS
2516 Expr_Node := P_Expression;
2517 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2518 Set_Digits_Expression (Constraint_Node, Expr_Node);
2520 if Token = Tok_Range then
2521 Set_Range_Constraint (Constraint_Node, P_Range_Constraint);
2524 return Constraint_Node;
2525 end P_Digits_Constraint;
2527 -----------------------------
2528 -- 3.5.9 Delta Constraint --
2529 -----------------------------
2531 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2533 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2535 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2537 -- The caller has checked that the initial token is DELTA
2539 -- Error recovery: cannot raise Error_Resync
2541 function P_Delta_Constraint return Node_Id is
2542 Constraint_Node : Node_Id;
2543 Expr_Node : Node_Id;
2546 Constraint_Node := New_Node (N_Delta_Constraint, Token_Ptr);
2548 Expr_Node := P_Expression;
2549 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2550 Set_Delta_Expression (Constraint_Node, Expr_Node);
2552 if Token = Tok_Range then
2553 Set_Range_Constraint (Constraint_Node, P_Range_Constraint);
2556 return Constraint_Node;
2557 end P_Delta_Constraint;
2559 --------------------------------
2560 -- 3.6 Array Type Definition --
2561 --------------------------------
2563 -- ARRAY_TYPE_DEFINITION ::=
2564 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2566 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2567 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2568 -- COMPONENT_DEFINITION
2570 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2572 -- CONSTRAINED_ARRAY_DEFINITION ::=
2573 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2574 -- COMPONENT_DEFINITION
2576 -- DISCRETE_SUBTYPE_DEFINITION ::=
2577 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2579 -- COMPONENT_DEFINITION ::=
2580 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2582 -- The caller has checked that the initial token is ARRAY
2584 -- Error recovery: can raise Error_Resync
2586 function P_Array_Type_Definition return Node_Id is
2587 Array_Loc : Source_Ptr;
2588 CompDef_Node : Node_Id;
2590 Not_Null_Present : Boolean := False;
2591 Subs_List : List_Id;
2592 Scan_State : Saved_Scan_State;
2593 Aliased_Present : Boolean := False;
2596 Array_Loc := Token_Ptr;
2598 Subs_List := New_List;
2601 -- It's quite tricky to disentangle these two possibilities, so we do
2602 -- a prescan to determine which case we have and then reset the scan.
2603 -- The prescan skips past possible subtype mark tokens.
2605 Save_Scan_State (Scan_State); -- just after paren
2607 while Token in Token_Class_Desig or else
2608 Token = Tok_Dot or else
2609 Token = Tok_Apostrophe -- because of 'BASE, 'CLASS
2614 -- If we end up on RANGE <> then we have the unconstrained case. We
2615 -- will also allow the RANGE to be omitted, just to improve error
2616 -- handling for a case like array (integer <>) of integer;
2618 Scan; -- past possible RANGE or <>
2620 if (Prev_Token = Tok_Range and then Token = Tok_Box) or else
2621 Prev_Token = Tok_Box
2623 Def_Node := New_Node (N_Unconstrained_Array_Definition, Array_Loc);
2624 Restore_Scan_State (Scan_State); -- to first subtype mark
2627 Append (P_Subtype_Mark_Resync, Subs_List);
2630 exit when Token = Tok_Right_Paren or else Token = Tok_Of;
2634 Set_Subtype_Marks (Def_Node, Subs_List);
2637 Def_Node := New_Node (N_Constrained_Array_Definition, Array_Loc);
2638 Restore_Scan_State (Scan_State); -- to first discrete range
2641 Append (P_Discrete_Subtype_Definition, Subs_List);
2642 exit when not Comma_Present;
2645 Set_Discrete_Subtype_Definitions (Def_Node, Subs_List);
2651 CompDef_Node := New_Node (N_Component_Definition, Token_Ptr);
2653 if Token_Name = Name_Aliased then
2654 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
2657 if Token = Tok_Aliased then
2658 Aliased_Present := True;
2659 Scan; -- past ALIASED
2662 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/AI-254)
2664 -- Ada 2005 (AI-230): Access Definition case
2666 if Token = Tok_Access then
2667 if Ada_Version < Ada_05 then
2669 ("generalized use of anonymous access types " &
2670 "is an Ada 2005 extension");
2671 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
2674 if Aliased_Present then
2675 Error_Msg_SP -- CODEFIX???
2676 ("ALIASED not allowed here");
2679 Set_Subtype_Indication (CompDef_Node, Empty);
2680 Set_Aliased_Present (CompDef_Node, False);
2681 Set_Access_Definition (CompDef_Node,
2682 P_Access_Definition (Not_Null_Present));
2685 Set_Access_Definition (CompDef_Node, Empty);
2686 Set_Aliased_Present (CompDef_Node, Aliased_Present);
2687 Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present);
2688 Set_Subtype_Indication (CompDef_Node,
2689 P_Subtype_Indication (Not_Null_Present));
2692 Set_Component_Definition (Def_Node, CompDef_Node);
2695 end P_Array_Type_Definition;
2697 -----------------------------------------
2698 -- 3.6 Unconstrained Array Definition --
2699 -----------------------------------------
2701 -- Parsed by P_Array_Type_Definition (3.6)
2703 ---------------------------------------
2704 -- 3.6 Constrained Array Definition --
2705 ---------------------------------------
2707 -- Parsed by P_Array_Type_Definition (3.6)
2709 --------------------------------------
2710 -- 3.6 Discrete Subtype Definition --
2711 --------------------------------------
2713 -- DISCRETE_SUBTYPE_DEFINITION ::=
2714 -- discrete_SUBTYPE_INDICATION | RANGE
2716 -- Note: the discrete subtype definition appearing in a constrained
2717 -- array definition is parsed by P_Array_Type_Definition (3.6)
2719 -- Error recovery: cannot raise Error_Resync
2721 function P_Discrete_Subtype_Definition return Node_Id is
2723 -- The syntax of a discrete subtype definition is identical to that
2724 -- of a discrete range, so we simply share the same parsing code.
2726 return P_Discrete_Range;
2727 end P_Discrete_Subtype_Definition;
2729 -------------------------------
2730 -- 3.6 Component Definition --
2731 -------------------------------
2733 -- For the array case, parsed by P_Array_Type_Definition (3.6)
2734 -- For the record case, parsed by P_Component_Declaration (3.8)
2736 -----------------------------
2737 -- 3.6.1 Index Constraint --
2738 -----------------------------
2740 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2742 ---------------------------
2743 -- 3.6.1 Discrete Range --
2744 ---------------------------
2746 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
2748 -- The possible forms for a discrete range are:
2750 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
2751 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
2752 -- Range_Attribute (RANGE, 3.5)
2753 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
2755 -- Error recovery: cannot raise Error_Resync
2757 function P_Discrete_Range return Node_Id is
2758 Expr_Node : Node_Id;
2759 Range_Node : Node_Id;
2762 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
2764 if Expr_Form = EF_Range_Attr then
2767 elsif Token = Tok_Range then
2768 if Expr_Form /= EF_Simple_Name then
2769 Error_Msg_SC ("range must be preceded by subtype mark");
2772 return P_Subtype_Indication (Expr_Node);
2774 -- Check Expression .. Expression case
2776 elsif Token = Tok_Dot_Dot then
2777 Range_Node := New_Node (N_Range, Token_Ptr);
2778 Set_Low_Bound (Range_Node, Expr_Node);
2780 Expr_Node := P_Expression;
2781 Check_Simple_Expression (Expr_Node);
2782 Set_High_Bound (Range_Node, Expr_Node);
2785 -- Otherwise we must have a subtype mark
2787 elsif Expr_Form = EF_Simple_Name then
2790 -- If incorrect, complain that we expect ..
2796 end P_Discrete_Range;
2798 ----------------------------
2799 -- 3.7 Discriminant Part --
2800 ----------------------------
2802 -- DISCRIMINANT_PART ::=
2803 -- UNKNOWN_DISCRIMINANT_PART
2804 -- | KNOWN_DISCRIMINANT_PART
2806 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
2807 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
2809 ------------------------------------
2810 -- 3.7 Unknown Discriminant Part --
2811 ------------------------------------
2813 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
2815 -- If no unknown discriminant part is present, then False is returned,
2816 -- otherwise the unknown discriminant is scanned out and True is returned.
2818 -- Error recovery: cannot raise Error_Resync
2820 function P_Unknown_Discriminant_Part_Opt return Boolean is
2821 Scan_State : Saved_Scan_State;
2824 -- If <> right now, then this is missing left paren
2826 if Token = Tok_Box then
2829 -- If not <> or left paren, then definitely no box
2831 elsif Token /= Tok_Left_Paren then
2834 -- Left paren, so might be a box after it
2837 Save_Scan_State (Scan_State);
2838 Scan; -- past the left paren
2840 if Token /= Tok_Box then
2841 Restore_Scan_State (Scan_State);
2846 -- We are now pointing to the box
2848 if Ada_Version = Ada_83 then
2849 Error_Msg_SC ("(Ada 83) unknown discriminant not allowed!");
2852 Scan; -- past the box
2853 U_Right_Paren; -- must be followed by right paren
2855 end P_Unknown_Discriminant_Part_Opt;
2857 ----------------------------------
2858 -- 3.7 Known Discriminant Part --
2859 ----------------------------------
2861 -- KNOWN_DISCRIMINANT_PART ::=
2862 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
2864 -- DISCRIMINANT_SPECIFICATION ::=
2865 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
2866 -- [:= DEFAULT_EXPRESSION]
2867 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
2868 -- [:= DEFAULT_EXPRESSION]
2870 -- If no known discriminant part is present, then No_List is returned
2872 -- Error recovery: cannot raise Error_Resync
2874 function P_Known_Discriminant_Part_Opt return List_Id is
2875 Specification_Node : Node_Id;
2876 Specification_List : List_Id;
2877 Ident_Sloc : Source_Ptr;
2878 Scan_State : Saved_Scan_State;
2880 Not_Null_Present : Boolean;
2883 Idents : array (Int range 1 .. 4096) of Entity_Id;
2884 -- This array holds the list of defining identifiers. The upper bound
2885 -- of 4096 is intended to be essentially infinite, and we do not even
2886 -- bother to check for it being exceeded.
2889 if Token = Tok_Left_Paren then
2890 Specification_List := New_List;
2892 P_Pragmas_Misplaced;
2894 Specification_Loop : loop
2896 Ident_Sloc := Token_Ptr;
2897 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
2900 while Comma_Present loop
2901 Num_Idents := Num_Idents + 1;
2902 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
2905 -- If there are multiple identifiers, we repeatedly scan the
2906 -- type and initialization expression information by resetting
2907 -- the scan pointer (so that we get completely separate trees
2908 -- for each occurrence).
2910 if Num_Idents > 1 then
2911 Save_Scan_State (Scan_State);
2916 -- Loop through defining identifiers in list
2920 Specification_Node :=
2921 New_Node (N_Discriminant_Specification, Ident_Sloc);
2922 Set_Defining_Identifier (Specification_Node, Idents (Ident));
2923 Not_Null_Present := -- Ada 2005 (AI-231, AI-447)
2924 P_Null_Exclusion (Allow_Anonymous_In_95 => True);
2926 if Token = Tok_Access then
2927 if Ada_Version = Ada_83 then
2929 ("(Ada 83) access discriminant not allowed!");
2932 Set_Discriminant_Type
2933 (Specification_Node,
2934 P_Access_Definition (Not_Null_Present));
2937 Set_Discriminant_Type
2938 (Specification_Node, P_Subtype_Mark);
2940 Set_Null_Exclusion_Present -- Ada 2005 (AI-231)
2941 (Specification_Node, Not_Null_Present);
2945 (Specification_Node, Init_Expr_Opt (True));
2948 Set_Prev_Ids (Specification_Node, True);
2951 if Ident < Num_Idents then
2952 Set_More_Ids (Specification_Node, True);
2955 Append (Specification_Node, Specification_List);
2956 exit Ident_Loop when Ident = Num_Idents;
2958 Restore_Scan_State (Scan_State);
2960 end loop Ident_Loop;
2962 exit Specification_Loop when Token /= Tok_Semicolon;
2964 P_Pragmas_Misplaced;
2965 end loop Specification_Loop;
2968 return Specification_List;
2973 end P_Known_Discriminant_Part_Opt;
2975 -------------------------------------
2976 -- 3.7 Discriminant Specification --
2977 -------------------------------------
2979 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
2981 -----------------------------
2982 -- 3.7 Default Expression --
2983 -----------------------------
2985 -- Always parsed (simply as an Expression) by the parent construct
2987 ------------------------------------
2988 -- 3.7.1 Discriminant Constraint --
2989 ------------------------------------
2991 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2993 --------------------------------------------------------
2994 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
2995 --------------------------------------------------------
2997 -- DISCRIMINANT_CONSTRAINT ::=
2998 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
3000 -- DISCRIMINANT_ASSOCIATION ::=
3001 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3004 -- This routine parses either an index or a discriminant constraint. As
3005 -- is clear from the above grammar, it is often possible to clearly
3006 -- determine which of the two possibilities we have, but there are
3007 -- cases (those in which we have a series of expressions of the same
3008 -- syntactic form as subtype indications), where we cannot tell. Since
3009 -- this means that in any case the semantic phase has to distinguish
3010 -- between the two, there is not much point in the parser trying to
3011 -- distinguish even those cases where the difference is clear. In any
3012 -- case, if we have a situation like:
3014 -- (A => 123, 235 .. 500)
3016 -- it is not clear which of the two items is the wrong one, better to
3017 -- let the semantic phase give a clear message. Consequently, this
3018 -- routine in general returns a list of items which can be either
3019 -- discrete ranges or discriminant associations.
3021 -- The caller has checked that the initial token is a left paren
3023 -- Error recovery: can raise Error_Resync
3025 function P_Index_Or_Discriminant_Constraint return Node_Id is
3026 Scan_State : Saved_Scan_State;
3027 Constr_Node : Node_Id;
3028 Constr_List : List_Id;
3029 Expr_Node : Node_Id;
3030 Result_Node : Node_Id;
3033 Result_Node := New_Node (N_Index_Or_Discriminant_Constraint, Token_Ptr);
3035 Constr_List := New_List;
3036 Set_Constraints (Result_Node, Constr_List);
3038 -- The two syntactic forms are a little mixed up, so what we are doing
3039 -- here is looking at the first entry to determine which case we have
3041 -- A discriminant constraint is a list of discriminant associations,
3042 -- which have one of the following possible forms:
3046 -- Id | Id | .. | Id => Expression
3048 -- An index constraint is a list of discrete ranges which have one
3049 -- of the following possible forms:
3052 -- Subtype_Mark range Range
3054 -- Simple_Expression .. Simple_Expression
3056 -- Loop through discriminants in list
3059 -- Check cases of Id => Expression or Id | Id => Expression
3061 if Token = Tok_Identifier then
3062 Save_Scan_State (Scan_State); -- at Id
3065 if Token = Tok_Arrow or else Token = Tok_Vertical_Bar then
3066 Restore_Scan_State (Scan_State); -- to Id
3067 Append (P_Discriminant_Association, Constr_List);
3070 Restore_Scan_State (Scan_State); -- to Id
3074 -- Otherwise scan out an expression and see what we have got
3076 Expr_Node := P_Expression_Or_Range_Attribute;
3078 if Expr_Form = EF_Range_Attr then
3079 Append (Expr_Node, Constr_List);
3081 elsif Token = Tok_Range then
3082 if Expr_Form /= EF_Simple_Name then
3083 Error_Msg_SC ("subtype mark required before RANGE");
3086 Append (P_Subtype_Indication (Expr_Node), Constr_List);
3089 -- Check Simple_Expression .. Simple_Expression case
3091 elsif Token = Tok_Dot_Dot then
3092 Check_Simple_Expression (Expr_Node);
3093 Constr_Node := New_Node (N_Range, Token_Ptr);
3094 Set_Low_Bound (Constr_Node, Expr_Node);
3096 Expr_Node := P_Expression;
3097 Check_Simple_Expression (Expr_Node);
3098 Set_High_Bound (Constr_Node, Expr_Node);
3099 Append (Constr_Node, Constr_List);
3102 -- Case of an expression which could be either form
3105 Append (Expr_Node, Constr_List);
3109 -- Here with a single entry scanned
3112 exit when not Comma_Present;
3118 end P_Index_Or_Discriminant_Constraint;
3120 -------------------------------------
3121 -- 3.7.1 Discriminant Association --
3122 -------------------------------------
3124 -- DISCRIMINANT_ASSOCIATION ::=
3125 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3128 -- This routine is used only when the name list is present and the caller
3129 -- has already checked this (by scanning ahead and repositioning the
3132 -- Error_Recovery: cannot raise Error_Resync;
3134 function P_Discriminant_Association return Node_Id is
3135 Discr_Node : Node_Id;
3136 Names_List : List_Id;
3137 Ident_Sloc : Source_Ptr;
3140 Ident_Sloc := Token_Ptr;
3141 Names_List := New_List;
3144 Append (P_Identifier (C_Vertical_Bar_Arrow), Names_List);
3145 exit when Token /= Tok_Vertical_Bar;
3149 Discr_Node := New_Node (N_Discriminant_Association, Ident_Sloc);
3150 Set_Selector_Names (Discr_Node, Names_List);
3152 Set_Expression (Discr_Node, P_Expression);
3154 end P_Discriminant_Association;
3156 ---------------------------------
3157 -- 3.8 Record Type Definition --
3158 ---------------------------------
3160 -- RECORD_TYPE_DEFINITION ::=
3161 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3163 -- There is no node in the tree for a record type definition. Instead
3164 -- a record definition node appears, with possible Abstract_Present,
3165 -- Tagged_Present, and Limited_Present flags set appropriately.
3167 ----------------------------
3168 -- 3.8 Record Definition --
3169 ----------------------------
3171 -- RECORD_DEFINITION ::=
3177 -- Note: in the case where a record definition node is used to represent
3178 -- a record type definition, the caller sets the Tagged_Present and
3179 -- Limited_Present flags in the resulting N_Record_Definition node as
3182 -- Note that the RECORD token at the start may be missing in certain
3183 -- error situations, so this function is expected to post the error
3185 -- Error recovery: can raise Error_Resync
3187 function P_Record_Definition return Node_Id is
3191 Rec_Node := New_Node (N_Record_Definition, Token_Ptr);
3195 if Token = Tok_Null then
3198 Set_Null_Present (Rec_Node, True);
3200 -- Catch incomplete declaration to prevent cascaded errors, see
3201 -- ACATS B393002 for an example.
3203 elsif Token = Tok_Semicolon then
3204 Error_Msg_AP ("missing record definition");
3206 -- Case starting with RECORD keyword. Build scope stack entry. For the
3207 -- column, we use the first non-blank character on the line, to deal
3208 -- with situations such as:
3214 -- which is not official RM indentation, but is not uncommon usage, and
3215 -- in particular is standard GNAT coding style, so handle it nicely.
3219 Scope.Table (Scope.Last).Etyp := E_Record;
3220 Scope.Table (Scope.Last).Ecol := Start_Column;
3221 Scope.Table (Scope.Last).Sloc := Token_Ptr;
3222 Scope.Table (Scope.Last).Labl := Error;
3223 Scope.Table (Scope.Last).Junk := (Token /= Tok_Record);
3227 Set_Component_List (Rec_Node, P_Component_List);
3230 exit when Check_End;
3231 Discard_Junk_Node (P_Component_List);
3236 end P_Record_Definition;
3238 -------------------------
3239 -- 3.8 Component List --
3240 -------------------------
3242 -- COMPONENT_LIST ::=
3243 -- COMPONENT_ITEM {COMPONENT_ITEM}
3244 -- | {COMPONENT_ITEM} VARIANT_PART
3247 -- Error recovery: cannot raise Error_Resync
3249 function P_Component_List return Node_Id is
3250 Component_List_Node : Node_Id;
3251 Decls_List : List_Id;
3252 Scan_State : Saved_Scan_State;
3255 Component_List_Node := New_Node (N_Component_List, Token_Ptr);
3256 Decls_List := New_List;
3258 if Token = Tok_Null then
3261 P_Pragmas_Opt (Decls_List);
3262 Set_Null_Present (Component_List_Node, True);
3263 return Component_List_Node;
3266 P_Pragmas_Opt (Decls_List);
3268 if Token /= Tok_Case then
3269 Component_Scan_Loop : loop
3270 P_Component_Items (Decls_List);
3271 P_Pragmas_Opt (Decls_List);
3273 exit Component_Scan_Loop when Token = Tok_End
3274 or else Token = Tok_Case
3275 or else Token = Tok_When;
3277 -- We are done if we do not have an identifier. However, if
3278 -- we have a misspelled reserved identifier that is in a column
3279 -- to the right of the record definition, we will treat it as
3280 -- an identifier. It turns out to be too dangerous in practice
3281 -- to accept such a mis-spelled identifier which does not have
3282 -- this additional clue that confirms the incorrect spelling.
3284 if Token /= Tok_Identifier then
3285 if Start_Column > Scope.Table (Scope.Last).Ecol
3286 and then Is_Reserved_Identifier
3288 Save_Scan_State (Scan_State); -- at reserved id
3289 Scan; -- possible reserved id
3291 if Token = Tok_Comma or else Token = Tok_Colon then
3292 Restore_Scan_State (Scan_State);
3293 Scan_Reserved_Identifier (Force_Msg => True);
3295 -- Note reserved identifier used as field name after
3296 -- all because not followed by colon or comma
3299 Restore_Scan_State (Scan_State);
3300 exit Component_Scan_Loop;
3303 -- Non-identifier that definitely was not reserved id
3306 exit Component_Scan_Loop;
3309 end loop Component_Scan_Loop;
3312 if Token = Tok_Case then
3313 Set_Variant_Part (Component_List_Node, P_Variant_Part);
3315 -- Check for junk after variant part
3317 if Token = Tok_Identifier then
3318 Save_Scan_State (Scan_State);
3319 Scan; -- past identifier
3321 if Token = Tok_Colon then
3322 Restore_Scan_State (Scan_State);
3323 Error_Msg_SC -- CODEFIX???
3324 ("component may not follow variant part");
3325 Discard_Junk_Node (P_Component_List);
3327 elsif Token = Tok_Case then
3328 Restore_Scan_State (Scan_State);
3329 Error_Msg_SC ("only one variant part allowed in a record");
3330 Discard_Junk_Node (P_Component_List);
3333 Restore_Scan_State (Scan_State);
3339 Set_Component_Items (Component_List_Node, Decls_List);
3340 return Component_List_Node;
3341 end P_Component_List;
3343 -------------------------
3344 -- 3.8 Component Item --
3345 -------------------------
3347 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3349 -- COMPONENT_DECLARATION ::=
3350 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3351 -- [:= DEFAULT_EXPRESSION];
3353 -- COMPONENT_DEFINITION ::=
3354 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3356 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3357 -- the scan is positioned past the following semicolon.
3359 -- Note: we do not yet allow representation clauses to appear as component
3360 -- items, do we need to add this capability sometime in the future ???
3362 procedure P_Component_Items (Decls : List_Id) is
3363 Aliased_Present : Boolean := False;
3364 CompDef_Node : Node_Id;
3365 Decl_Node : Node_Id;
3366 Scan_State : Saved_Scan_State;
3367 Not_Null_Present : Boolean := False;
3370 Ident_Sloc : Source_Ptr;
3372 Idents : array (Int range 1 .. 4096) of Entity_Id;
3373 -- This array holds the list of defining identifiers. The upper bound
3374 -- of 4096 is intended to be essentially infinite, and we do not even
3375 -- bother to check for it being exceeded.
3378 if Token /= Tok_Identifier then
3379 Error_Msg_SC ("component declaration expected");
3380 Resync_Past_Semicolon;
3384 Ident_Sloc := Token_Ptr;
3385 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
3388 while Comma_Present loop
3389 Num_Idents := Num_Idents + 1;
3390 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
3393 -- If there are multiple identifiers, we repeatedly scan the
3394 -- type and initialization expression information by resetting
3395 -- the scan pointer (so that we get completely separate trees
3396 -- for each occurrence).
3398 if Num_Idents > 1 then
3399 Save_Scan_State (Scan_State);
3404 -- Loop through defining identifiers in list
3409 -- The following block is present to catch Error_Resync
3410 -- which causes the parse to be reset past the semicolon
3413 Decl_Node := New_Node (N_Component_Declaration, Ident_Sloc);
3414 Set_Defining_Identifier (Decl_Node, Idents (Ident));
3416 if Token = Tok_Constant then
3417 Error_Msg_SC -- CODEFIX???
3418 ("constant components are not permitted");
3422 CompDef_Node := New_Node (N_Component_Definition, Token_Ptr);
3424 if Token_Name = Name_Aliased then
3425 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
3428 if Token = Tok_Aliased then
3429 Aliased_Present := True;
3430 Scan; -- past ALIASED
3433 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/AI-254)
3435 -- Ada 2005 (AI-230): Access Definition case
3437 if Token = Tok_Access then
3438 if Ada_Version < Ada_05 then
3440 ("generalized use of anonymous access types " &
3441 "is an Ada 2005 extension");
3442 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
3445 if Aliased_Present then
3446 Error_Msg_SP -- CODEFIX???
3447 ("ALIASED not allowed here");
3450 Set_Subtype_Indication (CompDef_Node, Empty);
3451 Set_Aliased_Present (CompDef_Node, False);
3452 Set_Access_Definition (CompDef_Node,
3453 P_Access_Definition (Not_Null_Present));
3456 Set_Access_Definition (CompDef_Node, Empty);
3457 Set_Aliased_Present (CompDef_Node, Aliased_Present);
3458 Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present);
3460 if Token = Tok_Array then
3461 Error_Msg_SC -- CODEFIX???
3462 ("anonymous arrays not allowed as components");
3466 Set_Subtype_Indication (CompDef_Node,
3467 P_Subtype_Indication (Not_Null_Present));
3470 Set_Component_Definition (Decl_Node, CompDef_Node);
3471 Set_Expression (Decl_Node, Init_Expr_Opt);
3474 Set_Prev_Ids (Decl_Node, True);
3477 if Ident < Num_Idents then
3478 Set_More_Ids (Decl_Node, True);
3481 Append (Decl_Node, Decls);
3484 when Error_Resync =>
3485 if Token /= Tok_End then
3486 Resync_Past_Semicolon;
3490 exit Ident_Loop when Ident = Num_Idents;
3492 Restore_Scan_State (Scan_State);
3495 end loop Ident_Loop;
3498 end P_Component_Items;
3500 --------------------------------
3501 -- 3.8 Component Declaration --
3502 --------------------------------
3504 -- Parsed by P_Component_Items (3.8)
3506 -------------------------
3507 -- 3.8.1 Variant Part --
3508 -------------------------
3511 -- case discriminant_DIRECT_NAME is
3516 -- The caller has checked that the initial token is CASE
3518 -- Error recovery: cannot raise Error_Resync
3520 function P_Variant_Part return Node_Id is
3521 Variant_Part_Node : Node_Id;
3522 Variants_List : List_Id;
3523 Case_Node : Node_Id;
3526 Variant_Part_Node := New_Node (N_Variant_Part, Token_Ptr);
3528 Scope.Table (Scope.Last).Etyp := E_Case;
3529 Scope.Table (Scope.Last).Sloc := Token_Ptr;
3530 Scope.Table (Scope.Last).Ecol := Start_Column;
3533 Case_Node := P_Expression;
3534 Set_Name (Variant_Part_Node, Case_Node);
3536 if Nkind (Case_Node) /= N_Identifier then
3537 Set_Name (Variant_Part_Node, Error);
3538 Error_Msg ("discriminant name expected", Sloc (Case_Node));
3540 elsif Paren_Count (Case_Node) /= 0 then
3541 Error_Msg -- CODEFIX???
3542 ("|discriminant name may not be parenthesized",
3544 Set_Paren_Count (Case_Node, 0);
3548 Variants_List := New_List;
3549 P_Pragmas_Opt (Variants_List);
3551 -- Test missing variant
3553 if Token = Tok_End then
3554 Error_Msg_BC ("WHEN expected (must have at least one variant)");
3556 Append (P_Variant, Variants_List);
3559 -- Loop through variants, note that we allow if in place of when,
3560 -- this error will be detected and handled in P_Variant.
3563 P_Pragmas_Opt (Variants_List);
3565 if Token /= Tok_When
3566 and then Token /= Tok_If
3567 and then Token /= Tok_Others
3569 exit when Check_End;
3572 Append (P_Variant, Variants_List);
3575 Set_Variants (Variant_Part_Node, Variants_List);
3576 return Variant_Part_Node;
3579 --------------------
3581 --------------------
3584 -- when DISCRETE_CHOICE_LIST =>
3587 -- Error recovery: cannot raise Error_Resync
3589 -- The initial token on entry is either WHEN, IF or OTHERS
3591 function P_Variant return Node_Id is
3592 Variant_Node : Node_Id;
3595 -- Special check to recover nicely from use of IF in place of WHEN
3597 if Token = Tok_If then
3604 Variant_Node := New_Node (N_Variant, Prev_Token_Ptr);
3605 Set_Discrete_Choices (Variant_Node, P_Discrete_Choice_List);
3607 Set_Component_List (Variant_Node, P_Component_List);
3608 return Variant_Node;
3611 ---------------------------------
3612 -- 3.8.1 Discrete Choice List --
3613 ---------------------------------
3615 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3617 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3619 -- Note: in Ada 83, the expression must be a simple expression
3621 -- Error recovery: cannot raise Error_Resync
3623 function P_Discrete_Choice_List return List_Id is
3625 Expr_Node : Node_Id;
3626 Choice_Node : Node_Id;
3629 Choices := New_List;
3631 if Token = Tok_Others then
3632 Append (New_Node (N_Others_Choice, Token_Ptr), Choices);
3633 Scan; -- past OTHERS
3637 -- Scan out expression or range attribute
3639 Expr_Node := P_Expression_Or_Range_Attribute;
3640 Ignore (Tok_Right_Paren);
3642 if Token = Tok_Colon
3643 and then Nkind (Expr_Node) = N_Identifier
3645 Error_Msg_SP ("label not permitted in this context");
3650 elsif Expr_Form = EF_Range_Attr then
3651 Append (Expr_Node, Choices);
3655 elsif Token = Tok_Dot_Dot then
3656 Check_Simple_Expression (Expr_Node);
3657 Choice_Node := New_Node (N_Range, Token_Ptr);
3658 Set_Low_Bound (Choice_Node, Expr_Node);
3660 Expr_Node := P_Expression_No_Right_Paren;
3661 Check_Simple_Expression (Expr_Node);
3662 Set_High_Bound (Choice_Node, Expr_Node);
3663 Append (Choice_Node, Choices);
3665 -- Simple name, must be subtype, so range allowed
3667 elsif Expr_Form = EF_Simple_Name then
3668 if Token = Tok_Range then
3669 Append (P_Subtype_Indication (Expr_Node), Choices);
3671 elsif Token in Token_Class_Consk then
3673 ("the only constraint allowed here " &
3674 "is a range constraint");
3675 Discard_Junk_Node (P_Constraint_Opt);
3676 Append (Expr_Node, Choices);
3679 Append (Expr_Node, Choices);
3685 -- If extensions are permitted then the expression must be a
3686 -- simple expression. The resaon for this restriction (i.e.
3687 -- going back to the Ada 83 rule) is to avoid ambiguities
3688 -- when set membership operations are allowed, consider the
3691 -- when A in 1 .. 10 | 12 =>
3693 -- This is ambiguous without parentheses, so we require one
3694 -- of the following two parenthesized forms to disambuguate:
3696 -- one of the following:
3698 -- when (A in 1 .. 10 | 12) =>
3699 -- when (A in 1 .. 10) | 12 =>
3701 -- To solve this, if extensins are enabled, we disallow
3702 -- the use of membership operations in expressions in
3703 -- choices. Technically in the grammar, the expression
3704 -- must match the grammar for restricted expression.
3706 if Extensions_Allowed then
3707 Check_Restricted_Expression (Expr_Node);
3709 -- In Ada 83 mode, the syntax required a simple expression
3712 Check_Simple_Expression_In_Ada_83 (Expr_Node);
3715 Append (Expr_Node, Choices);
3719 when Error_Resync =>
3725 if Token = Tok_Comma then
3726 Error_Msg_SC -- CODEFIX
3727 (""","" should be ""'|""");
3729 exit when Token /= Tok_Vertical_Bar;
3732 Scan; -- past | or comma
3736 end P_Discrete_Choice_List;
3738 ----------------------------
3739 -- 3.8.1 Discrete Choice --
3740 ----------------------------
3742 -- Parsed by P_Discrete_Choice_List (3.8.1)
3744 ----------------------------------
3745 -- 3.9.1 Record Extension Part --
3746 ----------------------------------
3748 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
3750 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
3752 --------------------------------------
3753 -- 3.9.4 Interface Type Definition --
3754 --------------------------------------
3756 -- INTERFACE_TYPE_DEFINITION ::=
3757 -- [limited | task | protected | synchronized] interface
3758 -- [and INTERFACE_LIST]
3760 -- Error recovery: cannot raise Error_Resync
3762 function P_Interface_Type_Definition
3763 (Abstract_Present : Boolean) return Node_Id
3765 Typedef_Node : Node_Id;
3768 if Ada_Version < Ada_05 then
3769 Error_Msg_SP ("abstract interface is an Ada 2005 extension");
3770 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
3773 if Abstract_Present then
3774 Error_Msg_SP -- CODEFIX???
3775 ("ABSTRACT not allowed in interface type definition " &
3779 Scan; -- past INTERFACE
3781 -- Ada 2005 (AI-345): In case of interfaces with a null list of
3782 -- interfaces we build a record_definition node.
3784 if Token = Tok_Semicolon then
3785 Typedef_Node := New_Node (N_Record_Definition, Token_Ptr);
3787 Set_Abstract_Present (Typedef_Node);
3788 Set_Tagged_Present (Typedef_Node);
3789 Set_Null_Present (Typedef_Node);
3790 Set_Interface_Present (Typedef_Node);
3792 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
3793 -- a list of interfaces we build a derived_type_definition node. This
3794 -- simplifies the semantic analysis (and hence further maintenance)
3797 if Token /= Tok_And then
3798 Error_Msg_AP -- CODEFIX???
3804 Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr);
3806 Set_Abstract_Present (Typedef_Node);
3807 Set_Interface_Present (Typedef_Node);
3808 Set_Subtype_Indication (Typedef_Node, P_Qualified_Simple_Name);
3810 Set_Record_Extension_Part (Typedef_Node,
3811 New_Node (N_Record_Definition, Token_Ptr));
3812 Set_Null_Present (Record_Extension_Part (Typedef_Node));
3814 if Token = Tok_And then
3815 Set_Interface_List (Typedef_Node, New_List);
3819 Append (P_Qualified_Simple_Name,
3820 Interface_List (Typedef_Node));
3821 exit when Token /= Tok_And;
3827 return Typedef_Node;
3828 end P_Interface_Type_Definition;
3830 ----------------------------------
3831 -- 3.10 Access Type Definition --
3832 ----------------------------------
3834 -- ACCESS_TYPE_DEFINITION ::=
3835 -- ACCESS_TO_OBJECT_DEFINITION
3836 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3838 -- ACCESS_TO_OBJECT_DEFINITION ::=
3839 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
3841 -- GENERAL_ACCESS_MODIFIER ::= all | constant
3843 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3844 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3845 -- | [NULL_EXCLUSION] access [protected] function
3846 -- PARAMETER_AND_RESULT_PROFILE
3848 -- PARAMETER_PROFILE ::= [FORMAL_PART]
3850 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
3852 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
3853 -- parsed the null_exclusion part and has also removed the ACCESS token;
3854 -- otherwise the caller has just checked that the initial token is ACCESS
3856 -- Error recovery: can raise Error_Resync
3858 function P_Access_Type_Definition
3859 (Header_Already_Parsed : Boolean := False) return Node_Id
3861 Access_Loc : constant Source_Ptr := Token_Ptr;
3862 Prot_Flag : Boolean;
3863 Not_Null_Present : Boolean := False;
3864 Type_Def_Node : Node_Id;
3865 Result_Not_Null : Boolean;
3866 Result_Node : Node_Id;
3868 procedure Check_Junk_Subprogram_Name;
3869 -- Used in access to subprogram definition cases to check for an
3870 -- identifier or operator symbol that does not belong.
3872 --------------------------------
3873 -- Check_Junk_Subprogram_Name --
3874 --------------------------------
3876 procedure Check_Junk_Subprogram_Name is
3877 Saved_State : Saved_Scan_State;
3880 if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then
3881 Save_Scan_State (Saved_State);
3882 Scan; -- past possible junk subprogram name
3884 if Token = Tok_Left_Paren or else Token = Tok_Semicolon then
3885 Error_Msg_SP -- CODEFIX???
3886 ("unexpected subprogram name ignored");
3890 Restore_Scan_State (Saved_State);
3893 end Check_Junk_Subprogram_Name;
3895 -- Start of processing for P_Access_Type_Definition
3898 if not Header_Already_Parsed then
3899 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
3900 Scan; -- past ACCESS
3903 if Token_Name = Name_Protected then
3904 Check_95_Keyword (Tok_Protected, Tok_Procedure);
3905 Check_95_Keyword (Tok_Protected, Tok_Function);
3908 Prot_Flag := (Token = Tok_Protected);
3911 Scan; -- past PROTECTED
3913 if Token /= Tok_Procedure and then Token /= Tok_Function then
3914 Error_Msg_SC -- CODEFIX
3915 ("FUNCTION or PROCEDURE expected");
3919 if Token = Tok_Procedure then
3920 if Ada_Version = Ada_83 then
3921 Error_Msg_SC ("(Ada 83) access to procedure not allowed!");
3924 Type_Def_Node := New_Node (N_Access_Procedure_Definition, Access_Loc);
3925 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3926 Scan; -- past PROCEDURE
3927 Check_Junk_Subprogram_Name;
3928 Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile);
3929 Set_Protected_Present (Type_Def_Node, Prot_Flag);
3931 elsif Token = Tok_Function then
3932 if Ada_Version = Ada_83 then
3933 Error_Msg_SC ("(Ada 83) access to function not allowed!");
3936 Type_Def_Node := New_Node (N_Access_Function_Definition, Access_Loc);
3937 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3938 Scan; -- past FUNCTION
3939 Check_Junk_Subprogram_Name;
3940 Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile);
3941 Set_Protected_Present (Type_Def_Node, Prot_Flag);
3944 Result_Not_Null := P_Null_Exclusion; -- Ada 2005 (AI-231)
3946 -- Ada 2005 (AI-318-02)
3948 if Token = Tok_Access then
3949 if Ada_Version < Ada_05 then
3951 ("anonymous access result type is an Ada 2005 extension");
3952 Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
3955 Result_Node := P_Access_Definition (Result_Not_Null);
3958 Result_Node := P_Subtype_Mark;
3961 -- A null exclusion on the result type must be recorded in a flag
3962 -- distinct from the one used for the access-to-subprogram type's
3965 Set_Null_Exclusion_In_Return_Present
3966 (Type_Def_Node, Result_Not_Null);
3969 Set_Result_Definition (Type_Def_Node, Result_Node);
3973 New_Node (N_Access_To_Object_Definition, Access_Loc);
3974 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3976 if Token = Tok_All or else Token = Tok_Constant then
3977 if Ada_Version = Ada_83 then
3978 Error_Msg_SC ("(Ada 83) access modifier not allowed!");
3981 if Token = Tok_All then
3982 Set_All_Present (Type_Def_Node, True);
3985 Set_Constant_Present (Type_Def_Node, True);
3988 Scan; -- past ALL or CONSTANT
3991 Set_Subtype_Indication (Type_Def_Node,
3992 P_Subtype_Indication (Not_Null_Present));
3995 return Type_Def_Node;
3996 end P_Access_Type_Definition;
3998 ---------------------------------------
3999 -- 3.10 Access To Object Definition --
4000 ---------------------------------------
4002 -- Parsed by P_Access_Type_Definition (3.10)
4004 -----------------------------------
4005 -- 3.10 General Access Modifier --
4006 -----------------------------------
4008 -- Parsed by P_Access_Type_Definition (3.10)
4010 -------------------------------------------
4011 -- 3.10 Access To Subprogram Definition --
4012 -------------------------------------------
4014 -- Parsed by P_Access_Type_Definition (3.10)
4016 -----------------------------
4017 -- 3.10 Access Definition --
4018 -----------------------------
4020 -- ACCESS_DEFINITION ::=
4021 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4022 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
4024 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4025 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4026 -- | [NULL_EXCLUSION] access [protected] function
4027 -- PARAMETER_AND_RESULT_PROFILE
4029 -- The caller has parsed the null-exclusion part and it has also checked
4030 -- that the next token is ACCESS
4032 -- Error recovery: cannot raise Error_Resync
4034 function P_Access_Definition
4035 (Null_Exclusion_Present : Boolean) return Node_Id
4038 Subp_Node : Node_Id;
4041 Def_Node := New_Node (N_Access_Definition, Token_Ptr);
4042 Scan; -- past ACCESS
4044 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
4046 if Token = Tok_Protected
4047 or else Token = Tok_Procedure
4048 or else Token = Tok_Function
4050 if Ada_Version < Ada_05 then
4051 Error_Msg_SP ("access-to-subprogram is an Ada 2005 extension");
4052 Error_Msg_SP ("\unit should be compiled with -gnat05 switch");
4055 Subp_Node := P_Access_Type_Definition (Header_Already_Parsed => True);
4056 Set_Null_Exclusion_Present (Subp_Node, Null_Exclusion_Present);
4057 Set_Access_To_Subprogram_Definition (Def_Node, Subp_Node);
4059 -- Ada 2005 (AI-231)
4060 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4063 Set_Null_Exclusion_Present (Def_Node, Null_Exclusion_Present);
4065 if Token = Tok_All then
4066 if Ada_Version < Ada_05 then
4067 Error_Msg_SP -- CODEFIX???
4068 ("ALL is not permitted for anonymous access types");
4072 Set_All_Present (Def_Node);
4074 elsif Token = Tok_Constant then
4075 if Ada_Version < Ada_05 then
4076 Error_Msg_SP ("access-to-constant is an Ada 2005 extension");
4077 Error_Msg_SP ("\unit should be compiled with -gnat05 switch");
4080 Scan; -- past CONSTANT
4081 Set_Constant_Present (Def_Node);
4084 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
4089 end P_Access_Definition;
4091 -----------------------------------------
4092 -- 3.10.1 Incomplete Type Declaration --
4093 -----------------------------------------
4095 -- Parsed by P_Type_Declaration (3.2.1)
4097 ----------------------------
4098 -- 3.11 Declarative Part --
4099 ----------------------------
4101 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
4103 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Items
4104 -- handles errors, and returns cleanly after an error has occurred)
4106 function P_Declarative_Part return List_Id is
4111 -- Indicate no bad declarations detected yet. This will be reset by
4112 -- P_Declarative_Items if a bad declaration is discovered.
4114 Missing_Begin_Msg := No_Error_Msg;
4116 -- Get rid of active SIS entry from outer scope. This means we will
4117 -- miss some nested cases, but it doesn't seem worth the effort. See
4118 -- discussion in Par for further details
4120 SIS_Entry_Active := False;
4123 -- Loop to scan out the declarations
4126 P_Declarative_Items (Decls, Done, In_Spec => False);
4130 -- Get rid of active SIS entry which is left set only if we scanned a
4131 -- procedure declaration and have not found the body. We could give
4132 -- an error message, but that really would be usurping the role of
4133 -- semantic analysis (this really is a missing body case).
4135 SIS_Entry_Active := False;
4137 end P_Declarative_Part;
4139 ----------------------------
4140 -- 3.11 Declarative Item --
4141 ----------------------------
4143 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4145 -- Can return Error if a junk declaration is found, or Empty if no
4146 -- declaration is found (i.e. a token ending declarations, such as
4147 -- BEGIN or END is encountered).
4149 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4150 -- then the scan is set past the next semicolon and Error is returned.
4152 procedure P_Declarative_Items
4157 Scan_State : Saved_Scan_State;
4161 Style.Check_Indentation;
4166 when Tok_Function =>
4168 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
4174 -- Check for loop (premature statement)
4176 Save_Scan_State (Scan_State);
4179 if Token = Tok_Identifier then
4180 Scan; -- past identifier
4182 if Token = Tok_In then
4183 Restore_Scan_State (Scan_State);
4184 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
4189 -- Not a loop, so must be rep clause
4191 Restore_Scan_State (Scan_State);
4192 Append (P_Representation_Clause, Decls);
4197 Append (P_Generic, Decls);
4200 when Tok_Identifier =>
4203 -- Special check for misuse of overriding not in Ada 2005 mode
4205 if Token_Name = Name_Overriding
4206 and then not Next_Token_Is (Tok_Colon)
4208 Error_Msg_SC ("overriding indicator is an Ada 2005 extension");
4209 Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
4211 Token := Tok_Overriding;
4212 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
4215 -- Normal case, no overriding, or overriding followed by colon
4218 P_Identifier_Declarations (Decls, Done, In_Spec);
4221 -- Ada2005: A subprogram declaration can start with "not" or
4222 -- "overriding". In older versions, "overriding" is handled
4223 -- like an identifier, with the appropriate messages.
4227 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
4230 when Tok_Overriding =>
4232 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
4237 Append (P_Package (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
4241 Append (P_Pragma, Decls);
4244 when Tok_Procedure =>
4246 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub), Decls);
4249 when Tok_Protected =>
4251 Scan; -- past PROTECTED
4252 Append (P_Protected, Decls);
4257 Append (P_Subtype_Declaration, Decls);
4263 Append (P_Task, Decls);
4268 Append (P_Type_Declaration, Decls);
4273 Append (P_Use_Clause, Decls);
4278 Error_Msg_SC -- CODEFIX???
4279 ("WITH can only appear in context clause");
4282 -- BEGIN terminates the scan of a sequence of declarations unless
4283 -- there is a missing subprogram body, see section on handling
4284 -- semicolon in place of IS. We only treat the begin as satisfying
4285 -- the subprogram declaration if it falls in the expected column
4289 if SIS_Entry_Active and then Start_Column >= SIS_Ecol then
4291 -- Here we have the case where a BEGIN is encountered during
4292 -- declarations in a declarative part, or at the outer level,
4293 -- and there is a subprogram declaration outstanding for which
4294 -- no body has been supplied. This is the case where we assume
4295 -- that the semicolon in the subprogram declaration should
4296 -- really have been is. The active SIS entry describes the
4297 -- subprogram declaration. On return the declaration has been
4298 -- modified to become a body.
4301 Specification_Node : Node_Id;
4302 Decl_Node : Node_Id;
4303 Body_Node : Node_Id;
4306 -- First issue the error message. If we had a missing
4307 -- semicolon in the declaration, then change the message
4308 -- to <missing "is">
4310 if SIS_Missing_Semicolon_Message /= No_Error_Msg then
4311 Change_Error_Text -- Replace: "missing "";"" "
4312 (SIS_Missing_Semicolon_Message, "missing ""is""");
4314 -- Otherwise we saved the semicolon position, so complain
4317 Error_Msg -- CODEFIX
4318 ("|"";"" should be IS", SIS_Semicolon_Sloc);
4321 -- The next job is to fix up any declarations that occurred
4322 -- between the procedure header and the BEGIN. These got
4323 -- chained to the outer declarative region (immediately
4324 -- after the procedure declaration) and they should be
4325 -- chained to the subprogram itself, which is a body
4326 -- rather than a spec.
4328 Specification_Node := Specification (SIS_Declaration_Node);
4329 Change_Node (SIS_Declaration_Node, N_Subprogram_Body);
4330 Body_Node := SIS_Declaration_Node;
4331 Set_Specification (Body_Node, Specification_Node);
4332 Set_Declarations (Body_Node, New_List);
4335 Decl_Node := Remove_Next (Body_Node);
4336 exit when Decl_Node = Empty;
4337 Append (Decl_Node, Declarations (Body_Node));
4340 -- Now make the scope table entry for the Begin-End and
4344 Scope.Table (Scope.Last).Sloc := SIS_Sloc;
4345 Scope.Table (Scope.Last).Etyp := E_Name;
4346 Scope.Table (Scope.Last).Ecol := SIS_Ecol;
4347 Scope.Table (Scope.Last).Labl := SIS_Labl;
4348 Scope.Table (Scope.Last).Lreq := False;
4349 SIS_Entry_Active := False;
4351 Set_Handled_Statement_Sequence (Body_Node,
4352 P_Handled_Sequence_Of_Statements);
4353 End_Statements (Handled_Statement_Sequence (Body_Node));
4362 -- Normally an END terminates the scan for basic declarative
4363 -- items. The one exception is END RECORD, which is probably
4364 -- left over from some other junk.
4367 Save_Scan_State (Scan_State); -- at END
4370 if Token = Tok_Record then
4371 Error_Msg_SP ("no RECORD for this `end record`!");
4372 Scan; -- past RECORD
4376 Restore_Scan_State (Scan_State); -- to END
4380 -- The following tokens which can only be the start of a statement
4381 -- are considered to end a declarative part (i.e. we have a missing
4382 -- BEGIN situation). We are fairly conservative in making this
4383 -- judgment, because it is a real mess to go into statement mode
4384 -- prematurely in response to a junk declaration.
4399 -- But before we decide that it's a statement, let's check for
4400 -- a reserved word misused as an identifier.
4402 if Is_Reserved_Identifier then
4403 Save_Scan_State (Scan_State);
4404 Scan; -- past the token
4406 -- If reserved identifier not followed by colon or comma, then
4407 -- this is most likely an assignment statement to the bad id.
4409 if Token /= Tok_Colon and then Token /= Tok_Comma then
4410 Restore_Scan_State (Scan_State);
4411 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
4414 -- Otherwise we have a declaration of the bad id
4417 Restore_Scan_State (Scan_State);
4418 Scan_Reserved_Identifier (Force_Msg => True);
4419 P_Identifier_Declarations (Decls, Done, In_Spec);
4422 -- If not reserved identifier, then it's definitely a statement
4425 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
4429 -- The token RETURN may well also signal a missing BEGIN situation,
4430 -- however, we never let it end the declarative part, because it may
4431 -- also be part of a half-baked function declaration.
4434 Error_Msg_SC ("misplaced RETURN statement");
4437 -- PRIVATE definitely terminates the declarations in a spec,
4438 -- and is an error in a body.
4444 Error_Msg_SC -- CODEFIX???
4445 ("PRIVATE not allowed in body");
4446 Scan; -- past PRIVATE
4449 -- An end of file definitely terminates the declarations!
4454 -- The remaining tokens do not end the scan, but cannot start a
4455 -- valid declaration, so we signal an error and resynchronize.
4456 -- But first check for misuse of a reserved identifier.
4460 -- Here we check for a reserved identifier
4462 if Is_Reserved_Identifier then
4463 Save_Scan_State (Scan_State);
4464 Scan; -- past the token
4466 if Token /= Tok_Colon and then Token /= Tok_Comma then
4467 Restore_Scan_State (Scan_State);
4468 Set_Declaration_Expected;
4471 Restore_Scan_State (Scan_State);
4472 Scan_Reserved_Identifier (Force_Msg => True);
4474 P_Identifier_Declarations (Decls, Done, In_Spec);
4478 Set_Declaration_Expected;
4483 -- To resynchronize after an error, we scan to the next semicolon and
4484 -- return with Done = False, indicating that there may still be more
4485 -- valid declarations to come.
4488 when Error_Resync =>
4489 Resync_Past_Semicolon;
4491 end P_Declarative_Items;
4493 ----------------------------------
4494 -- 3.11 Basic Declarative Item --
4495 ----------------------------------
4497 -- BASIC_DECLARATIVE_ITEM ::=
4498 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4500 -- Scan zero or more basic declarative items
4502 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4503 -- the scan pointer is repositioned past the next semicolon, and the scan
4504 -- for declarative items continues.
4506 function P_Basic_Declarative_Items return List_Id is
4513 -- Indicate no bad declarations detected yet in the current context:
4514 -- visible or private declarations of a package spec.
4516 Missing_Begin_Msg := No_Error_Msg;
4518 -- Get rid of active SIS entry from outer scope. This means we will
4519 -- miss some nested cases, but it doesn't seem worth the effort. See
4520 -- discussion in Par for further details
4522 SIS_Entry_Active := False;
4524 -- Loop to scan out declarations
4529 P_Declarative_Items (Decls, Done, In_Spec => True);
4533 -- Get rid of active SIS entry. This is set only if we have scanned a
4534 -- procedure declaration and have not found the body. We could give
4535 -- an error message, but that really would be usurping the role of
4536 -- semantic analysis (this really is a case of a missing body).
4538 SIS_Entry_Active := False;
4540 -- Test for assorted illegal declarations not diagnosed elsewhere
4542 Decl := First (Decls);
4544 while Present (Decl) loop
4545 Kind := Nkind (Decl);
4547 -- Test for body scanned, not acceptable as basic decl item
4549 if Kind = N_Subprogram_Body or else
4550 Kind = N_Package_Body or else
4551 Kind = N_Task_Body or else
4552 Kind = N_Protected_Body
4554 Error_Msg -- CODEFIX???
4555 ("proper body not allowed in package spec", Sloc (Decl));
4557 -- Test for body stub scanned, not acceptable as basic decl item
4559 elsif Kind in N_Body_Stub then
4560 Error_Msg -- CODEFIX???
4561 ("body stub not allowed in package spec", Sloc (Decl));
4563 elsif Kind = N_Assignment_Statement then
4564 Error_Msg -- CODEFIX???
4565 ("assignment statement not allowed in package spec",
4573 end P_Basic_Declarative_Items;
4579 -- For proper body, see below
4580 -- For body stub, see 10.1.3
4582 -----------------------
4583 -- 3.11 Proper Body --
4584 -----------------------
4586 -- Subprogram body is parsed by P_Subprogram (6.1)
4587 -- Package body is parsed by P_Package (7.1)
4588 -- Task body is parsed by P_Task (9.1)
4589 -- Protected body is parsed by P_Protected (9.4)
4591 ------------------------------
4592 -- Set_Declaration_Expected --
4593 ------------------------------
4595 procedure Set_Declaration_Expected is
4597 Error_Msg_SC ("declaration expected");
4599 if Missing_Begin_Msg = No_Error_Msg then
4600 Missing_Begin_Msg := Get_Msg_Id;
4602 end Set_Declaration_Expected;
4604 ----------------------
4605 -- Skip_Declaration --
4606 ----------------------
4608 procedure Skip_Declaration (S : List_Id) is
4609 Dummy_Done : Boolean;
4610 pragma Warnings (Off, Dummy_Done);
4612 P_Declarative_Items (S, Dummy_Done, False);
4613 end Skip_Declaration;
4615 -----------------------------------------
4616 -- Statement_When_Declaration_Expected --
4617 -----------------------------------------
4619 procedure Statement_When_Declaration_Expected
4625 -- Case of second occurrence of statement in one declaration sequence
4627 if Missing_Begin_Msg /= No_Error_Msg then
4629 -- In the procedure spec case, just ignore it, we only give one
4630 -- message for the first occurrence, since otherwise we may get
4631 -- horrible cascading if BODY was missing in the header line.
4636 -- In the declarative part case, take a second statement as a sure
4637 -- sign that we really have a missing BEGIN, and end the declarative
4638 -- part now. Note that the caller will fix up the first message to
4639 -- say "missing BEGIN" so that's how the error will be signalled.
4646 -- Case of first occurrence of unexpected statement
4649 -- If we are in a package spec, then give message of statement
4650 -- not allowed in package spec. This message never gets changed.
4653 Error_Msg_SC -- CODEFIX???
4654 ("statement not allowed in package spec");
4656 -- If in declarative part, then we give the message complaining
4657 -- about finding a statement when a declaration is expected. This
4658 -- gets changed to a complaint about a missing BEGIN if we later
4659 -- find that no BEGIN is present.
4662 Error_Msg_SC -- CODEFIX???
4663 ("statement not allowed in declarative part");
4666 -- Capture message Id. This is used for two purposes, first to
4667 -- stop multiple messages, see test above, and second, to allow
4668 -- the replacement of the message in the declarative part case.
4670 Missing_Begin_Msg := Get_Msg_Id;
4673 -- In all cases except the case in which we decided to terminate the
4674 -- declaration sequence on a second error, we scan out the statement
4675 -- and append it to the list of declarations (note that the semantics
4676 -- can handle statements in a declaration list so if we proceed to
4677 -- call the semantic phase, all will be (reasonably) well!
4679 Append_List_To (Decls, P_Sequence_Of_Statements (SS_Unco));
4681 -- Done is set to False, since we want to continue the scan of
4682 -- declarations, hoping that this statement was a temporary glitch.
4683 -- If we indeed are now in the statement part (i.e. this was a missing
4684 -- BEGIN, then it's not terrible, we will simply keep calling this
4685 -- procedure to process the statements one by one, and then finally
4686 -- hit the missing BEGIN, which will clean up the error message.
4689 end Statement_When_Declaration_Expected;