From: Ted Kremenek Date: Tue, 30 Oct 2007 21:48:34 +0000 (+0000) Subject: Refactored CFG construction code that processes DeclStmts to use StmtIterator. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f54c1faaa94c789883d426109796fd62b81a044;p=clang 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 --- 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(cast(S)->getDecl())) { - Block->appendStmt(S); - return WalkAST_VisitVarDecl(V); - } - else return Block; + case Stmt::DeclStmtClass: { + ScopedDecl* D = cast(S)->getDecl(); + Block->appendStmt(S); + + StmtIterator I(D); + return WalkAST_VisitDeclSubExprs(I); + } case Stmt::AddrLabelExprClass: { AddrLabelExpr* A = cast(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(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; }