From: Ted Kremenek Date: Mon, 29 Oct 2007 18:04:38 +0000 (+0000) Subject: Renamed internal variables of StmtIteratorBase to make the code X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=65f31e451c8d631f0e76cb9c8935465d68830cb1;p=clang Renamed internal variables of StmtIteratorBase to make the code slightly more succinct. Introduced VariableArrayType* within StmtIteratorBase to (soon) support iteration over the size expressions of variable length arrays. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43455 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/AST/StmtIterator.cpp b/AST/StmtIterator.cpp index bcf495a9ae..7a516a781f 100644 --- a/AST/StmtIterator.cpp +++ b/AST/StmtIterator.cpp @@ -30,12 +30,12 @@ static inline bool declHasExpr(ScopedDecl *decl) { } void StmtIteratorBase::NextDecl() { - assert (FirstDecl && Ptr.D); + assert (FirstDecl && decl); - do Ptr.D = Ptr.D->getNextDeclarator(); - while (Ptr.D != NULL && !declHasExpr(Ptr.D)); + do decl = decl->getNextDeclarator(); + while (decl != NULL && !declHasExpr(decl)); - if (Ptr.D == NULL) FirstDecl = NULL; + if (decl == NULL) FirstDecl = NULL; } StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) { @@ -45,12 +45,12 @@ StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) { d = d->getNextDeclarator(); FirstDecl = d; - Ptr.D = d; + decl = d; } void StmtIteratorBase::PrevDecl() { assert (FirstDecl); - assert (Ptr.D != FirstDecl); + assert (decl != FirstDecl); // March through the list of decls until we find the decl just before // the one we currently point @@ -58,7 +58,7 @@ void StmtIteratorBase::PrevDecl() { ScopedDecl* d = FirstDecl; ScopedDecl* lastVD = d; - while (d->getNextDeclarator() != Ptr.D) { + while (d->getNextDeclarator() != decl) { if (VarDecl* V = dyn_cast(d)) if (V->getInit()) lastVD = d; @@ -66,14 +66,14 @@ void StmtIteratorBase::PrevDecl() { d = d->getNextDeclarator(); } - Ptr.D = lastVD; + decl = lastVD; } Stmt*& StmtIteratorBase::GetDeclExpr() const { - if (VarDecl* D = dyn_cast(Ptr.D)) + if (VarDecl* D = dyn_cast(decl)) return reinterpret_cast(D->Init); else { - EnumConstantDecl* Decl = cast(Ptr.D); + EnumConstantDecl* Decl = cast(decl); return reinterpret_cast(Decl->Init); } } diff --git a/include/clang/AST/StmtIterator.h b/include/clang/AST/StmtIterator.h index 14c6aed3d4..714c3bd058 100644 --- a/include/clang/AST/StmtIterator.h +++ b/include/clang/AST/StmtIterator.h @@ -20,19 +20,21 @@ namespace clang { class Stmt; class ScopedDecl; - +class VariableArrayType; + class StmtIteratorBase { protected: - union { Stmt** S; ScopedDecl* D; } Ptr; + union { Stmt** stmt; ScopedDecl* decl; }; ScopedDecl* FirstDecl; + VariableArrayType* vat; void NextDecl(); void PrevDecl(); Stmt*& GetDeclExpr() const; - StmtIteratorBase(Stmt** s) : FirstDecl(NULL) { Ptr.S = s; } + StmtIteratorBase(Stmt** s) : stmt(s), FirstDecl(NULL), vat(NULL) {} StmtIteratorBase(ScopedDecl* d); - StmtIteratorBase() : FirstDecl(NULL) { Ptr.S = NULL; } + StmtIteratorBase() : stmt(NULL), FirstDecl(NULL), vat(NULL) {} }; @@ -51,7 +53,7 @@ public: DERIVED& operator++() { if (FirstDecl) NextDecl(); - else ++Ptr.S; + else ++stmt; return static_cast(*this); } @@ -64,7 +66,7 @@ public: DERIVED& operator--() { if (FirstDecl) PrevDecl(); - else --Ptr.S; + else --stmt; return static_cast(*this); } @@ -76,15 +78,15 @@ public: } bool operator==(const DERIVED& RHS) const { - return FirstDecl == RHS.FirstDecl && Ptr.S == RHS.Ptr.S; + return FirstDecl == RHS.FirstDecl && stmt == RHS.stmt; } bool operator!=(const DERIVED& RHS) const { - return FirstDecl != RHS.FirstDecl || Ptr.S != RHS.Ptr.S; + return FirstDecl != RHS.FirstDecl || stmt != RHS.stmt; } REFERENCE operator*() const { - return (REFERENCE) (FirstDecl ? GetDeclExpr() : *Ptr.S); + return (REFERENCE) (FirstDecl ? GetDeclExpr() : *stmt); } REFERENCE operator->() const { return operator*(); }