aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-04-18 23:35:57 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2024-04-25 22:35:46 +0200
commite163a407ce70a66d3fc7b8fdcfaea92e4655d70d (patch)
treee0221d85102cdecbc6b9164a28be36c6d534e24a /src
parente6e928069e203b801287a381929a9cc05382f52e (diff)
QQmlJSTypePropagator: Move QQmlSa related code into helper functions
That keeps the main control flow more readable. Change-Id: Ia32aa5d47773a54967e3f42c91876c4d052fa7c2 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qmlcompiler/qqmljstypepropagator.cpp141
-rw-r--r--src/qmlcompiler/qqmljstypepropagator_p.h9
2 files changed, 93 insertions, 57 deletions
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp
index a6fad46913..0ff2e18684 100644
--- a/src/qmlcompiler/qqmljstypepropagator.cpp
+++ b/src/qmlcompiler/qqmljstypepropagator.cpp
@@ -73,16 +73,21 @@ QQmlJSCompilePass::BlocksAndAnnotations QQmlJSTypePropagator::run(
qmlCompiler, QQmlJS::SourceLocation()); \
return;
+void QQmlJSTypePropagator::generate_ret_SAcheck()
+{
+ if (!m_function->isProperty)
+ return;
+ QQmlSA::PassManagerPrivate::get(m_passManager)
+ ->analyzeBinding(QQmlJSScope::createQQmlSAElement(m_function->qmlScope),
+ QQmlJSScope::createQQmlSAElement(
+ m_typeResolver->containedType(m_state.accumulatorIn())),
+ QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
+ getCurrentBindingSourceLocation()));
+}
void QQmlJSTypePropagator::generate_Ret()
{
- if (m_passManager != nullptr && m_function->isProperty) {
- QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeBinding(
- QQmlJSScope::createQQmlSAElement(m_function->qmlScope),
- QQmlJSScope::createQQmlSAElement(
- m_typeResolver->containedType(m_state.accumulatorIn())),
- QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
- getCurrentBindingSourceLocation()));
- }
+ if (m_passManager != nullptr)
+ generate_ret_SAcheck();
if (m_function->isSignalHandler) {
// Signal handlers cannot return anything.
@@ -543,6 +548,17 @@ bool QQmlJSTypePropagator::isCallingProperty(QQmlJSScope::ConstPtr scope, const
return true;
}
+
+void QQmlJSTypePropagator::generate_LoadQmlContextPropertyLookup_SAcheck(const QString &name)
+{
+ QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeRead(
+ QQmlJSScope::createQQmlSAElement(m_function->qmlScope), name,
+ QQmlJSScope::createQQmlSAElement(m_function->qmlScope),
+ QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
+ getCurrentBindingSourceLocation()));
+}
+
+
void QQmlJSTypePropagator::generate_LoadQmlContextPropertyLookup(int index)
{
// LoadQmlContextPropertyLookup does not use accumulatorIn. It always refers to the scope.
@@ -585,18 +601,23 @@ void QQmlJSTypePropagator::generate_LoadQmlContextPropertyLookup(int index)
return;
}
- if (m_passManager != nullptr) {
- QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeRead(
- QQmlJSScope::createQQmlSAElement(m_function->qmlScope), name,
- QQmlJSScope::createQQmlSAElement(m_function->qmlScope),
- QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
- getCurrentBindingSourceLocation()));
- }
+ if (m_passManager != nullptr)
+ generate_LoadQmlContextPropertyLookup_SAcheck(name);
if (m_state.accumulatorOut().variant() == QQmlJSRegisterContent::ScopeAttached)
m_attachedContext = QQmlJSScope::ConstPtr();
}
+void QQmlJSTypePropagator::generate_StoreNameCommon_SAcheck(const QQmlJSRegisterContent &in, const QString &name)
+{
+ QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeWrite(
+ QQmlJSScope::createQQmlSAElement(m_function->qmlScope), name,
+ QQmlJSScope::createQQmlSAElement(m_typeResolver->containedType(in)),
+ QQmlJSScope::createQQmlSAElement(m_function->qmlScope),
+ QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
+ getCurrentBindingSourceLocation()));
+}
+
/*!
\internal
As far as type propagation is involved, StoreNameSloppy and
@@ -645,14 +666,8 @@ void QQmlJSTypePropagator::generate_StoreNameCommon(int nameIndex)
.arg(in.descriptiveName(), type.descriptiveName()));
}
- if (m_passManager != nullptr) {
- QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeWrite(
- QQmlJSScope::createQQmlSAElement(m_function->qmlScope), name,
- QQmlJSScope::createQQmlSAElement(m_typeResolver->containedType(in)),
- QQmlJSScope::createQQmlSAElement(m_function->qmlScope),
- QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
- getCurrentBindingSourceLocation()));
- }
+ if (m_passManager != nullptr)
+ generate_StoreNameCommon_SAcheck(in, name);
if (m_typeResolver->canHoldUndefined(in) && !m_typeResolver->canHoldUndefined(type)) {
@@ -783,6 +798,21 @@ void QQmlJSTypePropagator::generate_StoreElement(int base, int index)
m_state.setHasSideEffects(true);
}
+void QQmlJSTypePropagator::propagatePropertyLookup_SAcheck(const QString &propertyName)
+{
+ const bool isAttached =
+ m_state.accumulatorIn().variant() == QQmlJSRegisterContent::ObjectAttached;
+
+ QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeRead(
+ QQmlJSScope::createQQmlSAElement(
+ m_typeResolver->containedType(m_state.accumulatorIn())),
+ propertyName,
+ QQmlJSScope::createQQmlSAElement(isAttached ? m_attachedContext
+ : m_function->qmlScope),
+ QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
+ getCurrentBindingSourceLocation()));
+}
+
void QQmlJSTypePropagator::propagatePropertyLookup(const QString &propertyName, int lookupIndex)
{
setAccumulator(
@@ -915,19 +945,8 @@ void QQmlJSTypePropagator::propagatePropertyLookup(const QString &propertyName,
}
}
- if (m_passManager != nullptr) {
- const bool isAttached =
- m_state.accumulatorIn().variant() == QQmlJSRegisterContent::ObjectAttached;
-
- QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeRead(
- QQmlJSScope::createQQmlSAElement(
- m_typeResolver->containedType(m_state.accumulatorIn())),
- propertyName,
- QQmlJSScope::createQQmlSAElement(isAttached ? m_attachedContext
- : m_function->qmlScope),
- QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
- getCurrentBindingSourceLocation()));
- }
+ if (m_passManager != nullptr)
+ propagatePropertyLookup_SAcheck(propertyName);
if (m_state.accumulatorOut().variant() == QQmlJSRegisterContent::ObjectAttached)
m_attachedContext = m_typeResolver->containedType(m_state.accumulatorIn());
@@ -971,6 +990,21 @@ void QQmlJSTypePropagator::generate_GetOptionalLookup(int index, int offset)
propagatePropertyLookup(m_jsUnitGenerator->lookupName(index), index);
}
+void QQmlJSTypePropagator::generate_StoreProperty_SAcheck(const QString propertyName, const QQmlJSRegisterContent &callBase)
+{
+ const bool isAttached = callBase.variant() == QQmlJSRegisterContent::ObjectAttached;
+
+ QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeWrite(
+ QQmlJSScope::createQQmlSAElement(m_typeResolver->containedType(callBase)),
+ propertyName,
+ QQmlJSScope::createQQmlSAElement(
+ m_typeResolver->containedType(m_state.accumulatorIn())),
+ QQmlJSScope::createQQmlSAElement(isAttached ? m_attachedContext
+ : m_function->qmlScope),
+ QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
+ getCurrentBindingSourceLocation()));
+}
+
void QQmlJSTypePropagator::generate_StoreProperty(int nameIndex, int base)
{
auto callBase = m_state.registers[base].content;
@@ -1004,19 +1038,8 @@ void QQmlJSTypePropagator::generate_StoreProperty(int nameIndex, int base)
return;
}
- if (m_passManager != nullptr) {
- const bool isAttached = callBase.variant() == QQmlJSRegisterContent::ObjectAttached;
-
- QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeWrite(
- QQmlJSScope::createQQmlSAElement(m_typeResolver->containedType(callBase)),
- propertyName,
- QQmlJSScope::createQQmlSAElement(
- m_typeResolver->containedType(m_state.accumulatorIn())),
- QQmlJSScope::createQQmlSAElement(isAttached ? m_attachedContext
- : m_function->qmlScope),
- QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
- getCurrentBindingSourceLocation()));
- }
+ if (m_passManager != nullptr)
+ generate_StoreProperty_SAcheck(propertyName, callBase);
// If the input can hold undefined we must not coerce it to the property type
// as that might eliminate an undefined value. For example, undefined -> string
@@ -1157,6 +1180,16 @@ void QQmlJSTypePropagator::generate_CallProperty_SCconsole(int base, int argc, i
m_typeResolver->consoleObject()));
}
+void QQmlJSTypePropagator::generate_callProperty_SAcheck(const QString propertyName, const QQmlJSScope::ConstPtr &baseType)
+{
+ // TODO: Should there be an analyzeCall() in the future? (w. corresponding onCall in Pass)
+ QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeRead(
+ QQmlJSScope::createQQmlSAElement(baseType), propertyName,
+ QQmlJSScope::createQQmlSAElement(m_function->qmlScope),
+ QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
+ getCurrentBindingSourceLocation()));
+}
+
void QQmlJSTypePropagator::generate_CallProperty(int nameIndex, int base, int argc, int argv)
{
Q_ASSERT(m_state.registers.contains(base));
@@ -1215,14 +1248,8 @@ void QQmlJSTypePropagator::generate_CallProperty(int nameIndex, int base, int ar
checkDeprecated(baseType, propertyName, true);
- if (m_passManager != nullptr) {
- // TODO: Should there be an analyzeCall() in the future? (w. corresponding onCall in Pass)
- QQmlSA::PassManagerPrivate::get(m_passManager)->analyzeRead(
- QQmlJSScope::createQQmlSAElement(baseType), propertyName,
- QQmlJSScope::createQQmlSAElement(m_function->qmlScope),
- QQmlSA::SourceLocationPrivate::createQQmlSASourceLocation(
- getCurrentBindingSourceLocation()));
- }
+ if (m_passManager != nullptr)
+ generate_callProperty_SAcheck(propertyName, baseType);
addReadRegister(base, callBase);
diff --git a/src/qmlcompiler/qqmljstypepropagator_p.h b/src/qmlcompiler/qqmljstypepropagator_p.h
index f9e4c236cd..c9bbeb27cc 100644
--- a/src/qmlcompiler/qqmljstypepropagator_p.h
+++ b/src/qmlcompiler/qqmljstypepropagator_p.h
@@ -249,6 +249,15 @@ private:
void generate_Construct_SCDate(int argc, int argv);
void generate_Construct_SCArray(int argc, int argv);
+ // helper functions to perform QQmlSA checks
+ void generate_ret_SAcheck();
+ void generate_LoadQmlContextPropertyLookup_SAcheck(const QString &name);
+ void generate_StoreNameCommon_SAcheck(const QQmlJSRegisterContent &in, const QString &name);
+ void propagatePropertyLookup_SAcheck(const QString &propertyName);
+ void generate_StoreProperty_SAcheck(const QString propertyName, const QQmlJSRegisterContent &callBase);
+ void generate_callProperty_SAcheck(const QString propertyName, const QQmlJSScope::ConstPtr &baseType);
+
+
QQmlJSRegisterContent m_returnType;
QQmlSA::PassManager *m_passManager = nullptr;
QQmlJSScope::ConstPtr m_attachedContext;