Skip to content

Commit df4b417

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

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/solvers/strings/string_refinement.cpp

Lines changed: 20 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,22 @@ 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>
381+
extract_strings_from_lhs(const exprt &lhs, const namespacet &ns)
380382
{
381383
std::vector<exprt> result;
382384
if(lhs.type() == string_typet())
383385
result.push_back(lhs);
384-
else if(lhs.type().id() == ID_struct)
386+
else if(lhs.type().id() == ID_struct || lhs.type().id() == ID_struct_tag)
385387
{
386-
const struct_typet &struct_type = to_struct_type(lhs.type());
388+
const struct_typet &struct_type = to_struct_type(ns.follow(lhs.type()));
387389
for(const auto &comp : struct_type.components())
388390
{
389391
const std::vector<exprt> strings_in_comp = extract_strings_from_lhs(
390-
member_exprt(lhs, comp.get_name(), comp.type()));
392+
member_exprt(lhs, comp.get_name(), comp.type()), ns);
391393
result.insert(
392394
result.end(), strings_in_comp.begin(), strings_in_comp.end());
393395
}
@@ -396,10 +398,12 @@ static std::vector<exprt> extract_strings_from_lhs(const exprt &lhs)
396398
}
397399

398400
/// \param expr: an expression
401+
/// \param ns: namespace to resolve type tags
399402
/// \return all subexpressions of type string which are not if_exprt expressions
400403
/// this includes expressions of the form `e.x` if e is a symbol subexpression
401404
/// with a field `x` of type string
402-
static std::vector<exprt> extract_strings(const exprt &expr)
405+
static std::vector<exprt>
406+
extract_strings(const exprt &expr, const namespacet &ns)
403407
{
404408
std::vector<exprt> result;
405409
for(auto it = expr.depth_begin(); it != expr.depth_end();)
@@ -411,7 +415,7 @@ static std::vector<exprt> extract_strings(const exprt &expr)
411415
}
412416
else if(it->id() == ID_symbol)
413417
{
414-
for(const exprt &e : extract_strings_from_lhs(*it))
418+
for(const exprt &e : extract_strings_from_lhs(*it, ns))
415419
result.push_back(e);
416420
it.next_sibling_or_parent();
417421
}
@@ -438,9 +442,12 @@ static void add_string_equation_to_symbol_resolution(
438442
}
439443
else if(has_subtype(eq.lhs().type(), ID_string, ns))
440444
{
441-
if(eq.rhs().type().id() == ID_struct)
445+
if(
446+
eq.rhs().type().id() == ID_struct ||
447+
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 =
450+
to_struct_type(ns.follow(eq.rhs().type()));
444451
for(const auto &comp : struct_type.components())
445452
{
446453
const member_exprt lhs_data(eq.lhs(), comp.get_name(), comp.type());
@@ -484,15 +491,15 @@ union_find_replacet string_identifiers_resolution_from_equations(
484491
if(required_equations.insert(i).second)
485492
equations_to_treat.push(i);
486493

487-
std::vector<exprt> rhs_strings = extract_strings(eq.rhs());
494+
std::vector<exprt> rhs_strings = extract_strings(eq.rhs(), ns);
488495
for(const auto &expr : rhs_strings)
489496
equation_map.add(i, expr);
490497
}
491498
else if(
492499
eq.lhs().type().id() != ID_pointer &&
493500
has_subtype(eq.lhs().type(), ID_string, ns))
494501
{
495-
std::vector<exprt> lhs_strings = extract_strings_from_lhs(eq.lhs());
502+
std::vector<exprt> lhs_strings = extract_strings_from_lhs(eq.lhs(), ns);
496503

497504
for(const auto &expr : lhs_strings)
498505
equation_map.add(i, expr);
@@ -504,7 +511,7 @@ union_find_replacet string_identifiers_resolution_from_equations(
504511
<< format(eq.lhs().type()) << eom;
505512
}
506513

507-
for(const exprt &expr : extract_strings(eq.rhs()))
514+
for(const exprt &expr : extract_strings(eq.rhs(), ns))
508515
equation_map.add(i, expr);
509516
}
510517
}

0 commit comments

Comments
 (0)