aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-11-23 17:50:02 +0100
committerUlf Hermann <ulf.hermann@qt.io>2020-11-24 10:44:11 +0100
commitdd243ff1df384f750c96d9c6e1f073f430815b97 (patch)
tree431e72ce5381f78d7796a217b07abdc39902934b /src/qmlcompiler
parent0c6fc54b7a1928dfae8b383844cc37787dbed7f3 (diff)
QtQmlCompiler: Notify any AOT compiler about binding scope and object
The scope can be different from the object a binding is attached to. In particular, a group property or an attached property are executed in the scope of the surrounding object but are attached to the inner object. Change-Id: I3671c0ba425b791960f3205baaff91471d2e7205 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r--src/qmlcompiler/qqmljscompiler.cpp16
-rw-r--r--src/qmlcompiler/qqmljscompiler_p.h2
2 files changed, 14 insertions, 4 deletions
diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp
index d69eacaa29..0990e0c896 100644
--- a/src/qmlcompiler/qqmljscompiler.cpp
+++ b/src/qmlcompiler/qqmljscompiler.cpp
@@ -198,8 +198,9 @@ bool qCompileQmlFile(const QString &inputFileName, QQmlJSSaveFunction saveFuncti
if (aotCompiler)
aotCompiler->setDocument(&irDocument);
+ QHash<QmlIR::Object *, QmlIR::Object *> effectiveScopes;
for (QmlIR::Object *object: qAsConst(irDocument.objects)) {
- if (object->functionsAndExpressions->count == 0)
+ if (object->functionsAndExpressions->count == 0 && object->bindingCount() == 0)
continue;
QList<QmlIR::CompiledFunctionOrExpression> functionsToCompile;
for (QmlIR::CompiledFunctionOrExpression *foe = object->functionsAndExpressions->first; foe; foe = foe->next)
@@ -216,13 +217,22 @@ bool qCompileQmlFile(const QString &inputFileName, QQmlJSSaveFunction saveFuncti
if (!aotCompiler)
continue;
- aotCompiler->setScopeObject(object);
+ QmlIR::Object *scope = object;
+ for (auto it = effectiveScopes.constFind(scope), end = effectiveScopes.constEnd();
+ it != end; it = effectiveScopes.constFind(scope)) {
+ scope = *it;
+ }
+
+ aotCompiler->setScope(object, scope);
aotFunctionsByIndex[FileScopeCodeIndex] = aotCompiler->globalCode();
std::for_each(object->bindingsBegin(), object->bindingsEnd(), [&](const QmlIR::Binding &binding) {
-
switch (binding.type) {
+ case QmlIR::Binding::Type_AttachedProperty:
+ case QmlIR::Binding::Type_GroupProperty:
+ effectiveScopes.insert(irDocument.objects.at(binding.value.objectIndex), scope);
+ return;
case QmlIR::Binding::Type_Boolean:
case QmlIR::Binding::Type_Number:
case QmlIR::Binding::Type_String:
diff --git a/src/qmlcompiler/qqmljscompiler_p.h b/src/qmlcompiler/qqmljscompiler_p.h
index 9fda257bd7..262957ad57 100644
--- a/src/qmlcompiler/qqmljscompiler_p.h
+++ b/src/qmlcompiler/qqmljscompiler_p.h
@@ -75,7 +75,7 @@ public:
virtual ~QQmlJSAotCompiler() = default;
virtual void setDocument(QmlIR::Document *document) = 0;
- virtual void setScopeObject(const QmlIR::Object *object) = 0;
+ virtual void setScope(const QmlIR::Object *object, const QmlIR::Object *scope) = 0;
virtual std::variant<QQmlJSAotFunction, QQmlJS::DiagnosticMessage> compileBinding(
const QmlIR::Binding &binding) = 0;
virtual std::variant<QQmlJSAotFunction, QQmlJS::DiagnosticMessage> compileFunction(