bool remove_const_function_pointerst::try_resolve_typecast( const typecast_exprt &typecast_expr, expressionst &out_expressions, bool &out_is_const) { expressionst typecast_values; bool typecast_const; bool resolved= try_resolve_expression( typecast_expr.op(), typecast_values, typecast_const); if(resolved) { out_expressions.insert( out_expressions.end(), typecast_values.begin(), typecast_values.end()); out_is_const=typecast_const; return true; } else { LOG("Could not resolve typecast value", typecast_expr); return false; } }
exprt dereferencet::dereference_typecast( const typecast_exprt &expr, const exprt &offset, const typet &type) { const exprt &op=expr.op(); const typet &op_type=ns.follow(op.type()); // pointer type cast? if(op_type.id()==ID_pointer) return dereference_rec(op, offset, type); // just pass down else if(op_type.id()==ID_signedbv || op_type.id()==ID_unsignedbv) { // We got an integer-typed address A. We turn this back (!) // into *(type *)(A+offset), and then let some other layer // worry about it. exprt integer=op; if(!offset.is_zero()) integer= plus_exprt(offset, typecast_exprt(op, offset.type())); exprt new_typecast= typecast_exprt(integer, pointer_typet(type)); return dereference_exprt(new_typecast, type); } else throw "dereferencet: unexpected cast"; }
bvt boolbvt::convert_bv_typecast(const typecast_exprt &expr) { const typet &expr_type=ns.follow(expr.type()); const exprt &op=expr.op(); const typet &op_type=ns.follow(op.type()); const bvt &op_bv=convert_bv(op); bvt bv; if(type_conversion(op_type, op_bv, expr_type, bv)) return conversion_failed(expr); return bv; }
bool remove_const_function_pointerst::try_resolve_typecast_function_call( const typecast_exprt &typecast_expr, functionst &out_functions) { // We simply ignore typecasts and assume they are valid // I thought simplify_expr would deal with this, but for example // a cast from a 32 bit width int to a 64bit width int it doesn't seem // to allow functionst typecast_values; bool resolved= try_resolve_function_call(typecast_expr.op(), typecast_values); if(resolved) { out_functions.insert(typecast_values.begin(), typecast_values.end()); return true; } else { LOG("Failed to squash typecast", typecast_expr); return false; } }