diff options
author | Ted Kremenek <kremenek@apple.com> | 2007-10-24 16:52:34 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2007-10-24 16:52:34 +0000 |
commit | 22c0fcba14e069bd3d35305ecd6d952f41666610 (patch) | |
tree | 2c71e3c9198bc95d72391f18bbeaa40257f7cbd4 | |
parent | c0006097e970e5e09636dc46df8d3182042640fb (diff) |
Modified operator* for StmtIterator to return Stmt*& instead of Stmt*.
This permits in-place replacement of the original AST statements.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43295 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | AST/StmtIterator.cpp | 4 | ||||
-rw-r--r-- | include/clang/AST/Decl.h | 2 | ||||
-rw-r--r-- | include/clang/AST/StmtIterator.h | 22 |
3 files changed, 14 insertions, 14 deletions
diff --git a/AST/StmtIterator.cpp b/AST/StmtIterator.cpp index b7a03bbb2c..2d198c029d 100644 --- a/AST/StmtIterator.cpp +++ b/AST/StmtIterator.cpp @@ -61,6 +61,6 @@ void StmtIteratorBase::PrevDecl() { Ptr.D = lastVD; } -Stmt* StmtIteratorBase::GetInitializer() const { - return cast<VarDecl>(Ptr.D)->getInit(); +Stmt*& StmtIteratorBase::GetInitializer() const { + return reinterpret_cast<Stmt*&>(cast<VarDecl>(Ptr.D)->Init); } diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h index adedf539e9..d06481fbdd 100644 --- a/include/clang/AST/Decl.h +++ b/include/clang/AST/Decl.h @@ -269,7 +269,7 @@ protected: private: StorageClass SClass; Expr *Init; - friend struct StmtIterator; + friend class StmtIteratorBase; }; /// BlockVarDecl - Represent a local variable declaration. diff --git a/include/clang/AST/StmtIterator.h b/include/clang/AST/StmtIterator.h index f347636fae..3752793c9f 100644 --- a/include/clang/AST/StmtIterator.h +++ b/include/clang/AST/StmtIterator.h @@ -28,7 +28,7 @@ protected: void NextDecl(); void PrevDecl(); - Stmt* GetInitializer() const; + Stmt*& GetInitializer() const; StmtIteratorBase(Stmt** s) : FirstDecl(NULL) { Ptr.S = s; } StmtIteratorBase(ScopedDecl* d); @@ -36,11 +36,11 @@ protected: }; -template <typename DERIVED, typename STMT_PTR> +template <typename DERIVED, typename REFERENCE> class StmtIteratorImpl : public StmtIteratorBase, public std::iterator<std::bidirectional_iterator_tag, - STMT_PTR, ptrdiff_t, - STMT_PTR, STMT_PTR> { + REFERENCE, ptrdiff_t, + REFERENCE, REFERENCE> { protected: StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {} public: @@ -83,17 +83,17 @@ public: return FirstDecl != RHS.FirstDecl || Ptr.S != RHS.Ptr.S; } - STMT_PTR operator*() const { - return (STMT_PTR) (FirstDecl ? GetInitializer() : *Ptr.S); + REFERENCE operator*() const { + return (REFERENCE) (FirstDecl ? GetInitializer() : *Ptr.S); } - STMT_PTR operator->() const { return operator*(); } + REFERENCE operator->() const { return operator*(); } }; -struct StmtIterator : public StmtIteratorImpl<StmtIterator,Stmt*> { - explicit StmtIterator() : StmtIteratorImpl<StmtIterator,Stmt*>() {} - StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator,Stmt*>(S) {} - StmtIterator(ScopedDecl* D) : StmtIteratorImpl<StmtIterator,Stmt*>(D) {} +struct StmtIterator : public StmtIteratorImpl<StmtIterator,Stmt*&> { + explicit StmtIterator() : StmtIteratorImpl<StmtIterator,Stmt*&>() {} + StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator,Stmt*&>(S) {} + StmtIterator(ScopedDecl* D) : StmtIteratorImpl<StmtIterator,Stmt*&>(D) {} }; struct ConstStmtIterator : public StmtIteratorImpl<ConstStmtIterator, |