本文整理汇总了C++中typet::swap方法的典型用法代码示例。如果您正苦于以下问题:C++ typet::swap方法的具体用法?C++ typet::swap怎么用?C++ typet::swap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typet
的用法示例。
在下文中一共展示了typet::swap方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: typecheck_typeof_type
void c_typecheck_baset::typecheck_typeof_type(typet &type)
{
// retain the qualifiers as is
c_qualifierst c_qualifiers;
c_qualifiers.read(type);
if(!((const exprt &)type).has_operands())
{
typet t=static_cast<const typet &>(type.find(ID_type_arg));
typecheck_type(t);
type.swap(t);
}
else
{
exprt expr=((const exprt &)type).op0();
typecheck_expr(expr);
// undo an implicit address-of
if(expr.id()==ID_address_of &&
expr.get_bool(ID_C_implicit))
{
assert(expr.operands().size()==1);
exprt tmp;
tmp.swap(expr.op0());
expr.swap(tmp);
}
type.swap(expr.type());
}
c_qualifiers.write(type);
}
示例2: typecheck_c_bit_field_type
void c_typecheck_baset::typecheck_c_bit_field_type(typet &type)
{
typecheck_type(type.subtype());
exprt &width_expr=static_cast<exprt &>(type.add(ID_size));
typecheck_expr(width_expr);
make_constant_index(width_expr);
mp_integer i;
if(to_integer(width_expr, i))
{
err_location(type);
throw "failed to convert bit field width";
}
if(i<0)
{
err_location(type);
throw "bit field width is negative";
}
const typet &base_type=follow(type.subtype());
if(base_type.id()==ID_bool)
{
if(i>1)
{
err_location(type);
throw "bit field width too large";
}
// We don't use bool, as it's really a byte long.
type.id(ID_unsignedbv);
type.set(ID_width, integer2long(i));
}
else if(base_type.id()==ID_signedbv ||
base_type.id()==ID_unsignedbv ||
base_type.id()==ID_c_enum)
{
unsigned width=base_type.get_int(ID_width);
if(i>width)
{
err_location(type);
throw "bit field width too large";
}
typet tmp(base_type);
type.swap(tmp);
type.set(ID_width, integer2string(i));
}
else
{
err_location(type);
str << "bit field with non-integer type: "
<< to_string(base_type);
throw 0;
}
}
示例3: adjust_function_parameter
void c_typecheck_baset::adjust_function_parameter(typet &type) const
{
if(type.id()==ID_array)
{
type.id(ID_pointer);
type.remove(ID_size);
type.remove(ID_C_constant);
}
else if(type.id()==ID_code)
{
// see ISO/IEC 9899:1999 page 199 clause 8
pointer_typet tmp;
tmp.subtype()=type;
type.swap(tmp);
}
else if(type.id()==ID_KnR)
{
// any KnR args without type yet?
type=signed_int_type(); // the default is integer!
}
}
示例4: write
void ansi_c_convert_typet::write(typet &type)
{
type.clear();
// first, do "other"
if(!other.empty())
{
if(
double_cnt || float_cnt || signed_cnt || unsigned_cnt || int_cnt ||
bool_cnt || short_cnt || char_cnt || int8_cnt || int16_cnt || int32_cnt ||
int64_cnt || ptr32_cnt || ptr64_cnt || long_cnt)
{
err_location(location);
error("illegal type modifier for defined type");
throw 0;
}
if(other.size() != 1)
{
err_location(location);
error("illegal combination of defined types");
throw 0;
}
type.swap(other.front());
}
else if(double_cnt || float_cnt)
{
if(
signed_cnt || unsigned_cnt || int_cnt || bool_cnt || int8_cnt ||
int16_cnt || int32_cnt || int64_cnt || ptr32_cnt || ptr64_cnt ||
short_cnt || char_cnt)
{
err_location(location);
error("cannot conbine integer type with float");
throw 0;
}
if(double_cnt && float_cnt)
{
err_location(location);
error("conflicting type modifiers");
throw 0;
}
if(long_cnt == 0)
{
if(double_cnt != 0)
type = double_type();
else
type = float_type();
}
else if(long_cnt == 1 || long_cnt == 2)
{
if(double_cnt != 0)
type = long_double_type();
else
{
err_location(location);
error("conflicting type modifiers");
throw 0;
}
}
else
{
err_location(location);
error("illegal type modifier for float");
throw 0;
}
}
else if(bool_cnt)
{
if(
signed_cnt || unsigned_cnt || int_cnt || short_cnt || int8_cnt ||
int16_cnt || int32_cnt || int64_cnt || ptr32_cnt || ptr64_cnt ||
char_cnt || long_cnt)
{
err_location(location);
error("illegal type modifier for boolean type");
throw 0;
}
type.id("bool");
}
else if(ptr32_cnt || ptr64_cnt)
{
type.id("pointer");
type.subtype() = typet("empty");
}
else
{
// it is integer -- signed or unsigned?
if(signed_cnt && unsigned_cnt)
{
err_location(location);
error("conflicting type modifiers");
throw 0;
}
//.........这里部分代码省略.........
示例5: write
void ansi_c_convert_typet::write(typet &type)
{
type.clear();
// first, do "other"
if(!other.empty())
{
if(double_cnt || float_cnt || signed_cnt ||
unsigned_cnt || int_cnt || c_bool_cnt || proper_bool_cnt ||
short_cnt || char_cnt || complex_cnt || long_cnt ||
int8_cnt || int16_cnt || int32_cnt || int64_cnt ||
gcc_float128_cnt || gcc_int128_cnt || bv_cnt)
{
err_location(location);
error("illegal type modifier for defined type");
throw 0;
}
if(other.size()!=1)
{
err_location(location);
error("illegal combination of defined types");
throw 0;
}
type.swap(other.front());
}
else if(gcc_float128_cnt)
{
if(signed_cnt || unsigned_cnt || int_cnt || c_bool_cnt || proper_bool_cnt ||
int8_cnt || int16_cnt || int32_cnt || int64_cnt ||
gcc_int128_cnt || bv_cnt ||
short_cnt || char_cnt)
{
err_location(location);
error("cannot combine integer type with float");
throw 0;
}
if(long_cnt || double_cnt || float_cnt)
{
err_location(location);
error("conflicting type modifiers");
throw 0;
}
type=long_double_type();
}
else if(double_cnt || float_cnt)
{
if(signed_cnt || unsigned_cnt || int_cnt || c_bool_cnt || proper_bool_cnt ||
int8_cnt || int16_cnt || int32_cnt || int64_cnt ||
gcc_int128_cnt|| bv_cnt ||
short_cnt || char_cnt)
{
err_location(location);
error("cannot combine integer type with float");
throw 0;
}
if(double_cnt && float_cnt)
{
err_location(location);
error("conflicting type modifiers");
throw 0;
}
if(long_cnt==0)
{
if(double_cnt!=0)
type=double_type();
else
type=float_type();
}
else if(long_cnt==1 || long_cnt==2)
{
if(double_cnt!=0)
type=long_double_type();
else
{
err_location(location);
error("conflicting type modifiers");
throw 0;
}
}
else
{
err_location(location);
error("illegal type modifier for float");
throw 0;
}
}
else if(c_bool_cnt)
{
if(signed_cnt || unsigned_cnt || int_cnt || short_cnt ||
int8_cnt || int16_cnt || int32_cnt || int64_cnt ||
gcc_float128_cnt || bv_cnt || proper_bool_cnt ||
char_cnt || long_cnt)
{
//.........这里部分代码省略.........
示例6: typecheck_type
void c_typecheck_baset::typecheck_type(typet &type)
{
// we first convert, and then check
{
ansi_c_convert_typet ansi_c_convert_type(get_message_handler());
ansi_c_convert_type.read(type);
ansi_c_convert_type.write(type);
}
if(type.id()==ID_already_typechecked)
{
// need to preserve any qualifiers
c_qualifierst c_qualifiers(type);
c_qualifiers+=c_qualifierst(type.subtype());
bool packed=type.get_bool(ID_C_packed);
exprt alignment=static_cast<const exprt &>(type.find(ID_C_alignment));
type.swap(type.subtype());
c_qualifiers.write(type);
if(packed)
type.set(ID_C_packed, true);
if(alignment.is_not_nil())
type.add(ID_C_alignment, alignment);
return; // done
}
// do we have alignment?
if(type.find(ID_C_alignment).is_not_nil())
{
exprt &alignment=static_cast<exprt &>(type.add(ID_C_alignment));
if(alignment.id()!=ID_default)
{
typecheck_expr(alignment);
make_constant(alignment);
}
}
if(type.id()==ID_code)
typecheck_code_type(to_code_type(type));
else if(type.id()==ID_array)
typecheck_array_type(to_array_type(type));
else if(type.id()==ID_pointer)
typecheck_type(type.subtype());
else if(type.id()==ID_struct ||
type.id()==ID_union)
typecheck_compound_type(to_struct_union_type(type));
else if(type.id()==ID_c_enum)
typecheck_c_enum_type(type);
else if(type.id()==ID_c_enum_tag)
typecheck_c_enum_tag_type(to_c_enum_tag_type(type));
else if(type.id()==ID_c_bit_field)
typecheck_c_bit_field_type(to_c_bit_field_type(type));
else if(type.id()==ID_typeof)
typecheck_typeof_type(type);
else if(type.id()==ID_symbol)
typecheck_symbol_type(type);
else if(type.id()==ID_vector)
typecheck_vector_type(to_vector_type(type));
else if(type.id()==ID_custom_unsignedbv ||
type.id()==ID_custom_signedbv ||
type.id()==ID_custom_floatbv ||
type.id()==ID_custom_fixedbv)
typecheck_custom_type(type);
else if(type.id()==ID_gcc_attribute_mode)
{
// get that mode
irep_idt mode=type.get(ID_size);
// A list of all modes ist at
// http://www.delorie.com/gnu/docs/gcc/gccint_53.html
typecheck_type(type.subtype());
typet underlying_type=type.subtype();
// gcc allows this, but clang doesn't; it's a compiler hint only,
// but we'll try to interpret it the GCC way
if(underlying_type.id()==ID_c_enum_tag)
{
underlying_type=
follow_tag(to_c_enum_tag_type(underlying_type)).subtype();
assert(underlying_type.id()==ID_signedbv ||
underlying_type.id()==ID_unsignedbv);
}
if(underlying_type.id()==ID_signedbv ||
underlying_type.id()==ID_unsignedbv)
{
bool is_signed=underlying_type.id()==ID_signedbv;
typet result;
if(mode=="__QI__") // 8 bits
result=is_signed?signed_char_type():unsigned_char_type();
else if(mode=="__byte__") // 8 bits
result=is_signed?signed_char_type():unsigned_char_type();
else if(mode=="__HI__") // 16 bits
//.........这里部分代码省略.........