本文整理汇总了C++中Exp::isTerminal方法的典型用法代码示例。如果您正苦于以下问题:C++ Exp::isTerminal方法的具体用法?C++ Exp::isTerminal怎么用?C++ Exp::isTerminal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exp
的用法示例。
在下文中一共展示了Exp::isTerminal方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: substitute
// Substitute s into all members of the set
void LocationSet::substitute(Assign& a)
{
Exp* lhs = a.getLeft();
if (lhs == NULL) return;
Exp* rhs = a.getRight();
if (rhs == NULL) return; // ? Will this ever happen?
std::set<Exp*, lessExpStar>::iterator it;
// Note: it's important not to change the pointer in the set of pointers to expressions, without removing and
// inserting again. Otherwise, the set becomes out of order, and operations such as set comparison fail!
// To avoid any funny behaviour when iterating the loop, we use the following two sets
LocationSet removeSet; // These will be removed after the loop
LocationSet removeAndDelete; // These will be removed then deleted
LocationSet insertSet; // These will be inserted after the loop
bool change;
for (it = lset.begin(); it != lset.end(); it++)
{
Exp* loc = *it;
Exp* replace;
if (loc->search(lhs, replace))
{
if (rhs->isTerminal())
{
// This is no longer a location of interest (e.g. %pc)
removeSet.insert(loc);
continue;
}
loc = loc->clone()->searchReplaceAll(lhs, rhs, change);
if (change)
{
loc = loc->simplifyArith();
loc = loc->simplify();
// If the result is no longer a register or memory (e.g.
// r[28]-4), then delete this expression and insert any
// components it uses (in the example, just r[28])
if (!loc->isRegOf() && !loc->isMemOf())
{
// Note: can't delete the expression yet, because the
// act of insertion into the remove set requires silent
// calls to the compare function
removeAndDelete.insert(*it);
loc->addUsedLocs(insertSet);
continue;
}
// Else we just want to replace it
// Regardless of whether the top level expression pointer has
// changed, remove and insert it from the set of pointers
removeSet.insert(*it); // Note: remove the unmodified ptr
insertSet.insert(loc);
}
}
}
makeDiff(removeSet); // Remove the items to be removed
makeDiff(removeAndDelete); // These are to be removed as well
makeUnion(insertSet); // Insert the items to be added
// Now delete the expressions that are no longer needed
std::set<Exp*, lessExpStar>::iterator dd;
for (dd = removeAndDelete.lset.begin(); dd != removeAndDelete.lset.end();
dd++)
delete *dd; // Plug that memory leak
}