-
Notifications
You must be signed in to change notification settings - Fork 277
exprt::opX cleanup #3465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exprt::opX cleanup #3465
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,21 +95,26 @@ std::string inv_object_storet::build_string(const exprt &expr) const | |
// we ignore some casts | ||
if(expr.id()==ID_typecast) | ||
{ | ||
assert(expr.operands().size()==1); | ||
const auto &typecast_expr = to_typecast_expr(expr); | ||
|
||
if(expr.type().id()==ID_signedbv || | ||
expr.type().id()==ID_unsignedbv) | ||
if( | ||
typecast_expr.type().id() == ID_signedbv || | ||
typecast_expr.type().id() == ID_unsignedbv) | ||
{ | ||
if(expr.op0().type().id()==ID_signedbv || | ||
expr.op0().type().id()==ID_unsignedbv) | ||
const typet &op_type = typecast_expr.op().type(); | ||
|
||
if(op_type.id() == ID_signedbv || op_type.id() == ID_unsignedbv) | ||
{ | ||
if(to_bitvector_type(expr.type()).get_width()>= | ||
to_bitvector_type(expr.op0().type()).get_width()) | ||
return build_string(expr.op0()); | ||
if( | ||
to_bitvector_type(typecast_expr.type()).get_width() >= | ||
to_bitvector_type(op_type).get_width()) | ||
{ | ||
return build_string(typecast_expr.op()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit pick: please add braces for readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
} | ||
else if(expr.op0().type().id()==ID_bool) | ||
else if(op_type.id() == ID_bool) | ||
{ | ||
return build_string(expr.op0()); | ||
return build_string(typecast_expr.op()); | ||
} | ||
} | ||
} | ||
|
@@ -137,8 +142,8 @@ std::string inv_object_storet::build_string(const exprt &expr) const | |
|
||
if(expr.id()==ID_member) | ||
{ | ||
assert(expr.operands().size()==1); | ||
return build_string(expr.op0())+"."+expr.get_string(ID_component_name); | ||
return build_string(to_member_expr(expr).compound()) + "." + | ||
expr.get_string(ID_component_name); | ||
} | ||
|
||
if(expr.id()==ID_symbol) | ||
|
@@ -158,8 +163,7 @@ bool invariant_sett::get_object( | |
bool inv_object_storet::is_constant_address(const exprt &expr) | ||
{ | ||
if(expr.id()==ID_address_of) | ||
if(expr.operands().size()==1) | ||
return is_constant_address_rec(expr.op0()); | ||
return is_constant_address_rec(to_address_of_expr(expr).object()); | ||
|
||
return false; | ||
} | ||
|
@@ -169,15 +173,12 @@ bool inv_object_storet::is_constant_address_rec(const exprt &expr) | |
if(expr.id()==ID_symbol) | ||
return true; | ||
else if(expr.id()==ID_member) | ||
{ | ||
assert(expr.operands().size()==1); | ||
return is_constant_address_rec(expr.op0()); | ||
} | ||
return is_constant_address_rec(to_member_expr(expr).compound()); | ||
else if(expr.id()==ID_index) | ||
{ | ||
assert(expr.operands().size()==2); | ||
if(expr.op1().is_constant()) | ||
return is_constant_address_rec(expr.op0()); | ||
const auto &index_expr = to_index_expr(expr); | ||
if(index_expr.index().is_constant()) | ||
return is_constant_address_rec(index_expr.array()); | ||
} | ||
|
||
return false; | ||
|
@@ -429,14 +430,14 @@ void invariant_sett::strengthen_rec(const exprt &expr) | |
else if(expr.id()==ID_le || | ||
expr.id()==ID_lt) | ||
{ | ||
assert(expr.operands().size()==2); | ||
const auto &rel = to_binary_relation_expr(expr); | ||
|
||
// special rule: x <= (a & b) | ||
// implies: x<=a && x<=b | ||
|
||
if(expr.op1().id()==ID_bitand) | ||
if(rel.op1().id() == ID_bitand) | ||
{ | ||
const exprt &bitand_op=expr.op1(); | ||
const exprt &bitand_op = rel.op1(); | ||
|
||
forall_operands(it, bitand_op) | ||
{ | ||
|
@@ -450,12 +451,11 @@ void invariant_sett::strengthen_rec(const exprt &expr) | |
|
||
std::pair<unsigned, unsigned> p; | ||
|
||
if(get_object(expr.op0(), p.first) || | ||
get_object(expr.op1(), p.second)) | ||
if(get_object(rel.op0(), p.first) || get_object(rel.op1(), p.second)) | ||
return; | ||
|
||
const auto i0 = numeric_cast<mp_integer>(expr.op0()); | ||
const auto i1 = numeric_cast<mp_integer>(expr.op1()); | ||
const auto i0 = numeric_cast<mp_integer>(rel.op0()); | ||
const auto i1 = numeric_cast<mp_integer>(rel.op1()); | ||
|
||
if(expr.id()==ID_le) | ||
{ | ||
|
@@ -483,9 +483,9 @@ void invariant_sett::strengthen_rec(const exprt &expr) | |
} | ||
else if(expr.id()==ID_equal) | ||
{ | ||
assert(expr.operands().size()==2); | ||
const auto &equal_expr = to_equal_expr(expr); | ||
|
||
const typet &op_type=ns->follow(expr.op0().type()); | ||
const typet &op_type = ns->follow(equal_expr.op0().type()); | ||
|
||
if(op_type.id()==ID_struct) | ||
{ | ||
|
@@ -495,9 +495,9 @@ void invariant_sett::strengthen_rec(const exprt &expr) | |
for(const auto &comp : struct_type.components()) | ||
{ | ||
const member_exprt lhs_member_expr( | ||
expr.op0(), comp.get_name(), comp.type()); | ||
equal_expr.op0(), comp.get_name(), comp.type()); | ||
const member_exprt rhs_member_expr( | ||
expr.op1(), comp.get_name(), comp.type()); | ||
equal_expr.op1(), comp.get_name(), comp.type()); | ||
|
||
const equal_exprt equality(lhs_member_expr, rhs_member_expr); | ||
|
||
|
@@ -511,48 +511,51 @@ void invariant_sett::strengthen_rec(const exprt &expr) | |
// special rule: x = (a & b) | ||
// implies: x<=a && x<=b | ||
|
||
if(expr.op1().id()==ID_bitand) | ||
if(equal_expr.op1().id() == ID_bitand) | ||
{ | ||
const exprt &bitand_op=expr.op1(); | ||
const exprt &bitand_op = equal_expr.op1(); | ||
|
||
forall_operands(it, bitand_op) | ||
{ | ||
exprt tmp(expr); | ||
exprt tmp(equal_expr); | ||
tmp.op1()=*it; | ||
tmp.id(ID_le); | ||
strengthen_rec(tmp); | ||
} | ||
|
||
return; | ||
} | ||
else if(expr.op0().id()==ID_bitand) | ||
else if(equal_expr.op0().id() == ID_bitand) | ||
{ | ||
exprt tmp(expr); | ||
exprt tmp(equal_expr); | ||
std::swap(tmp.op0(), tmp.op1()); | ||
strengthen_rec(tmp); | ||
return; | ||
} | ||
|
||
// special rule: x = (type) y | ||
if(expr.op1().id()==ID_typecast) | ||
if(equal_expr.op1().id() == ID_typecast) | ||
{ | ||
assert(expr.op1().operands().size()==1); | ||
add_type_bounds(expr.op0(), expr.op1().op0().type()); | ||
const auto &typecast_expr = to_typecast_expr(equal_expr.op1()); | ||
add_type_bounds(equal_expr.op0(), typecast_expr.op().type()); | ||
} | ||
else if(expr.op0().id()==ID_typecast) | ||
else if(equal_expr.op0().id() == ID_typecast) | ||
{ | ||
assert(expr.op0().operands().size()==1); | ||
add_type_bounds(expr.op1(), expr.op0().op0().type()); | ||
const auto &typecast_expr = to_typecast_expr(equal_expr.op0()); | ||
add_type_bounds(equal_expr.op1(), typecast_expr.op().type()); | ||
} | ||
|
||
std::pair<unsigned, unsigned> p, s; | ||
|
||
if(get_object(expr.op0(), p.first) || | ||
get_object(expr.op1(), p.second)) | ||
if( | ||
get_object(equal_expr.op0(), p.first) || | ||
get_object(equal_expr.op1(), p.second)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit pick: please add braces for readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
return; | ||
} | ||
|
||
const auto i0 = numeric_cast<mp_integer>(expr.op0()); | ||
const auto i1 = numeric_cast<mp_integer>(expr.op1()); | ||
const auto i0 = numeric_cast<mp_integer>(equal_expr.op0()); | ||
const auto i1 = numeric_cast<mp_integer>(equal_expr.op1()); | ||
if(i0.has_value()) | ||
add_bounds(p.second, boundst(*i0)); | ||
else if(i1.has_value()) | ||
|
@@ -569,13 +572,16 @@ void invariant_sett::strengthen_rec(const exprt &expr) | |
} | ||
else if(expr.id()==ID_notequal) | ||
{ | ||
assert(expr.operands().size()==2); | ||
const auto ¬equal_expr = to_notequal_expr(expr); | ||
|
||
std::pair<unsigned, unsigned> p; | ||
|
||
if(get_object(expr.op0(), p.first) || | ||
get_object(expr.op1(), p.second)) | ||
if( | ||
get_object(notequal_expr.op0(), p.first) || | ||
get_object(notequal_expr.op1(), p.second)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit pick: please add braces for readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
{ | ||
return; | ||
} | ||
|
||
// check if this is a contradiction | ||
if(has_eq(p)) | ||
|
@@ -629,19 +635,19 @@ tvt invariant_sett::implies_rec(const exprt &expr) const | |
expr.id()==ID_equal || | ||
expr.id()==ID_notequal) | ||
{ | ||
assert(expr.operands().size()==2); | ||
const auto &rel = to_binary_relation_expr(expr); | ||
|
||
std::pair<unsigned, unsigned> p; | ||
|
||
bool ob0=get_object(expr.op0(), p.first); | ||
bool ob1=get_object(expr.op1(), p.second); | ||
bool ob0 = get_object(rel.op0(), p.first); | ||
bool ob1 = get_object(rel.op1(), p.second); | ||
|
||
if(ob0 || ob1) | ||
return tvt::unknown(); | ||
|
||
tvt r; | ||
|
||
if(expr.id()==ID_le) | ||
if(rel.id() == ID_le) | ||
{ | ||
r=is_le(p); | ||
if(!r.is_unknown()) | ||
|
@@ -653,7 +659,7 @@ tvt invariant_sett::implies_rec(const exprt &expr) const | |
|
||
return b0<=b1; | ||
} | ||
else if(expr.id()==ID_lt) | ||
else if(rel.id() == ID_lt) | ||
{ | ||
r=is_lt(p); | ||
if(!r.is_unknown()) | ||
|
@@ -665,9 +671,9 @@ tvt invariant_sett::implies_rec(const exprt &expr) const | |
|
||
return b0<b1; | ||
} | ||
else if(expr.id()==ID_equal) | ||
else if(rel.id() == ID_equal) | ||
return is_eq(p); | ||
else if(expr.id()==ID_notequal) | ||
else if(rel.id() == ID_notequal) | ||
return is_ne(p); | ||
else | ||
UNREACHABLE; | ||
|
@@ -717,10 +723,9 @@ void invariant_sett::nnf(exprt &expr, bool negate) | |
} | ||
else if(expr.id()==ID_not) | ||
{ | ||
assert(expr.operands().size()==1); | ||
nnf(expr.op0(), !negate); | ||
nnf(to_not_expr(expr).op(), !negate); | ||
exprt tmp; | ||
tmp.swap(expr.op0()); | ||
tmp.swap(to_not_expr(expr).op()); | ||
expr.swap(tmp); | ||
} | ||
else if(expr.id()==ID_and) | ||
|
@@ -741,14 +746,15 @@ void invariant_sett::nnf(exprt &expr, bool negate) | |
} | ||
else if(expr.id()==ID_typecast) | ||
{ | ||
assert(expr.operands().size()==1); | ||
const auto &typecast_expr = to_typecast_expr(expr); | ||
|
||
if(expr.op0().type().id()==ID_unsignedbv || | ||
expr.op0().type().id()==ID_signedbv) | ||
if( | ||
typecast_expr.op().type().id() == ID_unsignedbv || | ||
typecast_expr.op().type().id() == ID_signedbv) | ||
{ | ||
equal_exprt tmp; | ||
tmp.lhs()=expr.op0(); | ||
tmp.rhs()=from_integer(0, expr.op0().type()); | ||
tmp.lhs() = typecast_expr.op(); | ||
tmp.rhs() = from_integer(0, typecast_expr.op().type()); | ||
nnf(tmp, !negate); | ||
expr.swap(tmp); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion that I shouldn't be making because out-of-scope for this PR: we use
typecast_expr.type().id()
andtypecast_expr.op().type().id()
several times in here, maybe add some temporaries?