diff options
author | Przemyslaw Gorszkowski <pgorszkowski@gmail.com> | 2014-06-07 14:17:39 +0200 |
---|---|---|
committer | Przemyslaw Gorszkowski <pgorszkowski@gmail.com> | 2014-06-13 23:32:07 +0200 |
commit | 9b6d4573aa494851939f775ce6a5c861968182cd (patch) | |
tree | bba7e535001680fd1c16f8c826dfd8f3cfe5999f /src/libs/cplusplus/LookupContext.cpp | |
parent | 6a700ff0573ffaf93373ef9def509a2762ff1228 (diff) | |
download | qt-creator-9b6d4573aa494851939f775ce6a5c861968182cd.tar.gz |
C++: fix 'using' in separate block of scope
Task-number: QTCREATORBUG-12357
Change-Id: I7397b0e66783d3249daa5a8ee422bfd5f5bc7bea
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/libs/cplusplus/LookupContext.cpp')
-rw-r--r-- | src/libs/cplusplus/LookupContext.cpp | 78 |
1 files changed, 46 insertions, 32 deletions
diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index ac4e8bebda..f8cdf106a0 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -242,26 +242,32 @@ const Name *LookupContext::minimalName(Symbol *symbol, ClassOrNamespace *target, return n; } -QList<LookupItem> LookupContext::lookupByUsing(const Name *name, Scope *scope) const +QList<LookupItem> LookupContext::lookupByUsing(const Name *name, + ClassOrNamespace *bindingScope) const { QList<LookupItem> candidates; // if it is a nameId there can be a using declaration for it if (name->isNameId() || name->isTemplateNameId()) { - for (unsigned i = 0, count = scope->memberCount(); i < count; ++i) { - if (UsingDeclaration *u = scope->memberAt(i)->asUsingDeclaration()) { - if (const Name *usingDeclarationName = u->name()) { - if (const QualifiedNameId *q = usingDeclarationName->asQualifiedNameId()) { - if (q->name() && q->identifier() && name->identifier() - && q->name()->identifier()->match(name->identifier())) { - candidates = bindings()->globalNamespace()->find(q); - - // if it is not a global scope(scope of scope is not equal 0) - // then add current using declaration as a candidate - if (scope->enclosingScope()) { - LookupItem item; - item.setDeclaration(u); - item.setScope(scope); - candidates.append(item); + foreach (Symbol *s, bindingScope->symbols()) { + if (Scope *scope = s->asScope()) { + for (unsigned i = 0, count = scope->memberCount(); i < count; ++i) { + if (UsingDeclaration *u = scope->memberAt(i)->asUsingDeclaration()) { + if (const Name *usingDeclarationName = u->name()) { + if (const QualifiedNameId *q + = usingDeclarationName->asQualifiedNameId()) { + if (q->name() && q->identifier() && name->identifier() + && q->name()->identifier()->match(name->identifier())) { + candidates = bindings()->globalNamespace()->find(q); + + // if it is not a global scope(scope of scope is not equal 0) + // then add current using declaration as a candidate + if (scope->enclosingScope()) { + LookupItem item; + item.setDeclaration(u); + item.setScope(scope); + candidates.append(item); + } + } } } } @@ -269,9 +275,15 @@ QList<LookupItem> LookupContext::lookupByUsing(const Name *name, Scope *scope) c } } } else if (const QualifiedNameId *q = name->asQualifiedNameId()) { - ClassOrNamespace *base = lookupType(q->base(), scope); - if (base && base->symbols().size() > 0 && base->symbols().first()->asScope()) - return lookupByUsing(q->name(), base->symbols().first()->asScope()); + foreach (Symbol *s, bindingScope->symbols()) { + if (Scope *scope = s->asScope()) { + ClassOrNamespace *base = lookupType(q->base(), scope); + if (base) + candidates = lookupByUsing(q->name(), base); + if (!candidates.isEmpty()) + return candidates; + } + } } return candidates; } @@ -400,13 +412,13 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const } } - candidates = lookupByUsing(name, scope); - if (! candidates.isEmpty()) - return candidates; + if (ClassOrNamespace *bindingScope = bindings()->lookupType(scope)) { + if (ClassOrNamespace *bindingBlock = bindingScope->findBlock(scope->asBlock())) { + candidates = lookupByUsing(name, bindingBlock); + if (! candidates.isEmpty()) + return candidates; - if (ClassOrNamespace *binding = bindings()->lookupType(scope)) { - if (ClassOrNamespace *block = binding->findBlock(scope->asBlock())) { - candidates = block->find(name); + candidates = bindingBlock->find(name); if (! candidates.isEmpty()) return candidates; @@ -461,15 +473,17 @@ QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const } else if (scope->asNamespace() || scope->asClass() || (scope->asEnum() && scope->asEnum()->isScoped())) { - if (ClassOrNamespace *binding = bindings()->lookupType(scope)) - candidates = binding->find(name); - if (! candidates.isEmpty()) - return candidates; + if (ClassOrNamespace *bindingScope = bindings()->lookupType(scope)) { + candidates = bindingScope->find(name); - candidates = lookupByUsing(name, scope); - if (! candidates.isEmpty()) - return candidates; + if (! candidates.isEmpty()) + return candidates; + + candidates = lookupByUsing(name, bindingScope); + if (!candidates.isEmpty()) + return candidates; + } // the scope can be defined inside a block, try to find it if (Block *block = scope->enclosingBlock()) { |