예제 #1
0
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(
  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;
  }
}
예제 #3
0
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";
}
예제 #4
0
literalt boolbvt::convert_typecast(const typecast_exprt &expr)
{
  assert(expr.operands().size()==1);
  
  if(expr.op0().type().id()==ID_range)
  {
    mp_integer from=string2integer(expr.op0().type().get_string(ID_from));
    mp_integer to=string2integer(expr.op0().type().get_string(ID_to));

    if(from==1 && to==1)
      return const_literal(true);
    else if(from==0 && to==0)
      return const_literal(false);
  }

  const bvt &bv=convert_bv(expr.op0());
  
  if(!bv.empty())
    return prop.lor(bv);

  return SUB::convert_rest(expr);
}
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;
  }
}