summaryrefslogtreecommitdiff
path: root/src/libs/cplusplus/LookupContext.cpp
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2015-04-09 17:26:19 +0300
committerOrgad Shaneh <orgads@gmail.com>2015-04-27 09:49:12 +0000
commit548ec9c099748a0625faf3e93f5a31fbc0fd93a8 (patch)
treec4690d005b3712da7a468cde587eef0ca46a208d /src/libs/cplusplus/LookupContext.cpp
parent00845c0503f280d8a067a0fea174da372163b83a (diff)
downloadqt-creator-548ec9c099748a0625faf3e93f5a31fbc0fd93a8.tar.gz
C++: Deduplicate enclosing and nested instantiation
Change-Id: Ib75e2d67acdf1fdbeb30b7c9689134f6ccf34063 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Diffstat (limited to 'src/libs/cplusplus/LookupContext.cpp')
-rw-r--r--src/libs/cplusplus/LookupContext.cpp65
1 files changed, 31 insertions, 34 deletions
diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp
index d34b4544db..ced7dc5e64 100644
--- a/src/libs/cplusplus/LookupContext.cpp
+++ b/src/libs/cplusplus/LookupContext.cpp
@@ -1308,8 +1308,8 @@ LookupScopePrivate *LookupScopePrivate::nestedType(
instantiation->_instantiationOrigin = origin;
// The instantiation should have all symbols, enums, and usings from the reference.
- instantiation->_enums.append(reference->_enums);
- instantiation->_usings.append(reference->_usings);
+ instantiation->_enums = reference->_enums;
+ instantiation->_usings = reference->_usings;
instantiation->_rootClass = reference->_rootClass;
@@ -1349,28 +1349,6 @@ LookupScopePrivate *LookupScopePrivate::nestedType(
subst.bind(cloner.name(name, &subst), ty);
}
- foreach (Symbol *s, reference->_symbols) {
- Symbol *clone = cloner.symbol(s, &subst);
- clone->setEnclosingScope(s->enclosingScope());
- instantiation->_symbols.append(clone);
- if (Q_UNLIKELY(debug)) {
- Overview oo;
- oo.showFunctionSignatures = true;
- oo.showReturnTypes = true;
- oo.showTemplateParameters = true;
- qDebug() << "cloned" << oo(clone->type());
- if (Class *klass = clone->asClass()) {
- const unsigned klassMemberCount = klass->memberCount();
- for (unsigned i = 0; i < klassMemberCount; ++i){
- Symbol *klassMemberAsSymbol = klass->memberAt(i);
- if (klassMemberAsSymbol->isTypedef()) {
- if (Declaration *declaration = klassMemberAsSymbol->asDeclaration())
- qDebug() << "Member: " << oo(declaration->type(), declaration->name());
- }
- }
- }
- }
- }
Instantiator instantiator(cloner, subst);
instantiator.instantiate(reference, instantiation);
} else {
@@ -1493,6 +1471,31 @@ void Instantiator::instantiate(LookupScopePrivate *lookupScope,
if (_alreadyConsideredInstantiations.contains(lookupScope))
return;
_alreadyConsideredInstantiations.insert(lookupScope);
+ if (instantiation != lookupScope) {
+ foreach (Symbol *s, lookupScope->_symbols) {
+ Symbol *clone = _cloner.symbol(s, &_subst);
+ if (!clone->enclosingScope()) // Not from the cache but just cloned.
+ clone->setEnclosingScope(s->enclosingScope());
+ instantiation->_symbols.append(clone);
+ if (Q_UNLIKELY(debug)) {
+ Overview oo;
+ oo.showFunctionSignatures = true;
+ oo.showReturnTypes = true;
+ oo.showTemplateParameters = true;
+ qDebug() << "cloned" << oo(clone->type());
+ if (Class *klass = clone->asClass()) {
+ const unsigned klassMemberCount = klass->memberCount();
+ for (unsigned i = 0; i < klassMemberCount; ++i){
+ Symbol *klassMemberAsSymbol = klass->memberAt(i);
+ if (klassMemberAsSymbol->isTypedef()) {
+ if (Declaration *declaration = klassMemberAsSymbol->asDeclaration())
+ qDebug() << "Member: " << oo(declaration->type(), declaration->name());
+ }
+ }
+ }
+ }
+ }
+ }
auto cit = lookupScope->_nestedScopes.begin();
for (; cit != lookupScope->_nestedScopes.end(); ++cit) {
const Name *nestedName = cit->first;
@@ -1500,18 +1503,12 @@ void Instantiator::instantiate(LookupScopePrivate *lookupScope,
LookupScopePrivate *nestedInstantiation = nestedLookupScope;
nestedLookupScope->flush();
- if (isInstantiationNeeded(nestedLookupScope)) {
+ const bool instantiationNeeded = isInstantiationNeeded(nestedInstantiation);
+ if (instantiationNeeded) {
nestedInstantiation = nestedLookupScope->allocateChild(nestedName);
- nestedInstantiation->_enums.append(nestedLookupScope->_enums);
- nestedInstantiation->_usings.append(nestedLookupScope->_usings);
+ nestedInstantiation->_enums = nestedLookupScope->_enums;
+ nestedInstantiation->_usings = nestedLookupScope->_usings;
nestedInstantiation->_instantiationOrigin = nestedLookupScope;
-
- foreach (Symbol *s, nestedLookupScope->_symbols) {
- Symbol *clone = _cloner.symbol(s, &_subst);
- if (!clone->enclosingScope()) // Not from the cache but just cloned.
- clone->setEnclosingScope(s->enclosingScope());
- nestedInstantiation->_symbols.append(clone);
- }
}
if (isNestedInstantiationEnclosingTemplate(nestedInstantiation, lookupScope))