Commit 37fde0c9 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Split LookupContext::lookup() in lookup() and find().

lookup() searches for symbols in the given binding and the enclosing scopes,
while find() searches for symbols only in the given binding.
parent 7446f5ca
......@@ -304,7 +304,17 @@ ClassOrNamespace *ClassOrNamespace::globalNamespace() const
return e;
}
QList<Symbol *> ClassOrNamespace::find(const Name *name)
{
return lookup_helper(name, false);
}
QList<Symbol *> ClassOrNamespace::lookup(const Name *name)
{
return lookup_helper(name, true);
}
QList<Symbol *> ClassOrNamespace::lookup_helper(const Name *name, bool searchInEnclosingScope)
{
QList<Symbol *> result;
if (! name)
......@@ -317,7 +327,7 @@ QList<Symbol *> ClassOrNamespace::lookup(const Name *name)
binding = globalNamespace();
if (q->nameCount() == 1)
return binding->lookup(q->unqualifiedNameId());
return binding->find(q->unqualifiedNameId());
binding = binding->lookupClassOrNamespace(q->nameAt(0));
......@@ -325,7 +335,7 @@ QList<Symbol *> ClassOrNamespace::lookup(const Name *name)
binding = binding->findClassOrNamespace(q->nameAt(index));
if (binding)
result = binding->lookup(q->unqualifiedNameId());
result = binding->find(q->unqualifiedNameId());
return result;
}
......@@ -335,7 +345,7 @@ QList<Symbol *> ClassOrNamespace::lookup(const Name *name)
do {
lookup_helper(name, binding, &result, &processed, /*templateId = */ 0);
binding = binding->_parent;
} while (binding);
} while (searchInEnclosingScope && binding);
return result;
}
......
......@@ -56,6 +56,7 @@ public:
ClassOrNamespace *globalNamespace() const;
QList<Symbol *> lookup(const Name *name);
QList<Symbol *> find(const Name *name);
ClassOrNamespace *lookupClassOrNamespace(const Name *name);
ClassOrNamespace *findClassOrNamespace(const Name *name);
......@@ -68,6 +69,8 @@ private:
/// \internal
ClassOrNamespace *findOrCreate(const Name *name);
QList<Symbol *> lookup_helper(const Name *name, bool searchInEnclosingScope);
void addTodo(Symbol *symbol);
void addSymbol(Symbol *symbol);
void addEnum(Enum *e);
......
......@@ -490,7 +490,7 @@ bool ResolveExpression::visit(CallAST *ast)
if (NamedType *namedTy = ty->asNamedType()) {
if (ClassOrNamespace *b = _context.classOrNamespace(namedTy->name(), lastVisibleSymbol)) {
foreach (Symbol *overload, b->lookup(functionCallOp)) {
foreach (Symbol *overload, b->find(functionCallOp)) {
if (Function *funTy = overload->type()->asFunctionType()) {
if (maybeValidPrototype(funTy, actualArgumentCount)) {
Function *proto = instantiate(namedTy->name(), funTy)->asFunctionType();
......@@ -535,7 +535,7 @@ bool ResolveExpression::visit(ArrayAccessAST *ast)
} else if (NamedType *namedTy = ty->asNamedType()) {
if (ClassOrNamespace *b = _context.classOrNamespace(namedTy->name(), lastVisibleSymbol)) {
foreach (Symbol *overload, b->lookup(arrayAccessOp)) {
foreach (Symbol *overload, b->find(arrayAccessOp)) {
if (Function *funTy = overload->type()->asFunctionType()) {
Function *proto = instantiate(namedTy->name(), funTy)->asFunctionType();
// ### TODO: check the actual arguments
......@@ -610,7 +610,7 @@ ResolveExpression::resolveBaseExpression(const QList<LookupItem> &baseResults, i
}
if (ClassOrNamespace *b = _context.classOrNamespace(namedTy->name(), result.lastVisibleSymbol())) {
foreach (Symbol *overload, b->lookup(arrowAccessOp)) {
foreach (Symbol *overload, b->find(arrowAccessOp)) {
if (Function *funTy = overload->type()->asFunctionType()) {
FullySpecifiedType f = instantiate(namedTy->name(), funTy);
FullySpecifiedType retTy = f->asFunctionType()->returnType().simplified();
......@@ -687,7 +687,7 @@ ResolveExpression::resolveMemberExpression(const QList<LookupItem> &baseResults,
else if (NamedType *namedTy = ty->asNamedType()) {
if (ClassOrNamespace *b = _context.classOrNamespace(namedTy->name(), r.lastVisibleSymbol())) {
foreach (Symbol *c, b->lookup(memberName))
foreach (Symbol *c, b->find(memberName))
results.append(LookupItem(instantiate(namedTy->name(), c), c));
}
}
......
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