本文整理汇总了C++中goto_programt::compute_location_numbers方法的典型用法代码示例。如果您正苦于以下问题:C++ goto_programt::compute_location_numbers方法的具体用法?C++ goto_programt::compute_location_numbers怎么用?C++ goto_programt::compute_location_numbers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类goto_programt
的用法示例。
在下文中一共展示了goto_programt::compute_location_numbers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convert
void convert( const irept &irep, goto_programt &program )
{
assert(irep.id()=="goto-program");
program.instructions.clear();
std::list< std::list<unsigned> > number_targets_list;
// convert instructions back
const irept::subt &subs = irep.get_sub();
for (irept::subt::const_iterator it=subs.begin();
it!=subs.end();
it++)
{
program.instructions.push_back(goto_programt::instructiont());
convert(*it, program.instructions.back());
number_targets_list.push_back(std::list<unsigned>());
const irept &targets=it->find(ID_targets);
const irept::subt &tsubs=targets.get_sub();
for (irept::subt::const_iterator tit=tsubs.begin();
tit!=tsubs.end();
tit++)
{
number_targets_list.back().push_back(
unsafe_string2unsigned(tit->id_string()));
}
}
program.compute_location_numbers();
// resolve targets
std::list< std::list<unsigned> >::iterator nit=
number_targets_list.begin();
for(goto_programt::instructionst::iterator lit=
program.instructions.begin();
lit!=program.instructions.end() && nit!=number_targets_list.end();
lit++, nit++)
{
for (std::list<unsigned>::iterator tit=nit->begin();
tit!=nit->end();
tit++)
{
goto_programt::targett fit=program.instructions.begin();
for(;fit!=program.instructions.end();fit++)
{
if (fit->location_number==*tit)
{
lit->targets.push_back(fit);
break;
}
}
if (fit==program.instructions.end())
{
std::cout << "Warning: could not resolve target link "
<< "during irep->goto_program translation." << std::endl;
throw 0;
}
}
}
program.update();
}
示例2: convert
//.........这里部分代码省略.........
xmlt::elementst::const_iterator eit = it->elements.begin();
for(; eit != it->elements.end(); eit++)
{
if(eit->name=="location")
{
convert(*eit, inst->location);
}
else if(eit->name=="variables")
{
}
else if(eit->name=="labels")
{
xmlt::elementst::const_iterator lit = eit->elements.begin();
for(; lit != eit->elements.end(); lit++)
{
if(lit->name=="label")
{
std::string ls = lit->get_attribute("name");
inst->labels.push_back(ls);
}
else
{
std::cout << "Unknown node in labels section." << std::endl;
return;
}
}
}
else if(eit->name=="guard")
{
inst->guard.remove("value");
convert(*eit, inst->guard);
}
else if(eit->name=="code")
{
convert(*eit, inst->code);
}
else if(eit->name=="targets")
{
// Don't do anything here, we'll need a second run for that
}
else if(eit->name=="comment")
{
inst->location.set("comment", eit->data);
}
else if(eit->name=="function")
{
inst->function = eit->data;
}
}
}
// assign line numbers
goto_program.compute_location_numbers();
// second run, for targets
goto_programt::targett ins_it = instructions.begin();
it = xml.elements.begin();
for(; it != xml.elements.end() && ins_it!=instructions.end(); it++)
{
xmlt::elementst::const_iterator eit = it->elements.begin();
for(; eit != it->elements.end(); eit++)
{
if(eit->name=="targets")
{
xmlt::elementst::const_iterator tit = eit->elements.begin();
for(; tit != eit->elements.end(); tit++)
{
if(tit->name=="target")
{
goto_programt::targett tins =
find_instruction(xml, instructions, tit->data);
if(tins != instructions.end())
{
// Here we insert the iterators that somehow seem
// to be strange afterwards (see line 87)
ins_it->targets.push_back(tins);
}
else
{
std::cout << "Warning: instruction not found when "
"resolving target links." << std::endl;
}
}
else
{
std::cout << "Unknown node in targets section." << std::endl;
return;
}
}
}
}
ins_it++;
}
// resolve links
goto_program.update();
// std::cout << "TNI: " << goto_program.target_numbers.size() << std::endl;
}