Commit 034798c0 authored by Roberto Raggi's avatar Roberto Raggi

Recognize the members.

parent 6974b2be
......@@ -301,6 +301,8 @@ CheckSymbols::CheckSymbols(Document::Ptr doc, const LookupContext &context)
_scopes = collectTypes.scopes();
_flushRequested = false;
_flushLine = 0;
typeOfExpression.init(_doc, _context.snapshot(), _context.bindings());
}
CheckSymbols::~CheckSymbols()
......@@ -381,6 +383,25 @@ bool CheckSymbols::visit(NamedTypeSpecifierAST *)
bool CheckSymbols::visit(MemberAccessAST *ast)
{
accept(ast->base_expression);
if (! ast->member_name)
return false;
if (const Name *name = ast->member_name->name) {
if (const Identifier *ident = name->identifier()) {
const QByteArray id = QByteArray::fromRawData(ident->chars(), ident->size());
if (_potentialMembers.contains(id)) {
Scope *scope = findScope(ast);
const Token start = tokenAt(ast->firstToken());
const Token end = tokenAt(ast->lastToken() - 1);
const QByteArray expression = _doc->source().mid(start.begin(), end.end() - start.begin());
const QList<LookupItem> candidates = typeOfExpression(expression, scope, TypeOfExpression::Preprocess);
addMemberUsage(candidates, ast->member_name);
}
}
}
return false;
}
......@@ -431,10 +452,6 @@ void CheckSymbols::checkMemberName(NameAST *ast)
Scope *scope = findScope(ast);
const QList<LookupItem> candidates = _context.lookup(ast->name, scope);
addMemberUsage(candidates, ast);
} else if (_potentialMembers.contains(id)) {
Scope *scope = findScope(ast);
const QList<LookupItem> candidates = _context.lookup(ast->name, scope);
addMemberUsage(candidates, ast);
}
}
}
......@@ -647,6 +664,7 @@ void CheckSymbols::addMemberUsage(const QList<LookupItem> &candidates, NameAST *
const Use use(line, column, length, Use::Field);
addUsage(use);
//Overview oo;
//qDebug() << "added use" << oo(ast->name) << line << column << length;
}
}
......
......@@ -34,6 +34,8 @@
#include <cplusplus/CppDocument.h>
#include <cplusplus/LookupContext.h>
#include <cplusplus/TypeOfExpression.h>
#include <ASTVisitor.h>
#include <QtCore/QSet>
#include <QtCore/QFuture>
......@@ -129,6 +131,7 @@ protected:
private:
Document::Ptr _doc;
LookupContext _context;
TypeOfExpression typeOfExpression;
QString _fileName;
QList<Document::DiagnosticMessage> _diagnosticMessages;
QSet<QByteArray> _potentialTypes;
......
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