diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-26 11:26:55 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-26 20:01:51 +0100 |
commit | 81629021ebc8789974c2f3c142b46eef799c1a95 (patch) | |
tree | 923d5f3ca1776265ce0bae8466e4da8a2de9c0f5 | |
parent | f16f477eba8415f9edfd5d4b220ab8a565051410 (diff) |
QML: Introduce "pragma Strict"
This doesn't carry any meaning, yet, but it can be used by any tools to
apply stricter rules to a particular piece of QML.
Change-Id: I0bf8f22001c19c7cc2989abedc747d3d5b1bdee1
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/qml/common/qv4compileddata_p.h | 3 | ||||
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 11 | ||||
-rw-r--r-- | src/qml/compiler/qqmlirbuilder_p.h | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlirloader.cpp | 12 |
4 files changed, 21 insertions, 8 deletions
diff --git a/src/qml/common/qv4compileddata_p.h b/src/qml/common/qv4compileddata_p.h index 4f2c49fbdc..76ed48913a 100644 --- a/src/qml/common/qv4compileddata_p.h +++ b/src/qml/common/qv4compileddata_p.h @@ -964,7 +964,8 @@ struct Unit IsSingleton = 0x4, IsSharedLibrary = 0x8, // .pragma shared? IsESModule = 0x10, - PendingTypeCompilation = 0x20 // the QML data structures present are incomplete and require type compilation + PendingTypeCompilation = 0x20, // the QML data structures present are incomplete and require type compilation + IsStrict = 0x40 }; quint32_le flags; quint32_le stringTableSize; diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index fa25d41113..b6bc48c833 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -787,9 +787,10 @@ bool IRBuilder::visit(QQmlJS::AST::UiPragma *node) // For now the only valid pragma is Singleton, so lets validate the input if (!node->name.isNull()) { - if (QLatin1String("Singleton") == node->name) - { + if (node->name == QStringLiteral("Singleton")) { pragma->type = Pragma::PragmaSingleton; + } else if (node->name == QStringLiteral("Strict")) { + pragma->type = Pragma::PragmaStrict; } else { recordError(node->pragmaToken, QCoreApplication::translate("QQmlParser","Pragma requires a valid qualifier")); return false; @@ -1603,9 +1604,13 @@ void QmlUnitGenerator::generate(Document &output, const QV4::CompiledData::Depen // enable flag if we encountered pragma Singleton for (Pragma *p : qAsConst(output.pragmas)) { - if (p->type == Pragma::PragmaSingleton) { + switch (p->type) { + case Pragma::PragmaSingleton: createdUnit->flags |= QV4::CompiledData::Unit::IsSingleton; break; + case Pragma::PragmaStrict: + createdUnit->flags |= QV4::CompiledData::Unit::IsStrict; + break; } } diff --git a/src/qml/compiler/qqmlirbuilder_p.h b/src/qml/compiler/qqmlirbuilder_p.h index 058f9802ae..e755694335 100644 --- a/src/qml/compiler/qqmlirbuilder_p.h +++ b/src/qml/compiler/qqmlirbuilder_p.h @@ -410,7 +410,8 @@ private: struct Q_QMLCOMPILER_PRIVATE_EXPORT Pragma { enum PragmaType { - PragmaSingleton = 0x1 + PragmaSingleton = 0x1, + PragmaStrict = 0x2 }; quint32 type; diff --git a/src/qml/qml/qqmlirloader.cpp b/src/qml/qml/qqmlirloader.cpp index 121ac25ced..5a010e6263 100644 --- a/src/qml/qml/qqmlirloader.cpp +++ b/src/qml/qml/qqmlirloader.cpp @@ -58,12 +58,18 @@ void QQmlIRLoader::load() for (quint32 i = 0; i < qmlUnit->nImports; ++i) output->imports << qmlUnit->importAt(i); - if (unit->flags & QV4::CompiledData::Unit::IsSingleton) { + const auto createPragma = [&](QmlIR::Pragma::PragmaType type) { QmlIR::Pragma *p = New<QmlIR::Pragma>(); p->location = QV4::CompiledData::Location(); - p->type = QmlIR::Pragma::PragmaSingleton; + p->type = type; output->pragmas << p; - } + }; + + if (unit->flags & QV4::CompiledData::Unit::IsSingleton) + createPragma(QmlIR::Pragma::PragmaSingleton); + if (unit->flags & QV4::CompiledData::Unit::IsStrict) + createPragma(QmlIR::Pragma::PragmaStrict); + for (uint i = 0; i < qmlUnit->nObjects; ++i) { const QV4::CompiledData::Object *serializedObject = qmlUnit->objectAt(i); |