aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2024-04-18 23:11:12 +0200
committerFabian Kosmale <fabian.kosmale@qt.io>2024-04-25 22:35:43 +0200
commite6e928069e203b801287a381929a9cc05382f52e (patch)
tree3ef59ed08078cb05644783fc4c17da7f651a399a
parentdc26ab6a445a66af95c0437c1f41f08ca4df8451 (diff)
compiler: Move consoleObject and mathObject into type resolver
instead of the code generator where they used to be. Then, reuse them in the type propagator, and simplify the code there. Change-Id: I1df0465b8b07d2e13da742376b94c90a1d70b7e1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp6
-rw-r--r--src/qmlcompiler/qqmljscodegenerator_p.h12
-rw-r--r--src/qmlcompiler/qqmljstypepropagator.cpp22
-rw-r--r--src/qmlcompiler/qqmljstypepropagator_p.h4
-rw-r--r--src/qmlcompiler/qqmljstyperesolver.cpp10
-rw-r--r--src/qmlcompiler/qqmljstyperesolver_p.h3
6 files changed, 28 insertions, 29 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index 65387e3681..376e7e2e60 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -1260,7 +1260,7 @@ void QQmlJSCodeGenerator::generate_GetLookupHelper(int index)
return;
}
- if (m_typeResolver->equals(m_state.accumulatorOut().scopeType(), mathObject())) {
+ if (m_typeResolver->equals(m_state.accumulatorOut().scopeType(), m_typeResolver->mathObject())) {
QString name = m_jsUnitGenerator->lookupName(index);
double value{};
@@ -2156,10 +2156,10 @@ void QQmlJSCodeGenerator::generate_CallPropertyLookup(int index, int base, int a
const QQmlJSRegisterContent baseType = registerType(base);
const QString name = m_jsUnitGenerator->lookupName(index);
- if (m_typeResolver->equals(scope, mathObject())) {
+ if (m_typeResolver->equals(scope, m_typeResolver->mathObject())) {
if (inlineMathMethod(name, argc, argv))
return;
- } else if (m_typeResolver->equals(scope, consoleObject())) {
+ } else if (m_typeResolver->equals(scope, m_typeResolver->consoleObject())) {
if (inlineConsoleMethod(name, argc, argv))
return;
} else if (m_typeResolver->equals(scope, m_typeResolver->stringType())) {
diff --git a/src/qmlcompiler/qqmljscodegenerator_p.h b/src/qmlcompiler/qqmljscodegenerator_p.h
index 33589c13a3..79f6352551 100644
--- a/src/qmlcompiler/qqmljscodegenerator_p.h
+++ b/src/qmlcompiler/qqmljscodegenerator_p.h
@@ -322,18 +322,6 @@ private:
void generate_GetLookupHelper(int index);
- QQmlJSScope::ConstPtr mathObject() const
- {
- using namespace Qt::StringLiterals;
- return m_typeResolver->jsGlobalObject()->property(u"Math"_s).type();
- }
-
- QQmlJSScope::ConstPtr consoleObject() const
- {
- using namespace Qt::StringLiterals;
- return m_typeResolver->jsGlobalObject()->property(u"console"_s).type();
- }
-
QString resolveValueTypeContentPointer(
const QQmlJSScope::ConstPtr &required, const QQmlJSRegisterContent &actual,
const QString &variable, const QString &errorMessage);
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp
index 9f90314ff9..a6fad46913 100644
--- a/src/qmlcompiler/qqmljstypepropagator.cpp
+++ b/src/qmlcompiler/qqmljstypepropagator.cpp
@@ -1093,7 +1093,7 @@ static bool isLoggingMethod(const QString &consoleMethod)
|| consoleMethod == u"warn" || consoleMethod == u"error";
}
-void QQmlJSTypePropagator::generate_CallProperty_SCMath(int base, int argc, int argv, const QQmlJSScope::ConstPtr mathObject)
+void QQmlJSTypePropagator::generate_CallProperty_SCMath(int base, int argc, int argv)
{
// If we call a method on the Math object we don't need the actual Math object. We do need
// to transfer the type information to the code generator so that it knows that this is the
@@ -1104,13 +1104,14 @@ void QQmlJSTypePropagator::generate_CallProperty_SCMath(int base, int argc, int
addReadRegister(base, m_typeResolver->globalType(m_typeResolver->voidType()));
QQmlJSRegisterContent realType = m_typeResolver->returnType(
- m_typeResolver->realType(), QQmlJSRegisterContent::MethodReturnValue, mathObject);
+ m_typeResolver->realType(), QQmlJSRegisterContent::MethodReturnValue,
+ m_typeResolver->mathObject());
for (int i = 0; i < argc; ++i)
addReadRegister(argv + i, realType);
setAccumulator(realType);
}
-void QQmlJSTypePropagator::generate_CallProperty_SCconsole(int base, int argc, int argv, const QQmlJSScope::ConstPtr consoleType)
+void QQmlJSTypePropagator::generate_CallProperty_SCconsole(int base, int argc, int argv)
{
const QQmlJSRegisterContent voidType
= m_typeResolver->globalType(m_typeResolver->voidType());
@@ -1152,7 +1153,8 @@ void QQmlJSTypePropagator::generate_CallProperty_SCconsole(int base, int argc, i
m_state.setHasSideEffects(true);
setAccumulator(m_typeResolver->returnType(
- m_typeResolver->voidType(), QQmlJSRegisterContent::MethodReturnValue, consoleType));
+ m_typeResolver->voidType(), QQmlJSRegisterContent::MethodReturnValue,
+ m_typeResolver->consoleObject()));
}
void QQmlJSTypePropagator::generate_CallProperty(int nameIndex, int base, int argc, int argv)
@@ -1161,17 +1163,13 @@ void QQmlJSTypePropagator::generate_CallProperty(int nameIndex, int base, int ar
const auto callBase = m_state.registers[base].content;
const QString propertyName = m_jsUnitGenerator->stringForIndex(nameIndex);
- const QQmlJSScope::ConstPtr mathObject
- = m_typeResolver->jsGlobalObject()->property(u"Math"_s).type();
- if (m_typeResolver->registerContains(callBase, mathObject)) {
- generate_CallProperty_SCMath(base, argc, argv, mathObject);
+ if (m_typeResolver->registerContains(callBase, m_typeResolver->mathObject())) {
+ generate_CallProperty_SCMath(base, argc, argv);
return;
}
- const QQmlJSScope::ConstPtr consoleType
- = m_typeResolver->jsGlobalObject()->property(u"console"_s).type();
- if (m_typeResolver->registerContains(callBase, consoleType) && isLoggingMethod(propertyName)) {
- generate_CallProperty_SCconsole(base, argc, argv, consoleType);
+ if (m_typeResolver->registerContains(callBase, m_typeResolver->consoleObject()) && isLoggingMethod(propertyName)) {
+ generate_CallProperty_SCconsole(base, argc, argv);
return;
}
diff --git a/src/qmlcompiler/qqmljstypepropagator_p.h b/src/qmlcompiler/qqmljstypepropagator_p.h
index f009abac9f..f9e4c236cd 100644
--- a/src/qmlcompiler/qqmljstypepropagator_p.h
+++ b/src/qmlcompiler/qqmljstypepropagator_p.h
@@ -244,8 +244,8 @@ private:
void recordCompareType(int lhs);
// helper functions to deal with special cases in generate_ methods
- void generate_CallProperty_SCMath(int base, int arcg, int argv, const QQmlJSScope::ConstPtr mathObject);
- void generate_CallProperty_SCconsole(int base, int argc, int argv, const QQmlJSScope::ConstPtr consoleType);
+ void generate_CallProperty_SCMath(int base, int arcg, int argv);
+ void generate_CallProperty_SCconsole(int base, int argc, int argv);
void generate_Construct_SCDate(int argc, int argv);
void generate_Construct_SCArray(int argc, int argv);
diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp
index f8d6bd016a..41198a716b 100644
--- a/src/qmlcompiler/qqmljstyperesolver.cpp
+++ b/src/qmlcompiler/qqmljstyperesolver.cpp
@@ -182,6 +182,16 @@ void QQmlJSTypeResolver::init(QQmlJSImportVisitor *visitor, QQmlJS::AST::Node *p
m_imports = visitor->imports();
}
+QQmlJSScope::ConstPtr QQmlJSTypeResolver::mathObject() const
+{
+ return jsGlobalObject()->property(u"Math"_s).type();
+}
+
+QQmlJSScope::ConstPtr QQmlJSTypeResolver::consoleObject() const
+{
+ return jsGlobalObject()->property(u"console"_s).type();
+}
+
QQmlJSScope::ConstPtr
QQmlJSTypeResolver::scopeForLocation(const QV4::CompiledData::Location &location) const
{
diff --git a/src/qmlcompiler/qqmljstyperesolver_p.h b/src/qmlcompiler/qqmljstyperesolver_p.h
index 70ccf09fe4..4ddc4e468a 100644
--- a/src/qmlcompiler/qqmljstyperesolver_p.h
+++ b/src/qmlcompiler/qqmljstyperesolver_p.h
@@ -77,6 +77,9 @@ public:
QQmlJSScope::ConstPtr forInIteratorPtr() const { return m_forInIteratorPtr; }
QQmlJSScope::ConstPtr forOfIteratorPtr() const { return m_forOfIteratorPtr; }
+ QQmlJSScope::ConstPtr mathObject() const;
+ QQmlJSScope::ConstPtr consoleObject() const;
+
QQmlJSScope::ConstPtr scopeForLocation(const QV4::CompiledData::Location &location) const;
bool isPrefix(const QString &name) const