diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2014-03-12 16:55:06 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-04-23 21:16:46 +0200 |
commit | a885d10a0289da85b8c966d2fa40fb10edae4fd7 (patch) | |
tree | 7c16b5abd88d436f6596d6a424126c1b1dd2aba8 /src/qml/qml | |
parent | 937fdde5d3b26291d417f856ee05ba479a6ba730 (diff) |
Extend the QML bootstrap library by the IR builders
This is among other things needed to fix the qml import scanner to detect
dependencies from .js files correctly.
The patch also fixes the use of Q_QML_EXPORT towards Q_QML_PRIVATE_EXPORT
where appropriate and corrects the wrong include path for the double conversion
code to actually be relative to the file it is included from. This worked by
accident because of other include paths present in the build.
Change-Id: I338583dad2f76300819af8ab0dae8e5724c84430
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r-- | src/qml/qml/qml.pri | 12 | ||||
-rw-r--r-- | src/qml/qml/qqmldirparser.cpp | 38 | ||||
-rw-r--r-- | src/qml/qml/qqmldirparser_p.h | 17 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 5 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport_p.h | 1 | ||||
-rw-r--r-- | src/qml/qml/qqmltypeloader.cpp | 25 |
6 files changed, 70 insertions, 28 deletions
diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri index b6250ee35d..013f757c90 100644 --- a/src/qml/qml/qml.pri +++ b/src/qml/qml/qml.pri @@ -1,4 +1,12 @@ SOURCES += \ + $$PWD/qqmldirparser.cpp \ + +HEADERS += \ + $$PWD/qqmldirparser_p.h \ + +!qmldevtools_build { + +SOURCES += \ $$PWD/qqmlopenmetaobject.cpp \ $$PWD/qqmlvmemetaobject.cpp \ $$PWD/qqmlengine.cpp \ @@ -31,7 +39,6 @@ SOURCES += \ $$PWD/qqmltypenamecache.cpp \ $$PWD/qqmlscriptstring.cpp \ $$PWD/qqmlnetworkaccessmanagerfactory.cpp \ - $$PWD/qqmldirparser.cpp \ $$PWD/qqmlextensionplugin.cpp \ $$PWD/qqmlimport.cpp \ $$PWD/qqmllist.cpp \ @@ -102,7 +109,6 @@ HEADERS += \ $$PWD/qqmlscriptstring.h \ $$PWD/qqmlguard_p.h \ $$PWD/qqmlnetworkaccessmanagerfactory.h \ - $$PWD/qqmldirparser_p.h \ $$PWD/qqmlextensioninterface.h \ $$PWD/qqmlimport_p.h \ $$PWD/qqmlextensionplugin.h \ @@ -133,3 +139,5 @@ HEADERS += \ include(ftw/ftw.pri) include(v8/v8.pri) + +} diff --git a/src/qml/qml/qqmldirparser.cpp b/src/qml/qml/qqmldirparser.cpp index c1d0132c61..a2b4b5edd0 100644 --- a/src/qml/qml/qqmldirparser.cpp +++ b/src/qml/qml/qqmldirparser.cpp @@ -41,9 +41,7 @@ #include "qqmldirparser_p.h" #include "qqmlerror.h" -#include "qqmlglobal_p.h" -#include <QtQml/qqmlfile.h> #include <QtCore/QtDebug> QT_BEGIN_NAMESPACE @@ -281,10 +279,10 @@ bool QQmlDirParser::parse(const QString &source) void QQmlDirParser::reportError(quint16 line, quint16 column, const QString &description) { - QQmlError error; - error.setLine(line); - error.setColumn(column); - error.setDescription(description); + QQmlJS::DiagnosticMessage error; + error.loc.startLine = line; + error.loc.startColumn = column; + error.message = description; _errors.append(error); } @@ -296,25 +294,41 @@ bool QQmlDirParser::hasError() const return false; } +#if defined(QT_BUILD_QMLDEVTOOLS_LIB) || defined(QT_QMLDEVTOOLS_LIB) +QList<QQmlJS::DiagnosticMessage> QQmlDirParser::errors(const QString &uri) const +{ + QList<QQmlJS::DiagnosticMessage> errors = _errors; + for (int i = 0; i < errors.size(); ++i) { + QQmlJS::DiagnosticMessage &msg = errors[i]; + msg.message.replace(QLatin1String("$$URI$$"), uri); + } + return errors; +} +#else void QQmlDirParser::setError(const QQmlError &e) { _errors.clear(); - _errors.append(e); + reportError(e.line(), e.column(), e.description()); } QList<QQmlError> QQmlDirParser::errors(const QString &uri) const { QUrl url(uri); - QList<QQmlError> errors = _errors; - for (int i = 0; i < errors.size(); ++i) { - QQmlError &e = errors[i]; - QString description = e.description(); + QList<QQmlError> errors; + for (int i = 0; i < _errors.size(); ++i) { + const QQmlJS::DiagnosticMessage &msg = _errors.at(i); + QQmlError e; + QString description = msg.message; description.replace(QLatin1String("$$URI$$"), uri); e.setDescription(description); e.setUrl(url); + e.setLine(msg.loc.startLine); + e.setColumn(msg.loc.startColumn); + errors << e; } return errors; } +#endif QString QQmlDirParser::typeNamespace() const { @@ -331,7 +345,7 @@ QList<QQmlDirParser::Plugin> QQmlDirParser::plugins() const return _plugins; } -QHash<QHashedStringRef,QQmlDirParser::Component> QQmlDirParser::components() const +QHash<QString, QQmlDirParser::Component> QQmlDirParser::components() const { return _components; } diff --git a/src/qml/qml/qqmldirparser_p.h b/src/qml/qml/qqmldirparser_p.h index e3607d1e72..bcdb366c6c 100644 --- a/src/qml/qml/qqmldirparser_p.h +++ b/src/qml/qml/qqmldirparser_p.h @@ -56,13 +56,14 @@ #include <QtCore/QUrl> #include <QtCore/QHash> #include <QtCore/QDebug> -#include <private/qhashedstring_p.h> +#include <private/qqmljsengine_p.h> +#include <private/qtqmlglobal_p.h> QT_BEGIN_NAMESPACE class QQmlError; class QQmlEngine; -class Q_AUTOTEST_EXPORT QQmlDirParser +class Q_QML_PRIVATE_EXPORT QQmlDirParser { Q_DISABLE_COPY(QQmlDirParser) @@ -73,8 +74,12 @@ public: bool parse(const QString &source); bool hasError() const; +#if defined(QT_BUILD_QMLDEVTOOLS_LIB) || defined(QT_QMLDEVTOOLS_LIB) + QList<QQmlJS::DiagnosticMessage> errors(const QString &uri) const; +#else void setError(const QQmlError &); QList<QQmlError> errors(const QString &uri) const; +#endif QString typeNamespace() const; void setTypeNamespace(const QString &s); @@ -121,7 +126,7 @@ public: int minorVersion; }; - QHash<QHashedStringRef,Component> components() const; + QHash<QString,Component> components() const; QList<Script> scripts() const; QList<Plugin> plugins() const; @@ -142,9 +147,9 @@ private: void reportError(quint16 line, quint16 column, const QString &message); private: - QList<QQmlError> _errors; + QList<QQmlJS::DiagnosticMessage> _errors; QString _typeNamespace; - QHash<QHashedStringRef,Component> _components; // multi hash + QHash<QString,Component> _components; // multi hash QList<Script> _scripts; QList<Plugin> _plugins; #ifdef QT_CREATOR @@ -152,7 +157,7 @@ private: #endif }; -typedef QHash<QHashedStringRef,QQmlDirParser::Component> QQmlDirComponents; +typedef QHash<QString,QQmlDirParser::Component> QQmlDirComponents; typedef QList<QQmlDirParser::Script> QQmlDirScripts; typedef QList<QQmlDirParser::Plugin> QQmlDirPlugins; diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 980d4ed026..c0b21a943f 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -624,12 +624,13 @@ bool QQmlImportNamespace::Import::resolveType(QQmlTypeLoader *typeLoader, } } - QQmlDirComponents::ConstIterator it = qmlDirComponents.find(type), end = qmlDirComponents.end(); + const QString typeStr = type.toString(); + QQmlDirComponents::ConstIterator it = qmlDirComponents.find(typeStr), end = qmlDirComponents.end(); if (it != end) { QString componentUrl; bool isCompositeSingleton = false; QQmlDirComponents::ConstIterator candidate = end; - for ( ; it != end && it.key() == type; ++it) { + for ( ; it != end && it.key() == typeStr; ++it) { const QQmlDirParser::Component &c = *it; // importing version -1 means import ALL versions diff --git a/src/qml/qml/qqmlimport_p.h b/src/qml/qml/qqmlimport_p.h index e0c630e9d3..3c9452963c 100644 --- a/src/qml/qml/qqmlimport_p.h +++ b/src/qml/qml/qqmlimport_p.h @@ -48,6 +48,7 @@ #include <QtCore/qstringlist.h> #include <private/qqmldirparser_p.h> #include <private/qqmlmetatype_p.h> +#include <private/qhashedstring_p.h> // // W A R N I N G diff --git a/src/qml/qml/qqmltypeloader.cpp b/src/qml/qml/qqmltypeloader.cpp index c6693c2ae8..7fc08bd114 100644 --- a/src/qml/qml/qqmltypeloader.cpp +++ b/src/qml/qml/qqmltypeloader.cpp @@ -2207,8 +2207,17 @@ void QQmlTypeData::dataReceived(const Data &data) QQmlEngine *qmlEngine = typeLoader()->engine(); m_document.reset(new QmlIR::Document(QV8Engine::getV4(qmlEngine)->debugger != 0)); QmlIR::IRBuilder compiler(QV8Engine::get(qmlEngine)->illegalNames()); - if (!compiler.generateFromQml(code, finalUrl(), finalUrlString(), m_document.data())) { - setError(compiler.errors); + if (!compiler.generateFromQml(code, finalUrlString(), finalUrlString(), m_document.data())) { + QList<QQmlError> errors; + foreach (const QQmlJS::DiagnosticMessage &msg, compiler.errors) { + QQmlError e; + e.setUrl(finalUrl()); + e.setLine(msg.loc.startLine); + e.setColumn(msg.loc.startColumn); + e.setDescription(msg.message); + errors << e; + } + setError(errors); return; } @@ -2673,11 +2682,15 @@ void QQmlScriptBlob::dataReceived(const Data &data) QV4::ExecutionEngine *v4 = QV8Engine::getV4(m_typeLoader->engine()); QmlIR::Document irUnit(v4->debugger != 0); - QQmlError metaDataError; + QQmlJS::DiagnosticMessage metaDataError; irUnit.extractScriptMetaData(source, &metaDataError); - if (metaDataError.isValid()) { - metaDataError.setUrl(finalUrl()); - setError(metaDataError); + if (!metaDataError.message.isEmpty()) { + QQmlError e; + e.setUrl(finalUrl()); + e.setLine(metaDataError.loc.startLine); + e.setColumn(metaDataError.loc.startColumn); + e.setDescription(metaDataError.message); + setError(e); return; } |