Skip to content

Commit 8169994

Browse files
committed
String refinement: handle both struct and struct tag types
struct tags need to be expanded.
1 parent d21be2d commit 8169994

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/solvers/strings/string_refinement.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ static void add_equations_for_symbol_resolution(
348348
else if(
349349
lhs.type().id() != ID_pointer && has_char_pointer_subtype(lhs.type(), ns))
350350
{
351-
if(rhs.type().id() == ID_struct)
351+
if(rhs.type().id() == ID_struct || rhs.type().id() == ID_struct_tag)
352352
{
353-
const struct_typet &struct_type = to_struct_type(rhs.type());
353+
const struct_typet &struct_type = to_struct_type(ns.follow(rhs.type()));
354354
for(const auto &comp : struct_type.components())
355355
{
356356
if(is_char_pointer_type(comp.type()))
@@ -374,20 +374,23 @@ static void add_equations_for_symbol_resolution(
374374
/// This is meant to be used on the lhs of an equation with string subtype.
375375
/// \param lhs: expression which is either of string type, or a symbol
376376
/// representing a struct with some string members
377+
/// \param ns: namespace to resolve type tags
377378
/// \return if lhs is a string return this string, if it is a struct return the
378379
/// members of the expression that have string type.
379-
static std::vector<exprt> extract_strings_from_lhs(const exprt &lhs)
380+
static std::vector<exprt> extract_strings_from_lhs(
381+
const exprt &lhs,
382+
const namespacet &ns)
380383
{
381384
std::vector<exprt> result;
382385
if(lhs.type() == string_typet())
383386
result.push_back(lhs);
384-
else if(lhs.type().id() == ID_struct)
387+
else if(lhs.type().id() == ID_struct || lhs.type().id() == ID_struct_tag)
385388
{
386-
const struct_typet &struct_type = to_struct_type(lhs.type());
389+
const struct_typet &struct_type = to_struct_type(ns.follow(lhs.type()));
387390
for(const auto &comp : struct_type.components())
388391
{
389392
const std::vector<exprt> strings_in_comp = extract_strings_from_lhs(
390-
member_exprt(lhs, comp.get_name(), comp.type()));
393+
member_exprt(lhs, comp.get_name(), comp.type()), ns);
391394
result.insert(
392395
result.end(), strings_in_comp.begin(), strings_in_comp.end());
393396
}
@@ -396,10 +399,13 @@ static std::vector<exprt> extract_strings_from_lhs(const exprt &lhs)
396399
}
397400

398401
/// \param expr: an expression
402+
/// \param ns: namespace to resolve type tags
399403
/// \return all subexpressions of type string which are not if_exprt expressions
400404
/// this includes expressions of the form `e.x` if e is a symbol subexpression
401405
/// with a field `x` of type string
402-
static std::vector<exprt> extract_strings(const exprt &expr)
406+
static std::vector<exprt> extract_strings(
407+
const exprt &expr,
408+
const namespacet &ns)
403409
{
404410
std::vector<exprt> result;
405411
for(auto it = expr.depth_begin(); it != expr.depth_end();)
@@ -411,7 +417,7 @@ static std::vector<exprt> extract_strings(const exprt &expr)
411417
}
412418
else if(it->id() == ID_symbol)
413419
{
414-
for(const exprt &e : extract_strings_from_lhs(*it))
420+
for(const exprt &e : extract_strings_from_lhs(*it, ns))
415421
result.push_back(e);
416422
it.next_sibling_or_parent();
417423
}
@@ -438,9 +444,9 @@ static void add_string_equation_to_symbol_resolution(
438444
}
439445
else if(has_subtype(eq.lhs().type(), ID_string, ns))
440446
{
441-
if(eq.rhs().type().id() == ID_struct)
447+
if(eq.rhs().type().id() == ID_struct || eq.rhs().type().id() == ID_struct_tag)
442448
{
443-
const struct_typet &struct_type = to_struct_type(eq.rhs().type());
449+
const struct_typet &struct_type = to_struct_type(ns.follow(eq.rhs().type()));
444450
for(const auto &comp : struct_type.components())
445451
{
446452
const member_exprt lhs_data(eq.lhs(), comp.get_name(), comp.type());
@@ -484,15 +490,15 @@ union_find_replacet string_identifiers_resolution_from_equations(
484490
if(required_equations.insert(i).second)
485491
equations_to_treat.push(i);
486492

487-
std::vector<exprt> rhs_strings = extract_strings(eq.rhs());
493+
std::vector<exprt> rhs_strings = extract_strings(eq.rhs(), ns);
488494
for(const auto &expr : rhs_strings)
489495
equation_map.add(i, expr);
490496
}
491497
else if(
492498
eq.lhs().type().id() != ID_pointer &&
493499
has_subtype(eq.lhs().type(), ID_string, ns))
494500
{
495-
std::vector<exprt> lhs_strings = extract_strings_from_lhs(eq.lhs());
501+
std::vector<exprt> lhs_strings = extract_strings_from_lhs(eq.lhs(), ns);
496502

497503
for(const auto &expr : lhs_strings)
498504
equation_map.add(i, expr);
@@ -504,7 +510,7 @@ union_find_replacet string_identifiers_resolution_from_equations(
504510
<< format(eq.lhs().type()) << eom;
505511
}
506512

507-
for(const exprt &expr : extract_strings(eq.rhs()))
513+
for(const exprt &expr : extract_strings(eq.rhs(), ns))
508514
equation_map.add(i, expr);
509515
}
510516
}

0 commit comments

Comments
 (0)