зеркало из 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;
|
SourceLocation ElseLoc;
|
||||||
|
|
||||||
public:
|
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)
|
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[COND] = reinterpret_cast<Stmt*>(cond);
|
||||||
SubExprs[THEN] = then;
|
SubExprs[THEN] = then;
|
||||||
SubExprs[ELSE] = elsev;
|
SubExprs[ELSE] = elsev;
|
||||||
|
@ -674,9 +674,13 @@ public:
|
||||||
}
|
}
|
||||||
static bool classof(const IfStmt *) { return true; }
|
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_begin();
|
||||||
virtual child_iterator child_end();
|
virtual child_iterator child_end();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void DoDestroy(ASTContext &Ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// SwitchStmt - This represents a 'switch' stmt.
|
/// SwitchStmt - This represents a 'switch' stmt.
|
||||||
|
|
|
@ -66,7 +66,7 @@ protected:
|
||||||
Stmt*& GetDeclExpr() const;
|
Stmt*& GetDeclExpr() const;
|
||||||
|
|
||||||
StmtIteratorBase(Stmt **s) : stmt(s), decl(0), RawVAPtr(0) {}
|
StmtIteratorBase(Stmt **s) : stmt(s), decl(0), RawVAPtr(0) {}
|
||||||
StmtIteratorBase(Decl *d);
|
StmtIteratorBase(Decl *d, Stmt **s);
|
||||||
StmtIteratorBase(VariableArrayType *t);
|
StmtIteratorBase(VariableArrayType *t);
|
||||||
StmtIteratorBase(Decl **dgi, Decl **dge);
|
StmtIteratorBase(Decl **dgi, Decl **dge);
|
||||||
StmtIteratorBase() : stmt(0), decl(0), RawVAPtr(0) {}
|
StmtIteratorBase() : stmt(0), decl(0), RawVAPtr(0) {}
|
||||||
|
@ -84,7 +84,7 @@ public:
|
||||||
StmtIteratorImpl() {}
|
StmtIteratorImpl() {}
|
||||||
StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
|
StmtIteratorImpl(Stmt **s) : StmtIteratorBase(s) {}
|
||||||
StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
|
StmtIteratorImpl(Decl **dgi, Decl **dge) : StmtIteratorBase(dgi, dge) {}
|
||||||
StmtIteratorImpl(Decl* d) : StmtIteratorBase(d) {}
|
StmtIteratorImpl(Decl *d, Stmt **s) : StmtIteratorBase(d, s) {}
|
||||||
StmtIteratorImpl(VariableArrayType* t) : StmtIteratorBase(t) {}
|
StmtIteratorImpl(VariableArrayType* t) : StmtIteratorBase(t) {}
|
||||||
|
|
||||||
DERIVED& operator++() {
|
DERIVED& operator++() {
|
||||||
|
@ -125,11 +125,15 @@ struct StmtIterator : public StmtIteratorImpl<StmtIterator,Stmt*&> {
|
||||||
explicit StmtIterator() : StmtIteratorImpl<StmtIterator,Stmt*&>() {}
|
explicit StmtIterator() : StmtIteratorImpl<StmtIterator,Stmt*&>() {}
|
||||||
|
|
||||||
StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator,Stmt*&>(S) {}
|
StmtIterator(Stmt** S) : StmtIteratorImpl<StmtIterator,Stmt*&>(S) {}
|
||||||
|
|
||||||
StmtIterator(Decl** dgi, Decl** dge)
|
StmtIterator(Decl** dgi, Decl** dge)
|
||||||
: StmtIteratorImpl<StmtIterator,Stmt*&>(dgi, dge) {}
|
: StmtIteratorImpl<StmtIterator,Stmt*&>(dgi, dge) {}
|
||||||
|
|
||||||
StmtIterator(VariableArrayType* t):StmtIteratorImpl<StmtIterator,Stmt*&>(t) {}
|
StmtIterator(VariableArrayType* t)
|
||||||
StmtIterator(Decl* D) : StmtIteratorImpl<StmtIterator,Stmt*&>(D) {}
|
: StmtIteratorImpl<StmtIterator,Stmt*&>(t) {}
|
||||||
|
|
||||||
|
StmtIterator(Decl* D, Stmt **s = 0)
|
||||||
|
: StmtIteratorImpl<StmtIterator,Stmt*&>(D, s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConstStmtIterator : public StmtIteratorImpl<ConstStmtIterator,
|
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; }
|
Stmt::child_iterator LabelStmt::child_end() { return &SubStmt+1; }
|
||||||
|
|
||||||
// IfStmt
|
// IfStmt
|
||||||
Stmt::child_iterator IfStmt::child_begin() { return &SubExprs[0]; }
|
Stmt::child_iterator IfStmt::child_begin() {
|
||||||
Stmt::child_iterator IfStmt::child_end() { return &SubExprs[0]+END_EXPR; }
|
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
|
// SwitchStmt
|
||||||
Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; }
|
Stmt::child_iterator SwitchStmt::child_begin() { return &SubExprs[0]; }
|
||||||
|
|
|
@ -113,9 +113,9 @@ bool StmtIteratorBase::HandleDecl(Decl* D) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
StmtIteratorBase::StmtIteratorBase(Decl* d)
|
StmtIteratorBase::StmtIteratorBase(Decl *d, Stmt **s)
|
||||||
: stmt(0), decl(d), RawVAPtr(DeclMode) {
|
: stmt(s), decl(d), RawVAPtr(d ? DeclMode : 0) {
|
||||||
assert (decl);
|
if (decl)
|
||||||
NextDecl(false);
|
NextDecl(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче