Commit f088ba71 authored by Roberto Raggi's avatar Roberto Raggi

Handle C++ mem-intitializers

parent fb316ed7
...@@ -425,17 +425,18 @@ void CheckSymbols::checkNamespace(NameAST *name) ...@@ -425,17 +425,18 @@ void CheckSymbols::checkNamespace(NameAST *name)
warning(line, column, QCoreApplication::translate("CheckUndefinedSymbols", "Expected a namespace-name"), length); warning(line, column, QCoreApplication::translate("CheckUndefinedSymbols", "Expected a namespace-name"), length);
} }
void CheckSymbols::checkName(NameAST *ast) void CheckSymbols::checkName(NameAST *ast, Scope *scope)
{ {
if (ast && ast->name) { if (ast && ast->name) {
if (! scope)
scope = findScope(ast);
if (const Identifier *ident = ast->name->identifier()) { if (const Identifier *ident = ast->name->identifier()) {
const QByteArray id = QByteArray::fromRawData(ident->chars(), ident->size()); const QByteArray id = QByteArray::fromRawData(ident->chars(), ident->size());
if (_potentialTypes.contains(id)) { if (_potentialTypes.contains(id)) {
Scope *scope = findScope(ast);
const QList<LookupItem> candidates = _context.lookup(ast->name, scope); const QList<LookupItem> candidates = _context.lookup(ast->name, scope);
addUsage(candidates, ast); addUsage(candidates, ast);
} else if (_potentialMembers.contains(id)) { } else if (_potentialMembers.contains(id)) {
Scope *scope = findScope(ast);
const QList<LookupItem> candidates = _context.lookup(ast->name, scope); const QList<LookupItem> candidates = _context.lookup(ast->name, scope);
addMemberUsage(candidates, ast); addMemberUsage(candidates, ast);
} }
...@@ -545,6 +546,28 @@ void CheckSymbols::endVisit(TemplateDeclarationAST *) ...@@ -545,6 +546,28 @@ void CheckSymbols::endVisit(TemplateDeclarationAST *)
_templateDeclarationStack.takeFirst(); _templateDeclarationStack.takeFirst();
} }
bool CheckSymbols::visit(MemInitializerAST *ast)
{
if (_functionDefinitionStack.isEmpty())
return false;
if (ast->name) {
FunctionDefinitionAST *enclosingFunction = _functionDefinitionStack.back();
if (ClassOrNamespace *binding = _context.lookupType(enclosingFunction->symbol)) {
foreach (Symbol *s, binding->symbols()) {
if (Class *klass = s->asClass()){
checkName(ast->name, klass->members());
break;
}
}
}
}
accept(ast->expression_list);
return false;
}
bool CheckSymbols::visit(FunctionDefinitionAST *ast) bool CheckSymbols::visit(FunctionDefinitionAST *ast)
{ {
_functionDefinitionStack.append(ast); _functionDefinitionStack.append(ast);
......
...@@ -93,7 +93,7 @@ protected: ...@@ -93,7 +93,7 @@ protected:
bool warning(unsigned line, unsigned column, const QString &text, unsigned length = 0); bool warning(unsigned line, unsigned column, const QString &text, unsigned length = 0);
bool warning(AST *ast, const QString &text); bool warning(AST *ast, const QString &text);
void checkName(NameAST *ast); void checkName(NameAST *ast, Scope *scope = 0);
void checkNamespace(NameAST *name); void checkNamespace(NameAST *name);
void addUsage(ClassOrNamespace *b, NameAST *ast); void addUsage(ClassOrNamespace *b, NameAST *ast);
void addUsage(const QList<LookupItem> &candidates, NameAST *ast); void addUsage(const QList<LookupItem> &candidates, NameAST *ast);
...@@ -123,6 +123,8 @@ protected: ...@@ -123,6 +123,8 @@ protected:
virtual bool visit(FunctionDefinitionAST *ast); virtual bool visit(FunctionDefinitionAST *ast);
virtual bool visit(MemberAccessAST *ast); virtual bool visit(MemberAccessAST *ast);
virtual bool visit(MemInitializerAST *ast);
unsigned startOfTemplateDeclaration(TemplateDeclarationAST *ast) const; unsigned startOfTemplateDeclaration(TemplateDeclarationAST *ast) const;
Scope *findScope(AST *ast) const; Scope *findScope(AST *ast) const;
......
...@@ -155,6 +155,12 @@ protected: ...@@ -155,6 +155,12 @@ protected:
return false; return false;
} }
virtual bool visit(MemInitializerAST *ast)
{
accept(ast->expression_list);
return false;
}
virtual bool visit(TemplateIdAST *ast) virtual bool visit(TemplateIdAST *ast)
{ {
for (TemplateArgumentListAST *arg = ast->template_argument_list; arg; arg = arg->next) for (TemplateArgumentListAST *arg = ast->template_argument_list; arg; arg = arg->next)
......
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