[cfe-commits] r43520 - /cfe/trunk/AST/CFG.cpp
Ted Kremenek
kremenek at apple.com
Tue Oct 30 14:48:35 PDT 2007
Author: kremenek
Date: Tue Oct 30 16:48:34 2007
New Revision: 43520
URL: http://llvm.org/viewvc/llvm-project?rev=43520&view=rev
Log:
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.
Modified:
cfe/trunk/AST/CFG.cpp
Modified: cfe/trunk/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/CFG.cpp?rev=43520&r1=43519&r2=43520&view=diff
==============================================================================
--- cfe/trunk/AST/CFG.cpp (original)
+++ cfe/trunk/AST/CFG.cpp Tue Oct 30 16:48:34 2007
@@ -113,7 +113,7 @@
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 @@
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 @@
};
}
-/// 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;
}
More information about the cfe-commits
mailing list