本文整理汇总了C++中tl::Type::is_pointer方法的典型用法代码示例。如果您正苦于以下问题:C++ Type::is_pointer方法的具体用法?C++ Type::is_pointer怎么用?C++ Type::is_pointer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tl::Type
的用法示例。
在下文中一共展示了Type::is_pointer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute_pointer_vars_size_rec
void PointerSize::compute_pointer_vars_size_rec(Node* current)
{
if(current->is_visited())
return;
current->set_visited(true);
if(current->is_graph_node())
{
compute_pointer_vars_size_rec(current->get_graph_entry_node());
}
else
{
if(current->has_statements())
{
NBase s;
NBase value;
TL::Type t;
NodeclList stmts = current->get_statements();
for(NodeclList::iterator it = stmts.begin(); it != stmts.end(); ++it)
{
// If assignment (or object init) check whether its for is a dynamic allocation of resources for a pointer type
if(it->is<Nodecl::ObjectInit>() || it->is<Nodecl::Assignment>())
{
// Get the variable assigned and the value used for the assignment
if(it->is<Nodecl::ObjectInit>())
{
Symbol tmp(it->get_symbol());
s = Nodecl::Symbol::make(tmp);
t = tmp.get_type();
s.set_type(t);
value = tmp.get_value().no_conv();
}
else if(it->is<Nodecl::Assignment>())
{
s = it->as<Nodecl::Assignment>().get_lhs().no_conv();
t = s.get_type().no_ref();
if(!s.is<Nodecl::Symbol>() && !s.is<Nodecl::ClassMemberAccess>() && !s.is<Nodecl::ArraySubscript>())
continue;
value = it->as<Nodecl::Assignment>().get_rhs().no_conv();
}
// Check whether this is a pointer and the assignment is a recognized memory operation
if(t.is_pointer() && !value.is_null()) // This can be null if uninitialized ObjectInit
{
if(value.is<Nodecl::FunctionCall>())
{
Symbol called_sym = value.as<Nodecl::FunctionCall>().get_called().get_symbol();
Type return_t = called_sym.get_type().returns();
Nodecl::List args = value.as<Nodecl::FunctionCall>().get_arguments().as<Nodecl::List>();
std::string sym_name = called_sym.get_name();
NBase size = NBase::null();
if((sym_name == "malloc") && (args.size() == 1))
{ // void* malloc (size_t size);
Type arg0_t = args[0].get_type();
if(return_t.is_pointer() && return_t.points_to().is_void() && arg0_t.is_same_type(get_size_t_type()))
{ // We recognize the form 'sizeof(base_type) * n_elemes' and 'n_elemes * sizeof(base_type)'
if(args[0].is<Nodecl::Mul>())
{
NBase lhs = args[0].as<Nodecl::Mul>().get_lhs().no_conv();
NBase rhs = args[0].as<Nodecl::Mul>().get_rhs().no_conv();
if(lhs.is<Nodecl::Sizeof>() && (rhs.is<Nodecl::IntegerLiteral>() || rhs.is<Nodecl::Symbol>()))
size = rhs;
else if(rhs.is<Nodecl::Sizeof>() && (lhs.is<Nodecl::IntegerLiteral>() || lhs.is<Nodecl::Symbol>()))
size = lhs;
}
}
}
else if((sym_name == "calloc") && (args.size() == 2))
{ // void* calloc (size_t num, size_t size);
Type arg0_t = args[0].get_type();
Type arg1_t = args[1].get_type();
if(return_t.is_pointer() && return_t.points_to().is_void()
&& arg0_t.is_same_type(get_size_t_type())
&& arg1_t.is_same_type(get_size_t_type()))
{
size = args[0];
}
}
if(!size.is_null())
_pcfg->set_pointer_n_elems(s, size);
}
}
// Clear up the common variables s, value and t
s = NBase::null();
value = NBase::null();
t = Type();
}
}
}
}
// Keep iterating over the children
ObjectList<Node*> children = current->get_children();
for(ObjectList<Node*>::iterator it = children.begin(); it != children.end(); ++it)
compute_pointer_vars_size_rec(*it);
}