+ -- Error recovery: can raise Error_Resync
+
+ procedure P_Return_Subtype_Indication (Decl_Node : Node_Id) is
+
+ -- Note: We don't need to check Ada_Version here, because this is
+ -- only called in >= Ada 2005 cases anyway.
+
+ Not_Null_Present : constant Boolean := P_Null_Exclusion;
+
+ begin
+ Set_Null_Exclusion_Present (Decl_Node, Not_Null_Present);
+
+ if Token = Tok_Access then
+ Set_Object_Definition
+ (Decl_Node, P_Access_Definition (Not_Null_Present));
+ else
+ Set_Object_Definition
+ (Decl_Node, P_Subtype_Indication (Not_Null_Present));
+ end if;
+ end P_Return_Subtype_Indication;
+
+ -- Error recovery: can raise Error_Resync
+
+ function P_Return_Object_Declaration return Node_Id is
+ Return_Obj : Node_Id;
+ Decl_Node : Node_Id;
+
+ begin
+ Return_Obj := Token_Node;
+ Change_Identifier_To_Defining_Identifier (Return_Obj);
+ Decl_Node := New_Node (N_Object_Declaration, Token_Ptr);
+ Set_Defining_Identifier (Decl_Node, Return_Obj);
+
+ Scan; -- past identifier
+ Scan; -- past :
+
+ -- First an error check, if we have two identifiers in a row, a likely
+ -- possibility is that the first of the identifiers is an incorrectly
+ -- spelled keyword. See similar check in P_Identifier_Declarations.
+
+ if Token = Tok_Identifier then
+ declare
+ SS : Saved_Scan_State;
+ I2 : Boolean;
+
+ begin
+ Save_Scan_State (SS);
+ Scan; -- past initial identifier
+ I2 := (Token = Tok_Identifier);
+ Restore_Scan_State (SS);
+
+ if I2
+ and then
+ (Bad_Spelling_Of (Tok_Access) or else
+ Bad_Spelling_Of (Tok_Aliased) or else
+ Bad_Spelling_Of (Tok_Constant))
+ then
+ null;
+ end if;
+ end;
+ end if;
+
+ -- We allow "constant" here (as in "return Result : constant
+ -- T..."). This is not in the latest RM, but the ARG is considering an
+ -- AI on the subject (see AI05-0015-1), which we expect to be approved.
+
+ if Token = Tok_Constant then
+ Scan; -- past CONSTANT
+ Set_Constant_Present (Decl_Node);
+
+ if Token = Tok_Aliased then
+ Error_Msg_SC -- CODEFIX
+ ("ALIASED should be before CONSTANT");
+ Scan; -- past ALIASED
+ Set_Aliased_Present (Decl_Node);
+ end if;
+
+ elsif Token = Tok_Aliased then
+ Scan; -- past ALIASED
+ Set_Aliased_Present (Decl_Node);
+
+ if Token = Tok_Constant then
+ Scan; -- past CONSTANT
+ Set_Constant_Present (Decl_Node);
+ end if;
+ end if;
+
+ P_Return_Subtype_Indication (Decl_Node);
+
+ if Token = Tok_Colon_Equal then
+ Scan; -- past :=
+ Set_Expression (Decl_Node, P_Expression_No_Right_Paren);
+ end if;
+
+ return Decl_Node;
+ end P_Return_Object_Declaration;