Skip to content
Snippets Groups Projects
Commit 6a3382d8 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Say hello to LookupContext::resolveNestedNameSpecifier()

parent 6a5d81b0
No related branches found
No related tags found
No related merge requests found
...@@ -126,59 +126,48 @@ bool LookupContext::maybeValidSymbol(Symbol *symbol, ...@@ -126,59 +126,48 @@ bool LookupContext::maybeValidSymbol(Symbol *symbol,
return false; return false;
} }
QList<Symbol *> LookupContext::resolveQualifiedNameId(QualifiedNameId *q, QList<Scope *> LookupContext::resolveNestedNameSpecifier(QualifiedNameId *q,
const QList<Scope *> &visibleScopes, const QList<Scope *> &visibleScopes) const
ResolveMode mode) const
{ {
QList<Scope *> scopes = visibleScopes;
QList<Symbol *> candidates; QList<Symbol *> candidates;
QList<Scope *> scopes = visibleScopes;
for (unsigned i = 0; i < q->nameCount(); ++i) { for (unsigned i = 0; i < q->nameCount() - 1; ++i) {
Name *name = q->nameAt(i); Name *name = q->nameAt(i);
if (i + 1 == q->nameCount()) candidates = resolveClassOrNamespace(name, scopes);
candidates = resolve(name, scopes, mode);
else
candidates = resolveClassOrNamespace(name, scopes);
if (candidates.isEmpty() || i + 1 == q->nameCount()) if (candidates.isEmpty())
break; break;
scopes.clear(); scopes.clear();
foreach (Symbol *candidate, candidates) { foreach (Symbol *candidate, candidates) {
if (ScopedSymbol *scoped = candidate->asScopedSymbol()) { ScopedSymbol *scoped = candidate->asScopedSymbol();
scopes.append(scoped->members()); Scope *members = scoped->members();
}
if (! scopes.contains(members))
scopes.append(members);
} }
} }
Identifier *id = q->identifier(); return scopes;
foreach (Scope *scope, visibleScopes) { }
Symbol *symbol = scope->lookat(id);
for (; symbol; symbol = symbol->next()) { QList<Symbol *> LookupContext::resolveQualifiedNameId(QualifiedNameId *q,
if (! symbol->name()) const QList<Scope *> &visibleScopes,
continue; ResolveMode mode) const
else if (! maybeValidSymbol(symbol, mode, candidates)) {
continue; QList<Scope *> scopes;
QualifiedNameId *qq = symbol->name()->asQualifiedNameId();
if (! qq)
continue;
if (q->nameCount() > qq->nameCount())
continue;
for (int i = q->nameCount() - 1; i != -1; --i) { if (q->nameCount() == 1)
Name *a = q->nameAt(i); scopes = visibleScopes; // ### handle global scope lookup
Name *b = qq->nameAt(i); else
scopes = resolveNestedNameSpecifier(q, visibleScopes);
if (! a->isEqualTo(b)) // ### expand the scopes.
break;
else if (i == 0)
candidates.append(symbol);
}
}
}
return candidates; return resolve(q->unqualifiedNameId(), scopes, mode);
} }
QList<Symbol *> LookupContext::resolveOperatorNameId(OperatorNameId *opId, QList<Symbol *> LookupContext::resolveOperatorNameId(OperatorNameId *opId,
......
...@@ -123,6 +123,9 @@ private: ...@@ -123,6 +123,9 @@ private:
const QList<Scope *> &visibleScopes, const QList<Scope *> &visibleScopes,
ResolveMode mode) const; ResolveMode mode) const;
QList<Scope *> resolveNestedNameSpecifier(QualifiedNameId *q,
const QList<Scope *> &visibleScopes) const;
Identifier *identifier(const Name *name) const; Identifier *identifier(const Name *name) const;
QList<Scope *> buildVisibleScopes(); QList<Scope *> buildVisibleScopes();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment