本文整理汇总了C++中BlockList::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ BlockList::erase方法的具体用法?C++ BlockList::erase怎么用?C++ BlockList::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockList
的用法示例。
在下文中一共展示了BlockList::erase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: optimize
/** Perform simple tests to remove redundant blocks. */
void optimize(BlockList & blocks)
{
int changes = 1;
while (changes > 0)
{
changes = 0;
BlockIter it = blocks.begin();
while (it != blocks.end())
{
// Negative start indicates block is unreachable.
if ((*it)->start < 0)
{
it = blocks.erase(it);
++changes;
}
// A block can be removed if it has no statements
// and does not change locking status.
else if ((*it)->stmts.size() == 0 && !(*it)->unlock)
{
int start = (*it)->start;
// cerr << "\nRemoving " << start << endl;
Node closure = (*it)->closure;
int transfer = (*it)->transfer;
for (BlockIter ib = blocks.begin(); ib != blocks.end(); ++ib)
{
if ((*ib)->start == transfer && closure !=0)
(*ib)->closure = closure;
if ((*ib)->transfer == start)
(*ib)->transfer = transfer;
if ((*ib)->altTransfer == start)
(*ib)->altTransfer = transfer;
}
it = blocks.erase(it);
++changes;
}
else
++it;
}
// Build a set of all labels in use
set<int> labels;
for (BlockIter it = blocks.begin(); it != blocks.end(); ++it)
{
labels.insert((*it)->transfer);
labels.insert((*it)->altTransfer);
// Include addresses of option nodes
for (ListIter is = (*it)->stmts.begin(); is != (*it)->stmts.end(); ++is)
{
NodeKind k = (*is)->kind();
if (k == OPTION_NODE || k == RECEIVE_OPTION_NODE || k == SEND_OPTION_NODE)
labels.insert((*it)->start);
}
}
// cerr << "Labels: ";
// for (set<int>::iterator it = labels.begin(); it != labels.end(); ++it)
// cerr << ' ' << *it;
// cerr << endl;
it = blocks.begin();
while (it != blocks.end())
{
if ((*it)->closure == 0 && labels.find((*it)->start) == labels.end())
{
it = blocks.erase(it);
++changes;
}
else
++it;
}
}
}