ada: Rename Is_Constr_Subt_For_UN_Aliased flag
[official-gcc.git] / gcc / ada / par-ch13.adb
blob85adad2d7820e36a48b058e81117952e3c762076
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- P A R . C H 1 3 --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Rident; use Rident;
27 with Restrict; use Restrict;
28 pragma Style_Checks (All_Checks);
29 -- Turn off subprogram body ordering check. Subprograms are in order
30 -- by RM section rather than alphabetical
32 separate (Par)
33 package body Ch13 is
35 -- Local functions, used only in this chapter
37 function P_Component_Clause return Node_Id;
38 function P_Mod_Clause return Node_Id;
40 -----------------------------------
41 -- Aspect_Specifications_Present --
42 -----------------------------------
44 function Aspect_Specifications_Present
45 (Strict : Boolean := Ada_Version < Ada_2012) return Boolean
47 Scan_State : Saved_Scan_State;
48 Result : Boolean;
50 function With_Present return Boolean;
51 -- Returns True if WITH is present, indicating presence of aspect
52 -- specifications. Also allows incorrect use of WHEN in place of WITH.
54 ------------------
55 -- With_Present --
56 ------------------
58 function With_Present return Boolean is
59 begin
60 if Token = Tok_With then
61 return True;
63 -- Check for WHEN used in place of WITH
65 elsif Token = Tok_When then
66 declare
67 Scan_State : Saved_Scan_State;
69 begin
70 Save_Scan_State (Scan_State);
71 Scan; -- past WHEN
73 if Token = Tok_Identifier
74 and then Is_Aspect_Id (Token_Name)
75 then
76 Error_Msg_SC ("WHEN should be WITH");
77 Restore_Scan_State (Scan_State);
78 return True;
80 else
81 Restore_Scan_State (Scan_State);
82 return False;
83 end if;
84 end;
86 else
87 return False;
88 end if;
89 end With_Present;
91 -- Start of processing for Aspect_Specifications_Present
93 begin
94 -- Definitely must have WITH to consider aspect specs to be present
96 -- Note that this means that if we have a semicolon, we immediately
97 -- return False. There is a case in which this is not optimal, namely
98 -- something like
100 -- type R is new Integer;
101 -- with bla bla;
103 -- where the semicolon is redundant, but scanning forward for it would
104 -- be too expensive. Instead we pick up the aspect specifications later
105 -- as a bogus declaration, and diagnose the semicolon at that point.
107 if not With_Present then
108 return False;
109 end if;
111 -- Have a WITH or some token that we accept as a legitimate bad attempt
112 -- at writing WITH. See if it looks like an aspect specification
114 Save_Scan_State (Scan_State);
115 Scan; -- past WITH (or WHEN or other bad keyword)
117 -- If no identifier, then consider that we definitely do not have an
118 -- aspect specification.
120 if Token /= Tok_Identifier then
121 Result := False;
123 -- This is where we pay attention to the Strict mode. Normally when
124 -- we are in Ada 2012 mode, Strict is False, and we consider that we
125 -- have an aspect specification if the identifier is an aspect name
126 -- or a likely misspelling of one (even if not followed by =>) or
127 -- the identifier is not an aspect name but is followed by =>, by
128 -- a comma, or by a semicolon. The last two cases correspond to
129 -- (misspelled) Boolean aspects with a defaulted value of True.
130 -- P_Aspect_Specifications will generate messages if the aspect
131 -- specification is ill-formed.
133 elsif not Strict then
134 if Is_Aspect_Id (Token_Name)
135 or else Aspect_Spell_Check (Token_Name)
136 then
137 Result := True;
138 else
139 Scan; -- past identifier
140 Result := Token in
141 Tok_Arrow | Tok_Comma | Tok_Is | Tok_Semicolon | Tok_Right_Paren;
142 end if;
144 -- If earlier than Ada 2012, check for valid aspect identifier (possibly
145 -- completed with 'CLASS) followed by an arrow, and consider that this
146 -- is still an aspect specification so we give an appropriate message.
148 else
149 if not Is_Aspect_Id (Token_Name) then
150 Result := False;
152 else
153 Scan; -- past aspect name
155 Result := False;
157 if Token = Tok_Arrow then
158 Result := True;
160 -- The identifier may be the name of a boolean aspect with a
161 -- defaulted True value. Further checks when analyzing aspect
162 -- specification, which may include further aspects.
164 elsif Token in Tok_Comma | Tok_Semicolon then
165 Result := True;
167 elsif Token = Tok_Apostrophe then
168 Scan; -- past apostrophe
170 if Token = Tok_Identifier
171 and then Token_Name = Name_Class
172 then
173 Scan; -- past CLASS
175 if Token = Tok_Arrow then
176 Result := True;
177 end if;
178 end if;
179 end if;
181 if Result then
182 Restore_Scan_State (Scan_State);
183 Error_Msg_Ada_2012_Feature ("|aspect specification", Token_Ptr);
184 return True;
185 end if;
186 end if;
187 end if;
189 Restore_Scan_State (Scan_State);
190 return Result;
191 end Aspect_Specifications_Present;
193 -------------------------------
194 -- Get_Aspect_Specifications --
195 -------------------------------
197 function Get_Aspect_Specifications
198 (Semicolon : Boolean := True) return List_Id
200 A_Id : Aspect_Id;
201 Aspect : Node_Id;
202 Aspects : List_Id;
203 OK : Boolean;
205 Opt : Boolean;
206 -- True if current aspect takes an optional argument
208 begin
209 Aspects := Empty_List;
211 -- Check if aspect specification present
213 if not Aspect_Specifications_Present then
214 if Semicolon then
215 TF_Semicolon;
216 end if;
218 return Aspects;
219 end if;
221 Scan; -- past WITH (or possible WHEN after error)
222 Aspects := Empty_List;
224 -- Loop to scan aspects
226 loop
227 OK := True;
229 -- The aspect mark is not an identifier
231 if Token /= Tok_Identifier then
232 Error_Msg_SC ("aspect identifier expected");
234 -- Skip the whole aspect specification list
236 if Semicolon then
237 Resync_Past_Semicolon;
238 end if;
240 return Aspects;
241 end if;
243 A_Id := Get_Aspect_Id (Token_Name);
244 Aspect :=
245 Make_Aspect_Specification (Token_Ptr,
246 Identifier => Token_Node);
248 -- The aspect mark is not recognized
250 if A_Id = No_Aspect then
251 declare
252 Msg_Issued : Boolean := False;
253 begin
254 Check_Restriction (Msg_Issued, No_Unrecognized_Aspects, Aspect);
255 if not Msg_Issued then
256 Bad_Aspect (Token_Node, Token_Name, not Debug_Flag_2);
258 OK := False;
260 end if;
261 end;
263 Scan; -- past incorrect identifier
265 if Token = Tok_Apostrophe then
266 Scan; -- past apostrophe
267 Scan; -- past presumably CLASS
268 end if;
270 -- Attempt to parse the aspect definition by assuming it is an
271 -- expression.
273 if Token = Tok_Arrow then
274 Scan; -- past arrow
275 Set_Expression (Aspect, P_Expression);
277 -- If we have a correct terminator (comma or semicolon, or a
278 -- reasonable likely missing comma), then just proceed.
280 elsif Token = Tok_Comma or else
281 Token = Tok_Semicolon or else
282 Token = Tok_Identifier
283 then
284 null;
286 -- Otherwise the aspect contains a junk definition
288 else
289 if Semicolon then
290 Resync_Past_Semicolon;
291 end if;
293 return Aspects;
294 end if;
296 -- Aspect mark is OK
298 else
299 Scan; -- past identifier
300 Opt := Aspect_Argument (A_Id) = Optional_Expression
301 or else
302 Aspect_Argument (A_Id) = Optional_Name;
304 -- Check for 'Class present
306 if Token = Tok_Apostrophe then
307 if Class_Aspect_OK (A_Id) then
308 Scan; -- past apostrophe
310 if Token = Tok_Identifier
311 and then Token_Name = Name_Class
312 then
313 Scan; -- past CLASS
314 Set_Class_Present (Aspect);
315 else
316 Error_Msg_SC ("Class attribute expected here");
317 OK := False;
319 if Token = Tok_Identifier then
320 Scan; -- past identifier not CLASS
321 end if;
322 end if;
324 -- The aspect does not allow 'Class
326 else
327 Error_Msg_Node_1 := Identifier (Aspect);
328 Error_Msg_SC ("aspect& does not permit attribute here");
329 OK := False;
331 Scan; -- past apostrophe
332 Scan; -- past presumably CLASS
333 end if;
334 end if;
336 -- Check for a missing aspect definition. Aspects with optional
337 -- definitions are not considered.
339 if Token in Tok_Comma | Tok_Semicolon then
340 if not Opt then
341 Error_Msg_Node_1 := Identifier (Aspect);
342 Error_Msg_AP ("aspect& requires an aspect definition");
343 OK := False;
344 end if;
346 -- Here we do not have a comma or a semicolon, we are done if we
347 -- do not have an arrow and the aspect does not need an argument
349 elsif Opt and then Token /= Tok_Arrow then
350 null;
352 -- Here we have either an arrow, or an aspect that definitely
353 -- needs an aspect definition, and we will look for one even if
354 -- no arrow is preseant.
356 -- Otherwise we have an aspect definition
358 else
359 if Token = Tok_Arrow then
360 Scan; -- past arrow
361 else
362 T_Arrow;
363 OK := False;
364 end if;
366 -- Detect a common error where the non-null definition of
367 -- aspect Depends, Global, Refined_Depends, Refined_Global
368 -- or Refined_State lacks enclosing parentheses.
370 if Token not in Tok_Left_Paren | Tok_Null then
372 -- [Refined_]Depends
374 if A_Id = Aspect_Depends
375 or else
376 A_Id = Aspect_Refined_Depends
377 then
378 Error_Msg_SC -- CODEFIX
379 ("missing ""(""");
380 Resync_Past_Malformed_Aspect;
382 -- Return when the current aspect is the last in the list
383 -- of specifications and the list applies to a body.
385 if Token = Tok_Is then
386 return Aspects;
387 end if;
389 -- [Refined_]Global
391 elsif A_Id = Aspect_Global
392 or else
393 A_Id = Aspect_Refined_Global
394 then
395 declare
396 Scan_State : Saved_Scan_State;
398 begin
399 Save_Scan_State (Scan_State);
400 Scan; -- past item or mode_selector
402 -- Emit an error when the aspect has a mode_selector
403 -- as the moded_global_list must be parenthesized:
404 -- with Global => Output => Item
406 if Token = Tok_Arrow then
407 Restore_Scan_State (Scan_State);
408 Error_Msg_SC -- CODEFIX
409 ("missing ""(""");
410 Resync_Past_Malformed_Aspect;
412 -- Return when the current aspect is the last in
413 -- the list of specifications and the list applies
414 -- to a body.
416 if Token = Tok_Is then
417 return Aspects;
418 end if;
420 elsif Token = Tok_Comma then
421 Scan; -- past comma
423 -- An item followed by a comma does not need to
424 -- be parenthesized if the next token is a valid
425 -- aspect name:
426 -- with Global => Item,
427 -- Aspect => ...
429 if Token = Tok_Identifier
430 and then Is_Aspect_Id (Token_Name)
431 then
432 Restore_Scan_State (Scan_State);
434 -- Otherwise this is a list of items in which case
435 -- the list must be parenthesized.
437 else
438 Restore_Scan_State (Scan_State);
439 Error_Msg_SC -- CODEFIX
440 ("missing ""(""");
441 Resync_Past_Malformed_Aspect;
443 -- Return when the current aspect is the last
444 -- in the list of specifications and the list
445 -- applies to a body.
447 if Token = Tok_Is then
448 return Aspects;
449 end if;
450 end if;
452 -- The definition of [Refined_]Global does not need to
453 -- be parenthesized.
455 else
456 Restore_Scan_State (Scan_State);
457 end if;
458 end;
460 -- Refined_State
462 elsif A_Id = Aspect_Refined_State then
463 if Token = Tok_Identifier then
464 declare
465 Scan_State : Saved_Scan_State;
467 begin
468 Save_Scan_State (Scan_State);
469 Scan; -- past state
471 -- The refinement contains a constituent, the whole
472 -- argument of Refined_State must be parenthesized.
474 -- with Refined_State => State => Constit
476 if Token = Tok_Arrow then
477 Restore_Scan_State (Scan_State);
478 Error_Msg_SC -- CODEFIX
479 ("missing ""(""");
480 Resync_Past_Malformed_Aspect;
482 -- Return when the current aspect is the last
483 -- in the list of specifications and the list
484 -- applies to a body.
486 if Token = Tok_Is then
487 return Aspects;
488 end if;
490 -- The refinement lacks constituents. Do not flag
491 -- this case as the error would be misleading. The
492 -- diagnostic is left to the analysis.
494 -- with Refined_State => State
496 else
497 Restore_Scan_State (Scan_State);
498 end if;
499 end;
500 end if;
501 end if;
502 end if;
504 -- Note if inside Depends or Refined_Depends aspect
506 if A_Id = Aspect_Depends
507 or else A_Id = Aspect_Refined_Depends
508 then
509 Inside_Depends := True;
510 end if;
512 -- Note that we have seen an Import aspect specification.
513 -- This matters only while parsing a subprogram.
515 if A_Id = Aspect_Import then
516 SIS_Aspect_Import_Seen := True;
517 -- Should do it only for subprograms
518 end if;
520 -- Parse the aspect definition depending on the expected
521 -- argument kind.
523 if Aspect_Argument (A_Id) = Name
524 or else Aspect_Argument (A_Id) = Optional_Name
525 then
526 Set_Expression (Aspect, P_Name);
528 else
529 pragma Assert
530 (Aspect_Argument (A_Id) = Expression
531 or else
532 Aspect_Argument (A_Id) = Optional_Expression);
533 Set_Expression (Aspect, P_Expression);
534 end if;
536 -- Unconditionally reset flag for Inside_Depends
538 Inside_Depends := False;
539 end if;
541 -- Add the aspect to the resulting list only when it was properly
542 -- parsed.
544 if OK then
545 Append (Aspect, Aspects);
546 end if;
547 end if;
549 -- Merge here after good or bad aspect (we should be at a comma
550 -- or a semicolon, but there might be other possible errors).
552 -- The aspect specification list contains more than one aspect
554 if Token = Tok_Comma then
555 Scan; -- past comma
556 goto Continue;
558 -- Check for a missing comma between two aspects. Emit an error
559 -- and proceed to the next aspect.
561 elsif Token = Tok_Identifier
562 and then Is_Aspect_Id (Token_Name)
563 then
564 declare
565 Scan_State : Saved_Scan_State;
567 begin
568 Save_Scan_State (Scan_State);
569 Scan; -- past identifier
571 -- Attempt to detect ' or => following a potential aspect
572 -- mark.
574 if Token in Tok_Apostrophe | Tok_Arrow then
575 Restore_Scan_State (Scan_State);
576 Error_Msg_AP -- CODEFIX
577 ("|missing "",""");
578 goto Continue;
580 -- The construct following the current aspect is not an
581 -- aspect.
583 else
584 Restore_Scan_State (Scan_State);
585 end if;
586 end;
588 -- Check for a mistyped semicolon in place of a comma between two
589 -- aspects. Emit an error and proceed to the next aspect.
591 elsif Token = Tok_Semicolon then
592 declare
593 Scan_State : Saved_Scan_State;
595 begin
596 Save_Scan_State (Scan_State);
597 Scan; -- past semicolon
599 if Token = Tok_Identifier
600 and then Is_Aspect_Id (Token_Name)
601 then
602 Scan; -- past identifier
604 -- Attempt to detect ' or => following potential aspect mark
606 if Token in Tok_Apostrophe | Tok_Arrow then
607 Restore_Scan_State (Scan_State);
608 Error_Msg_SC -- CODEFIX
609 ("|"";"" should be "",""");
610 Scan; -- past semicolon
611 goto Continue;
612 end if;
613 end if;
615 -- Construct following the current aspect is not an aspect
617 Restore_Scan_State (Scan_State);
618 end;
619 end if;
621 -- Require semicolon if caller expects to scan this out
623 if Semicolon then
624 T_Semicolon;
625 end if;
627 exit;
629 <<Continue>>
630 null;
631 end loop;
633 return Aspects;
634 end Get_Aspect_Specifications;
636 --------------------------------------------
637 -- 13.1 Representation Clause (also I.7) --
638 --------------------------------------------
640 -- REPRESENTATION_CLAUSE ::=
641 -- ATTRIBUTE_DEFINITION_CLAUSE
642 -- | ENUMERATION_REPRESENTATION_CLAUSE
643 -- | RECORD_REPRESENTATION_CLAUSE
644 -- | AT_CLAUSE
646 -- ATTRIBUTE_DEFINITION_CLAUSE ::=
647 -- for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use EXPRESSION;
648 -- | for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use NAME;
650 -- Note: in Ada 83, the expression must be a simple expression
652 -- AT_CLAUSE ::= for DIRECT_NAME use at EXPRESSION;
654 -- Note: in Ada 83, the expression must be a simple expression
656 -- ENUMERATION_REPRESENTATION_CLAUSE ::=
657 -- for first_subtype_LOCAL_NAME use ENUMERATION_AGGREGATE;
659 -- ENUMERATION_AGGREGATE ::= ARRAY_AGGREGATE
661 -- RECORD_REPRESENTATION_CLAUSE ::=
662 -- for first_subtype_LOCAL_NAME use
663 -- record [MOD_CLAUSE]
664 -- {COMPONENT_CLAUSE}
665 -- end record;
667 -- Note: for now we allow only a direct name as the local name in the
668 -- above constructs. This probably needs changing later on ???
670 -- The caller has checked that the initial token is FOR
672 -- Error recovery: cannot raise Error_Resync, if an error occurs,
673 -- the scan is repositioned past the next semicolon.
675 function P_Representation_Clause return Node_Id is
676 For_Loc : Source_Ptr;
677 Name_Node : Node_Id;
678 Prefix_Node : Node_Id;
679 Attr_Name : Name_Id;
680 Identifier_Node : Node_Id;
681 Rep_Clause_Node : Node_Id;
682 Expr_Node : Node_Id;
683 Record_Items : List_Id;
685 begin
686 For_Loc := Token_Ptr;
687 Scan; -- past FOR
689 -- Note that the name in a representation clause is always a simple
690 -- name, even in the attribute case, see AI-300 which made this so.
692 Identifier_Node := P_Identifier (C_Use);
694 -- Check case of qualified name to give good error message
696 if Token = Tok_Dot then
697 Error_Msg_SC
698 ("representation clause requires simple name!");
700 loop
701 exit when Token /= Tok_Dot;
702 Scan; -- past dot
703 Discard_Junk_Node (P_Identifier);
704 end loop;
705 end if;
707 -- Attribute Definition Clause
709 if Token = Tok_Apostrophe then
711 -- Allow local names of the form a'b'.... This enables
712 -- us to parse class-wide streams attributes correctly.
714 Name_Node := Identifier_Node;
715 while Token = Tok_Apostrophe loop
717 Scan; -- past apostrophe
719 Identifier_Node := Token_Node;
720 Attr_Name := No_Name;
722 if Token = Tok_Identifier then
723 Attr_Name := Token_Name;
725 -- Note that the parser must complain in case of an internal
726 -- attribute name that comes from source since internal names
727 -- are meant to be used only by the compiler.
729 if not Is_Attribute_Name (Attr_Name)
730 and then (not Is_Internal_Attribute_Name (Attr_Name)
731 or else Comes_From_Source (Token_Node))
732 then
733 Signal_Bad_Attribute;
734 end if;
736 if Style_Check then
737 Style.Check_Attribute_Name (False);
738 end if;
740 -- Here for case of attribute designator is not an identifier
742 else
743 if Token = Tok_Delta then
744 Attr_Name := Name_Delta;
746 elsif Token = Tok_Digits then
747 Attr_Name := Name_Digits;
749 elsif Token = Tok_Access then
750 Attr_Name := Name_Access;
752 else
753 Error_Msg_AP ("attribute designator expected");
754 raise Error_Resync;
755 end if;
757 if Style_Check then
758 Style.Check_Attribute_Name (True);
759 end if;
760 end if;
762 -- Here we have an OK attribute scanned, and the corresponding
763 -- Attribute identifier node is stored in Ident_Node.
765 Prefix_Node := Name_Node;
766 Name_Node := New_Node (N_Attribute_Reference, Prev_Token_Ptr);
767 Set_Prefix (Name_Node, Prefix_Node);
768 Set_Attribute_Name (Name_Node, Attr_Name);
769 Scan;
771 -- Check for Address clause which needs to be marked for use in
772 -- optimizing performance of Exp_Util.Following_Address_Clause.
774 if Attr_Name = Name_Address
775 and then Nkind (Prefix_Node) = N_Identifier
776 then
777 Set_Name_Table_Boolean1 (Chars (Prefix_Node), True);
778 end if;
779 end loop;
781 Rep_Clause_Node := New_Node (N_Attribute_Definition_Clause, For_Loc);
782 Set_Name (Rep_Clause_Node, Prefix_Node);
783 Set_Chars (Rep_Clause_Node, Attr_Name);
784 T_Use;
786 Expr_Node := P_Expression_No_Right_Paren;
787 Check_Simple_Expression_In_Ada_83 (Expr_Node);
788 Set_Expression (Rep_Clause_Node, Expr_Node);
790 else
791 TF_Use;
792 Rep_Clause_Node := Empty;
794 -- AT follows USE (At Clause)
796 if Token = Tok_At then
797 Scan; -- past AT
798 Rep_Clause_Node := New_Node (N_At_Clause, For_Loc);
799 Set_Identifier (Rep_Clause_Node, Identifier_Node);
800 Expr_Node := P_Expression_No_Right_Paren;
801 Check_Simple_Expression_In_Ada_83 (Expr_Node);
802 Set_Expression (Rep_Clause_Node, Expr_Node);
804 -- Mark occurrence of address clause (used to optimize performance
805 -- of Exp_Util.Following_Address_Clause).
807 Set_Name_Table_Boolean1 (Chars (Identifier_Node), True);
809 -- RECORD follows USE (Record Representation Clause)
811 elsif Token = Tok_Record then
812 Record_Items := P_Pragmas_Opt;
813 Rep_Clause_Node :=
814 New_Node (N_Record_Representation_Clause, For_Loc);
815 Set_Identifier (Rep_Clause_Node, Identifier_Node);
817 Push_Scope_Stack;
818 Scopes (Scope.Last).Etyp := E_Record;
819 Scopes (Scope.Last).Ecol := Start_Column;
820 Scopes (Scope.Last).Sloc := Token_Ptr;
821 Scan; -- past RECORD
822 Record_Items := P_Pragmas_Opt;
824 -- Possible Mod Clause
826 if Token = Tok_At then
827 Set_Mod_Clause (Rep_Clause_Node, P_Mod_Clause);
828 Set_Pragmas_Before (Mod_Clause (Rep_Clause_Node), Record_Items);
829 Record_Items := P_Pragmas_Opt;
830 end if;
832 if No (Record_Items) then
833 Record_Items := New_List;
834 end if;
836 Set_Component_Clauses (Rep_Clause_Node, Record_Items);
838 -- Loop through component clauses
840 loop
841 if Token not in Token_Class_Name then
842 exit when Check_End;
843 end if;
845 Append (P_Component_Clause, Record_Items);
846 P_Pragmas_Opt (Record_Items);
847 end loop;
849 -- Left paren follows USE (Enumeration Representation Clause)
851 elsif Token = Tok_Left_Paren then
852 Rep_Clause_Node :=
853 New_Node (N_Enumeration_Representation_Clause, For_Loc);
854 Set_Identifier (Rep_Clause_Node, Identifier_Node);
855 Set_Array_Aggregate (Rep_Clause_Node, P_Aggregate);
857 -- Some other token follows FOR (invalid representation clause)
859 else
860 Error_Msg_SC ("invalid representation clause");
861 raise Error_Resync;
862 end if;
863 end if;
865 TF_Semicolon;
866 return Rep_Clause_Node;
868 exception
869 when Error_Resync =>
870 Resync_Past_Semicolon;
871 return Error;
873 end P_Representation_Clause;
875 ----------------------
876 -- 13.1 Local Name --
877 ----------------------
879 -- Local name is always parsed by its parent. In the case of its use in
880 -- pragmas, the check for a local name is handled in Par.Prag and allows
881 -- all the possible forms of local name. For the uses in chapter 13, we
882 -- currently only allow a direct name, but this should probably change???
884 ---------------------------
885 -- 13.1 At Clause (I.7) --
886 ---------------------------
888 -- Parsed by P_Representation_Clause (13.1)
890 ---------------------------------------
891 -- 13.3 Attribute Definition Clause --
892 ---------------------------------------
894 -- Parsed by P_Representation_Clause (13.1)
896 --------------------------------
897 -- 13.1 Aspect Specification --
898 --------------------------------
900 -- ASPECT_SPECIFICATION ::=
901 -- with ASPECT_MARK [=> ASPECT_DEFINITION] {,
902 -- ASPECT_MARK [=> ASPECT_DEFINITION] }
904 -- ASPECT_MARK ::= aspect_IDENTIFIER['Class]
906 -- ASPECT_DEFINITION ::= NAME | EXPRESSION
908 -- Error recovery: cannot raise Error_Resync
910 procedure P_Aspect_Specifications
911 (Decl : Node_Id;
912 Semicolon : Boolean := True)
914 Aspects : List_Id;
915 Ptr : Source_Ptr;
917 begin
918 -- Aspect Specification is present
920 Ptr := Token_Ptr;
922 -- Here we have an aspect specification to scan, note that we don't
923 -- set the flag till later, because it may turn out that we have no
924 -- valid aspects in the list.
926 Aspects := Get_Aspect_Specifications (Semicolon);
928 -- Here if aspects present
930 if Is_Non_Empty_List (Aspects) then
932 -- If Decl is Empty, we just ignore the aspects (the caller in this
933 -- case has always issued an appropriate error message).
935 if Decl = Empty then
936 null;
938 -- If Decl is Error, we ignore the aspects, and issue a message
940 elsif Decl = Error
941 or else not Permits_Aspect_Specifications (Decl)
942 then
943 Error_Msg ("aspect specifications not allowed here", Ptr);
945 -- Here aspects are allowed, and we store them
947 else
948 Set_Aspect_Specifications (Decl, Aspects);
949 end if;
950 end if;
951 end P_Aspect_Specifications;
953 ---------------------------------------------
954 -- 13.4 Enumeration Representation Clause --
955 ---------------------------------------------
957 -- Parsed by P_Representation_Clause (13.1)
959 ---------------------------------
960 -- 13.4 Enumeration Aggregate --
961 ---------------------------------
963 -- Parsed by P_Representation_Clause (13.1)
965 ------------------------------------------
966 -- 13.5.1 Record Representation Clause --
967 ------------------------------------------
969 -- Parsed by P_Representation_Clause (13.1)
971 ------------------------------
972 -- 13.5.1 Mod Clause (I.8) --
973 ------------------------------
975 -- MOD_CLAUSE ::= at mod static_EXPRESSION;
977 -- Note: in Ada 83, the expression must be a simple expression
979 -- The caller has checked that the initial Token is AT
981 -- Error recovery: cannot raise Error_Resync
983 -- Note: the caller is responsible for setting the Pragmas_Before field
985 function P_Mod_Clause return Node_Id is
986 Mod_Node : Node_Id;
987 Expr_Node : Node_Id;
989 begin
990 Mod_Node := New_Node (N_Mod_Clause, Token_Ptr);
991 Scan; -- past AT
992 T_Mod;
993 Expr_Node := P_Expression_No_Right_Paren;
994 Check_Simple_Expression_In_Ada_83 (Expr_Node);
995 Set_Expression (Mod_Node, Expr_Node);
996 TF_Semicolon;
997 return Mod_Node;
998 end P_Mod_Clause;
1000 ------------------------------
1001 -- 13.5.1 Component Clause --
1002 ------------------------------
1004 -- COMPONENT_CLAUSE ::=
1005 -- COMPONENT_CLAUSE_COMPONENT_NAME at POSITION
1006 -- range FIRST_BIT .. LAST_BIT;
1008 -- COMPONENT_CLAUSE_COMPONENT_NAME ::=
1009 -- component_DIRECT_NAME
1010 -- | component_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1011 -- | FIRST_SUBTYPE_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
1013 -- POSITION ::= static_EXPRESSION
1015 -- Note: in Ada 83, the expression must be a simple expression
1017 -- FIRST_BIT ::= static_SIMPLE_EXPRESSION
1018 -- LAST_BIT ::= static_SIMPLE_EXPRESSION
1020 -- Note: the AARM V2.0 grammar has an error at this point, it uses
1021 -- EXPRESSION instead of SIMPLE_EXPRESSION for FIRST_BIT and LAST_BIT
1023 -- Error recovery: cannot raise Error_Resync
1025 function P_Component_Clause return Node_Id is
1026 Component_Node : Node_Id;
1027 Comp_Name : Node_Id;
1028 Expr_Node : Node_Id;
1030 begin
1031 Component_Node := New_Node (N_Component_Clause, Token_Ptr);
1032 Comp_Name := P_Name;
1034 if Nkind (Comp_Name) = N_Identifier
1035 or else Nkind (Comp_Name) = N_Attribute_Reference
1036 then
1037 Set_Component_Name (Component_Node, Comp_Name);
1038 else
1039 Error_Msg_N
1040 ("component name must be direct name or attribute", Comp_Name);
1041 Set_Component_Name (Component_Node, Error);
1042 end if;
1044 Set_Sloc (Component_Node, Token_Ptr);
1045 T_At;
1046 Expr_Node := P_Expression_No_Right_Paren;
1047 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1048 Set_Position (Component_Node, Expr_Node);
1049 T_Range;
1050 Expr_Node := P_Expression_No_Right_Paren;
1051 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1052 Set_First_Bit (Component_Node, Expr_Node);
1053 T_Dot_Dot;
1054 Expr_Node := P_Expression_No_Right_Paren;
1055 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1056 Set_Last_Bit (Component_Node, Expr_Node);
1057 TF_Semicolon;
1058 return Component_Node;
1059 end P_Component_Clause;
1061 ----------------------
1062 -- 13.5.1 Position --
1063 ----------------------
1065 -- Parsed by P_Component_Clause (13.5.1)
1067 -----------------------
1068 -- 13.5.1 First Bit --
1069 -----------------------
1071 -- Parsed by P_Component_Clause (13.5.1)
1073 ----------------------
1074 -- 13.5.1 Last Bit --
1075 ----------------------
1077 -- Parsed by P_Component_Clause (13.5.1)
1079 --------------------------
1080 -- 13.8 Code Statement --
1081 --------------------------
1083 -- CODE_STATEMENT ::= QUALIFIED_EXPRESSION
1085 -- On entry the caller has scanned the SUBTYPE_MARK (passed in as the
1086 -- single argument, and the scan points to the apostrophe.
1088 -- Error recovery: can raise Error_Resync
1090 function P_Code_Statement (Subtype_Mark : Node_Id) return Node_Id is
1091 Node1 : Node_Id;
1093 begin
1094 Scan; -- past apostrophe
1096 -- If left paren, then we have a possible code statement
1098 if Token = Tok_Left_Paren then
1099 Node1 := New_Node (N_Code_Statement, Sloc (Subtype_Mark));
1100 Set_Expression (Node1, P_Qualified_Expression (Subtype_Mark));
1101 TF_Semicolon;
1102 return Node1;
1104 -- Otherwise we have an illegal range attribute. Note that P_Name
1105 -- ensures that Token = Tok_Range is the only possibility left here.
1107 else
1108 Error_Msg_SC ("RANGE attribute illegal here!");
1109 raise Error_Resync;
1110 end if;
1111 end P_Code_Statement;
1113 end Ch13;