aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compileddata.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-07-25 11:40:18 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-07-31 17:08:19 +0000
commita05d1796b88e628655afdba6063a186d3a0803bf (patch)
treef264bc7c52c1f1d62563ac3cb6444fecc537a4d7 /src/qml/compiler/qv4compileddata.cpp
parentc8f118d3a4ba53761d3dbc6e08b3454a2dae0a0a (diff)
Simplify signal handler parameter handling
Unify the two QQmlBoundSignalExpression constructors and always call updateInternalClass on the run-time function to set up the parameter name -> argument mapping. This streamlines the code, shares the error handling for unnamed parameter clashes and allows getting rid of the code to extend the formals of functions that become signal handlers in AOT generated cache files. Either onThatSignal: function(param1, param2) { ... } syntax is used and the mapping is fixed and known at AOT/compile time. Or alternatively the dynamic variant is used where the formals are determined at signal handler installation time. Saves a whopping KB of RAM on the QQC1 gallery. Change-Id: I33a9afc06474143d7893f42366cb6553a07ce937 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compileddata.cpp')
-rw-r--r--src/qml/compiler/qv4compileddata.cpp69
1 files changed, 0 insertions, 69 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index e99c1ec842..f9216b5c4a 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -485,75 +485,6 @@ Unit *CompilationUnit::createUnitData(QmlIR::Document *irDocument)
jsUnit->finalUrlIndex = stringTable.registerString(irDocument->jsModule.finalUrl);
}
- // Collect signals that have had a change in signature (from onClicked to onClicked(mouse) for example)
- // and now need fixing in the QV4::CompiledData. Also register strings at the same time, to finalize
- // the string table.
- QVector<quint32> changedSignals;
- QVector<QQmlJS::AST::FormalParameterList*> changedSignalParameters;
- for (QmlIR::Object *o: qAsConst(irDocument->objects)) {
- for (QmlIR::Binding *binding = o->firstBinding(); binding; binding = binding->next) {
- if (!(binding->flags & QV4::CompiledData::Binding::IsSignalHandlerExpression))
- continue;
-
- quint32 functionIndex = binding->value.compiledScriptIndex;
- QmlIR::CompiledFunctionOrExpression *foe = o->functionsAndExpressions->slowAt(functionIndex);
- if (!foe)
- continue;
-
- // save absolute index
- changedSignals << o->runtimeFunctionIndices.at(functionIndex);
-
- Q_ASSERT(foe->node);
- Q_ASSERT(QQmlJS::AST::cast<QQmlJS::AST::FunctionDeclaration*>(foe->node));
-
- QQmlJS::AST::FormalParameterList *parameters = QQmlJS::AST::cast<QQmlJS::AST::FunctionDeclaration*>(foe->node)->formals;
- changedSignalParameters << parameters;
-
- if (parameters) {
- const QStringList formals = parameters->formals();
- for (const QString &arg : formals)
- stringTable.registerString(arg);
- }
- }
- }
-
- QVector<quint32> signalParameterNameTable;
- quint32 signalParameterNameTableOffset = jsUnit->unitSize;
-
- // Update signal signatures
- if (!changedSignals.isEmpty()) {
- for (int i = 0; i < changedSignals.count(); ++i) {
- const uint functionIndex = changedSignals.at(i);
- // The data is now read-write due to the copy above, so the const_cast is ok.
- QV4::CompiledData::Function *function = const_cast<QV4::CompiledData::Function *>(jsUnit->functionAt(functionIndex));
- Q_ASSERT(function->nFormals == quint32(0));
-
- function->formalsOffset = signalParameterNameTableOffset - jsUnit->functionOffsetTable()[functionIndex];
-
- if (QQmlJS::AST::FormalParameterList *parameters = changedSignalParameters.at(i)) {
- const QStringList formals = parameters->formals();
- for (const QString &arg : formals)
- signalParameterNameTable.append(stringTable.getStringId(arg));
-
- function->nFormals = formals.size();
- }
- function->length = function->nFormals;
-
- signalParameterNameTableOffset += function->nFormals * sizeof(quint32);
- }
- }
-
- if (!signalParameterNameTable.isEmpty()) {
- Q_ASSERT(jsUnit != compilationUnit->data);
- const uint signalParameterTableSize = signalParameterNameTable.count() * sizeof(quint32);
- uint newSize = jsUnit->unitSize + signalParameterTableSize;
- const uint oldSize = jsUnit->unitSize;
- char *unitWithSignalParameters = (char*)realloc(jsUnit, newSize);
- memcpy(unitWithSignalParameters + oldSize, signalParameterNameTable.constData(), signalParameterTableSize);
- jsUnit = reinterpret_cast<QV4::CompiledData::Unit*>(unitWithSignalParameters);
- jsUnit->unitSize = newSize;
- }
-
return jsUnit;
}