Skip to content

Commit edf7057

Browse files
Complete string solver rework
This devides string_exprt into two types: * refined_string_exprt which is used in the preprocessing to pass arguments to string primitives * array_string_exprt which is used by the string solver The solver therefore now works with arrays in the back end. This commit contains a lot of renaming from string_exprt to one of the two new expression type, and the solver procedure is adapted for working on finite arrays.
1 parent 9ea2eda commit edf7057

25 files changed

+1421
-1444
lines changed

src/java_bytecode/java_bytecode_typecheck_expr.cpp

+34-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Author: Daniel Kroening, [email protected]
1313

1414
#include <iomanip>
1515

16+
#include <util/std_expr.h>
17+
#include <util/prefix.h>
1618
#include <util/arith_tools.h>
1719
#include <util/unicode.h>
1820

@@ -22,6 +24,7 @@ Author: Daniel Kroening, [email protected]
2224
#include "java_types.h"
2325
#include "java_utils.h"
2426
#include "java_root_class.h"
27+
#include "java_string_library_preprocess.h"
2528

2629
void java_bytecode_typecheckt::typecheck_expr(exprt &expr)
2730
{
@@ -95,7 +98,8 @@ static std::string escape_non_alnum(const std::string &toescape)
9598
static array_exprt utf16_to_array(const std::wstring &in)
9699
{
97100
const auto jchar=java_char_type();
98-
array_exprt ret(array_typet(jchar, infinity_exprt(java_int_type())));
101+
array_exprt ret(
102+
array_typet(jchar, from_integer(in.length(), java_int_type())));
99103
for(const auto c : in)
100104
ret.copy_to_operands(from_integer(c, jchar));
101105
return ret;
@@ -141,33 +145,51 @@ void java_bytecode_typecheckt::typecheck_expr_java_string_literal(exprt &expr)
141145
{
142146
struct_exprt literal_init(new_symbol.type);
143147
literal_init.move_to_operands(jlo_init);
148+
literal_init.copy_to_operands(
149+
from_integer(id2string(value).size(), jls_struct.components()[1].type()));
144150

145151
// Initialize the string with a constant utf-16 array:
146152
symbolt array_symbol;
147153
array_symbol.name=escaped_symbol_name+"_constarray";
148-
array_symbol.type=array_typet(
149-
java_char_type(), infinity_exprt(java_int_type()));
150154
array_symbol.base_name="Literal_constarray";
155+
// TODO: this should be obtained from java_string_library_preprocess
151156
array_symbol.pretty_name=value;
152157
array_symbol.mode=ID_java;
153158
array_symbol.is_type=false;
154159
array_symbol.is_lvalue=true;
155160
// These are basically const global data:
156161
array_symbol.is_static_lifetime=true;
157162
array_symbol.is_state_var=true;
158-
auto literal_array=utf16_to_array(
159-
utf8_to_utf16_little_endian(id2string(value)));
160-
array_symbol.value=literal_array;
163+
array_symbol.value =
164+
utf16_to_array(utf8_to_utf16_little_endian(id2string(value)));
165+
array_symbol.type = array_symbol.value.type();
161166

162167
if(symbol_table.add(array_symbol))
163168
throw "failed to add constarray symbol to symbol table";
164169

165-
literal_init.copy_to_operands(
166-
from_integer(literal_array.operands().size(),
167-
jls_struct.components()[1].type()));
168-
literal_init.copy_to_operands(
169-
address_of_exprt(array_symbol.symbol_expr()));
170-
170+
const symbol_exprt array_expr = array_symbol.symbol_expr();
171+
const address_of_exprt first_index(
172+
index_exprt(array_expr, from_integer(0, java_int_type())));
173+
literal_init.copy_to_operands(first_index);
174+
175+
// Associate array with pointer
176+
symbolt return_symbol;
177+
return_symbol.name = "return_value_" + escaped_symbol_name;
178+
return_symbol.base_name = escaped_symbol_name;
179+
return_symbol.pretty_name = "return_value";
180+
return_symbol.mode = ID_java;
181+
return_symbol.is_type = false;
182+
return_symbol.is_lvalue = true;
183+
return_symbol.is_static_lifetime = true;
184+
return_symbol.is_state_var = true;
185+
return_symbol.value = make_function_application(
186+
ID_cprover_associate_array_to_pointer_func,
187+
{array_symbol.value, first_index},
188+
java_int_type(),
189+
symbol_table);
190+
return_symbol.type = return_symbol.value.type();
191+
if(symbol_table.add(return_symbol))
192+
throw "failed to add return symbol to symbol table";
171193
new_symbol.value=literal_init;
172194
}
173195
else if(jls_struct.components().size()>=1 &&

0 commit comments

Comments
 (0)