Skip to content

Commit 61af061

Browse files
author
Daniel Kroening
committed
added typecast_exprt::conditional_cast
1 parent 376beab commit 61af061

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/util/std_expr.h

+9
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,15 @@ class typecast_exprt:public unary_exprt
21112111
unary_exprt(ID_typecast, op, _type)
21122112
{
21132113
}
2114+
2115+
// returns a typecast if the type doesn't already match
2116+
static exprt conditional_cast(const exprt &expr, const typet &type)
2117+
{
2118+
if(expr.type() == type)
2119+
return expr;
2120+
else
2121+
return typecast_exprt(expr, type);
2122+
}
21142123
};
21152124

21162125
/*! \brief Cast a generic exprt to a \ref typecast_exprt

0 commit comments

Comments
 (0)