Skip to content

Commit 8c3a118

Browse files
Use ASTs in smt2_conv::convert_literal
This is in preparation for making convert_expr return an AST.
1 parent 1c75839 commit 8c3a118

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
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
}
@@ -655,32 +655,28 @@ literalt smt2_convt::convert(const exprt &expr)
655655

656656
out << "; convert\n";
657657
out << "(define-fun ";
658-
convert_literal(l);
658+
print(convert_literal(l), out);
659659
out << " () Bool ";
660660
convert_expr(expr);
661661
out << ")" << "\n";
662662

663663
return l;
664664
}
665665

666-
void smt2_convt::convert_literal(const literalt l)
666+
smt2_astt smt2_convt::convert_literal(const literalt l)
667667
{
668668
if(l==const_literal(false))
669-
out << "false";
670-
else if(l==const_literal(true))
671-
out << "true";
672-
else
673-
{
674-
if(l.sign())
675-
out << "(not ";
669+
return smt2_astt("false");
670+
if(l == const_literal(true))
671+
return smt2_astt("true");
676672

677-
out << "|B" << l.var_no() << "|";
673+
std::string literal_name = "B" + std::to_string(l.var_no());
674+
smt2_identifiers.insert(literal_name);
675+
auto literal_without_sign = smt2_astt("|" + literal_name + "|");
678676

679-
if(l.sign())
680-
out << ")";
681-
682-
smt2_identifiers.insert("B"+std::to_string(l.var_no()));
683-
}
677+
if(!l.sign())
678+
return literal_without_sign;
679+
return smt2_not(std::move(literal_without_sign));
684680
}
685681

686682
std::string smt2_convt::convert_identifier(const irep_idt &identifier)
@@ -1697,7 +1693,7 @@ void smt2_convt::convert_expr(const exprt &expr)
16971693
}
16981694
else if(expr.id()==ID_literal)
16991695
{
1700-
convert_literal(to_literal_expr(expr).get_literal());
1696+
print(convert_literal(to_literal_expr(expr).get_literal()), out);
17011697
}
17021698
else if(expr.id()==ID_forall ||
17031699
expr.id()==ID_exists)

src/solvers/smt2/smt2_conv.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ Author: Daniel Kroening, [email protected]
2020
#include <util/irep_hash_container.h>
2121
#endif
2222

23-
#include <solvers/prop/prop_conv.h>
2423
#include <solvers/flattening/boolbv_width.h>
2524
#include <solvers/flattening/pointer_logic.h>
25+
#include <solvers/prop/prop_conv.h>
26+
#include <solvers/smt2/smt2_ast.h>
2627

2728
class typecast_exprt;
2829
class constant_exprt;
@@ -131,7 +132,7 @@ class smt2_convt:public prop_convt
131132

132133
void convert_expr(const exprt &);
133134
void convert_type(const typet &);
134-
void convert_literal(const literalt);
135+
smt2_astt convert_literal(const literalt);
135136

136137
std::size_t get_number_of_solver_calls() const override;
137138

0 commit comments

Comments
 (0)