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)
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 (! scope)
scope = findScope(ast);
if (const Identifier *ident = ast->name->identifier()) {
const QByteArray id = QByteArray::fromRawData(ident->chars(), ident->size());
if (_potentialTypes.contains(id)) {
Scope *scope = findScope(ast);
const QList<LookupItem> candidates = _context.lookup(ast->name, scope);
addUsage(candidates, ast);
} else if (_potentialMembers.contains(id)) {
Scope *scope = findScope(ast);
const QList<LookupItem> candidates = _context.lookup(ast->name, scope);
addMemberUsage(candidates, ast);
}
......@@ -545,6 +546,28 @@ void CheckSymbols::endVisit(TemplateDeclarationAST *)
_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)
{
_functionDefinitionStack.append(ast);
......
......@@ -93,7 +93,7 @@ protected:
bool warning(unsigned line, unsigned column, const QString &text, unsigned length = 0);
bool warning(AST *ast, const QString &text);
void checkName(NameAST *ast);
void checkName(NameAST *ast, Scope *scope = 0);
void checkNamespace(NameAST *name);
void addUsage(ClassOrNamespace *b, NameAST *ast);
void addUsage(const QList<LookupItem> &candidates, NameAST *ast);
......@@ -123,6 +123,8 @@ protected:
virtual bool visit(FunctionDefinitionAST *ast);
virtual bool visit(MemberAccessAST *ast);
virtual bool visit(MemInitializerAST *ast);
unsigned startOfTemplateDeclaration(TemplateDeclarationAST *ast) const;
Scope *findScope(AST *ast) const;
......
......@@ -155,6 +155,12 @@ protected:
return false;
}
virtual bool visit(MemInitializerAST *ast)
{
accept(ast->expression_list);
return false;
}
virtual bool visit(TemplateIdAST *ast)
{
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