}
/// \class ScanReachableSymbols
-/// A Utility class that allows to visit the reachable symbols using a custom
-/// SymbolVisitor.
+/// A utility class that visits the reachable symbols using a custom
+/// SymbolVisitor. Terminates recursive traversal when the visitor function
+/// returns false.
class ScanReachableSymbols {
typedef llvm::DenseSet<const void*> VisitedItems;
}
bool ScanReachableSymbols::scan(const SymExpr *sym) {
- bool wasVisited = !visited.insert(sym).second;
- if (wasVisited)
- return true;
-
- if (!visitor.VisitSymbol(sym))
- return false;
+ for (SymExpr::symbol_iterator SI = sym->symbol_begin(),
+ SE = sym->symbol_end();
+ SI != SE; ++SI) {
+ bool wasVisited = !visited.insert(*SI).second;
+ if (wasVisited)
+ continue;
- // TODO: should be rewritten using SymExpr::symbol_iterator.
- switch (sym->getKind()) {
- case SymExpr::SymbolRegionValueKind:
- case SymExpr::SymbolConjuredKind:
- case SymExpr::SymbolDerivedKind:
- case SymExpr::SymbolExtentKind:
- case SymExpr::SymbolMetadataKind:
- break;
- case SymExpr::SymbolCastKind:
- return scan(cast<SymbolCast>(sym)->getOperand());
- case SymExpr::SymIntExprKind:
- return scan(cast<SymIntExpr>(sym)->getLHS());
- case SymExpr::IntSymExprKind:
- return scan(cast<IntSymExpr>(sym)->getRHS());
- case SymExpr::SymSymExprKind: {
- const SymSymExpr *x = cast<SymSymExpr>(sym);
- return scan(x->getLHS()) && scan(x->getRHS());
- }
+ if (!visitor.VisitSymbol(*SI))
+ return false;
}
+
return true;
}