diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-09-06 14:14:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-08 09:00:31 +0200 |
commit | 8ac5506f2a6a8f1f6f50d3175a28e3e695f65a81 (patch) | |
tree | 00582e04f79809a5e8b07f989c0df995af6b6805 /src/qml | |
parent | 2ed0cd0602093d316bfbce6b1f3f8f8bfe026fca (diff) |
Fix error reporting for wrong signal parameter declarations
Record the line/column in the signal and report it together with the url
if there was an error in declaring the signals.
Change-Id: Idbbee9be271b0ca55709ffc1791637595d7ebd89
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 6 | ||||
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator_p.h | 1 | ||||
-rw-r--r-- | src/qml/compiler/qv4compileddata_p.h | 13 | ||||
-rw-r--r-- | src/qml/qml/qqmlcomponent.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator.cpp | 30 | ||||
-rw-r--r-- | src/qml/qml/qqmlobjectcreator_p.h | 10 | ||||
-rw-r--r-- | src/qml/qml/qqmlpropertycache_p.h | 4 |
7 files changed, 48 insertions, 18 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index c2ad55dda3..e3c5660f47 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -340,6 +340,11 @@ bool QQmlCodeGenerator::visit(AST::UiPublicMember *node) if (node->type == AST::UiPublicMember::Signal) { Signal *signal = New<Signal>(); signal->nameIndex = registerString(node->name.toString()); + + AST::SourceLocation loc = node->firstSourceLocation(); + signal->location.line = loc.startLine; + signal->location.column = loc.startColumn; + signal->parameters = New<PoolList<SignalParameter> >(); AST::UiParameterList *p = node->parameters; @@ -721,6 +726,7 @@ QV4::CompiledData::QmlUnit *QmlUnitGenerator::generate(ParsedQML &output) QV4::CompiledData::Signal *signalToWrite = reinterpret_cast<QV4::CompiledData::Signal*>(signalPtr); signalToWrite->nameIndex = s->nameIndex; + signalToWrite->location = s->location; signalToWrite->nParameters = s->parameters->count; QV4::CompiledData::Parameter *parameterToWrite = reinterpret_cast<QV4::CompiledData::Parameter*>(signalPtr + sizeof(*signalToWrite)); diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 35a40f5bc4..850bec95a0 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -111,6 +111,7 @@ struct SignalParameter : public QV4::CompiledData::Parameter struct Signal { int nameIndex; + QV4::CompiledData::Location location; PoolList<SignalParameter> *parameters; Signal *next; }; diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 50ed39f0d8..3224adad54 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -223,6 +223,12 @@ struct Function // Qml data structures +struct Location +{ + int line; + int column; +}; + struct Value { enum ValueType { @@ -262,6 +268,7 @@ struct Signal { quint32 nameIndex; quint32 nParameters; + Location location; // Parameter parameters[1]; const Parameter *parameterAt(int idx) const { @@ -344,12 +351,6 @@ struct Object } }; -struct Location -{ - int line; - int column; -}; - struct Import { enum ImportType { diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index ff961c7822..a70b9064d9 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -895,7 +895,7 @@ QQmlComponentPrivate::beginCreate(QQmlContextData *context) enginePriv->referenceScarceResources(); QObject *rv = 0; if (enginePriv->useNewCompiler) { - state.creator = new QtQml::QmlObjectCreator(engine, context, cc); + state.creator = new QtQml::QmlObjectCreator(engine, url, context, cc); rv = state.creator->create(); if (!rv) state.errors = state.creator->errors; diff --git a/src/qml/qml/qqmlobjectcreator.cpp b/src/qml/qml/qqmlobjectcreator.cpp index 724f97ef12..4f84cea151 100644 --- a/src/qml/qml/qqmlobjectcreator.cpp +++ b/src/qml/qml/qqmlobjectcreator.cpp @@ -63,8 +63,9 @@ static void removeBindingOnProperty(QObject *o, int index) if (binding) binding->destroy(); } -QmlObjectCreator::QmlObjectCreator(QQmlEngine *engine, QQmlContextData *contextData, QQmlCompiledData *runtimeData) +QmlObjectCreator::QmlObjectCreator(QQmlEngine *engine, const QUrl &url, QQmlContextData *contextData, QQmlCompiledData *runtimeData) : engine(engine) + , url(url) , unit(runtimeData->qmlUnit) , jsUnit(runtimeData->compilationUnit) , context(contextData) @@ -263,8 +264,11 @@ bool QmlObjectCreator::needsCustomMetaObject(const QV4::CompiledData::Object *ob return obj->nProperties > 0 || obj->nSignals > 0 || obj->nFunctions > 0; } -// ### -#define COMPILE_EXCEPTION(token, desc) {} +#define COMPILE_EXCEPTION(token, desc) \ + { \ + recordError((token)->location, desc); \ + return false; \ + } static QAtomicInt classIndexCounter(0); @@ -423,9 +427,10 @@ bool QmlObjectCreator::createVMEMetaObjectAndPropertyCache(const QV4::CompiledDa } else { // lazily resolved type Q_ASSERT(param->type == QV4::CompiledData::Property::Custom); + const QString customTypeName = stringAt(param->customTypeNameIndex); QQmlType *qmltype = 0; - if (!imports.resolveType(stringAt(param->customTypeNameIndex), &qmltype, 0, 0, 0)) - COMPILE_EXCEPTION(s, tr("Invalid signal parameter type: %1").arg(s->parameterTypeNames.at(i).toString())); + if (!imports.resolveType(customTypeName, &qmltype, 0, 0, 0)) + COMPILE_EXCEPTION(s, tr("Invalid signal parameter type: %1").arg(customTypeName)); if (qmltype->isComposite()) { QQmlTypeData *tdata = QQmlEnginePrivate::get(engine)->typeLoader.getType(qmltype->sourceUrl()); @@ -520,8 +525,9 @@ bool QmlObjectCreator::createVMEMetaObjectAndPropertyCache(const QV4::CompiledDa p->type == QV4::CompiledData::Property::Custom); QQmlType *qmltype = 0; - if (!imports.resolveType(stringAt(p->customTypeNameIndex), &qmltype, 0, 0, 0)) - COMPILE_EXCEPTION(p, tr("Invalid property type")); + if (!imports.resolveType(stringAt(p->customTypeNameIndex), &qmltype, 0, 0, 0)) { + // COMPILE_EXCEPTION(p, tr("Invalid property type")); + } Q_ASSERT(qmltype); if (qmltype->isComposite()) { @@ -690,3 +696,13 @@ bool QmlObjectCreator::valueAsBoolean(const QV4::CompiledData::Value *value) return false; } +void QmlObjectCreator::recordError(const QV4::CompiledData::Location &location, const QString &description) +{ + QQmlError error; + error.setUrl(url); + error.setLine(location.line); + error.setColumn(location.column); + error.setDescription(description); + errors << error; +} + diff --git a/src/qml/qml/qqmlobjectcreator_p.h b/src/qml/qml/qqmlobjectcreator_p.h index 553be6f075..e62efc3439 100644 --- a/src/qml/qml/qqmlobjectcreator_p.h +++ b/src/qml/qml/qqmlobjectcreator_p.h @@ -51,9 +51,12 @@ class QQmlAbstractBinding; namespace QtQml { -struct Q_QML_EXPORT QmlObjectCreator +class Q_QML_EXPORT QmlObjectCreator { - QmlObjectCreator(QQmlEngine *engine, + Q_DECLARE_TR_FUNCTIONS(QQmlCompiler) +public: + + QmlObjectCreator(QQmlEngine *engine, const QUrl &url, // extra data/output stored in these two QQmlContextData *contextData, QQmlCompiledData *runtimeData); @@ -80,7 +83,10 @@ private: static double valueAsNumber(const QV4::CompiledData::Value *value); static bool valueAsBoolean(const QV4::CompiledData::Value *value); + void recordError(const QV4::CompiledData::Location &location, const QString &description); + QQmlEngine *engine; + QUrl url; const QV4::CompiledData::QmlUnit *unit; const QV4::CompiledData::CompilationUnit *jsUnit; QQmlContextData *context; diff --git a/src/qml/qml/qqmlpropertycache_p.h b/src/qml/qml/qqmlpropertycache_p.h index 0fd9252754..fe509843ab 100644 --- a/src/qml/qml/qqmlpropertycache_p.h +++ b/src/qml/qml/qqmlpropertycache_p.h @@ -67,7 +67,7 @@ QT_BEGIN_NAMESPACE namespace QtQml { -struct QmlObjectCreator; +class QmlObjectCreator; } class QV8Engine; @@ -343,7 +343,7 @@ protected: private: friend class QQmlEnginePrivate; friend class QQmlCompiler; - friend struct QtQml::QmlObjectCreator; + friend class QtQml::QmlObjectCreator; inline QQmlPropertyCache *copy(int reserve); |