Commit 17fd33bd authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Store the declaration (if any) associated with the LookupItem.

parent 37fde0c9
......@@ -44,11 +44,11 @@ uint CPlusPlus::qHash(const CPlusPlus::LookupItem &key)
}
LookupItem::LookupItem()
: _lastVisibleSymbol(0)
: _lastVisibleSymbol(0), _declaration(0)
{ }
LookupItem::LookupItem(const FullySpecifiedType &type, Symbol *lastVisibleSymbol)
: _type(type), _lastVisibleSymbol(lastVisibleSymbol)
LookupItem::LookupItem(const FullySpecifiedType &type, Symbol *lastVisibleSymbol, Symbol *declaration)
: _type(type), _lastVisibleSymbol(lastVisibleSymbol), _declaration(declaration)
{ }
FullySpecifiedType LookupItem::type() const
......@@ -57,6 +57,12 @@ FullySpecifiedType LookupItem::type() const
void LookupItem::setType(const FullySpecifiedType &type)
{ _type = type; }
Symbol *LookupItem::declaration() const
{ return _declaration; }
void LookupItem::setDeclaration(Symbol *declaration)
{ _declaration = declaration; }
Symbol *LookupItem::lastVisibleSymbol() const
{ return _lastVisibleSymbol; }
......@@ -65,8 +71,8 @@ void LookupItem::setLastVisibleSymbol(Symbol *symbol)
bool LookupItem::operator == (const LookupItem &other) const
{
if (_type == other._type)
return _lastVisibleSymbol == other._lastVisibleSymbol;
if (_type == other._type && _declaration == other._declaration && _lastVisibleSymbol == other._lastVisibleSymbol)
return true;
return false;
}
......
......@@ -38,21 +38,37 @@ namespace CPlusPlus {
class CPLUSPLUS_EXPORT LookupItem
{
public:
/// Constructs an null LookupItem.
LookupItem();
LookupItem(const FullySpecifiedType &type, Symbol *lastVisibleSymbol);
/// Contructs a LookupItem with the given \a type, \a lastVisibleSymbol and \a declaration.
LookupItem(const FullySpecifiedType &type, Symbol *lastVisibleSymbol, Symbol *declaration = 0);
/// Returns this item's type.
FullySpecifiedType type() const;
/// Sets this item's type.
void setType(const FullySpecifiedType &type);
/// Returns the last visible symbol.
Symbol *lastVisibleSymbol() const;
/// Sets the last visible symbol.
void setLastVisibleSymbol(Symbol *symbol);
/// Returns this item's declaration.
Symbol *declaration() const;
/// Sets this item's declaration.
void setDeclaration(Symbol *declaration);
bool operator == (const LookupItem &other) const;
bool operator != (const LookupItem &other) const;
private:
FullySpecifiedType _type;
Symbol *_lastVisibleSymbol;
Symbol *_declaration;
};
uint qHash(const CPlusPlus::LookupItem &result);
......
......@@ -107,10 +107,12 @@ ResolveExpression::switchResults(const QList<LookupItem> &results)
return previousResults;
}
void ResolveExpression::addResults(const QList<LookupItem> &results)
void ResolveExpression::addResults(const QList<Symbol *> &symbols)
{
foreach (const LookupItem r, results)
addResult(r);
foreach (Symbol *s, symbols) {
LookupItem item(s->type(), s, s);
_results.append(item);
}
}
void ResolveExpression::addResult(const FullySpecifiedType &ty, Symbol *symbol)
......@@ -402,9 +404,7 @@ bool ResolveExpression::visit(QualifiedNameAST *ast)
{
if (const Name *name = ast->name) {
const QList<Symbol *> candidates = _context.lookup(name, _scope);
foreach (Symbol *candidate, candidates)
addResult(candidate->type(), candidate);
addResults(candidates);
}
return false;
......@@ -412,19 +412,15 @@ bool ResolveExpression::visit(QualifiedNameAST *ast)
bool ResolveExpression::visit(SimpleNameAST *ast)
{
QList<Symbol *> symbols = _context.lookup(ast->name, _scope);
foreach (Symbol *symbol, symbols)
addResult(symbol->type(), symbol);
const QList<Symbol *> candidates = _context.lookup(ast->name, _scope);
addResults(candidates);
return false;
}
bool ResolveExpression::visit(TemplateIdAST *ast)
{
const QList<Symbol *> symbols = _context.lookup(ast->name, _scope);
foreach (Symbol *symbol, symbols)
addResult(symbol->type(), symbol);
const QList<Symbol *> candidates = _context.lookup(ast->name, _scope);
addResults(candidates);
return false;
}
......
......@@ -67,9 +67,11 @@ protected:
FullySpecifiedType instantiate(const Name *className, Symbol *candidate) const;
void thisObject();
void addResult(const FullySpecifiedType &ty, Symbol *symbol = 0);
void addResult(const LookupItem &result);
void addResults(const QList<LookupItem> &results);
void addResults(const QList<Symbol *> &symbols);
bool maybeValidPrototype(Function *funTy, unsigned actualArgumentCount) const;
......
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