本文整理汇总了C++中typet::source_location方法的典型用法代码示例。如果您正苦于以下问题:C++ typet::source_location方法的具体用法?C++ typet::source_location怎么用?C++ typet::source_location使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类typet
的用法示例。
在下文中一共展示了typet::source_location方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: typecheck_symbol_type
void c_typecheck_baset::typecheck_symbol_type(typet &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())
{
error().source_location=type.source_location();
error() << "type symbol `" << identifier << "' not found"
<< eom;
throw 0;
}
const symbolt &symbol=s_it->second;
if(!symbol.is_type)
{
error().source_location=type.source_location();
error() << "expected type symbol" << eom;
throw 0;
}
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();
}
}
示例2: convert_with
void boolbvt::convert_with(
const typet &type,
const exprt &op1,
const exprt &op2,
const bvt &prev_bv,
bvt &next_bv)
{
// we only do that on arrays, bitvectors, structs, and unions
next_bv.resize(prev_bv.size());
if(type.id()==ID_array)
return convert_with_array(to_array_type(type), op1, op2, prev_bv, next_bv);
else if(type.id()==ID_bv ||
type.id()==ID_unsignedbv ||
type.id()==ID_signedbv)
return convert_with_bv(type, op1, op2, prev_bv, next_bv);
else if(type.id()==ID_struct)
return convert_with_struct(to_struct_type(type), op1, op2, prev_bv, next_bv);
else if(type.id()==ID_union)
return convert_with_union(to_union_type(type), op1, op2, prev_bv, next_bv);
else if(type.id()==ID_symbol)
return convert_with(ns.follow(type), op1, op2, prev_bv, next_bv);
error().source_location=type.source_location();
error() << "unexpected with type: " << type.id();
throw 0;
}
示例3: find_constructor
void cpp_typecheckt::find_constructor(
const typet &start_dest_type,
exprt &constructor_expr)
{
constructor_expr.make_nil();
source_locationt source_location=start_dest_type.source_location();
typet dest_type(start_dest_type);
follow_symbol(dest_type);
if(dest_type.id()!=ID_struct)
return;
const struct_typet::componentst &components=
to_struct_type(dest_type).components();
for(struct_typet::componentst::const_iterator
it=components.begin();
it!=components.end();
it++)
{
const struct_typet::componentt &component=*it;
const typet &type=component.type();
if(type.find(ID_return_type).id()==ID_constructor)
{
const irept::subt ¶meters=
type.find(ID_parameters).get_sub();
namespacet ns(symbol_table);
if(parameters.size()==1)
{
const exprt ¶meter=(exprt &)parameters.front();
const typet &arg_type=parameter.type();
if(arg_type.id()==ID_pointer &&
type_eq(arg_type.subtype(), dest_type, ns))
{
// found!
const irep_idt &identifier=
component.get(ID_name);
if(identifier=="")
throw "constructor without identifier";
constructor_expr=exprt(ID_symbol, type);
constructor_expr.set(ID_identifier, identifier);
constructor_expr.add_source_location()=source_location;
return;
}
}
}
}
}
示例4: read
void ansi_c_convert_typet::read(const typet &type)
{
clear();
source_location=type.source_location();
read_rec(type);
if(!aligned &&
type.find(ID_C_alignment).is_not_nil())
{
aligned=true;
alignment=static_cast<const exprt &>(type.find(ID_C_alignment));
}
}
示例5: typecheck_typeof_type
void c_typecheck_baset::typecheck_typeof_type(typet &type)
{
// save location
source_locationt source_location=type.source_location();
// 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());
}
type.add_source_location()=source_location;
c_qualifiers.write(type);
}
示例6: typecheck_enum_type
void cpp_typecheckt::typecheck_enum_type(typet &type)
{
// first save qualifiers
c_qualifierst qualifiers;
qualifiers.read(type);
cpp_enum_typet &enum_type=to_cpp_enum_type(type);
bool anonymous=!enum_type.has_tag();
irep_idt base_name;
if(anonymous)
{
// we fabricate a tag based on the enum constants contained
base_name=enum_type.generate_anon_tag();
}
else
{
const cpp_namet &tag=enum_type.tag();
if(tag.is_simple_name())
base_name=tag.get_base_name();
else
{
err_location(type);
throw "enum tag is expected to be a simple name";
}
}
bool has_body=enum_type.has_body();
bool tag_only_declaration=enum_type.get_tag_only_declaration();
cpp_scopet &dest_scope=
tag_scope(base_name, has_body, tag_only_declaration);
const irep_idt symbol_name=
dest_scope.prefix+"tag-"+id2string(base_name);
// check if we have it
symbol_tablet::symbolst::iterator previous_symbol=
symbol_table.symbols.find(symbol_name);
if(previous_symbol!=symbol_table.symbols.end())
{
// we do!
symbolt &symbol=previous_symbol->second;
if(has_body)
{
err_location(type);
str << "error: enum symbol `" << base_name
<< "' declared previously\n";
str << "location of previous definition: "
<< symbol.location;
throw 0;
}
}
else if(has_body)
{
std::string pretty_name=
cpp_scopes.current_scope().prefix+id2string(base_name);
// C++11 enumerations have an underlying type,
// which defaults to int.
// enums without underlying type may be 'packed'.
if(type.subtype().is_nil())
type.subtype()=signed_int_type();
else
{
typecheck_type(type.subtype());
if(type.subtype().id()==ID_signedbv ||
type.subtype().id()==ID_unsignedbv)
{
}
else
{
err_location(type);
str << "underlying type must be integral";
throw 0;
}
}
symbolt symbol;
symbol.name=symbol_name;
symbol.base_name=base_name;
symbol.value.make_nil();
symbol.location=type.source_location();
symbol.mode=ID_cpp;
symbol.module=module;
symbol.type.swap(type);
symbol.is_type=true;
symbol.is_macro=false;
symbol.pretty_name=pretty_name;
// move early, must be visible before doing body
symbolt *new_symbol;
if(symbol_table.move(symbol, new_symbol))
throw "cpp_typecheckt::typecheck_enum_type: symbol_table.move() failed";
//.........这里部分代码省略.........
示例7: 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())
//.........这里部分代码省略.........
示例8: read
void ansi_c_convert_typet::read(const typet &type)
{
clear();
source_location=type.source_location();
read_rec(type);
}
示例9: typecheck_type
//.........这里部分代码省略.........
else if(mode=="__SI__") // 32 bits
result=is_signed?signed_int_type():unsigned_int_type();
else if(mode=="__word__") // long int, we think
result=is_signed?signed_long_int_type():unsigned_long_int_type();
else if(mode=="__pointer__") // we think this is size_t/ssize_t
result=is_signed?signed_size_type():size_type();
else if(mode=="__DI__") // 64 bits
{
if(config.ansi_c.long_int_width==64)
result=is_signed?signed_long_int_type():unsigned_long_int_type();
else
{
assert(config.ansi_c.long_long_int_width==64);
result=
is_signed?signed_long_long_int_type():unsigned_long_long_int_type();
}
}
else if(mode=="__TI__") // 128 bits
result=is_signed?gcc_signed_int128_type():gcc_unsigned_int128_type();
else if(mode=="__V2SI__") // vector of 2 ints, deprecated by gcc
result=
vector_typet(
is_signed?signed_int_type():unsigned_int_type(),
from_integer(2, size_type()));
else if(mode=="__V4SI__") // vector of 4 ints, deprecated by gcc
result=
vector_typet(
is_signed?signed_int_type():unsigned_int_type(),
from_integer(4, size_type()));
else // give up, just use subtype
result=type.subtype();
// save the location
result.add_source_location()=type.source_location();
if(type.subtype().id()==ID_c_enum_tag)
{
const irep_idt &tag_name=
to_c_enum_tag_type(type.subtype()).get_identifier();
symbol_tablet::symbolst::iterator entry=
symbol_table.symbols.find(tag_name);
assert(entry!=symbol_table.symbols.end());
entry->second.type.subtype()=result;
}
type=result;
}
else if(underlying_type.id()==ID_floatbv)
{
typet result;
if(mode=="__SF__") // 32 bits
result=float_type();
else if(mode=="__DF__") // 64 bits
result=double_type();
else if(mode=="__TF__") // 128 bits
result=gcc_float128_type();
else if(mode=="__V2SF__") // vector of 2 floats, deprecated by gcc
result=vector_typet(float_type(), from_integer(2, size_type()));
else if(mode=="__V2DF__") // vector of 2 doubles, deprecated by gcc
result=vector_typet(double_type(), from_integer(2, size_type()));
else if(mode=="__V4SF__") // vector of 4 floats, deprecated by gcc
result=vector_typet(float_type(), from_integer(4, size_type()));
else if(mode=="__V4DF__") // vector of 4 doubles, deprecated by gcc
示例10: 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+='$';
//.........这里部分代码省略.........