Modified operator* for StmtIterator to return Stmt*& instead of Stmt*.

This permits in-place replacement of the original AST statements.

llvm-svn: 43295
This commit is contained in:
Ted Kremenek 2007-10-24 16:52:34 +00:00
parent 544f860f59
commit 38f87dd9d0
3 changed files with 14 additions and 14 deletions

View File

@ -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);
}

View File

@ -269,7 +269,7 @@ protected:
private:
StorageClass SClass;
Expr *Init;
friend struct StmtIterator;
friend class StmtIteratorBase;
};
/// BlockVarDecl - Represent a local variable declaration.

View File

@ -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,