1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 Stringt
; use Stringt
;
35 -- Attributes that cannot have arguments
37 Is_Parameterless_Attribute
: constant Attribute_Class_Array
:=
38 (Attribute_Body_Version
=> True,
39 Attribute_External_Tag
=> True,
40 Attribute_Img
=> True,
41 Attribute_Version
=> True,
42 Attribute_Base
=> True,
43 Attribute_Class
=> True,
44 Attribute_Stub_Type
=> True,
46 -- This map contains True for parameterless attributes that return a
47 -- string or a type. For those attributes, a left parenthesis after
48 -- the attribute should not be analyzed as the beginning of a parameters
49 -- list because it may denote a slice operation (X'Img (1 .. 2)) or
50 -- a type conversion (X'Class (Y)).
52 -- Note that this map designates the minimum set of attributes where a
53 -- construct in parentheses that is not an argument can appear right
54 -- after the attribute. For attributes like 'Size, we do not put them
55 -- in the map. If someone writes X'Size (3), that's illegal in any case,
56 -- but we get a better error message by parsing the (3) as an illegal
57 -- argument to the attribute, rather than some meaningless junk that
58 -- follows the attribute.
60 -----------------------
61 -- Local Subprograms --
62 -----------------------
64 function P_Aggregate_Or_Paren_Expr
return Node_Id
;
65 function P_Allocator
return Node_Id
;
66 function P_Record_Or_Array_Component_Association
return Node_Id
;
67 function P_Factor
return Node_Id
;
68 function P_Primary
return Node_Id
;
69 function P_Relation
return Node_Id
;
70 function P_Term
return Node_Id
;
72 function P_Binary_Adding_Operator
return Node_Kind
;
73 function P_Logical_Operator
return Node_Kind
;
74 function P_Multiplying_Operator
return Node_Kind
;
75 function P_Relational_Operator
return Node_Kind
;
76 function P_Unary_Adding_Operator
return Node_Kind
;
78 procedure Bad_Range_Attribute
(Loc
: Source_Ptr
);
79 -- Called to place complaint about bad range attribute at the given
80 -- source location. Terminates by raising Error_Resync.
82 function P_Range_Attribute_Reference
83 (Prefix_Node
: Node_Id
)
85 -- Scan a range attribute reference. The caller has scanned out the
86 -- prefix. The current token is known to be an apostrophe and the
87 -- following token is known to be RANGE.
89 procedure Set_Op_Name
(Node
: Node_Id
);
90 -- Procedure to set name field (Chars) in operator node
92 -------------------------
93 -- Bad_Range_Attribute --
94 -------------------------
96 procedure Bad_Range_Attribute
(Loc
: Source_Ptr
) is
98 Error_Msg
("range attribute cannot be used in expression!", Loc
);
100 end Bad_Range_Attribute
;
106 procedure Set_Op_Name
(Node
: Node_Id
) is
107 type Name_Of_Type
is array (N_Op
) of Name_Id
;
108 Name_Of
: constant Name_Of_Type
:= Name_Of_Type
'(
109 N_Op_And => Name_Op_And,
110 N_Op_Or => Name_Op_Or,
111 N_Op_Xor => Name_Op_Xor,
112 N_Op_Eq => Name_Op_Eq,
113 N_Op_Ne => Name_Op_Ne,
114 N_Op_Lt => Name_Op_Lt,
115 N_Op_Le => Name_Op_Le,
116 N_Op_Gt => Name_Op_Gt,
117 N_Op_Ge => Name_Op_Ge,
118 N_Op_Add => Name_Op_Add,
119 N_Op_Subtract => Name_Op_Subtract,
120 N_Op_Concat => Name_Op_Concat,
121 N_Op_Multiply => Name_Op_Multiply,
122 N_Op_Divide => Name_Op_Divide,
123 N_Op_Mod => Name_Op_Mod,
124 N_Op_Rem => Name_Op_Rem,
125 N_Op_Expon => Name_Op_Expon,
126 N_Op_Plus => Name_Op_Add,
127 N_Op_Minus => Name_Op_Subtract,
128 N_Op_Abs => Name_Op_Abs,
129 N_Op_Not => Name_Op_Not,
131 -- We don't really need these shift operators, since they never
132 -- appear as operators in the source, but the path of least
133 -- resistance is to put them in (the aggregate must be complete)
135 N_Op_Rotate_Left => Name_Rotate_Left,
136 N_Op_Rotate_Right => Name_Rotate_Right,
137 N_Op_Shift_Left => Name_Shift_Left,
138 N_Op_Shift_Right => Name_Shift_Right,
139 N_Op_Shift_Right_Arithmetic => Name_Shift_Right_Arithmetic);
142 if Nkind (Node) in N_Op then
143 Set_Chars (Node, Name_Of (Nkind (Node)));
147 --------------------------
148 -- 4.1 Name (also 6.4) --
149 --------------------------
152 -- DIRECT_NAME | EXPLICIT_DEREFERENCE
153 -- | INDEXED_COMPONENT | SLICE
154 -- | SELECTED_COMPONENT | ATTRIBUTE
155 -- | TYPE_CONVERSION | FUNCTION_CALL
156 -- | CHARACTER_LITERAL
158 -- DIRECT_NAME ::= IDENTIFIER | OPERATOR_SYMBOL
160 -- PREFIX ::= NAME | IMPLICIT_DEREFERENCE
162 -- EXPLICIT_DEREFERENCE ::= NAME . all
164 -- IMPLICIT_DEREFERENCE ::= NAME
166 -- INDEXED_COMPONENT ::= PREFIX (EXPRESSION {, EXPRESSION})
168 -- SLICE ::= PREFIX (DISCRETE_RANGE)
170 -- SELECTED_COMPONENT ::= PREFIX . SELECTOR_NAME
172 -- SELECTOR_NAME ::= IDENTIFIER | CHARACTER_LITERAL | OPERATOR_SYMBOL
174 -- ATTRIBUTE_REFERENCE ::= PREFIX ' ATTRIBUTE_DESIGNATOR
176 -- ATTRIBUTE_DESIGNATOR ::=
177 -- IDENTIFIER [(static_EXPRESSION)]
178 -- | access | delta | digits
182 -- | function_PREFIX ACTUAL_PARAMETER_PART
184 -- ACTUAL_PARAMETER_PART ::=
185 -- (PARAMETER_ASSOCIATION {,PARAMETER_ASSOCIATION})
187 -- PARAMETER_ASSOCIATION ::=
188 -- [formal_parameter_SELECTOR_NAME =>] EXPLICIT_ACTUAL_PARAMETER
190 -- EXPLICIT_ACTUAL_PARAMETER ::= EXPRESSION | variable_NAME
192 -- Note: syntactically a procedure call looks just like a function call,
193 -- so this routine is in practice used to scan out procedure calls as well.
195 -- On return, Expr_Form is set to either EF_Name or EF_Simple_Name
197 -- Error recovery: can raise Error_Resync
199 -- Note: if on return Token = Tok_Apostrophe, then the apostrophe must be
200 -- followed by either a left paren (qualified expression case), or by
201 -- range (range attribute case). All other uses of apostrophe (i.e. all
202 -- other attributes) are handled in this routine.
204 -- Error recovery: can raise Error_Resync
206 function P_Name
return Node_Id
is
207 Scan_State
: Saved_Scan_State
;
209 Prefix_Node
: Node_Id
;
210 Ident_Node
: Node_Id
;
212 Range_Node
: Node_Id
;
215 Arg_List
: List_Id
:= No_List
; -- kill junk warning
216 Attr_Name
: Name_Id
:= No_Name
; -- kill junk warning
219 -- Case of not a name
221 if Token
not in Token_Class_Name
then
223 -- If it looks like start of expression, complain and scan expression
225 if Token
in Token_Class_Literal
226 or else Token
= Tok_Left_Paren
228 Error_Msg_SC
("name expected");
231 -- Otherwise some other junk, not much we can do
234 Error_Msg_AP
("name expected");
239 -- Loop through designators in qualified name
241 Name_Node
:= Token_Node
;
244 Scan
; -- past designator
245 exit when Token
/= Tok_Dot
;
246 Save_Scan_State
(Scan_State
); -- at dot
249 -- If we do not have another designator after the dot, then join
250 -- the normal circuit to handle a dot extension (may be .all or
251 -- character literal case). Otherwise loop back to scan the next
254 if Token
not in Token_Class_Desig
then
255 goto Scan_Name_Extension_Dot
;
257 Prefix_Node
:= Name_Node
;
258 Name_Node
:= New_Node
(N_Selected_Component
, Prev_Token_Ptr
);
259 Set_Prefix
(Name_Node
, Prefix_Node
);
260 Set_Selector_Name
(Name_Node
, Token_Node
);
264 -- We have now scanned out a qualified designator. If the last token is
265 -- an operator symbol, then we certainly do not have the Snam case, so
266 -- we can just use the normal name extension check circuit
268 if Prev_Token
= Tok_Operator_Symbol
then
269 goto Scan_Name_Extension
;
272 -- We have scanned out a qualified simple name, check for name extension
273 -- Note that we know there is no dot here at this stage, so the only
274 -- possible cases of name extension are apostrophe and left paren.
276 if Token
= Tok_Apostrophe
then
277 Save_Scan_State
(Scan_State
); -- at apostrophe
278 Scan
; -- past apostrophe
280 -- If left paren, then this might be a qualified expression, but we
281 -- are only in the business of scanning out names, so return with
282 -- Token backed up to point to the apostrophe. The treatment for
283 -- the range attribute is similar (we do not consider x'range to
284 -- be a name in this grammar).
286 if Token
= Tok_Left_Paren
or else Token
= Tok_Range
then
287 Restore_Scan_State
(Scan_State
); -- to apostrophe
288 Expr_Form
:= EF_Simple_Name
;
291 -- Otherwise we have the case of a name extended by an attribute
294 goto Scan_Name_Extension_Apostrophe
;
297 -- Check case of qualified simple name extended by a left parenthesis
299 elsif Token
= Tok_Left_Paren
then
300 Scan
; -- past left paren
301 goto Scan_Name_Extension_Left_Paren
;
303 -- Otherwise the qualified simple name is not extended, so return
306 Expr_Form
:= EF_Simple_Name
;
310 -- Loop scanning past name extensions. A label is used for control
311 -- transfer for this loop for ease of interfacing with the finite state
312 -- machine in the parenthesis scanning circuit, and also to allow for
313 -- passing in control to the appropriate point from the above code.
315 <<Scan_Name_Extension
>>
317 -- Character literal used as name cannot be extended. Also this
318 -- cannot be a call, since the name for a call must be a designator.
319 -- Return in these cases, or if there is no name extension
321 if Token
not in Token_Class_Namext
322 or else Prev_Token
= Tok_Char_Literal
324 Expr_Form
:= EF_Name
;
328 -- Merge here when we know there is a name extension
330 <<Scan_Name_Extension_OK
>>
332 if Token
= Tok_Left_Paren
then
333 Scan
; -- past left paren
334 goto Scan_Name_Extension_Left_Paren
;
336 elsif Token
= Tok_Apostrophe
then
337 Save_Scan_State
(Scan_State
); -- at apostrophe
338 Scan
; -- past apostrophe
339 goto Scan_Name_Extension_Apostrophe
;
341 else -- Token = Tok_Dot
342 Save_Scan_State
(Scan_State
); -- at dot
344 goto Scan_Name_Extension_Dot
;
347 -- Case of name extended by dot (selection), dot is already skipped
348 -- and the scan state at the point of the dot is saved in Scan_State.
350 <<Scan_Name_Extension_Dot
>>
352 -- Explicit dereference case
354 if Token
= Tok_All
then
355 Prefix_Node
:= Name_Node
;
356 Name_Node
:= New_Node
(N_Explicit_Dereference
, Token_Ptr
);
357 Set_Prefix
(Name_Node
, Prefix_Node
);
359 goto Scan_Name_Extension
;
361 -- Selected component case
363 elsif Token
in Token_Class_Name
then
364 Prefix_Node
:= Name_Node
;
365 Name_Node
:= New_Node
(N_Selected_Component
, Prev_Token_Ptr
);
366 Set_Prefix
(Name_Node
, Prefix_Node
);
367 Set_Selector_Name
(Name_Node
, Token_Node
);
368 Scan
; -- past selector
369 goto Scan_Name_Extension
;
371 -- Reserved identifier as selector
373 elsif Is_Reserved_Identifier
then
374 Scan_Reserved_Identifier
(Force_Msg
=> False);
375 Prefix_Node
:= Name_Node
;
376 Name_Node
:= New_Node
(N_Selected_Component
, Prev_Token_Ptr
);
377 Set_Prefix
(Name_Node
, Prefix_Node
);
378 Set_Selector_Name
(Name_Node
, Token_Node
);
379 Scan
; -- past identifier used as selector
380 goto Scan_Name_Extension
;
382 -- If dot is at end of line and followed by nothing legal,
383 -- then assume end of name and quit (dot will be taken as
384 -- an erroneous form of some other punctuation by our caller).
386 elsif Token_Is_At_Start_Of_Line
then
387 Restore_Scan_State
(Scan_State
);
390 -- Here if nothing legal after the dot
393 Error_Msg_AP
("selector expected");
397 -- Here for an apostrophe as name extension. The scan position at the
398 -- apostrophe has already been saved, and the apostrophe scanned out.
400 <<Scan_Name_Extension_Apostrophe
>>
402 Scan_Apostrophe
: declare
403 function Apostrophe_Should_Be_Semicolon
return Boolean;
404 -- Checks for case where apostrophe should probably be
405 -- a semicolon, and if so, gives appropriate message,
406 -- resets the scan pointer to the apostrophe, changes
407 -- the current token to Tok_Semicolon, and returns True.
408 -- Otherwise returns False.
410 function Apostrophe_Should_Be_Semicolon
return Boolean is
412 if Token_Is_At_Start_Of_Line
then
413 Restore_Scan_State
(Scan_State
); -- to apostrophe
414 Error_Msg_SC
("|""''"" should be "";""");
415 Token
:= Tok_Semicolon
;
420 end Apostrophe_Should_Be_Semicolon
;
422 -- Start of processing for Scan_Apostrophe
425 -- If range attribute after apostrophe, then return with Token
426 -- pointing to the apostrophe. Note that in this case the prefix
427 -- need not be a simple name (cases like A.all'range). Similarly
428 -- if there is a left paren after the apostrophe, then we also
429 -- return with Token pointing to the apostrophe (this is the
430 -- qualified expression case).
432 if Token
= Tok_Range
or else Token
= Tok_Left_Paren
then
433 Restore_Scan_State
(Scan_State
); -- to apostrophe
434 Expr_Form
:= EF_Name
;
437 -- Here for cases where attribute designator is an identifier
439 elsif Token
= Tok_Identifier
then
440 Attr_Name
:= Token_Name
;
442 if not Is_Attribute_Name
(Attr_Name
) then
443 if Apostrophe_Should_Be_Semicolon
then
444 Expr_Form
:= EF_Name
;
447 -- Here for a bad attribute name
450 Signal_Bad_Attribute
;
451 Scan
; -- past bad identifier
453 if Token
= Tok_Left_Paren
then
454 Scan
; -- past left paren
457 Discard_Junk_Node
(P_Expression
);
458 exit when not Comma_Present
;
469 Style
.Check_Attribute_Name
(False);
472 -- Here for case of attribute designator is not an identifier
475 if Token
= Tok_Delta
then
476 Attr_Name
:= Name_Delta
;
478 elsif Token
= Tok_Digits
then
479 Attr_Name
:= Name_Digits
;
481 elsif Token
= Tok_Access
then
482 Attr_Name
:= Name_Access
;
484 elsif Token
= Tok_Mod
and then Ada_Version
= Ada_05
then
485 Attr_Name
:= Name_Mod
;
487 elsif Apostrophe_Should_Be_Semicolon
then
488 Expr_Form
:= EF_Name
;
492 Error_Msg_AP
("attribute designator expected");
497 Style
.Check_Attribute_Name
(True);
501 -- We come here with an OK attribute scanned, and the
502 -- corresponding Attribute identifier node stored in Ident_Node.
504 Prefix_Node
:= Name_Node
;
505 Name_Node
:= New_Node
(N_Attribute_Reference
, Prev_Token_Ptr
);
506 Scan
; -- past attribute designator
507 Set_Prefix
(Name_Node
, Prefix_Node
);
508 Set_Attribute_Name
(Name_Node
, Attr_Name
);
510 -- Scan attribute arguments/designator. We skip this if we know
511 -- that the attribute cannot have an argument.
513 if Token
= Tok_Left_Paren
515 Is_Parameterless_Attribute
(Get_Attribute_Id
(Attr_Name
))
517 Set_Expressions
(Name_Node
, New_List
);
518 Scan
; -- past left paren
522 Expr
: constant Node_Id
:= P_Expression
;
525 if Token
= Tok_Arrow
then
527 ("named parameters not permitted for attributes");
528 Scan
; -- past junk arrow
531 Append
(Expr
, Expressions
(Name_Node
));
532 exit when not Comma_Present
;
540 goto Scan_Name_Extension
;
543 -- Here for left parenthesis extending name (left paren skipped)
545 <<Scan_Name_Extension_Left_Paren
>>
547 -- We now have to scan through a list of items, terminated by a
548 -- right parenthesis. The scan is handled by a finite state
549 -- machine. The possibilities are:
553 -- This is a slice. This case is handled in LP_State_Init
555 -- (expression, expression, ..)
557 -- This is interpreted as an indexed component, i.e. as a
558 -- case of a name which can be extended in the normal manner.
559 -- This case is handled by LP_State_Name or LP_State_Expr.
561 -- (..., identifier => expression , ...)
563 -- If there is at least one occurrence of identifier => (but
564 -- none of the other cases apply), then we have a call.
566 -- Test for Id => case
568 if Token
= Tok_Identifier
then
569 Save_Scan_State
(Scan_State
); -- at Id
572 -- Test for => (allow := as an error substitute)
574 if Token
= Tok_Arrow
or else Token
= Tok_Colon_Equal
then
575 Restore_Scan_State
(Scan_State
); -- to Id
576 Arg_List
:= New_List
;
580 Restore_Scan_State
(Scan_State
); -- to Id
584 -- Here we have an expression after all
586 Expr_Node
:= P_Expression_Or_Range_Attribute
;
588 -- Check cases of discrete range for a slice
590 -- First possibility: Range_Attribute_Reference
592 if Expr_Form
= EF_Range_Attr
then
593 Range_Node
:= Expr_Node
;
595 -- Second possibility: Simple_expression .. Simple_expression
597 elsif Token
= Tok_Dot_Dot
then
598 Check_Simple_Expression
(Expr_Node
);
599 Range_Node
:= New_Node
(N_Range
, Token_Ptr
);
600 Set_Low_Bound
(Range_Node
, Expr_Node
);
602 Expr_Node
:= P_Expression
;
603 Check_Simple_Expression
(Expr_Node
);
604 Set_High_Bound
(Range_Node
, Expr_Node
);
606 -- Third possibility: Type_name range Range
608 elsif Token
= Tok_Range
then
609 if Expr_Form
/= EF_Simple_Name
then
610 Error_Msg_SC
("subtype mark must precede RANGE");
614 Range_Node
:= P_Subtype_Indication
(Expr_Node
);
616 -- Otherwise we just have an expression. It is true that we might
617 -- have a subtype mark without a range constraint but this case
618 -- is syntactically indistinguishable from the expression case.
621 Arg_List
:= New_List
;
625 -- Fall through here with unmistakable Discrete range scanned,
626 -- which means that we definitely have the case of a slice. The
627 -- Discrete range is in Range_Node.
629 if Token
= Tok_Comma
then
630 Error_Msg_SC
("slice cannot have more than one dimension");
633 elsif Token
/= Tok_Right_Paren
then
638 Scan
; -- past right paren
639 Prefix_Node
:= Name_Node
;
640 Name_Node
:= New_Node
(N_Slice
, Sloc
(Prefix_Node
));
641 Set_Prefix
(Name_Node
, Prefix_Node
);
642 Set_Discrete_Range
(Name_Node
, Range_Node
);
644 -- An operator node is legal as a prefix to other names,
645 -- but not for a slice.
647 if Nkind
(Prefix_Node
) = N_Operator_Symbol
then
648 Error_Msg_N
("illegal prefix for slice", Prefix_Node
);
651 -- If we have a name extension, go scan it
653 if Token
in Token_Class_Namext
then
654 goto Scan_Name_Extension_OK
;
656 -- Otherwise return (a slice is a name, but is not a call)
659 Expr_Form
:= EF_Name
;
664 -- In LP_State_Expr, we have scanned one or more expressions, and
665 -- so we have a call or an indexed component which is a name. On
666 -- entry we have the expression just scanned in Expr_Node and
667 -- Arg_List contains the list of expressions encountered so far
670 Append
(Expr_Node
, Arg_List
);
672 if Token
= Tok_Arrow
then
674 ("expect identifier in parameter association",
678 elsif not Comma_Present
then
680 Prefix_Node
:= Name_Node
;
681 Name_Node
:= New_Node
(N_Indexed_Component
, Sloc
(Prefix_Node
));
682 Set_Prefix
(Name_Node
, Prefix_Node
);
683 Set_Expressions
(Name_Node
, Arg_List
);
684 goto Scan_Name_Extension
;
687 -- Comma present (and scanned out), test for identifier => case
688 -- Test for identifier => case
690 if Token
= Tok_Identifier
then
691 Save_Scan_State
(Scan_State
); -- at Id
694 -- Test for => (allow := as error substitute)
696 if Token
= Tok_Arrow
or else Token
= Tok_Colon_Equal
then
697 Restore_Scan_State
(Scan_State
); -- to Id
700 -- Otherwise it's just an expression after all, so backup
703 Restore_Scan_State
(Scan_State
); -- to Id
707 -- Here we have an expression after all, so stay in this state
709 Expr_Node
:= P_Expression
;
712 -- LP_State_Call corresponds to the situation in which at least
713 -- one instance of Id => Expression has been encountered, so we
714 -- know that we do not have a name, but rather a call. We enter
715 -- it with the scan pointer pointing to the next argument to scan,
716 -- and Arg_List containing the list of arguments scanned so far.
720 -- Test for case of Id => Expression (named parameter)
722 if Token
= Tok_Identifier
then
723 Save_Scan_State
(Scan_State
); -- at Id
724 Ident_Node
:= Token_Node
;
727 -- Deal with => (allow := as erroneous substitute)
729 if Token
= Tok_Arrow
or else Token
= Tok_Colon_Equal
then
731 New_Node
(N_Parameter_Association
, Prev_Token_Ptr
);
732 Set_Selector_Name
(Arg_Node
, Ident_Node
);
734 Set_Explicit_Actual_Parameter
(Arg_Node
, P_Expression
);
735 Append
(Arg_Node
, Arg_List
);
737 -- If a comma follows, go back and scan next entry
739 if Comma_Present
then
742 -- Otherwise we have the end of a call
745 Prefix_Node
:= Name_Node
;
747 New_Node
(N_Function_Call
, Sloc
(Prefix_Node
));
748 Set_Name
(Name_Node
, Prefix_Node
);
749 Set_Parameter_Associations
(Name_Node
, Arg_List
);
752 if Token
in Token_Class_Namext
then
753 goto Scan_Name_Extension_OK
;
755 -- This is a case of a call which cannot be a name
758 Expr_Form
:= EF_Name
;
763 -- Not named parameter: Id started an expression after all
766 Restore_Scan_State
(Scan_State
); -- to Id
770 -- Here if entry did not start with Id => which means that it
771 -- is a positional parameter, which is not allowed, since we
772 -- have seen at least one named parameter already.
775 ("positional parameter association " &
776 "not allowed after named one");
778 Expr_Node
:= P_Expression
;
780 -- Leaving the '>' in an association is not unusual, so suggest
783 if Nkind
(Expr_Node
) = N_Op_Eq
then
784 Error_Msg_N
("\maybe `='>` was intended", Expr_Node
);
787 -- We go back to scanning out expressions, so that we do not get
788 -- multiple error messages when several positional parameters
789 -- follow a named parameter.
793 -- End of treatment for name extensions starting with left paren
795 -- End of loop through name extensions
799 -- This function parses a restricted form of Names which are either
800 -- designators, or designators preceded by a sequence of prefixes
801 -- that are direct names.
803 -- Error recovery: cannot raise Error_Resync
805 function P_Function_Name
return Node_Id
is
806 Designator_Node
: Node_Id
;
807 Prefix_Node
: Node_Id
;
808 Selector_Node
: Node_Id
;
809 Dot_Sloc
: Source_Ptr
:= No_Location
;
812 -- Prefix_Node is set to the gathered prefix so far, Empty means that
813 -- no prefix has been scanned. This allows us to build up the result
814 -- in the required right recursive manner.
816 Prefix_Node
:= Empty
;
818 -- Loop through prefixes
821 Designator_Node
:= Token_Node
;
823 if Token
not in Token_Class_Desig
then
824 return P_Identifier
; -- let P_Identifier issue the error message
826 else -- Token in Token_Class_Desig
827 Scan
; -- past designator
828 exit when Token
/= Tok_Dot
;
831 -- Here at a dot, with token just before it in Designator_Node
833 if No
(Prefix_Node
) then
834 Prefix_Node
:= Designator_Node
;
836 Selector_Node
:= New_Node
(N_Selected_Component
, Dot_Sloc
);
837 Set_Prefix
(Selector_Node
, Prefix_Node
);
838 Set_Selector_Name
(Selector_Node
, Designator_Node
);
839 Prefix_Node
:= Selector_Node
;
842 Dot_Sloc
:= Token_Ptr
;
846 -- Fall out of the loop having just scanned a designator
848 if No
(Prefix_Node
) then
849 return Designator_Node
;
851 Selector_Node
:= New_Node
(N_Selected_Component
, Dot_Sloc
);
852 Set_Prefix
(Selector_Node
, Prefix_Node
);
853 Set_Selector_Name
(Selector_Node
, Designator_Node
);
854 return Selector_Node
;
863 -- This function parses a restricted form of Names which are either
864 -- identifiers, or identifiers preceded by a sequence of prefixes
865 -- that are direct names.
867 -- Error recovery: cannot raise Error_Resync
869 function P_Qualified_Simple_Name
return Node_Id
is
870 Designator_Node
: Node_Id
;
871 Prefix_Node
: Node_Id
;
872 Selector_Node
: Node_Id
;
873 Dot_Sloc
: Source_Ptr
:= No_Location
;
876 -- Prefix node is set to the gathered prefix so far, Empty means that
877 -- no prefix has been scanned. This allows us to build up the result
878 -- in the required right recursive manner.
880 Prefix_Node
:= Empty
;
882 -- Loop through prefixes
885 Designator_Node
:= Token_Node
;
887 if Token
= Tok_Identifier
then
888 Scan
; -- past identifier
889 exit when Token
/= Tok_Dot
;
891 elsif Token
not in Token_Class_Desig
then
892 return P_Identifier
; -- let P_Identifier issue the error message
895 Scan
; -- past designator
897 if Token
/= Tok_Dot
then
898 Error_Msg_SP
("identifier expected");
903 -- Here at a dot, with token just before it in Designator_Node
905 if No
(Prefix_Node
) then
906 Prefix_Node
:= Designator_Node
;
908 Selector_Node
:= New_Node
(N_Selected_Component
, Dot_Sloc
);
909 Set_Prefix
(Selector_Node
, Prefix_Node
);
910 Set_Selector_Name
(Selector_Node
, Designator_Node
);
911 Prefix_Node
:= Selector_Node
;
914 Dot_Sloc
:= Token_Ptr
;
918 -- Fall out of the loop having just scanned an identifier
920 if No
(Prefix_Node
) then
921 return Designator_Node
;
923 Selector_Node
:= New_Node
(N_Selected_Component
, Dot_Sloc
);
924 Set_Prefix
(Selector_Node
, Prefix_Node
);
925 Set_Selector_Name
(Selector_Node
, Designator_Node
);
926 return Selector_Node
;
933 end P_Qualified_Simple_Name
;
935 -- This procedure differs from P_Qualified_Simple_Name only in that it
936 -- raises Error_Resync if any error is encountered. It only returns after
937 -- scanning a valid qualified simple name.
939 -- Error recovery: can raise Error_Resync
941 function P_Qualified_Simple_Name_Resync
return Node_Id
is
942 Designator_Node
: Node_Id
;
943 Prefix_Node
: Node_Id
;
944 Selector_Node
: Node_Id
;
945 Dot_Sloc
: Source_Ptr
:= No_Location
;
948 Prefix_Node
:= Empty
;
950 -- Loop through prefixes
953 Designator_Node
:= Token_Node
;
955 if Token
= Tok_Identifier
then
956 Scan
; -- past identifier
957 exit when Token
/= Tok_Dot
;
959 elsif Token
not in Token_Class_Desig
then
960 Discard_Junk_Node
(P_Identifier
); -- to issue the error message
964 Scan
; -- past designator
966 if Token
/= Tok_Dot
then
967 Error_Msg_SP
("identifier expected");
972 -- Here at a dot, with token just before it in Designator_Node
974 if No
(Prefix_Node
) then
975 Prefix_Node
:= Designator_Node
;
977 Selector_Node
:= New_Node
(N_Selected_Component
, Dot_Sloc
);
978 Set_Prefix
(Selector_Node
, Prefix_Node
);
979 Set_Selector_Name
(Selector_Node
, Designator_Node
);
980 Prefix_Node
:= Selector_Node
;
983 Dot_Sloc
:= Token_Ptr
;
987 -- Fall out of the loop having just scanned an identifier
989 if No
(Prefix_Node
) then
990 return Designator_Node
;
992 Selector_Node
:= New_Node
(N_Selected_Component
, Dot_Sloc
);
993 Set_Prefix
(Selector_Node
, Prefix_Node
);
994 Set_Selector_Name
(Selector_Node
, Designator_Node
);
995 return Selector_Node
;
998 end P_Qualified_Simple_Name_Resync
;
1000 ----------------------
1001 -- 4.1 Direct_Name --
1002 ----------------------
1004 -- Parsed by P_Name and other functions in section 4.1
1010 -- Parsed by P_Name (4.1)
1012 -------------------------------
1013 -- 4.1 Explicit Dereference --
1014 -------------------------------
1016 -- Parsed by P_Name (4.1)
1018 -------------------------------
1019 -- 4.1 Implicit_Dereference --
1020 -------------------------------
1022 -- Parsed by P_Name (4.1)
1024 ----------------------------
1025 -- 4.1 Indexed Component --
1026 ----------------------------
1028 -- Parsed by P_Name (4.1)
1034 -- Parsed by P_Name (4.1)
1036 -----------------------------
1037 -- 4.1 Selected_Component --
1038 -----------------------------
1040 -- Parsed by P_Name (4.1)
1042 ------------------------
1043 -- 4.1 Selector Name --
1044 ------------------------
1046 -- Parsed by P_Name (4.1)
1048 ------------------------------
1049 -- 4.1 Attribute Reference --
1050 ------------------------------
1052 -- Parsed by P_Name (4.1)
1054 -------------------------------
1055 -- 4.1 Attribute Designator --
1056 -------------------------------
1058 -- Parsed by P_Name (4.1)
1060 --------------------------------------
1061 -- 4.1.4 Range Attribute Reference --
1062 --------------------------------------
1064 -- RANGE_ATTRIBUTE_REFERENCE ::= PREFIX ' RANGE_ATTRIBUTE_DESIGNATOR
1066 -- RANGE_ATTRIBUTE_DESIGNATOR ::= range [(static_EXPRESSION)]
1068 -- In the grammar, a RANGE attribute is simply a name, but its use is
1069 -- highly restricted, so in the parser, we do not regard it as a name.
1070 -- Instead, P_Name returns without scanning the 'RANGE part of the
1071 -- attribute, and the caller uses the following function to construct
1072 -- a range attribute in places where it is appropriate.
1074 -- Note that RANGE here is treated essentially as an identifier,
1075 -- rather than a reserved word.
1077 -- The caller has parsed the prefix, i.e. a name, and Token points to
1078 -- the apostrophe. The token after the apostrophe is known to be RANGE
1079 -- at this point. The prefix node becomes the prefix of the attribute.
1081 -- Error_Recovery: Cannot raise Error_Resync
1083 function P_Range_Attribute_Reference
1084 (Prefix_Node
: Node_Id
)
1087 Attr_Node
: Node_Id
;
1090 Attr_Node
:= New_Node
(N_Attribute_Reference
, Token_Ptr
);
1091 Set_Prefix
(Attr_Node
, Prefix_Node
);
1092 Scan
; -- past apostrophe
1095 Style
.Check_Attribute_Name
(True);
1098 Set_Attribute_Name
(Attr_Node
, Name_Range
);
1101 if Token
= Tok_Left_Paren
then
1102 Scan
; -- past left paren
1103 Set_Expressions
(Attr_Node
, New_List
(P_Expression
));
1108 end P_Range_Attribute_Reference
;
1110 ---------------------------------------
1111 -- 4.1.4 Range Attribute Designator --
1112 ---------------------------------------
1114 -- Parsed by P_Range_Attribute_Reference (4.4)
1116 --------------------
1118 --------------------
1120 -- AGGREGATE ::= RECORD_AGGREGATE | EXTENSION_AGGREGATE | ARRAY_AGGREGATE
1122 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3), except in the case where
1123 -- an aggregate is known to be required (code statement, extension
1124 -- aggregate), in which cases this routine performs the necessary check
1125 -- that we have an aggregate rather than a parenthesized expression
1127 -- Error recovery: can raise Error_Resync
1129 function P_Aggregate
return Node_Id
is
1130 Aggr_Sloc
: constant Source_Ptr
:= Token_Ptr
;
1131 Aggr_Node
: constant Node_Id
:= P_Aggregate_Or_Paren_Expr
;
1134 if Nkind
(Aggr_Node
) /= N_Aggregate
1136 Nkind
(Aggr_Node
) /= N_Extension_Aggregate
1139 ("aggregate may not have single positional component", Aggr_Sloc
);
1146 ------------------------------------------------
1147 -- 4.3 Aggregate or Parenthesized Expression --
1148 ------------------------------------------------
1150 -- This procedure parses out either an aggregate or a parenthesized
1151 -- expression (these two constructs are closely related, since a
1152 -- parenthesized expression looks like an aggregate with a single
1153 -- positional component).
1156 -- RECORD_AGGREGATE | EXTENSION_AGGREGATE | ARRAY_AGGREGATE
1158 -- RECORD_AGGREGATE ::= (RECORD_COMPONENT_ASSOCIATION_LIST)
1160 -- RECORD_COMPONENT_ASSOCIATION_LIST ::=
1161 -- RECORD_COMPONENT_ASSOCIATION {, RECORD_COMPONENT_ASSOCIATION}
1164 -- RECORD_COMPONENT_ASSOCIATION ::=
1165 -- [COMPONENT_CHOICE_LIST =>] EXPRESSION
1167 -- COMPONENT_CHOICE_LIST ::=
1168 -- component_SELECTOR_NAME {| component_SELECTOR_NAME}
1171 -- EXTENSION_AGGREGATE ::=
1172 -- (ANCESTOR_PART with RECORD_COMPONENT_ASSOCIATION_LIST)
1174 -- ANCESTOR_PART ::= EXPRESSION | SUBTYPE_MARK
1176 -- ARRAY_AGGREGATE ::=
1177 -- POSITIONAL_ARRAY_AGGREGATE | NAMED_ARRAY_AGGREGATE
1179 -- POSITIONAL_ARRAY_AGGREGATE ::=
1180 -- (EXPRESSION, EXPRESSION {, EXPRESSION})
1181 -- | (EXPRESSION {, EXPRESSION}, others => EXPRESSION)
1182 -- | (EXPRESSION {, EXPRESSION}, others => <>)
1184 -- NAMED_ARRAY_AGGREGATE ::=
1185 -- (ARRAY_COMPONENT_ASSOCIATION {, ARRAY_COMPONENT_ASSOCIATION})
1187 -- PRIMARY ::= (EXPRESSION);
1189 -- Error recovery: can raise Error_Resync
1191 -- Note: POSITIONAL_ARRAY_AGGREGATE rule has been extended to give support
1192 -- to Ada 2005 limited aggregates (AI-287)
1194 function P_Aggregate_Or_Paren_Expr
return Node_Id
is
1195 Aggregate_Node
: Node_Id
;
1196 Expr_List
: List_Id
;
1197 Assoc_List
: List_Id
;
1198 Expr_Node
: Node_Id
;
1199 Lparen_Sloc
: Source_Ptr
;
1200 Scan_State
: Saved_Scan_State
;
1203 Lparen_Sloc
:= Token_Ptr
;
1206 -- Note: the mechanism used here of rescanning the initial expression
1207 -- is distinctly unpleasant, but it saves a lot of fiddling in scanning
1208 -- out the discrete choice list.
1210 -- Deal with expression and extension aggregate cases first
1212 if Token
/= Tok_Others
then
1213 Save_Scan_State
(Scan_State
); -- at start of expression
1215 -- Deal with (NULL RECORD) case
1217 if Token
= Tok_Null
then
1220 if Token
= Tok_Record
then
1221 Aggregate_Node
:= New_Node
(N_Aggregate
, Lparen_Sloc
);
1222 Set_Null_Record_Present
(Aggregate_Node
, True);
1223 Scan
; -- past RECORD
1225 return Aggregate_Node
;
1227 Restore_Scan_State
(Scan_State
); -- to NULL that must be expr
1231 -- Ada 2005 (AI-287): The box notation is allowed only with named
1232 -- notation because positional notation might be error prone. For
1233 -- example, in "(X, <>, Y, <>)", there is no type associated with
1234 -- the boxes, so you might not be leaving out the components you
1235 -- thought you were leaving out.
1237 if Ada_Version
>= Ada_05
and then Token
= Tok_Box
then
1238 Error_Msg_SC
("(Ada 2005) box notation only allowed with "
1239 & "named notation");
1241 Aggregate_Node
:= New_Node
(N_Aggregate
, Lparen_Sloc
);
1242 return Aggregate_Node
;
1245 Expr_Node
:= P_Expression_Or_Range_Attribute
;
1247 -- Extension aggregate case
1249 if Token
= Tok_With
then
1251 if Nkind
(Expr_Node
) = N_Attribute_Reference
1252 and then Attribute_Name
(Expr_Node
) = Name_Range
1254 Bad_Range_Attribute
(Sloc
(Expr_Node
));
1258 if Ada_Version
= Ada_83
then
1259 Error_Msg_SC
("(Ada 83) extension aggregate not allowed");
1262 Aggregate_Node
:= New_Node
(N_Extension_Aggregate
, Lparen_Sloc
);
1263 Set_Ancestor_Part
(Aggregate_Node
, Expr_Node
);
1266 -- Deal with WITH NULL RECORD case
1268 if Token
= Tok_Null
then
1269 Save_Scan_State
(Scan_State
); -- at NULL
1272 if Token
= Tok_Record
then
1273 Scan
; -- past RECORD
1274 Set_Null_Record_Present
(Aggregate_Node
, True);
1276 return Aggregate_Node
;
1279 Restore_Scan_State
(Scan_State
); -- to NULL that must be expr
1283 if Token
/= Tok_Others
then
1284 Save_Scan_State
(Scan_State
);
1285 Expr_Node
:= P_Expression
;
1292 elsif Token
= Tok_Right_Paren
or else Token
in Token_Class_Eterm
then
1293 if Nkind
(Expr_Node
) = N_Attribute_Reference
1294 and then Attribute_Name
(Expr_Node
) = Name_Range
1297 ("|parentheses not allowed for range attribute", Lparen_Sloc
);
1298 Scan
; -- past right paren
1302 -- Bump paren count of expression
1304 if Expr_Node
/= Error
then
1305 Set_Paren_Count
(Expr_Node
, Paren_Count
(Expr_Node
) + 1);
1308 T_Right_Paren
; -- past right paren (error message if none)
1311 -- Normal aggregate case
1314 Aggregate_Node
:= New_Node
(N_Aggregate
, Lparen_Sloc
);
1320 Aggregate_Node
:= New_Node
(N_Aggregate
, Lparen_Sloc
);
1324 -- Prepare to scan list of component associations
1326 Expr_List
:= No_List
; -- don't set yet, maybe all named entries
1327 Assoc_List
:= No_List
; -- don't set yet, maybe all positional entries
1329 -- This loop scans through component associations. On entry to the
1330 -- loop, an expression has been scanned at the start of the current
1331 -- association unless initial token was OTHERS, in which case
1332 -- Expr_Node is set to Empty.
1335 -- Deal with others association first. This is a named association
1337 if No
(Expr_Node
) then
1338 if No
(Assoc_List
) then
1339 Assoc_List
:= New_List
;
1342 Append
(P_Record_Or_Array_Component_Association
, Assoc_List
);
1344 -- Improper use of WITH
1346 elsif Token
= Tok_With
then
1347 Error_Msg_SC
("WITH must be preceded by single expression in " &
1348 "extension aggregate");
1351 -- A range attribute can only appear as part of a discrete choice
1354 elsif Nkind
(Expr_Node
) = N_Attribute_Reference
1355 and then Attribute_Name
(Expr_Node
) = Name_Range
1356 and then Token
/= Tok_Arrow
1357 and then Token
/= Tok_Vertical_Bar
1359 Bad_Range_Attribute
(Sloc
(Expr_Node
));
1362 -- Assume positional case if comma, right paren, or literal or
1363 -- identifier or OTHERS follows (the latter cases are missing
1364 -- comma cases). Also assume positional if a semicolon follows,
1365 -- which can happen if there are missing parens
1367 elsif Token
= Tok_Comma
1368 or else Token
= Tok_Right_Paren
1369 or else Token
= Tok_Others
1370 or else Token
in Token_Class_Lit_Or_Name
1371 or else Token
= Tok_Semicolon
1373 if Present
(Assoc_List
) then
1375 ("""='>"" expected (positional association cannot follow " &
1376 "named association)");
1379 if No
(Expr_List
) then
1380 Expr_List
:= New_List
;
1383 Append
(Expr_Node
, Expr_List
);
1385 -- Anything else is assumed to be a named association
1388 Restore_Scan_State
(Scan_State
); -- to start of expression
1390 if No
(Assoc_List
) then
1391 Assoc_List
:= New_List
;
1394 Append
(P_Record_Or_Array_Component_Association
, Assoc_List
);
1397 exit when not Comma_Present
;
1399 -- If we are at an expression terminator, something is seriously
1400 -- wrong, so let's get out now, before we start eating up stuff
1401 -- that doesn't belong to us!
1403 if Token
in Token_Class_Eterm
then
1404 Error_Msg_AP
("expecting expression or component association");
1408 -- Otherwise initiate for reentry to top of loop by scanning an
1409 -- initial expression, unless the first token is OTHERS.
1411 if Token
= Tok_Others
then
1414 Save_Scan_State
(Scan_State
); -- at start of expression
1415 Expr_Node
:= P_Expression_Or_Range_Attribute
;
1420 -- All component associations (positional and named) have been scanned
1423 Set_Expressions
(Aggregate_Node
, Expr_List
);
1424 Set_Component_Associations
(Aggregate_Node
, Assoc_List
);
1425 return Aggregate_Node
;
1426 end P_Aggregate_Or_Paren_Expr
;
1428 ------------------------------------------------
1429 -- 4.3 Record or Array Component Association --
1430 ------------------------------------------------
1432 -- RECORD_COMPONENT_ASSOCIATION ::=
1433 -- [COMPONENT_CHOICE_LIST =>] EXPRESSION
1434 -- | COMPONENT_CHOICE_LIST => <>
1436 -- COMPONENT_CHOICE_LIST =>
1437 -- component_SELECTOR_NAME {| component_SELECTOR_NAME}
1440 -- ARRAY_COMPONENT_ASSOCIATION ::=
1441 -- DISCRETE_CHOICE_LIST => EXPRESSION
1442 -- | DISCRETE_CHOICE_LIST => <>
1444 -- Note: this routine only handles the named cases, including others.
1445 -- Cases where the component choice list is not present have already
1446 -- been handled directly.
1448 -- Error recovery: can raise Error_Resync
1450 -- Note: RECORD_COMPONENT_ASSOCIATION and ARRAY_COMPONENT_ASSOCIATION
1451 -- rules have been extended to give support to Ada 2005 limited
1452 -- aggregates (AI-287)
1454 function P_Record_Or_Array_Component_Association
return Node_Id
is
1455 Assoc_Node
: Node_Id
;
1458 Assoc_Node
:= New_Node
(N_Component_Association
, Token_Ptr
);
1459 Set_Choices
(Assoc_Node
, P_Discrete_Choice_List
);
1460 Set_Sloc
(Assoc_Node
, Token_Ptr
);
1463 if Token
= Tok_Box
then
1465 -- Ada 2005(AI-287): The box notation is used to indicate the
1466 -- default initialization of aggregate components
1468 if Ada_Version
< Ada_05
then
1470 ("component association with '<'> is an Ada 2005 extension");
1471 Error_Msg_SP
("\unit must be compiled with -gnat05 switch");
1474 Set_Box_Present
(Assoc_Node
);
1477 Set_Expression
(Assoc_Node
, P_Expression
);
1481 end P_Record_Or_Array_Component_Association
;
1483 -----------------------------
1484 -- 4.3.1 Record Aggregate --
1485 -----------------------------
1487 -- Case of enumeration aggregate is parsed by P_Aggregate (4.3)
1488 -- All other cases are parsed by P_Aggregate_Or_Paren_Expr (4.3)
1490 ----------------------------------------------
1491 -- 4.3.1 Record Component Association List --
1492 ----------------------------------------------
1494 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3)
1496 ----------------------------------
1497 -- 4.3.1 Component Choice List --
1498 ----------------------------------
1500 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3)
1502 --------------------------------
1503 -- 4.3.1 Extension Aggregate --
1504 --------------------------------
1506 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3)
1508 --------------------------
1509 -- 4.3.1 Ancestor Part --
1510 --------------------------
1512 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3)
1514 ----------------------------
1515 -- 4.3.1 Array Aggregate --
1516 ----------------------------
1518 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3)
1520 ---------------------------------------
1521 -- 4.3.1 Positional Array Aggregate --
1522 ---------------------------------------
1524 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3)
1526 ----------------------------------
1527 -- 4.3.1 Named Array Aggregate --
1528 ----------------------------------
1530 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3)
1532 ----------------------------------------
1533 -- 4.3.1 Array Component Association --
1534 ----------------------------------------
1536 -- Parsed by P_Aggregate_Or_Paren_Expr (4.3)
1538 ---------------------
1539 -- 4.4 Expression --
1540 ---------------------
1543 -- RELATION {and RELATION} | RELATION {and then RELATION}
1544 -- | RELATION {or RELATION} | RELATION {or else RELATION}
1545 -- | RELATION {xor RELATION}
1547 -- On return, Expr_Form indicates the categorization of the expression
1548 -- EF_Range_Attr is not a possible value (if a range attribute is found,
1549 -- an error message is given, and Error is returned).
1551 -- Error recovery: cannot raise Error_Resync
1553 function P_Expression
return Node_Id
is
1554 Logical_Op
: Node_Kind
;
1555 Prev_Logical_Op
: Node_Kind
;
1556 Op_Location
: Source_Ptr
;
1561 Node1
:= P_Relation
;
1563 if Token
in Token_Class_Logop
then
1564 Prev_Logical_Op
:= N_Empty
;
1567 Op_Location
:= Token_Ptr
;
1568 Logical_Op
:= P_Logical_Operator
;
1570 if Prev_Logical_Op
/= N_Empty
and then
1571 Logical_Op
/= Prev_Logical_Op
1574 ("mixed logical operators in expression", Op_Location
);
1575 Prev_Logical_Op
:= N_Empty
;
1577 Prev_Logical_Op
:= Logical_Op
;
1581 Node1
:= New_Node
(Logical_Op
, Op_Location
);
1582 Set_Left_Opnd
(Node1
, Node2
);
1583 Set_Right_Opnd
(Node1
, P_Relation
);
1584 Set_Op_Name
(Node1
);
1585 exit when Token
not in Token_Class_Logop
;
1588 Expr_Form
:= EF_Non_Simple
;
1591 if Token
= Tok_Apostrophe
then
1592 Bad_Range_Attribute
(Token_Ptr
);
1599 -- This function is identical to the normal P_Expression, except that it
1600 -- checks that the expression scan did not stop on a right paren. It is
1601 -- called in all contexts where a right parenthesis cannot legitimately
1602 -- follow an expression.
1604 -- Error recovery: can not raise Error_Resync
1606 function P_Expression_No_Right_Paren
return Node_Id
is
1607 Expr
: constant Node_Id
:= P_Expression
;
1609 Ignore
(Tok_Right_Paren
);
1611 end P_Expression_No_Right_Paren
;
1613 ----------------------------------------
1614 -- 4.4 Expression_Or_Range_Attribute --
1615 ----------------------------------------
1618 -- RELATION {and RELATION} | RELATION {and then RELATION}
1619 -- | RELATION {or RELATION} | RELATION {or else RELATION}
1620 -- | RELATION {xor RELATION}
1622 -- RANGE_ATTRIBUTE_REFERENCE ::= PREFIX ' RANGE_ATTRIBUTE_DESIGNATOR
1624 -- RANGE_ATTRIBUTE_DESIGNATOR ::= range [(static_EXPRESSION)]
1626 -- On return, Expr_Form indicates the categorization of the expression
1627 -- and EF_Range_Attr is one of the possibilities.
1629 -- Error recovery: cannot raise Error_Resync
1631 -- In the grammar, a RANGE attribute is simply a name, but its use is
1632 -- highly restricted, so in the parser, we do not regard it as a name.
1633 -- Instead, P_Name returns without scanning the 'RANGE part of the
1634 -- attribute, and P_Expression_Or_Range_Attribute handles the range
1635 -- attribute reference. In the normal case where a range attribute is
1636 -- not allowed, an error message is issued by P_Expression.
1638 function P_Expression_Or_Range_Attribute
return Node_Id
is
1639 Logical_Op
: Node_Kind
;
1640 Prev_Logical_Op
: Node_Kind
;
1641 Op_Location
: Source_Ptr
;
1644 Attr_Node
: Node_Id
;
1647 Node1
:= P_Relation
;
1649 if Token
= Tok_Apostrophe
then
1650 Attr_Node
:= P_Range_Attribute_Reference
(Node1
);
1651 Expr_Form
:= EF_Range_Attr
;
1654 elsif Token
in Token_Class_Logop
then
1655 Prev_Logical_Op
:= N_Empty
;
1658 Op_Location
:= Token_Ptr
;
1659 Logical_Op
:= P_Logical_Operator
;
1661 if Prev_Logical_Op
/= N_Empty
and then
1662 Logical_Op
/= Prev_Logical_Op
1665 ("mixed logical operators in expression", Op_Location
);
1666 Prev_Logical_Op
:= N_Empty
;
1668 Prev_Logical_Op
:= Logical_Op
;
1672 Node1
:= New_Node
(Logical_Op
, Op_Location
);
1673 Set_Left_Opnd
(Node1
, Node2
);
1674 Set_Right_Opnd
(Node1
, P_Relation
);
1675 Set_Op_Name
(Node1
);
1676 exit when Token
not in Token_Class_Logop
;
1679 Expr_Form
:= EF_Non_Simple
;
1682 if Token
= Tok_Apostrophe
then
1683 Bad_Range_Attribute
(Token_Ptr
);
1688 end P_Expression_Or_Range_Attribute
;
1695 -- SIMPLE_EXPRESSION [RELATIONAL_OPERATOR SIMPLE_EXPRESSION]
1696 -- | SIMPLE_EXPRESSION [not] in RANGE
1697 -- | SIMPLE_EXPRESSION [not] in SUBTYPE_MARK
1699 -- On return, Expr_Form indicates the categorization of the expression
1701 -- Note: if Token = Tok_Apostrophe on return, then Expr_Form is set to
1702 -- EF_Simple_Name and the following token is RANGE (range attribute case).
1704 -- Error recovery: cannot raise Error_Resync. If an error occurs within an
1705 -- expression, then tokens are scanned until either a non-expression token,
1706 -- a right paren (not matched by a left paren) or a comma, is encountered.
1708 function P_Relation
return Node_Id
is
1709 Node1
, Node2
: Node_Id
;
1713 Node1
:= P_Simple_Expression
;
1715 if Token
not in Token_Class_Relop
then
1719 -- Here we have a relational operator following. If so then scan it
1720 -- out. Note that the assignment symbol := is treated as a relational
1721 -- operator to improve the error recovery when it is misused for =.
1722 -- P_Relational_Operator also parses the IN and NOT IN operations.
1725 Node2
:= New_Node
(P_Relational_Operator
, Optok
);
1726 Set_Left_Opnd
(Node2
, Node1
);
1727 Set_Op_Name
(Node2
);
1729 -- Case of IN or NOT IN
1731 if Prev_Token
= Tok_In
then
1732 Set_Right_Opnd
(Node2
, P_Range_Or_Subtype_Mark
);
1734 -- Case of relational operator (= /= < <= > >=)
1737 Set_Right_Opnd
(Node2
, P_Simple_Expression
);
1740 Expr_Form
:= EF_Non_Simple
;
1742 if Token
in Token_Class_Relop
then
1743 Error_Msg_SC
("unexpected relational operator");
1750 -- If any error occurs, then scan to the next expression terminator symbol
1751 -- or comma or right paren at the outer (i.e. current) parentheses level.
1752 -- The flags are set to indicate a normal simple expression.
1755 when Error_Resync
=>
1757 Expr_Form
:= EF_Simple
;
1761 ----------------------------
1762 -- 4.4 Simple Expression --
1763 ----------------------------
1765 -- SIMPLE_EXPRESSION ::=
1766 -- [UNARY_ADDING_OPERATOR] TERM {BINARY_ADDING_OPERATOR TERM}
1768 -- On return, Expr_Form indicates the categorization of the expression
1770 -- Note: if Token = Tok_Apostrophe on return, then Expr_Form is set to
1771 -- EF_Simple_Name and the following token is RANGE (range attribute case).
1773 -- Error recovery: cannot raise Error_Resync. If an error occurs within an
1774 -- expression, then tokens are scanned until either a non-expression token,
1775 -- a right paren (not matched by a left paren) or a comma, is encountered.
1777 -- Note: P_Simple_Expression is called only internally by higher level
1778 -- expression routines. In cases in the grammar where a simple expression
1779 -- is required, the approach is to scan an expression, and then post an
1780 -- appropriate error message if the expression obtained is not simple. This
1781 -- gives better error recovery and treatment.
1783 function P_Simple_Expression
return Node_Id
is
1784 Scan_State
: Saved_Scan_State
;
1787 Tokptr
: Source_Ptr
;
1790 -- Check for cases starting with a name. There are two reasons for
1791 -- special casing. First speed things up by catching a common case
1792 -- without going through several routine layers. Second the caller must
1793 -- be informed via Expr_Form when the simple expression is a name.
1795 if Token
in Token_Class_Name
then
1798 -- Deal with apostrophe cases
1800 if Token
= Tok_Apostrophe
then
1801 Save_Scan_State
(Scan_State
); -- at apostrophe
1802 Scan
; -- past apostrophe
1804 -- If qualified expression, scan it out and fall through
1806 if Token
= Tok_Left_Paren
then
1807 Node1
:= P_Qualified_Expression
(Node1
);
1808 Expr_Form
:= EF_Simple
;
1810 -- If range attribute, then we return with Token pointing to the
1811 -- apostrophe. Note: avoid the normal error check on exit. We
1812 -- know that the expression really is complete in this case!
1814 else -- Token = Tok_Range then
1815 Restore_Scan_State
(Scan_State
); -- to apostrophe
1816 Expr_Form
:= EF_Simple_Name
;
1821 -- If an expression terminator follows, the previous processing
1822 -- completely scanned out the expression (a common case), and
1823 -- left Expr_Form set appropriately for returning to our caller.
1825 if Token
in Token_Class_Sterm
then
1828 -- If we do not have an expression terminator, then complete the
1829 -- scan of a simple expression. This code duplicates the code
1830 -- found in P_Term and P_Factor.
1833 if Token
= Tok_Double_Asterisk
then
1835 Style
.Check_Exponentiation_Operator
;
1838 Node2
:= New_Node
(N_Op_Expon
, Token_Ptr
);
1840 Set_Left_Opnd
(Node2
, Node1
);
1841 Set_Right_Opnd
(Node2
, P_Primary
);
1842 Set_Op_Name
(Node2
);
1847 exit when Token
not in Token_Class_Mulop
;
1848 Tokptr
:= Token_Ptr
;
1849 Node2
:= New_Node
(P_Multiplying_Operator
, Tokptr
);
1852 Style
.Check_Binary_Operator
;
1855 Scan
; -- past operator
1856 Set_Left_Opnd
(Node2
, Node1
);
1857 Set_Right_Opnd
(Node2
, P_Factor
);
1858 Set_Op_Name
(Node2
);
1863 exit when Token
not in Token_Class_Binary_Addop
;
1864 Tokptr
:= Token_Ptr
;
1865 Node2
:= New_Node
(P_Binary_Adding_Operator
, Tokptr
);
1868 Style
.Check_Binary_Operator
;
1871 Scan
; -- past operator
1872 Set_Left_Opnd
(Node2
, Node1
);
1873 Set_Right_Opnd
(Node2
, P_Term
);
1874 Set_Op_Name
(Node2
);
1878 Expr_Form
:= EF_Simple
;
1881 -- Cases where simple expression does not start with a name
1884 -- Scan initial sign and initial Term
1886 if Token
in Token_Class_Unary_Addop
then
1887 Tokptr
:= Token_Ptr
;
1888 Node1
:= New_Node
(P_Unary_Adding_Operator
, Tokptr
);
1891 Style
.Check_Unary_Plus_Or_Minus
;
1894 Scan
; -- past operator
1895 Set_Right_Opnd
(Node1
, P_Term
);
1896 Set_Op_Name
(Node1
);
1901 -- In the following, we special-case a sequence of concatenations of
1902 -- string literals, such as "aaa" & "bbb" & ... & "ccc", with nothing
1903 -- else mixed in. For such a sequence, we return a tree representing
1904 -- "" & "aaabbb...ccc" (a single concatenation). This is done only if
1905 -- the number of concatenations is large. If semantic analysis
1906 -- resolves the "&" to a predefined one, then this folding gives the
1907 -- right answer. Otherwise, semantic analysis will complain about a
1908 -- capacity-exceeded error. The purpose of this trick is to avoid
1909 -- creating a deeply nested tree, which would cause deep recursion
1910 -- during semantics, causing stack overflow. This way, we can handle
1911 -- enormous concatenations in the normal case of predefined "&". We
1912 -- first build up the normal tree, and then rewrite it if
1916 Num_Concats_Threshold
: constant Positive := 1000;
1917 -- Arbitrary threshold value to enable optimization
1919 First_Node
: constant Node_Id
:= Node1
;
1920 Is_Strlit_Concat
: Boolean;
1921 -- True iff we've parsed a sequence of concatenations of string
1922 -- literals, with nothing else mixed in.
1924 Num_Concats
: Natural;
1925 -- Number of "&" operators if Is_Strlit_Concat is True
1929 Nkind
(Node1
) = N_String_Literal
1930 and then Token
= Tok_Ampersand
;
1933 -- Scan out sequence of terms separated by binary adding operators
1936 exit when Token
not in Token_Class_Binary_Addop
;
1937 Tokptr
:= Token_Ptr
;
1938 Node2
:= New_Node
(P_Binary_Adding_Operator
, Tokptr
);
1939 Scan
; -- past operator
1940 Set_Left_Opnd
(Node2
, Node1
);
1942 Set_Right_Opnd
(Node2
, Node1
);
1943 Set_Op_Name
(Node2
);
1945 -- Check if we're still concatenating string literals
1949 and then Nkind
(Node2
) = N_Op_Concat
1950 and then Nkind
(Node1
) = N_String_Literal
;
1952 if Is_Strlit_Concat
then
1953 Num_Concats
:= Num_Concats
+ 1;
1959 -- If we have an enormous series of concatenations of string
1960 -- literals, rewrite as explained above. The Is_Folded_In_Parser
1961 -- flag tells semantic analysis that if the "&" is not predefined,
1962 -- the folded value is wrong.
1965 and then Num_Concats
>= Num_Concats_Threshold
1968 Empty_String_Val
: String_Id
;
1971 Strlit_Concat_Val
: String_Id
;
1972 -- Contains the folded value (which will be correct if the
1973 -- "&" operators are the predefined ones).
1976 -- For walking up the tree
1979 -- Folded node to replace Node1
1981 Loc
: constant Source_Ptr
:= Sloc
(First_Node
);
1984 -- Walk up the tree starting at the leftmost string literal
1985 -- (First_Node), building up the Strlit_Concat_Val as we
1986 -- go. Note that we do not use recursion here -- the whole
1987 -- point is to avoid recursively walking that enormous tree.
1990 Store_String_Chars
(Strval
(First_Node
));
1992 Cur_Node
:= Parent
(First_Node
);
1993 while Present
(Cur_Node
) loop
1994 pragma Assert
(Nkind
(Cur_Node
) = N_Op_Concat
and then
1995 Nkind
(Right_Opnd
(Cur_Node
)) = N_String_Literal
);
1997 Store_String_Chars
(Strval
(Right_Opnd
(Cur_Node
)));
1998 Cur_Node
:= Parent
(Cur_Node
);
2001 Strlit_Concat_Val
:= End_String
;
2003 -- Create new folded node, and rewrite result with a concat-
2004 -- enation of an empty string literal and the folded node.
2007 Empty_String_Val
:= End_String
;
2009 Make_Op_Concat
(Loc
,
2010 Make_String_Literal
(Loc
, Empty_String_Val
),
2011 Make_String_Literal
(Loc
, Strlit_Concat_Val
,
2012 Is_Folded_In_Parser
=> True));
2013 Rewrite
(Node1
, New_Node
);
2018 -- All done, we clearly do not have name or numeric literal so this
2019 -- is a case of a simple expression which is some other possibility.
2021 Expr_Form
:= EF_Simple
;
2024 -- Come here at end of simple expression, where we do a couple of
2025 -- special checks to improve error recovery.
2027 -- Special test to improve error recovery. If the current token
2028 -- is a period, then someone is trying to do selection on something
2029 -- that is not a name, e.g. a qualified expression.
2031 if Token
= Tok_Dot
then
2032 Error_Msg_SC
("prefix for selection is not a name");
2036 -- Special test to improve error recovery: If the current token is
2037 -- not the first token on a line (as determined by checking the
2038 -- previous token position with the start of the current line),
2039 -- then we insist that we have an appropriate terminating token.
2040 -- Consider the following two examples:
2042 -- 1) if A nad B then ...
2047 -- In the first example, we would like to issue a binary operator
2048 -- expected message and resynchronize to the then. In the second
2049 -- example, we do not want to issue a binary operator message, so
2050 -- that instead we will get the missing semicolon message. This
2051 -- distinction is of course a heuristic which does not always work,
2052 -- but in practice it is quite effective.
2054 -- Note: the one case in which we do not go through this circuit is
2055 -- when we have scanned a range attribute and want to return with
2056 -- Token pointing to the apostrophe. The apostrophe is not normally
2057 -- an expression terminator, and is not in Token_Class_Sterm, but
2058 -- in this special case we know that the expression is complete.
2060 if not Token_Is_At_Start_Of_Line
2061 and then Token
not in Token_Class_Sterm
2063 Error_Msg_AP
("binary operator expected");
2069 -- If any error occurs, then scan to next expression terminator symbol
2070 -- or comma, right paren or vertical bar at the outer (i.e. current) paren
2071 -- level. Expr_Form is set to indicate a normal simple expression.
2074 when Error_Resync
=>
2076 Expr_Form
:= EF_Simple
;
2079 end P_Simple_Expression
;
2081 -----------------------------------------------
2082 -- 4.4 Simple Expression or Range Attribute --
2083 -----------------------------------------------
2085 -- SIMPLE_EXPRESSION ::=
2086 -- [UNARY_ADDING_OPERATOR] TERM {BINARY_ADDING_OPERATOR TERM}
2088 -- RANGE_ATTRIBUTE_REFERENCE ::= PREFIX ' RANGE_ATTRIBUTE_DESIGNATOR
2090 -- RANGE_ATTRIBUTE_DESIGNATOR ::= range [(static_EXPRESSION)]
2092 -- Error recovery: cannot raise Error_Resync
2094 function P_Simple_Expression_Or_Range_Attribute
return Node_Id
is
2096 Attr_Node
: Node_Id
;
2099 -- We don't just want to roar ahead and call P_Simple_Expression
2100 -- here, since we want to handle the case of a parenthesized range
2101 -- attribute cleanly.
2103 if Token
= Tok_Left_Paren
then
2105 Lptr
: constant Source_Ptr
:= Token_Ptr
;
2106 Scan_State
: Saved_Scan_State
;
2109 Save_Scan_State
(Scan_State
);
2110 Scan
; -- past left paren
2111 Sexpr
:= P_Simple_Expression
;
2113 if Token
= Tok_Apostrophe
then
2114 Attr_Node
:= P_Range_Attribute_Reference
(Sexpr
);
2115 Expr_Form
:= EF_Range_Attr
;
2117 if Token
= Tok_Right_Paren
then
2118 Scan
; -- scan past right paren if present
2121 Error_Msg
("parentheses not allowed for range attribute", Lptr
);
2126 Restore_Scan_State
(Scan_State
);
2130 -- Here after dealing with parenthesized range attribute
2132 Sexpr
:= P_Simple_Expression
;
2134 if Token
= Tok_Apostrophe
then
2135 Attr_Node
:= P_Range_Attribute_Reference
(Sexpr
);
2136 Expr_Form
:= EF_Range_Attr
;
2142 end P_Simple_Expression_Or_Range_Attribute
;
2148 -- TERM ::= FACTOR {MULTIPLYING_OPERATOR FACTOR}
2150 -- Error recovery: can raise Error_Resync
2152 function P_Term
return Node_Id
is
2153 Node1
, Node2
: Node_Id
;
2154 Tokptr
: Source_Ptr
;
2160 exit when Token
not in Token_Class_Mulop
;
2161 Tokptr
:= Token_Ptr
;
2162 Node2
:= New_Node
(P_Multiplying_Operator
, Tokptr
);
2163 Scan
; -- past operator
2164 Set_Left_Opnd
(Node2
, Node1
);
2165 Set_Right_Opnd
(Node2
, P_Factor
);
2166 Set_Op_Name
(Node2
);
2177 -- FACTOR ::= PRIMARY [** PRIMARY] | abs PRIMARY | not PRIMARY
2179 -- Error recovery: can raise Error_Resync
2181 function P_Factor
return Node_Id
is
2186 if Token
= Tok_Abs
then
2187 Node1
:= New_Node
(N_Op_Abs
, Token_Ptr
);
2190 Style
.Check_Abs_Not
;
2194 Set_Right_Opnd
(Node1
, P_Primary
);
2195 Set_Op_Name
(Node1
);
2198 elsif Token
= Tok_Not
then
2199 Node1
:= New_Node
(N_Op_Not
, Token_Ptr
);
2202 Style
.Check_Abs_Not
;
2206 Set_Right_Opnd
(Node1
, P_Primary
);
2207 Set_Op_Name
(Node1
);
2213 if Token
= Tok_Double_Asterisk
then
2214 Node2
:= New_Node
(N_Op_Expon
, Token_Ptr
);
2216 Set_Left_Opnd
(Node2
, Node1
);
2217 Set_Right_Opnd
(Node2
, P_Primary
);
2218 Set_Op_Name
(Node2
);
2231 -- NUMERIC_LITERAL | null
2232 -- | STRING_LITERAL | AGGREGATE
2233 -- | NAME | QUALIFIED_EXPRESSION
2234 -- | ALLOCATOR | (EXPRESSION)
2236 -- Error recovery: can raise Error_Resync
2238 function P_Primary
return Node_Id
is
2239 Scan_State
: Saved_Scan_State
;
2243 -- The loop runs more than once only if misplaced pragmas are found
2248 -- Name token can start a name, call or qualified expression, all
2249 -- of which are acceptable possibilities for primary. Note also
2250 -- that string literal is included in name (as operator symbol)
2251 -- and type conversion is included in name (as indexed component).
2253 when Tok_Char_Literal | Tok_Operator_Symbol | Tok_Identifier
=>
2256 -- All done unless apostrophe follows
2258 if Token
/= Tok_Apostrophe
then
2261 -- Apostrophe following means that we have either just parsed
2262 -- the subtype mark of a qualified expression, or the prefix
2263 -- or a range attribute.
2265 else -- Token = Tok_Apostrophe
2266 Save_Scan_State
(Scan_State
); -- at apostrophe
2267 Scan
; -- past apostrophe
2269 -- If range attribute, then this is always an error, since
2270 -- the only legitimate case (where the scanned expression is
2271 -- a qualified simple name) is handled at the level of the
2272 -- Simple_Expression processing. This case corresponds to a
2273 -- usage such as 3 + A'Range, which is always illegal.
2275 if Token
= Tok_Range
then
2276 Restore_Scan_State
(Scan_State
); -- to apostrophe
2277 Bad_Range_Attribute
(Token_Ptr
);
2280 -- If left paren, then we have a qualified expression.
2281 -- Note that P_Name guarantees that in this case, where
2282 -- Token = Tok_Apostrophe on return, the only two possible
2283 -- tokens following the apostrophe are left paren and
2284 -- RANGE, so we know we have a left paren here.
2286 else -- Token = Tok_Left_Paren
2287 return P_Qualified_Expression
(Node1
);
2292 -- Numeric or string literal
2294 when Tok_Integer_Literal |
2296 Tok_String_Literal
=>
2298 Node1
:= Token_Node
;
2299 Scan
; -- past number
2302 -- Left paren, starts aggregate or parenthesized expression
2304 when Tok_Left_Paren
=>
2306 Expr
: constant Node_Id
:= P_Aggregate_Or_Paren_Expr
;
2309 if Nkind
(Expr
) = N_Attribute_Reference
2310 and then Attribute_Name
(Expr
) = Name_Range
2312 Bad_Range_Attribute
(Sloc
(Expr
));
2327 return New_Node
(N_Null
, Prev_Token_Ptr
);
2329 -- Pragma, not allowed here, so just skip past it
2332 P_Pragmas_Misplaced
;
2334 -- Anything else is illegal as the first token of a primary, but
2335 -- we test for a reserved identifier so that it is treated nicely
2338 if Is_Reserved_Identifier
then
2339 return P_Identifier
;
2341 elsif Prev_Token
= Tok_Comma
then
2342 Error_Msg_SP
("|extra "","" ignored");
2346 Error_Msg_AP
("missing operand");
2354 ---------------------------
2355 -- 4.5 Logical Operator --
2356 ---------------------------
2358 -- LOGICAL_OPERATOR ::= and | or | xor
2360 -- Note: AND THEN and OR ELSE are also treated as logical operators
2361 -- by the parser (even though they are not operators semantically)
2363 -- The value returned is the appropriate Node_Kind code for the operator
2364 -- On return, Token points to the token following the scanned operator.
2366 -- The caller has checked that the first token is a legitimate logical
2367 -- operator token (i.e. is either XOR, AND, OR).
2369 -- Error recovery: cannot raise Error_Resync
2371 function P_Logical_Operator
return Node_Kind
is
2373 if Token
= Tok_And
then
2375 Style
.Check_Binary_Operator
;
2380 if Token
= Tok_Then
then
2387 elsif Token
= Tok_Or
then
2389 Style
.Check_Binary_Operator
;
2394 if Token
= Tok_Else
then
2401 else -- Token = Tok_Xor
2403 Style
.Check_Binary_Operator
;
2409 end P_Logical_Operator
;
2411 ------------------------------
2412 -- 4.5 Relational Operator --
2413 ------------------------------
2415 -- RELATIONAL_OPERATOR ::= = | /= | < | <= | > | >=
2417 -- The value returned is the appropriate Node_Kind code for the operator.
2418 -- On return, Token points to the operator token, NOT past it.
2420 -- The caller has checked that the first token is a legitimate relational
2421 -- operator token (i.e. is one of the operator tokens listed above).
2423 -- Error recovery: cannot raise Error_Resync
2425 function P_Relational_Operator
return Node_Kind
is
2426 Op_Kind
: Node_Kind
;
2427 Relop_Node
: constant array (Token_Class_Relop
) of Node_Kind
:=
2428 (Tok_Less
=> N_Op_Lt
,
2429 Tok_Equal
=> N_Op_Eq
,
2430 Tok_Greater
=> N_Op_Gt
,
2431 Tok_Not_Equal
=> N_Op_Ne
,
2432 Tok_Greater_Equal
=> N_Op_Ge
,
2433 Tok_Less_Equal
=> N_Op_Le
,
2435 Tok_Not
=> N_Not_In
,
2436 Tok_Box
=> N_Op_Ne
);
2439 if Token
= Tok_Box
then
2440 Error_Msg_SC
("|""'<'>"" should be ""/=""");
2443 Op_Kind
:= Relop_Node
(Token
);
2446 Style
.Check_Binary_Operator
;
2449 Scan
; -- past operator token
2451 if Prev_Token
= Tok_Not
then
2456 end P_Relational_Operator
;
2458 ---------------------------------
2459 -- 4.5 Binary Adding Operator --
2460 ---------------------------------
2462 -- BINARY_ADDING_OPERATOR ::= + | - | &
2464 -- The value returned is the appropriate Node_Kind code for the operator.
2465 -- On return, Token points to the operator token (NOT past it).
2467 -- The caller has checked that the first token is a legitimate adding
2468 -- operator token (i.e. is one of the operator tokens listed above).
2470 -- Error recovery: cannot raise Error_Resync
2472 function P_Binary_Adding_Operator
return Node_Kind
is
2473 Addop_Node
: constant array (Token_Class_Binary_Addop
) of Node_Kind
:=
2474 (Tok_Ampersand
=> N_Op_Concat
,
2475 Tok_Minus
=> N_Op_Subtract
,
2476 Tok_Plus
=> N_Op_Add
);
2478 return Addop_Node
(Token
);
2479 end P_Binary_Adding_Operator
;
2481 --------------------------------
2482 -- 4.5 Unary Adding Operator --
2483 --------------------------------
2485 -- UNARY_ADDING_OPERATOR ::= + | -
2487 -- The value returned is the appropriate Node_Kind code for the operator.
2488 -- On return, Token points to the operator token (NOT past it).
2490 -- The caller has checked that the first token is a legitimate adding
2491 -- operator token (i.e. is one of the operator tokens listed above).
2493 -- Error recovery: cannot raise Error_Resync
2495 function P_Unary_Adding_Operator
return Node_Kind
is
2496 Addop_Node
: constant array (Token_Class_Unary_Addop
) of Node_Kind
:=
2497 (Tok_Minus
=> N_Op_Minus
,
2498 Tok_Plus
=> N_Op_Plus
);
2500 return Addop_Node
(Token
);
2501 end P_Unary_Adding_Operator
;
2503 -------------------------------
2504 -- 4.5 Multiplying Operator --
2505 -------------------------------
2507 -- MULTIPLYING_OPERATOR ::= * | / | mod | rem
2509 -- The value returned is the appropriate Node_Kind code for the operator.
2510 -- On return, Token points to the operator token (NOT past it).
2512 -- The caller has checked that the first token is a legitimate multiplying
2513 -- operator token (i.e. is one of the operator tokens listed above).
2515 -- Error recovery: cannot raise Error_Resync
2517 function P_Multiplying_Operator
return Node_Kind
is
2518 Mulop_Node
: constant array (Token_Class_Mulop
) of Node_Kind
:=
2519 (Tok_Asterisk
=> N_Op_Multiply
,
2520 Tok_Mod
=> N_Op_Mod
,
2521 Tok_Rem
=> N_Op_Rem
,
2522 Tok_Slash
=> N_Op_Divide
);
2524 return Mulop_Node
(Token
);
2525 end P_Multiplying_Operator
;
2527 --------------------------------------
2528 -- 4.5 Highest Precedence Operator --
2529 --------------------------------------
2531 -- Parsed by P_Factor (4.4)
2533 -- Note: this rule is not in fact used by the grammar at any point!
2535 --------------------------
2536 -- 4.6 Type Conversion --
2537 --------------------------
2539 -- Parsed by P_Primary as a Name (4.1)
2541 -------------------------------
2542 -- 4.7 Qualified Expression --
2543 -------------------------------
2545 -- QUALIFIED_EXPRESSION ::=
2546 -- SUBTYPE_MARK ' (EXPRESSION) | SUBTYPE_MARK ' AGGREGATE
2548 -- The caller has scanned the name which is the Subtype_Mark parameter
2549 -- and scanned past the single quote following the subtype mark. The
2550 -- caller has not checked that this name is in fact appropriate for
2551 -- a subtype mark name (i.e. it is a selected component or identifier).
2553 -- Error_Recovery: cannot raise Error_Resync
2555 function P_Qualified_Expression
(Subtype_Mark
: Node_Id
) return Node_Id
is
2556 Qual_Node
: Node_Id
;
2558 Qual_Node
:= New_Node
(N_Qualified_Expression
, Prev_Token_Ptr
);
2559 Set_Subtype_Mark
(Qual_Node
, Check_Subtype_Mark
(Subtype_Mark
));
2560 Set_Expression
(Qual_Node
, P_Aggregate_Or_Paren_Expr
);
2562 end P_Qualified_Expression
;
2564 --------------------
2566 --------------------
2569 -- new [NULL_EXCLUSION] SUBTYPE_INDICATION | new QUALIFIED_EXPRESSION
2571 -- The caller has checked that the initial token is NEW
2573 -- Error recovery: can raise Error_Resync
2575 function P_Allocator
return Node_Id
is
2576 Alloc_Node
: Node_Id
;
2577 Type_Node
: Node_Id
;
2578 Null_Exclusion_Present
: Boolean;
2581 Alloc_Node
:= New_Node
(N_Allocator
, Token_Ptr
);
2584 -- Scan Null_Exclusion if present (Ada 2005 (AI-231))
2586 Null_Exclusion_Present
:= P_Null_Exclusion
;
2587 Set_Null_Exclusion_Present
(Alloc_Node
, Null_Exclusion_Present
);
2588 Type_Node
:= P_Subtype_Mark_Resync
;
2590 if Token
= Tok_Apostrophe
then
2591 Scan
; -- past apostrophe
2592 Set_Expression
(Alloc_Node
, P_Qualified_Expression
(Type_Node
));
2596 P_Subtype_Indication
(Type_Node
, Null_Exclusion_Present
));