Skip to content

Commit 1c7a8ab

Browse files
author
Sonny Martin
committed
Code cleanup
1 parent 0097e74 commit 1c7a8ab

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

src/util/simplify_expr.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,17 +1365,12 @@ bool simplify_exprt::simplify_update(exprt &expr)
13651365
{
13661366
const irep_idt &component_name=
13671367
e.get(ID_component_name);
1368-
1369-
if(!to_struct_type(value_ptr_type).
1370-
has_component(component_name))
1368+
const struct_typet &value_ptr_struct_type=to_struct_type(value_ptr_type);
1369+
if(!value_ptr_struct_type.has_component(component_name))
13711370
return true;
1372-
1373-
std::size_t number=to_struct_type(value_ptr_type).
1374-
component_number(component_name);
1375-
1376-
CHECK_RETURN(number < value_ptr->operands().size());
1377-
1378-
value_ptr=&value_ptr->operands()[number];
1371+
auto &designator_as_struct_expr = to_struct_expr(*value_ptr);
1372+
value_ptr = &designator_as_struct_expr.component(component_name, ns);
1373+
CHECK_RETURN(value_ptr->id() != ID_nil);
13791374
}
13801375
else
13811376
return true; // give up, unknown designator
@@ -1407,18 +1402,13 @@ bool simplify_exprt::simplify_object(exprt &expr)
14071402
}
14081403
else if(expr.id()==ID_typecast)
14091404
{
1410-
const typet &op_type=ns.follow(expr.op0().type());
1411-
1412-
DATA_INVARIANT(
1413-
expr.operands().size() == 1,
1414-
"typecasts must have exactly one argument");
1405+
auto const& typecast_expr = to_typecast_expr(expr);
1406+
const typet &op_type=ns.follow(typecast_expr.op().type());
14151407

14161408
if(op_type.id()==ID_pointer)
14171409
{
14181410
// cast from pointer to pointer
1419-
exprt tmp;
1420-
tmp.swap(expr.op0());
1421-
expr.swap(tmp);
1411+
expr = typecast_expr.op();
14221412
simplify_object(expr);
14231413
return false;
14241414
}
@@ -1429,10 +1419,10 @@ bool simplify_exprt::simplify_object(exprt &expr)
14291419
// We do a bit of special treatment for (TYPE *)(a+(int)&o) and
14301420
// (TYPE *)(a+(int)((T*)&o+x)), which are re-written to '&o'.
14311421

1432-
exprt tmp=expr.op0();
1433-
if(tmp.id()==ID_plus && tmp.operands().size()==2)
1422+
exprt casted_expr=typecast_expr.op();
1423+
if(casted_expr.id()==ID_plus && casted_expr.operands().size()==2)
14341424
{
1435-
exprt cand=tmp.op0().id()==ID_typecast?tmp.op0():tmp.op1();
1425+
exprt cand=casted_expr.op0().id()==ID_typecast?casted_expr.op0():casted_expr.op1();
14361426

14371427
if(cand.id()==ID_typecast &&
14381428
cand.operands().size()==1 &&

src/util/simplify_expr_boolean.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,12 @@ bool simplify_exprt::simplify_not(exprt &expr)
213213
}
214214
else if(op.id()==ID_exists) // !(exists: a) <-> forall: not a
215215
{
216-
DATA_INVARIANT(
217-
op.operands().size() == 2,
218-
"exists expression has two parameters");
219-
exprt tmp;
220-
tmp.swap(op);
221-
expr.swap(tmp);
222-
expr.id(ID_forall);
223-
expr.op1().make_not();
224-
simplify_node(expr.op1());
216+
auto const& op_as_exists = to_exists_expr(op);
217+
forall_exprt rewritten_op(op_as_exists.symbol()
218+
, op_as_exists.where());
219+
rewritten_op.where().make_not();
220+
simplify_node(rewritten_op.where());
221+
expr = rewritten_op;
225222
return false;
226223
}
227224

src/util/std_expr.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4512,6 +4512,22 @@ class exists_exprt:public quantifier_exprt
45124512
}
45134513
};
45144514

4515+
inline const exists_exprt &to_exists_expr(const exprt &expr)
4516+
{
4517+
PRECONDITION(expr.id() == ID_exists);
4518+
DATA_INVARIANT(expr.operands().size()== 2,
4519+
"exists expressions have exactly two operands");
4520+
return static_cast<const exists_exprt&>(expr);
4521+
}
4522+
4523+
inline exists_exprt &to_exists_expr(exprt &expr)
4524+
{
4525+
PRECONDITION(expr.id() == ID_exists);
4526+
DATA_INVARIANT(expr.operands().size()== 2,
4527+
"exists expressions have exactly two operands");
4528+
return static_cast<exists_exprt&>(expr);
4529+
}
4530+
45154531
/// \brief The popcount (counting the number of bits set to 1) expression
45164532
class popcount_exprt: public unary_exprt
45174533
{

0 commit comments

Comments
 (0)