diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2022-12-02 13:56:20 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2022-12-15 17:47:58 +0100 |
commit | c4fc1167188cde9e89d44a8e5e02c5b1e04c61a7 (patch) | |
tree | 8d2ff74980203ce361e8a18dc7eb3a7de7d733c3 /src/qml/compiler/qv4compiler.cpp | |
parent | b13e22f2745562d0549461c85cfee1bbada631ce (diff) |
QmlCompiler: Fix recognition of builtin list types
Previously all list types used as arguments or return types for methods
had to be looked up via the imports. However, builtin types are not part
of the imports at run time. Therefore, recognize list types already
early on, when generating the IR. This is the same way we do it for
property types and it allows us to easily identify lists of builtins.
Pick-to: 6.5
Fixes: QTBUG-109147
Change-Id: I91fa9c8fc99c1e0155cc5db5faddd928ca7fabbc
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compiler.cpp')
-rw-r--r-- | src/qml/compiler/qv4compiler.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/src/qml/compiler/qv4compiler.cpp b/src/qml/compiler/qv4compiler.cpp index e1e26715cd..051a87a6c7 100644 --- a/src/qml/compiler/qv4compiler.cpp +++ b/src/qml/compiler/qv4compiler.cpp @@ -221,14 +221,28 @@ int QV4::Compiler::JSUnitGenerator::registerTranslation(const QV4::CompiledData: QV4::CompiledData::Unit *QV4::Compiler::JSUnitGenerator::generateUnit(GeneratorOption option) { + const auto registerTypeStrings = [this](QQmlJS::AST::Type *type) { + if (!type) + return; + + if (type->typeArgument) { + registerString(type->typeArgument->toString()); + registerString(type->typeId->toString()); + } + registerString(type->toString()); + }; + registerString(module->fileName); registerString(module->finalUrl); for (Context *f : std::as_const(module->functions)) { registerString(f->name); - registerString(f->returnType); + registerTypeStrings(f->returnType); for (int i = 0; i < f->arguments.size(); ++i) { registerString(f->arguments.at(i).id); - registerString(f->arguments.at(i).typeName()); + if (const QQmlJS::AST::TypeAnnotation *annotation + = f->arguments.at(i).typeAnnotation.data()) { + registerTypeStrings(annotation->type); + } } for (int i = 0; i < f->locals.size(); ++i) registerString(f->locals.at(i)); @@ -414,7 +428,9 @@ void QV4::Compiler::JSUnitGenerator::writeFunction(char *f, QV4::Compiler::Conte function->formalsOffset = currentOffset; currentOffset += function->nFormals * sizeof(CompiledData::Parameter); - QmlIR::Parameter::initType(&function->returnType, this, getStringId(irFunction->returnType)); + const auto idGenerator = [this](const QString &str) { return getStringId(str); }; + + QmlIR::Parameter::initType(&function->returnType, idGenerator, irFunction->returnType); function->sizeOfLocalTemporalDeadZone = irFunction->sizeOfLocalTemporalDeadZone; function->sizeOfRegisterTemporalDeadZone = irFunction->sizeOfRegisterTemporalDeadZone; @@ -446,8 +462,10 @@ void QV4::Compiler::JSUnitGenerator::writeFunction(char *f, QV4::Compiler::Conte // write formals CompiledData::Parameter *formals = (CompiledData::Parameter *)(f + function->formalsOffset); for (int i = 0; i < irFunction->arguments.size(); ++i) { - QmlIR::Parameter::init(&formals[i], this, getStringId(irFunction->arguments.at(i).id), - getStringId(irFunction->arguments.at(i).typeName())); + auto *formal = &formals[i]; + formal->nameIndex = getStringId(irFunction->arguments.at(i).id); + if (QQmlJS::AST::TypeAnnotation *annotation = irFunction->arguments.at(i).typeAnnotation.data()) + QmlIR::Parameter::initType(&formal->type, idGenerator, annotation->type); } // write locals |