* g++.dg/template/using30.C: Move ...
[official-gcc.git] / gcc / ada / par-ch13.adb
blob0bbca4339357d71f4337b32ac195959a8860a80f
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-2014, 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 pragma Style_Checks (All_Checks);
27 -- Turn off subprogram body ordering check. Subprograms are in order
28 -- by RM section rather than alphabetical
30 separate (Par)
31 package body Ch13 is
33 -- Local functions, used only in this chapter
35 function P_Component_Clause return Node_Id;
36 function P_Mod_Clause return Node_Id;
38 -----------------------------------
39 -- Aspect_Specifications_Present --
40 -----------------------------------
42 function Aspect_Specifications_Present
43 (Strict : Boolean := Ada_Version < Ada_2012) return Boolean
45 Scan_State : Saved_Scan_State;
46 Result : Boolean;
48 function Possible_Misspelled_Aspect return Boolean;
49 -- Returns True, if Token_Name is a misspelling of some aspect name
51 --------------------------------
52 -- Possible_Misspelled_Aspect --
53 --------------------------------
55 function Possible_Misspelled_Aspect return Boolean is
56 begin
57 for J in Aspect_Id_Exclude_No_Aspect loop
58 if Is_Bad_Spelling_Of (Token_Name, Aspect_Names (J)) then
59 return True;
60 end if;
61 end loop;
63 return False;
64 end Possible_Misspelled_Aspect;
66 -- Start of processing for Aspect_Specifications_Present
68 begin
69 -- Definitely must have WITH to consider aspect specs to be present
71 -- Note that this means that if we have a semicolon, we immediately
72 -- return False. There is a case in which this is not optimal, namely
73 -- something like
75 -- type R is new Integer;
76 -- with bla bla;
78 -- where the semicolon is redundant, but scanning forward for it would
79 -- be too expensive. Instead we pick up the aspect specifications later
80 -- as a bogus declaration, and diagnose the semicolon at that point.
82 if Token /= Tok_With then
83 return False;
84 end if;
86 -- Have a WITH, see if it looks like an aspect specification
88 Save_Scan_State (Scan_State);
89 Scan; -- past WITH
91 -- If no identifier, then consider that we definitely do not have an
92 -- aspect specification.
94 if Token /= Tok_Identifier then
95 Result := False;
97 -- This is where we pay attention to the Strict mode. Normally when
98 -- we are in Ada 2012 mode, Strict is False, and we consider that we
99 -- have an aspect specification if the identifier is an aspect name
100 -- or a likely misspelling of one (even if not followed by =>) or
101 -- the identifier is not an aspect name but is followed by =>, by
102 -- a comma, or by a semicolon. The last two cases correspond to
103 -- (misspelled) Boolean aspects with a defaulted value of True.
104 -- P_Aspect_Specifications will generate messages if the aspect
105 -- specification is ill-formed.
107 elsif not Strict then
108 if Get_Aspect_Id (Token_Name) /= No_Aspect
109 or else Possible_Misspelled_Aspect
110 then
111 Result := True;
112 else
113 Scan; -- past identifier
114 Result := Token = Tok_Arrow or else
115 Token = Tok_Comma or else
116 Token = Tok_Semicolon;
117 end if;
119 -- If earlier than Ada 2012, check for valid aspect identifier (possibly
120 -- completed with 'CLASS) followed by an arrow, and consider that this
121 -- is still an aspect specification so we give an appropriate message.
123 else
124 if Get_Aspect_Id (Token_Name) = No_Aspect then
125 Result := False;
127 else
128 Scan; -- past aspect name
130 Result := False;
132 if Token = Tok_Arrow then
133 Result := True;
135 -- The identifier may be the name of a boolean aspect with a
136 -- defaulted True value. Further checks when analyzing aspect
137 -- specification, which may include further aspects.
139 elsif Token = Tok_Comma or else Token = Tok_Semicolon then
140 Result := True;
142 elsif Token = Tok_Apostrophe then
143 Scan; -- past apostrophe
145 if Token = Tok_Identifier
146 and then Token_Name = Name_Class
147 then
148 Scan; -- past CLASS
150 if Token = Tok_Arrow then
151 Result := True;
152 end if;
153 end if;
154 end if;
156 if Result then
157 Restore_Scan_State (Scan_State);
158 Error_Msg_Ada_2012_Feature ("|aspect specification", Token_Ptr);
159 return True;
160 end if;
161 end if;
162 end if;
164 Restore_Scan_State (Scan_State);
165 return Result;
166 end Aspect_Specifications_Present;
168 -------------------------------
169 -- Get_Aspect_Specifications --
170 -------------------------------
172 function Get_Aspect_Specifications
173 (Semicolon : Boolean := True) return List_Id
175 A_Id : Aspect_Id;
176 Aspect : Node_Id;
177 Aspects : List_Id;
178 OK : Boolean;
180 Opt : Boolean;
181 -- True if current aspect takes an optional argument
183 begin
184 Aspects := Empty_List;
186 -- Check if aspect specification present
188 if not Aspect_Specifications_Present then
189 if Semicolon then
190 TF_Semicolon;
191 end if;
193 return Aspects;
194 end if;
196 Scan; -- past WITH
197 Aspects := Empty_List;
199 -- Loop to scan aspects
201 loop
202 OK := True;
204 -- The aspect mark is not an identifier
206 if Token /= Tok_Identifier then
207 Error_Msg_SC ("aspect identifier expected");
209 -- Skip the whole aspect specification list
211 if Semicolon then
212 Resync_Past_Semicolon;
213 end if;
215 return Aspects;
216 end if;
218 A_Id := Get_Aspect_Id (Token_Name);
219 Aspect :=
220 Make_Aspect_Specification (Token_Ptr,
221 Identifier => Token_Node);
223 -- The aspect mark is not recognized
225 if A_Id = No_Aspect then
226 Error_Msg_N ("& is not a valid aspect identifier", Token_Node);
227 OK := False;
229 -- Check bad spelling
231 for J in Aspect_Id_Exclude_No_Aspect loop
232 if Is_Bad_Spelling_Of (Token_Name, Aspect_Names (J)) then
233 Error_Msg_Name_1 := Aspect_Names (J);
234 Error_Msg_N -- CODEFIX
235 ("\possible misspelling of%", Token_Node);
236 exit;
237 end if;
238 end loop;
240 Scan; -- past incorrect identifier
242 if Token = Tok_Apostrophe then
243 Scan; -- past apostrophe
244 Scan; -- past presumably CLASS
245 end if;
247 -- Attempt to parse the aspect definition by assuming it is an
248 -- expression.
250 if Token = Tok_Arrow then
251 Scan; -- past arrow
252 Set_Expression (Aspect, P_Expression);
254 -- If we have a correct terminator (comma or semicolon, or a
255 -- reasonable likely missing comma), then just proceed.
257 elsif Token = Tok_Comma or else
258 Token = Tok_Semicolon or else
259 Token = Tok_Identifier
260 then
261 null;
263 -- Otherwise the aspect contains a junk definition
265 else
266 if Semicolon then
267 Resync_Past_Semicolon;
268 end if;
270 return Aspects;
271 end if;
273 -- Aspect mark is OK
275 else
276 Scan; -- past identifier
277 Opt := Aspect_Argument (A_Id) = Optional_Expression
278 or else
279 Aspect_Argument (A_Id) = Optional_Name;
281 -- Check for 'Class present
283 if Token = Tok_Apostrophe then
284 if Class_Aspect_OK (A_Id) then
285 Scan; -- past apostrophe
287 if Token = Tok_Identifier
288 and then Token_Name = Name_Class
289 then
290 Scan; -- past CLASS
291 Set_Class_Present (Aspect);
292 else
293 Error_Msg_SC ("Class attribute expected here");
294 OK := False;
296 if Token = Tok_Identifier then
297 Scan; -- past identifier not CLASS
298 end if;
299 end if;
301 -- The aspect does not allow 'Class
303 else
304 Error_Msg_Node_1 := Identifier (Aspect);
305 Error_Msg_SC ("aspect& does not permit attribute here");
306 OK := False;
308 Scan; -- past apostrophe
309 Scan; -- past presumably CLASS
310 end if;
311 end if;
313 -- Check for a missing aspect definition. Aspects with optional
314 -- definitions are not considered.
316 if Token = Tok_Comma or else Token = Tok_Semicolon then
317 if not Opt then
318 Error_Msg_Node_1 := Identifier (Aspect);
319 Error_Msg_AP ("aspect& requires an aspect definition");
320 OK := False;
321 end if;
323 -- Here we do not have a comma or a semicolon, we are done if we
324 -- do not have an arrow and the aspect does not need an argument
326 elsif Opt and then Token /= Tok_Arrow then
327 null;
329 -- Here we have either an arrow, or an aspect that definitely
330 -- needs an aspect definition, and we will look for one even if
331 -- no arrow is preseant.
333 -- Otherwise we have an aspect definition
335 else
336 if Token = Tok_Arrow then
337 Scan; -- past arrow
338 else
339 T_Arrow;
340 OK := False;
341 end if;
343 -- Detect a common error where the non-null definition of
344 -- aspect Depends, Global, Refined_Depends, Refined_Global
345 -- or Refined_State lacks enclosing parentheses.
347 if Token /= Tok_Left_Paren and then Token /= Tok_Null then
349 -- [Refined_]Depends
351 if A_Id = Aspect_Depends
352 or else
353 A_Id = Aspect_Refined_Depends
354 then
355 Error_Msg_SC -- CODEFIX
356 ("missing ""(""");
357 Resync_Past_Malformed_Aspect;
359 -- Return when the current aspect is the last in the list
360 -- of specifications and the list applies to a body.
362 if Token = Tok_Is then
363 return Aspects;
364 end if;
366 -- [Refined_]Global
368 elsif A_Id = Aspect_Global
369 or else
370 A_Id = Aspect_Refined_Global
371 then
372 declare
373 Scan_State : Saved_Scan_State;
375 begin
376 Save_Scan_State (Scan_State);
377 Scan; -- past item or mode_selector
379 -- Emit an error when the aspect has a mode_selector
380 -- as the moded_global_list must be parenthesized:
381 -- with Global => Output => Item
383 if Token = Tok_Arrow then
384 Restore_Scan_State (Scan_State);
385 Error_Msg_SC -- CODEFIX
386 ("missing ""(""");
387 Resync_Past_Malformed_Aspect;
389 -- Return when the current aspect is the last in
390 -- the list of specifications and the list applies
391 -- to a body.
393 if Token = Tok_Is then
394 return Aspects;
395 end if;
397 elsif Token = Tok_Comma then
398 Scan; -- past comma
400 -- An item followed by a comma does not need to
401 -- be parenthesized if the next token is a valid
402 -- aspect name:
403 -- with Global => Item,
404 -- Aspect => ...
406 if Token = Tok_Identifier
407 and then Get_Aspect_Id (Token_Name) /= No_Aspect
408 then
409 Restore_Scan_State (Scan_State);
411 -- Otherwise this is a list of items in which case
412 -- the list must be parenthesized.
414 else
415 Restore_Scan_State (Scan_State);
416 Error_Msg_SC -- CODEFIX
417 ("missing ""(""");
418 Resync_Past_Malformed_Aspect;
420 -- Return when the current aspect is the last
421 -- in the list of specifications and the list
422 -- applies to a body.
424 if Token = Tok_Is then
425 return Aspects;
426 end if;
427 end if;
429 -- The definition of [Refined_]Global does not need to
430 -- be parenthesized.
432 else
433 Restore_Scan_State (Scan_State);
434 end if;
435 end;
437 -- Refined_State
439 elsif A_Id = Aspect_Refined_State then
440 if Token = Tok_Identifier then
441 declare
442 Scan_State : Saved_Scan_State;
444 begin
445 Save_Scan_State (Scan_State);
446 Scan; -- past state
448 -- The refinement contains a constituent, the whole
449 -- argument of Refined_State must be parenthesized.
451 -- with Refined_State => State => Constit
453 if Token = Tok_Arrow then
454 Restore_Scan_State (Scan_State);
455 Error_Msg_SC -- CODEFIX
456 ("missing ""(""");
457 Resync_Past_Malformed_Aspect;
459 -- Return when the current aspect is the last
460 -- in the list of specifications and the list
461 -- applies to a body.
463 if Token = Tok_Is then
464 return Aspects;
465 end if;
467 -- The refinement lacks constituents. Do not flag
468 -- this case as the error would be misleading. The
469 -- diagnostic is left to the analysis.
471 -- with Refined_State => State
473 else
474 Restore_Scan_State (Scan_State);
475 end if;
476 end;
477 end if;
478 end if;
479 end if;
481 -- Note if inside Depends aspect
483 if A_Id = Aspect_Depends then
484 Inside_Depends := True;
485 end if;
487 -- Parse the aspect definition depening on the expected
488 -- argument kind.
490 if Aspect_Argument (A_Id) = Name
491 or else Aspect_Argument (A_Id) = Optional_Name
492 then
493 Set_Expression (Aspect, P_Name);
495 else
496 pragma Assert
497 (Aspect_Argument (A_Id) = Expression
498 or else
499 Aspect_Argument (A_Id) = Optional_Expression);
500 Set_Expression (Aspect, P_Expression);
501 end if;
503 -- Unconditionally reset flag for Inside_Depends
505 Inside_Depends := False;
506 end if;
508 -- Add the aspect to the resulting list only when it was properly
509 -- parsed.
511 if OK then
512 Append (Aspect, Aspects);
513 end if;
514 end if;
516 -- Merge here after good or bad aspect (we should be at a comma
517 -- or a semicolon, but there might be other possible errors).
519 -- The aspect specification list contains more than one aspect
521 if Token = Tok_Comma then
522 Scan; -- past comma
523 goto Continue;
525 -- Check for a missing comma between two aspects. Emit an error
526 -- and proceed to the next aspect.
528 elsif Token = Tok_Identifier
529 and then Get_Aspect_Id (Token_Name) /= No_Aspect
530 then
531 declare
532 Scan_State : Saved_Scan_State;
534 begin
535 Save_Scan_State (Scan_State);
536 Scan; -- past identifier
538 -- Attempt to detect ' or => following a potential aspect
539 -- mark.
541 if Token = Tok_Apostrophe or else Token = Tok_Arrow then
542 Restore_Scan_State (Scan_State);
543 Error_Msg_AP -- CODEFIX
544 ("|missing "",""");
545 goto Continue;
547 -- The construct following the current aspect is not an
548 -- aspect.
550 else
551 Restore_Scan_State (Scan_State);
552 end if;
553 end;
555 -- Check for a mistyped semicolon in place of a comma between two
556 -- aspects. Emit an error and proceed to the next aspect.
558 elsif Token = Tok_Semicolon then
559 declare
560 Scan_State : Saved_Scan_State;
562 begin
563 Save_Scan_State (Scan_State);
564 Scan; -- past semicolon
566 if Token = Tok_Identifier
567 and then Get_Aspect_Id (Token_Name) /= No_Aspect
568 then
569 Scan; -- past identifier
571 -- Attempt to detect ' or => following potential aspect mark
573 if Token = Tok_Apostrophe or else Token = Tok_Arrow then
574 Restore_Scan_State (Scan_State);
575 Error_Msg_SC -- CODEFIX
576 ("|"";"" should be "",""");
577 Scan; -- past semicolon
578 goto Continue;
579 end if;
580 end if;
582 -- Construct following the current aspect is not an aspect
584 Restore_Scan_State (Scan_State);
585 end;
586 end if;
588 -- Require semicolon if caller expects to scan this out
590 if Semicolon then
591 T_Semicolon;
592 end if;
594 exit;
596 <<Continue>>
597 null;
598 end loop;
600 return Aspects;
601 end Get_Aspect_Specifications;
603 --------------------------------------------
604 -- 13.1 Representation Clause (also I.7) --
605 --------------------------------------------
607 -- REPRESENTATION_CLAUSE ::=
608 -- ATTRIBUTE_DEFINITION_CLAUSE
609 -- | ENUMERATION_REPRESENTATION_CLAUSE
610 -- | RECORD_REPRESENTATION_CLAUSE
611 -- | AT_CLAUSE
613 -- ATTRIBUTE_DEFINITION_CLAUSE ::=
614 -- for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use EXPRESSION;
615 -- | for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use NAME;
617 -- Note: in Ada 83, the expression must be a simple expression
619 -- AT_CLAUSE ::= for DIRECT_NAME use at EXPRESSION;
621 -- Note: in Ada 83, the expression must be a simple expression
623 -- ENUMERATION_REPRESENTATION_CLAUSE ::=
624 -- for first_subtype_LOCAL_NAME use ENUMERATION_AGGREGATE;
626 -- ENUMERATION_AGGREGATE ::= ARRAY_AGGREGATE
628 -- RECORD_REPRESENTATION_CLAUSE ::=
629 -- for first_subtype_LOCAL_NAME use
630 -- record [MOD_CLAUSE]
631 -- {COMPONENT_CLAUSE}
632 -- end record;
634 -- Note: for now we allow only a direct name as the local name in the
635 -- above constructs. This probably needs changing later on ???
637 -- The caller has checked that the initial token is FOR
639 -- Error recovery: cannot raise Error_Resync, if an error occurs,
640 -- the scan is repositioned past the next semicolon.
642 function P_Representation_Clause return Node_Id is
643 For_Loc : Source_Ptr;
644 Name_Node : Node_Id;
645 Prefix_Node : Node_Id;
646 Attr_Name : Name_Id;
647 Identifier_Node : Node_Id;
648 Rep_Clause_Node : Node_Id;
649 Expr_Node : Node_Id;
650 Record_Items : List_Id;
652 begin
653 For_Loc := Token_Ptr;
654 Scan; -- past FOR
656 -- Note that the name in a representation clause is always a simple
657 -- name, even in the attribute case, see AI-300 which made this so.
659 Identifier_Node := P_Identifier (C_Use);
661 -- Check case of qualified name to give good error message
663 if Token = Tok_Dot then
664 Error_Msg_SC
665 ("representation clause requires simple name!");
667 loop
668 exit when Token /= Tok_Dot;
669 Scan; -- past dot
670 Discard_Junk_Node (P_Identifier);
671 end loop;
672 end if;
674 -- Attribute Definition Clause
676 if Token = Tok_Apostrophe then
678 -- Allow local names of the form a'b'.... This enables
679 -- us to parse class-wide streams attributes correctly.
681 Name_Node := Identifier_Node;
682 while Token = Tok_Apostrophe loop
684 Scan; -- past apostrophe
686 Identifier_Node := Token_Node;
687 Attr_Name := No_Name;
689 if Token = Tok_Identifier then
690 Attr_Name := Token_Name;
692 -- Note that the parser must complain in case of an internal
693 -- attribute name that comes from source since internal names
694 -- are meant to be used only by the compiler.
696 if not Is_Attribute_Name (Attr_Name)
697 and then (not Is_Internal_Attribute_Name (Attr_Name)
698 or else Comes_From_Source (Token_Node))
699 then
700 Signal_Bad_Attribute;
701 end if;
703 if Style_Check then
704 Style.Check_Attribute_Name (False);
705 end if;
707 -- Here for case of attribute designator is not an identifier
709 else
710 if Token = Tok_Delta then
711 Attr_Name := Name_Delta;
713 elsif Token = Tok_Digits then
714 Attr_Name := Name_Digits;
716 elsif Token = Tok_Access then
717 Attr_Name := Name_Access;
719 else
720 Error_Msg_AP ("attribute designator expected");
721 raise Error_Resync;
722 end if;
724 if Style_Check then
725 Style.Check_Attribute_Name (True);
726 end if;
727 end if;
729 -- Here we have an OK attribute scanned, and the corresponding
730 -- Attribute identifier node is stored in Ident_Node.
732 Prefix_Node := Name_Node;
733 Name_Node := New_Node (N_Attribute_Reference, Prev_Token_Ptr);
734 Set_Prefix (Name_Node, Prefix_Node);
735 Set_Attribute_Name (Name_Node, Attr_Name);
736 Scan;
738 -- Check for Address clause which needs to be marked for use in
739 -- optimizing performance of Exp_Util.Following_Address_Clause.
741 if Attr_Name = Name_Address
742 and then Nkind (Prefix_Node) = N_Identifier
743 then
744 Set_Name_Table_Boolean (Chars (Prefix_Node), True);
745 end if;
746 end loop;
748 Rep_Clause_Node := New_Node (N_Attribute_Definition_Clause, For_Loc);
749 Set_Name (Rep_Clause_Node, Prefix_Node);
750 Set_Chars (Rep_Clause_Node, Attr_Name);
751 T_Use;
753 Expr_Node := P_Expression_No_Right_Paren;
754 Check_Simple_Expression_In_Ada_83 (Expr_Node);
755 Set_Expression (Rep_Clause_Node, Expr_Node);
757 else
758 TF_Use;
759 Rep_Clause_Node := Empty;
761 -- AT follows USE (At Clause)
763 if Token = Tok_At then
764 Scan; -- past AT
765 Rep_Clause_Node := New_Node (N_At_Clause, For_Loc);
766 Set_Identifier (Rep_Clause_Node, Identifier_Node);
767 Expr_Node := P_Expression_No_Right_Paren;
768 Check_Simple_Expression_In_Ada_83 (Expr_Node);
769 Set_Expression (Rep_Clause_Node, Expr_Node);
771 -- Mark occurrence of address clause (used to optimize performance
772 -- of Exp_Util.Following_Address_Clause).
774 Set_Name_Table_Boolean (Chars (Identifier_Node), True);
776 -- RECORD follows USE (Record Representation Clause)
778 elsif Token = Tok_Record then
779 Record_Items := P_Pragmas_Opt;
780 Rep_Clause_Node :=
781 New_Node (N_Record_Representation_Clause, For_Loc);
782 Set_Identifier (Rep_Clause_Node, Identifier_Node);
784 Push_Scope_Stack;
785 Scope.Table (Scope.Last).Etyp := E_Record;
786 Scope.Table (Scope.Last).Ecol := Start_Column;
787 Scope.Table (Scope.Last).Sloc := Token_Ptr;
788 Scan; -- past RECORD
789 Record_Items := P_Pragmas_Opt;
791 -- Possible Mod Clause
793 if Token = Tok_At then
794 Set_Mod_Clause (Rep_Clause_Node, P_Mod_Clause);
795 Set_Pragmas_Before (Mod_Clause (Rep_Clause_Node), Record_Items);
796 Record_Items := P_Pragmas_Opt;
797 end if;
799 if No (Record_Items) then
800 Record_Items := New_List;
801 end if;
803 Set_Component_Clauses (Rep_Clause_Node, Record_Items);
805 -- Loop through component clauses
807 loop
808 if Token not in Token_Class_Name then
809 exit when Check_End;
810 end if;
812 Append (P_Component_Clause, Record_Items);
813 P_Pragmas_Opt (Record_Items);
814 end loop;
816 -- Left paren follows USE (Enumeration Representation Clause)
818 elsif Token = Tok_Left_Paren then
819 Rep_Clause_Node :=
820 New_Node (N_Enumeration_Representation_Clause, For_Loc);
821 Set_Identifier (Rep_Clause_Node, Identifier_Node);
822 Set_Array_Aggregate (Rep_Clause_Node, P_Aggregate);
824 -- Some other token follows FOR (invalid representation clause)
826 else
827 Error_Msg_SC ("invalid representation clause");
828 raise Error_Resync;
829 end if;
830 end if;
832 TF_Semicolon;
833 return Rep_Clause_Node;
835 exception
836 when Error_Resync =>
837 Resync_Past_Semicolon;
838 return Error;
840 end P_Representation_Clause;
842 ----------------------
843 -- 13.1 Local Name --
844 ----------------------
846 -- Local name is always parsed by its parent. In the case of its use in
847 -- pragmas, the check for a local name is handled in Par.Prag and allows
848 -- all the possible forms of local name. For the uses in chapter 13, we
849 -- currently only allow a direct name, but this should probably change???
851 ---------------------------
852 -- 13.1 At Clause (I.7) --
853 ---------------------------
855 -- Parsed by P_Representation_Clause (13.1)
857 ---------------------------------------
858 -- 13.3 Attribute Definition Clause --
859 ---------------------------------------
861 -- Parsed by P_Representation_Clause (13.1)
863 --------------------------------
864 -- 13.1 Aspect Specification --
865 --------------------------------
867 -- ASPECT_SPECIFICATION ::=
868 -- with ASPECT_MARK [=> ASPECT_DEFINITION] {,
869 -- ASPECT_MARK [=> ASPECT_DEFINITION] }
871 -- ASPECT_MARK ::= aspect_IDENTIFIER['Class]
873 -- ASPECT_DEFINITION ::= NAME | EXPRESSION
875 -- Error recovery: cannot raise Error_Resync
877 procedure P_Aspect_Specifications
878 (Decl : Node_Id;
879 Semicolon : Boolean := True)
881 Aspects : List_Id;
882 Ptr : Source_Ptr;
884 begin
885 -- Aspect Specification is present
887 Ptr := Token_Ptr;
889 -- Here we have an aspect specification to scan, note that we don't
890 -- set the flag till later, because it may turn out that we have no
891 -- valid aspects in the list.
893 Aspects := Get_Aspect_Specifications (Semicolon);
895 -- Here if aspects present
897 if Is_Non_Empty_List (Aspects) then
899 -- If Decl is Empty, we just ignore the aspects (the caller in this
900 -- case has always issued an appropriate error message).
902 if Decl = Empty then
903 null;
905 -- If Decl is Error, we ignore the aspects, and issue a message
907 elsif Decl = Error then
908 Error_Msg ("aspect specifications not allowed here", Ptr);
910 -- Here aspects are allowed, and we store them
912 else
913 Set_Parent (Aspects, Decl);
914 Set_Aspect_Specifications (Decl, Aspects);
915 end if;
916 end if;
917 end P_Aspect_Specifications;
919 ---------------------------------------------
920 -- 13.4 Enumeration Representation Clause --
921 ---------------------------------------------
923 -- Parsed by P_Representation_Clause (13.1)
925 ---------------------------------
926 -- 13.4 Enumeration Aggregate --
927 ---------------------------------
929 -- Parsed by P_Representation_Clause (13.1)
931 ------------------------------------------
932 -- 13.5.1 Record Representation Clause --
933 ------------------------------------------
935 -- Parsed by P_Representation_Clause (13.1)
937 ------------------------------
938 -- 13.5.1 Mod Clause (I.8) --
939 ------------------------------
941 -- MOD_CLAUSE ::= at mod static_EXPRESSION;
943 -- Note: in Ada 83, the expression must be a simple expression
945 -- The caller has checked that the initial Token is AT
947 -- Error recovery: cannot raise Error_Resync
949 -- Note: the caller is responsible for setting the Pragmas_Before field
951 function P_Mod_Clause return Node_Id is
952 Mod_Node : Node_Id;
953 Expr_Node : Node_Id;
955 begin
956 Mod_Node := New_Node (N_Mod_Clause, Token_Ptr);
957 Scan; -- past AT
958 T_Mod;
959 Expr_Node := P_Expression_No_Right_Paren;
960 Check_Simple_Expression_In_Ada_83 (Expr_Node);
961 Set_Expression (Mod_Node, Expr_Node);
962 TF_Semicolon;
963 return Mod_Node;
964 end P_Mod_Clause;
966 ------------------------------
967 -- 13.5.1 Component Clause --
968 ------------------------------
970 -- COMPONENT_CLAUSE ::=
971 -- COMPONENT_CLAUSE_COMPONENT_NAME at POSITION
972 -- range FIRST_BIT .. LAST_BIT;
974 -- COMPONENT_CLAUSE_COMPONENT_NAME ::=
975 -- component_DIRECT_NAME
976 -- | component_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
977 -- | FIRST_SUBTYPE_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
979 -- POSITION ::= static_EXPRESSION
981 -- Note: in Ada 83, the expression must be a simple expression
983 -- FIRST_BIT ::= static_SIMPLE_EXPRESSION
984 -- LAST_BIT ::= static_SIMPLE_EXPRESSION
986 -- Note: the AARM V2.0 grammar has an error at this point, it uses
987 -- EXPRESSION instead of SIMPLE_EXPRESSION for FIRST_BIT and LAST_BIT
989 -- Error recovery: cannot raise Error_Resync
991 function P_Component_Clause return Node_Id is
992 Component_Node : Node_Id;
993 Comp_Name : Node_Id;
994 Expr_Node : Node_Id;
996 begin
997 Component_Node := New_Node (N_Component_Clause, Token_Ptr);
998 Comp_Name := P_Name;
1000 if Nkind (Comp_Name) = N_Identifier
1001 or else Nkind (Comp_Name) = N_Attribute_Reference
1002 then
1003 Set_Component_Name (Component_Node, Comp_Name);
1004 else
1005 Error_Msg_N
1006 ("component name must be direct name or attribute", Comp_Name);
1007 Set_Component_Name (Component_Node, Error);
1008 end if;
1010 Set_Sloc (Component_Node, Token_Ptr);
1011 T_At;
1012 Expr_Node := P_Expression_No_Right_Paren;
1013 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1014 Set_Position (Component_Node, Expr_Node);
1015 T_Range;
1016 Expr_Node := P_Expression_No_Right_Paren;
1017 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1018 Set_First_Bit (Component_Node, Expr_Node);
1019 T_Dot_Dot;
1020 Expr_Node := P_Expression_No_Right_Paren;
1021 Check_Simple_Expression_In_Ada_83 (Expr_Node);
1022 Set_Last_Bit (Component_Node, Expr_Node);
1023 TF_Semicolon;
1024 return Component_Node;
1025 end P_Component_Clause;
1027 ----------------------
1028 -- 13.5.1 Position --
1029 ----------------------
1031 -- Parsed by P_Component_Clause (13.5.1)
1033 -----------------------
1034 -- 13.5.1 First Bit --
1035 -----------------------
1037 -- Parsed by P_Component_Clause (13.5.1)
1039 ----------------------
1040 -- 13.5.1 Last Bit --
1041 ----------------------
1043 -- Parsed by P_Component_Clause (13.5.1)
1045 --------------------------
1046 -- 13.8 Code Statement --
1047 --------------------------
1049 -- CODE_STATEMENT ::= QUALIFIED_EXPRESSION
1051 -- On entry the caller has scanned the SUBTYPE_MARK (passed in as the
1052 -- single argument, and the scan points to the apostrophe.
1054 -- Error recovery: can raise Error_Resync
1056 function P_Code_Statement (Subtype_Mark : Node_Id) return Node_Id is
1057 Node1 : Node_Id;
1059 begin
1060 Scan; -- past apostrophe
1062 -- If left paren, then we have a possible code statement
1064 if Token = Tok_Left_Paren then
1065 Node1 := New_Node (N_Code_Statement, Sloc (Subtype_Mark));
1066 Set_Expression (Node1, P_Qualified_Expression (Subtype_Mark));
1067 TF_Semicolon;
1068 return Node1;
1070 -- Otherwise we have an illegal range attribute. Note that P_Name
1071 -- ensures that Token = Tok_Range is the only possibility left here.
1073 else
1074 Error_Msg_SC ("RANGE attribute illegal here!");
1075 raise Error_Resync;
1076 end if;
1077 end P_Code_Statement;
1079 end Ch13;