Commit d01795d9 authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Reimplemented Type::as*Type() using virtual methods.

parent ce22a960
...@@ -63,11 +63,13 @@ Icons::Icons() ...@@ -63,11 +63,13 @@ Icons::Icons()
QIcon Icons::iconForSymbol(const Symbol *symbol) const QIcon Icons::iconForSymbol(const Symbol *symbol) const
{ {
if (symbol->isFunction() || (symbol->isDeclaration() && symbol->type()->isFunction())) FullySpecifiedType symbolType = symbol->type();
if (symbol->isFunction() || (symbol->isDeclaration() && symbolType &&
symbolType->isFunctionType()))
{ {
const Function *function = symbol->asFunction(); const Function *function = symbol->asFunction();
if (!function) if (!function)
function = symbol->type()->asFunction(); function = symbol->type()->asFunctionType();
if (function->isSlot()) { if (function->isSlot()) {
if (function->isPublic()) { if (function->isPublic()) {
......
...@@ -171,7 +171,7 @@ QVariant OverviewModel::data(const QModelIndex &index, int role) const ...@@ -171,7 +171,7 @@ QVariant OverviewModel::data(const QModelIndex &index, int role) const
if (! symbol->isScopedSymbol() || symbol->isFunction()) { if (! symbol->isScopedSymbol() || symbol->isFunction()) {
QString type = _overview.prettyType(symbol->type()); QString type = _overview.prettyType(symbol->type());
if (! type.isEmpty()) { if (! type.isEmpty()) {
if (! symbol->type()->isFunction()) if (! symbol->type()->isFunctionType())
name += QLatin1String(": "); name += QLatin1String(": ");
name += type; name += type;
} }
......
...@@ -512,7 +512,7 @@ bool ResolveExpression::visit(CallAST *ast) ...@@ -512,7 +512,7 @@ bool ResolveExpression::visit(CallAST *ast)
_results.clear(); _results.clear();
foreach (Result p, baseResults) { foreach (Result p, baseResults) {
if (Function *funTy = p.first->asFunction()) { if (Function *funTy = p.first->asFunctionType()) {
unsigned minNumberArguments = 0; unsigned minNumberArguments = 0;
for (; minNumberArguments < funTy->argumentCount(); ++minNumberArguments) { for (; minNumberArguments < funTy->argumentCount(); ++minNumberArguments) {
Argument *arg = funTy->argumentAt(minNumberArguments)->asArgument(); Argument *arg = funTy->argumentAt(minNumberArguments)->asArgument();
...@@ -528,7 +528,7 @@ bool ResolveExpression::visit(CallAST *ast) ...@@ -528,7 +528,7 @@ bool ResolveExpression::visit(CallAST *ast)
p.first = funTy->returnType(); p.first = funTy->returnType();
addResult(p); addResult(p);
} }
} else if (Class *classTy = p.first->asClass()) { } else if (Class *classTy = p.first->asClassType()) {
// Constructor call // Constructor call
p.first = control()->namedType(classTy->name()); p.first = control()->namedType(classTy->name());
addResult(p); addResult(p);
...@@ -566,7 +566,7 @@ bool ResolveExpression::visit(ArrayAccessAST *ast) ...@@ -566,7 +566,7 @@ bool ResolveExpression::visit(ArrayAccessAST *ast)
resolveArrayOperator(p, namedTy, classObject->asClass()); resolveArrayOperator(p, namedTy, classObject->asClass());
foreach (Result r, overloads) { foreach (Result r, overloads) {
FullySpecifiedType ty = r.first; FullySpecifiedType ty = r.first;
Function *funTy = ty->asFunction(); Function *funTy = ty->asFunctionType();
if (! funTy) if (! funTy)
continue; continue;
...@@ -621,7 +621,7 @@ ResolveExpression::resolveMemberExpression(const QList<Result> &baseResults, ...@@ -621,7 +621,7 @@ ResolveExpression::resolveMemberExpression(const QList<Result> &baseResults,
classObject->asClass()); classObject->asClass());
foreach (Result r, overloads) { foreach (Result r, overloads) {
FullySpecifiedType ty = r.first; FullySpecifiedType ty = r.first;
Function *funTy = ty->asFunction(); Function *funTy = ty->asFunctionType();
if (! funTy) if (! funTy)
continue; continue;
...@@ -651,7 +651,7 @@ ResolveExpression::resolveMemberExpression(const QList<Result> &baseResults, ...@@ -651,7 +651,7 @@ ResolveExpression::resolveMemberExpression(const QList<Result> &baseResults,
if (NamedType *namedTy = ty->asNamedType()) if (NamedType *namedTy = ty->asNamedType())
results += resolveMember(p, memberName, namedTy); results += resolveMember(p, memberName, namedTy);
else if (Function *fun = ty->asFunction()) { else if (Function *fun = ty->asFunctionType()) {
if (fun->scope()->isBlockScope() || fun->scope()->isNamespaceScope()) { if (fun->scope()->isBlockScope() || fun->scope()->isNamespaceScope()) {
ty = fun->returnType(); ty = fun->returnType();
...@@ -849,7 +849,7 @@ QList<Symbol *> ResolveClass::resolveClass(NamedType *namedTy, ...@@ -849,7 +849,7 @@ QList<Symbol *> ResolveClass::resolveClass(NamedType *namedTy,
resolvedSymbols.append(klass); resolvedSymbols.append(klass);
} else if (candidate->isTypedef()) { } else if (candidate->isTypedef()) {
if (Declaration *decl = candidate->asDeclaration()) { if (Declaration *decl = candidate->asDeclaration()) {
if (Class *asClass = decl->type()->asClass()) { if (Class *asClass = decl->type()->asClassType()) {
// typedef struct { } Point; // typedef struct { } Point;
// Point pt; // Point pt;
// pt. // pt.
...@@ -863,7 +863,7 @@ QList<Symbol *> ResolveClass::resolveClass(NamedType *namedTy, ...@@ -863,7 +863,7 @@ QList<Symbol *> ResolveClass::resolveClass(NamedType *namedTy,
} }
} }
} else if (Declaration *decl = candidate->asDeclaration()) { } else if (Declaration *decl = candidate->asDeclaration()) {
if (Function *funTy = decl->type()->asFunction()) { if (Function *funTy = decl->type()->asFunctionType()) {
// QString foo("ciao"); // QString foo("ciao");
// foo. // foo.
if (funTy->scope()->isBlockScope() || funTy->scope()->isNamespaceScope()) { if (funTy->scope()->isBlockScope() || funTy->scope()->isNamespaceScope()) {
......
...@@ -424,7 +424,7 @@ static bool isCompatible(Name *name, Name *otherName) ...@@ -424,7 +424,7 @@ static bool isCompatible(Name *name, Name *otherName)
static bool isCompatible(Function *definition, Symbol *declaration, QualifiedNameId *declarationName) static bool isCompatible(Function *definition, Symbol *declaration, QualifiedNameId *declarationName)
{ {
Function *declTy = declaration->type()->asFunction(); Function *declTy = declaration->type()->asFunctionType();
if (! declTy) if (! declTy)
return false; return false;
...@@ -507,7 +507,7 @@ void CPPEditor::switchDeclarationDefinition() ...@@ -507,7 +507,7 @@ void CPPEditor::switchDeclarationDefinition()
if (declaration) if (declaration)
openEditorAt(declaration); openEditorAt(declaration);
} else if (lastSymbol->type()->isFunction()) { } else if (lastSymbol->type()->isFunctionType()) {
if (Symbol *def = findDefinition(lastSymbol)) if (Symbol *def = findDefinition(lastSymbol))
openEditorAt(def); openEditorAt(def);
} }
...@@ -594,7 +594,7 @@ Symbol *CPPEditor::findDefinition(Symbol *symbol) ...@@ -594,7 +594,7 @@ Symbol *CPPEditor::findDefinition(Symbol *symbol)
if (symbol->isFunction()) if (symbol->isFunction())
return 0; // symbol is a function definition. return 0; // symbol is a function definition.
Function *funTy = symbol->type()->asFunction(); Function *funTy = symbol->type()->asFunctionType();
if (! funTy) if (! funTy)
return 0; // symbol does not have function type. return 0; // symbol does not have function type.
......
...@@ -147,13 +147,13 @@ static QString buildHelpId(const FullySpecifiedType &type, ...@@ -147,13 +147,13 @@ static QString buildHelpId(const FullySpecifiedType &type,
Name *name = 0; Name *name = 0;
Scope *scope = 0; Scope *scope = 0;
if (const Function *f = type->asFunction()) { if (const Function *f = type->asFunctionType()) {
name = f->name(); name = f->name();
scope = f->scope(); scope = f->scope();
} else if (const Class *c = type->asClass()) { } else if (const Class *c = type->asClassType()) {
name = c->name(); name = c->name();
scope = c->scope(); scope = c->scope();
} else if (const Enum *e = type->asEnum()) { } else if (const Enum *e = type->asEnumType()) {
name = e->name(); name = e->name();
scope = e->scope(); scope = e->scope();
} else if (const NamedType *t = type->asNamedType()) { } else if (const NamedType *t = type->asNamedType()) {
...@@ -270,7 +270,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -270,7 +270,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
m_helpId = buildHelpId(docType, symbol); m_helpId = buildHelpId(docType, symbol);
QString displayName = buildHelpId(firstType, symbol); QString displayName = buildHelpId(firstType, symbol);
if (!firstType->isClass() && !firstType->isNamedType()) { if (!firstType->isClassType() && !firstType->isNamedType()) {
Overview overview; Overview overview;
overview.setShowArgumentNames(true); overview.setShowArgumentNames(true);
overview.setShowReturnTypes(true); overview.setShowReturnTypes(true);
......
...@@ -512,7 +512,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) ...@@ -512,7 +512,7 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
context = typeOfExpression.lookupContext(); context = typeOfExpression.lookupContext();
} }
if (! resolvedTypes.isEmpty()) { if (! resolvedTypes.isEmpty() && resolvedTypes.first().first) {
FullySpecifiedType exprTy = resolvedTypes.first().first; FullySpecifiedType exprTy = resolvedTypes.first().first;
if (exprTy->isReferenceType()) if (exprTy->isReferenceType())
...@@ -549,9 +549,9 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor) ...@@ -549,9 +549,9 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
// If it's a class, add completions for the constructors // If it's a class, add completions for the constructors
foreach (const TypeOfExpression::Result &result, results) { foreach (const TypeOfExpression::Result &result, results) {
if (result.first->isClass()) { if (result.first->isClassType()) {
FullySpecifiedType exprTy = result.first; FullySpecifiedType exprTy = result.first;
if (completeConstructors(exprTy->asClass())) if (completeConstructors(exprTy->asClassType()))
return m_startPosition; return m_startPosition;
break; break;
} }
...@@ -567,7 +567,7 @@ bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy, ...@@ -567,7 +567,7 @@ bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy,
const QList<TypeOfExpression::Result> &resolvedTypes, const QList<TypeOfExpression::Result> &resolvedTypes,
const LookupContext &) const LookupContext &)
{ {
if (Class *klass = exprTy->asClass()) { if (Class *klass = exprTy->asClassType()) {
completeConstructors(klass); completeConstructors(klass);
} else { } else {
ConvertToCompletionItem toCompletionItem(this); ConvertToCompletionItem toCompletionItem(this);
...@@ -578,7 +578,7 @@ bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy, ...@@ -578,7 +578,7 @@ bool CppCodeCompletion::completeFunction(FullySpecifiedType exprTy,
QSet<QString> signatures; QSet<QString> signatures;
foreach (TypeOfExpression::Result p, resolvedTypes) { foreach (TypeOfExpression::Result p, resolvedTypes) {
FullySpecifiedType ty = p.first; FullySpecifiedType ty = p.first;
if (Function *fun = ty->asFunction()) { if (Function *fun = ty->asFunctionType()) {
if (TextEditor::CompletionItem item = toCompletionItem(fun)) { if (TextEditor::CompletionItem item = toCompletionItem(fun)) {
QString signature; QString signature;
signature += overview.prettyName(fun->name()); signature += overview.prettyName(fun->name());
...@@ -612,7 +612,7 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re ...@@ -612,7 +612,7 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re
if (ReferenceType *refTy = ty->asReferenceType()) if (ReferenceType *refTy = ty->asReferenceType())
ty = refTy->elementType(); ty = refTy->elementType();
if (Class *classTy = ty->asClass()) { if (Class *classTy = ty->asClassType()) {
Symbol *symbol = result.second; Symbol *symbol = result.second;
if (symbol && ! symbol->isClass()) if (symbol && ! symbol->isClass())
classObjectCandidates.append(classTy); classObjectCandidates.append(classTy);
...@@ -641,7 +641,7 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re ...@@ -641,7 +641,7 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re
foreach (TypeOfExpression::Result r, overloads) { foreach (TypeOfExpression::Result r, overloads) {
FullySpecifiedType ty = r.first; FullySpecifiedType ty = r.first;
Function *funTy = ty->asFunction(); Function *funTy = ty->asFunctionType();
if (! funTy) if (! funTy)
continue; continue;
...@@ -674,7 +674,7 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re ...@@ -674,7 +674,7 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re
if (! classObjectCandidates.contains(c)) if (! classObjectCandidates.contains(c))
classObjectCandidates.append(c); classObjectCandidates.append(c);
} }
} else if (Class *classTy = ptrTy->elementType()->asClass()) { } else if (Class *classTy = ptrTy->elementType()->asClassType()) {
// typedef struct { int x } *Ptr; // typedef struct { int x } *Ptr;
// Ptr p; // Ptr p;
// p-> // p->
...@@ -715,14 +715,14 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re ...@@ -715,14 +715,14 @@ bool CppCodeCompletion::completeMember(const QList<TypeOfExpression::Result> &re
++m_startPosition; ++m_startPosition;
namedTy = ptrTy->elementType()->asNamedType(); namedTy = ptrTy->elementType()->asNamedType();
} }
} else if (Class *classTy = ty->asClass()) { } else if (Class *classTy = ty->asClassType()) {
Symbol *symbol = result.second; Symbol *symbol = result.second;
if (symbol && ! symbol->isClass()) if (symbol && ! symbol->isClass())
classObjectCandidates.append(classTy); classObjectCandidates.append(classTy);
} else { } else {
namedTy = ty->asNamedType(); namedTy = ty->asNamedType();
if (! namedTy) { if (! namedTy) {
Function *fun = ty->asFunction(); Function *fun = ty->asFunctionType();
if (fun && (fun->scope()->isBlockScope() || fun->scope()->isNamespaceScope())) if (fun && (fun->scope()->isBlockScope() || fun->scope()->isNamespaceScope()))
namedTy = fun->returnType()->asNamedType(); namedTy = fun->returnType()->asNamedType();
} }
...@@ -759,24 +759,24 @@ bool CppCodeCompletion::completeScope(const QList<TypeOfExpression::Result> &res ...@@ -759,24 +759,24 @@ bool CppCodeCompletion::completeScope(const QList<TypeOfExpression::Result> &res
foreach (result, results) { foreach (result, results) {
FullySpecifiedType ty = result.first; FullySpecifiedType ty = result.first;
if (ty->isClass() || ty->isNamespace()) if (ty->isClassType() || ty->isNamespaceType())
break; break;
} }
FullySpecifiedType exprTy = result.first; FullySpecifiedType exprTy = result.first;
if (! exprTy) { if (! exprTy) {
return false; return false;
} else if (exprTy->asNamespace()) { } else if (exprTy->isNamespaceType()) {
QList<Symbol *> candidates; QList<Symbol *> candidates;
foreach (TypeOfExpression::Result p, results) { foreach (TypeOfExpression::Result p, results) {
if (Namespace *ns = p.first->asNamespace()) if (Namespace *ns = p.first->asNamespaceType())
candidates.append(ns); candidates.append(ns);
} }
completeNamespace(candidates, context); completeNamespace(candidates, context);
} else if (exprTy->isClass()) { } else if (exprTy->isClassType()) {
QList<Symbol *> candidates; QList<Symbol *> candidates;
foreach (TypeOfExpression::Result p, results) { foreach (TypeOfExpression::Result p, results) {
if (Class *k = p.first->asClass()) if (Class *k = p.first->asClassType())
candidates.append(k); candidates.append(k);
} }
completeClass(candidates, context); completeClass(candidates, context);
...@@ -896,7 +896,7 @@ bool CppCodeCompletion::completeConstructors(Class *klass) ...@@ -896,7 +896,7 @@ bool CppCodeCompletion::completeConstructors(Class *klass)
for (unsigned i = 0; i < klass->memberCount(); ++i) { for (unsigned i = 0; i < klass->memberCount(); ++i) {
Symbol *member = klass->memberAt(i); Symbol *member = klass->memberAt(i);
if (! member->type()->isFunction()) if (! member->type()->isFunctionType())
continue; continue;
else if (! member->identity()) else if (! member->identity())
continue; continue;
...@@ -959,7 +959,7 @@ bool CppCodeCompletion::completeQtMethod(CPlusPlus::FullySpecifiedType, ...@@ -959,7 +959,7 @@ bool CppCodeCompletion::completeQtMethod(CPlusPlus::FullySpecifiedType,
for (unsigned i = 0; i < scope->symbolCount(); ++i) { for (unsigned i = 0; i < scope->symbolCount(); ++i) {
Symbol *member = scope->symbolAt(i); Symbol *member = scope->symbolAt(i);
Function *fun = member->type()->asFunction(); Function *fun = member->type()->asFunctionType();
if (! fun) if (! fun)
continue; continue;
if (wantSignals && ! fun->isSignal()) if (wantSignals && ! fun->isSignal())
...@@ -1075,7 +1075,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) ...@@ -1075,7 +1075,7 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
if (m_completionOperator == T_LPAREN) { if (m_completionOperator == T_LPAREN) {
if (symbol) { if (symbol) {
Function *function = symbol->type()->asFunction(); Function *function = symbol->type()->asFunctionType();
QTC_ASSERT(function, return); QTC_ASSERT(function, return);
m_functionArgumentWidget = new FunctionArgumentWidget(); m_functionArgumentWidget = new FunctionArgumentWidget();
...@@ -1094,8 +1094,8 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item) ...@@ -1094,8 +1094,8 @@ void CppCodeCompletion::complete(const TextEditor::CompletionItem &item)
//qDebug() << "current symbol:" << overview.prettyName(symbol->name()) //qDebug() << "current symbol:" << overview.prettyName(symbol->name())
//<< overview.prettyType(symbol->type()); //<< overview.prettyType(symbol->type());
if (m_autoInsertBraces && symbol) { if (m_autoInsertBraces && symbol && symbol->type()) {
if (Function *function = symbol->type()->asFunction()) { if (Function *function = symbol->type()->asFunctionType()) {
// If the member is a function, automatically place the opening parenthesis, // If the member is a function, automatically place the opening parenthesis,
// except when it might take template parameters. // except when it might take template parameters.
const bool hasReturnType = function->returnType().isValid() || const bool hasReturnType = function->returnType().isValid() ||
......
...@@ -195,7 +195,7 @@ static const Function *findDeclaration(const Class *cl, const QString &functionN ...@@ -195,7 +195,7 @@ static const Function *findDeclaration(const Class *cl, const QString &functionN
const Overview overview; const Overview overview;
for (unsigned j = 0; j < mCount; j++) { // go through all members for (unsigned j = 0; j < mCount; j++) { // go through all members
if (const Declaration *decl = cl->memberAt(j)->asDeclaration()) if (const Declaration *decl = cl->memberAt(j)->asDeclaration())
if (const Function *fun = decl->type()->asFunction()) { if (const Function *fun = decl->type()->asFunctionType()) {
// Format signature // Format signature
QString memberFunction = overview.prettyName(fun->name()); QString memberFunction = overview.prettyName(fun->name());
memberFunction += QLatin1Char('('); memberFunction += QLatin1Char('(');
...@@ -233,7 +233,7 @@ static bool isCompatible(const Name *name, const Name *otherName) ...@@ -233,7 +233,7 @@ static bool isCompatible(const Name *name, const Name *otherName)
// TODO: remove me, see below // TODO: remove me, see below
static bool isCompatible(const Function *definition, const Symbol *declaration, const QualifiedNameId *declarationName) static bool isCompatible(const Function *definition, const Symbol *declaration, const QualifiedNameId *declarationName)
{ {
Function *declTy = declaration->type()->asFunction(); Function *declTy = declaration->type()->asFunctionType();
if (! declTy) if (! declTy)
return false; return false;
...@@ -385,7 +385,7 @@ static void addDeclaration(const QString &docFileName, const Class *cl, const QS ...@@ -385,7 +385,7 @@ static void addDeclaration(const QString &docFileName, const Class *cl, const QS
const unsigned mCount = cl->memberCount(); const unsigned mCount = cl->memberCount();
for (unsigned j = 0; j < mCount; j++) { // go through all members for (unsigned j = 0; j < mCount; j++) { // go through all members
if (const Declaration *decl = cl->memberAt(j)->asDeclaration()) if (const Declaration *decl = cl->memberAt(j)->asDeclaration())
if (const Function *fun = decl->type()->asFunction()) { if (const Function *fun = decl->type()->asFunctionType()) {
// we are only interested in declarations of methods. // we are only interested in declarations of methods.
// fun->column() returns always 0, what can cause trouble in case in one // fun->column() returns always 0, what can cause trouble in case in one
// line if there is: "private slots: void foo();" // line if there is: "private slots: void foo();"
......
...@@ -130,8 +130,8 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast) ...@@ -130,8 +130,8 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
FullySpecifiedType ty = semantic()->check(ast->decl_specifier_seq, _scope); FullySpecifiedType ty = semantic()->check(ast->decl_specifier_seq, _scope);
FullySpecifiedType qualTy = ty.qualifiedType(); FullySpecifiedType qualTy = ty.qualifiedType();
if (_templateParameters) { if (_templateParameters && ty) {
if (Class *klass = ty->asClass()) { if (Class *klass = ty->asClassType()) {
klass->setTemplateParameters(_templateParameters); klass->setTemplateParameters(_templateParameters);
} }
} }
...@@ -142,7 +142,8 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast) ...@@ -142,7 +142,8 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
FullySpecifiedType declTy = semantic()->check(it->declarator, qualTy, FullySpecifiedType declTy = semantic()->check(it->declarator, qualTy,
_scope, &name); _scope, &name);
if (Function *fun = declTy->asFunction()) { Function *fun = 0;
if (declTy && 0 != (fun = declTy->asFunctionType())) {
fun->setScope(_scope); fun->setScope(_scope);
fun->setName(name); fun->setName(name);
fun->setMethodKey(semantic()->currentMethodKey()); fun->setMethodKey(semantic()->currentMethodKey());
...@@ -162,7 +163,7 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast) ...@@ -162,7 +163,7 @@ bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
symbol->setType(control()->integerType(IntegerType::Int)); symbol->setType(control()->integerType(IntegerType::Int));
symbol->setType(declTy); symbol->setType(declTy);
if (_templateParameters && it == ast->declarators && ! ty->asClass()) if (_templateParameters && it == ast->declarators && ty && ! ty->isClassType())
symbol->setTemplateParameters(_templateParameters); symbol->setTemplateParameters(_templateParameters);
symbol->setVisibility(semantic()->currentVisibility()); symbol->setVisibility(semantic()->currentVisibility());
...@@ -225,13 +226,13 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast) ...@@ -225,13 +226,13 @@ bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
Name *name = 0; Name *name = 0;
FullySpecifiedType funTy = semantic()->check(ast->declarator, qualTy, FullySpecifiedType funTy = semantic()->check(ast->declarator, qualTy,
_scope, &name); _scope, &name);
Function *fun = funTy->asFunction(); if (! (funTy && funTy->isFunctionType())) {
if (! fun) {
translationUnit()->error(ast->firstToken(), translationUnit()->error(ast->firstToken(),
"expected a function prototype"); "expected a function prototype");
return false; return false;
} }
Function *fun = funTy->asFunctionType();
fun->setName(name); fun->setName(name);
fun->setTemplateParameters(_templateParameters); fun->setTemplateParameters(_templateParameters);
fun->setVisibility(semantic()->currentVisibility()); fun->setVisibility(semantic()->currentVisibility());
......
...@@ -135,9 +135,12 @@ bool CheckDeclarator::visit(DeclaratorAST *ast) ...@@ -135,9 +135,12 @@ bool CheckDeclarator::visit(DeclaratorAST *ast)
// ### check the initializer // ### check the initializer
// FullySpecifiedType exprTy = semantic()->check(ast->initializer, _scope); // FullySpecifiedType exprTy = semantic()->check(ast->initializer, _scope);
if (ast->initializer && _fullySpecifiedType->isFunction()) { if (ast->initializer && _fullySpecifiedType) {
_fullySpecifiedType->asFunction()->setPureVirtual(true); if (Function *funTy = _fullySpecifiedType->asFunctionType()) {
funTy->setPureVirtual(true);
}
} }
return false; return false;
} }
......
...@@ -319,7 +319,7 @@ bool CheckExpression::visit(QtMethodAST *ast) ...@@ -319,7 +319,7 @@ bool CheckExpression::visit(QtMethodAST *ast)
Scope dummy; Scope dummy;
FullySpecifiedType methTy = semantic()->check(ast->declarator, FullySpecifiedType(), FullySpecifiedType methTy = semantic()->check(ast->declarator, FullySpecifiedType(),
&dummy, &name); &dummy, &name);
Function *fty = methTy->asFunction(); Function *fty = methTy->asFunctionType();
if (! fty) if (! fty)
translationUnit()->warning(ast->firstToken(), "expected a function declarator"); translationUnit()->warning(ast->firstToken(), "expected a function declarator");
else { else {
......