Skip to content

Commit 444c186

Browse files
codebyzebromainbrenguier
authored andcommitted
Implement model for String.equals
String.equals currently handled by CBMC, this removes support within CBMC so that String.equals will be handled by a model instead.
1 parent 0d80558 commit 444c186

File tree

2 files changed

+0
-75
lines changed

2 files changed

+0
-75
lines changed

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -937,66 +937,6 @@ java_string_library_preprocesst::string_literal_to_string_expr(
937937
ID_cprover_string_literal_func, {expr}, loc, symbol_table, code);
938938
}
939939

940-
/// Used to provide code for the Java String.equals(Object) function.
941-
/// \param type: type of the function call
942-
/// \param loc: location in the program_invocation_name
943-
/// \param symbol_table: symbol table
944-
/// \return Code corresponding to:
945-
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
946-
/// IF arg->@class_identifier == "java.lang.String"
947-
/// THEN
948-
/// string_expr1 = {this->length; *this->data}
949-
/// string_expr2 = {arg->length; *arg->data}
950-
/// bool string_equals_tmp = cprover_string_equal(string_expr1, string_expr2)
951-
/// return string_equals_tmp
952-
/// ELSE
953-
/// return false
954-
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
955-
codet java_string_library_preprocesst::make_equals_function_code(
956-
const code_typet &type,
957-
const source_locationt &loc,
958-
const irep_idt &function_id,
959-
symbol_table_baset &symbol_table)
960-
{
961-
const typet &return_type = type.return_type();
962-
exprt::operandst ops;
963-
for(const auto &p : type.parameters())
964-
{
965-
symbol_exprt sym(p.get_identifier(), p.type());
966-
ops.push_back(sym);
967-
}
968-
969-
code_ifthenelset code;
970-
code.cond() = [&] {
971-
const member_exprt class_identifier(
972-
checked_dereference(ops[1], ops[1].type().subtype()),
973-
"@class_identifier",
974-
string_typet());
975-
return equal_exprt(
976-
class_identifier,
977-
constant_exprt("java::java.lang.String", string_typet()));
978-
}();
979-
980-
code.then_case() = [&] {
981-
code_blockt instance_case;
982-
// Check content equality
983-
const symbolt string_equals_sym = get_fresh_aux_symbol(
984-
return_type, "string_equals", "str_eq", loc, ID_java, symbol_table);
985-
const symbol_exprt string_equals = string_equals_sym.symbol_expr();
986-
instance_case.add(code_declt(string_equals), loc);
987-
const exprt::operandst args =
988-
process_equals_function_operands(ops, loc, symbol_table, instance_case);
989-
const auto fun_app = make_function_application(
990-
ID_cprover_string_equal_func, args, return_type, symbol_table);
991-
instance_case.add(code_assignt(string_equals, fun_app), loc);
992-
instance_case.add(code_returnt(string_equals), loc);
993-
return instance_case;
994-
}();
995-
996-
code.else_case() = code_returnt(from_integer(false, return_type));
997-
return code;
998-
}
999-
1000940
/// Provide code for the String.valueOf(F) function.
1001941
/// \param type: type of the function call
1002942
/// \param loc: location in the program_invocation_name
@@ -2006,15 +1946,6 @@ void java_string_library_preprocesst::initialize_conversion_table()
20061946
cprover_equivalent_to_java_function
20071947
["java::java.lang.String.endsWith:(Ljava/lang/String;)Z"]=
20081948
ID_cprover_string_endswith_func;
2009-
2010-
conversion_table["java::java.lang.String.equals:(Ljava/lang/Object;)Z"] =
2011-
std::bind(
2012-
&java_string_library_preprocesst::make_equals_function_code,
2013-
this,
2014-
std::placeholders::_1,
2015-
std::placeholders::_2,
2016-
std::placeholders::_3,
2017-
std::placeholders::_4);
20181949
cprover_equivalent_to_java_function
20191950
["java::java.lang.String.equalsIgnoreCase:(Ljava/lang/String;)Z"]=
20201951
ID_cprover_string_equals_ignore_case_func;

jbmc/src/java_bytecode/java_string_library_preprocess.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ class java_string_library_preprocesst:public messaget
145145
// A set tells us what java types should be considered as string objects
146146
std::unordered_set<irep_idt> string_types;
147147

148-
codet make_equals_function_code(
149-
const code_typet &type,
150-
const source_locationt &loc,
151-
const irep_idt &function_id,
152-
symbol_table_baset &symbol_table);
153-
154148
codet make_float_to_string_code(
155149
const code_typet &type,
156150
const source_locationt &loc,

0 commit comments

Comments
 (0)