aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/IdentifierResolver.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-07-17 17:49:50 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2008-07-17 17:49:50 +0000
commit90eb539bc3121bdc0e867ab1cd6bdca3b36d961e (patch)
tree709cd176611f6f3980490c9ca8155e2bc34f91ca /lib/Sema/IdentifierResolver.cpp
parentf616ebb9b61239182a2ebc29bf3bd4f80530daab (diff)
Unify ctx_iterator/ctx_begin()/ctx_end() and iterator/begin()/end() so that a single iterator type is used for both traversing decls of the same declaration context *and* of the parent declaration contexts, depending on the value of the bool parameter 'LookInParentCtx' that is passed to IdentifierResolver::begin().
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53724 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/IdentifierResolver.cpp')
-rw-r--r--lib/Sema/IdentifierResolver.cpp78
1 files changed, 45 insertions, 33 deletions
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp
index 33b2102fd1..0b63ad9b53 100644
--- a/lib/Sema/IdentifierResolver.cpp
+++ b/lib/Sema/IdentifierResolver.cpp
@@ -111,58 +111,70 @@ void IdentifierResolver::RemoveDecl(NamedDecl *D) {
return toIdDeclInfo(Ptr)->RemoveDecl(D);
}
-/// begin - Returns an iterator for all decls, starting at the given
-/// declaration context.
+/// begin - Returns an iterator for decls of identifier 'II', starting at
+/// declaration context 'Ctx'. If 'LookInParentCtx' is true, it will walk the
+/// decls of parent declaration contexts too.
IdentifierResolver::iterator
-IdentifierResolver::begin(const IdentifierInfo *II, DeclContext *Ctx) {
+IdentifierResolver::begin(const IdentifierInfo *II, DeclContext *Ctx,
+ bool LookInParentCtx) {
assert(Ctx && "null param passed");
void *Ptr = II->getFETokenInfo<void>();
- if (!Ptr) return end(II);
+ if (!Ptr) return end();
LookupContext LC(Ctx);
if (isDeclPtr(Ptr)) {
NamedDecl *D = static_cast<NamedDecl*>(Ptr);
+ LookupContext DC(D);
- if (LC.isEqOrContainedBy(LookupContext(D)))
+ if (( LookInParentCtx && LC.isEqOrContainedBy(DC)) ||
+ (!LookInParentCtx && LC == DC))
return iterator(D);
else
- return end(II);
-
+ return end();
}
-
- IdDeclInfo *IDI = toIdDeclInfo(Ptr);
- return iterator(IDI->FindContext(LC));
-}
-/// ctx_begin - Returns an iterator for only decls that belong to the given
-/// declaration context.
-IdentifierResolver::ctx_iterator
-IdentifierResolver::ctx_begin(const IdentifierInfo *II, DeclContext *Ctx) {
- assert(Ctx && "null param passed");
-
- void *Ptr = II->getFETokenInfo<void>();
- if (!Ptr) return ctx_end(II);
-
- LookupContext LC(Ctx);
+ IdDeclInfo *IDI = toIdDeclInfo(Ptr);
- if (isDeclPtr(Ptr)) {
- NamedDecl *D = static_cast<NamedDecl*>(Ptr);
+ IdDeclInfo::DeclsTy::iterator I;
+ if (LookInParentCtx)
+ I = IDI->FindContext(LC);
+ else {
+ for (I = IDI->decls_end(); I != IDI->decls_begin(); --I)
+ if (LookupContext(*(I-1)) == LC)
+ break;
+ }
- if (LC == LookupContext(D))
- return ctx_iterator(D);
- else
- return ctx_end(II);
+ if (I != IDI->decls_begin())
+ return iterator(I-1, LookInParentCtx);
+ else // No decls found.
+ return end();
+}
+/// PreIncIter - Do a preincrement when 'Ptr' is a BaseIter.
+void IdentifierResolver::iterator::PreIncIter() {
+ NamedDecl *D = **this;
+ LookupContext Ctx(D);
+ void *InfoPtr = D->getIdentifier()->getFETokenInfo<void>();
+ assert(!isDeclPtr(InfoPtr) && "Decl with wrong id ?");
+ IdDeclInfo *Info = toIdDeclInfo(InfoPtr);
+
+ BaseIter I = getIterator();
+ if (LookInParentCtx())
+ I = Info->FindContext(Ctx, I);
+ else {
+ if (I != Info->decls_begin() && LookupContext(*(I-1)) != Ctx) {
+ // The next decl is in different declaration context.
+ // Skip remaining decls and set the iterator to the end.
+ I = Info->decls_begin();
+ }
}
-
- IdDeclInfo *IDI = toIdDeclInfo(Ptr);
- IdDeclInfo::DeclsTy::iterator I = IDI->FindContext(LookupContext(Ctx));
- if (I != IDI->decls_begin() && LC != LookupContext(*(I-1)))
- I = IDI->decls_begin();
- return ctx_iterator(I);
+ if (I != Info->decls_begin())
+ *this = iterator(I-1, LookInParentCtx());
+ else // No more decls.
+ *this = end();
}