Skip to content

Commit 81f6ddf

Browse files
Use ASTs in smt2_conv::convert_literal
This is in preparation for making convert_expr return an AST.
1 parent 505f45c commit 81f6ddf

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/solvers/smt2/smt2_conv.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void smt2_convt::write_footer(std::ostream &os)
106106
forall_literals(it, assumptions)
107107
{
108108
os << "(assert ";
109-
convert_literal(*it);
109+
print(convert_literal(*it), out);
110110
os << ")"
111111
<< "\n";
112112
}
@@ -726,32 +726,28 @@ literalt smt2_convt::convert(const exprt &expr)
726726

727727
out << "; convert\n";
728728
out << "(define-fun ";
729-
convert_literal(l);
729+
print(convert_literal(l), out);
730730
out << " () Bool ";
731731
convert_expr(expr);
732732
out << ")" << "\n";
733733

734734
return l;
735735
}
736736

737-
void smt2_convt::convert_literal(const literalt l)
737+
std::shared_ptr<smt2_astt> smt2_convt::convert_literal(const literalt l)
738738
{
739739
if(l==const_literal(false))
740-
out << "false";
741-
else if(l==const_literal(true))
742-
out << "true";
743-
else
744-
{
745-
if(l.sign())
746-
out << "(not ";
740+
return smt2_ast_symbol_leaf("false");
741+
if(l==const_literal(true))
742+
return smt2_ast_symbol_leaf("true");
747743

748-
out << "|B" << l.var_no() << "|";
744+
std::string literal_name = "B"+std::to_string(l.var_no());
745+
smt2_identifiers.insert(literal_name);
746+
auto literal_without_sign = smt2_ast_symbol_leaf("|"+literal_name+"|");
749747

750-
if(l.sign())
751-
out << ")";
752-
753-
smt2_identifiers.insert("B"+std::to_string(l.var_no()));
754-
}
748+
if(!l.sign())
749+
return literal_without_sign;
750+
return smt2_not(literal_without_sign);
755751
}
756752

757753
std::string smt2_convt::convert_identifier(const irep_idt &identifier)
@@ -1755,7 +1751,7 @@ void smt2_convt::convert_expr(const exprt &expr)
17551751
}
17561752
else if(expr.id()==ID_literal)
17571753
{
1758-
convert_literal(to_literal_expr(expr).get_literal());
1754+
print(convert_literal(to_literal_expr(expr).get_literal()), out);
17591755
}
17601756
else if(expr.id()==ID_forall ||
17611757
expr.id()==ID_exists)

src/solvers/smt2/smt2_conv.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
2323
#include <solvers/prop/prop_conv.h>
2424
#include <solvers/flattening/boolbv_width.h>
2525
#include <solvers/flattening/pointer_logic.h>
26+
#include <solvers/smt2/smt2_ast.h>
2627

2728
class typecast_exprt;
2829
class constant_exprt;
@@ -125,7 +126,7 @@ class smt2_convt:public prop_convt
125126
// new stuff
126127
void convert_expr(const exprt &);
127128
void convert_type(const typet &);
128-
void convert_literal(const literalt);
129+
std::shared_ptr<smt2_astt> convert_literal(const literalt);
129130

130131
protected:
131132
const namespacet &ns;

0 commit comments

Comments
 (0)