OSDN Git Service

Add NIOS2 support. Code from SourceyG++.
[pf3gnuchains/gcc-fork.git] / gcc / ada / par-ch13.adb
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-2012, 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 pragma Style_Checks (All_Checks);
27 --  Turn off subprogram body ordering check. Subprograms are in order
28 --  by RM section rather than alphabetical
29
30 separate (Par)
31 package body Ch13 is
32
33    --  Local functions, used only in this chapter
34
35    function P_Component_Clause return Node_Id;
36    function P_Mod_Clause return Node_Id;
37
38    -----------------------------------
39    -- Aspect_Specifications_Present --
40    -----------------------------------
41
42    function Aspect_Specifications_Present
43      (Strict : Boolean := Ada_Version < Ada_2012) return Boolean
44    is
45       Scan_State : Saved_Scan_State;
46       Result     : Boolean;
47
48    begin
49       --  Definitely must have WITH to consider aspect specs to be present
50
51       --  Note that this means that if we have a semicolon, we immediately
52       --  return False. There is a case in which this is not optimal, namely
53       --  something like
54
55       --    type R is new Integer;
56       --      with bla bla;
57
58       --  where the semicolon is redundant, but scanning forward for it would
59       --  be too expensive. Instead we pick up the aspect specifications later
60       --  as a bogus declaration, and diagnose the semicolon at that point.
61
62       if Token /= Tok_With then
63          return False;
64       end if;
65
66       --  Have a WITH, see if it looks like an aspect specification
67
68       Save_Scan_State (Scan_State);
69       Scan; -- past WITH
70
71       --  If no identifier, then consider that we definitely do not have an
72       --  aspect specification.
73
74       if Token /= Tok_Identifier then
75          Result := False;
76
77       --  This is where we pay attention to the Strict mode. Normally when we
78       --  are in Ada 2012 mode, Strict is False, and we consider that we have
79       --  an aspect specification if the identifier is an aspect name (even if
80       --  not followed by =>) or the identifier is not an aspect name but is
81       --  followed by =>. P_Aspect_Specifications will generate messages if the
82       --  aspect specification is ill-formed.
83
84       elsif not Strict then
85          if Get_Aspect_Id (Token_Name) /= No_Aspect then
86             Result := True;
87          else
88             Scan; -- past identifier
89             Result := Token = Tok_Arrow;
90          end if;
91
92       --  If earlier than Ada 2012, check for valid aspect identifier (possibly
93       --  completed with 'CLASS) followed by an arrow, and consider that this
94       --  is still an aspect specification so we give an appropriate message.
95
96       else
97          if Get_Aspect_Id (Token_Name) = No_Aspect then
98             Result := False;
99
100          else
101             Scan; -- past aspect name
102
103             Result := False;
104
105             if Token = Tok_Arrow then
106                Result := True;
107
108             elsif Token = Tok_Apostrophe then
109                Scan; -- past apostrophe
110
111                if Token = Tok_Identifier
112                  and then Token_Name = Name_Class
113                then
114                   Scan; -- past CLASS
115
116                   if Token = Tok_Arrow then
117                      Result := True;
118                   end if;
119                end if;
120             end if;
121
122             if Result then
123                Restore_Scan_State (Scan_State);
124                Error_Msg_SC ("|aspect specification is an Ada 2012 feature");
125                Error_Msg_SC ("\|unit must be compiled with -gnat2012 switch");
126                return True;
127             end if;
128          end if;
129       end if;
130
131       Restore_Scan_State (Scan_State);
132       return Result;
133    end Aspect_Specifications_Present;
134
135    --------------------------------------------
136    -- 13.1  Representation Clause (also I.7) --
137    --------------------------------------------
138
139    --  REPRESENTATION_CLAUSE ::=
140    --    ATTRIBUTE_DEFINITION_CLAUSE
141    --  | ENUMERATION_REPRESENTATION_CLAUSE
142    --  | RECORD_REPRESENTATION_CLAUSE
143    --  | AT_CLAUSE
144
145    --  ATTRIBUTE_DEFINITION_CLAUSE ::=
146    --    for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use EXPRESSION;
147    --  | for LOCAL_NAME'ATTRIBUTE_DESIGNATOR use NAME;
148
149    --  Note: in Ada 83, the expression must be a simple expression
150
151    --  AT_CLAUSE ::= for DIRECT_NAME use at EXPRESSION;
152
153    --  Note: in Ada 83, the expression must be a simple expression
154
155    --  ENUMERATION_REPRESENTATION_CLAUSE ::=
156    --    for first_subtype_LOCAL_NAME use ENUMERATION_AGGREGATE;
157
158    --  ENUMERATION_AGGREGATE ::= ARRAY_AGGREGATE
159
160    --  RECORD_REPRESENTATION_CLAUSE ::=
161    --    for first_subtype_LOCAL_NAME use
162    --      record [MOD_CLAUSE]
163    --        {COMPONENT_CLAUSE}
164    --      end record;
165
166    --  Note: for now we allow only a direct name as the local name in the
167    --  above constructs. This probably needs changing later on ???
168
169    --  The caller has checked that the initial token is FOR
170
171    --  Error recovery: cannot raise Error_Resync, if an error occurs,
172    --  the scan is repositioned past the next semicolon.
173
174    function P_Representation_Clause return Node_Id is
175       For_Loc         : Source_Ptr;
176       Name_Node       : Node_Id;
177       Prefix_Node     : Node_Id;
178       Attr_Name       : Name_Id;
179       Identifier_Node : Node_Id;
180       Rep_Clause_Node : Node_Id;
181       Expr_Node       : Node_Id;
182       Record_Items    : List_Id;
183
184    begin
185       For_Loc := Token_Ptr;
186       Scan; -- past FOR
187
188       --  Note that the name in a representation clause is always a simple
189       --  name, even in the attribute case, see AI-300 which made this so!
190
191       Identifier_Node := P_Identifier (C_Use);
192
193       --  Check case of qualified name to give good error message
194
195       if Token = Tok_Dot then
196          Error_Msg_SC
197             ("representation clause requires simple name!");
198
199          loop
200             exit when Token /= Tok_Dot;
201             Scan; -- past dot
202             Discard_Junk_Node (P_Identifier);
203          end loop;
204       end if;
205
206       --  Attribute Definition Clause
207
208       if Token = Tok_Apostrophe then
209
210          --  Allow local names of the form a'b'.... This enables
211          --  us to parse class-wide streams attributes correctly.
212
213          Name_Node := Identifier_Node;
214          while Token = Tok_Apostrophe loop
215
216             Scan; -- past apostrophe
217
218             Identifier_Node := Token_Node;
219             Attr_Name := No_Name;
220
221             if Token = Tok_Identifier then
222                Attr_Name := Token_Name;
223
224                if not Is_Attribute_Name (Attr_Name) then
225                   Signal_Bad_Attribute;
226                end if;
227
228                if Style_Check then
229                   Style.Check_Attribute_Name (False);
230                end if;
231
232             --  Here for case of attribute designator is not an identifier
233
234             else
235                if Token = Tok_Delta then
236                   Attr_Name := Name_Delta;
237
238                elsif Token = Tok_Digits then
239                   Attr_Name := Name_Digits;
240
241                elsif Token = Tok_Access then
242                   Attr_Name := Name_Access;
243
244                else
245                   Error_Msg_AP ("attribute designator expected");
246                   raise Error_Resync;
247                end if;
248
249                if Style_Check then
250                   Style.Check_Attribute_Name (True);
251                end if;
252             end if;
253
254             --  We come here with an OK attribute scanned, and the
255             --  corresponding Attribute identifier node stored in Ident_Node.
256
257             Prefix_Node := Name_Node;
258             Name_Node := New_Node (N_Attribute_Reference, Prev_Token_Ptr);
259             Set_Prefix (Name_Node, Prefix_Node);
260             Set_Attribute_Name (Name_Node, Attr_Name);
261             Scan;
262          end loop;
263
264          Rep_Clause_Node := New_Node (N_Attribute_Definition_Clause, For_Loc);
265          Set_Name (Rep_Clause_Node, Prefix_Node);
266          Set_Chars (Rep_Clause_Node, Attr_Name);
267          T_Use;
268
269          Expr_Node := P_Expression_No_Right_Paren;
270          Check_Simple_Expression_In_Ada_83 (Expr_Node);
271          Set_Expression (Rep_Clause_Node, Expr_Node);
272
273       else
274          TF_Use;
275          Rep_Clause_Node := Empty;
276
277          --  AT follows USE (At Clause)
278
279          if Token = Tok_At then
280             Scan; -- past AT
281             Rep_Clause_Node := New_Node (N_At_Clause, For_Loc);
282             Set_Identifier (Rep_Clause_Node, Identifier_Node);
283             Expr_Node := P_Expression_No_Right_Paren;
284             Check_Simple_Expression_In_Ada_83 (Expr_Node);
285             Set_Expression (Rep_Clause_Node, Expr_Node);
286
287          --  RECORD follows USE (Record Representation Clause)
288
289          elsif Token = Tok_Record then
290             Record_Items := P_Pragmas_Opt;
291             Rep_Clause_Node :=
292               New_Node (N_Record_Representation_Clause, For_Loc);
293             Set_Identifier (Rep_Clause_Node, Identifier_Node);
294
295             Push_Scope_Stack;
296             Scope.Table (Scope.Last).Etyp := E_Record;
297             Scope.Table (Scope.Last).Ecol := Start_Column;
298             Scope.Table (Scope.Last).Sloc := Token_Ptr;
299             Scan; -- past RECORD
300             Record_Items := P_Pragmas_Opt;
301
302             --  Possible Mod Clause
303
304             if Token = Tok_At then
305                Set_Mod_Clause (Rep_Clause_Node, P_Mod_Clause);
306                Set_Pragmas_Before (Mod_Clause (Rep_Clause_Node), Record_Items);
307                Record_Items := P_Pragmas_Opt;
308             end if;
309
310             if No (Record_Items) then
311                Record_Items := New_List;
312             end if;
313
314             Set_Component_Clauses (Rep_Clause_Node, Record_Items);
315
316             --  Loop through component clauses
317
318             loop
319                if Token not in Token_Class_Name then
320                   exit when Check_End;
321                end if;
322
323                Append (P_Component_Clause, Record_Items);
324                P_Pragmas_Opt (Record_Items);
325             end loop;
326
327          --  Left paren follows USE (Enumeration Representation Clause)
328
329          elsif Token = Tok_Left_Paren then
330             Rep_Clause_Node :=
331               New_Node (N_Enumeration_Representation_Clause, For_Loc);
332             Set_Identifier (Rep_Clause_Node, Identifier_Node);
333             Set_Array_Aggregate (Rep_Clause_Node, P_Aggregate);
334
335          --  Some other token follows FOR (invalid representation clause)
336
337          else
338             Error_Msg_SC ("invalid representation clause");
339             raise Error_Resync;
340          end if;
341       end if;
342
343       TF_Semicolon;
344       return Rep_Clause_Node;
345
346    exception
347       when Error_Resync =>
348          Resync_Past_Semicolon;
349          return Error;
350
351    end P_Representation_Clause;
352
353    ----------------------
354    -- 13.1  Local Name --
355    ----------------------
356
357    --  Local name is always parsed by its parent. In the case of its use in
358    --  pragmas, the check for a local name is handled in Par.Prag and allows
359    --  all the possible forms of local name. For the uses in chapter 13, we
360    --  currently only allow a direct name, but this should probably change???
361
362    ---------------------------
363    -- 13.1  At Clause (I.7) --
364    ---------------------------
365
366    --  Parsed by P_Representation_Clause (13.1)
367
368    ---------------------------------------
369    -- 13.3  Attribute Definition Clause --
370    ---------------------------------------
371
372    --  Parsed by P_Representation_Clause (13.1)
373
374    --------------------------------
375    -- 13.1  Aspect Specification --
376    --------------------------------
377
378    --  ASPECT_SPECIFICATION ::=
379    --    with ASPECT_MARK [=> ASPECT_DEFINITION] {,
380    --         ASPECT_MARK [=> ASPECT_DEFINITION] }
381
382    --  ASPECT_MARK ::= aspect_IDENTIFIER['Class]
383
384    --  ASPECT_DEFINITION ::= NAME | EXPRESSION
385
386    --  Error recovery: cannot raise Error_Resync
387
388    procedure P_Aspect_Specifications
389      (Decl      : Node_Id;
390       Semicolon : Boolean := True)
391    is
392       Aspects : List_Id;
393       Aspect  : Node_Id;
394       A_Id    : Aspect_Id;
395       OK      : Boolean;
396       Ptr     : Source_Ptr;
397
398    begin
399       --  Check if aspect specification present
400
401       if not Aspect_Specifications_Present then
402          if Semicolon then
403             TF_Semicolon;
404          end if;
405
406          return;
407       end if;
408
409       --  Aspect Specification is present
410
411       Ptr := Token_Ptr;
412       Scan; -- past WITH
413
414       --  Here we have an aspect specification to scan, note that we don't
415       --  set the flag till later, because it may turn out that we have no
416       --  valid aspects in the list.
417
418       Aspects := Empty_List;
419       loop
420          OK := True;
421
422          if Token /= Tok_Identifier then
423             Error_Msg_SC ("aspect identifier expected");
424
425             if Semicolon then
426                Resync_Past_Semicolon;
427             end if;
428
429             return;
430          end if;
431
432          --  We have an identifier (which should be an aspect identifier)
433
434          A_Id := Get_Aspect_Id (Token_Name);
435          Aspect :=
436            Make_Aspect_Specification (Token_Ptr,
437              Identifier => Token_Node);
438
439          --  No valid aspect identifier present
440
441          if A_Id = No_Aspect then
442             Error_Msg_SC ("aspect identifier expected");
443
444             --  Check bad spelling
445
446             for J in Aspect_Id loop
447                if Is_Bad_Spelling_Of (Token_Name, Aspect_Names (J)) then
448                   Error_Msg_Name_1 := Aspect_Names (J);
449                   Error_Msg_SC -- CODEFIX
450                     ("\possible misspelling of%");
451                   exit;
452                end if;
453             end loop;
454
455             Scan; -- past incorrect identifier
456
457             if Token = Tok_Apostrophe then
458                Scan; -- past '
459                Scan; -- past presumably CLASS
460             end if;
461
462             if Token = Tok_Arrow then
463                Scan; -- Past arrow
464                Set_Expression (Aspect, P_Expression);
465                OK := False;
466
467             elsif Token = Tok_Comma then
468                OK := False;
469
470             else
471                if Semicolon then
472                   Resync_Past_Semicolon;
473                end if;
474
475                return;
476             end if;
477
478          --  OK aspect scanned
479
480          else
481             Scan; -- past identifier
482
483             --  Check for 'Class present
484
485             if Token = Tok_Apostrophe then
486                if not Class_Aspect_OK (A_Id) then
487                   Error_Msg_Node_1 := Identifier (Aspect);
488                   Error_Msg_SC ("aspect& does not permit attribute here");
489                   Scan; -- past apostrophe
490                   Scan; -- past presumed CLASS
491                   OK := False;
492
493                else
494                   Scan; -- past apostrophe
495
496                   if Token /= Tok_Identifier
497                     or else Token_Name /= Name_Class
498                   then
499                      Error_Msg_SC ("Class attribute expected here");
500                      OK := False;
501
502                      if Token = Tok_Identifier then
503                         Scan; -- past identifier not CLASS
504                      end if;
505
506                   else
507                      Scan; -- past CLASS
508                      Set_Class_Present (Aspect);
509                   end if;
510                end if;
511             end if;
512
513             --  Test case of missing aspect definition
514
515             if Token = Tok_Comma
516               or else Token = Tok_Semicolon
517             then
518                if Aspect_Argument (A_Id) /= Optional then
519                   Error_Msg_Node_1 := Identifier (Aspect);
520                   Error_Msg_AP ("aspect& requires an aspect definition");
521                   OK := False;
522                end if;
523
524             elsif not Semicolon and then Token /= Tok_Arrow then
525                if Aspect_Argument (A_Id) /= Optional then
526
527                   --  The name or expression may be there, but the arrow is
528                   --  missing. Skip to the end of the declaration.
529
530                   T_Arrow;
531                   Resync_To_Semicolon;
532                end if;
533
534             --  Here we have an aspect definition
535
536             else
537                if Token = Tok_Arrow then
538                   Scan; -- past arrow
539                else
540                   T_Arrow;
541                   OK := False;
542                end if;
543
544                if Aspect_Argument (A_Id) = Name then
545                   Set_Expression (Aspect, P_Name);
546                else
547                   Set_Expression (Aspect, P_Expression);
548                end if;
549             end if;
550
551             --  If OK clause scanned, add it to the list
552
553             if OK then
554                Append (Aspect, Aspects);
555             end if;
556
557             if Token = Tok_Comma then
558                Scan; -- past comma
559                goto Continue;
560
561             --  Recognize the case where a comma is missing between two
562             --  aspects, issue an error and proceed with next aspect.
563
564             elsif Token = Tok_Identifier
565               and then Get_Aspect_Id (Token_Name) /= No_Aspect
566             then
567                declare
568                   Scan_State : Saved_Scan_State;
569
570                begin
571                   Save_Scan_State (Scan_State);
572                   Scan; -- past identifier
573
574                   if Token = Tok_Arrow then
575                      Restore_Scan_State (Scan_State);
576                      Error_Msg_AP -- CODEFIX
577                        ("|missing "",""");
578                      goto Continue;
579
580                   else
581                      Restore_Scan_State (Scan_State);
582                   end if;
583                end;
584
585             --  Recognize the case where a semicolon was mistyped for a comma
586             --  between two aspects, issue an error and proceed with next
587             --  aspect.
588
589             elsif Token = Tok_Semicolon then
590                declare
591                   Scan_State : Saved_Scan_State;
592
593                begin
594                   Save_Scan_State (Scan_State);
595                   Scan; -- past semicolon
596
597                   if Token = Tok_Identifier
598                     and then Get_Aspect_Id (Token_Name) /= No_Aspect
599                   then
600                      Scan; -- past identifier
601
602                      if Token = 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
609                      else
610                         Restore_Scan_State (Scan_State);
611                      end if;
612
613                   else
614                      Restore_Scan_State (Scan_State);
615                   end if;
616                end;
617             end if;
618
619             --  Must be terminator character
620
621             if Semicolon then
622                T_Semicolon;
623             end if;
624
625             exit;
626
627          <<Continue>>
628             null;
629          end if;
630       end loop;
631
632       --  Here if aspects present
633
634       if Is_Non_Empty_List (Aspects) then
635
636          --  If Decl is Empty, we just ignore the aspects (the caller in this
637          --  case has always issued an appropriate error message).
638
639          if Decl = Empty then
640             null;
641
642          --  If Decl is Error, we ignore the aspects, and issue a message
643
644          elsif Decl = Error then
645             Error_Msg ("aspect specifications not allowed here", Ptr);
646
647          --  Here aspects are allowed, and we store them
648
649          else
650             Set_Parent (Aspects, Decl);
651             Set_Aspect_Specifications (Decl, Aspects);
652          end if;
653       end if;
654    end P_Aspect_Specifications;
655
656    ---------------------------------------------
657    -- 13.4  Enumeration Representation Clause --
658    ---------------------------------------------
659
660    --  Parsed by P_Representation_Clause (13.1)
661
662    ---------------------------------
663    -- 13.4  Enumeration Aggregate --
664    ---------------------------------
665
666    --  Parsed by P_Representation_Clause (13.1)
667
668    ------------------------------------------
669    -- 13.5.1  Record Representation Clause --
670    ------------------------------------------
671
672    --  Parsed by P_Representation_Clause (13.1)
673
674    ------------------------------
675    -- 13.5.1  Mod Clause (I.8) --
676    ------------------------------
677
678    --  MOD_CLAUSE ::= at mod static_EXPRESSION;
679
680    --  Note: in Ada 83, the expression must be a simple expression
681
682    --  The caller has checked that the initial Token is AT
683
684    --  Error recovery: cannot raise Error_Resync
685
686    --  Note: the caller is responsible for setting the Pragmas_Before field
687
688    function P_Mod_Clause return Node_Id is
689       Mod_Node  : Node_Id;
690       Expr_Node : Node_Id;
691
692    begin
693       Mod_Node := New_Node (N_Mod_Clause, Token_Ptr);
694       Scan; -- past AT
695       T_Mod;
696       Expr_Node := P_Expression_No_Right_Paren;
697       Check_Simple_Expression_In_Ada_83 (Expr_Node);
698       Set_Expression (Mod_Node, Expr_Node);
699       TF_Semicolon;
700       return Mod_Node;
701    end P_Mod_Clause;
702
703    ------------------------------
704    -- 13.5.1  Component Clause --
705    ------------------------------
706
707    --  COMPONENT_CLAUSE ::=
708    --    COMPONENT_CLAUSE_COMPONENT_NAME at POSITION
709    --      range FIRST_BIT .. LAST_BIT;
710
711    --  COMPONENT_CLAUSE_COMPONENT_NAME ::=
712    --    component_DIRECT_NAME
713    --  | component_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
714    --  | FIRST_SUBTYPE_DIRECT_NAME'ATTRIBUTE_DESIGNATOR
715
716    --  POSITION ::= static_EXPRESSION
717
718    --  Note: in Ada 83, the expression must be a simple expression
719
720    --  FIRST_BIT ::= static_SIMPLE_EXPRESSION
721    --  LAST_BIT ::= static_SIMPLE_EXPRESSION
722
723    --  Note: the AARM V2.0 grammar has an error at this point, it uses
724    --  EXPRESSION instead of SIMPLE_EXPRESSION for FIRST_BIT and LAST_BIT
725
726    --  Error recovery: cannot raise Error_Resync
727
728    function P_Component_Clause return Node_Id is
729       Component_Node : Node_Id;
730       Comp_Name      : Node_Id;
731       Expr_Node      : Node_Id;
732
733    begin
734       Component_Node := New_Node (N_Component_Clause, Token_Ptr);
735       Comp_Name := P_Name;
736
737       if Nkind (Comp_Name) = N_Identifier
738         or else Nkind (Comp_Name) = N_Attribute_Reference
739       then
740          Set_Component_Name (Component_Node, Comp_Name);
741       else
742          Error_Msg_N
743            ("component name must be direct name or attribute", Comp_Name);
744          Set_Component_Name (Component_Node, Error);
745       end if;
746
747       Set_Sloc (Component_Node, Token_Ptr);
748       T_At;
749       Expr_Node := P_Expression_No_Right_Paren;
750       Check_Simple_Expression_In_Ada_83 (Expr_Node);
751       Set_Position (Component_Node, Expr_Node);
752       T_Range;
753       Expr_Node := P_Expression_No_Right_Paren;
754       Check_Simple_Expression_In_Ada_83 (Expr_Node);
755       Set_First_Bit (Component_Node, Expr_Node);
756       T_Dot_Dot;
757       Expr_Node := P_Expression_No_Right_Paren;
758       Check_Simple_Expression_In_Ada_83 (Expr_Node);
759       Set_Last_Bit (Component_Node, Expr_Node);
760       TF_Semicolon;
761       return Component_Node;
762    end P_Component_Clause;
763
764    ----------------------
765    -- 13.5.1  Position --
766    ----------------------
767
768    --  Parsed by P_Component_Clause (13.5.1)
769
770    -----------------------
771    -- 13.5.1  First Bit --
772    -----------------------
773
774    --  Parsed by P_Component_Clause (13.5.1)
775
776    ----------------------
777    -- 13.5.1  Last Bit --
778    ----------------------
779
780    --  Parsed by P_Component_Clause (13.5.1)
781
782    --------------------------
783    -- 13.8  Code Statement --
784    --------------------------
785
786    --  CODE_STATEMENT ::= QUALIFIED_EXPRESSION
787
788    --  On entry the caller has scanned the SUBTYPE_MARK (passed in as the
789    --  single argument, and the scan points to the apostrophe.
790
791    --  Error recovery: can raise Error_Resync
792
793    function P_Code_Statement (Subtype_Mark : Node_Id) return Node_Id is
794       Node1 : Node_Id;
795
796    begin
797       Scan; -- past apostrophe
798
799       --  If left paren, then we have a possible code statement
800
801       if Token = Tok_Left_Paren then
802          Node1 := New_Node (N_Code_Statement, Sloc (Subtype_Mark));
803          Set_Expression (Node1, P_Qualified_Expression (Subtype_Mark));
804          TF_Semicolon;
805          return Node1;
806
807       --  Otherwise we have an illegal range attribute. Note that P_Name
808       --  ensures that Token = Tok_Range is the only possibility left here.
809
810       else -- Token = Tok_Range
811          Error_Msg_SC ("RANGE attribute illegal here!");
812          raise Error_Resync;
813       end if;
814
815    end P_Code_Statement;
816
817 end Ch13;