[cfe-commits] r54368 - in /cfe/trunk: include/clang/AST/Stmt.h lib/AST/Stmt.cpp lib/Analysis/CheckDeadStores.cpp lib/Analysis/LiveVariables.cpp lib/Analysis/UninitializedValues.cpp
Ted Kremenek
kremenek at apple.com
Tue Aug 5 13:47:00 PDT 2008
Author: kremenek
Date: Tue Aug 5 15:46:55 2008
New Revision: 54368
URL: http://llvm.org/viewvc/llvm-project?rev=54368&view=rev
Log:
Added decl_iterator to DeclStmt to provide an abstract interface to iterate over the ScopedDecls of a DeclStmt.
Updated a few clients of DeclStmt::getNextDeclarator() to use decl_iterator instead. Will update other clients after additional testing.
Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/lib/Analysis/CheckDeadStores.cpp
cfe/trunk/lib/Analysis/LiveVariables.cpp
cfe/trunk/lib/Analysis/UninitializedValues.cpp
Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=54368&r1=54367&r2=54368&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Aug 5 15:46:55 2008
@@ -162,10 +162,25 @@
}
static bool classof(const DeclStmt *) { return true; }
- // Iterators
+ // Iterators over subexpressions.
virtual child_iterator child_begin();
virtual child_iterator child_end();
+ // Iterators over the decls.
+ class decl_iterator {
+ ScopedDecl* D;
+ public:
+ decl_iterator(ScopedDecl *d) : D(d) {}
+ bool operator==(const decl_iterator& I) const { return D == I.D; }
+ bool operator!=(const decl_iterator& I) const { return D != I.D; }
+ ScopedDecl* operator*() const { return D; }
+ decl_iterator& operator++();
+ };
+
+ virtual decl_iterator decl_begin() { return TheDecl; }
+ virtual decl_iterator decl_end() { return 0; }
+
+ // Serialization.
virtual void EmitImpl(llvm::Serializer& S) const;
static DeclStmt* CreateImpl(llvm::Deserializer& D, ASTContext& C);
};
Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=54368&r1=54367&r2=54368&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Tue Aug 5 15:46:55 2008
@@ -193,6 +193,11 @@
Stmt::child_iterator DeclStmt::child_begin() { return getDecl(); }
Stmt::child_iterator DeclStmt::child_end() { return child_iterator(); }
+DeclStmt::decl_iterator& DeclStmt::decl_iterator::operator++() {
+ D = D->getNextDeclarator();
+ return *this;
+}
+
// NullStmt
Stmt::child_iterator NullStmt::child_begin() { return child_iterator(); }
Stmt::child_iterator NullStmt::child_end() { return child_iterator(); }
Modified: cfe/trunk/lib/Analysis/CheckDeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckDeadStores.cpp?rev=54368&r1=54367&r2=54368&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckDeadStores.cpp Tue Aug 5 15:46:55 2008
@@ -161,9 +161,10 @@
else if (DeclStmt* DS = dyn_cast<DeclStmt>(S))
// Iterate through the decls. Warn if any initializers are complex
// expressions that are not live (never used).
- for (ScopedDecl* SD = DS->getDecl(); SD; SD = SD->getNextDeclarator()) {
+ for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE=DS->decl_end();
+ DI != DE; ++DI) {
- VarDecl* V = dyn_cast<VarDecl>(SD);
+ VarDecl* V = dyn_cast<VarDecl>(*DI);
if (!V)
continue;
Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=54368&r1=54367&r2=54368&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Tue Aug 5 15:46:55 2008
@@ -229,8 +229,9 @@
void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
// Declarations effectively "kill" a variable since they cannot
// possibly be live before they are declared.
- for (ScopedDecl* D = DS->getDecl(); D != NULL; D = D->getNextDeclarator())
- if (VarDecl* VD = dyn_cast<VarDecl>(D)) {
+ for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE = DS->decl_end();
+ DI != DE; ++DI)
+ if (VarDecl* VD = dyn_cast<VarDecl>(*DI)) {
// Update liveness information.
unsigned bit = AD.getIdx(VD);
Modified: cfe/trunk/lib/Analysis/UninitializedValues.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/UninitializedValues.cpp?rev=54368&r1=54367&r2=54368&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/UninitializedValues.cpp (original)
+++ cfe/trunk/lib/Analysis/UninitializedValues.cpp Tue Aug 5 15:46:55 2008
@@ -131,8 +131,8 @@
}
bool TransferFuncs::VisitDeclStmt(DeclStmt* S) {
- for (ScopedDecl* D = S->getDecl(); D != NULL; D = D->getNextDeclarator()) {
- VarDecl *VD = dyn_cast<VarDecl>(D);
+ for (DeclStmt::decl_iterator I=S->decl_begin(), E=S->decl_end(); I!=E; ++I) {
+ VarDecl *VD = dyn_cast<VarDecl>(*I);
if (VD && VD->isBlockVarDecl()) {
if (Stmt* I = VD->getInit())
V(VD,AD) = AD.FullUninitTaint ? V(cast<Expr>(I),AD) : Initialized;
More information about the cfe-commits
mailing list