Commit d9a65bea authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Moved the lookup of qualified name ids in LookupContext::resolveQualifiedNameId()

parent ed02e7ee
...@@ -126,63 +126,71 @@ bool LookupContext::maybeValidSymbol(Symbol *symbol, ...@@ -126,63 +126,71 @@ bool LookupContext::maybeValidSymbol(Symbol *symbol,
return false; return false;
} }
QList<Symbol *> LookupContext::resolve(Name *name, const QList<Scope *> &visibleScopes, QList<Symbol *> LookupContext::resolveQualifiedNameId(QualifiedNameId *q,
ResolveMode mode) const const QList<Scope *> &visibleScopes,
ResolveMode mode) const
{ {
QList<Scope *> scopes = visibleScopes;
QList<Symbol *> candidates; QList<Symbol *> candidates;
if (!name) for (unsigned i = 0; i < q->nameCount(); ++i) {
return candidates; Name *name = q->nameAt(i);
if (QualifiedNameId *q = name->asQualifiedNameId()) {
QList<Scope *> scopes = visibleScopes;
for (unsigned i = 0; i < q->nameCount(); ++i) {
Name *name = q->nameAt(i);
if (i + 1 == q->nameCount()) if (i + 1 == q->nameCount())
candidates = resolve(name, scopes, mode); candidates = resolve(name, scopes, mode);
else else
candidates = resolveClassOrNamespace(name, scopes); candidates = resolveClassOrNamespace(name, scopes);
if (candidates.isEmpty() || i + 1 == q->nameCount()) if (candidates.isEmpty() || i + 1 == q->nameCount())
break; break;
scopes.clear(); scopes.clear();
foreach (Symbol *candidate, candidates) { foreach (Symbol *candidate, candidates) {
if (ScopedSymbol *scoped = candidate->asScopedSymbol()) { if (ScopedSymbol *scoped = candidate->asScopedSymbol()) {
scopes.append(scoped->members()); scopes.append(scoped->members());
}
} }
} }
}
Identifier *id = identifier(name); Identifier *id = q->identifier();
foreach (Scope *scope, visibleScopes) { foreach (Scope *scope, visibleScopes) {
Symbol *symbol = scope->lookat(id); Symbol *symbol = scope->lookat(id);
for (; symbol; symbol = symbol->next()) { for (; symbol; symbol = symbol->next()) {
if (! symbol->name()) if (! symbol->name())
continue; continue;
else if (! maybeValidSymbol(symbol, mode, candidates)) else if (! maybeValidSymbol(symbol, mode, candidates))
continue; continue;
QualifiedNameId *qq = symbol->name()->asQualifiedNameId(); QualifiedNameId *qq = symbol->name()->asQualifiedNameId();
if (! qq) if (! qq)
continue; continue;
if (q->nameCount() > qq->nameCount()) if (q->nameCount() > qq->nameCount())
continue; continue;
for (int i = q->nameCount() - 1; i != -1; --i) { for (int i = q->nameCount() - 1; i != -1; --i) {
Name *a = q->nameAt(i); Name *a = q->nameAt(i);
Name *b = qq->nameAt(i); Name *b = qq->nameAt(i);
if (! a->isEqualTo(b)) if (! a->isEqualTo(b))
break; break;
else if (i == 0) else if (i == 0)
candidates.append(symbol); candidates.append(symbol);
}
} }
} }
}
return candidates;
}
QList<Symbol *> LookupContext::resolve(Name *name, const QList<Scope *> &visibleScopes,
ResolveMode mode) const
{
QList<Symbol *> candidates;
if (!name)
return candidates; return candidates;
}
if (QualifiedNameId *q = name->asQualifiedNameId())
return resolveQualifiedNameId(q, visibleScopes, mode);
if (Identifier *id = identifier(name)) { if (Identifier *id = identifier(name)) {
for (int scopeIndex = 0; scopeIndex < visibleScopes.size(); ++scopeIndex) { for (int scopeIndex = 0; scopeIndex < visibleScopes.size(); ++scopeIndex) {
......
...@@ -115,6 +115,10 @@ public: ...@@ -115,6 +115,10 @@ public:
QList<Scope *> *expandedScopes) const; QList<Scope *> *expandedScopes) const;
private: private:
QList<Symbol *> resolveQualifiedNameId(QualifiedNameId *q,
const QList<Scope *> &visibleScopes,
ResolveMode mode) const;
Identifier *identifier(const Name *name) const; Identifier *identifier(const Name *name) const;
QList<Scope *> buildVisibleScopes(); QList<Scope *> buildVisibleScopes();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment