Commit 3c51e5b2 authored by Roberto Raggi's avatar Roberto Raggi

Return the class declaration as canonical symbol for ctors, dtors, and class names.

parent ef0e1a64
......@@ -504,10 +504,29 @@ void LookupContext::expand(Scope *scope,
Symbol *LookupContext::canonicalSymbol(Symbol *symbol)
{
Symbol *canonical = symbol;
Class *canonicalClass = 0;
for (; symbol; symbol = symbol->next()) {
if (symbol->name() == canonical->name())
if (symbol->identifier() == canonical->identifier()) {
canonical = symbol;
if (Class *klass = symbol->asClass())
canonicalClass = klass;
}
}
if (canonicalClass) {
Q_ASSERT(canonical != 0);
if (canonical->isForwardClassDeclaration())
return canonicalClass; // prefer class declarations when available.
}
if (canonical && canonical->scope()->isClassScope()) {
Class *enclosingClass = canonical->scope()->owner()->asClass();
if (enclosingClass->identifier() == canonical->identifier())
return enclosingClass;
}
return canonical;
......
......@@ -304,14 +304,22 @@ protected:
}
}
if (ast->unqualified_name) {
SimpleNameAST *simple_name = ast->unqualified_name->asSimpleName();
if (NameAST *unqualified_name = ast->unqualified_name) {
unsigned identifier_token = 0;
if (SimpleNameAST *simple_name = unqualified_name->asSimpleName())
identifier_token = simple_name->identifier_token;
else if (DestructorNameAST *dtor_name = unqualified_name->asDestructorName())
identifier_token = dtor_name->identifier_token;
TemplateIdAST *template_id = 0;
if (! simple_name) {
template_id = ast->unqualified_name->asTemplateId();
if (! identifier_token) {
template_id = unqualified_name->asTemplateId();
if (template_id) {
identifier_token = template_id->identifier_token;
for (TemplateArgumentListAST *template_arguments = template_id->template_arguments;
template_arguments; template_arguments = template_arguments->next) {
accept(template_arguments->template_argument);
......@@ -319,14 +327,8 @@ protected:
}
}
if (simple_name || template_id) {
const unsigned identifier_token = simple_name
? simple_name->identifier_token
: template_id->identifier_token;
if (identifier(identifier_token) == _id)
checkExpression(ast->firstToken(), identifier_token);
}
if (identifier_token && identifier(identifier_token) == _id)
checkExpression(ast->firstToken(), identifier_token);
}
return false;
......
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