зеркало из https://github.com/microsoft/clang.git
Add StmtIterator support for iterating over both the condition
variable initializer and the other expressions in an IfStmt. This change required adding a 'DoDestroy()' method for IfStmt that did not include destroying the initializer (since that is owned by the VarDecl). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92089 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
8a69366a1c
Коммит
35628d1f17
|
@ -624,9 +624,9 @@ class IfStmt : public Stmt {
|
|||
SourceLocation ElseLoc;
|
||||
|
||||
public:
|
||||
IfStmt(SourceLocation IL, VarDecl *Var, Expr *cond, Stmt *then,
|
||||
IfStmt(SourceLocation IL, VarDecl *var, Expr *cond, Stmt *then,
|
||||
SourceLocation EL = SourceLocation(), Stmt *elsev = 0)
|
||||
: Stmt(IfStmtClass), Var(Var), IfLoc(IL), ElseLoc(EL) {
|
||||
: Stmt(IfStmtClass), Var(var), IfLoc(IL), ElseLoc(EL) {
|
||||
SubExprs[COND] = reinterpret_cast<Stmt*>(cond);
|
||||
SubExprs[THEN] = then;
|
||||
SubExprs[ELSE] = elsev;
|
||||
|
@ -674,9 +674,13 @@ public:
|
|||
}
|
||||
static bool classof(const IfStmt *) { return true; }
|
||||
|
||||
// Iterators
|
||||
// Iterators over subexpressions. The iterators will include iterating
|
||||
// over the initialization expression referenced by the condition variable.
|
||||
virtual child_iterator child_begin();
|
||||
virtual child_iterator child_end();
|
||||
|
||||
protected:
|
||||
virtual void DoDestroy(ASTContext &Ctx);
|
||||
};
|
||||
|
||||
/// SwitchStmt - This represents a 'switch' stmt.
|
||||
|
|
|
@ -66,7 +66,7 @@ protected:
|
|||
Stmt*& GetDeclExpr() const;
|
||||
|
||||
StmtIteratorBase(Stmt **s) : stmt(s), decl(0), RawVAPtr(0) {}
|
||||
StmtIteratorBase(Decl *d);
|
||||
StmtIteratorBase(Decl *d, Stmt **s);
|
||||
StmtIteratorBase(VariableArrayType *t);
|
||||
StmtIteratorBase(Decl **dgi, Decl **dge);
|
||||
StmtIteratorBase() : stmt(0), decl(0), RawVAPtr(0) {}
|
||||
|
@ -82,9 +82,9 @@ protected:
|
|||
StmtIteratorImpl(const StmtIteratorBase& RHS) : StmtIteratorBase(RHS) {}
|
||||
public:
|
||||
StmtIteratorImpl() {}
|
||||
StmtIteratorImpl(Stmt** s) : StmtIteratorBase(s) {}
|
||||
StmtIteratorImpl(Decl** dgi, Decl** dge) : StmtIteratorBase(dgi, dge) {}
|
||||
StmtIteratorImpl(Decl* d) : StmtIteratorBase(d) {}
|
||||
StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
|
||||
StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
|
||||
StmtIteratorImpl(Decl *d, Stmt **s) : StmtIteratorBase(d, s) {}
|
||||
StmtIteratorImpl(VariableArrayType* t) : StmtIteratorBase(t) {}
|
||||
|
||||
DERIVED& operator++() {
|
||||
|
@ -125,11 +125,15 @@ struct StmtIterator : public StmtIteratorImpl<StmtIterator,Stmt*&> {
|
|||
explicit StmtIterator() : StmtIteratorImpl<StmtIterator,Stmt*&>() {}
|
||||
|
||||
StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator,Stmt*&>(S) {}
|
||||
|
||||
StmtIterator(Decl** dgi, Decl** dge)
|
||||
: StmtIteratorImpl<StmtIterator,Stmt*&>(dgi, dge) {}
|
||||
|
||||
StmtIterator(VariableArrayType* t):StmtIteratorImpl<StmtIterator,Stmt*&>(t) {}
|
||||
StmtIterator(Decl* D) : StmtIteratorImpl<StmtIterator,Stmt*&>(D) {}
|
||||
StmtIterator(VariableArrayType* t)
|
||||
: StmtIteratorImpl<StmtIterator,Stmt*&>(t) {}
|
||||
|
||||
StmtIterator(Decl* D, Stmt **s = 0)
|
||||
: StmtIteratorImpl<StmtIterator,Stmt*&>(D, s) {}
|
||||
};
|
||||
|
||||
struct ConstStmtIterator : public StmtIteratorImpl<ConstStmtIterator,
|
||||
|
|
|
@ -455,8 +455,21 @@ Stmt::child_iterator LabelStmt::child_begin() { return &SubStmt; }
|
|||
Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; }
|
||||
|
||||
// IfStmt
|
||||
Stmt::child_iterator IfStmt::child_begin() { return &SubExprs[0]; }
|
||||
Stmt::child_iterator IfStmt::child_end() { return &SubExprs[0]+END_EXPR; }
|
||||
Stmt::child_iterator IfStmt::child_begin() {
|
||||
return child_iterator(Var, &SubExprs[0]);
|
||||
}
|
||||
Stmt::child_iterator IfStmt::child_end() {
|
||||
return child_iterator(0, &SubExprs[0]+END_EXPR);
|
||||
}
|
||||
void IfStmt::DoDestroy(ASTContext &C) {
|
||||
// We do not use child_iterator here because that will include
|
||||
// the expressions referenced by the condition variable.
|
||||
for (Stmt **I = &SubExprs[0], **E = &SubExprs[END_EXPR]; I != E; ++I)
|
||||
if (Stmt *Child = *I) Child->Destroy(C);
|
||||
|
||||
this->~Stmt();
|
||||
C.Deallocate((void *)this);
|
||||
}
|
||||
|
||||
// SwitchStmt
|
||||
Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; }
|
||||
|
|
|
@ -65,7 +65,7 @@ void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
|
|||
assert (getVAPtr() == NULL);
|
||||
|
||||
if (inDecl()) {
|
||||
assert (decl);
|
||||
assert(decl);
|
||||
|
||||
// FIXME: SIMPLIFY AWAY.
|
||||
if (ImmediateAdvance)
|
||||
|
@ -74,7 +74,7 @@ void StmtIteratorBase::NextDecl(bool ImmediateAdvance) {
|
|||
return;
|
||||
}
|
||||
else {
|
||||
assert (inDeclGroup());
|
||||
assert(inDeclGroup());
|
||||
|
||||
if (ImmediateAdvance)
|
||||
++DGI;
|
||||
|
@ -113,10 +113,10 @@ bool StmtIteratorBase::HandleDecl(Decl* D) {
|
|||
return false;
|
||||
}
|
||||
|
||||
StmtIteratorBase::StmtIteratorBase(Decl* d)
|
||||
: stmt(0), decl(d), RawVAPtr(DeclMode) {
|
||||
assert (decl);
|
||||
NextDecl(false);
|
||||
StmtIteratorBase::StmtIteratorBase(Decl *d, Stmt **s)
|
||||
: stmt(s), decl(d), RawVAPtr(d ? DeclMode : 0) {
|
||||
if (decl)
|
||||
NextDecl(false);
|
||||
}
|
||||
|
||||
StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge)
|
||||
|
|
Загрузка…
Ссылка в новой задаче