aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2007-10-30 21:48:34 +0000
committerTed Kremenek <kremenek@apple.com>2007-10-30 21:48:34 +0000
commit8f54c1faaa94c789883d426109796fd62b81a044 (patch)
tree62148cd5c1fc551897e59f4232d3bc2e96576168
parent9e32d4b4a7270a9701b7cb454381eeaa4cc42a77 (diff)
Refactored CFG construction code that processes DeclStmts to use StmtIterator.
Now CFG construction transparently supports Variable Length Array declarations with expressions for their sizes, and typedefs that include VLAs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43520 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--AST/CFG.cpp44
1 files changed, 21 insertions, 23 deletions
diff --git a/AST/CFG.cpp b/AST/CFG.cpp
index 42f401b847..4a54b469cc 100644
--- a/AST/CFG.cpp
+++ b/AST/CFG.cpp
@@ -113,7 +113,7 @@ private:
CFGBlock* addStmt(Stmt* S);
CFGBlock* WalkAST(Stmt* S, bool AlwaysAddStmt);
CFGBlock* WalkAST_VisitChildren(Stmt* S);
- CFGBlock* WalkAST_VisitVarDecl(VarDecl* D);
+ CFGBlock* WalkAST_VisitDeclSubExprs(StmtIterator& I);
CFGBlock* WalkAST_VisitStmtExpr(StmtExpr* S);
CFGBlock* WalkAST_VisitCallExpr(CallExpr* C);
void FinishBlock(CFGBlock* B);
@@ -266,12 +266,13 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* S, bool AlwaysAddStmt = false) {
return addStmt(C->getCond());
}
- case Stmt::DeclStmtClass:
- if (VarDecl* V = dyn_cast<VarDecl>(cast<DeclStmt>(S)->getDecl())) {
- Block->appendStmt(S);
- return WalkAST_VisitVarDecl(V);
- }
- else return Block;
+ case Stmt::DeclStmtClass: {
+ ScopedDecl* D = cast<DeclStmt>(S)->getDecl();
+ Block->appendStmt(S);
+
+ StmtIterator I(D);
+ return WalkAST_VisitDeclSubExprs(I);
+ }
case Stmt::AddrLabelExprClass: {
AddrLabelExpr* A = cast<AddrLabelExpr>(S);
@@ -325,22 +326,19 @@ CFGBlock* CFGBuilder::WalkAST(Stmt* S, bool AlwaysAddStmt = false) {
};
}
-/// WalkAST_VisitVarDecl - Utility method to handle VarDecls contained in
-/// DeclStmts. Because the initialization code for declarations can
-/// contain arbitrary expressions, we must linearize declarations
-/// to handle arbitrary control-flow induced by those expressions.
-CFGBlock* CFGBuilder::WalkAST_VisitVarDecl(VarDecl* V) {
- // We actually must parse the LAST declaration in a chain of
- // declarations first, because we are building the CFG in reverse
- // order.
- if (Decl* D = V->getNextDeclarator())
- if (VarDecl* Next = cast<VarDecl>(D))
- Block = WalkAST_VisitVarDecl(Next);
-
- if (Expr* E = V->getInit())
- return addStmt(E);
-
- assert (Block);
+/// WalkAST_VisitDeclSubExprs - Utility method to handle Decls contained in
+/// DeclStmts. Because the initialization code (and sometimes the
+/// the type declarations) for DeclStmts can contain arbitrary expressions,
+/// we must linearize declarations to handle arbitrary control-flow induced by
+/// those expressions.
+CFGBlock* CFGBuilder::WalkAST_VisitDeclSubExprs(StmtIterator& I) {
+ Stmt* S = *I;
+ ++I;
+
+ if (I != StmtIterator())
+ WalkAST_VisitDeclSubExprs(I);
+
+ Block = addStmt(S);
return Block;
}