Commit 6a3382d8 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Say hello to LookupContext::resolveNestedNameSpecifier()

parent 6a5d81b0
......@@ -126,59 +126,48 @@ bool LookupContext::maybeValidSymbol(Symbol *symbol,
return false;
}
QList<Symbol *> LookupContext::resolveQualifiedNameId(QualifiedNameId *q,
const QList<Scope *> &visibleScopes,
ResolveMode mode) const
QList<Scope *> LookupContext::resolveNestedNameSpecifier(QualifiedNameId *q,
const QList<Scope *> &visibleScopes) const
{
QList<Scope *> scopes = visibleScopes;
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);
if (i + 1 == q->nameCount())
candidates = resolve(name, scopes, mode);
else
candidates = resolveClassOrNamespace(name, scopes);
candidates = resolveClassOrNamespace(name, scopes);
if (candidates.isEmpty() || i + 1 == q->nameCount())
if (candidates.isEmpty())
break;
scopes.clear();
foreach (Symbol *candidate, candidates) {
if (ScopedSymbol *scoped = candidate->asScopedSymbol()) {
scopes.append(scoped->members());
}
ScopedSymbol *scoped = candidate->asScopedSymbol();
Scope *members = scoped->members();
if (! scopes.contains(members))
scopes.append(members);
}
}
Identifier *id = q->identifier();
foreach (Scope *scope, visibleScopes) {
Symbol *symbol = scope->lookat(id);
for (; symbol; symbol = symbol->next()) {
if (! symbol->name())
continue;
else if (! maybeValidSymbol(symbol, mode, candidates))
continue;
QualifiedNameId *qq = symbol->name()->asQualifiedNameId();
if (! qq)
continue;
if (q->nameCount() > qq->nameCount())
continue;
return scopes;
}
QList<Symbol *> LookupContext::resolveQualifiedNameId(QualifiedNameId *q,
const QList<Scope *> &visibleScopes,
ResolveMode mode) const
{
QList<Scope *> scopes;
for (int i = q->nameCount() - 1; i != -1; --i) {
Name *a = q->nameAt(i);
Name *b = qq->nameAt(i);
if (q->nameCount() == 1)
scopes = visibleScopes; // ### handle global scope lookup
else
scopes = resolveNestedNameSpecifier(q, visibleScopes);
if (! a->isEqualTo(b))
break;
else if (i == 0)
candidates.append(symbol);
}
}
}
// ### expand the scopes.
return candidates;
return resolve(q->unqualifiedNameId(), scopes, mode);
}
QList<Symbol *> LookupContext::resolveOperatorNameId(OperatorNameId *opId,
......
......@@ -123,6 +123,9 @@ private:
const QList<Scope *> &visibleScopes,
ResolveMode mode) const;
QList<Scope *> resolveNestedNameSpecifier(QualifiedNameId *q,
const QList<Scope *> &visibleScopes) const;
Identifier *identifier(const Name *name) const;
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