diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-12-17 15:52:17 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-12-23 09:27:03 +0000 |
commit | ceb872b603170293e95c5005d7ea8ec900511e01 (patch) | |
tree | 01430bc8e3209506423d330a3f43b89092b95431 /tools/qmltc/prototype/codegenerator.cpp | |
parent | d5fa4a6bb7a1948cedbadceda6caa2ddfcf3db01 (diff) |
Unify common logic around QQmlJSScope and friends
We have many things duplicated all over the place
Change-Id: If929a5d683153781f6db630312240bf9c24ec777
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@qt.io>
(cherry picked from commit 1d1ad6cbc79ab5eb3fad5cb604f5d4f5da8f35cd)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tools/qmltc/prototype/codegenerator.cpp')
-rw-r--r-- | tools/qmltc/prototype/codegenerator.cpp | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/tools/qmltc/prototype/codegenerator.cpp b/tools/qmltc/prototype/codegenerator.cpp index 70fddf2fe8..ffe49c77ee 100644 --- a/tools/qmltc/prototype/codegenerator.cpp +++ b/tools/qmltc/prototype/codegenerator.cpp @@ -39,6 +39,8 @@ #include <QtCore/qloggingcategory.h> +#include <private/qqmljsutils_p.h> + #include <optional> #include <utility> #include <numeric> @@ -84,7 +86,7 @@ static QString figureReturnType(const QQmlJSMetaMethod &m) if (isVoidMethod) { type = u"void"_qs; } else { - type = CodeGeneratorUtility::getInternalNameAwareOfAccessSemantics(m.returnType()); + type = m.returnType()->augmentedInternalName(); } return type; } @@ -103,9 +105,8 @@ compileMethodParameters(const QStringList &names, Q_ASSERT(allowUnnamed || !name.isEmpty()); // assume verified if (name.isEmpty() && allowUnnamed) name = u"unnamed_" + QString::number(i); - paramList.emplaceBack(QQmlJSAotVariable { - CodeGeneratorUtility::getInternalNameAwareOfAccessSemantics(types[i]), names[i], - QString() }); + paramList.emplaceBack( + QQmlJSAotVariable { types[i]->augmentedInternalName(), names[i], QString() }); } return paramList; } @@ -809,9 +810,8 @@ void CodeGenerator::compileProperty(QQmlJSAotObject ¤t, const QQmlJSMetaPr setter.returnType = u"void"_qs; setter.name = compilationData.write; // QQmlJSAotVariable - setter.parameterList.emplaceBack( - CodeGeneratorUtility::wrapInConstRefIfNotAPointer(underlyingType), name + u"_", - u""_qs); + setter.parameterList.emplaceBack(QQmlJSUtils::constRefify(underlyingType), name + u"_", + u""_qs); setter.body << variableName + u".setValue(" + name + u"_);"; setter.body << u"emit " + compilationData.notify + u"();"; current.functions.emplaceBack(setter); @@ -873,7 +873,7 @@ void CodeGenerator::compileProperty(QQmlJSAotObject ¤t, const QQmlJSMetaPr memberName + u"(QQmlListProperty<" + underlyingType + u">(this, std::addressof(" + memberName + u"_storage)))"); underlyingType = u"QQmlListProperty<" + underlyingType + u">"; - } else if (isPointer(p)) { + } else if (p.type()->isReferenceType()) { underlyingType += u'*'; } @@ -895,8 +895,7 @@ void CodeGenerator::compileProperty(QQmlJSAotObject ¤t, const QQmlJSMetaPr setter.returnType = u"void"_qs; setter.name = compilationData.write; // QQmlJSAotVariable - setter.parameterList.emplaceBack( - CodeGeneratorUtility::wrapInConstRefIfNotAPointer(underlyingType), inputName, u""_qs); + setter.parameterList.emplaceBack(QQmlJSUtils::constRefify(underlyingType), inputName, u""_qs); setter.body << memberName + u".setValue(" + inputName + u"_);"; // TODO: Qt.binding() (and old bindings?) requires signal emission setter.body << u"emit " + compilationData.notify + u"();"; @@ -1035,7 +1034,7 @@ void CodeGenerator::compileAlias(QQmlJSAotObject ¤t, const QQmlJSMetaPrope info.underlyingType = resultingProperty.type()->internalName(); if (resultingProperty.isList()) { info.underlyingType = u"QQmlListProperty<" + info.underlyingType + u">"; - } else if (isPointer(resultingProperty)) { + } else if (resultingProperty.type()->isReferenceType()) { info.underlyingType += u"*"_qs; } // reset to generic type when having alias to id: @@ -1080,9 +1079,8 @@ void CodeGenerator::compileAlias(QQmlJSAotObject ¤t, const QQmlJSMetaPrope QList<QQmlJSMetaMethod> methods = type->methods(resultingProperty.write()); if (methods.isEmpty()) { // QQmlJSAotVariable - setter.parameterList.emplaceBack( - CodeGeneratorUtility::wrapInConstRefIfNotAPointer(info.underlyingType), - aliasName + u"_", u""_qs); + setter.parameterList.emplaceBack(QQmlJSUtils::constRefify(info.underlyingType), + aliasName + u"_", u""_qs); } else { setter.parameterList = compileMethodParameters(methods.at(0).parameterNames(), methods.at(0).parameterTypes(), true); @@ -1232,7 +1230,7 @@ void CodeGenerator::compileBinding(QQmlJSAotObject ¤t, const QmlIR::Bindin } case QmlIR::Binding::Type_String: { const QString str = m_doc->stringAt(binding.stringIndex); - addPropertyLine(propertyName, p, CodeGeneratorUtility::createStringLiteral(str)); + addPropertyLine(propertyName, p, QQmlJSUtils::toLiteral(str)); break; } case QmlIR::Binding::Type_TranslationById: { // TODO: add test @@ -1323,8 +1321,9 @@ void CodeGenerator::compileBinding(QQmlJSAotObject ¤t, const QmlIR::Bindin if (!m_listReferencesCreated.contains(uniqueId)) { m_listReferencesCreated.insert(uniqueId); // TODO: figure if Unicode support is needed here - current.endInit.body << u"QQmlListReference " + refName + u"(" + objectAddr - + u", QByteArrayLiteral(\"" + propertyName + u"\"));"; + current.endInit.body << u"QQmlListReference " + refName + u"(" + objectAddr + u", " + + QQmlJSUtils::toLiteral(propertyName, u"QByteArrayLiteral") + + u");"; current.endInit.body << u"Q_ASSERT(" + refName + u".canAppend());"; } } @@ -1641,8 +1640,8 @@ void CodeGenerator::compileScriptBinding(QQmlJSAotObject ¤t, const QmlIR:: if (!QmlIR::IRBuilder::isSignalPropertyName(propertyName)) return BindingKind::JustProperty; - const auto offset = static_cast<uint>(strlen("on")); - signalName = propertyName[offset].toLower() + propertyName.mid(offset + 1); + if (auto name = QQmlJSUtils::signalName(propertyName); name.has_value()) + signalName = *name; std::optional<QQmlJSMetaMethod> possibleSignal = signalByName(signalName); if (possibleSignal) { // signal with signalName exists |