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.
114 ---------------------------------
115 -- Check_Restricted_Expression --
116 ---------------------------------
118 procedure Check_Restricted_Expression (N : Node_Id) is
120 if Nkind_In (N, N_Op_And, N_Op_Or, N_Op_Xor, N_And_Then, N_Or_Else) then
121 Check_Restricted_Expression (Left_Opnd (N));
122 Check_Restricted_Expression (Right_Opnd (N));
124 elsif Nkind_In (N, N_In, N_Not_In)
125 and then Paren_Count (N) = 0
128 ("|this expression must be parenthesized in Ada 2012 mode!", N);
130 end Check_Restricted_Expression;
136 function Init_Expr_Opt (P : Boolean := False) return Node_Id is
138 -- For colon, assume it means := unless it is at the end of
139 -- a line, in which case guess that it means a semicolon.
141 if Token = Tok_Colon then
142 if Token_Is_At_End_Of_Line then
147 -- Here if := or something that we will take as equivalent
149 elsif Token = Tok_Colon_Equal
150 or else Token = Tok_Equal
151 or else Token = Tok_Is
155 -- Another possibility. If we have a literal followed by a semicolon,
156 -- we assume that we have a missing colon-equal.
158 elsif Token in Token_Class_Literal then
160 Scan_State : Saved_Scan_State;
163 Save_Scan_State (Scan_State);
164 Scan; -- past literal or identifier
166 if Token = Tok_Semicolon then
167 Restore_Scan_State (Scan_State);
169 Restore_Scan_State (Scan_State);
174 -- Otherwise we definitely have no initialization expression
180 -- Merge here if we have an initialization expression
187 return P_Expression_No_Right_Paren;
191 ----------------------------
192 -- 3.1 Basic Declaration --
193 ----------------------------
195 -- Parsed by P_Basic_Declarative_Items (3.9)
197 ------------------------------
198 -- 3.1 Defining Identifier --
199 ------------------------------
201 -- DEFINING_IDENTIFIER ::= IDENTIFIER
203 -- Error recovery: can raise Error_Resync
205 function P_Defining_Identifier (C : Id_Check := None) return Node_Id is
206 Ident_Node : Node_Id;
209 -- Scan out the identifier. Note that this code is essentially identical
210 -- to P_Identifier, except that in the call to Scan_Reserved_Identifier
211 -- we set Force_Msg to True, since we want at least one message for each
212 -- separate declaration (but not use) of a reserved identifier.
214 if Token = Tok_Identifier then
216 -- Ada 2005 (AI-284): Compiling in Ada95 mode we warn that INTERFACE,
217 -- OVERRIDING, and SYNCHRONIZED are new reserved words. Note that
218 -- in the case where these keywords are misused in Ada 95 mode,
219 -- this routine will generally not be called at all.
221 if Ada_Version = Ada_95
222 and then Warn_On_Ada_2005_Compatibility
224 if Token_Name = Name_Overriding
225 or else Token_Name = Name_Synchronized
226 or else (Token_Name = Name_Interface
227 and then Prev_Token /= Tok_Pragma)
229 Error_Msg_N ("& is a reserved word in Ada 2005?", Token_Node);
233 -- If we have a reserved identifier, manufacture an identifier with
234 -- a corresponding name after posting an appropriate error message
236 elsif Is_Reserved_Identifier (C) then
237 Scan_Reserved_Identifier (Force_Msg => True);
239 -- Otherwise we have junk that cannot be interpreted as an identifier
242 T_Identifier; -- to give message
246 Ident_Node := Token_Node;
247 Scan; -- past the reserved identifier
249 -- If we already have a defining identifier, clean it out and make
250 -- a new clean identifier. This situation arises in some error cases
251 -- and we need to fix it.
253 if Nkind (Ident_Node) = N_Defining_Identifier then
255 Make_Identifier (Sloc (Ident_Node),
256 Chars => Chars (Ident_Node));
259 -- Change identifier to defining identifier if not in error
261 if Ident_Node /= Error then
262 Change_Identifier_To_Defining_Identifier (Ident_Node);
266 end P_Defining_Identifier;
268 -----------------------------
269 -- 3.2.1 Type Declaration --
270 -----------------------------
272 -- TYPE_DECLARATION ::=
273 -- FULL_TYPE_DECLARATION
274 -- | INCOMPLETE_TYPE_DECLARATION
275 -- | PRIVATE_TYPE_DECLARATION
276 -- | PRIVATE_EXTENSION_DECLARATION
278 -- FULL_TYPE_DECLARATION ::=
279 -- type DEFINING_IDENTIFIER [KNOWN_DISCRIMINANT_PART] is TYPE_DEFINITION
280 -- [ASPECT_SPECIFICATIONS];
281 -- | CONCURRENT_TYPE_DECLARATION
283 -- INCOMPLETE_TYPE_DECLARATION ::=
284 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] [is tagged];
286 -- PRIVATE_TYPE_DECLARATION ::=
287 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART]
288 -- is [abstract] [tagged] [limited] private;
290 -- PRIVATE_EXTENSION_DECLARATION ::=
291 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
292 -- [abstract] [limited | synchronized]
293 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
296 -- TYPE_DEFINITION ::=
297 -- ENUMERATION_TYPE_DEFINITION | INTEGER_TYPE_DEFINITION
298 -- | REAL_TYPE_DEFINITION | ARRAY_TYPE_DEFINITION
299 -- | RECORD_TYPE_DEFINITION | ACCESS_TYPE_DEFINITION
300 -- | DERIVED_TYPE_DEFINITION | INTERFACE_TYPE_DEFINITION
302 -- INTEGER_TYPE_DEFINITION ::=
303 -- SIGNED_INTEGER_TYPE_DEFINITION
304 -- MODULAR_TYPE_DEFINITION
306 -- INTERFACE_TYPE_DEFINITION ::=
307 -- [limited | task | protected | synchronized ] interface
308 -- [and INTERFACE_LIST]
310 -- Error recovery: can raise Error_Resync
312 -- Note: The processing for full type declaration, incomplete type
313 -- declaration, private type declaration and type definition is
314 -- included in this function. The processing for concurrent type
315 -- declarations is NOT here, but rather in chapter 9 (i.e. this
316 -- function handles only declarations starting with TYPE).
318 function P_Type_Declaration return Node_Id is
319 Abstract_Present : Boolean := False;
320 Abstract_Loc : Source_Ptr := No_Location;
322 Discr_List : List_Id;
323 Discr_Sloc : Source_Ptr;
325 Ident_Node : Node_Id;
326 Is_Derived_Iface : Boolean := False;
327 Type_Loc : Source_Ptr;
328 Type_Start_Col : Column_Number;
329 Unknown_Dis : Boolean;
331 Typedef_Node : Node_Id;
332 -- Normally holds type definition, except in the case of a private
333 -- extension declaration, in which case it holds the declaration itself
336 Type_Loc := Token_Ptr;
337 Type_Start_Col := Start_Column;
339 -- If we have TYPE, then proceed ahead and scan identifier
341 if Token = Tok_Type then
342 Type_Token_Location := Type_Loc;
344 Ident_Node := P_Defining_Identifier (C_Is);
346 -- Otherwise this is an error case
350 Type_Token_Location := Type_Loc;
351 Ident_Node := P_Defining_Identifier (C_Is);
354 Discr_Sloc := Token_Ptr;
356 if P_Unknown_Discriminant_Part_Opt then
358 Discr_List := No_List;
360 Unknown_Dis := False;
361 Discr_List := P_Known_Discriminant_Part_Opt;
364 -- Incomplete type declaration. We complete the processing for this
365 -- case here and return the resulting incomplete type declaration node
367 if Token = Tok_Semicolon then
369 Decl_Node := New_Node (N_Incomplete_Type_Declaration, Type_Loc);
370 Set_Defining_Identifier (Decl_Node, Ident_Node);
371 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
372 Set_Discriminant_Specifications (Decl_Node, Discr_List);
379 -- Full type declaration or private type declaration, must have IS
381 if Token = Tok_Equal then
383 Scan; -- past = used in place of IS
385 elsif Token = Tok_Renames then
386 Error_Msg_SC -- CODEFIX
387 ("RENAMES should be IS");
388 Scan; -- past RENAMES used in place of IS
394 -- First an error check, if we have two identifiers in a row, a likely
395 -- possibility is that the first of the identifiers is an incorrectly
398 if Token = Tok_Identifier then
400 SS : Saved_Scan_State;
404 Save_Scan_State (SS);
405 Scan; -- past initial identifier
406 I2 := (Token = Tok_Identifier);
407 Restore_Scan_State (SS);
411 (Bad_Spelling_Of (Tok_Abstract) or else
412 Bad_Spelling_Of (Tok_Access) or else
413 Bad_Spelling_Of (Tok_Aliased) or else
414 Bad_Spelling_Of (Tok_Constant))
421 -- Check for misuse of Ada 95 keyword abstract in Ada 83 mode
423 if Token_Name = Name_Abstract then
424 Check_95_Keyword (Tok_Abstract, Tok_Tagged);
425 Check_95_Keyword (Tok_Abstract, Tok_New);
428 -- Check cases of misuse of ABSTRACT
430 if Token = Tok_Abstract then
431 Abstract_Present := True;
432 Abstract_Loc := Token_Ptr;
433 Scan; -- past ABSTRACT
435 -- Ada 2005 (AI-419): AARM 3.4 (2/2)
437 if (Ada_Version < Ada_2005 and then Token = Tok_Limited)
438 or else Token = Tok_Private
439 or else Token = Tok_Record
440 or else Token = Tok_Null
442 Error_Msg_AP ("TAGGED expected");
446 -- Check for misuse of Ada 95 keyword Tagged
448 if Token_Name = Name_Tagged then
449 Check_95_Keyword (Tok_Tagged, Tok_Private);
450 Check_95_Keyword (Tok_Tagged, Tok_Limited);
451 Check_95_Keyword (Tok_Tagged, Tok_Record);
454 -- Special check for misuse of Aliased
456 if Token = Tok_Aliased or else Token_Name = Name_Aliased then
457 Error_Msg_SC ("ALIASED not allowed in type definition");
458 Scan; -- past ALIASED
461 -- The following processing deals with either a private type declaration
462 -- or a full type declaration. In the private type case, we build the
463 -- N_Private_Type_Declaration node, setting its Tagged_Present and
464 -- Limited_Present flags, on encountering the Private keyword, and
465 -- leave Typedef_Node set to Empty. For the full type declaration
466 -- case, Typedef_Node gets set to the type definition.
468 Typedef_Node := Empty;
470 -- Switch on token following the IS. The loop normally runs once. It
471 -- only runs more than once if an error is detected, to try again after
472 -- detecting and fixing up the error.
478 Tok_Not => -- Ada 2005 (AI-231)
479 Typedef_Node := P_Access_Type_Definition;
483 Typedef_Node := P_Array_Type_Definition;
487 Typedef_Node := P_Fixed_Point_Definition;
491 Typedef_Node := P_Floating_Point_Definition;
497 when Tok_Integer_Literal =>
499 Typedef_Node := P_Signed_Integer_Type_Definition;
503 Typedef_Node := P_Record_Definition;
506 when Tok_Left_Paren =>
507 Typedef_Node := P_Enumeration_Type_Definition;
510 Make_Identifier (Token_Ptr,
511 Chars => Chars (Ident_Node));
512 Set_Comes_From_Source (End_Labl, False);
514 Set_End_Label (Typedef_Node, End_Labl);
518 Typedef_Node := P_Modular_Type_Definition;
522 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
524 if Nkind (Typedef_Node) = N_Derived_Type_Definition
525 and then Present (Record_Extension_Part (Typedef_Node))
528 Make_Identifier (Token_Ptr,
529 Chars => Chars (Ident_Node));
530 Set_Comes_From_Source (End_Labl, False);
533 (Record_Extension_Part (Typedef_Node), End_Labl);
539 Typedef_Node := P_Signed_Integer_Type_Definition;
543 Typedef_Node := P_Record_Definition;
546 Make_Identifier (Token_Ptr,
547 Chars => Chars (Ident_Node));
548 Set_Comes_From_Source (End_Labl, False);
550 Set_End_Label (Typedef_Node, End_Labl);
556 -- Ada 2005 (AI-326): If the words IS TAGGED appear, the type
557 -- is a tagged incomplete type.
559 if Ada_Version >= Ada_2005
560 and then Token = Tok_Semicolon
565 New_Node (N_Incomplete_Type_Declaration, Type_Loc);
566 Set_Defining_Identifier (Decl_Node, Ident_Node);
567 Set_Tagged_Present (Decl_Node);
568 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
569 Set_Discriminant_Specifications (Decl_Node, Discr_List);
574 if Token = Tok_Abstract then
575 Error_Msg_SC -- CODEFIX
576 ("ABSTRACT must come before TAGGED");
577 Abstract_Present := True;
578 Abstract_Loc := Token_Ptr;
579 Scan; -- past ABSTRACT
582 if Token = Tok_Limited then
583 Scan; -- past LIMITED
585 -- TAGGED LIMITED PRIVATE case
587 if Token = Tok_Private then
589 New_Node (N_Private_Type_Declaration, Type_Loc);
590 Set_Tagged_Present (Decl_Node, True);
591 Set_Limited_Present (Decl_Node, True);
592 Scan; -- past PRIVATE
594 -- TAGGED LIMITED RECORD
597 Typedef_Node := P_Record_Definition;
598 Set_Tagged_Present (Typedef_Node, True);
599 Set_Limited_Present (Typedef_Node, True);
602 Make_Identifier (Token_Ptr,
603 Chars => Chars (Ident_Node));
604 Set_Comes_From_Source (End_Labl, False);
606 Set_End_Label (Typedef_Node, End_Labl);
612 if Token = Tok_Private then
614 New_Node (N_Private_Type_Declaration, Type_Loc);
615 Set_Tagged_Present (Decl_Node, True);
616 Scan; -- past PRIVATE
621 Typedef_Node := P_Record_Definition;
622 Set_Tagged_Present (Typedef_Node, True);
625 Make_Identifier (Token_Ptr,
626 Chars => Chars (Ident_Node));
627 Set_Comes_From_Source (End_Labl, False);
629 Set_End_Label (Typedef_Node, End_Labl);
636 Scan; -- past LIMITED
639 if Token = Tok_Tagged then
640 Error_Msg_SC -- CODEFIX
641 ("TAGGED must come before LIMITED");
644 elsif Token = Tok_Abstract then
645 Error_Msg_SC -- CODEFIX
646 ("ABSTRACT must come before LIMITED");
647 Scan; -- past ABSTRACT
654 -- LIMITED RECORD or LIMITED NULL RECORD
656 if Token = Tok_Record or else Token = Tok_Null then
657 if Ada_Version = Ada_83 then
659 ("(Ada 83) limited record declaration not allowed!");
661 -- In Ada2005, "abstract limited" can appear before "new",
662 -- but it cannot be part of an untagged record declaration.
664 elsif Abstract_Present
665 and then Prev_Token /= Tok_Tagged
667 Error_Msg_SP ("TAGGED expected");
670 Typedef_Node := P_Record_Definition;
671 Set_Limited_Present (Typedef_Node, True);
673 -- Ada 2005 (AI-251): LIMITED INTERFACE
675 -- If we are compiling in Ada 83 or Ada 95 mode, "interface"
676 -- is not a reserved word but we force its analysis to
677 -- generate the corresponding usage error.
679 elsif Token = Tok_Interface
680 or else (Token = Tok_Identifier
681 and then Chars (Token_Node) = Name_Interface)
684 P_Interface_Type_Definition (Abstract_Present);
685 Abstract_Present := True;
686 Set_Limited_Present (Typedef_Node);
688 if Nkind (Typedef_Node) = N_Derived_Type_Definition then
689 Is_Derived_Iface := True;
692 -- Ada 2005 (AI-419): LIMITED NEW
694 elsif Token = Tok_New then
695 if Ada_Version < Ada_2005 then
697 ("LIMITED in derived type is an Ada 2005 extension");
699 ("\unit must be compiled with -gnat05 switch");
702 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
703 Set_Limited_Present (Typedef_Node);
705 if Nkind (Typedef_Node) = N_Derived_Type_Definition
706 and then Present (Record_Extension_Part (Typedef_Node))
709 Make_Identifier (Token_Ptr,
710 Chars => Chars (Ident_Node));
711 Set_Comes_From_Source (End_Labl, False);
714 (Record_Extension_Part (Typedef_Node), End_Labl);
717 -- LIMITED PRIVATE is the only remaining possibility here
720 Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
721 Set_Limited_Present (Decl_Node, True);
722 T_Private; -- past PRIVATE (or complain if not there!)
727 -- Here we have an identifier after the IS, which is certainly
728 -- wrong and which might be one of several different mistakes.
730 when Tok_Identifier =>
732 -- First case, if identifier is on same line, then probably we
733 -- have something like "type X is Integer .." and the best
734 -- diagnosis is a missing NEW. Note: the missing new message
735 -- will be posted by P_Derived_Type_Def_Or_Private_Ext_Decl.
737 if not Token_Is_At_Start_Of_Line then
738 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
740 -- If the identifier is at the start of the line, and is in the
741 -- same column as the type declaration itself then we consider
742 -- that we had a missing type definition on the previous line
744 elsif Start_Column <= Type_Start_Col then
745 Error_Msg_AP ("type definition expected");
746 Typedef_Node := Error;
748 -- If the identifier is at the start of the line, and is in
749 -- a column to the right of the type declaration line, then we
750 -- may have something like:
755 -- and the best diagnosis is a missing record keyword
758 Typedef_Node := P_Record_Definition;
763 -- Ada 2005 (AI-251): INTERFACE
765 when Tok_Interface =>
766 Typedef_Node := P_Interface_Type_Definition (Abstract_Present);
767 Abstract_Present := True;
771 Decl_Node := New_Node (N_Private_Type_Declaration, Type_Loc);
772 Scan; -- past PRIVATE
775 -- Ada 2005 (AI-345): Protected, synchronized or task interface
776 -- or Ada 2005 (AI-443): Synchronized private extension.
783 Saved_Token : constant Token_Type := Token;
786 Scan; -- past TASK, PROTECTED or SYNCHRONIZED
788 -- Synchronized private extension
790 if Token = Tok_New then
791 Typedef_Node := P_Derived_Type_Def_Or_Private_Ext_Decl;
793 if Saved_Token = Tok_Synchronized then
794 if Nkind (Typedef_Node) =
795 N_Derived_Type_Definition
798 ("SYNCHRONIZED not allowed for record extension",
801 Set_Synchronized_Present (Typedef_Node);
805 Error_Msg_SC ("invalid kind of private extension");
811 if Token /= Tok_Interface then
812 Error_Msg_SC ("NEW or INTERFACE expected");
816 P_Interface_Type_Definition (Abstract_Present);
817 Abstract_Present := True;
821 Set_Task_Present (Typedef_Node);
823 when Tok_Protected =>
824 Set_Protected_Present (Typedef_Node);
826 when Tok_Synchronized =>
827 Set_Synchronized_Present (Typedef_Node);
830 pragma Assert (False);
838 -- Anything else is an error
841 if Bad_Spelling_Of (Tok_Access)
843 Bad_Spelling_Of (Tok_Array)
845 Bad_Spelling_Of (Tok_Delta)
847 Bad_Spelling_Of (Tok_Digits)
849 Bad_Spelling_Of (Tok_Limited)
851 Bad_Spelling_Of (Tok_Private)
853 Bad_Spelling_Of (Tok_Range)
855 Bad_Spelling_Of (Tok_Record)
857 Bad_Spelling_Of (Tok_Tagged)
862 Error_Msg_AP ("type definition expected");
869 -- For the private type declaration case, the private type declaration
870 -- node has been built, with the Tagged_Present and Limited_Present
871 -- flags set as needed, and Typedef_Node is left set to Empty.
873 if No (Typedef_Node) then
874 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
875 Set_Abstract_Present (Decl_Node, Abstract_Present);
877 -- For a private extension declaration, Typedef_Node contains the
878 -- N_Private_Extension_Declaration node, which we now complete. Note
879 -- that the private extension declaration, unlike a full type
880 -- declaration, does permit unknown discriminants.
882 elsif Nkind (Typedef_Node) = N_Private_Extension_Declaration then
883 Decl_Node := Typedef_Node;
884 Set_Sloc (Decl_Node, Type_Loc);
885 Set_Unknown_Discriminants_Present (Decl_Node, Unknown_Dis);
886 Set_Abstract_Present (Typedef_Node, Abstract_Present);
888 -- In the full type declaration case, Typedef_Node has the type
889 -- definition and here is where we build the full type declaration
890 -- node. This is also where we check for improper use of an unknown
891 -- discriminant part (not allowed for full type declaration).
894 if Nkind (Typedef_Node) = N_Record_Definition
895 or else (Nkind (Typedef_Node) = N_Derived_Type_Definition
896 and then Present (Record_Extension_Part (Typedef_Node)))
897 or else Is_Derived_Iface
899 Set_Abstract_Present (Typedef_Node, Abstract_Present);
901 elsif Abstract_Present then
902 Error_Msg ("ABSTRACT not allowed here, ignored", Abstract_Loc);
905 Decl_Node := New_Node (N_Full_Type_Declaration, Type_Loc);
906 Set_Type_Definition (Decl_Node, Typedef_Node);
910 ("Full type declaration cannot have unknown discriminants",
915 -- Remaining processing is common for all three cases
917 Set_Defining_Identifier (Decl_Node, Ident_Node);
918 Set_Discriminant_Specifications (Decl_Node, Discr_List);
919 P_Aspect_Specifications (Decl_Node);
921 end P_Type_Declaration;
923 ----------------------------------
924 -- 3.2.1 Full Type Declaration --
925 ----------------------------------
927 -- Parsed by P_Type_Declaration (3.2.1)
929 ----------------------------
930 -- 3.2.1 Type Definition --
931 ----------------------------
933 -- Parsed by P_Type_Declaration (3.2.1)
935 --------------------------------
936 -- 3.2.2 Subtype Declaration --
937 --------------------------------
939 -- SUBTYPE_DECLARATION ::=
940 -- subtype DEFINING_IDENTIFIER is [NULL_EXCLUSION] SUBTYPE_INDICATION;
942 -- The caller has checked that the initial token is SUBTYPE
944 -- Error recovery: can raise Error_Resync
946 function P_Subtype_Declaration return Node_Id is
948 Not_Null_Present : Boolean := False;
951 Decl_Node := New_Node (N_Subtype_Declaration, Token_Ptr);
952 Scan; -- past SUBTYPE
953 Set_Defining_Identifier (Decl_Node, P_Defining_Identifier (C_Is));
956 if Token = Tok_New then
957 Error_Msg_SC -- CODEFIX
958 ("NEW ignored (only allowed in type declaration)");
962 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
963 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
965 Set_Subtype_Indication
966 (Decl_Node, P_Subtype_Indication (Not_Null_Present));
967 P_Aspect_Specifications (Decl_Node);
969 end P_Subtype_Declaration;
971 -------------------------------
972 -- 3.2.2 Subtype Indication --
973 -------------------------------
975 -- SUBTYPE_INDICATION ::=
976 -- [not null] SUBTYPE_MARK [CONSTRAINT]
978 -- Error recovery: can raise Error_Resync
980 function P_Null_Exclusion
981 (Allow_Anonymous_In_95 : Boolean := False) return Boolean
983 Not_Loc : constant Source_Ptr := Token_Ptr;
984 -- Source position of "not", if present
987 if Token /= Tok_Not then
993 if Token = Tok_Null then
996 -- Ada 2005 (AI-441, AI-447): null_exclusion is illegal in Ada 95,
997 -- except in the case of anonymous access types.
999 -- Allow_Anonymous_In_95 will be True if we're parsing a formal
1000 -- parameter or discriminant, which are the only places where
1001 -- anonymous access types occur in Ada 95. "Formal : not null
1002 -- access ..." is legal in Ada 95, whereas "Formal : not null
1003 -- Named_Access_Type" is not.
1005 if Ada_Version >= Ada_2005
1006 or else (Ada_Version >= Ada_95
1007 and then Allow_Anonymous_In_95
1008 and then Token = Tok_Access)
1014 ("`NOT NULL` access type is an Ada 2005 extension", Not_Loc);
1016 ("\unit should be compiled with -gnat05 switch", Not_Loc);
1020 Error_Msg_SP ("NULL expected");
1023 if Token = Tok_New then
1024 Error_Msg ("`NOT NULL` comes after NEW, not before", Not_Loc);
1029 end P_Null_Exclusion;
1031 function P_Subtype_Indication
1032 (Not_Null_Present : Boolean := False) return Node_Id
1034 Type_Node : Node_Id;
1037 if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then
1038 Type_Node := P_Subtype_Mark;
1039 return P_Subtype_Indication (Type_Node, Not_Null_Present);
1042 -- Check for error of using record definition and treat it nicely,
1043 -- otherwise things are really messed up, so resynchronize.
1045 if Token = Tok_Record then
1046 Error_Msg_SC ("anonymous record definitions are not permitted");
1047 Discard_Junk_Node (P_Record_Definition);
1051 Error_Msg_AP ("subtype indication expected");
1055 end P_Subtype_Indication;
1057 -- The following function is identical except that it is called with
1058 -- the subtype mark already scanned out, and it scans out the constraint
1060 -- Error recovery: can raise Error_Resync
1062 function P_Subtype_Indication
1063 (Subtype_Mark : Node_Id;
1064 Not_Null_Present : Boolean := False) return Node_Id
1066 Indic_Node : Node_Id;
1067 Constr_Node : Node_Id;
1070 Constr_Node := P_Constraint_Opt;
1072 if No (Constr_Node) then
1073 return Subtype_Mark;
1075 if Not_Null_Present then
1076 Error_Msg_SP ("`NOT NULL` not allowed if constraint given");
1079 Indic_Node := New_Node (N_Subtype_Indication, Sloc (Subtype_Mark));
1080 Set_Subtype_Mark (Indic_Node, Check_Subtype_Mark (Subtype_Mark));
1081 Set_Constraint (Indic_Node, Constr_Node);
1084 end P_Subtype_Indication;
1086 -------------------------
1087 -- 3.2.2 Subtype Mark --
1088 -------------------------
1090 -- SUBTYPE_MARK ::= subtype_NAME;
1092 -- Note: The subtype mark which appears after an IN or NOT IN
1093 -- operator is parsed by P_Range_Or_Subtype_Mark (3.5)
1095 -- Error recovery: cannot raise Error_Resync
1097 function P_Subtype_Mark return Node_Id is
1099 return P_Subtype_Mark_Resync;
1101 when Error_Resync =>
1105 -- This routine differs from P_Subtype_Mark in that it insists that an
1106 -- identifier be present, and if it is not, it raises Error_Resync.
1108 -- Error recovery: can raise Error_Resync
1110 function P_Subtype_Mark_Resync return Node_Id is
1111 Type_Node : Node_Id;
1114 if Token = Tok_Access then
1115 Error_Msg_SC ("anonymous access type definition not allowed here");
1116 Scan; -- past ACCESS
1119 if Token = Tok_Array then
1120 Error_Msg_SC ("anonymous array definition not allowed here");
1121 Discard_Junk_Node (P_Array_Type_Definition);
1125 Type_Node := P_Qualified_Simple_Name_Resync;
1127 -- Check for a subtype mark attribute. The only valid possibilities
1128 -- are 'CLASS and 'BASE. Anything else is a definite error. We may
1129 -- as well catch it here.
1131 if Token = Tok_Apostrophe then
1132 return P_Subtype_Mark_Attribute (Type_Node);
1137 end P_Subtype_Mark_Resync;
1139 -- The following function is called to scan out a subtype mark attribute.
1140 -- The caller has already scanned out the subtype mark, which is passed in
1141 -- as the argument, and has checked that the current token is apostrophe.
1143 -- Only a special subclass of attributes, called type attributes
1144 -- (see Snames package) are allowed in this syntactic position.
1146 -- Note: if the apostrophe is followed by other than an identifier, then
1147 -- the input expression is returned unchanged, and the scan pointer is
1148 -- left pointing to the apostrophe.
1150 -- Error recovery: can raise Error_Resync
1152 function P_Subtype_Mark_Attribute (Type_Node : Node_Id) return Node_Id is
1153 Attr_Node : Node_Id := Empty;
1154 Scan_State : Saved_Scan_State;
1158 Prefix := Check_Subtype_Mark (Type_Node);
1160 if Prefix = Error then
1164 -- Loop through attributes appearing (more than one can appear as for
1165 -- for example in X'Base'Class). We are at an apostrophe on entry to
1166 -- this loop, and it runs once for each attribute parsed, with
1167 -- Prefix being the current possible prefix if it is an attribute.
1170 Save_Scan_State (Scan_State); -- at Apostrophe
1171 Scan; -- past apostrophe
1173 if Token /= Tok_Identifier then
1174 Restore_Scan_State (Scan_State); -- to apostrophe
1175 return Prefix; -- no attribute after all
1177 elsif not Is_Type_Attribute_Name (Token_Name) then
1179 ("attribute & may not be used in a subtype mark", Token_Node);
1184 Make_Attribute_Reference (Prev_Token_Ptr,
1186 Attribute_Name => Token_Name);
1187 Scan; -- past type attribute identifier
1190 exit when Token /= Tok_Apostrophe;
1191 Prefix := Attr_Node;
1194 -- Fall through here after scanning type attribute
1197 end P_Subtype_Mark_Attribute;
1199 -----------------------
1200 -- 3.2.2 Constraint --
1201 -----------------------
1203 -- CONSTRAINT ::= SCALAR_CONSTRAINT | COMPOSITE_CONSTRAINT
1205 -- SCALAR_CONSTRAINT ::=
1206 -- RANGE_CONSTRAINT | DIGITS_CONSTRAINT | DELTA_CONSTRAINT
1208 -- COMPOSITE_CONSTRAINT ::=
1209 -- INDEX_CONSTRAINT | DISCRIMINANT_CONSTRAINT
1211 -- If no constraint is present, this function returns Empty
1213 -- Error recovery: can raise Error_Resync
1215 function P_Constraint_Opt return Node_Id is
1217 if Token = Tok_Range
1218 or else Bad_Spelling_Of (Tok_Range)
1220 return P_Range_Constraint;
1222 elsif Token = Tok_Digits
1223 or else Bad_Spelling_Of (Tok_Digits)
1225 return P_Digits_Constraint;
1227 elsif Token = Tok_Delta
1228 or else Bad_Spelling_Of (Tok_Delta)
1230 return P_Delta_Constraint;
1232 elsif Token = Tok_Left_Paren then
1233 return P_Index_Or_Discriminant_Constraint;
1235 elsif Token = Tok_In then
1237 return P_Constraint_Opt;
1242 end P_Constraint_Opt;
1244 ------------------------------
1245 -- 3.2.2 Scalar Constraint --
1246 ------------------------------
1248 -- Parsed by P_Constraint_Opt (3.2.2)
1250 ---------------------------------
1251 -- 3.2.2 Composite Constraint --
1252 ---------------------------------
1254 -- Parsed by P_Constraint_Opt (3.2.2)
1256 --------------------------------------------------------
1257 -- 3.3 Identifier Declarations (Also 7.4, 8.5, 11.1) --
1258 --------------------------------------------------------
1260 -- This routine scans out a declaration starting with an identifier:
1262 -- OBJECT_DECLARATION ::=
1263 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1264 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION]
1265 -- [ASPECT_SPECIFICATIONS];
1266 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1267 -- ACCESS_DEFINITION [:= EXPRESSION]
1268 -- [ASPECT_SPECIFICATIONS];
1269 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1270 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION]
1271 -- [ASPECT_SPECIFICATIONS];
1273 -- NUMBER_DECLARATION ::=
1274 -- DEFINING_IDENTIFIER_LIST : constant ::= static_EXPRESSION;
1276 -- OBJECT_RENAMING_DECLARATION ::=
1277 -- DEFINING_IDENTIFIER :
1278 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME;
1279 -- | DEFINING_IDENTIFIER :
1280 -- ACCESS_DEFINITION renames object_NAME;
1282 -- EXCEPTION_RENAMING_DECLARATION ::=
1283 -- DEFINING_IDENTIFIER : exception renames exception_NAME;
1285 -- EXCEPTION_DECLARATION ::=
1286 -- DEFINING_IDENTIFIER_LIST : exception
1287 -- [ASPECT_SPECIFICATIONS];
1289 -- Note that the ALIASED indication in an object declaration is
1290 -- marked by a flag in the parent node.
1292 -- The caller has checked that the initial token is an identifier
1294 -- The value returned is a list of declarations, one for each identifier
1295 -- in the list (as described in Sinfo, we always split up multiple
1296 -- declarations into the equivalent sequence of single declarations
1297 -- using the More_Ids and Prev_Ids flags to preserve the source).
1299 -- If the identifier turns out to be a probable statement rather than
1300 -- an identifier, then the scan is left pointing to the identifier and
1301 -- No_List is returned.
1303 -- Error recovery: can raise Error_Resync
1305 procedure P_Identifier_Declarations
1311 Decl_Node : Node_Id;
1312 Type_Node : Node_Id;
1313 Ident_Sloc : Source_Ptr;
1314 Scan_State : Saved_Scan_State;
1315 List_OK : Boolean := True;
1317 Init_Expr : Node_Id;
1318 Init_Loc : Source_Ptr;
1319 Con_Loc : Source_Ptr;
1320 Not_Null_Present : Boolean := False;
1322 Idents : array (Int range 1 .. 4096) of Entity_Id;
1323 -- Used to save identifiers in the identifier list. The upper bound
1324 -- of 4096 is expected to be infinite in practice, and we do not even
1325 -- bother to check if this upper bound is exceeded.
1327 Num_Idents : Nat := 1;
1328 -- Number of identifiers stored in Idents
1331 -- This procedure is called in renames cases to make sure that we do
1332 -- not have more than one identifier. If we do have more than one
1333 -- then an error message is issued (and the declaration is split into
1334 -- multiple declarations)
1336 function Token_Is_Renames return Boolean;
1337 -- Checks if current token is RENAMES, and if so, scans past it and
1338 -- returns True, otherwise returns False. Includes checking for some
1339 -- common error cases.
1345 procedure No_List is
1347 if Num_Idents > 1 then
1349 ("identifier list not allowed for RENAMES",
1356 ----------------------
1357 -- Token_Is_Renames --
1358 ----------------------
1360 function Token_Is_Renames return Boolean is
1361 At_Colon : Saved_Scan_State;
1364 if Token = Tok_Colon then
1365 Save_Scan_State (At_Colon);
1367 Check_Misspelling_Of (Tok_Renames);
1369 if Token = Tok_Renames then
1370 Error_Msg_SP -- CODEFIX
1371 ("|extra "":"" ignored");
1372 Scan; -- past RENAMES
1375 Restore_Scan_State (At_Colon);
1380 Check_Misspelling_Of (Tok_Renames);
1382 if Token = Tok_Renames then
1383 Scan; -- past RENAMES
1389 end Token_Is_Renames;
1391 -- Start of processing for P_Identifier_Declarations
1394 Ident_Sloc := Token_Ptr;
1395 Save_Scan_State (Scan_State); -- at first identifier
1396 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
1398 -- If we have a colon after the identifier, then we can assume that
1399 -- this is in fact a valid identifier declaration and can steam ahead.
1401 if Token = Tok_Colon then
1404 -- If we have a comma, then scan out the list of identifiers
1406 elsif Token = Tok_Comma then
1407 while Comma_Present loop
1408 Num_Idents := Num_Idents + 1;
1409 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
1412 Save_Scan_State (Scan_State); -- at colon
1415 -- If we have identifier followed by := then we assume that what is
1416 -- really meant is an assignment statement. The assignment statement
1417 -- is scanned out and added to the list of declarations. An exception
1418 -- occurs if the := is followed by the keyword constant, in which case
1419 -- we assume it was meant to be a colon.
1421 elsif Token = Tok_Colon_Equal then
1424 if Token = Tok_Constant then
1425 Error_Msg_SP ("colon expected");
1428 Restore_Scan_State (Scan_State);
1429 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
1433 -- If we have an IS keyword, then assume the TYPE keyword was missing
1435 elsif Token = Tok_Is then
1436 Restore_Scan_State (Scan_State);
1437 Append_To (Decls, P_Type_Declaration);
1441 -- Otherwise we have an error situation
1444 Restore_Scan_State (Scan_State);
1446 -- First case is possible misuse of PROTECTED in Ada 83 mode. If
1447 -- so, fix the keyword and return to scan the protected declaration.
1449 if Token_Name = Name_Protected then
1450 Check_95_Keyword (Tok_Protected, Tok_Identifier);
1451 Check_95_Keyword (Tok_Protected, Tok_Type);
1452 Check_95_Keyword (Tok_Protected, Tok_Body);
1454 if Token = Tok_Protected then
1459 -- Check misspelling possibilities. If so, correct the misspelling
1460 -- and return to scan out the resulting declaration.
1462 elsif Bad_Spelling_Of (Tok_Function)
1463 or else Bad_Spelling_Of (Tok_Procedure)
1464 or else Bad_Spelling_Of (Tok_Package)
1465 or else Bad_Spelling_Of (Tok_Pragma)
1466 or else Bad_Spelling_Of (Tok_Protected)
1467 or else Bad_Spelling_Of (Tok_Generic)
1468 or else Bad_Spelling_Of (Tok_Subtype)
1469 or else Bad_Spelling_Of (Tok_Type)
1470 or else Bad_Spelling_Of (Tok_Task)
1471 or else Bad_Spelling_Of (Tok_Use)
1472 or else Bad_Spelling_Of (Tok_For)
1477 -- Otherwise we definitely have an ordinary identifier with a junk
1478 -- token after it. Just complain that we expect a declaration, and
1479 -- skip to a semicolon
1482 Set_Declaration_Expected;
1483 Resync_Past_Semicolon;
1489 -- Come here with an identifier list and colon scanned out. We now
1490 -- build the nodes for the declarative items. One node is built for
1491 -- each identifier in the list, with the type information being
1492 -- repeated by rescanning the appropriate section of source.
1494 -- First an error check, if we have two identifiers in a row, a likely
1495 -- possibility is that the first of the identifiers is an incorrectly
1498 if Token = Tok_Identifier then
1500 SS : Saved_Scan_State;
1504 Save_Scan_State (SS);
1505 Scan; -- past initial identifier
1506 I2 := (Token = Tok_Identifier);
1507 Restore_Scan_State (SS);
1511 (Bad_Spelling_Of (Tok_Access) or else
1512 Bad_Spelling_Of (Tok_Aliased) or else
1513 Bad_Spelling_Of (Tok_Constant))
1520 -- Loop through identifiers
1525 -- Check for some cases of misused Ada 95 keywords
1527 if Token_Name = Name_Aliased then
1528 Check_95_Keyword (Tok_Aliased, Tok_Array);
1529 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
1530 Check_95_Keyword (Tok_Aliased, Tok_Constant);
1535 if Token = Tok_Constant then
1536 Con_Loc := Token_Ptr;
1537 Scan; -- past CONSTANT
1539 -- Number declaration, initialization required
1541 Init_Expr := Init_Expr_Opt;
1543 if Present (Init_Expr) then
1544 if Not_Null_Present then
1546 ("`NOT NULL` not allowed in numeric expression");
1549 Decl_Node := New_Node (N_Number_Declaration, Ident_Sloc);
1550 Set_Expression (Decl_Node, Init_Expr);
1552 -- Constant object declaration
1555 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1556 Set_Constant_Present (Decl_Node, True);
1558 if Token_Name = Name_Aliased then
1559 Check_95_Keyword (Tok_Aliased, Tok_Array);
1560 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
1563 if Token = Tok_Aliased then
1564 Error_Msg_SC -- CODEFIX
1565 ("ALIASED should be before CONSTANT");
1566 Scan; -- past ALIASED
1567 Set_Aliased_Present (Decl_Node, True);
1570 if Token = Tok_Array then
1571 Set_Object_Definition
1572 (Decl_Node, P_Array_Type_Definition);
1575 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
1576 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1578 if Token = Tok_Access then
1579 if Ada_Version < Ada_2005 then
1581 ("generalized use of anonymous access types " &
1582 "is an Ada 2005 extension");
1584 ("\unit must be compiled with -gnat05 switch");
1587 Set_Object_Definition
1588 (Decl_Node, P_Access_Definition (Not_Null_Present));
1590 Set_Object_Definition
1591 (Decl_Node, P_Subtype_Indication (Not_Null_Present));
1595 if Token = Tok_Renames then
1597 ("CONSTANT not permitted in renaming declaration",
1599 Scan; -- Past renames
1600 Discard_Junk_Node (P_Name);
1606 elsif Token = Tok_Exception then
1607 Scan; -- past EXCEPTION
1609 if Token_Is_Renames then
1612 New_Node (N_Exception_Renaming_Declaration, Ident_Sloc);
1613 Set_Name (Decl_Node, P_Qualified_Simple_Name_Resync);
1616 Decl_Node := New_Node (N_Exception_Declaration, Prev_Token_Ptr);
1619 -- Aliased case (note that an object definition is required)
1621 elsif Token = Tok_Aliased then
1622 Scan; -- past ALIASED
1623 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1624 Set_Aliased_Present (Decl_Node, True);
1626 if Token = Tok_Constant then
1627 Scan; -- past CONSTANT
1628 Set_Constant_Present (Decl_Node, True);
1631 if Token = Tok_Array then
1632 Set_Object_Definition
1633 (Decl_Node, P_Array_Type_Definition);
1636 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
1637 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1639 -- Access definition (AI-406) or subtype indication
1641 if Token = Tok_Access then
1642 if Ada_Version < Ada_2005 then
1644 ("generalized use of anonymous access types " &
1645 "is an Ada 2005 extension");
1647 ("\unit must be compiled with -gnat05 switch");
1650 Set_Object_Definition
1651 (Decl_Node, P_Access_Definition (Not_Null_Present));
1653 Set_Object_Definition
1654 (Decl_Node, P_Subtype_Indication (Not_Null_Present));
1660 elsif Token = Tok_Array then
1661 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1662 Set_Object_Definition (Decl_Node, P_Array_Type_Definition);
1664 -- Ada 2005 (AI-254, AI-406)
1666 elsif Token = Tok_Not then
1668 -- OBJECT_DECLARATION ::=
1669 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1670 -- [NULL_EXCLUSION] SUBTYPE_INDICATION [:= EXPRESSION];
1671 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1672 -- ACCESS_DEFINITION [:= EXPRESSION];
1674 -- OBJECT_RENAMING_DECLARATION ::=
1675 -- DEFINING_IDENTIFIER :
1676 -- [NULL_EXCLUSION] SUBTYPE_MARK renames object_NAME;
1677 -- | DEFINING_IDENTIFIER :
1678 -- ACCESS_DEFINITION renames object_NAME;
1680 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/423)
1682 if Token = Tok_Access then
1683 if Ada_Version < Ada_2005 then
1685 ("generalized use of anonymous access types " &
1686 "is an Ada 2005 extension");
1687 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1690 Acc_Node := P_Access_Definition (Not_Null_Present);
1692 if Token /= Tok_Renames then
1693 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1694 Set_Object_Definition (Decl_Node, Acc_Node);
1697 Scan; -- past renames
1700 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1701 Set_Access_Definition (Decl_Node, Acc_Node);
1702 Set_Name (Decl_Node, P_Name);
1706 Type_Node := P_Subtype_Mark;
1708 -- Object renaming declaration
1710 if Token_Is_Renames then
1711 if Ada_Version < Ada_2005 then
1713 ("`NOT NULL` not allowed in object renaming");
1716 -- Ada 2005 (AI-423): Object renaming declaration with
1717 -- a null exclusion.
1722 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1723 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1724 Set_Subtype_Mark (Decl_Node, Type_Node);
1725 Set_Name (Decl_Node, P_Name);
1728 -- Object declaration
1731 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1732 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1733 Set_Object_Definition
1735 P_Subtype_Indication (Type_Node, Not_Null_Present));
1737 -- RENAMES at this point means that we had the combination
1738 -- of a constraint on the Type_Node and renames, which is
1741 if Token_Is_Renames then
1743 ("constraint not allowed in object renaming "
1745 Constraint (Object_Definition (Decl_Node)));
1751 -- Ada 2005 (AI-230): Access Definition case
1753 elsif Token = Tok_Access then
1754 if Ada_Version < Ada_2005 then
1756 ("generalized use of anonymous access types " &
1757 "is an Ada 2005 extension");
1758 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1761 Acc_Node := P_Access_Definition (Null_Exclusion_Present => False);
1763 -- Object declaration with access definition, or renaming
1765 if Token /= Tok_Renames then
1766 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1767 Set_Object_Definition (Decl_Node, Acc_Node);
1770 Scan; -- past renames
1773 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1774 Set_Access_Definition (Decl_Node, Acc_Node);
1775 Set_Name (Decl_Node, P_Name);
1778 -- Subtype indication case
1781 Type_Node := P_Subtype_Mark;
1783 -- Object renaming declaration
1785 if Token_Is_Renames then
1788 New_Node (N_Object_Renaming_Declaration, Ident_Sloc);
1789 Set_Subtype_Mark (Decl_Node, Type_Node);
1790 Set_Name (Decl_Node, P_Name);
1792 -- Object declaration
1795 Decl_Node := New_Node (N_Object_Declaration, Ident_Sloc);
1796 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1797 Set_Object_Definition
1799 P_Subtype_Indication (Type_Node, Not_Null_Present));
1801 -- RENAMES at this point means that we had the combination of
1802 -- a constraint on the Type_Node and renames, which is illegal
1804 if Token_Is_Renames then
1806 ("constraint not allowed in object renaming declaration",
1807 Constraint (Object_Definition (Decl_Node)));
1813 -- Scan out initialization, allowed only for object declaration
1815 Init_Loc := Token_Ptr;
1816 Init_Expr := Init_Expr_Opt;
1818 if Present (Init_Expr) then
1819 if Nkind (Decl_Node) = N_Object_Declaration then
1820 Set_Expression (Decl_Node, Init_Expr);
1821 Set_Has_Init_Expression (Decl_Node);
1823 Error_Msg ("initialization not allowed here", Init_Loc);
1827 Set_Defining_Identifier (Decl_Node, Idents (Ident));
1828 P_Aspect_Specifications (Decl_Node);
1831 if Ident < Num_Idents then
1832 Set_More_Ids (Decl_Node, True);
1836 Set_Prev_Ids (Decl_Node, True);
1840 Append (Decl_Node, Decls);
1841 exit Ident_Loop when Ident = Num_Idents;
1842 Restore_Scan_State (Scan_State);
1845 end loop Ident_Loop;
1848 end P_Identifier_Declarations;
1850 -------------------------------
1851 -- 3.3.1 Object Declaration --
1852 -------------------------------
1854 -- OBJECT DECLARATION ::=
1855 -- DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1856 -- SUBTYPE_INDICATION [:= EXPRESSION];
1857 -- | DEFINING_IDENTIFIER_LIST : [aliased] [constant]
1858 -- ARRAY_TYPE_DEFINITION [:= EXPRESSION];
1859 -- | SINGLE_TASK_DECLARATION
1860 -- | SINGLE_PROTECTED_DECLARATION
1862 -- Cases starting with TASK are parsed by P_Task (9.1)
1863 -- Cases starting with PROTECTED are parsed by P_Protected (9.4)
1864 -- All other cases are parsed by P_Identifier_Declarations (3.3)
1866 -------------------------------------
1867 -- 3.3.1 Defining Identifier List --
1868 -------------------------------------
1870 -- DEFINING_IDENTIFIER_LIST ::=
1871 -- DEFINING_IDENTIFIER {, DEFINING_IDENTIFIER}
1873 -- Always parsed by the construct in which it appears. See special
1874 -- section on "Handling of Defining Identifier Lists" in this unit.
1876 -------------------------------
1877 -- 3.3.2 Number Declaration --
1878 -------------------------------
1880 -- Parsed by P_Identifier_Declarations (3.3)
1882 -------------------------------------------------------------------------
1883 -- 3.4 Derived Type Definition or Private Extension Declaration (7.3) --
1884 -------------------------------------------------------------------------
1886 -- DERIVED_TYPE_DEFINITION ::=
1887 -- [abstract] [limited] new [NULL_EXCLUSION] parent_SUBTYPE_INDICATION
1888 -- [[and INTERFACE_LIST] RECORD_EXTENSION_PART]
1890 -- PRIVATE_EXTENSION_DECLARATION ::=
1891 -- type DEFINING_IDENTIFIER [DISCRIMINANT_PART] is
1892 -- [abstract] [limited | synchronized]
1893 -- new ancestor_SUBTYPE_INDICATION [and INTERFACE_LIST]
1896 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
1898 -- The caller has already scanned out the part up to the NEW, and Token
1899 -- either contains Tok_New (or ought to, if it doesn't this procedure
1900 -- will post an appropriate "NEW expected" message).
1902 -- Note: the caller is responsible for filling in the Sloc field of
1903 -- the returned node in the private extension declaration case as
1904 -- well as the stuff relating to the discriminant part.
1906 -- Error recovery: can raise Error_Resync;
1908 function P_Derived_Type_Def_Or_Private_Ext_Decl return Node_Id is
1909 Typedef_Node : Node_Id;
1910 Typedecl_Node : Node_Id;
1911 Not_Null_Present : Boolean := False;
1914 Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr);
1916 if Ada_Version < Ada_2005
1917 and then Token = Tok_Identifier
1918 and then Token_Name = Name_Interface
1921 ("abstract interface is an Ada 2005 extension");
1922 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1927 if Token = Tok_Abstract then
1928 Error_Msg_SC -- CODEFIX
1929 ("ABSTRACT must come before NEW, not after");
1933 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
1934 Set_Null_Exclusion_Present (Typedef_Node, Not_Null_Present);
1935 Set_Subtype_Indication (Typedef_Node,
1936 P_Subtype_Indication (Not_Null_Present));
1938 -- Ada 2005 (AI-251): Deal with interfaces
1940 if Token = Tok_And then
1943 if Ada_Version < Ada_2005 then
1945 ("abstract interface is an Ada 2005 extension");
1946 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1949 Set_Interface_List (Typedef_Node, New_List);
1952 Append (P_Qualified_Simple_Name, Interface_List (Typedef_Node));
1953 exit when Token /= Tok_And;
1957 if Token /= Tok_With then
1958 Error_Msg_SC ("WITH expected");
1963 -- Deal with record extension, note that we assume that a WITH is
1964 -- missing in the case of "type X is new Y record ..." or in the
1965 -- case of "type X is new Y null record".
1967 -- First make sure we don't have an aspect specification. If we do
1968 -- return now, so that our caller can check it (the WITH here is not
1969 -- part of a type extension).
1971 if Aspect_Specifications_Present then
1972 return Typedef_Node;
1974 -- OK, not an aspect specification, so continue test for extension
1976 elsif Token = Tok_With
1977 or else Token = Tok_Record
1978 or else Token = Tok_Null
1980 T_With; -- past WITH or give error message
1982 if Token = Tok_Limited then
1983 Error_Msg_SC ("LIMITED keyword not allowed in private extension");
1984 Scan; -- ignore LIMITED
1987 -- Private extension declaration
1989 if Token = Tok_Private then
1990 Scan; -- past PRIVATE
1992 -- Throw away the type definition node and build the type
1993 -- declaration node. Note the caller must set the Sloc,
1994 -- Discriminant_Specifications, Unknown_Discriminants_Present,
1995 -- and Defined_Identifier fields in the returned node.
1998 Make_Private_Extension_Declaration (No_Location,
1999 Defining_Identifier => Empty,
2000 Subtype_Indication => Subtype_Indication (Typedef_Node),
2001 Abstract_Present => Abstract_Present (Typedef_Node),
2002 Interface_List => Interface_List (Typedef_Node));
2004 return Typedecl_Node;
2006 -- Derived type definition with record extension part
2009 Set_Record_Extension_Part (Typedef_Node, P_Record_Definition);
2010 return Typedef_Node;
2013 -- Derived type definition with no record extension part
2016 return Typedef_Node;
2018 end P_Derived_Type_Def_Or_Private_Ext_Decl;
2020 ---------------------------
2021 -- 3.5 Range Constraint --
2022 ---------------------------
2024 -- RANGE_CONSTRAINT ::= range RANGE
2026 -- The caller has checked that the initial token is RANGE
2028 -- Error recovery: cannot raise Error_Resync
2030 function P_Range_Constraint return Node_Id is
2031 Range_Node : Node_Id;
2034 Range_Node := New_Node (N_Range_Constraint, Token_Ptr);
2036 Set_Range_Expression (Range_Node, P_Range);
2038 end P_Range_Constraint;
2045 -- RANGE_ATTRIBUTE_REFERENCE | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2047 -- Note: the range that appears in a membership test is parsed by
2048 -- P_Range_Or_Subtype_Mark (3.5).
2050 -- Error recovery: cannot raise Error_Resync
2052 function P_Range return Node_Id is
2053 Expr_Node : Node_Id;
2054 Range_Node : Node_Id;
2057 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
2059 if Expr_Form = EF_Range_Attr then
2062 elsif Token = Tok_Dot_Dot then
2063 Range_Node := New_Node (N_Range, Token_Ptr);
2064 Set_Low_Bound (Range_Node, Expr_Node);
2066 Expr_Node := P_Expression;
2067 Check_Simple_Expression (Expr_Node);
2068 Set_High_Bound (Range_Node, Expr_Node);
2071 -- Anything else is an error
2074 T_Dot_Dot; -- force missing .. message
2079 ----------------------------------
2080 -- 3.5 P_Range_Or_Subtype_Mark --
2081 ----------------------------------
2084 -- RANGE_ATTRIBUTE_REFERENCE
2085 -- | SIMPLE_EXPRESSION .. SIMPLE_EXPRESSION
2087 -- This routine scans out the range or subtype mark that forms the right
2088 -- operand of a membership test (it is not used in any other contexts, and
2089 -- error messages are specialized with this knowledge in mind).
2091 -- Note: as documented in the Sinfo interface, although the syntax only
2092 -- allows a subtype mark, we in fact allow any simple expression to be
2093 -- returned from this routine. The semantics is responsible for issuing
2094 -- an appropriate message complaining if the argument is not a name.
2095 -- This simplifies the coding and error recovery processing in the
2096 -- parser, and in any case it is preferable not to consider this a
2097 -- syntax error and to continue with the semantic analysis.
2099 -- Error recovery: cannot raise Error_Resync
2101 function P_Range_Or_Subtype_Mark
2102 (Allow_Simple_Expression : Boolean := False) return Node_Id
2104 Expr_Node : Node_Id;
2105 Range_Node : Node_Id;
2106 Save_Loc : Source_Ptr;
2108 -- Start of processing for P_Range_Or_Subtype_Mark
2111 -- Save location of possible junk parentheses
2113 Save_Loc := Token_Ptr;
2115 -- Scan out either a simple expression or a range (this accepts more
2116 -- than is legal here, but as explained above, we like to allow more
2117 -- with a proper diagnostic, and in the case of a membership operation
2118 -- where sets are allowed, a simple expression is permissible anyway.
2120 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
2124 if Expr_Form = EF_Range_Attr then
2127 -- Simple_Expression .. Simple_Expression
2129 elsif Token = Tok_Dot_Dot then
2130 Check_Simple_Expression (Expr_Node);
2131 Range_Node := New_Node (N_Range, Token_Ptr);
2132 Set_Low_Bound (Range_Node, Expr_Node);
2134 Set_High_Bound (Range_Node, P_Simple_Expression);
2137 -- Case of subtype mark (optionally qualified simple name or an
2138 -- attribute whose prefix is an optionally qualified simple name)
2140 elsif Expr_Form = EF_Simple_Name
2141 or else Nkind (Expr_Node) = N_Attribute_Reference
2143 -- Check for error of range constraint after a subtype mark
2145 if Token = Tok_Range then
2146 Error_Msg_SC ("range constraint not allowed in membership test");
2150 -- Check for error of DIGITS or DELTA after a subtype mark
2152 elsif Token = Tok_Digits or else Token = Tok_Delta then
2154 ("accuracy definition not allowed in membership test");
2155 Scan; -- past DIGITS or DELTA
2158 -- Attribute reference, may or may not be OK, but in any case we
2161 elsif Token = Tok_Apostrophe then
2162 return P_Subtype_Mark_Attribute (Expr_Node);
2164 -- OK case of simple name, just return it
2170 -- Simple expression case
2172 elsif Expr_Form = EF_Simple and then Allow_Simple_Expression then
2175 -- Here we have some kind of error situation. Check for junk parens
2176 -- then return what we have, caller will deal with other errors.
2179 if Nkind (Expr_Node) in N_Subexpr
2180 and then Paren_Count (Expr_Node) /= 0
2182 Error_Msg ("|parentheses not allowed for subtype mark", Save_Loc);
2183 Set_Paren_Count (Expr_Node, 0);
2188 end P_Range_Or_Subtype_Mark;
2190 ----------------------------------------
2191 -- 3.5.1 Enumeration Type Definition --
2192 ----------------------------------------
2194 -- ENUMERATION_TYPE_DEFINITION ::=
2195 -- (ENUMERATION_LITERAL_SPECIFICATION
2196 -- {, ENUMERATION_LITERAL_SPECIFICATION})
2198 -- The caller has already scanned out the TYPE keyword
2200 -- Error recovery: can raise Error_Resync;
2202 function P_Enumeration_Type_Definition return Node_Id is
2203 Typedef_Node : Node_Id;
2206 Typedef_Node := New_Node (N_Enumeration_Type_Definition, Token_Ptr);
2207 Set_Literals (Typedef_Node, New_List);
2212 Append (P_Enumeration_Literal_Specification, Literals (Typedef_Node));
2213 exit when not Comma_Present;
2217 return Typedef_Node;
2218 end P_Enumeration_Type_Definition;
2220 ----------------------------------------------
2221 -- 3.5.1 Enumeration Literal Specification --
2222 ----------------------------------------------
2224 -- ENUMERATION_LITERAL_SPECIFICATION ::=
2225 -- DEFINING_IDENTIFIER | DEFINING_CHARACTER_LITERAL
2227 -- Error recovery: can raise Error_Resync
2229 function P_Enumeration_Literal_Specification return Node_Id is
2231 if Token = Tok_Char_Literal then
2232 return P_Defining_Character_Literal;
2234 return P_Defining_Identifier (C_Comma_Right_Paren);
2236 end P_Enumeration_Literal_Specification;
2238 ---------------------------------------
2239 -- 3.5.1 Defining_Character_Literal --
2240 ---------------------------------------
2242 -- DEFINING_CHARACTER_LITERAL ::= CHARACTER_LITERAL
2244 -- Error recovery: cannot raise Error_Resync
2246 -- The caller has checked that the current token is a character literal
2248 function P_Defining_Character_Literal return Node_Id is
2249 Literal_Node : Node_Id;
2251 Literal_Node := Token_Node;
2252 Change_Character_Literal_To_Defining_Character_Literal (Literal_Node);
2253 Scan; -- past character literal
2254 return Literal_Node;
2255 end P_Defining_Character_Literal;
2257 ------------------------------------
2258 -- 3.5.4 Integer Type Definition --
2259 ------------------------------------
2261 -- Parsed by P_Type_Declaration (3.2.1)
2263 -------------------------------------------
2264 -- 3.5.4 Signed Integer Type Definition --
2265 -------------------------------------------
2267 -- SIGNED_INTEGER_TYPE_DEFINITION ::=
2268 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2270 -- Normally the initial token on entry is RANGE, but in some
2271 -- error conditions, the range token was missing and control is
2272 -- passed with Token pointing to first token of the first expression.
2274 -- Error recovery: cannot raise Error_Resync
2276 function P_Signed_Integer_Type_Definition return Node_Id is
2277 Typedef_Node : Node_Id;
2278 Expr_Node : Node_Id;
2281 Typedef_Node := New_Node (N_Signed_Integer_Type_Definition, Token_Ptr);
2283 if Token = Tok_Range then
2287 Expr_Node := P_Expression;
2288 Check_Simple_Expression (Expr_Node);
2289 Set_Low_Bound (Typedef_Node, Expr_Node);
2291 Expr_Node := P_Expression;
2292 Check_Simple_Expression (Expr_Node);
2293 Set_High_Bound (Typedef_Node, Expr_Node);
2294 return Typedef_Node;
2295 end P_Signed_Integer_Type_Definition;
2297 ------------------------------------
2298 -- 3.5.4 Modular Type Definition --
2299 ------------------------------------
2301 -- MODULAR_TYPE_DEFINITION ::= mod static_EXPRESSION
2303 -- The caller has checked that the initial token is MOD
2305 -- Error recovery: cannot raise Error_Resync
2307 function P_Modular_Type_Definition return Node_Id is
2308 Typedef_Node : Node_Id;
2311 if Ada_Version = Ada_83 then
2312 Error_Msg_SC ("(Ada 83): modular types not allowed");
2315 Typedef_Node := New_Node (N_Modular_Type_Definition, Token_Ptr);
2317 Set_Expression (Typedef_Node, P_Expression_No_Right_Paren);
2319 -- Handle mod L..R cleanly
2321 if Token = Tok_Dot_Dot then
2322 Error_Msg_SC ("range not allowed for modular type");
2324 Set_Expression (Typedef_Node, P_Expression_No_Right_Paren);
2327 return Typedef_Node;
2328 end P_Modular_Type_Definition;
2330 ---------------------------------
2331 -- 3.5.6 Real Type Definition --
2332 ---------------------------------
2334 -- Parsed by P_Type_Declaration (3.2.1)
2336 --------------------------------------
2337 -- 3.5.7 Floating Point Definition --
2338 --------------------------------------
2340 -- FLOATING_POINT_DEFINITION ::=
2341 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2343 -- Note: In Ada-83, the EXPRESSION must be a SIMPLE_EXPRESSION
2345 -- The caller has checked that the initial token is DIGITS
2347 -- Error recovery: cannot raise Error_Resync
2349 function P_Floating_Point_Definition return Node_Id is
2350 Digits_Loc : constant Source_Ptr := Token_Ptr;
2352 Expr_Node : Node_Id;
2355 Scan; -- past DIGITS
2356 Expr_Node := P_Expression_No_Right_Paren;
2357 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2359 -- Handle decimal fixed-point defn with DIGITS/DELTA in wrong order
2361 if Token = Tok_Delta then
2362 Error_Msg_SC -- CODEFIX
2363 ("|DELTA must come before DIGITS");
2364 Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Digits_Loc);
2366 Set_Delta_Expression (Def_Node, P_Expression_No_Right_Paren);
2368 -- OK floating-point definition
2371 Def_Node := New_Node (N_Floating_Point_Definition, Digits_Loc);
2374 Set_Digits_Expression (Def_Node, Expr_Node);
2375 Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt);
2377 end P_Floating_Point_Definition;
2379 -------------------------------------
2380 -- 3.5.7 Real Range Specification --
2381 -------------------------------------
2383 -- REAL_RANGE_SPECIFICATION ::=
2384 -- range static_SIMPLE_EXPRESSION .. static_SIMPLE_EXPRESSION
2386 -- Error recovery: cannot raise Error_Resync
2388 function P_Real_Range_Specification_Opt return Node_Id is
2389 Specification_Node : Node_Id;
2390 Expr_Node : Node_Id;
2393 if Token = Tok_Range then
2394 Specification_Node :=
2395 New_Node (N_Real_Range_Specification, Token_Ptr);
2397 Expr_Node := P_Expression_No_Right_Paren;
2398 Check_Simple_Expression (Expr_Node);
2399 Set_Low_Bound (Specification_Node, Expr_Node);
2401 Expr_Node := P_Expression_No_Right_Paren;
2402 Check_Simple_Expression (Expr_Node);
2403 Set_High_Bound (Specification_Node, Expr_Node);
2404 return Specification_Node;
2408 end P_Real_Range_Specification_Opt;
2410 -----------------------------------
2411 -- 3.5.9 Fixed Point Definition --
2412 -----------------------------------
2414 -- FIXED_POINT_DEFINITION ::=
2415 -- ORDINARY_FIXED_POINT_DEFINITION | DECIMAL_FIXED_POINT_DEFINITION
2417 -- ORDINARY_FIXED_POINT_DEFINITION ::=
2418 -- delta static_EXPRESSION REAL_RANGE_SPECIFICATION
2420 -- DECIMAL_FIXED_POINT_DEFINITION ::=
2421 -- delta static_EXPRESSION
2422 -- digits static_EXPRESSION [REAL_RANGE_SPECIFICATION]
2424 -- The caller has checked that the initial token is DELTA
2426 -- Error recovery: cannot raise Error_Resync
2428 function P_Fixed_Point_Definition return Node_Id is
2429 Delta_Node : Node_Id;
2430 Delta_Loc : Source_Ptr;
2432 Expr_Node : Node_Id;
2435 Delta_Loc := Token_Ptr;
2437 Delta_Node := P_Expression_No_Right_Paren;
2438 Check_Simple_Expression_In_Ada_83 (Delta_Node);
2440 if Token = Tok_Digits then
2441 if Ada_Version = Ada_83 then
2442 Error_Msg_SC ("(Ada 83) decimal fixed type not allowed!");
2445 Def_Node := New_Node (N_Decimal_Fixed_Point_Definition, Delta_Loc);
2446 Scan; -- past DIGITS
2447 Expr_Node := P_Expression_No_Right_Paren;
2448 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2449 Set_Digits_Expression (Def_Node, Expr_Node);
2452 Def_Node := New_Node (N_Ordinary_Fixed_Point_Definition, Delta_Loc);
2454 -- Range is required in ordinary fixed point case
2456 if Token /= Tok_Range then
2457 Error_Msg_AP ("range must be given for fixed-point type");
2462 Set_Delta_Expression (Def_Node, Delta_Node);
2463 Set_Real_Range_Specification (Def_Node, P_Real_Range_Specification_Opt);
2465 end P_Fixed_Point_Definition;
2467 --------------------------------------------
2468 -- 3.5.9 Ordinary Fixed Point Definition --
2469 --------------------------------------------
2471 -- Parsed by P_Fixed_Point_Definition (3.5.9)
2473 -------------------------------------------
2474 -- 3.5.9 Decimal Fixed Point Definition --
2475 -------------------------------------------
2477 -- Parsed by P_Decimal_Point_Definition (3.5.9)
2479 ------------------------------
2480 -- 3.5.9 Digits Constraint --
2481 ------------------------------
2483 -- DIGITS_CONSTRAINT ::=
2484 -- digits static_EXPRESSION [RANGE_CONSTRAINT]
2486 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2488 -- The caller has checked that the initial token is DIGITS
2490 function P_Digits_Constraint return Node_Id is
2491 Constraint_Node : Node_Id;
2492 Expr_Node : Node_Id;
2495 Constraint_Node := New_Node (N_Digits_Constraint, Token_Ptr);
2496 Scan; -- past DIGITS
2497 Expr_Node := P_Expression;
2498 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2499 Set_Digits_Expression (Constraint_Node, Expr_Node);
2501 if Token = Tok_Range then
2502 Set_Range_Constraint (Constraint_Node, P_Range_Constraint);
2505 return Constraint_Node;
2506 end P_Digits_Constraint;
2508 -----------------------------
2509 -- 3.5.9 Delta Constraint --
2510 -----------------------------
2512 -- DELTA CONSTRAINT ::= DELTA STATIC_EXPRESSION [RANGE_CONSTRAINT]
2514 -- Note: this is an obsolescent feature in Ada 95 (I.3)
2516 -- Note: in Ada 83, the EXPRESSION must be a SIMPLE_EXPRESSION
2518 -- The caller has checked that the initial token is DELTA
2520 -- Error recovery: cannot raise Error_Resync
2522 function P_Delta_Constraint return Node_Id is
2523 Constraint_Node : Node_Id;
2524 Expr_Node : Node_Id;
2527 Constraint_Node := New_Node (N_Delta_Constraint, Token_Ptr);
2529 Expr_Node := P_Expression;
2530 Check_Simple_Expression_In_Ada_83 (Expr_Node);
2531 Set_Delta_Expression (Constraint_Node, Expr_Node);
2533 if Token = Tok_Range then
2534 Set_Range_Constraint (Constraint_Node, P_Range_Constraint);
2537 return Constraint_Node;
2538 end P_Delta_Constraint;
2540 --------------------------------
2541 -- 3.6 Array Type Definition --
2542 --------------------------------
2544 -- ARRAY_TYPE_DEFINITION ::=
2545 -- UNCONSTRAINED_ARRAY_DEFINITION | CONSTRAINED_ARRAY_DEFINITION
2547 -- UNCONSTRAINED_ARRAY_DEFINITION ::=
2548 -- array (INDEX_SUBTYPE_DEFINITION {, INDEX_SUBTYPE_DEFINITION}) of
2549 -- COMPONENT_DEFINITION
2551 -- INDEX_SUBTYPE_DEFINITION ::= SUBTYPE_MARK range <>
2553 -- CONSTRAINED_ARRAY_DEFINITION ::=
2554 -- array (DISCRETE_SUBTYPE_DEFINITION {, DISCRETE_SUBTYPE_DEFINITION}) of
2555 -- COMPONENT_DEFINITION
2557 -- DISCRETE_SUBTYPE_DEFINITION ::=
2558 -- DISCRETE_SUBTYPE_INDICATION | RANGE
2560 -- COMPONENT_DEFINITION ::=
2561 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
2563 -- The caller has checked that the initial token is ARRAY
2565 -- Error recovery: can raise Error_Resync
2567 function P_Array_Type_Definition return Node_Id is
2568 Array_Loc : Source_Ptr;
2569 CompDef_Node : Node_Id;
2571 Not_Null_Present : Boolean := False;
2572 Subs_List : List_Id;
2573 Scan_State : Saved_Scan_State;
2574 Aliased_Present : Boolean := False;
2577 Array_Loc := Token_Ptr;
2579 Subs_List := New_List;
2582 -- It's quite tricky to disentangle these two possibilities, so we do
2583 -- a prescan to determine which case we have and then reset the scan.
2584 -- The prescan skips past possible subtype mark tokens.
2586 Save_Scan_State (Scan_State); -- just after paren
2588 while Token in Token_Class_Desig or else
2589 Token = Tok_Dot or else
2590 Token = Tok_Apostrophe -- because of 'BASE, 'CLASS
2595 -- If we end up on RANGE <> then we have the unconstrained case. We
2596 -- will also allow the RANGE to be omitted, just to improve error
2597 -- handling for a case like array (integer <>) of integer;
2599 Scan; -- past possible RANGE or <>
2601 if (Prev_Token = Tok_Range and then Token = Tok_Box) or else
2602 Prev_Token = Tok_Box
2604 Def_Node := New_Node (N_Unconstrained_Array_Definition, Array_Loc);
2605 Restore_Scan_State (Scan_State); -- to first subtype mark
2608 Append (P_Subtype_Mark_Resync, Subs_List);
2611 exit when Token = Tok_Right_Paren or else Token = Tok_Of;
2615 Set_Subtype_Marks (Def_Node, Subs_List);
2618 Def_Node := New_Node (N_Constrained_Array_Definition, Array_Loc);
2619 Restore_Scan_State (Scan_State); -- to first discrete range
2622 Append (P_Discrete_Subtype_Definition, Subs_List);
2623 exit when not Comma_Present;
2626 Set_Discrete_Subtype_Definitions (Def_Node, Subs_List);
2632 CompDef_Node := New_Node (N_Component_Definition, Token_Ptr);
2634 if Token_Name = Name_Aliased then
2635 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
2638 if Token = Tok_Aliased then
2639 Aliased_Present := True;
2640 Scan; -- past ALIASED
2643 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/AI-254)
2645 -- Ada 2005 (AI-230): Access Definition case
2647 if Token = Tok_Access then
2648 if Ada_Version < Ada_2005 then
2650 ("generalized use of anonymous access types " &
2651 "is an Ada 2005 extension");
2652 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
2655 if Aliased_Present then
2656 Error_Msg_SP ("ALIASED not allowed here");
2659 Set_Subtype_Indication (CompDef_Node, Empty);
2660 Set_Aliased_Present (CompDef_Node, False);
2661 Set_Access_Definition (CompDef_Node,
2662 P_Access_Definition (Not_Null_Present));
2665 Set_Access_Definition (CompDef_Node, Empty);
2666 Set_Aliased_Present (CompDef_Node, Aliased_Present);
2667 Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present);
2668 Set_Subtype_Indication (CompDef_Node,
2669 P_Subtype_Indication (Not_Null_Present));
2672 Set_Component_Definition (Def_Node, CompDef_Node);
2675 end P_Array_Type_Definition;
2677 -----------------------------------------
2678 -- 3.6 Unconstrained Array Definition --
2679 -----------------------------------------
2681 -- Parsed by P_Array_Type_Definition (3.6)
2683 ---------------------------------------
2684 -- 3.6 Constrained Array Definition --
2685 ---------------------------------------
2687 -- Parsed by P_Array_Type_Definition (3.6)
2689 --------------------------------------
2690 -- 3.6 Discrete Subtype Definition --
2691 --------------------------------------
2693 -- DISCRETE_SUBTYPE_DEFINITION ::=
2694 -- discrete_SUBTYPE_INDICATION | RANGE
2696 -- Note: the discrete subtype definition appearing in a constrained
2697 -- array definition is parsed by P_Array_Type_Definition (3.6)
2699 -- Error recovery: cannot raise Error_Resync
2701 function P_Discrete_Subtype_Definition return Node_Id is
2703 -- The syntax of a discrete subtype definition is identical to that
2704 -- of a discrete range, so we simply share the same parsing code.
2706 return P_Discrete_Range;
2707 end P_Discrete_Subtype_Definition;
2709 -------------------------------
2710 -- 3.6 Component Definition --
2711 -------------------------------
2713 -- For the array case, parsed by P_Array_Type_Definition (3.6)
2714 -- For the record case, parsed by P_Component_Declaration (3.8)
2716 -----------------------------
2717 -- 3.6.1 Index Constraint --
2718 -----------------------------
2720 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2722 ---------------------------
2723 -- 3.6.1 Discrete Range --
2724 ---------------------------
2726 -- DISCRETE_RANGE ::= discrete_SUBTYPE_INDICATION | RANGE
2728 -- The possible forms for a discrete range are:
2730 -- Subtype_Mark (SUBTYPE_INDICATION, 3.2.2)
2731 -- Subtype_Mark range Range (SUBTYPE_INDICATION, 3.2.2)
2732 -- Range_Attribute (RANGE, 3.5)
2733 -- Simple_Expression .. Simple_Expression (RANGE, 3.5)
2735 -- Error recovery: cannot raise Error_Resync
2737 function P_Discrete_Range return Node_Id is
2738 Expr_Node : Node_Id;
2739 Range_Node : Node_Id;
2742 Expr_Node := P_Simple_Expression_Or_Range_Attribute;
2744 if Expr_Form = EF_Range_Attr then
2747 elsif Token = Tok_Range then
2748 if Expr_Form /= EF_Simple_Name then
2749 Error_Msg_SC ("range must be preceded by subtype mark");
2752 return P_Subtype_Indication (Expr_Node);
2754 -- Check Expression .. Expression case
2756 elsif Token = Tok_Dot_Dot then
2757 Range_Node := New_Node (N_Range, Token_Ptr);
2758 Set_Low_Bound (Range_Node, Expr_Node);
2760 Expr_Node := P_Expression;
2761 Check_Simple_Expression (Expr_Node);
2762 Set_High_Bound (Range_Node, Expr_Node);
2765 -- Otherwise we must have a subtype mark
2767 elsif Expr_Form = EF_Simple_Name then
2770 -- If incorrect, complain that we expect ..
2776 end P_Discrete_Range;
2778 ----------------------------
2779 -- 3.7 Discriminant Part --
2780 ----------------------------
2782 -- DISCRIMINANT_PART ::=
2783 -- UNKNOWN_DISCRIMINANT_PART
2784 -- | KNOWN_DISCRIMINANT_PART
2786 -- A discriminant part is parsed by P_Known_Discriminant_Part_Opt (3.7)
2787 -- or P_Unknown_Discriminant_Part (3.7), since we know which we want.
2789 ------------------------------------
2790 -- 3.7 Unknown Discriminant Part --
2791 ------------------------------------
2793 -- UNKNOWN_DISCRIMINANT_PART ::= (<>)
2795 -- If no unknown discriminant part is present, then False is returned,
2796 -- otherwise the unknown discriminant is scanned out and True is returned.
2798 -- Error recovery: cannot raise Error_Resync
2800 function P_Unknown_Discriminant_Part_Opt return Boolean is
2801 Scan_State : Saved_Scan_State;
2804 -- If <> right now, then this is missing left paren
2806 if Token = Tok_Box then
2809 -- If not <> or left paren, then definitely no box
2811 elsif Token /= Tok_Left_Paren then
2814 -- Left paren, so might be a box after it
2817 Save_Scan_State (Scan_State);
2818 Scan; -- past the left paren
2820 if Token /= Tok_Box then
2821 Restore_Scan_State (Scan_State);
2826 -- We are now pointing to the box
2828 if Ada_Version = Ada_83 then
2829 Error_Msg_SC ("(Ada 83) unknown discriminant not allowed!");
2832 Scan; -- past the box
2833 U_Right_Paren; -- must be followed by right paren
2835 end P_Unknown_Discriminant_Part_Opt;
2837 ----------------------------------
2838 -- 3.7 Known Discriminant Part --
2839 ----------------------------------
2841 -- KNOWN_DISCRIMINANT_PART ::=
2842 -- (DISCRIMINANT_SPECIFICATION {; DISCRIMINANT_SPECIFICATION})
2844 -- DISCRIMINANT_SPECIFICATION ::=
2845 -- DEFINING_IDENTIFIER_LIST : [NULL_EXCLUSION] SUBTYPE_MARK
2846 -- [:= DEFAULT_EXPRESSION]
2847 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
2848 -- [:= DEFAULT_EXPRESSION]
2850 -- If no known discriminant part is present, then No_List is returned
2852 -- Error recovery: cannot raise Error_Resync
2854 function P_Known_Discriminant_Part_Opt return List_Id is
2855 Specification_Node : Node_Id;
2856 Specification_List : List_Id;
2857 Ident_Sloc : Source_Ptr;
2858 Scan_State : Saved_Scan_State;
2860 Not_Null_Present : Boolean;
2863 Idents : array (Int range 1 .. 4096) of Entity_Id;
2864 -- This array holds the list of defining identifiers. The upper bound
2865 -- of 4096 is intended to be essentially infinite, and we do not even
2866 -- bother to check for it being exceeded.
2869 if Token = Tok_Left_Paren then
2870 Specification_List := New_List;
2872 P_Pragmas_Misplaced;
2874 Specification_Loop : loop
2876 Ident_Sloc := Token_Ptr;
2877 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
2880 while Comma_Present loop
2881 Num_Idents := Num_Idents + 1;
2882 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
2885 -- If there are multiple identifiers, we repeatedly scan the
2886 -- type and initialization expression information by resetting
2887 -- the scan pointer (so that we get completely separate trees
2888 -- for each occurrence).
2890 if Num_Idents > 1 then
2891 Save_Scan_State (Scan_State);
2896 -- Loop through defining identifiers in list
2900 Specification_Node :=
2901 New_Node (N_Discriminant_Specification, Ident_Sloc);
2902 Set_Defining_Identifier (Specification_Node, Idents (Ident));
2903 Not_Null_Present := -- Ada 2005 (AI-231, AI-447)
2904 P_Null_Exclusion (Allow_Anonymous_In_95 => True);
2906 if Token = Tok_Access then
2907 if Ada_Version = Ada_83 then
2909 ("(Ada 83) access discriminant not allowed!");
2912 Set_Discriminant_Type
2913 (Specification_Node,
2914 P_Access_Definition (Not_Null_Present));
2917 Set_Discriminant_Type
2918 (Specification_Node, P_Subtype_Mark);
2920 Set_Null_Exclusion_Present -- Ada 2005 (AI-231)
2921 (Specification_Node, Not_Null_Present);
2925 (Specification_Node, Init_Expr_Opt (True));
2928 Set_Prev_Ids (Specification_Node, True);
2931 if Ident < Num_Idents then
2932 Set_More_Ids (Specification_Node, True);
2935 Append (Specification_Node, Specification_List);
2936 exit Ident_Loop when Ident = Num_Idents;
2938 Restore_Scan_State (Scan_State);
2940 end loop Ident_Loop;
2942 exit Specification_Loop when Token /= Tok_Semicolon;
2944 P_Pragmas_Misplaced;
2945 end loop Specification_Loop;
2948 return Specification_List;
2953 end P_Known_Discriminant_Part_Opt;
2955 -------------------------------------
2956 -- 3.7 Discriminant Specification --
2957 -------------------------------------
2959 -- Parsed by P_Known_Discriminant_Part_Opt (3.7)
2961 -----------------------------
2962 -- 3.7 Default Expression --
2963 -----------------------------
2965 -- Always parsed (simply as an Expression) by the parent construct
2967 ------------------------------------
2968 -- 3.7.1 Discriminant Constraint --
2969 ------------------------------------
2971 -- Parsed by P_Index_Or_Discriminant_Constraint (3.7.1)
2973 --------------------------------------------------------
2974 -- 3.7.1 Index or Discriminant Constraint (also 3.6) --
2975 --------------------------------------------------------
2977 -- DISCRIMINANT_CONSTRAINT ::=
2978 -- (DISCRIMINANT_ASSOCIATION {, DISCRIMINANT_ASSOCIATION})
2980 -- DISCRIMINANT_ASSOCIATION ::=
2981 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
2984 -- This routine parses either an index or a discriminant constraint. As
2985 -- is clear from the above grammar, it is often possible to clearly
2986 -- determine which of the two possibilities we have, but there are
2987 -- cases (those in which we have a series of expressions of the same
2988 -- syntactic form as subtype indications), where we cannot tell. Since
2989 -- this means that in any case the semantic phase has to distinguish
2990 -- between the two, there is not much point in the parser trying to
2991 -- distinguish even those cases where the difference is clear. In any
2992 -- case, if we have a situation like:
2994 -- (A => 123, 235 .. 500)
2996 -- it is not clear which of the two items is the wrong one, better to
2997 -- let the semantic phase give a clear message. Consequently, this
2998 -- routine in general returns a list of items which can be either
2999 -- discrete ranges or discriminant associations.
3001 -- The caller has checked that the initial token is a left paren
3003 -- Error recovery: can raise Error_Resync
3005 function P_Index_Or_Discriminant_Constraint return Node_Id is
3006 Scan_State : Saved_Scan_State;
3007 Constr_Node : Node_Id;
3008 Constr_List : List_Id;
3009 Expr_Node : Node_Id;
3010 Result_Node : Node_Id;
3013 Result_Node := New_Node (N_Index_Or_Discriminant_Constraint, Token_Ptr);
3015 Constr_List := New_List;
3016 Set_Constraints (Result_Node, Constr_List);
3018 -- The two syntactic forms are a little mixed up, so what we are doing
3019 -- here is looking at the first entry to determine which case we have
3021 -- A discriminant constraint is a list of discriminant associations,
3022 -- which have one of the following possible forms:
3026 -- Id | Id | .. | Id => Expression
3028 -- An index constraint is a list of discrete ranges which have one
3029 -- of the following possible forms:
3032 -- Subtype_Mark range Range
3034 -- Simple_Expression .. Simple_Expression
3036 -- Loop through discriminants in list
3039 -- Check cases of Id => Expression or Id | Id => Expression
3041 if Token = Tok_Identifier then
3042 Save_Scan_State (Scan_State); -- at Id
3045 if Token = Tok_Arrow or else Token = Tok_Vertical_Bar then
3046 Restore_Scan_State (Scan_State); -- to Id
3047 Append (P_Discriminant_Association, Constr_List);
3050 Restore_Scan_State (Scan_State); -- to Id
3054 -- Otherwise scan out an expression and see what we have got
3056 Expr_Node := P_Expression_Or_Range_Attribute;
3058 if Expr_Form = EF_Range_Attr then
3059 Append (Expr_Node, Constr_List);
3061 elsif Token = Tok_Range then
3062 if Expr_Form /= EF_Simple_Name then
3063 Error_Msg_SC ("subtype mark required before RANGE");
3066 Append (P_Subtype_Indication (Expr_Node), Constr_List);
3069 -- Check Simple_Expression .. Simple_Expression case
3071 elsif Token = Tok_Dot_Dot then
3072 Check_Simple_Expression (Expr_Node);
3073 Constr_Node := New_Node (N_Range, Token_Ptr);
3074 Set_Low_Bound (Constr_Node, Expr_Node);
3076 Expr_Node := P_Expression;
3077 Check_Simple_Expression (Expr_Node);
3078 Set_High_Bound (Constr_Node, Expr_Node);
3079 Append (Constr_Node, Constr_List);
3082 -- Case of an expression which could be either form
3085 Append (Expr_Node, Constr_List);
3089 -- Here with a single entry scanned
3092 exit when not Comma_Present;
3098 end P_Index_Or_Discriminant_Constraint;
3100 -------------------------------------
3101 -- 3.7.1 Discriminant Association --
3102 -------------------------------------
3104 -- DISCRIMINANT_ASSOCIATION ::=
3105 -- [discriminant_SELECTOR_NAME {| discriminant_SELECTOR_NAME} =>]
3108 -- This routine is used only when the name list is present and the caller
3109 -- has already checked this (by scanning ahead and repositioning the
3112 -- Error_Recovery: cannot raise Error_Resync;
3114 function P_Discriminant_Association return Node_Id is
3115 Discr_Node : Node_Id;
3116 Names_List : List_Id;
3117 Ident_Sloc : Source_Ptr;
3120 Ident_Sloc := Token_Ptr;
3121 Names_List := New_List;
3124 Append (P_Identifier (C_Vertical_Bar_Arrow), Names_List);
3125 exit when Token /= Tok_Vertical_Bar;
3129 Discr_Node := New_Node (N_Discriminant_Association, Ident_Sloc);
3130 Set_Selector_Names (Discr_Node, Names_List);
3132 Set_Expression (Discr_Node, P_Expression);
3134 end P_Discriminant_Association;
3136 ---------------------------------
3137 -- 3.8 Record Type Definition --
3138 ---------------------------------
3140 -- RECORD_TYPE_DEFINITION ::=
3141 -- [[abstract] tagged] [limited] RECORD_DEFINITION
3143 -- There is no node in the tree for a record type definition. Instead
3144 -- a record definition node appears, with possible Abstract_Present,
3145 -- Tagged_Present, and Limited_Present flags set appropriately.
3147 ----------------------------
3148 -- 3.8 Record Definition --
3149 ----------------------------
3151 -- RECORD_DEFINITION ::=
3157 -- Note: in the case where a record definition node is used to represent
3158 -- a record type definition, the caller sets the Tagged_Present and
3159 -- Limited_Present flags in the resulting N_Record_Definition node as
3162 -- Note that the RECORD token at the start may be missing in certain
3163 -- error situations, so this function is expected to post the error
3165 -- Error recovery: can raise Error_Resync
3167 function P_Record_Definition return Node_Id is
3171 Rec_Node := New_Node (N_Record_Definition, Token_Ptr);
3175 if Token = Tok_Null then
3178 Set_Null_Present (Rec_Node, True);
3180 -- Catch incomplete declaration to prevent cascaded errors, see
3181 -- ACATS B393002 for an example.
3183 elsif Token = Tok_Semicolon then
3184 Error_Msg_AP ("missing record definition");
3186 -- Case starting with RECORD keyword. Build scope stack entry. For the
3187 -- column, we use the first non-blank character on the line, to deal
3188 -- with situations such as:
3194 -- which is not official RM indentation, but is not uncommon usage, and
3195 -- in particular is standard GNAT coding style, so handle it nicely.
3199 Scope.Table (Scope.Last).Etyp := E_Record;
3200 Scope.Table (Scope.Last).Ecol := Start_Column;
3201 Scope.Table (Scope.Last).Sloc := Token_Ptr;
3202 Scope.Table (Scope.Last).Labl := Error;
3203 Scope.Table (Scope.Last).Junk := (Token /= Tok_Record);
3207 Set_Component_List (Rec_Node, P_Component_List);
3210 exit when Check_End;
3211 Discard_Junk_Node (P_Component_List);
3216 end P_Record_Definition;
3218 -------------------------
3219 -- 3.8 Component List --
3220 -------------------------
3222 -- COMPONENT_LIST ::=
3223 -- COMPONENT_ITEM {COMPONENT_ITEM}
3224 -- | {COMPONENT_ITEM} VARIANT_PART
3227 -- Error recovery: cannot raise Error_Resync
3229 function P_Component_List return Node_Id is
3230 Component_List_Node : Node_Id;
3231 Decls_List : List_Id;
3232 Scan_State : Saved_Scan_State;
3235 Component_List_Node := New_Node (N_Component_List, Token_Ptr);
3236 Decls_List := New_List;
3238 if Token = Tok_Null then
3241 P_Pragmas_Opt (Decls_List);
3242 Set_Null_Present (Component_List_Node, True);
3243 return Component_List_Node;
3246 P_Pragmas_Opt (Decls_List);
3248 if Token /= Tok_Case then
3249 Component_Scan_Loop : loop
3250 P_Component_Items (Decls_List);
3251 P_Pragmas_Opt (Decls_List);
3253 exit Component_Scan_Loop when Token = Tok_End
3254 or else Token = Tok_Case
3255 or else Token = Tok_When;
3257 -- We are done if we do not have an identifier. However, if
3258 -- we have a misspelled reserved identifier that is in a column
3259 -- to the right of the record definition, we will treat it as
3260 -- an identifier. It turns out to be too dangerous in practice
3261 -- to accept such a mis-spelled identifier which does not have
3262 -- this additional clue that confirms the incorrect spelling.
3264 if Token /= Tok_Identifier then
3265 if Start_Column > Scope.Table (Scope.Last).Ecol
3266 and then Is_Reserved_Identifier
3268 Save_Scan_State (Scan_State); -- at reserved id
3269 Scan; -- possible reserved id
3271 if Token = Tok_Comma or else Token = Tok_Colon then
3272 Restore_Scan_State (Scan_State);
3273 Scan_Reserved_Identifier (Force_Msg => True);
3275 -- Note reserved identifier used as field name after
3276 -- all because not followed by colon or comma
3279 Restore_Scan_State (Scan_State);
3280 exit Component_Scan_Loop;
3283 -- Non-identifier that definitely was not reserved id
3286 exit Component_Scan_Loop;
3289 end loop Component_Scan_Loop;
3292 if Token = Tok_Case then
3293 Set_Variant_Part (Component_List_Node, P_Variant_Part);
3295 -- Check for junk after variant part
3297 if Token = Tok_Identifier then
3298 Save_Scan_State (Scan_State);
3299 Scan; -- past identifier
3301 if Token = Tok_Colon then
3302 Restore_Scan_State (Scan_State);
3303 Error_Msg_SC ("component may not follow variant part");
3304 Discard_Junk_Node (P_Component_List);
3306 elsif Token = Tok_Case then
3307 Restore_Scan_State (Scan_State);
3308 Error_Msg_SC ("only one variant part allowed in a record");
3309 Discard_Junk_Node (P_Component_List);
3312 Restore_Scan_State (Scan_State);
3318 Set_Component_Items (Component_List_Node, Decls_List);
3319 return Component_List_Node;
3320 end P_Component_List;
3322 -------------------------
3323 -- 3.8 Component Item --
3324 -------------------------
3326 -- COMPONENT_ITEM ::= COMPONENT_DECLARATION | REPRESENTATION_CLAUSE
3328 -- COMPONENT_DECLARATION ::=
3329 -- DEFINING_IDENTIFIER_LIST : COMPONENT_DEFINITION
3330 -- [:= DEFAULT_EXPRESSION]
3331 -- [ASPECT_SPECIFICATIONS];
3333 -- COMPONENT_DEFINITION ::=
3334 -- [aliased] [NULL_EXCLUSION] SUBTYPE_INDICATION | ACCESS_DEFINITION
3336 -- Error recovery: cannot raise Error_Resync, if an error occurs,
3337 -- the scan is positioned past the following semicolon.
3339 -- Note: we do not yet allow representation clauses to appear as component
3340 -- items, do we need to add this capability sometime in the future ???
3342 procedure P_Component_Items (Decls : List_Id) is
3343 Aliased_Present : Boolean := False;
3344 CompDef_Node : Node_Id;
3345 Decl_Node : Node_Id;
3346 Scan_State : Saved_Scan_State;
3347 Not_Null_Present : Boolean := False;
3350 Ident_Sloc : Source_Ptr;
3352 Idents : array (Int range 1 .. 4096) of Entity_Id;
3353 -- This array holds the list of defining identifiers. The upper bound
3354 -- of 4096 is intended to be essentially infinite, and we do not even
3355 -- bother to check for it being exceeded.
3358 if Token /= Tok_Identifier then
3359 Error_Msg_SC ("component declaration expected");
3360 Resync_Past_Semicolon;
3364 Ident_Sloc := Token_Ptr;
3365 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
3368 while Comma_Present loop
3369 Num_Idents := Num_Idents + 1;
3370 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
3373 -- If there are multiple identifiers, we repeatedly scan the
3374 -- type and initialization expression information by resetting
3375 -- the scan pointer (so that we get completely separate trees
3376 -- for each occurrence).
3378 if Num_Idents > 1 then
3379 Save_Scan_State (Scan_State);
3384 -- Loop through defining identifiers in list
3389 -- The following block is present to catch Error_Resync
3390 -- which causes the parse to be reset past the semicolon
3393 Decl_Node := New_Node (N_Component_Declaration, Ident_Sloc);
3394 Set_Defining_Identifier (Decl_Node, Idents (Ident));
3396 if Token = Tok_Constant then
3397 Error_Msg_SC ("constant components are not permitted");
3401 CompDef_Node := New_Node (N_Component_Definition, Token_Ptr);
3403 if Token_Name = Name_Aliased then
3404 Check_95_Keyword (Tok_Aliased, Tok_Identifier);
3407 if Token = Tok_Aliased then
3408 Aliased_Present := True;
3409 Scan; -- past ALIASED
3412 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231/AI-254)
3414 -- Ada 2005 (AI-230): Access Definition case
3416 if Token = Tok_Access then
3417 if Ada_Version < Ada_2005 then
3419 ("generalized use of anonymous access types " &
3420 "is an Ada 2005 extension");
3421 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
3424 if Aliased_Present then
3425 Error_Msg_SP ("ALIASED not allowed here");
3428 Set_Subtype_Indication (CompDef_Node, Empty);
3429 Set_Aliased_Present (CompDef_Node, False);
3430 Set_Access_Definition (CompDef_Node,
3431 P_Access_Definition (Not_Null_Present));
3434 Set_Access_Definition (CompDef_Node, Empty);
3435 Set_Aliased_Present (CompDef_Node, Aliased_Present);
3436 Set_Null_Exclusion_Present (CompDef_Node, Not_Null_Present);
3438 if Token = Tok_Array then
3439 Error_Msg_SC ("anonymous arrays not allowed as components");
3443 Set_Subtype_Indication (CompDef_Node,
3444 P_Subtype_Indication (Not_Null_Present));
3447 Set_Component_Definition (Decl_Node, CompDef_Node);
3448 Set_Expression (Decl_Node, Init_Expr_Opt);
3451 Set_Prev_Ids (Decl_Node, True);
3454 if Ident < Num_Idents then
3455 Set_More_Ids (Decl_Node, True);
3458 Append (Decl_Node, Decls);
3461 when Error_Resync =>
3462 if Token /= Tok_End then
3463 Resync_Past_Semicolon;
3467 exit Ident_Loop when Ident = Num_Idents;
3469 Restore_Scan_State (Scan_State);
3471 end loop Ident_Loop;
3473 P_Aspect_Specifications (Decl_Node);
3474 end P_Component_Items;
3476 --------------------------------
3477 -- 3.8 Component Declaration --
3478 --------------------------------
3480 -- Parsed by P_Component_Items (3.8)
3482 -------------------------
3483 -- 3.8.1 Variant Part --
3484 -------------------------
3487 -- case discriminant_DIRECT_NAME is
3492 -- The caller has checked that the initial token is CASE
3494 -- Error recovery: cannot raise Error_Resync
3496 function P_Variant_Part return Node_Id is
3497 Variant_Part_Node : Node_Id;
3498 Variants_List : List_Id;
3499 Case_Node : Node_Id;
3502 Variant_Part_Node := New_Node (N_Variant_Part, Token_Ptr);
3504 Scope.Table (Scope.Last).Etyp := E_Case;
3505 Scope.Table (Scope.Last).Sloc := Token_Ptr;
3506 Scope.Table (Scope.Last).Ecol := Start_Column;
3509 Case_Node := P_Expression;
3510 Set_Name (Variant_Part_Node, Case_Node);
3512 if Nkind (Case_Node) /= N_Identifier then
3513 Set_Name (Variant_Part_Node, Error);
3514 Error_Msg ("discriminant name expected", Sloc (Case_Node));
3516 elsif Paren_Count (Case_Node) /= 0 then
3518 ("|discriminant name may not be parenthesized",
3520 Set_Paren_Count (Case_Node, 0);
3524 Variants_List := New_List;
3525 P_Pragmas_Opt (Variants_List);
3527 -- Test missing variant
3529 if Token = Tok_End then
3530 Error_Msg_BC ("WHEN expected (must have at least one variant)");
3532 Append (P_Variant, Variants_List);
3535 -- Loop through variants, note that we allow if in place of when,
3536 -- this error will be detected and handled in P_Variant.
3539 P_Pragmas_Opt (Variants_List);
3541 if Token /= Tok_When
3542 and then Token /= Tok_If
3543 and then Token /= Tok_Others
3545 exit when Check_End;
3548 Append (P_Variant, Variants_List);
3551 Set_Variants (Variant_Part_Node, Variants_List);
3552 return Variant_Part_Node;
3555 --------------------
3557 --------------------
3560 -- when DISCRETE_CHOICE_LIST =>
3563 -- Error recovery: cannot raise Error_Resync
3565 -- The initial token on entry is either WHEN, IF or OTHERS
3567 function P_Variant return Node_Id is
3568 Variant_Node : Node_Id;
3571 -- Special check to recover nicely from use of IF in place of WHEN
3573 if Token = Tok_If then
3580 Variant_Node := New_Node (N_Variant, Prev_Token_Ptr);
3581 Set_Discrete_Choices (Variant_Node, P_Discrete_Choice_List);
3583 Set_Component_List (Variant_Node, P_Component_List);
3584 return Variant_Node;
3587 ---------------------------------
3588 -- 3.8.1 Discrete Choice List --
3589 ---------------------------------
3591 -- DISCRETE_CHOICE_LIST ::= DISCRETE_CHOICE {| DISCRETE_CHOICE}
3593 -- DISCRETE_CHOICE ::= EXPRESSION | DISCRETE_RANGE | others
3595 -- Note: in Ada 83, the expression must be a simple expression
3597 -- Error recovery: cannot raise Error_Resync
3599 function P_Discrete_Choice_List return List_Id is
3601 Expr_Node : Node_Id;
3602 Choice_Node : Node_Id;
3605 Choices := New_List;
3607 if Token = Tok_Others then
3608 Append (New_Node (N_Others_Choice, Token_Ptr), Choices);
3609 Scan; -- past OTHERS
3613 -- Scan out expression or range attribute
3615 Expr_Node := P_Expression_Or_Range_Attribute;
3616 Ignore (Tok_Right_Paren);
3618 if Token = Tok_Colon
3619 and then Nkind (Expr_Node) = N_Identifier
3621 Error_Msg_SP ("label not permitted in this context");
3626 elsif Expr_Form = EF_Range_Attr then
3627 Append (Expr_Node, Choices);
3631 elsif Token = Tok_Dot_Dot then
3632 Check_Simple_Expression (Expr_Node);
3633 Choice_Node := New_Node (N_Range, Token_Ptr);
3634 Set_Low_Bound (Choice_Node, Expr_Node);
3636 Expr_Node := P_Expression_No_Right_Paren;
3637 Check_Simple_Expression (Expr_Node);
3638 Set_High_Bound (Choice_Node, Expr_Node);
3639 Append (Choice_Node, Choices);
3641 -- Simple name, must be subtype, so range allowed
3643 elsif Expr_Form = EF_Simple_Name then
3644 if Token = Tok_Range then
3645 Append (P_Subtype_Indication (Expr_Node), Choices);
3647 elsif Token in Token_Class_Consk then
3649 ("the only constraint allowed here " &
3650 "is a range constraint");
3651 Discard_Junk_Node (P_Constraint_Opt);
3652 Append (Expr_Node, Choices);
3655 Append (Expr_Node, Choices);
3661 -- In Ada 2012 mode, the expression must be a simple
3662 -- expression. The resaon for this restriction (i.e. going
3663 -- back to the Ada 83 rule) is to avoid ambiguities when set
3664 -- membership operations are allowed, consider the
3667 -- when A in 1 .. 10 | 12 =>
3669 -- This is ambiguous without parentheses, so we require one
3670 -- of the following two parenthesized forms to disambuguate:
3672 -- one of the following:
3674 -- when (A in 1 .. 10 | 12) =>
3675 -- when (A in 1 .. 10) | 12 =>
3677 -- To solve this, in Ada 2012 mode, we disallow the use of
3678 -- membership operations in expressions in choices.
3680 -- Technically in the grammar, the expression must match the
3681 -- grammar for restricted expression.
3683 if Ada_Version >= Ada_2012 then
3684 Check_Restricted_Expression (Expr_Node);
3686 -- In Ada 83 mode, the syntax required a simple expression
3689 Check_Simple_Expression_In_Ada_83 (Expr_Node);
3692 Append (Expr_Node, Choices);
3696 when Error_Resync =>
3702 if Token = Tok_Comma then
3703 Error_Msg_SC -- CODEFIX
3704 (""","" should be ""'|""");
3706 exit when Token /= Tok_Vertical_Bar;
3709 Scan; -- past | or comma
3713 end P_Discrete_Choice_List;
3715 ----------------------------
3716 -- 3.8.1 Discrete Choice --
3717 ----------------------------
3719 -- Parsed by P_Discrete_Choice_List (3.8.1)
3721 ----------------------------------
3722 -- 3.9.1 Record Extension Part --
3723 ----------------------------------
3725 -- RECORD_EXTENSION_PART ::= with RECORD_DEFINITION
3727 -- Parsed by P_Derived_Type_Def_Or_Private_Ext_Decl (3.4)
3729 --------------------------------------
3730 -- 3.9.4 Interface Type Definition --
3731 --------------------------------------
3733 -- INTERFACE_TYPE_DEFINITION ::=
3734 -- [limited | task | protected | synchronized] interface
3735 -- [and INTERFACE_LIST]
3737 -- Error recovery: cannot raise Error_Resync
3739 function P_Interface_Type_Definition
3740 (Abstract_Present : Boolean) return Node_Id
3742 Typedef_Node : Node_Id;
3745 if Ada_Version < Ada_2005 then
3746 Error_Msg_SP ("abstract interface is an Ada 2005 extension");
3747 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
3750 if Abstract_Present then
3752 ("ABSTRACT not allowed in interface type definition " &
3756 Scan; -- past INTERFACE
3758 -- Ada 2005 (AI-345): In case of interfaces with a null list of
3759 -- interfaces we build a record_definition node.
3761 if Token = Tok_Semicolon then
3762 Typedef_Node := New_Node (N_Record_Definition, Token_Ptr);
3764 Set_Abstract_Present (Typedef_Node);
3765 Set_Tagged_Present (Typedef_Node);
3766 Set_Null_Present (Typedef_Node);
3767 Set_Interface_Present (Typedef_Node);
3769 -- Ada 2005 (AI-251): In case of not-synchronized interfaces that have
3770 -- a list of interfaces we build a derived_type_definition node. This
3771 -- simplifies the semantic analysis (and hence further maintenance)
3774 if Token /= Tok_And then
3775 Error_Msg_AP ("AND expected");
3780 Typedef_Node := New_Node (N_Derived_Type_Definition, Token_Ptr);
3782 Set_Abstract_Present (Typedef_Node);
3783 Set_Interface_Present (Typedef_Node);
3784 Set_Subtype_Indication (Typedef_Node, P_Qualified_Simple_Name);
3786 Set_Record_Extension_Part (Typedef_Node,
3787 New_Node (N_Record_Definition, Token_Ptr));
3788 Set_Null_Present (Record_Extension_Part (Typedef_Node));
3790 if Token = Tok_And then
3791 Set_Interface_List (Typedef_Node, New_List);
3795 Append (P_Qualified_Simple_Name,
3796 Interface_List (Typedef_Node));
3797 exit when Token /= Tok_And;
3803 return Typedef_Node;
3804 end P_Interface_Type_Definition;
3806 ----------------------------------
3807 -- 3.10 Access Type Definition --
3808 ----------------------------------
3810 -- ACCESS_TYPE_DEFINITION ::=
3811 -- ACCESS_TO_OBJECT_DEFINITION
3812 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3814 -- ACCESS_TO_OBJECT_DEFINITION ::=
3815 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_INDICATION
3817 -- GENERAL_ACCESS_MODIFIER ::= all | constant
3819 -- ACCESS_TO_SUBPROGRAM_DEFINITION
3820 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
3821 -- | [NULL_EXCLUSION] access [protected] function
3822 -- PARAMETER_AND_RESULT_PROFILE
3824 -- PARAMETER_PROFILE ::= [FORMAL_PART]
3826 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] RETURN SUBTYPE_MARK
3828 -- Ada 2005 (AI-254): If Header_Already_Parsed then the caller has already
3829 -- parsed the null_exclusion part and has also removed the ACCESS token;
3830 -- otherwise the caller has just checked that the initial token is ACCESS
3832 -- Error recovery: can raise Error_Resync
3834 function P_Access_Type_Definition
3835 (Header_Already_Parsed : Boolean := False) return Node_Id
3837 Access_Loc : constant Source_Ptr := Token_Ptr;
3838 Prot_Flag : Boolean;
3839 Not_Null_Present : Boolean := False;
3840 Type_Def_Node : Node_Id;
3841 Result_Not_Null : Boolean;
3842 Result_Node : Node_Id;
3844 procedure Check_Junk_Subprogram_Name;
3845 -- Used in access to subprogram definition cases to check for an
3846 -- identifier or operator symbol that does not belong.
3848 --------------------------------
3849 -- Check_Junk_Subprogram_Name --
3850 --------------------------------
3852 procedure Check_Junk_Subprogram_Name is
3853 Saved_State : Saved_Scan_State;
3856 if Token = Tok_Identifier or else Token = Tok_Operator_Symbol then
3857 Save_Scan_State (Saved_State);
3858 Scan; -- past possible junk subprogram name
3860 if Token = Tok_Left_Paren or else Token = Tok_Semicolon then
3861 Error_Msg_SP ("unexpected subprogram name ignored");
3865 Restore_Scan_State (Saved_State);
3868 end Check_Junk_Subprogram_Name;
3870 -- Start of processing for P_Access_Type_Definition
3873 if not Header_Already_Parsed then
3874 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
3875 Scan; -- past ACCESS
3878 if Token_Name = Name_Protected then
3879 Check_95_Keyword (Tok_Protected, Tok_Procedure);
3880 Check_95_Keyword (Tok_Protected, Tok_Function);
3883 Prot_Flag := (Token = Tok_Protected);
3886 Scan; -- past PROTECTED
3888 if Token /= Tok_Procedure and then Token /= Tok_Function then
3889 Error_Msg_SC -- CODEFIX
3890 ("FUNCTION or PROCEDURE expected");
3894 if Token = Tok_Procedure then
3895 if Ada_Version = Ada_83 then
3896 Error_Msg_SC ("(Ada 83) access to procedure not allowed!");
3899 Type_Def_Node := New_Node (N_Access_Procedure_Definition, Access_Loc);
3900 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3901 Scan; -- past PROCEDURE
3902 Check_Junk_Subprogram_Name;
3903 Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile);
3904 Set_Protected_Present (Type_Def_Node, Prot_Flag);
3906 elsif Token = Tok_Function then
3907 if Ada_Version = Ada_83 then
3908 Error_Msg_SC ("(Ada 83) access to function not allowed!");
3911 Type_Def_Node := New_Node (N_Access_Function_Definition, Access_Loc);
3912 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3913 Scan; -- past FUNCTION
3914 Check_Junk_Subprogram_Name;
3915 Set_Parameter_Specifications (Type_Def_Node, P_Parameter_Profile);
3916 Set_Protected_Present (Type_Def_Node, Prot_Flag);
3919 Result_Not_Null := P_Null_Exclusion; -- Ada 2005 (AI-231)
3921 -- Ada 2005 (AI-318-02)
3923 if Token = Tok_Access then
3924 if Ada_Version < Ada_2005 then
3926 ("anonymous access result type is an Ada 2005 extension");
3927 Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
3930 Result_Node := P_Access_Definition (Result_Not_Null);
3933 Result_Node := P_Subtype_Mark;
3936 -- A null exclusion on the result type must be recorded in a flag
3937 -- distinct from the one used for the access-to-subprogram type's
3940 Set_Null_Exclusion_In_Return_Present
3941 (Type_Def_Node, Result_Not_Null);
3944 Set_Result_Definition (Type_Def_Node, Result_Node);
3948 New_Node (N_Access_To_Object_Definition, Access_Loc);
3949 Set_Null_Exclusion_Present (Type_Def_Node, Not_Null_Present);
3951 if Token = Tok_All or else Token = Tok_Constant then
3952 if Ada_Version = Ada_83 then
3953 Error_Msg_SC ("(Ada 83) access modifier not allowed!");
3956 if Token = Tok_All then
3957 Set_All_Present (Type_Def_Node, True);
3960 Set_Constant_Present (Type_Def_Node, True);
3963 Scan; -- past ALL or CONSTANT
3966 Set_Subtype_Indication (Type_Def_Node,
3967 P_Subtype_Indication (Not_Null_Present));
3970 return Type_Def_Node;
3971 end P_Access_Type_Definition;
3973 ---------------------------------------
3974 -- 3.10 Access To Object Definition --
3975 ---------------------------------------
3977 -- Parsed by P_Access_Type_Definition (3.10)
3979 -----------------------------------
3980 -- 3.10 General Access Modifier --
3981 -----------------------------------
3983 -- Parsed by P_Access_Type_Definition (3.10)
3985 -------------------------------------------
3986 -- 3.10 Access To Subprogram Definition --
3987 -------------------------------------------
3989 -- Parsed by P_Access_Type_Definition (3.10)
3991 -----------------------------
3992 -- 3.10 Access Definition --
3993 -----------------------------
3995 -- ACCESS_DEFINITION ::=
3996 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
3997 -- | ACCESS_TO_SUBPROGRAM_DEFINITION
3999 -- ACCESS_TO_SUBPROGRAM_DEFINITION
4000 -- [NULL_EXCLUSION] access [protected] procedure PARAMETER_PROFILE
4001 -- | [NULL_EXCLUSION] access [protected] function
4002 -- PARAMETER_AND_RESULT_PROFILE
4004 -- The caller has parsed the null-exclusion part and it has also checked
4005 -- that the next token is ACCESS
4007 -- Error recovery: cannot raise Error_Resync
4009 function P_Access_Definition
4010 (Null_Exclusion_Present : Boolean) return Node_Id
4013 Subp_Node : Node_Id;
4016 Def_Node := New_Node (N_Access_Definition, Token_Ptr);
4017 Scan; -- past ACCESS
4019 -- Ada 2005 (AI-254): Access_To_Subprogram_Definition
4021 if Token = Tok_Protected
4022 or else Token = Tok_Procedure
4023 or else Token = Tok_Function
4025 if Ada_Version < Ada_2005 then
4026 Error_Msg_SP ("access-to-subprogram is an Ada 2005 extension");
4027 Error_Msg_SP ("\unit should be compiled with -gnat05 switch");
4030 Subp_Node := P_Access_Type_Definition (Header_Already_Parsed => True);
4031 Set_Null_Exclusion_Present (Subp_Node, Null_Exclusion_Present);
4032 Set_Access_To_Subprogram_Definition (Def_Node, Subp_Node);
4034 -- Ada 2005 (AI-231)
4035 -- [NULL_EXCLUSION] access [GENERAL_ACCESS_MODIFIER] SUBTYPE_MARK
4038 Set_Null_Exclusion_Present (Def_Node, Null_Exclusion_Present);
4040 if Token = Tok_All then
4041 if Ada_Version < Ada_2005 then
4043 ("ALL is not permitted for anonymous access types");
4047 Set_All_Present (Def_Node);
4049 elsif Token = Tok_Constant then
4050 if Ada_Version < Ada_2005 then
4051 Error_Msg_SP ("access-to-constant is an Ada 2005 extension");
4052 Error_Msg_SP ("\unit should be compiled with -gnat05 switch");
4055 Scan; -- past CONSTANT
4056 Set_Constant_Present (Def_Node);
4059 Set_Subtype_Mark (Def_Node, P_Subtype_Mark);
4064 end P_Access_Definition;
4066 -----------------------------------------
4067 -- 3.10.1 Incomplete Type Declaration --
4068 -----------------------------------------
4070 -- Parsed by P_Type_Declaration (3.2.1)
4072 ----------------------------
4073 -- 3.11 Declarative Part --
4074 ----------------------------
4076 -- DECLARATIVE_PART ::= {DECLARATIVE_ITEM}
4078 -- Error recovery: cannot raise Error_Resync (because P_Declarative_Items
4079 -- handles errors, and returns cleanly after an error has occurred)
4081 function P_Declarative_Part return List_Id is
4086 -- Indicate no bad declarations detected yet. This will be reset by
4087 -- P_Declarative_Items if a bad declaration is discovered.
4089 Missing_Begin_Msg := No_Error_Msg;
4091 -- Get rid of active SIS entry from outer scope. This means we will
4092 -- miss some nested cases, but it doesn't seem worth the effort. See
4093 -- discussion in Par for further details
4095 SIS_Entry_Active := False;
4098 -- Loop to scan out the declarations
4101 P_Declarative_Items (Decls, Done, In_Spec => False);
4105 -- Get rid of active SIS entry which is left set only if we scanned a
4106 -- procedure declaration and have not found the body. We could give
4107 -- an error message, but that really would be usurping the role of
4108 -- semantic analysis (this really is a missing body case).
4110 SIS_Entry_Active := False;
4112 end P_Declarative_Part;
4114 ----------------------------
4115 -- 3.11 Declarative Item --
4116 ----------------------------
4118 -- DECLARATIVE_ITEM ::= BASIC_DECLARATIVE_ITEM | BODY
4120 -- Can return Error if a junk declaration is found, or Empty if no
4121 -- declaration is found (i.e. a token ending declarations, such as
4122 -- BEGIN or END is encountered).
4124 -- Error recovery: cannot raise Error_Resync. If an error resync occurs,
4125 -- then the scan is set past the next semicolon and Error is returned.
4127 procedure P_Declarative_Items
4132 Scan_State : Saved_Scan_State;
4136 Style.Check_Indentation;
4141 when Tok_Function =>
4143 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
4149 -- Check for loop (premature statement)
4151 Save_Scan_State (Scan_State);
4154 if Token = Tok_Identifier then
4155 Scan; -- past identifier
4157 if Token = Tok_In then
4158 Restore_Scan_State (Scan_State);
4159 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
4164 -- Not a loop, so must be rep clause
4166 Restore_Scan_State (Scan_State);
4167 Append (P_Representation_Clause, Decls);
4172 Append (P_Generic, Decls);
4175 when Tok_Identifier =>
4178 -- Special check for misuse of overriding not in Ada 2005 mode
4180 if Token_Name = Name_Overriding
4181 and then not Next_Token_Is (Tok_Colon)
4183 Error_Msg_SC ("overriding indicator is an Ada 2005 extension");
4184 Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
4186 Token := Tok_Overriding;
4187 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
4190 -- Normal case, no overriding, or overriding followed by colon
4193 P_Identifier_Declarations (Decls, Done, In_Spec);
4196 -- Ada2005: A subprogram declaration can start with "not" or
4197 -- "overriding". In older versions, "overriding" is handled
4198 -- like an identifier, with the appropriate messages.
4202 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
4205 when Tok_Overriding =>
4207 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
4212 Append (P_Package (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
4216 Append (P_Pragma, Decls);
4219 when Tok_Procedure =>
4221 Append (P_Subprogram (Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp), Decls);
4224 when Tok_Protected =>
4226 Scan; -- past PROTECTED
4227 Append (P_Protected, Decls);
4232 Append (P_Subtype_Declaration, Decls);
4238 Append (P_Task, Decls);
4243 Append (P_Type_Declaration, Decls);
4248 Append (P_Use_Clause, Decls);
4253 Error_Msg_SC ("WITH can only appear in context clause");
4256 -- BEGIN terminates the scan of a sequence of declarations unless
4257 -- there is a missing subprogram body, see section on handling
4258 -- semicolon in place of IS. We only treat the begin as satisfying
4259 -- the subprogram declaration if it falls in the expected column
4263 if SIS_Entry_Active and then Start_Column >= SIS_Ecol then
4265 -- Here we have the case where a BEGIN is encountered during
4266 -- declarations in a declarative part, or at the outer level,
4267 -- and there is a subprogram declaration outstanding for which
4268 -- no body has been supplied. This is the case where we assume
4269 -- that the semicolon in the subprogram declaration should
4270 -- really have been is. The active SIS entry describes the
4271 -- subprogram declaration. On return the declaration has been
4272 -- modified to become a body.
4275 Specification_Node : Node_Id;
4276 Decl_Node : Node_Id;
4277 Body_Node : Node_Id;
4280 -- First issue the error message. If we had a missing
4281 -- semicolon in the declaration, then change the message
4282 -- to <missing "is">
4284 if SIS_Missing_Semicolon_Message /= No_Error_Msg then
4285 Change_Error_Text -- Replace: "missing "";"" "
4286 (SIS_Missing_Semicolon_Message, "missing ""is""");
4288 -- Otherwise we saved the semicolon position, so complain
4291 Error_Msg -- CODEFIX
4292 ("|"";"" should be IS", SIS_Semicolon_Sloc);
4295 -- The next job is to fix up any declarations that occurred
4296 -- between the procedure header and the BEGIN. These got
4297 -- chained to the outer declarative region (immediately
4298 -- after the procedure declaration) and they should be
4299 -- chained to the subprogram itself, which is a body
4300 -- rather than a spec.
4302 Specification_Node := Specification (SIS_Declaration_Node);
4303 Change_Node (SIS_Declaration_Node, N_Subprogram_Body);
4304 Body_Node := SIS_Declaration_Node;
4305 Set_Specification (Body_Node, Specification_Node);
4306 Set_Declarations (Body_Node, New_List);
4309 Decl_Node := Remove_Next (Body_Node);
4310 exit when Decl_Node = Empty;
4311 Append (Decl_Node, Declarations (Body_Node));
4314 -- Now make the scope table entry for the Begin-End and
4318 Scope.Table (Scope.Last).Sloc := SIS_Sloc;
4319 Scope.Table (Scope.Last).Etyp := E_Name;
4320 Scope.Table (Scope.Last).Ecol := SIS_Ecol;
4321 Scope.Table (Scope.Last).Labl := SIS_Labl;
4322 Scope.Table (Scope.Last).Lreq := False;
4323 SIS_Entry_Active := False;
4325 Set_Handled_Statement_Sequence (Body_Node,
4326 P_Handled_Sequence_Of_Statements);
4327 End_Statements (Handled_Statement_Sequence (Body_Node));
4336 -- Normally an END terminates the scan for basic declarative items.
4337 -- The one exception is END RECORD, which is probably left over from
4341 Save_Scan_State (Scan_State); -- at END
4344 if Token = Tok_Record then
4345 Error_Msg_SP ("no RECORD for this `end record`!");
4346 Scan; -- past RECORD
4350 Restore_Scan_State (Scan_State); -- to END
4354 -- The following tokens which can only be the start of a statement
4355 -- are considered to end a declarative part (i.e. we have a missing
4356 -- BEGIN situation). We are fairly conservative in making this
4357 -- judgment, because it is a real mess to go into statement mode
4358 -- prematurely in response to a junk declaration.
4373 -- But before we decide that it's a statement, let's check for
4374 -- a reserved word misused as an identifier.
4376 if Is_Reserved_Identifier then
4377 Save_Scan_State (Scan_State);
4378 Scan; -- past the token
4380 -- If reserved identifier not followed by colon or comma, then
4381 -- this is most likely an assignment statement to the bad id.
4383 if Token /= Tok_Colon and then Token /= Tok_Comma then
4384 Restore_Scan_State (Scan_State);
4385 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
4388 -- Otherwise we have a declaration of the bad id
4391 Restore_Scan_State (Scan_State);
4392 Scan_Reserved_Identifier (Force_Msg => True);
4393 P_Identifier_Declarations (Decls, Done, In_Spec);
4396 -- If not reserved identifier, then it's definitely a statement
4399 Statement_When_Declaration_Expected (Decls, Done, In_Spec);
4403 -- The token RETURN may well also signal a missing BEGIN situation,
4404 -- however, we never let it end the declarative part, because it may
4405 -- also be part of a half-baked function declaration.
4408 Error_Msg_SC ("misplaced RETURN statement");
4411 -- PRIVATE definitely terminates the declarations in a spec,
4412 -- and is an error in a body.
4418 Error_Msg_SC ("PRIVATE not allowed in body");
4419 Scan; -- past PRIVATE
4422 -- An end of file definitely terminates the declarations!
4427 -- The remaining tokens do not end the scan, but cannot start a
4428 -- valid declaration, so we signal an error and resynchronize.
4429 -- But first check for misuse of a reserved identifier.
4433 -- Here we check for a reserved identifier
4435 if Is_Reserved_Identifier then
4436 Save_Scan_State (Scan_State);
4437 Scan; -- past the token
4439 if Token /= Tok_Colon and then Token /= Tok_Comma then
4440 Restore_Scan_State (Scan_State);
4441 Set_Declaration_Expected;
4444 Restore_Scan_State (Scan_State);
4445 Scan_Reserved_Identifier (Force_Msg => True);
4447 P_Identifier_Declarations (Decls, Done, In_Spec);
4451 Set_Declaration_Expected;
4456 -- To resynchronize after an error, we scan to the next semicolon and
4457 -- return with Done = False, indicating that there may still be more
4458 -- valid declarations to come.
4461 when Error_Resync =>
4462 Resync_Past_Semicolon;
4464 end P_Declarative_Items;
4466 ----------------------------------
4467 -- 3.11 Basic Declarative Item --
4468 ----------------------------------
4470 -- BASIC_DECLARATIVE_ITEM ::=
4471 -- BASIC_DECLARATION | REPRESENTATION_CLAUSE | USE_CLAUSE
4473 -- Scan zero or more basic declarative items
4475 -- Error recovery: cannot raise Error_Resync. If an error is detected, then
4476 -- the scan pointer is repositioned past the next semicolon, and the scan
4477 -- for declarative items continues.
4479 function P_Basic_Declarative_Items return List_Id is
4486 -- Indicate no bad declarations detected yet in the current context:
4487 -- visible or private declarations of a package spec.
4489 Missing_Begin_Msg := No_Error_Msg;
4491 -- Get rid of active SIS entry from outer scope. This means we will
4492 -- miss some nested cases, but it doesn't seem worth the effort. See
4493 -- discussion in Par for further details
4495 SIS_Entry_Active := False;
4497 -- Loop to scan out declarations
4502 P_Declarative_Items (Decls, Done, In_Spec => True);
4506 -- Get rid of active SIS entry. This is set only if we have scanned a
4507 -- procedure declaration and have not found the body. We could give
4508 -- an error message, but that really would be usurping the role of
4509 -- semantic analysis (this really is a case of a missing body).
4511 SIS_Entry_Active := False;
4513 -- Test for assorted illegal declarations not diagnosed elsewhere
4515 Decl := First (Decls);
4517 while Present (Decl) loop
4518 Kind := Nkind (Decl);
4520 -- Test for body scanned, not acceptable as basic decl item
4522 if Kind = N_Subprogram_Body or else
4523 Kind = N_Package_Body or else
4524 Kind = N_Task_Body or else
4525 Kind = N_Protected_Body
4527 Error_Msg ("proper body not allowed in package spec", Sloc (Decl));
4529 -- Test for body stub scanned, not acceptable as basic decl item
4531 elsif Kind in N_Body_Stub then
4532 Error_Msg ("body stub not allowed in package spec", Sloc (Decl));
4534 elsif Kind = N_Assignment_Statement then
4536 ("assignment statement not allowed in package spec",
4544 end P_Basic_Declarative_Items;
4550 -- For proper body, see below
4551 -- For body stub, see 10.1.3
4553 -----------------------
4554 -- 3.11 Proper Body --
4555 -----------------------
4557 -- Subprogram body is parsed by P_Subprogram (6.1)
4558 -- Package body is parsed by P_Package (7.1)
4559 -- Task body is parsed by P_Task (9.1)
4560 -- Protected body is parsed by P_Protected (9.4)
4562 ------------------------------
4563 -- Set_Declaration_Expected --
4564 ------------------------------
4566 procedure Set_Declaration_Expected is
4568 Error_Msg_SC ("declaration expected");
4570 if Missing_Begin_Msg = No_Error_Msg then
4571 Missing_Begin_Msg := Get_Msg_Id;
4573 end Set_Declaration_Expected;
4575 ----------------------
4576 -- Skip_Declaration --
4577 ----------------------
4579 procedure Skip_Declaration (S : List_Id) is
4580 Dummy_Done : Boolean;
4581 pragma Warnings (Off, Dummy_Done);
4583 P_Declarative_Items (S, Dummy_Done, False);
4584 end Skip_Declaration;
4586 -----------------------------------------
4587 -- Statement_When_Declaration_Expected --
4588 -----------------------------------------
4590 procedure Statement_When_Declaration_Expected
4596 -- Case of second occurrence of statement in one declaration sequence
4598 if Missing_Begin_Msg /= No_Error_Msg then
4600 -- In the procedure spec case, just ignore it, we only give one
4601 -- message for the first occurrence, since otherwise we may get
4602 -- horrible cascading if BODY was missing in the header line.
4607 -- In the declarative part case, take a second statement as a sure
4608 -- sign that we really have a missing BEGIN, and end the declarative
4609 -- part now. Note that the caller will fix up the first message to
4610 -- say "missing BEGIN" so that's how the error will be signalled.
4617 -- Case of first occurrence of unexpected statement
4620 -- If we are in a package spec, then give message of statement
4621 -- not allowed in package spec. This message never gets changed.
4624 Error_Msg_SC ("statement not allowed in package spec");
4626 -- If in declarative part, then we give the message complaining
4627 -- about finding a statement when a declaration is expected. This
4628 -- gets changed to a complaint about a missing BEGIN if we later
4629 -- find that no BEGIN is present.
4632 Error_Msg_SC ("statement not allowed in declarative part");
4635 -- Capture message Id. This is used for two purposes, first to
4636 -- stop multiple messages, see test above, and second, to allow
4637 -- the replacement of the message in the declarative part case.
4639 Missing_Begin_Msg := Get_Msg_Id;
4642 -- In all cases except the case in which we decided to terminate the
4643 -- declaration sequence on a second error, we scan out the statement
4644 -- and append it to the list of declarations (note that the semantics
4645 -- can handle statements in a declaration list so if we proceed to
4646 -- call the semantic phase, all will be (reasonably) well!
4648 Append_List_To (Decls, P_Sequence_Of_Statements (SS_Unco));
4650 -- Done is set to False, since we want to continue the scan of
4651 -- declarations, hoping that this statement was a temporary glitch.
4652 -- If we indeed are now in the statement part (i.e. this was a missing
4653 -- BEGIN, then it's not terrible, we will simply keep calling this
4654 -- procedure to process the statements one by one, and then finally
4655 -- hit the missing BEGIN, which will clean up the error message.
4658 end Statement_When_Declaration_Expected;