+ function Is_OK_Object_Reference (Nod : Node_Id) return Boolean;
+ -- Determine whether arbitrary node Nod denotes a source object that
+ -- may safely act as prefix of attribute 'Valid.
+
+ ----------------------------
+ -- Is_OK_Object_Reference --
+ ----------------------------
+
+ function Is_OK_Object_Reference (Nod : Node_Id) return Boolean is
+ Obj_Ref : Node_Id;
+
+ begin
+ -- Inspect the original operand
+
+ Obj_Ref := Original_Node (Nod);
+
+ -- The object reference must be a source construct, otherwise the
+ -- codefix suggestion may refer to nonexistent code from a user
+ -- perspective.
+
+ if Comes_From_Source (Obj_Ref) then
+
+ -- Recover the actual object reference. There may be more cases
+ -- to consider???
+
+ loop
+ if Nkind_In (Obj_Ref, N_Type_Conversion,
+ N_Unchecked_Type_Conversion)
+ then
+ Obj_Ref := Expression (Obj_Ref);
+ else
+ exit;
+ end if;
+ end loop;
+
+ return Is_Object_Reference (Obj_Ref);
+ end if;
+
+ return False;
+ end Is_OK_Object_Reference;
+
+ -- Start of processing for Substitute_Valid_Check
+