Skip to content

Commit 8831b62

Browse files
Daniel Kroeningtautschnig
Daniel Kroening
authored andcommitted
smt2_conv: preserve tag types
1 parent 91e0646 commit 8831b62

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,12 @@ constant_exprt smt2_convt::parse_literal(
322322
}
323323
else if(type.id()==ID_c_enum_tag)
324324
{
325-
return
326-
from_integer(
327-
value,
328-
ns.follow_tag(to_c_enum_tag_type(type)));
325+
constant_exprt result =
326+
from_integer(value, ns.follow_tag(to_c_enum_tag_type(type)));
327+
328+
// restore the c_enum_tag type
329+
result.type() = type;
330+
return result;
329331
}
330332
else if(type.id()==ID_fixedbv ||
331333
type.id()==ID_floatbv)
@@ -335,7 +337,9 @@ constant_exprt smt2_convt::parse_literal(
335337
}
336338
else if(type.id()==ID_integer ||
337339
type.id()==ID_range)
340+
{
338341
return from_integer(value, type);
342+
}
339343
else
340344
INVARIANT(
341345
false,
@@ -388,25 +392,24 @@ exprt smt2_convt::parse_union(
388392
return union_exprt(first.get_name(), converted, type);
389393
}
390394

391-
exprt smt2_convt::parse_struct(
392-
const irept &src,
393-
const struct_typet &type)
395+
struct_exprt
396+
smt2_convt::parse_struct(const irept &src, const struct_typet &type)
394397
{
395398
const struct_typet::componentst &components =
396399
type.components();
397400

398401
struct_exprt result(exprt::operandst(components.size(), nil_exprt()), type);
399402

400403
if(components.empty())
401-
return std::move(result);
404+
return result;
402405

403406
if(use_datatypes)
404407
{
405408
// Structs look like:
406409
// (mk-struct.1 <component0> <component1> ... <componentN>)
407410

408411
if(src.get_sub().size()!=components.size()+1)
409-
return std::move(result); // give up
412+
return result; // give up
410413

411414
for(std::size_t i=0; i<components.size(); i++)
412415
{
@@ -446,20 +449,17 @@ exprt smt2_convt::parse_struct(
446449
}
447450
}
448451

449-
return std::move(result);
452+
return result;
450453
}
451454

452-
exprt smt2_convt::parse_rec(const irept &src, const typet &_type)
455+
exprt smt2_convt::parse_rec(const irept &src, const typet &type)
453456
{
454-
const typet &type=ns.follow(_type);
455-
456-
if(type.id()==ID_signedbv ||
457-
type.id()==ID_unsignedbv ||
458-
type.id()==ID_integer ||
459-
type.id()==ID_rational ||
460-
type.id()==ID_real ||
461-
type.id()==ID_fixedbv ||
462-
type.id()==ID_floatbv)
457+
if(
458+
type.id() == ID_signedbv || type.id() == ID_unsignedbv ||
459+
type.id() == ID_integer || type.id() == ID_rational ||
460+
type.id() == ID_real || type.id() == ID_c_enum ||
461+
type.id() == ID_c_enum_tag || type.id() == ID_fixedbv ||
462+
type.id() == ID_floatbv)
463463
{
464464
return parse_literal(src, type);
465465
}
@@ -489,10 +489,25 @@ exprt smt2_convt::parse_rec(const irept &src, const typet &_type)
489489
{
490490
return parse_struct(src, to_struct_type(type));
491491
}
492+
else if(type.id() == ID_struct_tag)
493+
{
494+
auto struct_expr =
495+
parse_struct(src, ns.follow_tag(to_struct_tag_type(type)));
496+
// restore the tag type
497+
struct_expr.type() = type;
498+
return std::move(struct_expr);
499+
}
492500
else if(type.id()==ID_union)
493501
{
494502
return parse_union(src, to_union_type(type));
495503
}
504+
else if(type.id() == ID_union_tag)
505+
{
506+
auto union_expr = parse_union(src, ns.follow_tag(to_union_tag_type(type)));
507+
// restore the tag type
508+
union_expr.type() = type;
509+
return union_expr;
510+
}
496511
else if(type.id()==ID_array)
497512
{
498513
return parse_array(src, to_array_type(type));

src/solvers/smt2/smt2_conv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ class smt2_convt:public prop_convt
237237

238238
// Parsing solver responses
239239
constant_exprt parse_literal(const irept &, const typet &type);
240-
exprt parse_struct(const irept &s, const struct_typet &type);
240+
struct_exprt parse_struct(const irept &s, const struct_typet &type);
241241
exprt parse_union(const irept &s, const union_typet &type);
242242
exprt parse_array(const irept &s, const array_typet &type);
243243
exprt parse_rec(const irept &s, const typet &type);

0 commit comments

Comments
 (0)