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>
This commit is contained in:
Maximilian Goldstein 2022-05-18 14:39:52 +02:00
parent db17f81e4f
commit f4d9a2b1aa
4 changed files with 11 additions and 2 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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);

View File

@ -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;