aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-09-24 17:36:53 +0200
committerShawn Rutledge <shawn.rutledge@digia.com>2014-10-01 14:40:46 +0200
commit564c1038d1645d76004ad93651aa392d71d45490 (patch)
tree6724a918810f91dda0c4f5f5a8de11d655de950f /src/qml/qml
parent64e2fa80015fb7d9e53cc66357870d4ea11f3590 (diff)
qmldir parser: add support for "depends component version" syntax
Dependency declarations are initially for the benefit of qmlimportscanner which does not (yet) use this parser. This patch adds support for dependencies into the qmldir parser for completeness, along with autotests. It is necessary to prevent errors at runtime when parsing a qmldir which contains the "depends" declaration. Task-number: QTBUG-41489 Change-Id: Ief2524a30140c42874f94f1735755b171e15dcf7 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/qml/qml')
-rw-r--r--src/qml/qml/qqmldirparser.cpp27
-rw-r--r--src/qml/qml/qqmldirparser_p.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/src/qml/qml/qqmldirparser.cpp b/src/qml/qml/qqmldirparser.cpp
index 7068818f15..83e1c9c757 100644
--- a/src/qml/qml/qqmldirparser.cpp
+++ b/src/qml/qml/qqmldirparser.cpp
@@ -231,6 +231,28 @@ bool QQmlDirParser::parse(const QString &source)
reportError(lineNumber, 0, QString::fromLatin1("designersupported does not expect any argument"));
else
_designerSupported = true;
+ } else if (sections[0] == QLatin1String("depends")) {
+ if (sectionCount != 3) {
+ reportError(lineNumber, 0,
+ QString::fromLatin1("depends requires 2 arguments, but %1 were provided").arg(sectionCount - 1));
+ continue;
+ }
+
+ const QString &version = sections[2];
+ const int dotIndex = version.indexOf(QLatin1Char('.'));
+ bool validVersionNumber = false;
+ const int majorVersion = parseInt(QStringRef(&version, 0, dotIndex), &validVersionNumber);
+ if (validVersionNumber) {
+ const int minorVersion = parseInt(QStringRef(&version, dotIndex+1, version.length()-dotIndex-1), &validVersionNumber);
+
+ if (validVersionNumber) {
+ Component entry(sections[1], QString(), majorVersion, minorVersion);
+ entry.internal = true;
+ _dependencies.insert(entry.typeName, entry);
+ }
+ } else {
+ reportError(lineNumber, 0, QString(QLatin1String("invalid version %1")).arg(version));
+ }
} else if (sectionCount == 2) {
// No version specified (should only be used for relative qmldir files)
const Component entry(sections[0], sections[1], -1, -1);
@@ -348,6 +370,11 @@ QHash<QString, QQmlDirParser::Component> QQmlDirParser::components() const
return _components;
}
+QHash<QString, QQmlDirParser::Component> QQmlDirParser::dependencies() const
+{
+ return _dependencies;
+}
+
QList<QQmlDirParser::Script> QQmlDirParser::scripts() const
{
return _scripts;
diff --git a/src/qml/qml/qqmldirparser_p.h b/src/qml/qml/qqmldirparser_p.h
index 54843a13b0..bbe61dfb96 100644
--- a/src/qml/qml/qqmldirparser_p.h
+++ b/src/qml/qml/qqmldirparser_p.h
@@ -119,6 +119,7 @@ public:
};
QHash<QString,Component> components() const;
+ QHash<QString,Component> dependencies() const;
QList<Script> scripts() const;
QList<Plugin> plugins() const;
bool designerSupported() const;
@@ -137,12 +138,14 @@ public:
#endif
private:
+ bool maybeAddComponent(const QString &typeName, const QString &fileName, const QString &version, QHash<QString,Component> &hash, int lineNumber = -1, bool multi = true);
void reportError(quint16 line, quint16 column, const QString &message);
private:
QList<QQmlJS::DiagnosticMessage> _errors;
QString _typeNamespace;
QHash<QString,Component> _components; // multi hash
+ QHash<QString,Component> _dependencies;
QList<Script> _scripts;
QList<Plugin> _plugins;
bool _designerSupported;