@@ -1101,20 +1101,18 @@ code_blockt java_string_library_preprocesst::make_assign_function_from_call(
1101
1101
function_id, type, loc, symbol_table, false );
1102
1102
}
1103
1103
1104
- // / Used to provide our own implementation of the java.lang.Object.getClass ()
1104
+ // / Used to provide our own implementation of the CProver.classIdentifier ()
1105
1105
// / function.
1106
1106
// / \param type: type of the function called
1107
1107
// / \param loc: location in the source
1108
1108
// / \param function_id: function the generated code will be added to
1109
1109
// / \param symbol_table: the symbol table
1110
1110
// / \return Code corresponding to
1111
1111
// / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1112
- // / Class class1;
1113
- // / string_expr1 = substr(this->@class_identifier, 6)
1114
- // / class1=Class.forName(string_expr1)
1115
- // / return class1
1112
+ // / string_expr1 = substr(obj->@class_identifier, 6)
1113
+ // / return string_expr1;
1116
1114
// / ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1117
- code_blockt java_string_library_preprocesst::make_object_get_class_code (
1115
+ code_blockt java_string_library_preprocesst::make_class_identifier_code (
1118
1116
const java_method_typet &type,
1119
1117
const source_locationt &loc,
1120
1118
const irep_idt &function_id,
@@ -1123,21 +1121,14 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
1123
1121
java_method_typet::parameterst params = type.parameters ();
1124
1122
PRECONDITION (!params.empty ());
1125
1123
PRECONDITION (!params[0 ].get_identifier ().empty ());
1126
- const symbol_exprt this_obj (params[0 ].get_identifier (), params[0 ].type ());
1124
+ const symbol_exprt obj (params[0 ].get_identifier (), params[0 ].type ());
1127
1125
1128
1126
// Code to be returned
1129
1127
code_blockt code;
1130
1128
1131
- // > Class class1;
1132
- const pointer_typet &class_type = to_pointer_type (type.return_type ());
1133
- const symbolt &class1_sym = fresh_java_symbol (
1134
- class_type, " class_symbol" , loc, function_id, symbol_table);
1135
- const symbol_exprt class1 = class1_sym.symbol_expr ();
1136
- code.add (code_declt (class1), loc);
1137
-
1138
- // class_identifier is this->@class_identifier
1139
- const member_exprt class_identifier (
1140
- checked_dereference (this_obj), " @class_identifier" , string_typet ());
1129
+ // class_identifier is obj->@class_identifier
1130
+ const member_exprt class_identifier{
1131
+ checked_dereference (obj), " @class_identifier" , string_typet ()};
1141
1132
1142
1133
// string_expr = cprover_string_literal(this->@class_identifier)
1143
1134
const refined_string_exprt string_expr = string_expr_of_function (
@@ -1157,28 +1148,16 @@ code_blockt java_string_library_preprocesst::make_object_get_class_code(
1157
1148
code);
1158
1149
1159
1150
// string1 = (String*) string_expr
1160
- const pointer_typet string_ptr_type =
1161
- java_reference_type (symbol_table.lookup_ref (" java::java.lang.String" ).type );
1151
+ const typet &string_ptr_type = type.return_type ();
1162
1152
const exprt string1 = allocate_fresh_string (
1163
1153
string_ptr_type, loc, function_id, symbol_table, code);
1164
1154
code.add (
1165
1155
code_assign_string_expr_to_java_string (
1166
1156
string1, string_expr1, symbol_table, true ),
1167
1157
loc);
1168
1158
1169
- // > class1 = Class.forName(string1)
1170
- java_method_typet fun_type (
1171
- {java_method_typet::parametert (string_ptr_type)}, class_type);
1172
- code_function_callt fun_call (
1173
- class1,
1174
- symbol_exprt (
1175
- " java::java.lang.Class.forName:(Ljava/lang/String;)Ljava/lang/Class;" ,
1176
- std::move (fun_type)),
1177
- {string1});
1178
- code.add (fun_call, loc);
1179
-
1180
- // > return class1;
1181
- code.add (code_returnt (class1), loc);
1159
+ // > return string1;
1160
+ code.add (code_returnt{string1}, loc);
1182
1161
return code;
1183
1162
}
1184
1163
@@ -1900,9 +1879,10 @@ void java_string_library_preprocesst::initialize_conversion_table()
1900
1879
cprover_equivalent_to_java_string_returning_function
1901
1880
[" java::java.lang.Long.toString:(JI)Ljava/lang/String;" ]=
1902
1881
ID_cprover_string_of_int_func;
1903
- conversion_table[" java::java.lang.Object.getClass:()Ljava/lang/Class;" ] =
1882
+ conversion_table[" java::org.cprover.CProver.classIdentifier:("
1883
+ " Ljava/lang/Object;)Ljava/lang/String;" ] =
1904
1884
std::bind (
1905
- &java_string_library_preprocesst::make_object_get_class_code ,
1885
+ &java_string_library_preprocesst::make_class_identifier_code ,
1906
1886
this ,
1907
1887
std::placeholders::_1,
1908
1888
std::placeholders::_2,
0 commit comments