本文整理汇总了C++中typet::get_bool方法的典型用法代码示例。如果您正苦于以下问题:C++ typet::get_bool方法的具体用法?C++ typet::get_bool怎么用?C++ typet::get_bool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typet
的用法示例。
在下文中一共展示了typet::get_bool方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
void c_qualifierst::read(const typet &src)
{
if(src.get_bool(ID_C_constant))
is_constant=true;
if(src.get_bool(ID_C_volatile))
is_volatile=true;
if(src.get_bool(ID_C_restricted))
is_restricted=true;
if(src.get_bool(ID_C_atomic))
is_atomic=true;
if(src.get_bool(ID_C_ptr32))
is_ptr32=true;
if(src.get_bool(ID_C_ptr64))
is_ptr64=true;
if(src.get_bool(ID_C_transparent_union))
is_transparent_union=true;
if(src.get_bool(ID_C_noreturn))
is_noreturn=true;
}
示例2: is_global_const
bool is_global_const(const irep_idt &name, const typet &type)
{
if (!type.get_bool(ID_C_constant)) return false;
const std::string &n=id2string(name);
if (std::string::npos != n.find(CEGIS_CONSTANT_PREFIX)) return true;
return std::string::npos == n.find(NS_SEP);
}
示例3: read
void c_qualifierst::read(const typet &src)
{
if(src.get_bool(ID_C_constant))
is_constant=true;
if(src.get_bool(ID_C_volatile))
is_volatile=true;
if(src.get_bool(ID_C_restricted))
is_restricted=true;
if(src.get_bool(ID_C_ptr32))
is_ptr32=true;
if(src.get_bool(ID_C_ptr64))
is_ptr64=true;
}
示例4: typecheck_symbol_type
void c_typecheck_baset::typecheck_symbol_type(typet &type)
{
{
// add prefix
symbol_typet &symbol_type=to_symbol_type(type);
symbol_type.set_identifier(add_language_prefix(symbol_type.get_identifier()));
}
// adjust identifier, if needed
replace_symbol(type);
const irep_idt &identifier=
to_symbol_type(type).get_identifier();
symbol_tablet::symbolst::const_iterator s_it=
symbol_table.symbols.find(identifier);
if(s_it==symbol_table.symbols.end())
{
err_location(type);
str << "type symbol `" << identifier << "' not found";
throw 0;
}
const symbolt &symbol=s_it->second;
if(!symbol.is_type)
{
err_location(type);
throw "expected type symbol";
}
if(symbol.is_macro)
{
// overwrite, but preserve (add) any qualifiers and other flags
c_qualifierst c_qualifiers(type);
bool is_packed=type.get_bool(ID_C_packed);
irept alignment=type.find(ID_C_alignment);
c_qualifiers+=c_qualifierst(symbol.type);
type=symbol.type;
c_qualifiers.write(type);
if(is_packed) type.set(ID_C_packed, true);
if(alignment.is_not_nil()) type.set(ID_C_alignment, alignment);
}
// CPROVER extensions
if(symbol.base_name=="__CPROVER_rational")
{
type=rational_typet();
}
else if(symbol.base_name=="__CPROVER_integer")
{
type=integer_typet();
}
}
示例5: typecheck_type
void c_typecheck_baset::typecheck_type(typet &type)
{
// we first convert, and then check
// 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)
{
}
else if(type.id()==ID_c_bitfield)
typecheck_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);
// do a bit of rule checking
if(type.get_bool(ID_C_restricted) &&
type.id()!=ID_pointer &&
type.id()!=ID_array)
{
err_location(type);
error("only a pointer can be 'restrict'");
throw 0;
}
}
示例6: typecheck_type
void cpp_typecheckt::typecheck_type(typet &type)
{
assert(!type.id().empty());
assert(type.is_not_nil());
try
{
cpp_convert_plain_type(type);
}
catch(const char *err)
{
error().source_location=type.source_location();
error() << err << eom;
throw 0;
}
catch(const std::string &err)
{
error().source_location=type.source_location();
error() << err << eom;
throw 0;
}
if(type.id()==ID_cpp_name)
{
c_qualifierst qualifiers(type);
cpp_namet cpp_name;
cpp_name.swap(type);
exprt symbol_expr=resolve(
cpp_name,
cpp_typecheck_resolvet::wantt::TYPE,
cpp_typecheck_fargst());
if(symbol_expr.id()!=ID_type)
{
error().source_location=type.source_location();
error() << "error: expected type" << eom;
throw 0;
}
type=symbol_expr.type();
assert(type.is_not_nil());
if(type.get_bool(ID_C_constant))
qualifiers.is_constant = true;
qualifiers.write(type);
}
else if(type.id()==ID_struct ||
type.id()==ID_union)
{
typecheck_compound_type(to_struct_union_type(type));
}
else if(type.id()==ID_pointer)
{
// the pointer might have a qualifier, but do subtype first
typecheck_type(type.subtype());
// Check if it is a pointer-to-member
if(type.find("to-member").is_not_nil())
{
// these can point either to data members or member functions
// of a class
typet &class_object=static_cast<typet &>(type.add("to-member"));
if(class_object.id()==ID_cpp_name)
{
assert(class_object.get_sub().back().id()=="::");
class_object.get_sub().pop_back();
}
typecheck_type(class_object);
// there may be parameters if this is a pointer to member function
if(type.subtype().id()==ID_code)
{
irept::subt ¶meters=type.subtype().add(ID_parameters).get_sub();
if(parameters.empty() ||
parameters.front().get(ID_C_base_name)!=ID_this)
{
// Add 'this' to the parameters
exprt a0(ID_parameter);
a0.set(ID_C_base_name, ID_this);
a0.type().id(ID_pointer);
a0.type().subtype() = class_object;
parameters.insert(parameters.begin(), a0);
}
}
}
}
else if(type.id()==ID_array)
{
exprt &size_expr=to_array_type(type).size();
if(size_expr.is_not_nil())
//.........这里部分代码省略.........
示例7: is_rvalue_reference
bool is_rvalue_reference(const typet &type)
{
return type.id()==ID_pointer &&
type.get_bool(ID_C_rvalue_reference);
}
示例8: if
std::string type2name(const typet &type)
{
std::string result;
// qualifiers first
if(type.get_bool(ID_C_constant))
result+="c";
if(type.get_bool(ID_C_restricted))
result+="r";
if(type.get_bool(ID_C_volatile))
result+="v";
if(type.id()==irep_idt())
throw "Empty type encountered.";
else if(type.id()==ID_empty)
result+="V";
else if(type.id()==ID_signedbv)
result+="S" + type.get_string(ID_width);
else if(type.id()==ID_unsignedbv)
result+="U" + type.get_string(ID_width);
else if(type.id()==ID_bool)
result+="B";
else if(type.id()==ID_integer)
result+="I";
else if(type.id()==ID_real)
result+="R";
else if(type.id()==ID_complex)
result+="C";
else if(type.id()==ID_floatbv)
result+="F" + type.get_string(ID_width);
else if(type.id()==ID_fixedbv)
result+="X" + type.get_string(ID_width);
else if(type.id()==ID_natural)
result+="N";
else if(type.id()==ID_pointer)
result+="*";
else if(type.id()==ID_reference)
result+="&";
else if(type.id()==ID_code)
{
const code_typet &t=to_code_type(type);
const code_typet::argumentst arguments=t.arguments();
result+="P(";
for(code_typet::argumentst::const_iterator it=arguments.begin();
it!=arguments.end();
it++)
{
result+=type2name(it->type());
result+="'" + id2string(it->get_identifier()) + "'|";
}
result.resize(result.size()-1);
result+=")";
}
else if(type.id()==ID_array)
{
const array_typet &t=to_array_type(type);
if(t.size().is_nil())
result+="ARR?";
else
result+="ARR"+t.size().get_string(ID_value);
}
else if(type.id()==ID_symbol)
{
result+="SYM#"+type.get_string(ID_identifier)+"#";
}
else if(type.id()==ID_struct ||
type.id()==ID_union)
{
if(type.id()==ID_struct) result+="ST";
if(type.id()==ID_union) result+="UN";
const struct_union_typet &t=to_struct_union_type(type);
const struct_union_typet::componentst &components = t.components();
result+="[";
for(struct_union_typet::componentst::const_iterator
it=components.begin();
it!=components.end();
it++)
{
if(it!=components.begin()) result+="|";
result+=type2name(it->type());
result+="'"+it->get_string(ID_name)+"'|";
}
result+="]";
}
else if(type.id()==ID_incomplete_struct)
result +="ST?";
else if(type.id()==ID_incomplete_union)
result +="UN?";
else if(type.id()==ID_c_enum)
result +="EN"+type.get_string(ID_width);
else if(type.id()==ID_incomplete_c_enum)
result +="EN?";
else if(type.id()==ID_c_bitfield)
result+="BF"+type.get_string(ID_size);
else if(type.id()==ID_vector)
result+="VEC"+type.get_string(ID_size);
else
//.........这里部分代码省略.........
示例9: sizeof_rec
exprt c_sizeoft::sizeof_rec(const typet &type)
{
exprt dest;
if(type.id()==ID_signedbv ||
type.id()==ID_unsignedbv ||
type.id()==ID_floatbv ||
type.id()==ID_fixedbv ||
type.id()==ID_c_enum ||
type.id()==ID_incomplete_c_enum)
{
// We round up to bytes.
// See special treatment for bit-fields below.
unsigned bits=type.get_int(ID_width);
unsigned bytes=bits/8;
if((bits%8)!=0) bytes++;
dest=from_integer(bytes, size_type());
}
else if(type.id()==ID_pointer)
{
// the following is an MS extension
if(type.get_bool(ID_C_ptr32))
return from_integer(4, size_type());
unsigned bits=config.ansi_c.pointer_width;
unsigned bytes=bits/8;
if((bits%8)!=0) bytes++;
dest=from_integer(bytes, size_type());
}
else if(type.id()==ID_bool)
{
// We fit booleans into a byte.
dest=from_integer(1, size_type());
}
else if(type.id()==ID_array)
{
const exprt &size_expr=
to_array_type(type).size();
if(size_expr.is_nil())
{
// treated like an empty array
dest=from_integer(0, size_type());
}
else
{
exprt tmp_dest=sizeof_rec(type.subtype());
if(tmp_dest.is_nil())
return tmp_dest;
mp_integer a, b;
if(!to_integer(tmp_dest, a) &&
!to_integer(size_expr, b))
{
dest=from_integer(a*b, size_type());
}
else
{
dest.id(ID_mult);
dest.type()=size_type();
dest.copy_to_operands(size_expr);
dest.move_to_operands(tmp_dest);
c_implicit_typecast(dest.op0(), dest.type(), ns);
c_implicit_typecast(dest.op1(), dest.type(), ns);
}
}
}
else if(type.id()==ID_struct)
{
const struct_typet::componentst &components=
to_struct_type(type).components();
dest=from_integer(0, size_type());
mp_integer bit_field_width=0;
for(struct_typet::componentst::const_iterator
it=components.begin();
it!=components.end();
it++)
{
const typet &sub_type=ns.follow(it->type());
if(it->get_bool(ID_is_type))
{
}
else if(sub_type.id()==ID_code)
{
}
else if(it->get_is_bit_field())
{
// this needs to be a signedbv/unsignedbv/enum
if(sub_type.id()!=ID_signedbv &&
sub_type.id()!=ID_unsignedbv &&
sub_type.id()!=ID_c_enum)
return nil_exprt();
// We just sum them up.
//.........这里部分代码省略.........
示例10: implicit_typecast_followed
void c_typecastt::implicit_typecast_followed(
exprt &expr,
const typet &src_type,
const typet &dest_type)
{
if(dest_type.id()==ID_union)
// do transparent union
if(dest_type.id()==ID_union &&
dest_type.get_bool(ID_C_transparent_union) &&
src_type.id()!=ID_union)
{
// The argument corresponding to a transparent union type can be of any
// type in the union; no explicit cast is required.
// Check union members.
const union_typet &dest_union_type=to_union_type(dest_type);
for(union_typet::componentst::const_iterator
it=dest_union_type.components().begin();
it!=dest_union_type.components().end();
it++)
{
if(!check_c_implicit_typecast(src_type, it->type()))
{
// build union constructor
exprt union_expr(ID_union, dest_union_type);
union_expr.move_to_operands(expr);
union_expr.set(ID_component_name, it->get_name());
expr=union_expr;
return; // ok
}
}
}
if(dest_type.id()==ID_pointer)
{
// special case: 0 == NULL
if(expr.is_zero() && (
src_type.id()==ID_unsignedbv ||
src_type.id()==ID_signedbv ||
src_type.id()==ID_natural ||
src_type.id()==ID_integer))
{
expr=exprt(ID_constant, dest_type);
expr.set(ID_value, ID_NULL);
return; // ok
}
if(src_type.id()==ID_pointer ||
src_type.id()==ID_array)
{
// we are quite generous about pointers
const typet &src_sub=ns.follow(src_type.subtype());
const typet &dest_sub=ns.follow(dest_type.subtype());
if(is_void_pointer(src_type) ||
is_void_pointer(dest_type))
{
// from/to void is always good
}
else if(src_sub.id()==ID_code &&
dest_sub.id()==ID_code)
{
// very generous:
// between any two function pointers it's ok
}
else if(base_type_eq(src_type.subtype(), dest_type.subtype(), ns))
{
// ok
}
else if((is_number(src_sub) || src_sub.id()==ID_c_enum) &&
(is_number(dest_sub) || dest_sub.id()==ID_c_enum))
{
// Also generous: between any to scalar types it's ok.
// We should probably check the size.
}
else
warnings.push_back("incompatible pointer types");
// check qualifiers
/*
if(src_type.subtype().get_bool(ID_C_constant) &&
!dest_type.subtype().get_bool(ID_C_constant))
warnings.push_back("disregarding const");
*/
if(src_type.subtype().get_bool(ID_C_volatile) &&
!dest_type.subtype().get_bool(ID_C_volatile))
warnings.push_back("disregarding volatile");
if(src_type==dest_type)
{
expr.type()=src_type; // because of qualifiers
}
else
do_typecast(expr, dest_type);
//.........这里部分代码省略.........
示例11: 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));
irept _typedef=type.find(ID_C_typedef);
type=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);
if(_typedef.is_not_nil())
type.add(ID_C_typedef, _typedef);
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();
//.........这里部分代码省略.........
示例12: typecheck_c_enum_type
void c_typecheck_baset::typecheck_c_enum_type(typet &type)
{
// These come with the declarations
// of the enum constants as operands.
exprt &as_expr=static_cast<exprt &>(static_cast<irept &>(type));
source_locationt source_location=type.source_location();
// We allow empty enums in the grammar to get better
// error messages.
if(as_expr.operands().empty())
{
error().source_location=source_location;
error() << "empty enum" << eom;
throw 0;
}
// enums start at zero;
// we also track min and max to find a nice base type
mp_integer value=0, min_value=0, max_value=0;
std::list<c_enum_typet::c_enum_membert> enum_members;
// We need to determine a width, and a signedness
// to obtain an 'underlying type'.
// We just do int, but gcc might pick smaller widths
// if the type is marked as 'packed'.
// gcc/clang may also pick a larger width. Visual Studio doesn't.
for(auto &op : as_expr.operands())
{
ansi_c_declarationt &declaration=to_ansi_c_declaration(op);
exprt &v=declaration.declarator().value();
if(v.is_not_nil()) // value given?
{
exprt tmp_v=v;
typecheck_expr(tmp_v);
add_rounding_mode(tmp_v);
simplify(tmp_v, *this);
if(tmp_v.is_true())
value=1;
else if(tmp_v.is_false())
value=0;
else if(!to_integer(tmp_v, value))
{
}
else
{
error().source_location=v.source_location();
error() << "enum is not a constant";
throw 0;
}
}
if(value<min_value)
min_value=value;
if(value>max_value)
max_value=value;
typet constant_type=
enum_constant_type(min_value, max_value);
v=from_integer(value, constant_type);
declaration.type()=constant_type;
typecheck_declaration(declaration);
irep_idt base_name=
declaration.declarator().get_base_name();
irep_idt identifier=
declaration.declarator().get_name();
// store
c_enum_typet::c_enum_membert member;
member.set_identifier(identifier);
member.set_base_name(base_name);
member.set_value(integer2string(value));
enum_members.push_back(member);
// produce value for next constant
++value;
}
// Remove these now; we add them to the
// c_enum symbol later.
as_expr.operands().clear();
bool is_packed=type.get_bool(ID_C_packed);
// tag?
if(type.find(ID_tag).is_nil())
{
// None, it's anonymous. We generate a tag.
std::string anon_identifier="#anon_enum";
for(const auto &member : enum_members)
{
anon_identifier+='$';
//.........这里部分代码省略.........