diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-09-09 00:06:04 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-09-09 00:06:04 +0000 |
commit | b037185b52556e011023dcdb622b46a4f1284e9a (patch) | |
tree | b15ed6f81ff50f7c2fa2eb33d8af9b25910d7f44 /clang/lib/Analysis/CFG.cpp | |
parent | fd525ef338f4001f2515e865952cbbe6c4105aa3 (diff) | |
download | bcm5719-llvm-b037185b52556e011023dcdb622b46a4f1284e9a.tar.gz bcm5719-llvm-b037185b52556e011023dcdb622b46a4f1284e9a.zip |
Add 'filtered_pred_iterator' and 'filtered_succ_iterator' to CFGBlock. This allows a client
to selectively walk successors/predecessors based on commonly used filters. For starters, add
a filter to ignore 'default:' cases for SwitchStmts when all enum values are covered by CaseStmts.
llvm-svn: 113449
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r-- | clang/lib/Analysis/CFG.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index f0e48700d3b..3dae83b564f 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -1937,6 +1937,29 @@ unsigned CFG::getNumBlkExprs() { } //===----------------------------------------------------------------------===// +// Filtered walking of the CFG. +//===----------------------------------------------------------------------===// + +bool CFGBlock::FilterEdge(const CFGBlock::FilterOptions &F, + const CFGBlock *From, const CFGBlock *To) { + + if (F.IgnoreDefaultsWithCoveredEnums) { + // If the 'To' has no label or is labeled but the label isn't a + // CaseStmt then filter this edge. + if (const SwitchStmt *S = + dyn_cast_or_null<SwitchStmt>(From->getTerminator())) { + if (S->isAllEnumCasesCovered()) { + const Stmt *L = To->getLabel(); + if (!L || !isa<CaseStmt>(L)) + return true; + } + } + } + + return false; +} + +//===----------------------------------------------------------------------===// // Cleanup: CFG dstor. //===----------------------------------------------------------------------===// |