diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-10-07 23:04:14 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-10-07 23:04:14 +0000 |
commit | 3e6d1203b3346147cee51a8a6d374f1867f2cd23 (patch) | |
tree | 097cd7af9ede14906f2a621bf01ab6e092599021 /lib/AST/StmtIterator.cpp | |
parent | 3f2a8a0de575b02408384f92914729b7518d4e77 (diff) |
Add StmtIterator support for DeclGroups.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57271 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/StmtIterator.cpp')
-rw-r--r-- | lib/AST/StmtIterator.cpp | 111 |
1 files changed, 73 insertions, 38 deletions
diff --git a/lib/AST/StmtIterator.cpp b/lib/AST/StmtIterator.cpp index 3af66b30bf..1b0e9d57c0 100644 --- a/lib/AST/StmtIterator.cpp +++ b/lib/AST/StmtIterator.cpp @@ -35,12 +35,21 @@ void StmtIteratorBase::NextVA() { p = FindVA(p->getElementType().getTypePtr()); setVAPtr(p); - if (!p && inDecl()) { - if (VarDecl* VD = dyn_cast<VarDecl>(decl)) - if (VD->Init) - return; + if (!p) { + if (inDecl()) { + if (VarDecl* VD = dyn_cast<VarDecl>(decl)) + if (VD->Init) + return; + + NextDecl(); + } + else if (inDeclGroup()) { + if (VarDecl* VD = dyn_cast<VarDecl>(*DGI)) + if (VD->Init) + return; - NextDecl(); + NextDecl(); + } } else if (inSizeOfTypeVA()) { assert(!decl); RawVAPtr = 0; @@ -48,45 +57,56 @@ void StmtIteratorBase::NextVA() { } void StmtIteratorBase::NextDecl(bool ImmediateAdvance) { - assert (inDecl()); assert (getVAPtr() == NULL); - assert (decl); - - if (ImmediateAdvance) { - decl = decl->getNextDeclarator(); - - if (!decl) { - RawVAPtr = 0; - return; - } - } - for ( ; decl ; decl = decl->getNextDeclarator()) { - if (VarDecl* VD = dyn_cast<VarDecl>(decl)) { - if (VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) { - setVAPtr(VAPtr); + if (inDecl()) { + assert (decl); + + if (ImmediateAdvance) + decl = decl->getNextDeclarator(); + + for ( ; decl ; decl = decl->getNextDeclarator()) + if (HandleDecl(decl)) return; - } - - if (VD->getInit()) - return; - } - else if (TypedefDecl* TD = dyn_cast<TypedefDecl>(decl)) { - if (VariableArrayType* VAPtr = - FindVA(TD->getUnderlyingType().getTypePtr())) { - setVAPtr(VAPtr); + } + else { + assert (inDeclGroup()); + + if (ImmediateAdvance) + ++DGI; + + for ( ; DGI != DGE; ++DGI) + if (HandleDecl(*DGI)) return; - } + } + + RawVAPtr = 0; +} + +bool StmtIteratorBase::HandleDecl(Decl* D) { + + if (VarDecl* VD = dyn_cast<VarDecl>(D)) { + if (VariableArrayType* VAPtr = FindVA(VD->getType().getTypePtr())) { + setVAPtr(VAPtr); + return true; } - else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(decl)) - if (ECD->getInitExpr()) - return; + + if (VD->getInit()) + return true; } - - if (!decl) { - RawVAPtr = 0; - return; + else if (TypedefDecl* TD = dyn_cast<TypedefDecl>(D)) { + if (VariableArrayType* VAPtr = + FindVA(TD->getUnderlyingType().getTypePtr())) { + setVAPtr(VAPtr); + return true; + } + } + else if (EnumConstantDecl* ECD = dyn_cast<EnumConstantDecl>(D)) { + if (ECD->getInitExpr()) + return true; } + + return false; } StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) @@ -95,16 +115,31 @@ StmtIteratorBase::StmtIteratorBase(ScopedDecl* d) NextDecl(false); } +StmtIteratorBase::StmtIteratorBase(Decl** dgi, Decl** dge) + : DGI(dgi), RawVAPtr(DeclGroupMode), DGE(dge) { + NextDecl(false); +} + StmtIteratorBase::StmtIteratorBase(VariableArrayType* t) -: decl(NULL), RawVAPtr(SizeOfTypeVAMode) { +: decl(0), RawVAPtr(SizeOfTypeVAMode) { RawVAPtr |= reinterpret_cast<uintptr_t>(t); } Stmt*& StmtIteratorBase::GetDeclExpr() const { + + if (inDeclGroup()) { + VarDecl* VD = cast<VarDecl>(*DGI); + return VD->Init; + } + + assert (inDecl() || inSizeOfTypeVA()); + if (VariableArrayType* VAPtr = getVAPtr()) { assert (VAPtr->SizeExpr); return VAPtr->SizeExpr; } + + assert (inDecl()); if (VarDecl* VD = dyn_cast<VarDecl>(decl)) { assert (VD->Init); |