Skip to content

Commit 599501c

Browse files
committed
byte_extract flattening over Java strings
1 parent ffd0417 commit 599501c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/solvers/flattening/flatten_byte_operators.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ static exprt unpack_rec(
205205
}
206206

207207
member_exprt member(src, comp.get_name(), comp.type());
208+
if(src.id()==ID_struct)
209+
simplify(member, ns);
210+
208211
exprt sub=
209212
unpack_rec(
210213
member,
@@ -250,6 +253,37 @@ static exprt unpack_rec(
250253
array.copy_to_operands(op);
251254
}
252255
}
256+
else if(src.id()==ID_string_constant ||
257+
(src.id()==ID_constant && type.id()==ID_string))
258+
{
259+
// string constants
260+
std::string value=id2string(src.get(ID_value));
261+
262+
// create an array of characters and unpack that one
263+
array_exprt char_array(
264+
array_typet(
265+
unsignedbv_typet(8), from_integer(value.size(), size_type())));
266+
267+
exprt::operandst chars;
268+
chars.reserve(value.size());
269+
for(const char c : value)
270+
chars.push_back(from_integer(c, unsignedbv_typet(8)));
271+
272+
char_array.operands().swap(chars);
273+
274+
if(!unpack_byte_array)
275+
return char_array;
276+
277+
unpack_array_vector(
278+
char_array,
279+
to_array_type(char_array.type()).size(),
280+
8,
281+
little_endian,
282+
offset,
283+
max_bytes,
284+
ns,
285+
array);
286+
}
253287
else if(type.id()!=ID_empty)
254288
{
255289
// a basic type; we turn that into extractbits while considering

0 commit comments

Comments
 (0)