1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2021, 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 with Rident
; use Rident
;
27 with Restrict
; use Restrict
;
28 pragma Style_Checks
(All_Checks
);
29 -- Turn off subprogram body ordering check. Subprograms are in order
30 -- by RM section rather than alphabetical
35 -- Local functions, used only in this chapter
37 function P_Component_Clause
return Node_Id
;
38 function P_Mod_Clause
return Node_Id
;
40 -----------------------------------
41 -- Aspect_Specifications_Present --
42 -----------------------------------
44 function Aspect_Specifications_Present
45 (Strict
: Boolean := Ada_Version
< Ada_2012
) return Boolean
47 Scan_State
: Saved_Scan_State
;
50 function With_Present
return Boolean;
51 -- Returns True if WITH is present, indicating presence of aspect
52 -- specifications. Also allows incorrect use of WHEN in place of WITH.
58 function With_Present
return Boolean is
60 if Token
= Tok_With
then
63 -- Check for WHEN used in place of WITH
65 elsif Token
= Tok_When
then
67 Scan_State
: Saved_Scan_State
;
70 Save_Scan_State
(Scan_State
);
73 if Token
= Tok_Identifier
74 and then Is_Aspect_Id
(Token_Name
)
76 Error_Msg_SC
("WHEN should be WITH");
77 Restore_Scan_State
(Scan_State
);
81 Restore_Scan_State
(Scan_State
);
91 -- Start of processing for Aspect_Specifications_Present
94 -- Definitely must have WITH to consider aspect specs to be present
96 -- Note that this means that if we have a semicolon, we immediately
97 -- return False. There is a case in which this is not optimal, namely
100 -- type R is new Integer;
103 -- where the semicolon is redundant, but scanning forward for it would
104 -- be too expensive. Instead we pick up the aspect specifications later
105 -- as a bogus declaration, and diagnose the semicolon at that point.
107 if not With_Present
then
111 -- Have a WITH or some token that we accept as a legitimate bad attempt
112 -- at writing WITH. See if it looks like an aspect specification
114 Save_Scan_State
(Scan_State
);
115 Scan
; -- past WITH (or WHEN or other bad keyword)
117 -- If no identifier, then consider that we definitely do not have an
118 -- aspect specification.
120 if Token
/= Tok_Identifier
then
123 -- This is where we pay attention to the Strict mode. Normally when
124 -- we are in Ada 2012 mode, Strict is False, and we consider that we
125 -- have an aspect specification if the identifier is an aspect name
126 -- or a likely misspelling of one (even if not followed by =>) or
127 -- the identifier is not an aspect name but is followed by =>, by
128 -- a comma, or by a semicolon. The last two cases correspond to
129 -- (misspelled) Boolean aspects with a defaulted value of True.
130 -- P_Aspect_Specifications will generate messages if the aspect
131 -- specification is ill-formed.
133 elsif not Strict
then
134 if Is_Aspect_Id
(Token_Name
)
135 or else Aspect_Spell_Check
(Token_Name
)
139 Scan
; -- past identifier
141 Tok_Arrow | Tok_Comma | Tok_Is | Tok_Semicolon | Tok_Right_Paren
;
144 -- If earlier than Ada 2012, check for valid aspect identifier (possibly
145 -- completed with 'CLASS) followed by an arrow, and consider that this
146 -- is still an aspect specification so we give an appropriate message.
149 if not Is_Aspect_Id
(Token_Name
) then
153 Scan
; -- past aspect name
157 if Token
= Tok_Arrow
then
160 -- The identifier may be the name of a boolean aspect with a
161 -- defaulted True value. Further checks when analyzing aspect
162 -- specification, which may include further aspects.
164 elsif Token
in Tok_Comma | Tok_Semicolon
then
167 elsif Token
= Tok_Apostrophe
then
168 Scan
; -- past apostrophe
170 if Token
= Tok_Identifier
171 and then Token_Name
= Name_Class
175 if Token
= Tok_Arrow
then
182 Restore_Scan_State
(Scan_State
);
183 Error_Msg_Ada_2012_Feature
("|aspect specification", Token_Ptr
);
189 Restore_Scan_State
(Scan_State
);
191 end Aspect_Specifications_Present
;
193 -------------------------------
194 -- Get_Aspect_Specifications --
195 -------------------------------
197 function Get_Aspect_Specifications
198 (Semicolon
: Boolean := True) return List_Id
206 -- True if current aspect takes an optional argument
209 Aspects
:= Empty_List
;
211 -- Check if aspect specification present
213 if not Aspect_Specifications_Present
then
221 Scan
; -- past WITH (or possible WHEN after error)
222 Aspects
:= Empty_List
;
224 -- Loop to scan aspects
229 -- The aspect mark is not an identifier
231 if Token
/= Tok_Identifier
then
232 Error_Msg_SC
("aspect identifier expected");
234 -- Skip the whole aspect specification list
237 Resync_Past_Semicolon
;
243 A_Id
:= Get_Aspect_Id
(Token_Name
);
245 Make_Aspect_Specification
(Token_Ptr
,
246 Identifier
=> Token_Node
);
248 -- The aspect mark is not recognized
250 if A_Id
= No_Aspect
then
252 Msg_Issued
: Boolean := False;
254 Check_Restriction
(Msg_Issued
, No_Unrecognized_Aspects
, Aspect
);
255 if not Msg_Issued
then
256 Bad_Aspect
(Token_Node
, Token_Name
, not Debug_Flag_2
);
263 Scan
; -- past incorrect identifier
265 if Token
= Tok_Apostrophe
then
266 Scan
; -- past apostrophe
267 Scan
; -- past presumably CLASS
270 -- Attempt to parse the aspect definition by assuming it is an
273 if Token
= Tok_Arrow
then
275 Set_Expression
(Aspect
, P_Expression
);
277 -- If we have a correct terminator (comma or semicolon, or a
278 -- reasonable likely missing comma), then just proceed.
280 elsif Token
= Tok_Comma
or else
281 Token
= Tok_Semicolon
or else
282 Token
= Tok_Identifier
286 -- Otherwise the aspect contains a junk definition
290 Resync_Past_Semicolon
;
299 Scan
; -- past identifier
300 Opt
:= Aspect_Argument
(A_Id
) = Optional_Expression
302 Aspect_Argument
(A_Id
) = Optional_Name
;
304 -- Check for 'Class present
306 if Token
= Tok_Apostrophe
then
307 if Class_Aspect_OK
(A_Id
) then
308 Scan
; -- past apostrophe
310 if Token
= Tok_Identifier
311 and then Token_Name
= Name_Class
314 Set_Class_Present
(Aspect
);
316 Error_Msg_SC
("Class attribute expected here");
319 if Token
= Tok_Identifier
then
320 Scan
; -- past identifier not CLASS
324 -- The aspect does not allow 'Class
327 Error_Msg_Node_1
:= Identifier
(Aspect
);
328 Error_Msg_SC
("aspect& does not permit attribute here");
331 Scan
; -- past apostrophe
332 Scan
; -- past presumably CLASS
336 -- Check for a missing aspect definition. Aspects with optional
337 -- definitions are not considered.
339 if Token
= Tok_Comma
or else Token
= Tok_Semicolon
then
341 Error_Msg_Node_1
:= Identifier
(Aspect
);
342 Error_Msg_AP
("aspect& requires an aspect definition");
346 -- Here we do not have a comma or a semicolon, we are done if we
347 -- do not have an arrow and the aspect does not need an argument
349 elsif Opt
and then Token
/= Tok_Arrow
then
352 -- Here we have either an arrow, or an aspect that definitely
353 -- needs an aspect definition, and we will look for one even if
354 -- no arrow is preseant.
356 -- Otherwise we have an aspect definition
359 if Token
= Tok_Arrow
then
366 -- Detect a common error where the non-null definition of
367 -- aspect Depends, Global, Refined_Depends, Refined_Global
368 -- or Refined_State lacks enclosing parentheses.
370 if Token
/= Tok_Left_Paren
and then Token
/= Tok_Null
then
374 if A_Id
= Aspect_Depends
376 A_Id
= Aspect_Refined_Depends
378 Error_Msg_SC
-- CODEFIX
380 Resync_Past_Malformed_Aspect
;
382 -- Return when the current aspect is the last in the list
383 -- of specifications and the list applies to a body.
385 if Token
= Tok_Is
then
391 elsif A_Id
= Aspect_Global
393 A_Id
= Aspect_Refined_Global
396 Scan_State
: Saved_Scan_State
;
399 Save_Scan_State
(Scan_State
);
400 Scan
; -- past item or mode_selector
402 -- Emit an error when the aspect has a mode_selector
403 -- as the moded_global_list must be parenthesized:
404 -- with Global => Output => Item
406 if Token
= Tok_Arrow
then
407 Restore_Scan_State
(Scan_State
);
408 Error_Msg_SC
-- CODEFIX
410 Resync_Past_Malformed_Aspect
;
412 -- Return when the current aspect is the last in
413 -- the list of specifications and the list applies
416 if Token
= Tok_Is
then
420 elsif Token
= Tok_Comma
then
423 -- An item followed by a comma does not need to
424 -- be parenthesized if the next token is a valid
426 -- with Global => Item,
429 if Token
= Tok_Identifier
430 and then Is_Aspect_Id
(Token_Name
)
432 Restore_Scan_State
(Scan_State
);
434 -- Otherwise this is a list of items in which case
435 -- the list must be parenthesized.
438 Restore_Scan_State
(Scan_State
);
439 Error_Msg_SC
-- CODEFIX
441 Resync_Past_Malformed_Aspect
;
443 -- Return when the current aspect is the last
444 -- in the list of specifications and the list
445 -- applies to a body.
447 if Token
= Tok_Is
then
452 -- The definition of [Refined_]Global does not need to
456 Restore_Scan_State
(Scan_State
);
462 elsif A_Id
= Aspect_Refined_State
then
463 if Token
= Tok_Identifier
then
465 Scan_State
: Saved_Scan_State
;
468 Save_Scan_State
(Scan_State
);
471 -- The refinement contains a constituent, the whole
472 -- argument of Refined_State must be parenthesized.
474 -- with Refined_State => State => Constit
476 if Token
= Tok_Arrow
then
477 Restore_Scan_State
(Scan_State
);
478 Error_Msg_SC
-- CODEFIX
480 Resync_Past_Malformed_Aspect
;
482 -- Return when the current aspect is the last
483 -- in the list of specifications and the list
484 -- applies to a body.
486 if Token
= Tok_Is
then
490 -- The refinement lacks constituents. Do not flag
491 -- this case as the error would be misleading. The
492 -- diagnostic is left to the analysis.
494 -- with Refined_State => State
497 Restore_Scan_State
(Scan_State
);
504 -- Note if inside Depends or Refined_Depends aspect
506 if A_Id
= Aspect_Depends
507 or else A_Id
= Aspect_Refined_Depends
509 Inside_Depends
:= True;
512 -- Note that we have seen an Import aspect specification.
513 -- This matters only while parsing a subprogram.
515 if A_Id
= Aspect_Import
then
516 SIS_Aspect_Import_Seen
:= True;
517 -- Should do it only for subprograms
520 -- Parse the aspect definition depending on the expected
523 if Aspect_Argument
(A_Id
) = Name
524 or else Aspect_Argument
(A_Id
) = Optional_Name
526 Set_Expression
(Aspect
, P_Name
);
530 (Aspect_Argument
(A_Id
) = Expression
532 Aspect_Argument
(A_Id
) = Optional_Expression
);
533 Set_Expression
(Aspect
, P_Expression
);
536 -- Unconditionally reset flag for Inside_Depends
538 Inside_Depends
:= False;
541 -- Add the aspect to the resulting list only when it was properly
545 Append
(Aspect
, Aspects
);
549 -- Merge here after good or bad aspect (we should be at a comma
550 -- or a semicolon, but there might be other possible errors).
552 -- The aspect specification list contains more than one aspect
554 if Token
= Tok_Comma
then
558 -- Check for a missing comma between two aspects. Emit an error
559 -- and proceed to the next aspect.
561 elsif Token
= Tok_Identifier
562 and then Is_Aspect_Id
(Token_Name
)
565 Scan_State
: Saved_Scan_State
;
568 Save_Scan_State
(Scan_State
);
569 Scan
; -- past identifier
571 -- Attempt to detect ' or => following a potential aspect
574 if Token
= Tok_Apostrophe
or else Token
= Tok_Arrow
then
575 Restore_Scan_State
(Scan_State
);
576 Error_Msg_AP
-- CODEFIX
580 -- The construct following the current aspect is not an
584 Restore_Scan_State
(Scan_State
);
588 -- Check for a mistyped semicolon in place of a comma between two
589 -- aspects. Emit an error and proceed to the next aspect.
591 elsif Token
= Tok_Semicolon
then
593 Scan_State
: Saved_Scan_State
;
596 Save_Scan_State
(Scan_State
);
597 Scan
; -- past semicolon
599 if Token
= Tok_Identifier
600 and then Is_Aspect_Id
(Token_Name
)
602 Scan
; -- past identifier
604 -- Attempt to detect ' or => following potential aspect mark
606 if Token
= Tok_Apostrophe
or else Token
= Tok_Arrow
then
607 Restore_Scan_State
(Scan_State
);
608 Error_Msg_SC
-- CODEFIX
609 ("|"";"" should be "",""");
610 Scan
; -- past semicolon
615 -- Construct following the current aspect is not an aspect
617 Restore_Scan_State
(Scan_State
);
621 -- Require semicolon if caller expects to scan this out
634 end Get_Aspect_Specifications
;
636 --------------------------------------------
637 -- 13.1 Representation Clause (also I.7) --
638 --------------------------------------------
640 -- REPRESENTATION_CLAUSE ::=
641 -- ATTRIBUTE_DEFINITION_CLAUSE
642 -- | ENUMERATION_REPRESENTATION_CLAUSE
643 -- | RECORD_REPRESENTATION_CLAUSE
646 -- ATTRIBUTE_DEFINITION_CLAUSE ::=
647 -- for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use EXPRESSION;
648 -- | for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use NAME;
650 -- Note: in Ada 83, the expression must be a simple expression
652 -- AT_CLAUSE ::= for DIRECT_NAME use at EXPRESSION;
654 -- Note: in Ada 83, the expression must be a simple expression
656 -- ENUMERATION_REPRESENTATION_CLAUSE ::=
657 -- for first_subtype_LOCAL_NAME use ENUMERATION_AGGREGATE;
659 -- ENUMERATION_AGGREGATE ::= ARRAY_AGGREGATE
661 -- RECORD_REPRESENTATION_CLAUSE ::=
662 -- for first_subtype_LOCAL_NAME use
663 -- record [MOD_CLAUSE]
664 -- {COMPONENT_CLAUSE}
667 -- Note: for now we allow only a direct name as the local name in the
668 -- above constructs. This probably needs changing later on ???
670 -- The caller has checked that the initial token is FOR
672 -- Error recovery: cannot raise Error_Resync, if an error occurs,
673 -- the scan is repositioned past the next semicolon.
675 function P_Representation_Clause
return Node_Id
is
676 For_Loc
: Source_Ptr
;
678 Prefix_Node
: Node_Id
;
680 Identifier_Node
: Node_Id
;
681 Rep_Clause_Node
: Node_Id
;
683 Record_Items
: List_Id
;
686 For_Loc
:= Token_Ptr
;
689 -- Note that the name in a representation clause is always a simple
690 -- name, even in the attribute case, see AI-300 which made this so.
692 Identifier_Node
:= P_Identifier
(C_Use
);
694 -- Check case of qualified name to give good error message
696 if Token
= Tok_Dot
then
698 ("representation clause requires simple name!");
701 exit when Token
/= Tok_Dot
;
703 Discard_Junk_Node
(P_Identifier
);
707 -- Attribute Definition Clause
709 if Token
= Tok_Apostrophe
then
711 -- Allow local names of the form a'b'.... This enables
712 -- us to parse class-wide streams attributes correctly.
714 Name_Node
:= Identifier_Node
;
715 while Token
= Tok_Apostrophe
loop
717 Scan
; -- past apostrophe
719 Identifier_Node
:= Token_Node
;
720 Attr_Name
:= No_Name
;
722 if Token
= Tok_Identifier
then
723 Attr_Name
:= Token_Name
;
725 -- Note that the parser must complain in case of an internal
726 -- attribute name that comes from source since internal names
727 -- are meant to be used only by the compiler.
729 if not Is_Attribute_Name
(Attr_Name
)
730 and then (not Is_Internal_Attribute_Name
(Attr_Name
)
731 or else Comes_From_Source
(Token_Node
))
733 Signal_Bad_Attribute
;
737 Style
.Check_Attribute_Name
(False);
740 -- Here for case of attribute designator is not an identifier
743 if Token
= Tok_Delta
then
744 Attr_Name
:= Name_Delta
;
746 elsif Token
= Tok_Digits
then
747 Attr_Name
:= Name_Digits
;
749 elsif Token
= Tok_Access
then
750 Attr_Name
:= Name_Access
;
753 Error_Msg_AP
("attribute designator expected");
758 Style
.Check_Attribute_Name
(True);
762 -- Here we have an OK attribute scanned, and the corresponding
763 -- Attribute identifier node is stored in Ident_Node.
765 Prefix_Node
:= Name_Node
;
766 Name_Node
:= New_Node
(N_Attribute_Reference
, Prev_Token_Ptr
);
767 Set_Prefix
(Name_Node
, Prefix_Node
);
768 Set_Attribute_Name
(Name_Node
, Attr_Name
);
771 -- Check for Address clause which needs to be marked for use in
772 -- optimizing performance of Exp_Util.Following_Address_Clause.
774 if Attr_Name
= Name_Address
775 and then Nkind
(Prefix_Node
) = N_Identifier
777 Set_Name_Table_Boolean1
(Chars
(Prefix_Node
), True);
781 Rep_Clause_Node
:= New_Node
(N_Attribute_Definition_Clause
, For_Loc
);
782 Set_Name
(Rep_Clause_Node
, Prefix_Node
);
783 Set_Chars
(Rep_Clause_Node
, Attr_Name
);
786 Expr_Node
:= P_Expression_No_Right_Paren
;
787 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
788 Set_Expression
(Rep_Clause_Node
, Expr_Node
);
792 Rep_Clause_Node
:= Empty
;
794 -- AT follows USE (At Clause)
796 if Token
= Tok_At
then
798 Rep_Clause_Node
:= New_Node
(N_At_Clause
, For_Loc
);
799 Set_Identifier
(Rep_Clause_Node
, Identifier_Node
);
800 Expr_Node
:= P_Expression_No_Right_Paren
;
801 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
802 Set_Expression
(Rep_Clause_Node
, Expr_Node
);
804 -- Mark occurrence of address clause (used to optimize performance
805 -- of Exp_Util.Following_Address_Clause).
807 Set_Name_Table_Boolean1
(Chars
(Identifier_Node
), True);
809 -- RECORD follows USE (Record Representation Clause)
811 elsif Token
= Tok_Record
then
812 Record_Items
:= P_Pragmas_Opt
;
814 New_Node
(N_Record_Representation_Clause
, For_Loc
);
815 Set_Identifier
(Rep_Clause_Node
, Identifier_Node
);
818 Scopes
(Scope
.Last
).Etyp
:= E_Record
;
819 Scopes
(Scope
.Last
).Ecol
:= Start_Column
;
820 Scopes
(Scope
.Last
).Sloc
:= Token_Ptr
;
822 Record_Items
:= P_Pragmas_Opt
;
824 -- Possible Mod Clause
826 if Token
= Tok_At
then
827 Set_Mod_Clause
(Rep_Clause_Node
, P_Mod_Clause
);
828 Set_Pragmas_Before
(Mod_Clause
(Rep_Clause_Node
), Record_Items
);
829 Record_Items
:= P_Pragmas_Opt
;
832 if No
(Record_Items
) then
833 Record_Items
:= New_List
;
836 Set_Component_Clauses
(Rep_Clause_Node
, Record_Items
);
838 -- Loop through component clauses
841 if Token
not in Token_Class_Name
then
845 Append
(P_Component_Clause
, Record_Items
);
846 P_Pragmas_Opt
(Record_Items
);
849 -- Left paren follows USE (Enumeration Representation Clause)
851 elsif Token
= Tok_Left_Paren
then
853 New_Node
(N_Enumeration_Representation_Clause
, For_Loc
);
854 Set_Identifier
(Rep_Clause_Node
, Identifier_Node
);
855 Set_Array_Aggregate
(Rep_Clause_Node
, P_Aggregate
);
857 -- Some other token follows FOR (invalid representation clause)
860 Error_Msg_SC
("invalid representation clause");
866 return Rep_Clause_Node
;
870 Resync_Past_Semicolon
;
873 end P_Representation_Clause
;
875 ----------------------
876 -- 13.1 Local Name --
877 ----------------------
879 -- Local name is always parsed by its parent. In the case of its use in
880 -- pragmas, the check for a local name is handled in Par.Prag and allows
881 -- all the possible forms of local name. For the uses in chapter 13, we
882 -- currently only allow a direct name, but this should probably change???
884 ---------------------------
885 -- 13.1 At Clause (I.7) --
886 ---------------------------
888 -- Parsed by P_Representation_Clause (13.1)
890 ---------------------------------------
891 -- 13.3 Attribute Definition Clause --
892 ---------------------------------------
894 -- Parsed by P_Representation_Clause (13.1)
896 --------------------------------
897 -- 13.1 Aspect Specification --
898 --------------------------------
900 -- ASPECT_SPECIFICATION ::=
901 -- with ASPECT_MARK [=> ASPECT_DEFINITION] {,
902 -- ASPECT_MARK [=> ASPECT_DEFINITION] }
904 -- ASPECT_MARK ::= aspect_IDENTIFIER['Class]
906 -- ASPECT_DEFINITION ::= NAME | EXPRESSION
908 -- Error recovery: cannot raise Error_Resync
910 procedure P_Aspect_Specifications
912 Semicolon
: Boolean := True)
918 -- Aspect Specification is present
922 -- Here we have an aspect specification to scan, note that we don't
923 -- set the flag till later, because it may turn out that we have no
924 -- valid aspects in the list.
926 Aspects
:= Get_Aspect_Specifications
(Semicolon
);
928 -- Here if aspects present
930 if Is_Non_Empty_List
(Aspects
) then
932 -- If Decl is Empty, we just ignore the aspects (the caller in this
933 -- case has always issued an appropriate error message).
938 -- If Decl is Error, we ignore the aspects, and issue a message
941 or else not Permits_Aspect_Specifications
(Decl
)
943 Error_Msg
("aspect specifications not allowed here", Ptr
);
945 -- Here aspects are allowed, and we store them
948 Set_Parent
(Aspects
, Decl
);
949 Set_Aspect_Specifications
(Decl
, Aspects
);
952 end P_Aspect_Specifications
;
954 ---------------------------------------------
955 -- 13.4 Enumeration Representation Clause --
956 ---------------------------------------------
958 -- Parsed by P_Representation_Clause (13.1)
960 ---------------------------------
961 -- 13.4 Enumeration Aggregate --
962 ---------------------------------
964 -- Parsed by P_Representation_Clause (13.1)
966 ------------------------------------------
967 -- 13.5.1 Record Representation Clause --
968 ------------------------------------------
970 -- Parsed by P_Representation_Clause (13.1)
972 ------------------------------
973 -- 13.5.1 Mod Clause (I.8) --
974 ------------------------------
976 -- MOD_CLAUSE ::= at mod static_EXPRESSION;
978 -- Note: in Ada 83, the expression must be a simple expression
980 -- The caller has checked that the initial Token is AT
982 -- Error recovery: cannot raise Error_Resync
984 -- Note: the caller is responsible for setting the Pragmas_Before field
986 function P_Mod_Clause
return Node_Id
is
991 Mod_Node
:= New_Node
(N_Mod_Clause
, Token_Ptr
);
994 Expr_Node
:= P_Expression_No_Right_Paren
;
995 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
996 Set_Expression
(Mod_Node
, Expr_Node
);
1001 ------------------------------
1002 -- 13.5.1 Component Clause --
1003 ------------------------------
1005 -- COMPONENT_CLAUSE ::=
1006 -- COMPONENT_CLAUSE_COMPONENT_NAME at POSITION
1007 -- range FIRST_BIT .. LAST_BIT;
1009 -- COMPONENT_CLAUSE_COMPONENT_NAME ::=
1010 -- component_DIRECT_NAME
1011 -- | component_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1012 -- | FIRST_SUBTYPE_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1014 -- POSITION ::= static_EXPRESSION
1016 -- Note: in Ada 83, the expression must be a simple expression
1018 -- FIRST_BIT ::= static_SIMPLE_EXPRESSION
1019 -- LAST_BIT ::= static_SIMPLE_EXPRESSION
1021 -- Note: the AARM V2.0 grammar has an error at this point, it uses
1022 -- EXPRESSION instead of SIMPLE_EXPRESSION for FIRST_BIT and LAST_BIT
1024 -- Error recovery: cannot raise Error_Resync
1026 function P_Component_Clause
return Node_Id
is
1027 Component_Node
: Node_Id
;
1028 Comp_Name
: Node_Id
;
1029 Expr_Node
: Node_Id
;
1032 Component_Node
:= New_Node
(N_Component_Clause
, Token_Ptr
);
1033 Comp_Name
:= P_Name
;
1035 if Nkind
(Comp_Name
) = N_Identifier
1036 or else Nkind
(Comp_Name
) = N_Attribute_Reference
1038 Set_Component_Name
(Component_Node
, Comp_Name
);
1041 ("component name must be direct name or attribute", Comp_Name
);
1042 Set_Component_Name
(Component_Node
, Error
);
1045 Set_Sloc
(Component_Node
, Token_Ptr
);
1047 Expr_Node
:= P_Expression_No_Right_Paren
;
1048 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
1049 Set_Position
(Component_Node
, Expr_Node
);
1051 Expr_Node
:= P_Expression_No_Right_Paren
;
1052 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
1053 Set_First_Bit
(Component_Node
, Expr_Node
);
1055 Expr_Node
:= P_Expression_No_Right_Paren
;
1056 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
1057 Set_Last_Bit
(Component_Node
, Expr_Node
);
1059 return Component_Node
;
1060 end P_Component_Clause
;
1062 ----------------------
1063 -- 13.5.1 Position --
1064 ----------------------
1066 -- Parsed by P_Component_Clause (13.5.1)
1068 -----------------------
1069 -- 13.5.1 First Bit --
1070 -----------------------
1072 -- Parsed by P_Component_Clause (13.5.1)
1074 ----------------------
1075 -- 13.5.1 Last Bit --
1076 ----------------------
1078 -- Parsed by P_Component_Clause (13.5.1)
1080 --------------------------
1081 -- 13.8 Code Statement --
1082 --------------------------
1084 -- CODE_STATEMENT ::= QUALIFIED_EXPRESSION
1086 -- On entry the caller has scanned the SUBTYPE_MARK (passed in as the
1087 -- single argument, and the scan points to the apostrophe.
1089 -- Error recovery: can raise Error_Resync
1091 function P_Code_Statement
(Subtype_Mark
: Node_Id
) return Node_Id
is
1095 Scan
; -- past apostrophe
1097 -- If left paren, then we have a possible code statement
1099 if Token
= Tok_Left_Paren
then
1100 Node1
:= New_Node
(N_Code_Statement
, Sloc
(Subtype_Mark
));
1101 Set_Expression
(Node1
, P_Qualified_Expression
(Subtype_Mark
));
1105 -- Otherwise we have an illegal range attribute. Note that P_Name
1106 -- ensures that Token = Tok_Range is the only possibility left here.
1109 Error_Msg_SC
("RANGE attribute illegal here!");
1112 end P_Code_Statement
;