1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 pragma Style_Checks (All_Checks);
27 -- Turn off subprogram body ordering check. Subprograms are in order
28 -- by RM section rather than alphabetical
30 with Sinfo.CN; use Sinfo.CN;
35 -- Local subprograms, used only in this chapter
37 function P_Defining_Designator return Node_Id;
38 function P_Defining_Operator_Symbol return Node_Id;
39 function P_Return_Object_Declaration return Node_Id;
41 procedure P_Return_Subtype_Indication (Decl_Node : Node_Id);
42 -- Decl_Node is a N_Object_Declaration.
43 -- Set the Null_Exclusion_Present and Object_Definition fields of
46 procedure Check_Junk_Semicolon_Before_Return;
48 -- Check for common error of junk semicolon before RETURN keyword of
49 -- function specification. If present, skip over it with appropriate
50 -- error message, leaving Scan_Ptr pointing to the RETURN after. This
51 -- routine also deals with a possibly misspelled version of Return.
53 ----------------------------------------
54 -- Check_Junk_Semicolon_Before_Return --
55 ----------------------------------------
57 procedure Check_Junk_Semicolon_Before_Return is
58 Scan_State : Saved_Scan_State;
61 if Token = Tok_Semicolon then
62 Save_Scan_State (Scan_State);
63 Scan; -- past the semicolon
65 if Token = Tok_Return then
66 Restore_Scan_State (Scan_State);
67 Error_Msg_SC -- CODEFIX
68 ("|extra "";"" ignored");
69 Scan; -- rescan past junk semicolon
71 Restore_Scan_State (Scan_State);
74 elsif Bad_Spelling_Of (Tok_Return) then
77 end Check_Junk_Semicolon_Before_Return;
79 -----------------------------------------------------
80 -- 6.1 Subprogram (Also 6.3, 8.5.4, 10.1.3, 12.3) --
81 -----------------------------------------------------
83 -- This routine scans out a subprogram declaration, subprogram body,
84 -- subprogram renaming declaration or subprogram generic instantiation.
85 -- It also handles the new Ada 2012 expression function form
87 -- SUBPROGRAM_DECLARATION ::=
88 -- SUBPROGRAM_SPECIFICATION
89 -- [ASPECT_SPECIFICATIONS];
91 -- ABSTRACT_SUBPROGRAM_DECLARATION ::=
92 -- SUBPROGRAM_SPECIFICATION is abstract
93 -- [ASPECT_SPECIFICATIONS];
95 -- SUBPROGRAM_SPECIFICATION ::=
96 -- procedure DEFINING_PROGRAM_UNIT_NAME PARAMETER_PROFILE
97 -- | function DEFINING_DESIGNATOR PARAMETER_AND_RESULT_PROFILE
99 -- PARAMETER_PROFILE ::= [FORMAL_PART]
101 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] return SUBTYPE_MARK
103 -- SUBPROGRAM_BODY ::=
104 -- SUBPROGRAM_SPECIFICATION is
107 -- HANDLED_SEQUENCE_OF_STATEMENTS
110 -- SUBPROGRAM_RENAMING_DECLARATION ::=
111 -- SUBPROGRAM_SPECIFICATION renames callable_entity_NAME
112 -- [ASPECT_SPECIFICATIONS];
114 -- SUBPROGRAM_BODY_STUB ::=
115 -- SUBPROGRAM_SPECIFICATION is separate;
117 -- GENERIC_INSTANTIATION ::=
118 -- procedure DEFINING_PROGRAM_UNIT_NAME is
119 -- new generic_procedure_NAME [GENERIC_ACTUAL_PART];
120 -- | function DEFINING_DESIGNATOR is
121 -- new generic_function_NAME [GENERIC_ACTUAL_PART];
123 -- NULL_PROCEDURE_DECLARATION ::=
124 -- SUBPROGRAM_SPECIFICATION is null;
126 -- Null procedures are an Ada 2005 feature. A null procedure declaration
127 -- is classified as a basic declarative item, but it is parsed here, with
128 -- other subprogram constructs.
130 -- EXPRESSION_FUNCTION ::=
131 -- FUNCTION SPECIFICATION IS (EXPRESSION);
133 -- The value in Pf_Flags indicates which of these possible declarations
134 -- is acceptable to the caller:
136 -- Pf_Flags.Decl Set if declaration OK
137 -- Pf_Flags.Gins Set if generic instantiation OK
138 -- Pf_Flags.Pbod Set if proper body OK
139 -- Pf_Flags.Rnam Set if renaming declaration OK
140 -- Pf_Flags.Stub Set if body stub OK
141 -- Pf_Flags.Pexp Set if expression function OK
143 -- If an inappropriate form is encountered, it is scanned out but an
144 -- error message indicating that it is appearing in an inappropriate
145 -- context is issued. The only possible values for Pf_Flags are those
146 -- defined as constants in the Par package.
148 -- The caller has checked that the initial token is FUNCTION, PROCEDURE,
149 -- NOT or OVERRIDING.
151 -- Error recovery: cannot raise Error_Resync
153 function P_Subprogram (Pf_Flags : Pf_Rec) return Node_Id is
154 Specification_Node : Node_Id;
156 Fpart_List : List_Id;
157 Fpart_Sloc : Source_Ptr;
158 Result_Not_Null : Boolean := False;
159 Result_Node : Node_Id;
163 Rename_Node : Node_Id;
164 Absdec_Node : Node_Id;
166 Fproc_Sloc : Source_Ptr;
168 Scan_State : Saved_Scan_State;
170 -- Flags for optional overriding indication. Two flags are needed,
171 -- to distinguish positive and negative overriding indicators from
172 -- the absence of any indicator.
174 Is_Overriding : Boolean := False;
175 Not_Overriding : Boolean := False;
178 -- Set up scope stack entry. Note that the Labl field will be set later
180 SIS_Entry_Active := False;
181 SIS_Missing_Semicolon_Message := No_Error_Msg;
183 Scope.Table (Scope.Last).Sloc := Token_Ptr;
184 Scope.Table (Scope.Last).Etyp := E_Name;
185 Scope.Table (Scope.Last).Ecol := Start_Column;
186 Scope.Table (Scope.Last).Lreq := False;
188 -- Ada 2005: Scan leading NOT OVERRIDING indicator
190 if Token = Tok_Not then
193 if Token = Tok_Overriding then
194 Scan; -- past OVERRIDING
195 Not_Overriding := True;
197 -- Overriding keyword used in non Ada 2005 mode
199 elsif Token = Tok_Identifier
200 and then Token_Name = Name_Overriding
202 Error_Msg_SC ("overriding indicator is an Ada 2005 extension");
203 Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
204 Scan; -- past Overriding
205 Not_Overriding := True;
208 Error_Msg_SC -- CODEFIX
209 ("OVERRIDING expected!");
212 -- Ada 2005: scan leading OVERRIDING indicator
214 -- Note: in the case of OVERRIDING keyword used in Ada 95 mode, the
215 -- declaration circuit already gave an error message and changed the
216 -- token to Tok_Overriding.
218 elsif Token = Tok_Overriding then
219 Scan; -- past OVERRIDING
220 Is_Overriding := True;
223 if Is_Overriding or else Not_Overriding then
225 -- Note that if we are not in Ada_2005 mode, error messages have
226 -- already been given, so no need to give another message here.
228 -- An overriding indicator is allowed for subprogram declarations,
229 -- bodies (including subunits), renamings, stubs, and instantiations.
230 -- The test against Pf_Decl_Pbod is added to account for the case of
231 -- subprograms declared in a protected type, where only subprogram
232 -- declarations and bodies can occur. The Pf_Pbod case is for
235 if Pf_Flags /= Pf_Decl_Gins_Pbod_Rnam_Stub_Pexp
237 Pf_Flags /= Pf_Decl_Pbod_Pexp
239 Pf_Flags /= Pf_Pbod_Pexp
241 Error_Msg_SC ("overriding indicator not allowed here!");
243 elsif Token /= Tok_Function and then Token /= Tok_Procedure then
244 Error_Msg_SC -- CODEFIX
245 ("FUNCTION or PROCEDURE expected!");
249 Func := (Token = Tok_Function);
250 Fproc_Sloc := Token_Ptr;
251 Scan; -- past FUNCTION or PROCEDURE
256 Name_Node := P_Defining_Designator;
258 if Nkind (Name_Node) = N_Defining_Operator_Symbol
259 and then Scope.Last = 1
261 Error_Msg_SP ("operator symbol not allowed at library level");
262 Name_Node := New_Entity (N_Defining_Identifier, Sloc (Name_Node));
264 -- Set name from file name, we need some junk name, and that's
265 -- as good as anything. This is only approximate, since we do
266 -- not do anything with non-standard name translations.
268 Get_Name_String (File_Name (Current_Source_File));
270 for J in 1 .. Name_Len loop
271 if Name_Buffer (J) = '.' then
277 Set_Chars (Name_Node, Name_Find);
278 Set_Error_Posted (Name_Node);
282 Name_Node := P_Defining_Program_Unit_Name;
285 Scope.Table (Scope.Last).Labl := Name_Node;
288 -- Deal with generic instantiation, the one case in which we do not
289 -- have a subprogram specification as part of whatever we are parsing
291 if Token = Tok_Is then
292 Save_Scan_State (Scan_State); -- at the IS
293 T_Is; -- checks for redundant IS
295 if Token = Tok_New then
296 if not Pf_Flags.Gins then
297 Error_Msg_SC ("generic instantiation not allowed here!");
303 Inst_Node := New_Node (N_Function_Instantiation, Fproc_Sloc);
304 Set_Name (Inst_Node, P_Function_Name);
306 Inst_Node := New_Node (N_Procedure_Instantiation, Fproc_Sloc);
307 Set_Name (Inst_Node, P_Qualified_Simple_Name);
310 Set_Defining_Unit_Name (Inst_Node, Name_Node);
311 Set_Generic_Associations (Inst_Node, P_Generic_Actual_Part_Opt);
312 P_Aspect_Specifications (Inst_Node);
313 Pop_Scope_Stack; -- Don't need scope stack entry in this case
315 if Is_Overriding then
316 Set_Must_Override (Inst_Node);
318 elsif Not_Overriding then
319 Set_Must_Not_Override (Inst_Node);
325 Restore_Scan_State (Scan_State); -- to the IS
329 -- If not a generic instantiation, then we definitely have a subprogram
330 -- specification (all possibilities at this stage include one here)
332 Fpart_Sloc := Token_Ptr;
334 Check_Misspelling_Of (Tok_Return);
336 -- Scan formal part. First a special error check. If we have an
337 -- identifier here, then we have a definite error. If this identifier
338 -- is on the same line as the designator, then we assume it is the
339 -- first formal after a missing left parenthesis
341 if Token = Tok_Identifier
342 and then not Token_Is_At_Start_Of_Line
344 T_Left_Paren; -- to generate message
345 Fpart_List := P_Formal_Part;
347 -- Otherwise scan out an optional formal part in the usual manner
350 Fpart_List := P_Parameter_Profile;
353 -- We treat what we have as a function specification if FUNCTION was
354 -- used, or if a RETURN is present. This gives better error recovery
355 -- since later RETURN statements will be valid in either case.
357 Check_Junk_Semicolon_Before_Return;
358 Result_Node := Error;
360 if Token = Tok_Return then
363 ("PROCEDURE should be FUNCTION", Fproc_Sloc);
369 Result_Not_Null := P_Null_Exclusion; -- Ada 2005 (AI-231)
371 -- Ada 2005 (AI-318-02)
373 if Token = Tok_Access then
374 if Ada_Version < Ada_2005 then
376 ("anonymous access result type is an Ada 2005 extension");
377 Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
380 Result_Node := P_Access_Definition (Result_Not_Null);
383 Result_Node := P_Subtype_Mark;
388 -- Skip extra parenthesis at end of formal part
390 Ignore (Tok_Right_Paren);
392 -- For function, scan result subtype
397 if Prev_Token = Tok_Return then
398 Result_Node := P_Subtype_Mark;
404 Specification_Node :=
405 New_Node (N_Function_Specification, Fproc_Sloc);
407 Set_Null_Exclusion_Present (Specification_Node, Result_Not_Null);
408 Set_Result_Definition (Specification_Node, Result_Node);
411 Specification_Node :=
412 New_Node (N_Procedure_Specification, Fproc_Sloc);
415 Set_Defining_Unit_Name (Specification_Node, Name_Node);
416 Set_Parameter_Specifications (Specification_Node, Fpart_List);
418 if Is_Overriding then
419 Set_Must_Override (Specification_Node);
421 elsif Not_Overriding then
422 Set_Must_Not_Override (Specification_Node);
425 -- Error check: barriers not allowed on protected functions/procedures
427 if Token = Tok_When then
429 Error_Msg_SC ("barrier not allowed on function, only on entry");
431 Error_Msg_SC ("barrier not allowed on procedure, only on entry");
435 Discard_Junk_Node (P_Expression);
438 -- Deal with semicolon followed by IS. We want to treat this as IS
440 if Token = Tok_Semicolon then
441 Save_Scan_State (Scan_State);
442 Scan; -- past semicolon
444 if Token = Tok_Is then
445 Error_Msg_SP -- CODEFIX
446 ("extra "";"" ignored");
448 Restore_Scan_State (Scan_State);
452 -- Subprogram declaration ended by aspect specifications
454 if Aspect_Specifications_Present then
455 goto Subprogram_Declaration;
457 -- Deal with case of semicolon ending a subprogram declaration
459 elsif Token = Tok_Semicolon then
460 if not Pf_Flags.Decl then
464 Save_Scan_State (Scan_State);
465 Scan; -- past semicolon
467 -- If semicolon is immediately followed by IS, then ignore the
468 -- semicolon, and go process the body.
470 if Token = Tok_Is then
471 Error_Msg_SP -- CODEFIX
472 ("|extra "";"" ignored");
473 T_Is; -- scan past IS
474 goto Subprogram_Body;
476 -- If BEGIN follows in an appropriate column, we immediately
477 -- commence the error action of assuming that the previous
478 -- subprogram declaration should have been a subprogram body,
479 -- i.e. that the terminating semicolon should have been IS.
481 elsif Token = Tok_Begin
482 and then Start_Column >= Scope.Table (Scope.Last).Ecol
484 Error_Msg_SP -- CODEFIX
485 ("|"";"" should be IS!");
486 goto Subprogram_Body;
489 Restore_Scan_State (Scan_State);
490 goto Subprogram_Declaration;
493 -- Case of not followed by semicolon
496 -- Subprogram renaming declaration case
498 Check_Misspelling_Of (Tok_Renames);
500 if Token = Tok_Renames then
501 if not Pf_Flags.Rnam then
502 Error_Msg_SC ("renaming declaration not allowed here!");
506 New_Node (N_Subprogram_Renaming_Declaration, Token_Ptr);
507 Scan; -- past RENAMES
508 Set_Name (Rename_Node, P_Name);
509 Set_Specification (Rename_Node, Specification_Node);
510 P_Aspect_Specifications (Rename_Node);
515 -- Case of IS following subprogram specification
517 elsif Token = Tok_Is then
518 T_Is; -- ignore redundant Is's
520 if Token_Name = Name_Abstract then
521 Check_95_Keyword (Tok_Abstract, Tok_Semicolon);
524 -- Deal nicely with (now obsolete) use of <> in place of abstract
526 if Token = Tok_Box then
527 Error_Msg_SC -- CODEFIX
528 ("ABSTRACT expected");
529 Token := Tok_Abstract;
532 -- Abstract subprogram declaration case
534 if Token = Tok_Abstract then
536 New_Node (N_Abstract_Subprogram_Declaration, Token_Ptr);
537 Set_Specification (Absdec_Node, Specification_Node);
538 Pop_Scope_Stack; -- discard unneeded entry
539 Scan; -- past ABSTRACT
540 P_Aspect_Specifications (Absdec_Node);
543 -- Ada 2005 (AI-248): Parse a null procedure declaration
545 elsif Token = Tok_Null then
546 if Ada_Version < Ada_2005 then
547 Error_Msg_SP ("null procedures are an Ada 2005 extension");
548 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
554 Error_Msg_SP ("only procedures can be null");
556 Set_Null_Present (Specification_Node);
559 goto Subprogram_Declaration;
561 -- Check for IS NEW with Formal_Part present and handle nicely
563 elsif Token = Tok_New then
565 ("formal part not allowed in instantiation", Fpart_Sloc);
569 Inst_Node := New_Node (N_Function_Instantiation, Fproc_Sloc);
572 New_Node (N_Procedure_Instantiation, Fproc_Sloc);
575 Set_Defining_Unit_Name (Inst_Node, Name_Node);
576 Set_Name (Inst_Node, P_Name);
577 Set_Generic_Associations (Inst_Node, P_Generic_Actual_Part_Opt);
579 Pop_Scope_Stack; -- Don't need scope stack entry in this case
583 goto Subprogram_Body;
586 -- Aspect specifications present
588 elsif Aspect_Specifications_Present then
589 goto Subprogram_Declaration;
591 -- Here we have a missing IS or missing semicolon, we always guess
592 -- a missing semicolon, since we are pretty good at fixing up a
593 -- semicolon which should really be an IS
596 Error_Msg_AP -- CODEFIX
598 SIS_Missing_Semicolon_Message := Get_Msg_Id;
599 goto Subprogram_Declaration;
603 -- Processing for stub or subprogram body or expression function
607 -- Subprogram body stub case
609 if Separate_Present then
610 if not Pf_Flags.Stub then
611 Error_Msg_SC ("body stub not allowed here!");
614 if Nkind (Name_Node) = N_Defining_Operator_Symbol then
616 ("operator symbol cannot be used as subunit name",
621 New_Node (N_Subprogram_Body_Stub, Sloc (Specification_Node));
622 Set_Specification (Stub_Node, Specification_Node);
623 Scan; -- past SEPARATE
628 -- Subprogram body or expression function case
631 Scan_Body_Or_Expression_Function : declare
633 Body_Is_Hidden_In_SPARK : Boolean;
634 Hidden_Region_Start : Source_Ptr;
636 function Likely_Expression_Function return Boolean;
637 -- Returns True if we have a probable case of an expression
638 -- function omitting the parentheses, if so, returns True
639 -- and emits an appropriate error message, else returns False.
641 --------------------------------
642 -- Likely_Expression_Function --
643 --------------------------------
645 function Likely_Expression_Function return Boolean is
647 -- If currently pointing to BEGIN or a declaration keyword
648 -- or a pragma, then we definitely have a subprogram body.
649 -- This is a common case, so worth testing first.
652 or else Token in Token_Class_Declk
653 or else Token = Tok_Pragma
657 -- Test for tokens which could only start an expression and
658 -- thus signal the case of a expression function.
660 elsif Token in Token_Class_Literal
661 or else Token in Token_Class_Unary_Addop
662 or else Token = Tok_Left_Paren
663 or else Token = Tok_Abs
664 or else Token = Tok_Null
665 or else Token = Tok_New
666 or else Token = Tok_Not
670 -- Anything other than an identifier must be a body
672 elsif Token /= Tok_Identifier then
675 -- Here for an identifier
678 -- If the identifier is the first token on its line, then
679 -- let's assume that we have a missing begin and this is
680 -- intended as a subprogram body. However, if the context
681 -- is a function and the unit is a package declaration, a
682 -- body would be illegal, so try for an unparenthesized
683 -- expression function.
685 if Token_Is_At_Start_Of_Line then
687 -- The enclosing scope entry is a subprogram spec
689 Spec_Node : constant Node_Id :=
691 (Scope.Table (Scope.Last).Labl);
692 Lib_Node : Node_Id := Spec_Node;
695 -- Check whether there is an enclosing scope that
696 -- is a package declaration.
698 if Scope.Last > 1 then
700 Parent (Scope.Table (Scope.Last - 1).Labl);
703 if Ada_Version >= Ada_2012
705 Nkind (Lib_Node) = N_Package_Specification
707 Nkind (Spec_Node) = N_Function_Specification
715 -- Otherwise we have to scan ahead. If the identifier is
716 -- followed by a colon or a comma, it is a declaration
717 -- and hence we have a subprogram body. Otherwise assume
718 -- a expression function.
722 Scan_State : Saved_Scan_State;
726 Save_Scan_State (Scan_State);
727 Scan; -- past identifier
729 Restore_Scan_State (Scan_State);
731 if Tok = Tok_Colon or else Tok = Tok_Comma then
738 -- Fall through if we have a likely expression function
741 ("expression function must be enclosed in parentheses");
743 end Likely_Expression_Function;
745 -- Start of processing for Scan_Body_Or_Expression_Function
748 -- Expression_Function case
750 if Token = Tok_Left_Paren
751 or else Likely_Expression_Function
753 -- Check expression function allowed here
755 if not Pf_Flags.Pexp then
756 Error_Msg_SC ("expression function not allowed here!");
759 -- Check we are in Ada 2012 mode
761 if Ada_Version < Ada_2012 then
763 ("expression function is an Ada 2012 feature!");
765 ("\unit must be compiled with -gnat2012 switch!");
768 -- Parse out expression and build expression function
772 (N_Expression_Function, Sloc (Specification_Node));
773 Set_Specification (Body_Node, Specification_Node);
774 Set_Expression (Body_Node, P_Expression);
778 -- Subprogram body case
781 -- Check body allowed here
783 if not Pf_Flags.Pbod then
784 Error_Msg_SP ("subprogram body not allowed here!");
787 -- Here is the test for a suspicious IS (i.e. one that
788 -- looks like it might more properly be a semicolon).
789 -- See separate section describing use of IS instead
790 -- of semicolon in package Parse.
792 if (Token in Token_Class_Declk
794 Token = Tok_Identifier)
795 and then Start_Column <= Scope.Table (Scope.Last).Ecol
796 and then Scope.Last /= 1
798 Scope.Table (Scope.Last).Etyp := E_Suspicious_Is;
799 Scope.Table (Scope.Last).S_Is := Prev_Token_Ptr;
802 -- Build and return subprogram body, parsing declarations
803 -- and statement sequence that belong to the body.
806 New_Node (N_Subprogram_Body, Sloc (Specification_Node));
807 Set_Specification (Body_Node, Specification_Node);
809 -- In SPARK, a HIDE directive can be placed at the beginning
810 -- of a subprogram implementation, thus hiding the
811 -- subprogram body from SPARK tool-set. No violation of the
812 -- SPARK restriction should be issued on nodes in a hidden
813 -- part, which is obtained by marking such hidden parts.
815 if Token = Tok_SPARK_Hide then
816 Body_Is_Hidden_In_SPARK := True;
817 Hidden_Region_Start := Token_Ptr;
818 Scan; -- past HIDE directive
820 Body_Is_Hidden_In_SPARK := False;
823 Parse_Decls_Begin_End (Body_Node);
825 if Body_Is_Hidden_In_SPARK then
826 Set_Hidden_Part_In_SPARK (Hidden_Region_Start, Token_Ptr);
831 end Scan_Body_Or_Expression_Function;
834 -- Processing for subprogram declaration
836 <<Subprogram_Declaration>>
838 New_Node (N_Subprogram_Declaration, Sloc (Specification_Node));
839 Set_Specification (Decl_Node, Specification_Node);
840 P_Aspect_Specifications (Decl_Node);
842 -- If this is a context in which a subprogram body is permitted,
843 -- set active SIS entry in case (see section titled "Handling
844 -- Semicolon Used in Place of IS" in body of Parser package)
845 -- Note that SIS_Missing_Semicolon_Message is already set properly.
847 if Pf_Flags.Pbod then
848 SIS_Labl := Scope.Table (Scope.Last).Labl;
849 SIS_Sloc := Scope.Table (Scope.Last).Sloc;
850 SIS_Ecol := Scope.Table (Scope.Last).Ecol;
851 SIS_Declaration_Node := Decl_Node;
852 SIS_Semicolon_Sloc := Prev_Token_Ptr;
853 SIS_Entry_Active := True;
860 ---------------------------------
861 -- 6.1 Subprogram Declaration --
862 ---------------------------------
864 -- Parsed by P_Subprogram (6.1)
866 ------------------------------------------
867 -- 6.1 Abstract Subprogram Declaration --
868 ------------------------------------------
870 -- Parsed by P_Subprogram (6.1)
872 -----------------------------------
873 -- 6.1 Subprogram Specification --
874 -----------------------------------
876 -- SUBPROGRAM_SPECIFICATION ::=
877 -- procedure DEFINING_PROGRAM_UNIT_NAME PARAMETER_PROFILE
878 -- | function DEFINING_DESIGNATOR PARAMETER_AND_RESULT_PROFILE
880 -- PARAMETER_PROFILE ::= [FORMAL_PART]
882 -- PARAMETER_AND_RESULT_PROFILE ::= [FORMAL_PART] return SUBTYPE_MARK
884 -- Subprogram specifications that appear in subprogram declarations
885 -- are parsed by P_Subprogram (6.1). This routine is used in other
886 -- contexts where subprogram specifications occur.
888 -- Note: this routine does not affect the scope stack in any way
890 -- Error recovery: can raise Error_Resync
892 function P_Subprogram_Specification return Node_Id is
893 Specification_Node : Node_Id;
894 Result_Not_Null : Boolean;
895 Result_Node : Node_Id;
898 if Token = Tok_Function then
899 Specification_Node := New_Node (N_Function_Specification, Token_Ptr);
900 Scan; -- past FUNCTION
902 Set_Defining_Unit_Name (Specification_Node, P_Defining_Designator);
903 Set_Parameter_Specifications
904 (Specification_Node, P_Parameter_Profile);
905 Check_Junk_Semicolon_Before_Return;
908 Result_Not_Null := P_Null_Exclusion; -- Ada 2005 (AI-231)
910 -- Ada 2005 (AI-318-02)
912 if Token = Tok_Access then
913 if Ada_Version < Ada_2005 then
915 ("anonymous access result type is an Ada 2005 extension");
916 Error_Msg_SC ("\unit must be compiled with -gnat05 switch");
919 Result_Node := P_Access_Definition (Result_Not_Null);
922 Result_Node := P_Subtype_Mark;
926 Set_Null_Exclusion_Present (Specification_Node, Result_Not_Null);
927 Set_Result_Definition (Specification_Node, Result_Node);
928 return Specification_Node;
930 elsif Token = Tok_Procedure then
931 Specification_Node := New_Node (N_Procedure_Specification, Token_Ptr);
932 Scan; -- past PROCEDURE
934 Set_Defining_Unit_Name
935 (Specification_Node, P_Defining_Program_Unit_Name);
936 Set_Parameter_Specifications
937 (Specification_Node, P_Parameter_Profile);
938 return Specification_Node;
941 Error_Msg_SC ("subprogram specification expected");
944 end P_Subprogram_Specification;
946 ---------------------
948 ---------------------
951 -- [PARENT_UNIT_NAME .] IDENTIFIER | OPERATOR_SYMBOL
953 -- The caller has checked that the initial token is an identifier,
954 -- operator symbol, or string literal. Note that we don't bother to
955 -- do much error diagnosis in this routine, since it is only used for
956 -- the label on END lines, and the routines in package Par.Endh will
957 -- check that the label is appropriate.
959 -- Error recovery: cannot raise Error_Resync
961 function P_Designator return Node_Id is
962 Ident_Node : Node_Id;
964 Prefix_Node : Node_Id;
966 function Real_Dot return Boolean;
967 -- Tests if a current token is an interesting period, i.e. is followed
968 -- by an identifier or operator symbol or string literal. If not, it is
969 -- probably just incorrect punctuation to be caught by our caller. Note
970 -- that the case of an operator symbol or string literal is also an
971 -- error, but that is an error that we catch here. If the result is
972 -- True, a real dot has been scanned and we are positioned past it,
973 -- if the result is False, the scan position is unchanged.
979 function Real_Dot return Boolean is
980 Scan_State : Saved_Scan_State;
983 if Token /= Tok_Dot then
987 Save_Scan_State (Scan_State);
990 if Token = Tok_Identifier
991 or else Token = Tok_Operator_Symbol
992 or else Token = Tok_String_Literal
997 Restore_Scan_State (Scan_State);
1003 -- Start of processing for P_Designator
1006 Ident_Node := Token_Node;
1007 Scan; -- past initial token
1009 if Prev_Token = Tok_Operator_Symbol
1010 or else Prev_Token = Tok_String_Literal
1011 or else not Real_Dot
1018 Prefix_Node := Ident_Node;
1020 -- Loop through child names, on entry to this loop, Prefix contains
1021 -- the name scanned so far, and Ident_Node is the last identifier.
1024 Name_Node := New_Node (N_Selected_Component, Prev_Token_Ptr);
1025 Set_Prefix (Name_Node, Prefix_Node);
1026 Ident_Node := P_Identifier;
1027 Set_Selector_Name (Name_Node, Ident_Node);
1028 Prefix_Node := Name_Node;
1029 exit when not Real_Dot;
1032 -- On exit from the loop, Ident_Node is the last identifier scanned,
1033 -- i.e. the defining identifier, and Prefix_Node is a node for the
1034 -- entire name, structured (incorrectly!) as a selected component.
1036 Name_Node := Prefix (Prefix_Node);
1037 Change_Node (Prefix_Node, N_Designator);
1038 Set_Name (Prefix_Node, Name_Node);
1039 Set_Identifier (Prefix_Node, Ident_Node);
1044 when Error_Resync =>
1045 while Token = Tok_Dot or else Token = Tok_Identifier loop
1052 ------------------------------
1053 -- 6.1 Defining Designator --
1054 ------------------------------
1056 -- DEFINING_DESIGNATOR ::=
1057 -- DEFINING_PROGRAM_UNIT_NAME | DEFINING_OPERATOR_SYMBOL
1059 -- Error recovery: cannot raise Error_Resync
1061 function P_Defining_Designator return Node_Id is
1063 if Token = Tok_Operator_Symbol then
1064 return P_Defining_Operator_Symbol;
1066 elsif Token = Tok_String_Literal then
1067 Error_Msg_SC ("invalid operator name");
1068 Scan; -- past junk string
1072 return P_Defining_Program_Unit_Name;
1074 end P_Defining_Designator;
1076 -------------------------------------
1077 -- 6.1 Defining Program Unit Name --
1078 -------------------------------------
1080 -- DEFINING_PROGRAM_UNIT_NAME ::=
1081 -- [PARENT_UNIT_NAME .] DEFINING_IDENTIFIER
1083 -- Note: PARENT_UNIT_NAME may be present only in 95 mode at the outer level
1085 -- Error recovery: cannot raise Error_Resync
1087 function P_Defining_Program_Unit_Name return Node_Id is
1088 Ident_Node : Node_Id;
1089 Name_Node : Node_Id;
1090 Prefix_Node : Node_Id;
1093 -- Set identifier casing if not already set and scan initial identifier
1095 if Token = Tok_Identifier
1096 and then Identifier_Casing (Current_Source_File) = Unknown
1098 Set_Identifier_Casing (Current_Source_File, Determine_Token_Casing);
1101 Ident_Node := P_Identifier (C_Dot);
1102 Merge_Identifier (Ident_Node, Tok_Return);
1104 -- Normal case (not child library unit name)
1106 if Token /= Tok_Dot then
1107 Change_Identifier_To_Defining_Identifier (Ident_Node);
1110 -- Child library unit name case
1113 if Scope.Last > 1 then
1114 Error_Msg_SP ("child unit allowed only at library level");
1117 elsif Ada_Version = Ada_83 then
1118 Error_Msg_SP ("(Ada 83) child unit not allowed!");
1122 Prefix_Node := Ident_Node;
1124 -- Loop through child names, on entry to this loop, Prefix contains
1125 -- the name scanned so far, and Ident_Node is the last identifier.
1128 exit when Token /= Tok_Dot;
1129 Name_Node := New_Node (N_Selected_Component, Token_Ptr);
1130 Scan; -- past period
1131 Set_Prefix (Name_Node, Prefix_Node);
1132 Ident_Node := P_Identifier (C_Dot);
1133 Set_Selector_Name (Name_Node, Ident_Node);
1134 Prefix_Node := Name_Node;
1137 -- On exit from the loop, Ident_Node is the last identifier scanned,
1138 -- i.e. the defining identifier, and Prefix_Node is a node for the
1139 -- entire name, structured (incorrectly!) as a selected component.
1141 Name_Node := Prefix (Prefix_Node);
1142 Change_Node (Prefix_Node, N_Defining_Program_Unit_Name);
1143 Set_Name (Prefix_Node, Name_Node);
1144 Change_Identifier_To_Defining_Identifier (Ident_Node);
1145 Set_Defining_Identifier (Prefix_Node, Ident_Node);
1147 -- All set with unit name parsed
1153 when Error_Resync =>
1154 while Token = Tok_Dot or else Token = Tok_Identifier loop
1159 end P_Defining_Program_Unit_Name;
1161 --------------------------
1162 -- 6.1 Operator Symbol --
1163 --------------------------
1165 -- OPERATOR_SYMBOL ::= STRING_LITERAL
1167 -- Operator symbol is returned by the scanner as Tok_Operator_Symbol
1169 -----------------------------------
1170 -- 6.1 Defining Operator Symbol --
1171 -----------------------------------
1173 -- DEFINING_OPERATOR_SYMBOL ::= OPERATOR_SYMBOL
1175 -- The caller has checked that the initial symbol is an operator symbol
1177 function P_Defining_Operator_Symbol return Node_Id is
1181 Op_Node := Token_Node;
1182 Change_Operator_Symbol_To_Defining_Operator_Symbol (Op_Node);
1183 Scan; -- past operator symbol
1185 end P_Defining_Operator_Symbol;
1187 ----------------------------
1188 -- 6.1 Parameter_Profile --
1189 ----------------------------
1191 -- PARAMETER_PROFILE ::= [FORMAL_PART]
1193 -- Empty is returned if no formal part is present
1195 -- Error recovery: cannot raise Error_Resync
1197 function P_Parameter_Profile return List_Id is
1199 if Token = Tok_Left_Paren then
1200 Scan; -- part left paren
1201 return P_Formal_Part;
1205 end P_Parameter_Profile;
1207 ---------------------------------------
1208 -- 6.1 Parameter And Result Profile --
1209 ---------------------------------------
1211 -- Parsed by its parent construct, which uses P_Parameter_Profile to
1212 -- parse the parameters, and P_Subtype_Mark to parse the return type.
1214 ----------------------
1215 -- 6.1 Formal part --
1216 ----------------------
1218 -- FORMAL_PART ::= (PARAMETER_SPECIFICATION {; PARAMETER_SPECIFICATION})
1220 -- PARAMETER_SPECIFICATION ::=
1221 -- DEFINING_IDENTIFIER_LIST : [ALIASED] MODE [NULL_EXCLUSION]
1222 -- SUBTYPE_MARK [:= DEFAULT_EXPRESSION]
1223 -- | DEFINING_IDENTIFIER_LIST : ACCESS_DEFINITION
1224 -- [:= DEFAULT_EXPRESSION]
1226 -- This scans the construct Formal_Part. The caller has already checked
1227 -- that the initial token is a left parenthesis, and skipped past it, so
1228 -- that on entry Token is the first token following the left parenthesis.
1230 -- Note: The ALIASED keyword is allowed only in Ada 2012 mode (AI 142)
1232 -- Error recovery: cannot raise Error_Resync
1234 function P_Formal_Part return List_Id is
1235 Specification_List : List_Id;
1236 Specification_Node : Node_Id;
1237 Scan_State : Saved_Scan_State;
1240 Ident_Sloc : Source_Ptr;
1241 Not_Null_Present : Boolean := False;
1242 Not_Null_Sloc : Source_Ptr;
1244 Idents : array (Int range 1 .. 4096) of Entity_Id;
1245 -- This array holds the list of defining identifiers. The upper bound
1246 -- of 4096 is intended to be essentially infinite, and we do not even
1247 -- bother to check for it being exceeded.
1250 Specification_List := New_List;
1251 Specification_Loop : loop
1253 if Token = Tok_Pragma then
1254 Error_Msg_SC ("pragma not allowed in formal part");
1255 Discard_Junk_Node (P_Pragma (Skipping => True));
1258 Ignore (Tok_Left_Paren);
1259 Ident_Sloc := Token_Ptr;
1260 Idents (1) := P_Defining_Identifier (C_Comma_Colon);
1264 exit Ident_Loop when Token = Tok_Colon;
1266 -- The only valid tokens are colon and comma, so if we have
1267 -- neither do a bit of investigation to see which is the
1268 -- better choice for insertion.
1270 if Token /= Tok_Comma then
1272 -- Assume colon if ALIASED, IN or OUT keyword found
1274 exit Ident_Loop when Token = Tok_Aliased or else
1275 Token = Tok_In or else
1278 -- Otherwise scan ahead
1280 Save_Scan_State (Scan_State);
1283 -- If we run into a semicolon, then assume that a
1284 -- colon was missing, e.g. Parms (X Y; ...). Also
1285 -- assume missing colon on EOF (a real disaster!)
1286 -- and on a right paren, e.g. Parms (X Y), and also
1287 -- on an assignment symbol, e.g. Parms (X Y := ..)
1289 if Token = Tok_Semicolon
1290 or else Token = Tok_Right_Paren
1291 or else Token = Tok_EOF
1292 or else Token = Tok_Colon_Equal
1294 Restore_Scan_State (Scan_State);
1297 -- If we run into a colon, assume that we had a missing
1298 -- comma, e.g. Parms (A B : ...). Also assume a missing
1299 -- comma if we hit another comma, e.g. Parms (A B, C ..)
1301 elsif Token = Tok_Colon
1302 or else Token = Tok_Comma
1304 Restore_Scan_State (Scan_State);
1309 end loop Look_Ahead;
1312 -- Here if a comma is present, or to be assumed
1315 Num_Idents := Num_Idents + 1;
1316 Idents (Num_Idents) := P_Defining_Identifier (C_Comma_Colon);
1317 end loop Ident_Loop;
1319 -- Fall through the loop on encountering a colon, or deciding
1320 -- that there is a missing colon.
1324 -- If there are multiple identifiers, we repeatedly scan the
1325 -- type and initialization expression information by resetting
1326 -- the scan pointer (so that we get completely separate trees
1327 -- for each occurrence).
1329 if Num_Idents > 1 then
1330 Save_Scan_State (Scan_State);
1333 -- Loop through defining identifiers in list
1337 Ident_List_Loop : loop
1338 Specification_Node :=
1339 New_Node (N_Parameter_Specification, Ident_Sloc);
1340 Set_Defining_Identifier (Specification_Node, Idents (Ident));
1342 -- Scan possible ALIASED for Ada 2012 (AI-142)
1344 if Token = Tok_Aliased then
1345 if Ada_Version < Ada_2012 then
1346 Error_Msg_SC ("ALIASED parameter is an Ada 2012 feature");
1348 Set_Aliased_Present (Specification_Node);
1351 Scan; -- past ALIASED
1354 -- Scan possible NOT NULL for Ada 2005 (AI-231, AI-447)
1356 Not_Null_Sloc := Token_Ptr;
1358 P_Null_Exclusion (Allow_Anonymous_In_95 => True);
1360 -- Case of ACCESS keyword present
1362 if Token = Tok_Access then
1363 Set_Null_Exclusion_Present
1364 (Specification_Node, Not_Null_Present);
1366 if Ada_Version = Ada_83 then
1367 Error_Msg_SC ("(Ada 83) access parameters not allowed");
1371 (Specification_Node,
1372 P_Access_Definition (Not_Null_Present));
1374 -- Case of IN or OUT present
1377 if Token = Tok_In or else Token = Tok_Out then
1378 if Not_Null_Present then
1380 ("`NOT NULL` can only be used with `ACCESS`",
1383 if Token = Tok_In then
1385 ("\`IN` not allowed together with `ACCESS`",
1389 ("\`OUT` not allowed together with `ACCESS`",
1394 P_Mode (Specification_Node);
1395 Not_Null_Present := P_Null_Exclusion; -- Ada 2005 (AI-231)
1398 Set_Null_Exclusion_Present
1399 (Specification_Node, Not_Null_Present);
1401 if Token = Tok_Procedure
1403 Token = Tok_Function
1405 Error_Msg_SC ("formal subprogram parameter not allowed");
1408 if Token = Tok_Left_Paren then
1409 Discard_Junk_List (P_Formal_Part);
1412 if Token = Tok_Return then
1414 Discard_Junk_Node (P_Subtype_Mark);
1417 Set_Parameter_Type (Specification_Node, Error);
1420 Set_Parameter_Type (Specification_Node, P_Subtype_Mark);
1425 Set_Expression (Specification_Node, Init_Expr_Opt (True));
1428 Set_Prev_Ids (Specification_Node, True);
1431 if Ident < Num_Idents then
1432 Set_More_Ids (Specification_Node, True);
1435 Append (Specification_Node, Specification_List);
1436 exit Ident_List_Loop when Ident = Num_Idents;
1438 Restore_Scan_State (Scan_State);
1439 end loop Ident_List_Loop;
1442 when Error_Resync =>
1443 Resync_Semicolon_List;
1446 if Token = Tok_Semicolon then
1447 Save_Scan_State (Scan_State);
1448 Scan; -- past semicolon
1450 -- If we have RETURN or IS after the semicolon, then assume
1451 -- that semicolon should have been a right parenthesis and exit
1453 if Token = Tok_Is or else Token = Tok_Return then
1454 Error_Msg_SP -- CODEFIX
1455 ("|"";"" should be "")""");
1456 exit Specification_Loop;
1459 -- If we have a declaration keyword after the semicolon, then
1460 -- assume we had a missing right parenthesis and terminate list
1462 if Token in Token_Class_Declk then
1463 Error_Msg_AP -- CODEFIX
1465 Restore_Scan_State (Scan_State);
1466 exit Specification_Loop;
1469 elsif Token = Tok_Right_Paren then
1470 Scan; -- past right paren
1471 exit Specification_Loop;
1473 -- Special check for common error of using comma instead of semicolon
1475 elsif Token = Tok_Comma then
1479 -- Special check for omitted separator
1481 elsif Token = Tok_Identifier then
1484 -- If nothing sensible, skip to next semicolon or right paren
1488 Resync_Semicolon_List;
1490 if Token = Tok_Semicolon then
1491 Scan; -- past semicolon
1494 exit Specification_Loop;
1497 end loop Specification_Loop;
1499 return Specification_List;
1502 ----------------------------------
1503 -- 6.1 Parameter Specification --
1504 ----------------------------------
1506 -- Parsed by P_Formal_Part (6.1)
1512 -- MODE ::= [in] | in out | out
1514 -- There is no explicit node in the tree for the Mode. Instead the
1515 -- In_Present and Out_Present flags are set in the parent node to
1516 -- record the presence of keywords specifying the mode.
1518 -- Error_Recovery: cannot raise Error_Resync
1520 procedure P_Mode (Node : Node_Id) is
1522 if Token = Tok_In then
1524 Set_In_Present (Node, True);
1526 if Style.Mode_In_Check and then Token /= Tok_Out then
1527 Error_Msg_SP -- CODEFIX
1528 ("(style) IN should be omitted");
1531 if Token = Tok_Access then
1532 Error_Msg_SP ("IN not allowed together with ACCESS");
1533 Scan; -- past ACCESS
1537 if Token = Tok_Out then
1539 Set_Out_Present (Node, True);
1542 if Token = Tok_In then
1543 Error_Msg_SC ("IN must precede OUT in parameter mode");
1545 Set_In_Present (Node, True);
1549 --------------------------
1550 -- 6.3 Subprogram Body --
1551 --------------------------
1553 -- Parsed by P_Subprogram (6.1)
1555 -----------------------------------
1556 -- 6.4 Procedure Call Statement --
1557 -----------------------------------
1559 -- Parsed by P_Sequence_Of_Statements (5.1)
1561 ------------------------
1562 -- 6.4 Function Call --
1563 ------------------------
1565 -- Parsed by P_Name (4.1)
1567 --------------------------------
1568 -- 6.4 Actual Parameter Part --
1569 --------------------------------
1571 -- Parsed by P_Name (4.1)
1573 --------------------------------
1574 -- 6.4 Parameter Association --
1575 --------------------------------
1577 -- Parsed by P_Name (4.1)
1579 ------------------------------------
1580 -- 6.4 Explicit Actual Parameter --
1581 ------------------------------------
1583 -- Parsed by P_Name (4.1)
1585 ---------------------------
1586 -- 6.5 Return Statement --
1587 ---------------------------
1589 -- SIMPLE_RETURN_STATEMENT ::= return [EXPRESSION];
1591 -- EXTENDED_RETURN_STATEMENT ::=
1592 -- return DEFINING_IDENTIFIER : [aliased] RETURN_SUBTYPE_INDICATION
1593 -- [:= EXPRESSION] [do
1594 -- HANDLED_SEQUENCE_OF_STATEMENTS
1597 -- RETURN_SUBTYPE_INDICATION ::= SUBTYPE_INDICATION | ACCESS_DEFINITION
1599 -- RETURN_STATEMENT ::= return [EXPRESSION];
1601 -- Error recovery: can raise Error_Resync
1603 procedure P_Return_Subtype_Indication (Decl_Node : Node_Id) is
1605 -- Note: We don't need to check Ada_Version here, because this is
1606 -- only called in >= Ada 2005 cases anyway.
1608 Not_Null_Present : constant Boolean := P_Null_Exclusion;
1611 Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
1613 if Token = Tok_Access then
1614 Set_Object_Definition
1615 (Decl_Node, P_Access_Definition (Not_Null_Present));
1617 Set_Object_Definition
1618 (Decl_Node, P_Subtype_Indication (Not_Null_Present));
1620 end P_Return_Subtype_Indication;
1622 -- Error recovery: can raise Error_Resync
1624 function P_Return_Object_Declaration return Node_Id is
1625 Return_Obj : Node_Id;
1626 Decl_Node : Node_Id;
1629 Return_Obj := Token_Node;
1630 Change_Identifier_To_Defining_Identifier (Return_Obj);
1631 Decl_Node := New_Node (N_Object_Declaration, Token_Ptr);
1632 Set_Defining_Identifier (Decl_Node, Return_Obj);
1634 Scan; -- past identifier
1637 -- First an error check, if we have two identifiers in a row, a likely
1638 -- possibility is that the first of the identifiers is an incorrectly
1639 -- spelled keyword. See similar check in P_Identifier_Declarations.
1641 if Token = Tok_Identifier then
1643 SS : Saved_Scan_State;
1647 Save_Scan_State (SS);
1648 Scan; -- past initial identifier
1649 I2 := (Token = Tok_Identifier);
1650 Restore_Scan_State (SS);
1654 (Bad_Spelling_Of (Tok_Access) or else
1655 Bad_Spelling_Of (Tok_Aliased) or else
1656 Bad_Spelling_Of (Tok_Constant))
1663 -- We allow "constant" here (as in "return Result : constant
1664 -- T..."). This is not in the latest RM, but the ARG is considering an
1665 -- AI on the subject (see AI05-0015-1), which we expect to be approved.
1667 if Token = Tok_Constant then
1668 Scan; -- past CONSTANT
1669 Set_Constant_Present (Decl_Node);
1671 if Token = Tok_Aliased then
1672 Error_Msg_SC -- CODEFIX
1673 ("ALIASED should be before CONSTANT");
1674 Scan; -- past ALIASED
1675 Set_Aliased_Present (Decl_Node);
1678 elsif Token = Tok_Aliased then
1679 Scan; -- past ALIASED
1680 Set_Aliased_Present (Decl_Node);
1682 if Ada_Version < Ada_2012 then
1683 Error_Msg_SC -- CODEFIX
1684 ("ALIASED not allowed in extended return in Ada 2012?");
1686 Error_Msg_SC -- CODEFIX
1687 ("ALIASED not allowed in extended return");
1690 if Token = Tok_Constant then
1691 Scan; -- past CONSTANT
1692 Set_Constant_Present (Decl_Node);
1696 P_Return_Subtype_Indication (Decl_Node);
1698 if Token = Tok_Colon_Equal then
1700 Set_Expression (Decl_Node, P_Expression_No_Right_Paren);
1704 end P_Return_Object_Declaration;
1706 -- Error recovery: can raise Error_Resync
1708 function P_Return_Statement return Node_Id is
1709 -- The caller has checked that the initial token is RETURN
1711 function Is_Simple return Boolean;
1712 -- Scan state is just after RETURN (and is left that way).
1713 -- Determine whether this is a simple or extended return statement
1714 -- by looking ahead for "identifier :", which implies extended.
1720 function Is_Simple return Boolean is
1721 Scan_State : Saved_Scan_State;
1722 Result : Boolean := True;
1725 if Token = Tok_Identifier then
1726 Save_Scan_State (Scan_State); -- at identifier
1727 Scan; -- past identifier
1729 if Token = Tok_Colon then
1730 Result := False; -- It's an extended_return_statement.
1733 Restore_Scan_State (Scan_State); -- to identifier
1739 Return_Sloc : constant Source_Ptr := Token_Ptr;
1740 Return_Node : Node_Id;
1742 -- Start of processing for P_Return_Statement
1745 Scan; -- past RETURN
1747 -- Simple_return_statement, no expression, return an
1748 -- N_Simple_Return_Statement node with the expression field left Empty.
1750 if Token = Tok_Semicolon then
1752 Return_Node := New_Node (N_Simple_Return_Statement, Return_Sloc);
1757 -- Simple_return_statement with expression
1759 -- We avoid trying to scan an expression if we are at an
1760 -- expression terminator since in that case the best error
1761 -- message is probably that we have a missing semicolon.
1764 Return_Node := New_Node (N_Simple_Return_Statement, Return_Sloc);
1766 if Token not in Token_Class_Eterm then
1767 Set_Expression (Return_Node, P_Expression_No_Right_Paren);
1770 -- Extended_return_statement (Ada 2005 only -- AI-318):
1773 if Ada_Version < Ada_2005 then
1775 (" extended_return_statement is an Ada 2005 extension");
1776 Error_Msg_SP ("\unit must be compiled with -gnat05 switch");
1779 Return_Node := New_Node (N_Extended_Return_Statement, Return_Sloc);
1780 Set_Return_Object_Declarations
1781 (Return_Node, New_List (P_Return_Object_Declaration));
1783 if Token = Tok_Do then
1785 Scope.Table (Scope.Last).Etyp := E_Return;
1786 Scope.Table (Scope.Last).Ecol := Start_Column;
1787 Scope.Table (Scope.Last).Sloc := Return_Sloc;
1790 Set_Handled_Statement_Sequence
1791 (Return_Node, P_Handled_Sequence_Of_Statements);
1794 -- Do we need to handle Error_Resync here???
1802 end P_Return_Statement;