Commit dc59d287 authored by Nikolai Kosjar's avatar Nikolai Kosjar

C++: Check for Function::name() before using it

Lambdas do not have a name.

Change-Id: Ifda4816c62dcfe19bdbb1649dc1caf408e056b37
Task-number: QTCREATORBUG-12686
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 67a7696e
......@@ -721,7 +721,7 @@ void CreateBindings::lookupInScope(const Name *name, Scope *scope,
continue; // skip using namespace directives
else if (! id->match(s->identifier()))
continue;
else if (s->name()->isQualifiedNameId())
else if (s->name() && s->name()->isQualifiedNameId())
continue; // skip qualified ids.
if (Q_UNLIKELY(debug)) {
......
......@@ -350,13 +350,15 @@ void ResolveExpression::thisObject()
FullySpecifiedType ptrTy(control()->pointerType(classTy));
addResult(ptrTy, fun->enclosingScope());
break;
} else if (const QualifiedNameId *q = fun->name()->asQualifiedNameId()) {
if (q->base()) {
FullySpecifiedType classTy(control()->namedType(q->base()));
FullySpecifiedType ptrTy(control()->pointerType(classTy));
addResult(ptrTy, fun->enclosingScope());
} else if (const Name *name = fun->name()) {
if (const QualifiedNameId *q = name->asQualifiedNameId()) {
if (q->base()) {
FullySpecifiedType classTy(control()->namedType(q->base()));
FullySpecifiedType ptrTy(control()->pointerType(classTy));
addResult(ptrTy, fun->enclosingScope());
}
break;
}
break;
}
}
}
......
......@@ -193,7 +193,7 @@ Class *isMemberFunction(const LookupContext &context, Function *function)
const Name *functionName = function->name();
if (!functionName)
return 0; // anonymous function names are not valid c++
return 0;
if (!functionName->isQualifiedNameId())
return 0; // trying to add a declaration for a global function
......@@ -225,7 +225,7 @@ Namespace *isNamespaceFunction(const LookupContext &context, Function *function)
const Name *functionName = function->name();
if (!functionName)
return 0; // anonymous function names are not valid c++
return 0;
// global namespace
if (!functionName->isQualifiedNameId()) {
......@@ -4148,7 +4148,7 @@ QString definitionSignature(const CppQuickFixAssistInterface *assist,
oo.showReturnTypes = true;
oo.showArgumentNames = true;
const Name *name = func->name();
if (nameIncludesOperatorName(name)) {
if (name && nameIncludesOperatorName(name)) {
CoreDeclaratorAST *coreDeclarator = functionDefinitionAST->declarator->core_declarator;
const QString operatorNameText = baseFile->textOf(coreDeclarator);
oo.includeWhiteSpaceInOperatorName = operatorNameText.contains(QLatin1Char(' '));
......
......@@ -278,7 +278,7 @@ void SymbolFinder::findMatchingDeclaration(const LookupContext &context,
const Name *functionName = functionType->name();
if (!functionName)
return; // anonymous function names are not valid c++
return;
ClassOrNamespace *binding = 0;
const QualifiedNameId *qName = functionName->asQualifiedNameId();
......
......@@ -1122,56 +1122,59 @@ void generateAST_cpp(const Snapshot &snapshot, const QDir &cplusplusDir)
TranslationUnitAST *xUnit = AST_cpp_document->translationUnit()->ast()->asTranslationUnit();
for (DeclarationListAST *iter = xUnit->declaration_list; iter; iter = iter->next) {
if (FunctionDefinitionAST *funDef = iter->value->asFunctionDefinition()) {
if (const QualifiedNameId *qName = funDef->symbol->name()->asQualifiedNameId()) {
const QString className = oo(qName->base());
const QString methodName = oo(qName->name());
QTextCursor cursor(&cpp_document);
unsigned line = 0, column = 0;
AST_cpp_document->translationUnit()->getTokenStartPosition(funDef->firstToken(), &line, &column);
const int start = cpp_document.findBlockByNumber(line - 1).position() + column - 1;
cursor.setPosition(start);
int doxyStart = start;
const bool isGenerated = checkGenerated(cursor, &doxyStart);
AST_cpp_document->translationUnit()->getTokenEndPosition(funDef->lastToken() - 1, &line, &column);
int end = cpp_document.findBlockByNumber(line - 1).position() + column - 1;
while (cpp_document.characterAt(end).isSpace())
++end;
if (methodName == QLatin1String("firstToken")) {
ClassSpecifierAST *classAST = classesNeedingFirstToken.value(className, 0);
GenInfo info;
info.end = end;
if (classAST) {
info.classAST = classAST;
info.firstToken = true;
info.start = start;
classesNeedingFirstToken.remove(className);
} else {
info.start = doxyStart;
info.remove = true;
if (const Name *name = funDef->symbol->name()) {
if (const QualifiedNameId *qName = name->asQualifiedNameId()) {
const QString className = oo(qName->base());
const QString methodName = oo(qName->name());
QTextCursor cursor(&cpp_document);
unsigned line = 0, column = 0;
AST_cpp_document->translationUnit()->getTokenStartPosition(funDef->firstToken(), &line, &column);
const int start = cpp_document.findBlockByNumber(line - 1).position() + column - 1;
cursor.setPosition(start);
int doxyStart = start;
const bool isGenerated = checkGenerated(cursor, &doxyStart);
AST_cpp_document->translationUnit()->getTokenEndPosition(funDef->lastToken() - 1, &line, &column);
int end = cpp_document.findBlockByNumber(line - 1).position() + column - 1;
while (cpp_document.characterAt(end).isSpace())
++end;
if (methodName == QLatin1String("firstToken")) {
ClassSpecifierAST *classAST = classesNeedingFirstToken.value(className, 0);
GenInfo info;
info.end = end;
if (classAST) {
info.classAST = classAST;
info.firstToken = true;
info.start = start;
classesNeedingFirstToken.remove(className);
} else {
info.start = doxyStart;
info.remove = true;
}
if (isGenerated)
todo.append(info);
} else if (methodName == QLatin1String("lastToken")) {
ClassSpecifierAST *classAST = classesNeedingLastToken.value(className, 0);
GenInfo info;
info.end = end;
if (classAST) {
info.classAST = classAST;
info.start = start;
info.lastToken = true;
classesNeedingLastToken.remove(className);
} else {
info.start = doxyStart;
info.remove = true;
}
if (isGenerated)
todo.append(info);
}
if (isGenerated)
todo.append(info);
} else if (methodName == QLatin1String("lastToken")) {
ClassSpecifierAST *classAST = classesNeedingLastToken.value(className, 0);
GenInfo info;
info.end = end;
if (classAST) {
info.classAST = classAST;
info.start = start;
info.lastToken = true;
classesNeedingLastToken.remove(className);
} else {
info.start = doxyStart;
info.remove = true;
}
if (isGenerated)
todo.append(info);
}
}
}
}
......
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