diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-17 13:41:36 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-11-20 10:36:06 +0100 |
commit | 744b277733a03e0fb5a0c25640be0f73cf3eb6c9 (patch) | |
tree | e4faf101e397dca324349223b330f92f708b673f /src/qmlcompiler | |
parent | fe2d3a839775f64f7aad8610ea241c8760be4646 (diff) |
V4: Allow passing arguments to AOT-compiled functions
Change-Id: I2340f4413ae9a44c71000e840a79e904b6a0fec9
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmlcompiler')
-rw-r--r-- | src/qmlcompiler/qqmljscompiler.cpp | 35 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljscompiler_p.h | 1 |
2 files changed, 23 insertions, 13 deletions
diff --git a/src/qmlcompiler/qqmljscompiler.cpp b/src/qmlcompiler/qqmljscompiler.cpp index 7d780b21a1..d69eacaa29 100644 --- a/src/qmlcompiler/qqmljscompiler.cpp +++ b/src/qmlcompiler/qqmljscompiler.cpp @@ -451,25 +451,24 @@ bool qSaveQmlJSUnitAsCpp(const QString &inputFileName, const QString &outputFile writeStr(aotFunctions[FileScopeCodeIndex].code.toUtf8().constData()); if (aotFunctions.size() <= 1) { // FileScopeCodeIndex is always there, but it may be the only one. - writeStr("extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[] = { { 0, QMetaType::fromType<void>(), nullptr } };"); + writeStr("extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[] = { { 0, QMetaType::fromType<void>(), {}, nullptr } };"); } else { writeStr(R"(template <typename Binding> - void wrapCall(QQmlContext *context, QObject *scopeObject, void *dataPtr, Binding &&binding) { - using return_type = std::invoke_result_t<Binding, QQmlContext*, QObject*>; + void wrapCall(QQmlContext *context, QObject *scopeObject, void *dataPtr, const void **argumentsPtr, Binding &&binding) { + using return_type = std::invoke_result_t<Binding, QQmlContext*, QObject*, const void **>; if constexpr (std::is_same_v<return_type, void>) { - Q_UNUSED(dataPtr); - binding(context, scopeObject); + Q_UNUSED(dataPtr); + binding(context, scopeObject, argumentsPtr); } else { - auto result = binding(context, scopeObject); - *reinterpret_cast<return_type *>(dataPtr) = std::move(result); + new (dataPtr) return_type(binding(context, scopeObject, argumentsPtr)); } } )"); writeStr("extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[] = {"); - QString header = QStringLiteral("[](QQmlContext *context, QObject *scopeObject, void *dataPtr) {\n"); - header += QStringLiteral("wrapCall(context, scopeObject, dataPtr, [](QQmlContext *context, QObject *scopeObject) {"); - header += QStringLiteral("Q_UNUSED(context); Q_UNUSED(scopeObject);\n"); + QString header = QStringLiteral("[](QQmlContext *context, QObject *scopeObject, void *dataPtr, const void **argumentsPtr) {\n"); + header += QStringLiteral("wrapCall(context, scopeObject, dataPtr, argumentsPtr, [](QQmlContext *context, QObject *scopeObject, const void **argumentsPtr) {"); + header += QStringLiteral("Q_UNUSED(context); Q_UNUSED(scopeObject); Q_UNUSED(argumentsPtr);\n"); QString footer = QStringLiteral("});}\n"); @@ -482,13 +481,23 @@ bool qSaveQmlJSUnitAsCpp(const QString &inputFileName, const QString &outputFile QString function = header + func.value().code + footer; - writeStr(QStringLiteral("{ %1, QMetaType::fromType<%2>(), %3 },") - .arg(func.key()).arg(func.value().returnType).arg(function) + QString argumentTypes = func.value().argumentTypes.join( + QStringLiteral(">(), QMetaType::fromType<")); + if (!argumentTypes.isEmpty()) { + argumentTypes = QStringLiteral("QMetaType::fromType<") + + argumentTypes + QStringLiteral(">()"); + } + + writeStr(QStringLiteral("{ %1, QMetaType::fromType<%2>(), { %3 }, %4 },") + .arg(func.key()) + .arg(func.value().returnType) + .arg(argumentTypes) + .arg(function) .toUtf8().constData()); } // Conclude the list with a nullptr - writeStr("{ 0, QMetaType::fromType<void>(), nullptr }"); + writeStr("{ 0, QMetaType::fromType<void>(), {}, nullptr }"); writeStr("};\n"); } diff --git a/src/qmlcompiler/qqmljscompiler_p.h b/src/qmlcompiler/qqmljscompiler_p.h index 1bfb1369c1..9fda257bd7 100644 --- a/src/qmlcompiler/qqmljscompiler_p.h +++ b/src/qmlcompiler/qqmljscompiler_p.h @@ -64,6 +64,7 @@ struct QQmlJSCompileError struct QQmlJSAotFunction { QStringList includes; + QStringList argumentTypes; QString code; QString returnType; }; |