1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, 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
33 -- Local functions, used only in this chapter
35 function P_Component_Clause
return Node_Id
;
36 function P_Mod_Clause
return Node_Id
;
38 -----------------------------------
39 -- Aspect_Specifications_Present --
40 -----------------------------------
42 function Aspect_Specifications_Present
43 (Strict
: Boolean := Ada_Version
< Ada_2012
) return Boolean
45 Scan_State
: Saved_Scan_State
;
48 function Possible_Misspelled_Aspect
return Boolean;
49 -- Returns True, if Token_Name is a misspelling of some aspect name
51 --------------------------------
52 -- Possible_Misspelled_Aspect --
53 --------------------------------
55 function Possible_Misspelled_Aspect
return Boolean is
57 for J
in Aspect_Id_Exclude_No_Aspect
loop
58 if Is_Bad_Spelling_Of
(Token_Name
, Aspect_Names
(J
)) then
64 end Possible_Misspelled_Aspect
;
66 -- Start of processing for Aspect_Specifications_Present
69 -- Definitely must have WITH to consider aspect specs to be present
71 -- Note that this means that if we have a semicolon, we immediately
72 -- return False. There is a case in which this is not optimal, namely
75 -- type R is new Integer;
78 -- where the semicolon is redundant, but scanning forward for it would
79 -- be too expensive. Instead we pick up the aspect specifications later
80 -- as a bogus declaration, and diagnose the semicolon at that point.
82 if Token
/= Tok_With
then
86 -- Have a WITH, see if it looks like an aspect specification
88 Save_Scan_State
(Scan_State
);
91 -- If no identifier, then consider that we definitely do not have an
92 -- aspect specification.
94 if Token
/= Tok_Identifier
then
97 -- This is where we pay attention to the Strict mode. Normally when
98 -- we are in Ada 2012 mode, Strict is False, and we consider that we
99 -- have an aspect specification if the identifier is an aspect name
100 -- or a likely misspelling of one (even if not followed by =>) or
101 -- the identifier is not an aspect name but is followed by =>, by
102 -- a comma, or by a semicolon. The last two cases correspond to
103 -- (misspelled) Boolean aspects with a defaulted value of True.
104 -- P_Aspect_Specifications will generate messages if the aspect
105 -- specification is ill-formed.
107 elsif not Strict
then
108 if Get_Aspect_Id
(Token_Name
) /= No_Aspect
109 or else Possible_Misspelled_Aspect
113 Scan
; -- past identifier
114 Result
:= Token
= Tok_Arrow
or else
115 Token
= Tok_Comma
or else
116 Token
= Tok_Semicolon
;
119 -- If earlier than Ada 2012, check for valid aspect identifier (possibly
120 -- completed with 'CLASS) followed by an arrow, and consider that this
121 -- is still an aspect specification so we give an appropriate message.
124 if Get_Aspect_Id
(Token_Name
) = No_Aspect
then
128 Scan
; -- past aspect name
132 if Token
= Tok_Arrow
then
135 -- The identifier may be the name of a boolean aspect with a
136 -- defaulted True value. Further checks when analyzing aspect
137 -- specification, which may include further aspects.
139 elsif Token
= Tok_Comma
or else Token
= Tok_Semicolon
then
142 elsif Token
= Tok_Apostrophe
then
143 Scan
; -- past apostrophe
145 if Token
= Tok_Identifier
146 and then Token_Name
= Name_Class
150 if Token
= Tok_Arrow
then
157 Restore_Scan_State
(Scan_State
);
158 Error_Msg_Ada_2012_Feature
("|aspect specification", Token_Ptr
);
164 Restore_Scan_State
(Scan_State
);
166 end Aspect_Specifications_Present
;
168 -------------------------------
169 -- Get_Aspect_Specifications --
170 -------------------------------
172 function Get_Aspect_Specifications
173 (Semicolon
: Boolean := True) return List_Id
181 -- True if current aspect takes an optional argument
184 Aspects
:= Empty_List
;
186 -- Check if aspect specification present
188 if not Aspect_Specifications_Present
then
197 Aspects
:= Empty_List
;
199 -- Loop to scan aspects
204 -- The aspect mark is not an identifier
206 if Token
/= Tok_Identifier
then
207 Error_Msg_SC
("aspect identifier expected");
209 -- Skip the whole aspect specification list
212 Resync_Past_Semicolon
;
218 A_Id
:= Get_Aspect_Id
(Token_Name
);
220 Make_Aspect_Specification
(Token_Ptr
,
221 Identifier
=> Token_Node
);
223 -- The aspect mark is not recognized
225 if A_Id
= No_Aspect
then
226 Error_Msg_N
("& is not a valid aspect identifier", Token_Node
);
229 -- Check bad spelling
231 for J
in Aspect_Id_Exclude_No_Aspect
loop
232 if Is_Bad_Spelling_Of
(Token_Name
, Aspect_Names
(J
)) then
233 Error_Msg_Name_1
:= Aspect_Names
(J
);
234 Error_Msg_N
-- CODEFIX
235 ("\possible misspelling of%", Token_Node
);
240 Scan
; -- past incorrect identifier
242 if Token
= Tok_Apostrophe
then
243 Scan
; -- past apostrophe
244 Scan
; -- past presumably CLASS
247 -- Attempt to parse the aspect definition by assuming it is an
250 if Token
= Tok_Arrow
then
252 Set_Expression
(Aspect
, P_Expression
);
254 -- If we have a correct terminator (comma or semicolon, or a
255 -- reasonable likely missing comma), then just proceed.
257 elsif Token
= Tok_Comma
or else
258 Token
= Tok_Semicolon
or else
259 Token
= Tok_Identifier
263 -- Otherwise the aspect contains a junk definition
267 Resync_Past_Semicolon
;
276 Scan
; -- past identifier
277 Opt
:= Aspect_Argument
(A_Id
) = Optional_Expression
279 Aspect_Argument
(A_Id
) = Optional_Name
;
281 -- Check for 'Class present
283 if Token
= Tok_Apostrophe
then
284 if Class_Aspect_OK
(A_Id
) then
285 Scan
; -- past apostrophe
287 if Token
= Tok_Identifier
288 and then Token_Name
= Name_Class
291 Set_Class_Present
(Aspect
);
293 Error_Msg_SC
("Class attribute expected here");
296 if Token
= Tok_Identifier
then
297 Scan
; -- past identifier not CLASS
301 -- The aspect does not allow 'Class
304 Error_Msg_Node_1
:= Identifier
(Aspect
);
305 Error_Msg_SC
("aspect& does not permit attribute here");
308 Scan
; -- past apostrophe
309 Scan
; -- past presumably CLASS
313 -- Check for a missing aspect definition. Aspects with optional
314 -- definitions are not considered.
316 if Token
= Tok_Comma
or else Token
= Tok_Semicolon
then
318 Error_Msg_Node_1
:= Identifier
(Aspect
);
319 Error_Msg_AP
("aspect& requires an aspect definition");
323 -- Here we do not have a comma or a semicolon, we are done if we
324 -- do not have an arrow and the aspect does not need an argument
326 elsif Opt
and then Token
/= Tok_Arrow
then
329 -- Here we have either an arrow, or an aspect that definitely
330 -- needs an aspect definition, and we will look for one even if
331 -- no arrow is preseant.
333 -- Otherwise we have an aspect definition
336 if Token
= Tok_Arrow
then
343 -- Detect a common error where the non-null definition of
344 -- aspect Depends, Global, Refined_Depends, Refined_Global
345 -- or Refined_State lacks enclosing parentheses.
347 if Token
/= Tok_Left_Paren
and then Token
/= Tok_Null
then
351 if A_Id
= Aspect_Depends
353 A_Id
= Aspect_Refined_Depends
355 Error_Msg_SC
-- CODEFIX
357 Resync_Past_Malformed_Aspect
;
359 -- Return when the current aspect is the last in the list
360 -- of specifications and the list applies to a body.
362 if Token
= Tok_Is
then
368 elsif A_Id
= Aspect_Global
370 A_Id
= Aspect_Refined_Global
373 Scan_State
: Saved_Scan_State
;
376 Save_Scan_State
(Scan_State
);
377 Scan
; -- past item or mode_selector
379 -- Emit an error when the aspect has a mode_selector
380 -- as the moded_global_list must be parenthesized:
381 -- with Global => Output => Item
383 if Token
= Tok_Arrow
then
384 Restore_Scan_State
(Scan_State
);
385 Error_Msg_SC
-- CODEFIX
387 Resync_Past_Malformed_Aspect
;
389 -- Return when the current aspect is the last in
390 -- the list of specifications and the list applies
393 if Token
= Tok_Is
then
397 elsif Token
= Tok_Comma
then
400 -- An item followed by a comma does not need to
401 -- be parenthesized if the next token is a valid
403 -- with Global => Item,
406 if Token
= Tok_Identifier
407 and then Get_Aspect_Id
(Token_Name
) /= No_Aspect
409 Restore_Scan_State
(Scan_State
);
411 -- Otherwise this is a list of items in which case
412 -- the list must be parenthesized.
415 Restore_Scan_State
(Scan_State
);
416 Error_Msg_SC
-- CODEFIX
418 Resync_Past_Malformed_Aspect
;
420 -- Return when the current aspect is the last
421 -- in the list of specifications and the list
422 -- applies to a body.
424 if Token
= Tok_Is
then
429 -- The definition of [Refined_]Global does not need to
433 Restore_Scan_State
(Scan_State
);
439 elsif A_Id
= Aspect_Refined_State
then
440 if Token
= Tok_Identifier
then
442 Scan_State
: Saved_Scan_State
;
445 Save_Scan_State
(Scan_State
);
448 -- The refinement contains a constituent, the whole
449 -- argument of Refined_State must be parenthesized.
451 -- with Refined_State => State => Constit
453 if Token
= Tok_Arrow
then
454 Restore_Scan_State
(Scan_State
);
455 Error_Msg_SC
-- CODEFIX
457 Resync_Past_Malformed_Aspect
;
459 -- Return when the current aspect is the last
460 -- in the list of specifications and the list
461 -- applies to a body.
463 if Token
= Tok_Is
then
467 -- The refinement lacks constituents. Do not flag
468 -- this case as the error would be misleading. The
469 -- diagnostic is left to the analysis.
471 -- with Refined_State => State
474 Restore_Scan_State
(Scan_State
);
481 -- Note if inside Depends aspect
483 if A_Id
= Aspect_Depends
then
484 Inside_Depends
:= True;
487 -- Parse the aspect definition depening on the expected
490 if Aspect_Argument
(A_Id
) = Name
491 or else Aspect_Argument
(A_Id
) = Optional_Name
493 Set_Expression
(Aspect
, P_Name
);
497 (Aspect_Argument
(A_Id
) = Expression
499 Aspect_Argument
(A_Id
) = Optional_Expression
);
500 Set_Expression
(Aspect
, P_Expression
);
503 -- Unconditionally reset flag for Inside_Depends
505 Inside_Depends
:= False;
508 -- Add the aspect to the resulting list only when it was properly
512 Append
(Aspect
, Aspects
);
516 -- Merge here after good or bad aspect (we should be at a comma
517 -- or a semicolon, but there might be other possible errors).
519 -- The aspect specification list contains more than one aspect
521 if Token
= Tok_Comma
then
525 -- Check for a missing comma between two aspects. Emit an error
526 -- and proceed to the next aspect.
528 elsif Token
= Tok_Identifier
529 and then Get_Aspect_Id
(Token_Name
) /= No_Aspect
532 Scan_State
: Saved_Scan_State
;
535 Save_Scan_State
(Scan_State
);
536 Scan
; -- past identifier
538 -- Attempt to detect ' or => following a potential aspect
541 if Token
= Tok_Apostrophe
or else Token
= Tok_Arrow
then
542 Restore_Scan_State
(Scan_State
);
543 Error_Msg_AP
-- CODEFIX
547 -- The construct following the current aspect is not an
551 Restore_Scan_State
(Scan_State
);
555 -- Check for a mistyped semicolon in place of a comma between two
556 -- aspects. Emit an error and proceed to the next aspect.
558 elsif Token
= Tok_Semicolon
then
560 Scan_State
: Saved_Scan_State
;
563 Save_Scan_State
(Scan_State
);
564 Scan
; -- past semicolon
566 if Token
= Tok_Identifier
567 and then Get_Aspect_Id
(Token_Name
) /= No_Aspect
569 Scan
; -- past identifier
571 -- Attempt to detect ' or => following potential aspect mark
573 if Token
= Tok_Apostrophe
or else Token
= Tok_Arrow
then
574 Restore_Scan_State
(Scan_State
);
575 Error_Msg_SC
-- CODEFIX
576 ("|"";"" should be "",""");
577 Scan
; -- past semicolon
582 -- Construct following the current aspect is not an aspect
584 Restore_Scan_State
(Scan_State
);
588 -- Require semicolon if caller expects to scan this out
601 end Get_Aspect_Specifications
;
603 --------------------------------------------
604 -- 13.1 Representation Clause (also I.7) --
605 --------------------------------------------
607 -- REPRESENTATION_CLAUSE ::=
608 -- ATTRIBUTE_DEFINITION_CLAUSE
609 -- | ENUMERATION_REPRESENTATION_CLAUSE
610 -- | RECORD_REPRESENTATION_CLAUSE
613 -- ATTRIBUTE_DEFINITION_CLAUSE ::=
614 -- for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use EXPRESSION;
615 -- | for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use NAME;
617 -- Note: in Ada 83, the expression must be a simple expression
619 -- AT_CLAUSE ::= for DIRECT_NAME use at EXPRESSION;
621 -- Note: in Ada 83, the expression must be a simple expression
623 -- ENUMERATION_REPRESENTATION_CLAUSE ::=
624 -- for first_subtype_LOCAL_NAME use ENUMERATION_AGGREGATE;
626 -- ENUMERATION_AGGREGATE ::= ARRAY_AGGREGATE
628 -- RECORD_REPRESENTATION_CLAUSE ::=
629 -- for first_subtype_LOCAL_NAME use
630 -- record [MOD_CLAUSE]
631 -- {COMPONENT_CLAUSE}
634 -- Note: for now we allow only a direct name as the local name in the
635 -- above constructs. This probably needs changing later on ???
637 -- The caller has checked that the initial token is FOR
639 -- Error recovery: cannot raise Error_Resync, if an error occurs,
640 -- the scan is repositioned past the next semicolon.
642 function P_Representation_Clause
return Node_Id
is
643 For_Loc
: Source_Ptr
;
645 Prefix_Node
: Node_Id
;
647 Identifier_Node
: Node_Id
;
648 Rep_Clause_Node
: Node_Id
;
650 Record_Items
: List_Id
;
653 For_Loc
:= Token_Ptr
;
656 -- Note that the name in a representation clause is always a simple
657 -- name, even in the attribute case, see AI-300 which made this so.
659 Identifier_Node
:= P_Identifier
(C_Use
);
661 -- Check case of qualified name to give good error message
663 if Token
= Tok_Dot
then
665 ("representation clause requires simple name!");
668 exit when Token
/= Tok_Dot
;
670 Discard_Junk_Node
(P_Identifier
);
674 -- Attribute Definition Clause
676 if Token
= Tok_Apostrophe
then
678 -- Allow local names of the form a'b'.... This enables
679 -- us to parse class-wide streams attributes correctly.
681 Name_Node
:= Identifier_Node
;
682 while Token
= Tok_Apostrophe
loop
684 Scan
; -- past apostrophe
686 Identifier_Node
:= Token_Node
;
687 Attr_Name
:= No_Name
;
689 if Token
= Tok_Identifier
then
690 Attr_Name
:= Token_Name
;
692 -- Note that the parser must complain in case of an internal
693 -- attribute name that comes from source since internal names
694 -- are meant to be used only by the compiler.
696 if not Is_Attribute_Name
(Attr_Name
)
697 and then (not Is_Internal_Attribute_Name
(Attr_Name
)
698 or else Comes_From_Source
(Token_Node
))
700 Signal_Bad_Attribute
;
704 Style
.Check_Attribute_Name
(False);
707 -- Here for case of attribute designator is not an identifier
710 if Token
= Tok_Delta
then
711 Attr_Name
:= Name_Delta
;
713 elsif Token
= Tok_Digits
then
714 Attr_Name
:= Name_Digits
;
716 elsif Token
= Tok_Access
then
717 Attr_Name
:= Name_Access
;
720 Error_Msg_AP
("attribute designator expected");
725 Style
.Check_Attribute_Name
(True);
729 -- Here we have an OK attribute scanned, and the corresponding
730 -- Attribute identifier node is stored in Ident_Node.
732 Prefix_Node
:= Name_Node
;
733 Name_Node
:= New_Node
(N_Attribute_Reference
, Prev_Token_Ptr
);
734 Set_Prefix
(Name_Node
, Prefix_Node
);
735 Set_Attribute_Name
(Name_Node
, Attr_Name
);
738 -- Check for Address clause which needs to be marked for use in
739 -- optimizing performance of Exp_Util.Following_Address_Clause.
741 if Attr_Name
= Name_Address
742 and then Nkind
(Prefix_Node
) = N_Identifier
744 Set_Name_Table_Boolean
(Chars
(Prefix_Node
), True);
748 Rep_Clause_Node
:= New_Node
(N_Attribute_Definition_Clause
, For_Loc
);
749 Set_Name
(Rep_Clause_Node
, Prefix_Node
);
750 Set_Chars
(Rep_Clause_Node
, Attr_Name
);
753 Expr_Node
:= P_Expression_No_Right_Paren
;
754 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
755 Set_Expression
(Rep_Clause_Node
, Expr_Node
);
759 Rep_Clause_Node
:= Empty
;
761 -- AT follows USE (At Clause)
763 if Token
= Tok_At
then
765 Rep_Clause_Node
:= New_Node
(N_At_Clause
, For_Loc
);
766 Set_Identifier
(Rep_Clause_Node
, Identifier_Node
);
767 Expr_Node
:= P_Expression_No_Right_Paren
;
768 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
769 Set_Expression
(Rep_Clause_Node
, Expr_Node
);
771 -- Mark occurrence of address clause (used to optimize performance
772 -- of Exp_Util.Following_Address_Clause).
774 Set_Name_Table_Boolean
(Chars
(Identifier_Node
), True);
776 -- RECORD follows USE (Record Representation Clause)
778 elsif Token
= Tok_Record
then
779 Record_Items
:= P_Pragmas_Opt
;
781 New_Node
(N_Record_Representation_Clause
, For_Loc
);
782 Set_Identifier
(Rep_Clause_Node
, Identifier_Node
);
785 Scope
.Table
(Scope
.Last
).Etyp
:= E_Record
;
786 Scope
.Table
(Scope
.Last
).Ecol
:= Start_Column
;
787 Scope
.Table
(Scope
.Last
).Sloc
:= Token_Ptr
;
789 Record_Items
:= P_Pragmas_Opt
;
791 -- Possible Mod Clause
793 if Token
= Tok_At
then
794 Set_Mod_Clause
(Rep_Clause_Node
, P_Mod_Clause
);
795 Set_Pragmas_Before
(Mod_Clause
(Rep_Clause_Node
), Record_Items
);
796 Record_Items
:= P_Pragmas_Opt
;
799 if No
(Record_Items
) then
800 Record_Items
:= New_List
;
803 Set_Component_Clauses
(Rep_Clause_Node
, Record_Items
);
805 -- Loop through component clauses
808 if Token
not in Token_Class_Name
then
812 Append
(P_Component_Clause
, Record_Items
);
813 P_Pragmas_Opt
(Record_Items
);
816 -- Left paren follows USE (Enumeration Representation Clause)
818 elsif Token
= Tok_Left_Paren
then
820 New_Node
(N_Enumeration_Representation_Clause
, For_Loc
);
821 Set_Identifier
(Rep_Clause_Node
, Identifier_Node
);
822 Set_Array_Aggregate
(Rep_Clause_Node
, P_Aggregate
);
824 -- Some other token follows FOR (invalid representation clause)
827 Error_Msg_SC
("invalid representation clause");
833 return Rep_Clause_Node
;
837 Resync_Past_Semicolon
;
840 end P_Representation_Clause
;
842 ----------------------
843 -- 13.1 Local Name --
844 ----------------------
846 -- Local name is always parsed by its parent. In the case of its use in
847 -- pragmas, the check for a local name is handled in Par.Prag and allows
848 -- all the possible forms of local name. For the uses in chapter 13, we
849 -- currently only allow a direct name, but this should probably change???
851 ---------------------------
852 -- 13.1 At Clause (I.7) --
853 ---------------------------
855 -- Parsed by P_Representation_Clause (13.1)
857 ---------------------------------------
858 -- 13.3 Attribute Definition Clause --
859 ---------------------------------------
861 -- Parsed by P_Representation_Clause (13.1)
863 --------------------------------
864 -- 13.1 Aspect Specification --
865 --------------------------------
867 -- ASPECT_SPECIFICATION ::=
868 -- with ASPECT_MARK [=> ASPECT_DEFINITION] {,
869 -- ASPECT_MARK [=> ASPECT_DEFINITION] }
871 -- ASPECT_MARK ::= aspect_IDENTIFIER['Class]
873 -- ASPECT_DEFINITION ::= NAME | EXPRESSION
875 -- Error recovery: cannot raise Error_Resync
877 procedure P_Aspect_Specifications
879 Semicolon
: Boolean := True)
885 -- Aspect Specification is present
889 -- Here we have an aspect specification to scan, note that we don't
890 -- set the flag till later, because it may turn out that we have no
891 -- valid aspects in the list.
893 Aspects
:= Get_Aspect_Specifications
(Semicolon
);
895 -- Here if aspects present
897 if Is_Non_Empty_List
(Aspects
) then
899 -- If Decl is Empty, we just ignore the aspects (the caller in this
900 -- case has always issued an appropriate error message).
905 -- If Decl is Error, we ignore the aspects, and issue a message
907 elsif Decl
= Error
then
908 Error_Msg
("aspect specifications not allowed here", Ptr
);
910 -- Here aspects are allowed, and we store them
913 Set_Parent
(Aspects
, Decl
);
914 Set_Aspect_Specifications
(Decl
, Aspects
);
917 end P_Aspect_Specifications
;
919 ---------------------------------------------
920 -- 13.4 Enumeration Representation Clause --
921 ---------------------------------------------
923 -- Parsed by P_Representation_Clause (13.1)
925 ---------------------------------
926 -- 13.4 Enumeration Aggregate --
927 ---------------------------------
929 -- Parsed by P_Representation_Clause (13.1)
931 ------------------------------------------
932 -- 13.5.1 Record Representation Clause --
933 ------------------------------------------
935 -- Parsed by P_Representation_Clause (13.1)
937 ------------------------------
938 -- 13.5.1 Mod Clause (I.8) --
939 ------------------------------
941 -- MOD_CLAUSE ::= at mod static_EXPRESSION;
943 -- Note: in Ada 83, the expression must be a simple expression
945 -- The caller has checked that the initial Token is AT
947 -- Error recovery: cannot raise Error_Resync
949 -- Note: the caller is responsible for setting the Pragmas_Before field
951 function P_Mod_Clause
return Node_Id
is
956 Mod_Node
:= New_Node
(N_Mod_Clause
, Token_Ptr
);
959 Expr_Node
:= P_Expression_No_Right_Paren
;
960 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
961 Set_Expression
(Mod_Node
, Expr_Node
);
966 ------------------------------
967 -- 13.5.1 Component Clause --
968 ------------------------------
970 -- COMPONENT_CLAUSE ::=
971 -- COMPONENT_CLAUSE_COMPONENT_NAME at POSITION
972 -- range FIRST_BIT .. LAST_BIT;
974 -- COMPONENT_CLAUSE_COMPONENT_NAME ::=
975 -- component_DIRECT_NAME
976 -- | component_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
977 -- | FIRST_SUBTYPE_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
979 -- POSITION ::= static_EXPRESSION
981 -- Note: in Ada 83, the expression must be a simple expression
983 -- FIRST_BIT ::= static_SIMPLE_EXPRESSION
984 -- LAST_BIT ::= static_SIMPLE_EXPRESSION
986 -- Note: the AARM V2.0 grammar has an error at this point, it uses
987 -- EXPRESSION instead of SIMPLE_EXPRESSION for FIRST_BIT and LAST_BIT
989 -- Error recovery: cannot raise Error_Resync
991 function P_Component_Clause
return Node_Id
is
992 Component_Node
: Node_Id
;
997 Component_Node
:= New_Node
(N_Component_Clause
, Token_Ptr
);
1000 if Nkind
(Comp_Name
) = N_Identifier
1001 or else Nkind
(Comp_Name
) = N_Attribute_Reference
1003 Set_Component_Name
(Component_Node
, Comp_Name
);
1006 ("component name must be direct name or attribute", Comp_Name
);
1007 Set_Component_Name
(Component_Node
, Error
);
1010 Set_Sloc
(Component_Node
, Token_Ptr
);
1012 Expr_Node
:= P_Expression_No_Right_Paren
;
1013 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
1014 Set_Position
(Component_Node
, Expr_Node
);
1016 Expr_Node
:= P_Expression_No_Right_Paren
;
1017 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
1018 Set_First_Bit
(Component_Node
, Expr_Node
);
1020 Expr_Node
:= P_Expression_No_Right_Paren
;
1021 Check_Simple_Expression_In_Ada_83
(Expr_Node
);
1022 Set_Last_Bit
(Component_Node
, Expr_Node
);
1024 return Component_Node
;
1025 end P_Component_Clause
;
1027 ----------------------
1028 -- 13.5.1 Position --
1029 ----------------------
1031 -- Parsed by P_Component_Clause (13.5.1)
1033 -----------------------
1034 -- 13.5.1 First Bit --
1035 -----------------------
1037 -- Parsed by P_Component_Clause (13.5.1)
1039 ----------------------
1040 -- 13.5.1 Last Bit --
1041 ----------------------
1043 -- Parsed by P_Component_Clause (13.5.1)
1045 --------------------------
1046 -- 13.8 Code Statement --
1047 --------------------------
1049 -- CODE_STATEMENT ::= QUALIFIED_EXPRESSION
1051 -- On entry the caller has scanned the SUBTYPE_MARK (passed in as the
1052 -- single argument, and the scan points to the apostrophe.
1054 -- Error recovery: can raise Error_Resync
1056 function P_Code_Statement
(Subtype_Mark
: Node_Id
) return Node_Id
is
1060 Scan
; -- past apostrophe
1062 -- If left paren, then we have a possible code statement
1064 if Token
= Tok_Left_Paren
then
1065 Node1
:= New_Node
(N_Code_Statement
, Sloc
(Subtype_Mark
));
1066 Set_Expression
(Node1
, P_Qualified_Expression
(Subtype_Mark
));
1070 -- Otherwise we have an illegal range attribute. Note that P_Name
1071 -- ensures that Token = Tok_Range is the only possibility left here.
1074 Error_Msg_SC
("RANGE attribute illegal here!");
1077 end P_Code_Statement
;