diff options
author | Sami Shalayel <sami.shalayel@qt.io> | 2022-11-10 11:38:51 +0100 |
---|---|---|
committer | Sami Shalayel <sami.shalayel@qt.io> | 2022-12-02 10:39:48 +0100 |
commit | 784367ad1722a550e83e4925da2d4809adeca750 (patch) | |
tree | d55307c1628289fab71eebf4d34583e7a07b3e7b /tools | |
parent | 591306fb07346065482f796f6caf4bf7e0d8e826 (diff) |
QQmlJSMetaParameter: Encapsulate parameter information
Previously, there were four lists that contained each one entry
for each parameter. There was one list responsible for the names, types,
type names and const-qualifiers but this was quite bothersome to use
(e.g. they not always had the same length).
This commit introduces QQmlJSMetaParameter to
encapsulate all the information required when manipulating parameters.
This reduce the 4 lists to one, making parameters easier to handle
and QQmlJSMetaMethod easier to read.
This is a purely refactoring change, no new functionality was added.
Task-number: QTBUG-107625
Change-Id: Ia41b823c9e6294ee26e828071b802cac6b4058ce
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmltc/qmltccompiler.cpp | 36 | ||||
-rw-r--r-- | tools/qmltc/qmltcvisitor.cpp | 4 |
2 files changed, 14 insertions, 26 deletions
diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp index f7d06d8e9a..a69f8619e9 100644 --- a/tools/qmltc/qmltccompiler.cpp +++ b/tools/qmltc/qmltccompiler.cpp @@ -412,23 +412,20 @@ void QmltcCompiler::compileEnum(QmltcType ¤t, const QQmlJSMetaEnum &e) u"Q_ENUM(%1)"_s.arg(e.name())); } -static QList<QmltcVariable> compileMethodParameters( - const QStringList &names, const QList<QSharedPointer<const QQmlJSScope>> &types, - const QList<QQmlJSMetaMethod::Constness> ¶meterQualifiers, bool allowUnnamed = false) +static QList<QmltcVariable> +compileMethodParameters(const QList<QQmlJSMetaParameter> ¶meterInfos, bool allowUnnamed = false) { - Q_ASSERT(names.size() == types.size()); - Q_ASSERT(parameterQualifiers.size() == types.size()); - QList<QmltcVariable> parameters; - const auto size = names.size(); + const auto size = parameterInfos.size(); parameters.reserve(size); for (qsizetype i = 0; i < size; ++i) { - Q_ASSERT(types[i]); // assume verified - QString name = names[i]; + const auto &p = parameterInfos[i]; + Q_ASSERT(p.type()); // assume verified + QString name = p.name(); Q_ASSERT(allowUnnamed || !name.isEmpty()); // assume verified if (name.isEmpty() && allowUnnamed) name = u"unnamed_" + QString::number(i); - parameters.emplaceBack(types[i]->augmentedInternalName(), name, QString()); + parameters.emplaceBack(p.type()->augmentedInternalName(), name, QString()); } return parameters; } @@ -451,14 +448,8 @@ void QmltcCompiler::compileMethod(QmltcType ¤t, const QQmlJSMetaMethod &m, const QQmlJSScope::ConstPtr &owner) { const auto returnType = figureReturnType(m); - const auto paramNames = m.parameterNames(); - const auto paramTypes = m.parameterTypes(); - const auto paramFlags = m.parameterTypeQualifiers(); - - Q_ASSERT(paramNames.size() == paramTypes.size()); // assume verified - Q_ASSERT(paramFlags.size() == paramTypes.size()); - const QList<QmltcVariable> compiledParams = - compileMethodParameters(paramNames, paramTypes, paramFlags); + + const QList<QmltcVariable> compiledParams = compileMethodParameters(m.parameters()); const auto methodType = QQmlJSMetaMethod::Type(m.methodType()); QStringList code; @@ -917,9 +908,7 @@ void QmltcCompiler::compileAlias(QmltcType ¤t, const QQmlJSMetaProperty &a setter.parameterList.emplaceBack(QQmlJSUtils::constRefify(underlyingType), aliasName + u"_", u""_s); } else { - setter.parameterList = compileMethodParameters(methods.at(0).parameterNames(), - methods.at(0).parameterTypes(), - methods.at(0).parameterTypeQualifiers(), + setter.parameterList = compileMethodParameters(methods.at(0).parameters(), /* allow unnamed = */ true); } @@ -1652,9 +1641,8 @@ void QmltcCompiler::compileScriptBinding(QmltcType ¤t, const QString slotName = newSymbol(signalName + u"_slot"); const QString signalReturnType = figureReturnType(signal); - const QList<QmltcVariable> slotParameters = compileMethodParameters( - signal.parameterNames(), signal.parameterTypes(), signal.parameterTypeQualifiers(), - /* allow unnamed = */ true); + const QList<QmltcVariable> slotParameters = + compileMethodParameters(signal.parameters(), /* allow unnamed = */ true); // SignalHander specific: QmltcMethod slotMethod {}; diff --git a/tools/qmltc/qmltcvisitor.cpp b/tools/qmltc/qmltcvisitor.cpp index c777076d0c..236ad76467 100644 --- a/tools/qmltc/qmltcvisitor.cpp +++ b/tools/qmltc/qmltcvisitor.cpp @@ -159,9 +159,9 @@ void QmltcVisitor::findCppIncludes() for (const QQmlJSMetaMethod &m : methods) { findInType(m.returnType()); - const auto parameters = m.parameterTypes(); + const auto parameters = m.parameters(); for (const auto ¶m : parameters) - findInType(param); + findInType(param.type()); } } |