[cfe-commits] r43295 - in /cfe/trunk: AST/StmtIterator.cpp include/clang/AST/Decl.h include/clang/AST/StmtIterator.h
Steve Naroff
snaroff at apple.com
Wed Oct 24 10:55:45 PDT 2007
On Oct 24, 2007, at 9:52 AM, Ted Kremenek wrote:
> Author: kremenek
> Date: Wed Oct 24 11:52:34 2007
> New Revision: 43295
>
> URL: http://llvm.org/viewvc/llvm-project?rev=43295&view=rev
> Log:
> Modified operator* for StmtIterator to return Stmt*& instead of Stmt*.
> This permits in-place replacement of the original AST statements.
>
Thanks Ted. This will be put to good use!
snaroff
> Modified:
> cfe/trunk/AST/StmtIterator.cpp
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/include/clang/AST/StmtIterator.h
>
> Modified: cfe/trunk/AST/StmtIterator.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/
> StmtIterator.cpp?rev=43295&r1=43294&r2=43295&view=diff
>
> ======================================================================
> ========
> --- cfe/trunk/AST/StmtIterator.cpp (original)
> +++ cfe/trunk/AST/StmtIterator.cpp Wed Oct 24 11:52:34 2007
> @@ -61,6 +61,6 @@
> 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);
> }
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
> AST/Decl.h?rev=43295&r1=43294&r2=43295&view=diff
>
> ======================================================================
> ========
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Wed Oct 24 11:52:34 2007
> @@ -269,7 +269,7 @@
> private:
> StorageClass SClass;
> Expr *Init;
> - friend struct StmtIterator;
> + friend class StmtIteratorBase;
> };
>
> /// BlockVarDecl - Represent a local variable declaration.
>
> Modified: cfe/trunk/include/clang/AST/StmtIterator.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/
> AST/StmtIterator.h?rev=43295&r1=43294&r2=43295&view=diff
>
> ======================================================================
> ========
> --- cfe/trunk/include/clang/AST/StmtIterator.h (original)
> +++ cfe/trunk/include/clang/AST/StmtIterator.h Wed Oct 24 11:52:34
> 2007
> @@ -28,7 +28,7 @@
>
> 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 @@
> };
>
>
> -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 @@
> 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,
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list