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

Improved LookupContext::buildVisibleScopes().

parent 754b1c0f
No related branches found
No related tags found
No related merge requests found
...@@ -60,6 +60,17 @@ bool LookupContext::isNameCompatibleWithIdentifier(Name *name, Identifier *id) ...@@ -60,6 +60,17 @@ bool LookupContext::isNameCompatibleWithIdentifier(Name *name, Identifier *id)
return false; return false;
} }
#ifndef CPLUSPLUS_WITH_NO_DEBUG
static void printScopes(const QList<Scope *> &scopes)
{
qDebug() << "===========";
foreach (Scope *scope, scopes) {
qDebug() << "scope:" << scope << scope->owner()->name() << scope->owner()->fileName()
<< scope->owner()->line() << scope->owner()->column();
}
}
#endif
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// LookupContext // LookupContext
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
...@@ -270,33 +281,38 @@ QList<Symbol *> LookupContext::resolve(Name *name, const QList<Scope *> &visible ...@@ -270,33 +281,38 @@ QList<Symbol *> LookupContext::resolve(Name *name, const QList<Scope *> &visible
return candidates; return candidates;
} }
void LookupContext::buildVisibleScopes_helper(Document::Ptr doc, QList<Scope *> *scopes,
QSet<QString> *processed)
{
if (doc && ! processed->contains(doc->fileName())) {
processed->insert(doc->fileName());
if (doc->globalSymbolCount())
scopes->append(doc->globalSymbols());
foreach (const Document::Include &incl, doc->includes()) {
buildVisibleScopes_helper(_documents.value(incl.fileName()),
scopes, processed);
}
}
}
QList<Scope *> LookupContext::buildVisibleScopes() QList<Scope *> LookupContext::buildVisibleScopes()
{ {
QList<Scope *> scopes; QList<Scope *> scopes;
if (_symbol) { if (_symbol) {
for (Scope *scope = _symbol->scope(); scope; scope = scope->enclosingScope()) { for (Scope *scope = _symbol->scope(); scope; scope = scope->enclosingScope()) {
if (scope == _thisDocument->globalSymbols())
break;
scopes.append(scope); scopes.append(scope);
} }
} }
QSet<QString> processed; QSet<QString> processed;
processed.insert(_thisDocument->fileName()); buildVisibleScopes_helper(_thisDocument, &scopes, &processed);
return scopes;
QList<QString> todo = _thisDocument->includedFiles();
while (! todo.isEmpty()) {
QString fn = todo.last();
todo.removeLast();
if (processed.contains(fn))
continue;
processed.insert(fn);
if (Document::Ptr doc = document(fn)) {
scopes.append(doc->globalNamespace()->members());
todo += doc->includedFiles();
}
}
while (true) { while (true) {
QList<Scope *> expandedScopes; QList<Scope *> expandedScopes;
......
...@@ -128,6 +128,10 @@ public: ...@@ -128,6 +128,10 @@ public:
private: private:
QList<Scope *> buildVisibleScopes(); QList<Scope *> buildVisibleScopes();
void buildVisibleScopes_helper(Document::Ptr doc, QList<Scope *> *scopes,
QSet<QString> *processed);
static bool isNameCompatibleWithIdentifier(Name *name, Identifier *id); static bool isNameCompatibleWithIdentifier(Name *name, Identifier *id);
static bool maybeValidSymbol(Symbol *symbol, static bool maybeValidSymbol(Symbol *symbol,
......
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