本文整理汇总了C++中namespacet::lookup方法的典型用法代码示例。如果您正苦于以下问题:C++ namespacet::lookup方法的具体用法?C++ namespacet::lookup怎么用?C++ namespacet::lookup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类namespacet
的用法示例。
在下文中一共展示了namespacet::lookup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: type_eq
bool type_eq(const typet &type1, const typet &type2, const namespacet &ns)
{
if(type1 == type2)
return true;
if(type1.id() == "symbol")
{
const symbolt &symbol = ns.lookup(type1);
if(!symbol.is_type)
throw "symbol " + id2string(symbol.name) + " is not a type";
return type_eq(symbol.type, type2, ns);
}
if(type2.id() == "symbol")
{
const symbolt &symbol = ns.lookup(type2);
if(!symbol.is_type)
throw "symbol " + id2string(symbol.name) + " is not a type";
return type_eq(type1, symbol.type, ns);
}
return false;
}
示例2: array_name
std::string array_name(
const namespacet &ns,
const exprt &expr)
{
if(expr.id()==ID_index)
{
if(expr.operands().size()!=2)
throw "index takes two operands";
return array_name(ns, expr.op0())+"[]";
}
else if(is_ssa_expr(expr))
{
const symbolt &symbol=
ns.lookup(to_ssa_expr(expr).get_object_name());
return "array `"+id2string(symbol.base_name)+"'";
}
else if(expr.id()==ID_symbol)
{
const symbolt &symbol=ns.lookup(expr);
return "array `"+id2string(symbol.base_name)+"'";
}
else if(expr.id()==ID_string_constant)
{
return "string constant";
}
else if(expr.id()==ID_member)
{
assert(expr.operands().size()==1);
return array_name(ns, expr.op0())+"."+
expr.get_string(ID_component_name);
}
return "array";
}
示例3: transform
void uninitialized_domaint::transform(
locationt from,
locationt to,
ai_baset &ai,
const namespacet &ns)
{
if(has_values.is_false())
return;
switch(from->type)
{
case DECL:
{
const irep_idt &identifier=
to_code_decl(from->code).get_identifier();
const symbolt &symbol=ns.lookup(identifier);
if(!symbol.is_static_lifetime)
uninitialized.insert(identifier);
}
break;
default:
{
std::list<exprt> read=expressions_read(*from);
std::list<exprt> written=expressions_written(*from);
forall_expr_list(it, written) assign(*it);
// we only care about the *first* uninitalized use
forall_expr_list(it, read) assign(*it);
}
}
}
示例4: if
std::unique_ptr<languaget> get_language(
const namespacet &ns,
const irep_idt &identifier)
{
if(identifier=="")
return std::unique_ptr<languaget>(get_default_language());
else
{
const symbolt *symbol;
if(ns.lookup(identifier, symbol))
return std::unique_ptr<languaget>(get_default_language());
else if(symbol->mode=="")
return std::unique_ptr<languaget>(get_default_language());
else
{
languaget *ptr=get_language_from_mode(symbol->mode);
if(ptr==NULL)
throw "symbol `"+id2string(symbol->name)+
"' has unknown mode '"+id2string(symbol->mode)+"'";
return std::unique_ptr<languaget>(ptr);
}
}
}
示例5: base_type_rec
void base_type_rec(
typet &type, const namespacet &ns, std::set<irep_idt> &symb)
{
if(type.id()==ID_symbol ||
type.id()==ID_c_enum_tag ||
type.id()==ID_struct_tag ||
type.id()==ID_union_tag)
{
const symbolt *symbol;
if(!ns.lookup(type.get(ID_identifier), symbol) &&
symbol->is_type &&
!symbol->type.is_nil())
{
type=symbol->type;
base_type_rec(type, ns, symb); // recursive call
return;
}
}
else if(type.id()==ID_array)
{
base_type_rec(to_array_type(type).subtype(), ns, symb);
}
else if(type.id()==ID_struct ||
type.id()==ID_union)
{
struct_union_typet::componentst &components=
to_struct_union_type(type).components();
for(auto &component : components)
base_type_rec(component.type(), ns, symb);
}
else if(type.id()==ID_pointer)
{
typet &subtype=to_pointer_type(type).subtype();
// we need to avoid running into an infinite loop
if(subtype.id()==ID_symbol ||
subtype.id()==ID_c_enum_tag ||
subtype.id()==ID_struct_tag ||
subtype.id()==ID_union_tag)
{
const irep_idt &id=subtype.get(ID_identifier);
if(symb.find(id)!=symb.end())
return;
symb.insert(id);
base_type_rec(subtype, ns, symb);
symb.erase(id);
}
else
base_type_rec(subtype, ns, symb);
}
}
示例6: get_new_name
/// automated variable renaming
/// \par parameters: symbol to be renamed, namespace
/// \return new symbol
void get_new_name(irep_idt &new_name, const namespacet &ns)
{
const symbolt *symbol;
if(ns.lookup(new_name, symbol))
return;
std::string prefix=id2string(new_name)+"_";
new_name=prefix+std::to_string(ns.get_max(prefix)+1);
}
示例7: get_symbols_rec
void get_symbols_rec(
const namespacet &ns,
const symbolt &symbol,
find_symbols_sett &dest)
{
dest.insert(symbol.name);
find_symbols_sett new_symbols;
find_type_and_expr_symbols(symbol.type, new_symbols);
find_type_and_expr_symbols(symbol.value, new_symbols);
if(symbol.type.id()==ID_code)
{
const code_typet &code_type=to_code_type(symbol.type);
const code_typet::parameterst ¶meters=code_type.parameters();
for(code_typet::parameterst::const_iterator
it=parameters.begin();
it!=parameters.end();
it++)
{
irep_idt id=it->get_identifier();
const symbolt *s;
// identifiers for prototypes need not exist
if(!ns.lookup(id, s)) new_symbols.insert(id);
}
}
for(find_symbols_sett::const_iterator
it=new_symbols.begin();
it!=new_symbols.end();
it++)
{
if(dest.find(*it)==dest.end())
{
dest.insert(*it);
get_symbols_rec(ns, ns.lookup(*it), dest); // recursive call
}
}
}
示例8: get_method
exprt remove_virtual_functionst::get_method(
const irep_idt &class_id,
const irep_idt &component_name) const
{
irep_idt id=id2string(class_id)+"."+
id2string(component_name);
const symbolt *symbol;
if(ns.lookup(id, symbol))
return nil_exprt();
return symbol->symbol_expr();
}
示例9: if
static std::string type2name_symbol(
const typet &type,
const namespacet &ns,
symbol_numbert &symbol_number)
{
const irep_idt &identifier=type.get(ID_identifier);
const symbolt *symbol;
if(ns.lookup(identifier, symbol))
return "SYM#"+id2string(identifier)+"#";
assert(symbol && symbol->is_type);
if(symbol->type.id()!=ID_struct &&
symbol->type.id()!=ID_union)
return type2name(symbol->type, ns, symbol_number);
std::string result;
// assign each symbol a number when seen for the first time
std::pair<symbol_numbert::iterator, bool> entry=
symbol_number.insert(std::make_pair(
identifier,
std::make_pair(symbol_number.size(), true)));
// new entry, add definition
if(entry.second)
{
result="SYM#"+std::to_string(entry.first->second.first);
result+="={";
result+=type2name(symbol->type, ns, symbol_number);
result+='}';
entry.first->second.second=false;
}
#if 0
// in recursion, print the shorthand only
else if(entry.first->second.second)
result="SYM#"+std::to_string(entry.first->second.first);
// entering recursion
else
{
entry.first->second.second=true;
result=type2name(symbol->type, ns, symbol_number);
entry.first->second.second=false;
}
#else
// shorthand only as structs/unions are always symbols
else
示例10: to_expr
exprt to_expr(
const namespacet &ns,
const irep_idt &identifier,
const std::string &src)
{
std::unique_ptr<languaget> p=get_language(ns, identifier);
const symbolt &symbol=ns.lookup(identifier);
exprt expr;
if(p->to_expr(src, id2string(symbol.module), expr, ns))
return nil_exprt();
return expr;
}
示例11: simplify
int configt::ansi_ct::from_ns(const namespacet &ns, const std::string &what)
{
const irep_idt id="c::__CPROVER_architecture_"+what;
const symbolt *symbol;
if(ns.lookup(id, symbol))
throw "failed to find "+id2string(id);
exprt tmp=symbol->value;
simplify(tmp, ns);
mp_integer int_value;
if(to_integer(tmp, int_value))
throw "failed to convert "+id2string(id);
return integer2long(int_value);
}
示例12: make_expr_passive_rec
void predicatest::make_expr_passive_rec(
exprt& phi,
const namespacet& ns,
const unsigned subscript)
{
Forall_operands(it, phi)
make_expr_passive_rec(*it, ns, subscript);
if(phi.id()==ID_symbol)
{
symbol_exprt &phi_sym=to_symbol_expr(phi);
const irep_idt &identifier=phi_sym.get_identifier();
assert(identifier.as_string().find('#')==std::string::npos);
if(is_procedure_local(ns.lookup(identifier)))
{
std::ostringstream os;
os << identifier << '#' << subscript;
phi_sym.set_identifier(os.str());
}
}
}
示例13: from_ns
static unsigned from_ns(
const namespacet &ns,
const std::string &what)
{
const irep_idt id=CPROVER_PREFIX "architecture_"+what;
const symbolt *symbol;
if(ns.lookup(id, symbol))
throw "failed to find "+id2string(id);
exprt tmp=symbol->value;
simplify(tmp, ns);
if(tmp.id()!=ID_constant)
throw "symbol table configuration entry `"+id2string(id)+"' is not a constant";
mp_integer int_value;
if(to_integer(to_constant_expr(tmp), int_value))
throw "failed to convert symbol table configuration entry `"+id2string(id)+"'";
return integer2unsigned(int_value);
}
示例14: string_from_ns
static irep_idt string_from_ns(
const namespacet &ns,
const std::string &what)
{
const irep_idt id=CPROVER_PREFIX "architecture_"+what;
const symbolt *symbol;
if(ns.lookup(id, symbol))
throw "failed to find "+id2string(id);
const exprt &tmp=symbol->value;
if(tmp.id()!=ID_address_of ||
tmp.operands().size()!=1 ||
tmp.op0().id()!=ID_index ||
tmp.op0().operands().size()!=2 ||
tmp.op0().op0().id()!=ID_string_constant)
{
throw "symbol table configuration entry `"+id2string(id)+"' is not a string constant";
}
return tmp.op0().op0().get(ID_value);
}
示例15: find_macros
void find_macros(
const exprt &src,
const namespacet &ns,
find_macros_sett &dest)
{
std::stack<const exprt *> stack;
// use stack, these may be nested deeply
stack.push(&src);
while(!stack.empty())
{
const exprt &e=*stack.top();
stack.pop();
if(e.id()==ID_symbol ||
e.id()==ID_next_symbol)
{
const irep_idt &identifier=e.get(ID_identifier);
const symbolt &symbol=ns.lookup(identifier);
if(symbol.is_macro)
{
// inserted?
if(dest.insert(identifier).second)
stack.push(&symbol.value);
}
}
else
{
forall_operands(it, e)
stack.push(&(*it));
}
}
}