diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-07-16 11:03:39 +0200 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2010-07-16 11:04:52 +0200 |
commit | fff4203a46559e0afc751785e25eb702d8c8a608 (patch) | |
tree | 53e4a813426e6f2d4fc4603936e34601c8e30c11 /src/libs/cplusplus/LookupContext.cpp | |
parent | 41236d29d328950d9240d4e3a5e2c98d3214b65b (diff) | |
download | qt-creator-fff4203a46559e0afc751785e25eb702d8c8a608.tar.gz |
Introduced helpers to rewrite types and names.
Done-with: Erik Verbruggen
Diffstat (limited to 'src/libs/cplusplus/LookupContext.cpp')
-rw-r--r-- | src/libs/cplusplus/LookupContext.cpp | 92 |
1 files changed, 44 insertions, 48 deletions
diff --git a/src/libs/cplusplus/LookupContext.cpp b/src/libs/cplusplus/LookupContext.cpp index ce832e2df6..5c935eb6a1 100644 --- a/src/libs/cplusplus/LookupContext.cpp +++ b/src/libs/cplusplus/LookupContext.cpp @@ -39,13 +39,17 @@ #include <Scope.h> #include <Control.h> -#include <QtDebug> +#include <QtCore/QStack> +#include <QtCore/QHash> +#include <QtCore/QVarLengthArray> +#include <QtCore/QtDebug> + +using namespace CPlusPlus; namespace { - const bool debug = ! qgetenv("CPLUSPLUS_LOOKUPCONTEXT_DEBUG").isEmpty(); -} +const bool debug = ! qgetenv("CPLUSPLUS_LOOKUPCONTEXT_DEBUG").isEmpty(); +} // end of anonymous namespace -using namespace CPlusPlus; static void addNames(const Name *name, QList<const Name *> *names, bool addAllNames = false) { @@ -241,16 +245,16 @@ ClassOrNamespace *LookupContext::lookupType(Symbol *symbol) const return bindings()->lookupType(symbol); } -QList<Symbol *> LookupContext::lookup(const Name *name, Scope *scope) const +QList<LookupItem> LookupContext::lookup(const Name *name, Scope *scope) const { - QList<Symbol *> candidates; + QList<LookupItem> candidates; if (! name) return candidates; for (; scope; scope = scope->enclosingScope()) { if ((name->isNameId() || name->isTemplateNameId()) && scope->isBlockScope()) { - bindings()->lookupInScope(name, scope, &candidates, /*templateId = */ 0); + bindings()->lookupInScope(name, scope, &candidates, /*templateId = */ 0, /*binding=*/ 0); if (! candidates.isEmpty()) break; // it's a local. @@ -274,10 +278,10 @@ QList<Symbol *> LookupContext::lookup(const Name *name, Scope *scope) const } else if (scope->isFunctionScope()) { Function *fun = scope->owner()->asFunction(); - bindings()->lookupInScope(name, fun->arguments(), &candidates, /*templateId = */ 0); + bindings()->lookupInScope(name, fun->arguments(), &candidates, /*templateId = */ 0, /*binding=*/ 0); for (TemplateParameters *it = fun->templateParameters(); it && candidates.isEmpty(); it = it->previous()) - bindings()->lookupInScope(name, it->scope(), &candidates, /* templateId = */ 0); + bindings()->lookupInScope(name, it->scope(), &candidates, /* templateId = */ 0, /*binding=*/ 0); if (! candidates.isEmpty()) break; // it's an argument or a template parameter. @@ -295,7 +299,7 @@ QList<Symbol *> LookupContext::lookup(const Name *name, Scope *scope) const } else if (scope->isObjCMethodScope()) { ObjCMethod *method = scope->owner()->asObjCMethod(); - bindings()->lookupInScope(name, method->arguments(), &candidates, /*templateId = */ 0); + bindings()->lookupInScope(name, method->arguments(), &candidates, /*templateId = */ 0, /*binding=*/ 0); if (! candidates.isEmpty()) break; // it's a formal argument. @@ -304,7 +308,7 @@ QList<Symbol *> LookupContext::lookup(const Name *name, Scope *scope) const Class *klass = scope->owner()->asClass(); for (TemplateParameters *it = klass->templateParameters(); it && candidates.isEmpty(); it = it->previous()) - bindings()->lookupInScope(name, it->scope(), &candidates, /* templateId = */ 0); + bindings()->lookupInScope(name, it->scope(), &candidates, /* templateId = */ 0, /*binding=*/ 0); if (! candidates.isEmpty()) break; // it's an argument or a template parameter. @@ -398,19 +402,19 @@ ClassOrNamespace *ClassOrNamespace::globalNamespace() const return e; } -QList<Symbol *> ClassOrNamespace::find(const Name *name) +QList<LookupItem> ClassOrNamespace::find(const Name *name) { return lookup_helper(name, false); } -QList<Symbol *> ClassOrNamespace::lookup(const Name *name) +QList<LookupItem> ClassOrNamespace::lookup(const Name *name) { return lookup_helper(name, true); } -QList<Symbol *> ClassOrNamespace::lookup_helper(const Name *name, bool searchInEnclosingScope) +QList<LookupItem> ClassOrNamespace::lookup_helper(const Name *name, bool searchInEnclosingScope) { - QList<Symbol *> result; + QList<LookupItem> result; if (name) { if (const QualifiedNameId *q = name->asQualifiedNameId()) { @@ -435,9 +439,9 @@ QList<Symbol *> ClassOrNamespace::lookup_helper(const Name *name, bool searchInE } void ClassOrNamespace::lookup_helper(const Name *name, ClassOrNamespace *binding, - QList<Symbol *> *result, - QSet<ClassOrNamespace *> *processed, - const TemplateNameId *templateId) + QList<LookupItem> *result, + QSet<ClassOrNamespace *> *processed, + const TemplateNameId *templateId) { if (binding && ! processed->contains(binding)) { processed->insert(binding); @@ -448,16 +452,20 @@ void ClassOrNamespace::lookup_helper(const Name *name, ClassOrNamespace *binding if (ScopedSymbol *scoped = s->asScopedSymbol()) { if (Class *klass = scoped->asClass()) { if (const Identifier *id = klass->identifier()) { - if (nameId && nameId->isEqualTo(id)) - result->append(klass); + if (nameId && nameId->isEqualTo(id)) { + LookupItem item; + item.setDeclaration(klass); + item.setBinding(binding); + result->append(item); + } } } - _factory->lookupInScope(name, scoped->members(), result, templateId); + _factory->lookupInScope(name, scoped->members(), result, templateId, binding); } } foreach (Enum *e, binding->enums()) - _factory->lookupInScope(name, e->members(), result, templateId); + _factory->lookupInScope(name, e->members(), result, templateId, binding); foreach (ClassOrNamespace *u, binding->usings()) lookup_helper(name, u, result, processed, binding->_templateId); @@ -465,8 +473,9 @@ void ClassOrNamespace::lookup_helper(const Name *name, ClassOrNamespace *binding } void CreateBindings::lookupInScope(const Name *name, Scope *scope, - QList<Symbol *> *result, - const TemplateNameId *templateId) + QList<LookupItem> *result, + const TemplateNameId *templateId, + ClassOrNamespace *binding) { Q_UNUSED(templateId); @@ -480,7 +489,10 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope, else if (! s->name()->isEqualTo(op)) continue; - result->append(s); + LookupItem item; + item.setDeclaration(s); + item.setBinding(binding); + result->append(item); } } else if (const Identifier *id = name->identifier()) { @@ -490,34 +502,17 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope, else if (s->name()->isQualifiedNameId()) continue; // skip qualified ids. - if (templateId && (s->isDeclaration() || s->isFunction())) { + LookupItem item; + item.setDeclaration(s); + item.setBinding(binding); + if (templateId && (s->isDeclaration() || s->isFunction())) { FullySpecifiedType ty = DeprecatedGenTemplateInstance::instantiate(templateId, s, _control); - - if (debug) { - Overview oo; - oo.setShowFunctionSignatures(true); - oo.setShowReturnTypes(true); - qDebug() << "instantiate:" << oo(s->type(), s->name()) << "using:" << oo(templateId) << oo(ty); - } - - if (Declaration *decl = s->asDeclaration()) { - Declaration *d = _control->newDeclaration(0, 0); - d->copy(decl); - d->setType(ty); - result->append(d); - continue; - } else if (Function *fun = s->asFunction()) { - Function *d = ty->asFunctionType(); - d->copy(fun); - result->append(d); - continue; - } + item.setType(ty); // override the type. } - result->append(s); + result->append(item); } - } } @@ -987,3 +982,4 @@ bool CreateBindings::visit(ObjCMethod *) { return false; } + |