using namespace clang;
+static inline bool declHasExpr(ScopedDecl *decl) {
+ if (VarDecl* D = dyn_cast<VarDecl>(decl))
+ if (D->getInit())
+ return true;
+
+ if (EnumConstantDecl* D = dyn_cast<EnumConstantDecl>(decl))
+ if (D->getInitExpr())
+ return true;
+
+ return false;
+}
+
void StmtIteratorBase::NextDecl() {
assert (FirstDecl && Ptr.D);
do Ptr.D = Ptr.D->getNextDeclarator();
- while (Ptr.D != NULL && !isa<VarDecl>(Ptr.D));
+ while (Ptr.D != NULL && !declHasExpr(Ptr.D));
if (Ptr.D == NULL) FirstDecl = NULL;
}
StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) {
assert (d);
- while (d != NULL) {
- if (VarDecl* V = dyn_cast<VarDecl>(d))
- if (V->getInit()) break;
-
+ while (d != NULL && !declHasExpr(d))
d = d->getNextDeclarator();
- }
FirstDecl = d;
Ptr.D = d;
Ptr.D = lastVD;
}
-Stmt*& StmtIteratorBase::GetInitializer() const {
- return reinterpret_cast<Stmt*&>(cast<VarDecl>(Ptr.D)->Init);
+Stmt*& StmtIteratorBase::GetDeclExpr() const {
+ if (VarDecl* D = dyn_cast<VarDecl>(Ptr.D))
+ return reinterpret_cast<Stmt*&>(D->Init);
+ else {
+ EnumConstantDecl* D = cast<EnumConstantDecl>(Ptr.D);
+ return reinterpret_cast<Stmt*&>(D->Init);
+ }
}
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) { return D->getKind() == EnumConstant; }
static bool classof(const EnumConstantDecl *D) { return true; }
+
+ friend class StmtIteratorBase;
};
void NextDecl();
void PrevDecl();
- Stmt*& GetInitializer() const;
+ Stmt*& GetDeclExpr() const;
StmtIteratorBase(Stmt** s) : FirstDecl(NULL) { Ptr.S = s; }
StmtIteratorBase(ScopedDecl* d);
}
REFERENCE operator*() const {
- return (REFERENCE) (FirstDecl ? GetInitializer() : *Ptr.S);
+ return (REFERENCE) (FirstDecl ? GetDeclExpr() : *Ptr.S);
}
REFERENCE operator->() const { return operator*(); }