diff options
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r-- | src/libs/cplusplus/LookupContext.cpp | 38 | ||||
-rw-r--r-- | src/libs/cplusplus/LookupContext.h | 3 |
2 files changed, 30 insertions, 11 deletions
diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index fefe1ecd5e..58a8a27b2b 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -820,22 +820,38 @@ ClassOrNamespace *ClassOrNamespace::findType(const Name *name) return lookupType_helper(name, &processed, /*searchInEnclosingScope =*/ false, this); } -ClassOrNamespace *ClassOrNamespace::findBlock(Block *block) +ClassOrNamespace *ClassOrNamespace::findBlock_helper(Block *block, + QSet<ClassOrNamespace *> *processed, + bool searchInEnclosingScope) { - flush(); - - QHash<Block *, ClassOrNamespace *>::const_iterator citBlock = _blocks.find(block); - if (citBlock != _blocks.end()) - return citBlock.value(); - - for (citBlock = _blocks.begin(); citBlock != _blocks.end(); ++citBlock) { - if (ClassOrNamespace *foundNestedBlock = citBlock.value()->findBlock(block)) - return foundNestedBlock; + for (ClassOrNamespace *binding = this; binding; binding = binding->_parent) { + if (processed->contains(binding)) + break; + processed->insert(binding); + binding->flush(); + auto end = binding->_blocks.end(); + auto citBlock = binding->_blocks.find(block); + if (citBlock != end) + return citBlock.value(); + + for (citBlock = binding->_blocks.begin(); citBlock != end; ++citBlock) { + if (ClassOrNamespace *foundNestedBlock = + citBlock.value()->findBlock_helper(block, processed, false)) { + return foundNestedBlock; + } + } + if (!searchInEnclosingScope) + break; } - return 0; } +ClassOrNamespace *ClassOrNamespace::findBlock(Block *block) +{ + QSet<ClassOrNamespace *> processed; + return findBlock_helper(block, &processed, true); +} + Symbol *ClassOrNamespace::lookupInScope(const QList<const Name *> &fullName) { if (!_scopeLookupCache) { diff --git a/src/libs/cplusplus/LookupContext.h b/src/libs/cplusplus/LookupContext.h index 93d905598f..899514a13b 100644 --- a/src/libs/cplusplus/LookupContext.h +++ b/src/libs/cplusplus/LookupContext.h @@ -124,6 +124,9 @@ private: ClassOrNamespace *lookupType_helper(const Name *name, QSet<ClassOrNamespace *> *processed, bool searchInEnclosingScope, ClassOrNamespace *origin); + ClassOrNamespace *findBlock_helper(Block *block, QSet<ClassOrNamespace *> *processed, + bool searchInEnclosingScope); + ClassOrNamespace *nestedType(const Name *name, ClassOrNamespace *origin); void instantiateNestedClasses(ClassOrNamespace *enclosingTemplateClass, |