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,
return false;
}
QList<Symbol *> LookupContext::resolve(Name *name, const QList<Scope *> &visibleScopes,
ResolveMode mode) const
QList<Symbol *> LookupContext::resolveQualifiedNameId(QualifiedNameId *q,
const QList<Scope *> &visibleScopes,
ResolveMode mode) const
{
QList<Scope *> scopes = visibleScopes;
QList<Symbol *> candidates;
if (!name)
return candidates;
if (QualifiedNameId *q = name->asQualifiedNameId()) {
QList<Scope *> scopes = visibleScopes;
for (unsigned i = 0; i < q->nameCount(); ++i) {
Name *name = q->nameAt(i);
for (unsigned i = 0; i < q->nameCount(); ++i) {
Name *name = q->nameAt(i);
if (i + 1 == q->nameCount())
candidates = resolve(name, scopes, mode);
else
candidates = resolveClassOrNamespace(name, scopes);
if (i + 1 == q->nameCount())
candidates = resolve(name, scopes, mode);
else
candidates = resolveClassOrNamespace(name, scopes);
if (candidates.isEmpty() || i + 1 == q->nameCount())
break;
if (candidates.isEmpty() || i + 1 == q->nameCount())
break;
scopes.clear();
foreach (Symbol *candidate, candidates) {
if (ScopedSymbol *scoped = candidate->asScopedSymbol()) {
scopes.append(scoped->members());
}
scopes.clear();
foreach (Symbol *candidate, candidates) {
if (ScopedSymbol *scoped = candidate->asScopedSymbol()) {
scopes.append(scoped->members());
}
}
}
Identifier *id = identifier(name);
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;
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;
for (int i = q->nameCount() - 1; i != -1; --i) {
Name *a = q->nameAt(i);
Name *b = qq->nameAt(i);
for (int i = q->nameCount() - 1; i != -1; --i) {
Name *a = q->nameAt(i);
Name *b = qq->nameAt(i);
if (! a->isEqualTo(b))
break;
else if (i == 0)
candidates.append(symbol);
}
if (! a->isEqualTo(b))
break;
else if (i == 0)
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;
}
if (QualifiedNameId *q = name->asQualifiedNameId())
return resolveQualifiedNameId(q, visibleScopes, mode);
if (Identifier *id = identifier(name)) {
for (int scopeIndex = 0; scopeIndex < visibleScopes.size(); ++scopeIndex) {
......
......@@ -115,6 +115,10 @@ public:
QList<Scope *> *expandedScopes) const;
private:
QList<Symbol *> resolveQualifiedNameId(QualifiedNameId *q,
const QList<Scope *> &visibleScopes,
ResolveMode mode) 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