aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2022-05-18 14:39:52 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2022-05-20 20:19:39 +0200
commitf4d9a2b1aa630b2be9428afa8777b380f33ab9fc (patch)
treecf104fc684cd51cd0baca0de0ade19f17cd322ed
parentdb17f81e4f328c53a57e869d766ce531ae0873d9 (diff)
qmlcompiler: Implement function type
Implements a very limited function type we mainly use for linting purposes right now. This allows us to know when some binding or function returns another function. Limitations: - We do not distinguish between generators and regular functions - We do not record any parameter information or types - We do not record any return types - There is no code generation for actually utilizing these closures Change-Id: Ic43218d9a1a3a3966d5afbd42943192e5a61c864 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/qmlcompiler/qqmljscodegenerator.cpp2
-rw-r--r--src/qmlcompiler/qqmljstypepropagator.cpp4
-rw-r--r--src/qmlcompiler/qqmljstyperesolver.cpp5
-rw-r--r--src/qmlcompiler/qqmljstyperesolver_p.h2
4 files changed, 11 insertions, 2 deletions
diff --git a/src/qmlcompiler/qqmljscodegenerator.cpp b/src/qmlcompiler/qqmljscodegenerator.cpp
index 30fb88a60c..b04bff000f 100644
--- a/src/qmlcompiler/qqmljscodegenerator.cpp
+++ b/src/qmlcompiler/qqmljscodegenerator.cpp
@@ -493,7 +493,7 @@ void QQmlJSCodeGenerator::generate_MoveRegExp(int regExpId, int destReg)
void QQmlJSCodeGenerator::generate_LoadClosure(int value)
{
Q_UNUSED(value)
- BYTECODE_UNIMPLEMENTED();
+ reject(u"LoadClosure"_s);
}
void QQmlJSCodeGenerator::generate_LoadName(int nameIndex)
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp
index 30a4665c08..8aaa75aaa6 100644
--- a/src/qmlcompiler/qqmljstypepropagator.cpp
+++ b/src/qmlcompiler/qqmljstypepropagator.cpp
@@ -258,7 +258,9 @@ void QQmlJSTypePropagator::generate_MoveRegExp(int regExpId, int destReg)
void QQmlJSTypePropagator::generate_LoadClosure(int value)
{
Q_UNUSED(value)
- INSTR_PROLOGUE_NOT_IMPLEMENTED();
+ // TODO: Check the function at index and see whether it's a generator to return another type
+ // instead.
+ setAccumulator(m_typeResolver->globalType(m_typeResolver->functionType()));
}
void QQmlJSTypePropagator::generate_LoadName(int nameIndex)
diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp
index e80232c434..7a44489b6a 100644
--- a/src/qmlcompiler/qqmljstyperesolver.cpp
+++ b/src/qmlcompiler/qqmljstyperesolver.cpp
@@ -87,6 +87,11 @@ QQmlJSTypeResolver::QQmlJSTypeResolver(QQmlJSImporter *importer)
metaObjectType->setAccessSemantics(QQmlJSScope::AccessSemantics::Reference);
m_metaObjectType = metaObjectType;
+ QQmlJSScope::Ptr functionType = QQmlJSScope::create();
+ functionType->setInternalName(u"function"_s);
+ functionType->setAccessSemantics(QQmlJSScope::AccessSemantics::Value);
+ m_functionType = functionType;
+
m_jsGlobalObject = importer->jsGlobalObject();
auto numberMethods = m_jsGlobalObject->methods(u"Number"_s);
Q_ASSERT(numberMethods.length() == 1);
diff --git a/src/qmlcompiler/qqmljstyperesolver_p.h b/src/qmlcompiler/qqmljstyperesolver_p.h
index f45b43fc00..ec6ead2783 100644
--- a/src/qmlcompiler/qqmljstyperesolver_p.h
+++ b/src/qmlcompiler/qqmljstyperesolver_p.h
@@ -80,6 +80,7 @@ public:
QQmlJSScope::ConstPtr jsPrimitiveType() const { return m_jsPrimitiveType; }
QQmlJSScope::ConstPtr listPropertyType() const { return m_listPropertyType; }
QQmlJSScope::ConstPtr metaObjectType() const { return m_metaObjectType; }
+ QQmlJSScope::ConstPtr functionType() const { return m_functionType; }
QQmlJSScope::ConstPtr jsGlobalObject() const { return m_jsGlobalObject; }
QQmlJSScope::ConstPtr scopeForLocation(const QV4::CompiledData::Location &location) const;
@@ -208,6 +209,7 @@ protected:
QQmlJSScope::ConstPtr m_jsPrimitiveType;
QQmlJSScope::ConstPtr m_listPropertyType;
QQmlJSScope::ConstPtr m_metaObjectType;
+ QQmlJSScope::ConstPtr m_functionType;
QQmlJSScope::ConstPtr m_jsGlobalObject;
QQmlJSScopesById m_objectsById;