diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-07-03 15:13:46 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-07-09 16:52:55 +0200 |
commit | 910f98031fdd834a22af0da21c9ff6ae145f61c5 (patch) | |
tree | 03062e2ec8ccca2a1bbdc2c6e69587de1eedbe76 /src/qml/compiler/qqmlirbuilder.cpp | |
parent | f2cb10ebc4946b10526fa22581913ccc04cea164 (diff) |
Add support for C++ accessible typed parameters and return types in qml functions
These can be declared using the new typescript-like syntax and using
type names that are also used for signal parameters and property types.
This merely affects their signature on the C++ side and allows the
corresponding invocation.
Change-Id: Icaed4ee0dc7aa71330f99d96e073a2a63d409bbe
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qml/compiler/qqmlirbuilder.cpp')
-rw-r--r-- | src/qml/compiler/qqmlirbuilder.cpp | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/qml/compiler/qqmlirbuilder.cpp b/src/qml/compiler/qqmlirbuilder.cpp index a94a448ec0..6dc6f191ab 100644 --- a/src/qml/compiler/qqmlirbuilder.cpp +++ b/src/qml/compiler/qqmlirbuilder.cpp @@ -66,19 +66,31 @@ using namespace QmlIR; bool Parameter::init(QV4::Compiler::JSUnitGenerator *stringGenerator, const QString ¶meterName, const QString &typeName) { - nameIndex = stringGenerator->registerString(parameterName); - type.indexIsBuiltinType = false; - type.typeNameIndexOrBuiltinType = 0; + return init(this, stringGenerator, stringGenerator->registerString(parameterName), stringGenerator->registerString(typeName)); +} + +bool Parameter::init(QV4::CompiledData::Parameter *param, const QV4::Compiler::JSUnitGenerator *stringGenerator, + int parameterNameIndex, int typeNameIndex) +{ + param->nameIndex = parameterNameIndex; + return initType(¶m->type, stringGenerator, typeNameIndex); +} + +bool Parameter::initType(QV4::CompiledData::ParameterType *paramType, const QV4::Compiler::JSUnitGenerator *stringGenerator, int typeNameIndex) +{ + paramType->indexIsBuiltinType = false; + paramType->typeNameIndexOrBuiltinType = 0; + const QString typeName = stringGenerator->stringForIndex(typeNameIndex); auto builtinType = stringToBuiltinType(typeName); if (builtinType == QV4::CompiledData::BuiltinType::InvalidBuiltin) { if (typeName.isEmpty() || !typeName.at(0).isUpper()) return false; - type.indexIsBuiltinType = false; - type.typeNameIndexOrBuiltinType = stringGenerator->registerString(typeName); - Q_ASSERT(quint32(stringGenerator->getStringId(typeName)) < (1u << 31)); + paramType->indexIsBuiltinType = false; + paramType->typeNameIndexOrBuiltinType = typeNameIndex; + Q_ASSERT(quint32(typeNameIndex) < (1u << 31)); } else { - type.indexIsBuiltinType = true; - type.typeNameIndexOrBuiltinType = static_cast<quint32>(builtinType); + paramType->indexIsBuiltinType = true; + paramType->typeNameIndexOrBuiltinType = static_cast<quint32>(builtinType); Q_ASSERT(quint32(builtinType) < (1u << 31)); } return true; @@ -909,13 +921,16 @@ bool IRBuilder::visit(QQmlJS::AST::UiSourceElement *node) f->index = index; f->nameIndex = registerString(funDecl->name.toString()); + QString returnTypeName = funDecl->typeAnnotation ? funDecl->typeAnnotation->type->toString() : QString(); + Parameter::initType(&f->returnType, jsGenerator, registerString(returnTypeName)); + const QQmlJS::AST::BoundNames formals = funDecl->formals ? funDecl->formals->formals() : QQmlJS::AST::BoundNames(); int formalsCount = formals.size(); f->formals.allocate(pool, formalsCount); int i = 0; for (const auto &arg : formals) { - f->formals[i] = registerString(arg.id); + f->formals[i].init(jsGenerator, arg.id, arg.typeName()); ++i; } |