Debian Codegraph @

gcc/ada/par-ch13.adb

raw
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-2025, 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 ------------------------------------------------------------------------------
25
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
31
32 separate (Par)
33 package body Ch13 is
34
35 -- Local functions, used only in this chapter
36
37 function P_Component_Clause return Node_Id;
38 function P_Mod_Clause return Node_Id;
39
40 -----------------------------------
41 -- Aspect_Specifications_Present --
42 -----------------------------------
43
44 function Aspect_Specifications_Present
45 (Strict : Boolean := Ada_Version < Ada_2012) return Boolean
46 is
47 Scan_State : Saved_Scan_State;
48 Result : Boolean;
49
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.
53
54 ------------------
55 -- With_Present --
56 ------------------
57
58 function With_Present return Boolean is
59 begin
60 if Token = Tok_With then
61 return True;
62
63 -- Check for WHEN used in place of WITH
64
65 elsif Token = Tok_When then
66 declare
67 Scan_State : Saved_Scan_State;
68
69 begin
70 Save_Scan_State (Scan_State);
71 Scan; -- past WHEN
72
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;
79
80 else
81 Restore_Scan_State (Scan_State);
82 return False;
83 end if;
84 end;
85
86 else
87 return False;
88 end if;
89 end With_Present;
90
91 -- Start of processing for Aspect_Specifications_Present
92
93 begin
94 -- Definitely must have WITH to consider aspect specs to be present
95
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
99
100 -- type R is new Integer;
101 -- with bla bla;
102
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.
106
107 if not With_Present then
108 return False;
109 end if;
110
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
113
114 Save_Scan_State (Scan_State);
115 Scan; -- past WITH (or WHEN or other bad keyword)
116
117 -- If no identifier, then consider that we definitely do not have an
118 -- aspect specification.
119
120 if Token /= Tok_Identifier then
121 Result := False;
122
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.
132
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;
143
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.
147
148 else
149 if not Is_Aspect_Id (Token_Name) then
150 Result := False;
151
152 else
153 Scan; -- past aspect name
154
155 Result := False;
156
157 if Token = Tok_Arrow then
158 Result := True;
159
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.
163
164 elsif Token in Tok_Comma | Tok_Semicolon then
165 Result := True;
166
167 elsif Token = Tok_Apostrophe then
168 Scan; -- past apostrophe
169
170 if Token = Tok_Identifier
171 and then Token_Name = Name_Class
172 then
173 Scan; -- past CLASS
174
175 if Token = Tok_Arrow then
176 Result := True;
177 end if;
178 end if;
179 end if;
180
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;
188
189 Restore_Scan_State (Scan_State);
190 return Result;
191 end Aspect_Specifications_Present;
192
193 -------------------------------
194 -- Get_Aspect_Specifications --
195 -------------------------------
196
197 function Get_Aspect_Specifications (Semicolon : Boolean) return List_Id is
198 A_Id : Aspect_Id;
199 Aspect : Node_Id;
200 Aspects : List_Id := Empty_List;
201 OK : Boolean;
202
203 Opt : Boolean;
204 -- True if current aspect takes an optional argument
205
206 begin
207 -- Check if aspect specification present
208
209 if not Aspect_Specifications_Present then
210 if Semicolon then
211 TF_Semicolon;
212 end if;
213
214 return Aspects;
215 end if;
216
217 Scan; -- past WITH (or possible WHEN after error)
218 Aspects := Empty_List;
219
220 -- Loop to scan aspects
221
222 loop
223 OK := True;
224
225 -- The aspect mark is not an identifier
226
227 if Token /= Tok_Identifier then
228 Error_Msg_SC ("aspect identifier expected");
229
230 -- Skip the whole aspect specification list
231
232 if Semicolon then
233 Resync_Past_Semicolon;
234 end if;
235
236 return Aspects;
237 end if;
238
239 A_Id := Get_Aspect_Id (Token_Name);
240 Aspect :=
241 Make_Aspect_Specification (Token_Ptr,
242 Identifier => Token_Node);
243
244 -- The aspect mark is not recognized
245
246 if A_Id = No_Aspect then
247 declare
248 Msg_Issued : Boolean := False;
249 begin
250 Check_Restriction (Msg_Issued, No_Unrecognized_Aspects, Aspect);
251 if not Msg_Issued then
252 Bad_Aspect (Token_Node, Token_Name, not Debug_Flag_2);
253
254 OK := False;
255
256 end if;
257 end;
258
259 Scan; -- past incorrect identifier
260
261 if Token = Tok_Apostrophe then
262 Scan; -- past apostrophe
263 Scan; -- past presumably CLASS
264 end if;
265
266 -- Attempt to parse the aspect definition by assuming it is an
267 -- expression.
268
269 if Token = Tok_Arrow then
270 Scan; -- past arrow
271 Set_Expression (Aspect, P_Expression);
272
273 -- If we have a correct terminator (comma or semicolon, or a
274 -- reasonable likely missing comma), then just proceed.
275
276 elsif Token = Tok_Comma or else
277 Token = Tok_Semicolon or else
278 Token = Tok_Identifier
279 then
280 null;
281
282 -- Otherwise the aspect contains a junk definition
283
284 else
285 if Semicolon then
286 Resync_Past_Semicolon;
287 end if;
288
289 return Aspects;
290 end if;
291
292 -- Aspect mark is OK
293
294 else
295 Scan; -- past identifier
296 Opt := Aspect_Argument (A_Id) = Optional_Expression
297 or else
298 Aspect_Argument (A_Id) = Optional_Name;
299
300 -- Check for 'Class present
301
302 if Token = Tok_Apostrophe then
303 if Class_Aspect_OK (A_Id) then
304 Scan; -- past apostrophe
305
306 if Token = Tok_Identifier
307 and then Token_Name = Name_Class
308 then
309 Scan; -- past CLASS
310 Set_Class_Present (Aspect);
311 else
312 Error_Msg_SC ("Class attribute expected here");
313 OK := False;
314
315 if Token = Tok_Identifier then
316 Scan; -- past identifier not CLASS
317 end if;
318 end if;
319
320 -- The aspect does not allow 'Class
321
322 else
323 Error_Msg_Node_1 := Identifier (Aspect);
324 Error_Msg_SC ("aspect& does not permit attribute here");
325 OK := False;
326
327 Scan; -- past apostrophe
328 Scan; -- past presumably CLASS
329 end if;
330 end if;
331
332 -- Check for a missing aspect definition. Aspects with optional
333 -- definitions are not considered.
334
335 if Token in Tok_Comma | Tok_Semicolon then
336 if not Opt then
337 Error_Msg_Node_1 := Identifier (Aspect);
338 Error_Msg_AP ("aspect& requires an aspect definition");
339 OK := False;
340 end if;
341
342 -- Here we do not have a comma or a semicolon, we are done if we
343 -- do not have an arrow and the aspect does not need an argument
344
345 elsif Opt and then Token /= Tok_Arrow then
346 null;
347
348 -- Here we have either an arrow, or an aspect that definitely
349 -- needs an aspect definition, and we will look for one even if
350 -- no arrow is preseant.
351
352 -- Otherwise we have an aspect definition
353
354 else
355 if Token = Tok_Arrow then
356 Scan; -- past arrow
357 else
358 T_Arrow;
359 OK := False;
360 end if;
361
362 -- Detect a common error where the non-null definition of
363 -- aspect Depends, Global, Refined_Depends, Refined_Global
364 -- or Refined_State lacks enclosing parentheses.
365
366 if Token not in Tok_Left_Paren | Tok_Null then
367
368 -- [Refined_]Depends
369
370 if A_Id = Aspect_Depends
371 or else
372 A_Id = Aspect_Refined_Depends
373 then
374 Error_Msg_SC -- CODEFIX
375 ("missing ""(""");
376 Resync_Past_Malformed_Aspect;
377
378 -- Return when the current aspect is the last in the list
379 -- of specifications and the list applies to a body.
380
381 if Token = Tok_Is then
382 return Aspects;
383 end if;
384
385 -- [Refined_]Global
386
387 elsif A_Id = Aspect_Global
388 or else
389 A_Id = Aspect_Refined_Global
390 then
391 declare
392 Scan_State : Saved_Scan_State;
393
394 begin
395 Save_Scan_State (Scan_State);
396 Scan; -- past item or mode_selector
397
398 -- Emit an error when the aspect has a mode_selector
399 -- as the moded_global_list must be parenthesized:
400 -- with Global => Output => Item
401
402 if Token = Tok_Arrow then
403 Restore_Scan_State (Scan_State);
404 Error_Msg_SC -- CODEFIX
405 ("missing ""(""");
406 Resync_Past_Malformed_Aspect;
407
408 -- Return when the current aspect is the last in
409 -- the list of specifications and the list applies
410 -- to a body.
411
412 if Token = Tok_Is then
413 return Aspects;
414 end if;
415
416 elsif Token = Tok_Comma then
417 Scan; -- past comma
418
419 -- An item followed by a comma does not need to
420 -- be parenthesized if the next token is a valid
421 -- aspect name:
422 -- with Global => Item,
423 -- Aspect => ...
424
425 if Token = Tok_Identifier
426 and then Is_Aspect_Id (Token_Name)
427 then
428 Restore_Scan_State (Scan_State);
429
430 -- Otherwise this is a list of items in which case
431 -- the list must be parenthesized.
432
433 else
434 Restore_Scan_State (Scan_State);
435 Error_Msg_SC -- CODEFIX
436 ("missing ""(""");
437 Resync_Past_Malformed_Aspect;
438
439 -- Return when the current aspect is the last
440 -- in the list of specifications and the list
441 -- applies to a body.
442
443 if Token = Tok_Is then
444 return Aspects;
445 end if;
446 end if;
447
448 -- The definition of [Refined_]Global does not need to
449 -- be parenthesized.
450
451 else
452 Restore_Scan_State (Scan_State);
453 end if;
454 end;
455
456 -- Refined_State
457
458 elsif A_Id = Aspect_Refined_State then
459 if Token = Tok_Identifier then
460 declare
461 Scan_State : Saved_Scan_State;
462
463 begin
464 Save_Scan_State (Scan_State);
465 Scan; -- past state
466
467 -- The refinement contains a constituent, the whole
468 -- argument of Refined_State must be parenthesized.
469
470 -- with Refined_State => State => Constit
471
472 if Token = Tok_Arrow then
473 Restore_Scan_State (Scan_State);
474 Error_Msg_SC -- CODEFIX
475 ("missing ""(""");
476 Resync_Past_Malformed_Aspect;
477
478 -- Return when the current aspect is the last
479 -- in the list of specifications and the list
480 -- applies to a body.
481
482 if Token = Tok_Is then
483 return Aspects;
484 end if;
485
486 -- The refinement lacks constituents. Do not flag
487 -- this case as the error would be misleading. The
488 -- diagnostic is left to the analysis.
489
490 -- with Refined_State => State
491
492 else
493 Restore_Scan_State (Scan_State);
494 end if;
495 end;
496 end if;
497 end if;
498 end if;
499
500 -- Note if inside Depends or Refined_Depends aspect
501
502 if A_Id = Aspect_Depends
503 or else A_Id = Aspect_Refined_Depends
504 then
505 Inside_Depends := True;
506 end if;
507
508 -- Note that we have seen an Import aspect specification.
509 -- This matters only while parsing a subprogram.
510
511 if A_Id = Aspect_Import then
512 SIS_Aspect_Import_Seen := True;
513 -- Should do it only for subprograms
514 end if;
515
516 -- Parse the aspect definition depending on the expected
517 -- argument kind.
518
519 if Aspect_Argument (A_Id) = Name
520 or else Aspect_Argument (A_Id) = Optional_Name
521 then
522 Set_Expression (Aspect, P_Name);
523
524 else
525 pragma Assert
526 (Aspect_Argument (A_Id) = Expression
527 or else
528 Aspect_Argument (A_Id) = Optional_Expression);
529 Set_Expression (Aspect, P_Expression);
530 end if;
531
532 -- Unconditionally reset flag for Inside_Depends
533
534 Inside_Depends := False;
535 end if;
536
537 -- Add the aspect to the resulting list only when it was properly
538 -- parsed.
539
540 if OK then
541 Append (Aspect, Aspects);
542 end if;
543 end if;
544
545 -- Merge here after good or bad aspect (we should be at a comma
546 -- or a semicolon, but there might be other possible errors).
547
548 -- The aspect specification list contains more than one aspect
549
550 if Token = Tok_Comma then
551 Scan; -- past comma
552 goto Continue;
553
554 -- Check for a missing comma between two aspects. Emit an error
555 -- and proceed to the next aspect.
556
557 elsif Token = Tok_Identifier
558 and then Is_Aspect_Id (Token_Name)
559 then
560 declare
561 Scan_State : Saved_Scan_State;
562
563 begin
564 Save_Scan_State (Scan_State);
565 Scan; -- past identifier
566
567 -- Attempt to detect ' or => following a potential aspect
568 -- mark.
569
570 if Token in Tok_Apostrophe | Tok_Arrow then
571 Restore_Scan_State (Scan_State);
572 Error_Msg_AP -- CODEFIX
573 ("|missing "",""");
574 goto Continue;
575
576 -- The construct following the current aspect is not an
577 -- aspect.
578
579 else
580 Restore_Scan_State (Scan_State);
581 end if;
582 end;
583
584 -- Check for a mistyped semicolon in place of a comma between two
585 -- aspects. Emit an error and proceed to the next aspect.
586
587 elsif Token = Tok_Semicolon then
588 declare
589 Scan_State : Saved_Scan_State;
590
591 begin
592 Save_Scan_State (Scan_State);
593 Scan; -- past semicolon
594
595 if Token = Tok_Identifier
596 and then Is_Aspect_Id (Token_Name)
597 then
598 Scan; -- past identifier
599
600 -- Attempt to detect ' or => following potential aspect mark
601
602 if Token in Tok_Apostrophe | Tok_Arrow then
603 Restore_Scan_State (Scan_State);
604 Error_Msg_SC -- CODEFIX
605 ("|"";"" should be "",""");
606 Scan; -- past semicolon
607 goto Continue;
608 end if;
609 end if;
610
611 -- Construct following the current aspect is not an aspect
612
613 Restore_Scan_State (Scan_State);
614 end;
615 end if;
616
617 -- Require semicolon if caller expects to scan this out
618
619 if Semicolon then
620 T_Semicolon;
621 end if;
622
623 exit;
624
625 <<Continue>>
626 null;
627 end loop;
628
629 return Aspects;
630 end Get_Aspect_Specifications;
631
632 --------------------------------------------
633 -- 13.1 Representation Clause (also I.7) --
634 --------------------------------------------
635
636 -- REPRESENTATION_CLAUSE ::=
637 -- ATTRIBUTE_DEFINITION_CLAUSE
638 -- | ENUMERATION_REPRESENTATION_CLAUSE
639 -- | RECORD_REPRESENTATION_CLAUSE
640 -- | AT_CLAUSE
641
642 -- ATTRIBUTE_DEFINITION_CLAUSE ::=
643 -- for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use EXPRESSION;
644 -- | for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use NAME;
645
646 -- Note: in Ada 83, the expression must be a simple expression
647
648 -- AT_CLAUSE ::= for DIRECT_NAME use at EXPRESSION;
649
650 -- Note: in Ada 83, the expression must be a simple expression
651
652 -- ENUMERATION_REPRESENTATION_CLAUSE ::=
653 -- for first_subtype_LOCAL_NAME use ENUMERATION_AGGREGATE;
654
655 -- ENUMERATION_AGGREGATE ::= ARRAY_AGGREGATE
656
657 -- RECORD_REPRESENTATION_CLAUSE ::=
658 -- for first_subtype_LOCAL_NAME use
659 -- record [MOD_CLAUSE]
660 -- {COMPONENT_CLAUSE}
661 -- end record;
662
663 -- Note: for now we allow only a direct name as the local name in the
664 -- above constructs. This probably needs changing later on ???
665
666 -- The caller has checked that the initial token is FOR
667
668 -- Error recovery: cannot raise Error_Resync, if an error occurs,
669 -- the scan is repositioned past the next semicolon.
670
671 function P_Representation_Clause return Node_Id is
672 For_Loc : Source_Ptr;
673 Name_Node : Node_Id;
674 Prefix_Node : Node_Id;
675 Attr_Name : Name_Id;
676 Identifier_Node : Node_Id;
677 Rep_Clause_Node : Node_Id;
678 Expr_Node : Node_Id;
679 Record_Items : List_Id;
680
681 begin
682 For_Loc := Token_Ptr;
683 Scan; -- past FOR
684
685 -- Note that the name in a representation clause is always a simple
686 -- name, even in the attribute case, see AI-300 which made this so.
687
688 Identifier_Node := P_Identifier (C_Use);
689
690 -- Check case of qualified name to give good error message
691
692 if Token = Tok_Dot then
693 Error_Msg_SC
694 ("representation clause requires simple name!");
695
696 loop
697 exit when Token /= Tok_Dot;
698 Scan; -- past dot
699 Discard_Junk_Node (P_Identifier);
700 end loop;
701 end if;
702
703 -- Attribute Definition Clause
704
705 if Token = Tok_Apostrophe then
706
707 -- Allow local names of the form a'b'.... This enables
708 -- us to parse class-wide streams attributes correctly.
709
710 Name_Node := Identifier_Node;
711 while Token = Tok_Apostrophe loop
712
713 Scan; -- past apostrophe
714
715 Identifier_Node := Token_Node;
716 Attr_Name := No_Name;
717
718 if Token = Tok_Identifier then
719 Attr_Name := Token_Name;
720
721 -- Note that the parser must complain in case of an internal
722 -- attribute name that comes from source since internal names
723 -- are meant to be used only by the compiler.
724
725 if not Is_Attribute_Name (Attr_Name)
726 and then (not Is_Internal_Attribute_Name (Attr_Name)
727 or else Comes_From_Source (Token_Node))
728 then
729 Signal_Bad_Attribute;
730 end if;
731
732 if Style_Check then
733 Style.Check_Attribute_Name (False);
734 end if;
735
736 -- Here for case of attribute designator is not an identifier
737
738 else
739 if Token = Tok_Delta then
740 Attr_Name := Name_Delta;
741
742 elsif Token = Tok_Digits then
743 Attr_Name := Name_Digits;
744
745 elsif Token = Tok_Access then
746 Attr_Name := Name_Access;
747
748 else
749 Error_Msg_AP ("attribute designator expected");
750 raise Error_Resync;
751 end if;
752
753 if Style_Check then
754 Style.Check_Attribute_Name (True);
755 end if;
756 end if;
757
758 -- Here we have an OK attribute scanned, and the corresponding
759 -- Attribute identifier node is stored in Ident_Node.
760
761 Prefix_Node := Name_Node;
762 Name_Node := New_Node (N_Attribute_Reference, Prev_Token_Ptr);
763 Set_Prefix (Name_Node, Prefix_Node);
764 Set_Attribute_Name (Name_Node, Attr_Name);
765 Scan;
766
767 -- Check for Address clause which needs to be marked for use in
768 -- optimizing performance of Exp_Util.Following_Address_Clause.
769
770 if Attr_Name = Name_Address
771 and then Nkind (Prefix_Node) = N_Identifier
772 then
773 Set_Name_Table_Boolean1 (Chars (Prefix_Node), True);
774 end if;
775 end loop;
776
777 Rep_Clause_Node := New_Node (N_Attribute_Definition_Clause, For_Loc);
778 Set_Name (Rep_Clause_Node, Prefix_Node);
779 Set_Chars (Rep_Clause_Node, Attr_Name);
780 T_Use;
781
782 Expr_Node := P_Expression_No_Right_Paren;
783 Check_Simple_Expression_In_Ada_83 (Expr_Node);
784 Set_Expression (Rep_Clause_Node, Expr_Node);
785
786 else
787 TF_Use;
788 Rep_Clause_Node := Empty;
789
790 -- AT follows USE (At Clause)
791
792 if Token = Tok_At then
793 Scan; -- past AT
794 Rep_Clause_Node := New_Node (N_At_Clause, For_Loc);
795 Set_Identifier (Rep_Clause_Node, Identifier_Node);
796 Expr_Node := P_Expression_No_Right_Paren;
797 Check_Simple_Expression_In_Ada_83 (Expr_Node);
798 Set_Expression (Rep_Clause_Node, Expr_Node);
799
800 -- Mark occurrence of address clause (used to optimize performance
801 -- of Exp_Util.Following_Address_Clause).
802
803 Set_Name_Table_Boolean1 (Chars (Identifier_Node), True);
804
805 -- RECORD follows USE (Record Representation Clause)
806
807 elsif Token = Tok_Record then
808 Record_Items := P_Pragmas_Opt;
809 Rep_Clause_Node :=
810 New_Node (N_Record_Representation_Clause, For_Loc);
811 Set_Identifier (Rep_Clause_Node, Identifier_Node);
812
813 Push_Scope_Stack;
814 Scopes (Scope.Last).Etyp := E_Record;
815 Scopes (Scope.Last).Ecol := Start_Column;
816 Scopes (Scope.Last).Sloc := Token_Ptr;
817 Scan; -- past RECORD
818 Record_Items := P_Pragmas_Opt;
819
820 -- Possible Mod Clause
821
822 if Token = Tok_At then
823 Set_Mod_Clause (Rep_Clause_Node, P_Mod_Clause);
824 Set_Pragmas_Before (Mod_Clause (Rep_Clause_Node), Record_Items);
825 Record_Items := P_Pragmas_Opt;
826 end if;
827
828 if No (Record_Items) then
829 Record_Items := New_List;
830 end if;
831
832 Set_Component_Clauses (Rep_Clause_Node, Record_Items);
833
834 -- Loop through component clauses
835
836 loop
837 if Token not in Token_Class_Name then
838 exit when Check_End;
839 end if;
840
841 Append (P_Component_Clause, Record_Items);
842 P_Pragmas_Opt (Record_Items);
843 end loop;
844
845 -- Left paren follows USE (Enumeration Representation Clause)
846
847 elsif Token = Tok_Left_Paren then
848 Rep_Clause_Node :=
849 New_Node (N_Enumeration_Representation_Clause, For_Loc);
850 Set_Identifier (Rep_Clause_Node, Identifier_Node);
851 Set_Array_Aggregate (Rep_Clause_Node, P_Aggregate);
852
853 -- Some other token follows FOR (invalid representation clause)
854
855 else
856 Error_Msg_SC ("invalid representation clause");
857 raise Error_Resync;
858 end if;
859 end if;
860
861 TF_Semicolon;
862 return Rep_Clause_Node;
863
864 exception
865 when Error_Resync =>
866 Resync_Past_Semicolon;
867 return Error;
868
869 end P_Representation_Clause;
870
871 ----------------------
872 -- 13.1 Local Name --
873 ----------------------
874
875 -- Local name is always parsed by its parent. In the case of its use in
876 -- pragmas, the check for a local name is handled in Par.Prag and allows
877 -- all the possible forms of local name. For the uses in chapter 13, we
878 -- currently only allow a direct name, but this should probably change???
879
880 ---------------------------
881 -- 13.1 At Clause (I.7) --
882 ---------------------------
883
884 -- Parsed by P_Representation_Clause (13.1)
885
886 ---------------------------------------
887 -- 13.3 Attribute Definition Clause --
888 ---------------------------------------
889
890 -- Parsed by P_Representation_Clause (13.1)
891
892 --------------------------------
893 -- 13.1 Aspect Specification --
894 --------------------------------
895
896 -- ASPECT_SPECIFICATION ::=
897 -- with ASPECT_MARK [=> ASPECT_DEFINITION] {,
898 -- ASPECT_MARK [=> ASPECT_DEFINITION] }
899
900 -- ASPECT_MARK ::= aspect_IDENTIFIER['Class]
901
902 -- ASPECT_DEFINITION ::= NAME | EXPRESSION
903
904 -- Error recovery: cannot raise Error_Resync
905
906 procedure P_Aspect_Specifications
907 (Decl : Node_Id;
908 Semicolon : Boolean)
909 is
910 Ptr : constant Source_Ptr := Token_Ptr;
911 Aspects : constant List_Id := Get_Aspect_Specifications (Semicolon);
912
913 begin
914 if Is_Non_Empty_List (Aspects) then -- Aspects present?
915
916 -- If Decl is Empty, we just ignore the aspects (the caller in this
917 -- case has always issued an appropriate error message).
918
919 if Decl = Empty then
920 null;
921
922 -- Cases where we issue an error
923
924 elsif Decl = Error
925 or else not Permits_Aspect_Specifications (Decl)
926 then
927 Error_Msg ("aspect specifications not allowed here", Ptr);
928
929 -- Here aspects are allowed, and we store them
930
931 else
932 Set_Aspect_Specifications (Decl, Aspects);
933 end if;
934 end if;
935 end P_Aspect_Specifications;
936
937 ---------------------------------------------
938 -- 13.4 Enumeration Representation Clause --
939 ---------------------------------------------
940
941 -- Parsed by P_Representation_Clause (13.1)
942
943 ---------------------------------
944 -- 13.4 Enumeration Aggregate --
945 ---------------------------------
946
947 -- Parsed by P_Representation_Clause (13.1)
948
949 ------------------------------------------
950 -- 13.5.1 Record Representation Clause --
951 ------------------------------------------
952
953 -- Parsed by P_Representation_Clause (13.1)
954
955 ------------------------------
956 -- 13.5.1 Mod Clause (I.8) --
957 ------------------------------
958
959 -- MOD_CLAUSE ::= at mod static_EXPRESSION;
960
961 -- Note: in Ada 83, the expression must be a simple expression
962
963 -- The caller has checked that the initial Token is AT
964
965 -- Error recovery: cannot raise Error_Resync
966
967 -- Note: the caller is responsible for setting the Pragmas_Before field
968
969 function P_Mod_Clause return Node_Id is
970 Mod_Node : Node_Id;
971 Expr_Node : Node_Id;
972
973 begin
974 Mod_Node := New_Node (N_Mod_Clause, Token_Ptr);
975 Scan; -- past AT
976 T_Mod;
977 Expr_Node := P_Expression_No_Right_Paren;
978 Check_Simple_Expression_In_Ada_83 (Expr_Node);
979 Set_Expression (Mod_Node, Expr_Node);
980 TF_Semicolon;
981 return Mod_Node;
982 end P_Mod_Clause;
983
984 ------------------------------
985 -- 13.5.1 Component Clause --
986 ------------------------------
987
988 -- COMPONENT_CLAUSE ::=
989 -- COMPONENT_CLAUSE_COMPONENT_NAME at POSITION
990 -- range FIRST_BIT .. LAST_BIT;
991
992 -- COMPONENT_CLAUSE_COMPONENT_NAME ::=
993 -- component_DIRECT_NAME
994 -- | component_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
995 -- | FIRST_SUBTYPE_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
996
997 -- POSITION ::= static_EXPRESSION
998
999 -- Note: in Ada 83, the expression must be a simple expression
1000
1001 -- FIRST_BIT ::= static_SIMPLE_EXPRESSION
1002 -- LAST_BIT ::= static_SIMPLE_EXPRESSION
1003
1004 -- Note: the AARM V2.0 grammar has an error at this point, it uses
1005 -- EXPRESSION instead of SIMPLE_EXPRESSION for FIRST_BIT and LAST_BIT
1006
1007 -- Error recovery: cannot raise Error_Resync
1008
1009 function P_Component_Clause return Node_Id is
1010 Component_Node : Node_Id;
1011 Comp_Name : Node_Id;
1012 Expr_Node : Node_Id;
1013
1014 begin
1015 Component_Node := New_Node (N_Component_Clause, Token_Ptr);
1016 Comp_Name := P_Name;
1017
1018 if Nkind (Comp_Name) = N_Identifier
1019 or else Nkind (Comp_Name) = N_Attribute_Reference
1020 then
1021 Set_Component_Name (Component_Node, Comp_Name);
1022 else
1023 Error_Msg_N
1024 ("component name must be direct name or attribute", Comp_Name);
1025 Set_Component_Name (Component_Node, Error);
1026 end if;
1027
1028 Set_Sloc (Component_Node, Token_Ptr);
1029 T_At;
1030 Expr_Node := P_Expression_No_Right_Paren;
1031 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1032 Set_Position (Component_Node, Expr_Node);
1033 T_Range;
1034 Expr_Node := P_Expression_No_Right_Paren;
1035 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1036 Set_First_Bit (Component_Node, Expr_Node);
1037 T_Dot_Dot;
1038 Expr_Node := P_Expression_No_Right_Paren;
1039 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1040 Set_Last_Bit (Component_Node, Expr_Node);
1041 TF_Semicolon;
1042 return Component_Node;
1043 end P_Component_Clause;
1044
1045 ----------------------
1046 -- 13.5.1 Position --
1047 ----------------------
1048
1049 -- Parsed by P_Component_Clause (13.5.1)
1050
1051 -----------------------
1052 -- 13.5.1 First Bit --
1053 -----------------------
1054
1055 -- Parsed by P_Component_Clause (13.5.1)
1056
1057 ----------------------
1058 -- 13.5.1 Last Bit --
1059 ----------------------
1060
1061 -- Parsed by P_Component_Clause (13.5.1)
1062
1063 --------------------------
1064 -- 13.8 Code Statement --
1065 --------------------------
1066
1067 -- CODE_STATEMENT ::= QUALIFIED_EXPRESSION
1068
1069 -- On entry the caller has scanned the SUBTYPE_MARK (passed in as the
1070 -- single argument, and the scan points to the apostrophe.
1071
1072 -- Error recovery: can raise Error_Resync
1073
1074 function P_Code_Statement (Subtype_Mark : Node_Id) return Node_Id is
1075 Node1 : Node_Id;
1076
1077 begin
1078 Scan; -- past apostrophe
1079
1080 -- If left paren, then we have a possible code statement
1081
1082 if Token = Tok_Left_Paren then
1083 Node1 := New_Node (N_Code_Statement, Sloc (Subtype_Mark));
1084 Set_Expression (Node1, P_Qualified_Expression (Subtype_Mark));
1085 TF_Semicolon;
1086 return Node1;
1087
1088 -- Otherwise we have an illegal range attribute. Note that P_Name
1089 -- ensures that Token = Tok_Range is the only possibility left here.
1090
1091 else
1092 Error_Msg_SC ("RANGE attribute illegal here!");
1093 raise Error_Resync;
1094 end if;
1095 end P_Code_Statement;
1096
1097 end Ch13;