diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-07-27 13:36:04 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-07-28 16:22:37 +0000 |
commit | 1ecc61b2746782b576147470d0f6f0f30e0b40d1 (patch) | |
tree | 5f62e1c844f14b60e5d1be00a4ffaa7d60c9e119 | |
parent | e7dd123c57397ab721ecd7fe0aa12725f33234ac (diff) |
Address TODOs in qmltc tool
Deal with low hanging fruits. Remove outdated TODOs.
Fix the rest. Many things are still open
Change-Id: Ia2cd0724552b1116c34d12a30a4c911ee42e15d6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit ca2a903b55dfd6cc3191f6398f118e04427e7478)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | tools/qmltc/qmltccompiler.cpp | 2 | ||||
-rw-r--r-- | tools/qmltc/qmltccompilerpieces.cpp | 2 | ||||
-rw-r--r-- | tools/qmltc/qmltccompilerpieces.h | 39 | ||||
-rw-r--r-- | tools/qmltc/qmltcoutputprimitives.h | 1 | ||||
-rw-r--r-- | tools/qmltc/qmltctyperesolver.h | 4 |
5 files changed, 18 insertions, 30 deletions
diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp index 549d4bc3cc..7da38a989a 100644 --- a/tools/qmltc/qmltccompiler.cpp +++ b/tools/qmltc/qmltccompiler.cpp @@ -269,7 +269,7 @@ void QmltcCompiler::compileType( } auto postponedQmlContextSetup = generator.generate_initCode(current, type); - auto postponedFinalizeCode = generator.generate_endInitCode(current, type); + generator.generate_endInitCode(current, type); generator.generate_beginClassCode(current, type); generator.generate_completeComponentCode(current, type); generator.generate_finalizeComponentCode(current, type); diff --git a/tools/qmltc/qmltccompilerpieces.cpp b/tools/qmltc/qmltccompilerpieces.cpp index 2671d358a9..e367adca6d 100644 --- a/tools/qmltc/qmltccompilerpieces.cpp +++ b/tools/qmltc/qmltccompilerpieces.cpp @@ -118,7 +118,7 @@ void QmltcCodeGenerator::generate_assignToProperty(QStringList *block, *block += extensionEpilogue; *block += epilogue; - } else { // TODO: we should remove this branch eventually + } else { // this property is weird, fallback to `setProperty` *block << u"{ // couldn't find property setter, so using QObject::setProperty()"_s; QString val = value; diff --git a/tools/qmltc/qmltccompilerpieces.h b/tools/qmltc/qmltccompilerpieces.h index 9afc001b55..100fe8bdad 100644 --- a/tools/qmltc/qmltccompilerpieces.h +++ b/tools/qmltc/qmltccompilerpieces.h @@ -34,8 +34,7 @@ struct QmltcCodeGenerator const QQmlJSScope::ConstPtr &type) const; inline void generate_initCodeForTopLevelComponent(QmltcType ¤t, const QQmlJSScope::ConstPtr &type); - [[nodiscard]] inline decltype(auto) - generate_endInitCode(QmltcType ¤t, const QQmlJSScope::ConstPtr &type) const; + inline void generate_endInitCode(QmltcType ¤t, const QQmlJSScope::ConstPtr &type) const; inline void generate_interfaceCallCode(QmltcMethod *function, const QQmlJSScope::ConstPtr &type, const QString &interfaceName, @@ -69,7 +68,6 @@ struct QmltcCodeGenerator const QString &returnType, const QList<QmltcVariable> ¶meters = {}); - // TODO: 3 separate versions: bindable QML, bindable C++, non-bindable C++ static void generate_createBindingOnProperty(QStringList *block, const QString &unitVarName, const QString &scope, qsizetype functionIndex, const QString &target, int propertyIndex, @@ -140,7 +138,7 @@ inline decltype(auto) QmltcCodeGenerator::generate_initCode(QmltcType ¤t, // another document. we need to fix it by using parentContext->parent() const auto realQmlScope = [](const QQmlJSScope::ConstPtr &scope) { - if (scope->isArrayScope()) // TODO: it is special for some reason + if (scope->isArrayScope()) return scope->parentScope(); return scope; }; @@ -317,9 +315,8 @@ QmltcCodeGenerator::generate_initCodeForTopLevelComponent(QmltcType ¤t, initialization. Additionally, the QML document root's endInit calls endInit methods of all the necessary QML types within the document. */ -inline decltype(auto) -QmltcCodeGenerator::generate_endInitCode(QmltcType ¤t, - const QQmlJSScope::ConstPtr &type) const +inline void QmltcCodeGenerator::generate_endInitCode(QmltcType ¤t, + const QQmlJSScope::ConstPtr &type) const { using namespace Qt::StringLiterals; @@ -361,22 +358,18 @@ QmltcCodeGenerator::generate_endInitCode(QmltcType ¤t, current.endInit.body << u"}"_s; } - // TODO: QScopeGuard here is redundant. we should call endInit of children - // directly - const auto generateFinalLines = [¤t, isDocumentRoot, this]() { - if (!isDocumentRoot) // document root does all the work here - return; - - const auto types = visitor->pureQmlTypes(); - current.endInit.body << u"// finalize children"_s; - for (qsizetype i = 1; i < types.size(); ++i) { - const auto &type = types[i]; - Q_ASSERT(!type->isComponentRootElement()); - current.endInit.body << u"creator->get<%1>(%2)->%3(creator, engine);"_s.arg( - type->internalName(), QString::number(i), current.endInit.name); - } - }; - return QScopeGuard(generateFinalLines); + if (!isDocumentRoot) // document root does all the work here + return; + + const auto types = visitor->pureQmlTypes(); + current.endInit.body << u"// finalize children"_s; + for (qsizetype i = 1; i < types.size(); ++i) { + const auto &type = types[i]; + Q_ASSERT(!type->isComponentRootElement()); + current.endInit.body << u"creator->get<%1>(%2)->%3(creator, engine);"_s.arg( + type->internalName(), QString::number(i), current.endInit.name); + } + current.endInit.body << u"// finalize self"_s; } /*! diff --git a/tools/qmltc/qmltcoutputprimitives.h b/tools/qmltc/qmltcoutputprimitives.h index 74cfa79224..dae523b0d7 100644 --- a/tools/qmltc/qmltcoutputprimitives.h +++ b/tools/qmltc/qmltcoutputprimitives.h @@ -16,7 +16,6 @@ struct QmltcOutput QString cpp; }; -// TODO: this must adhere to C++ generated code templates (once introduced) class QmltcOutputWrapper { QmltcOutput &m_code; diff --git a/tools/qmltc/qmltctyperesolver.h b/tools/qmltc/qmltctyperesolver.h index a98d215bbb..19a3ee01bc 100644 --- a/tools/qmltc/qmltctyperesolver.h +++ b/tools/qmltc/qmltctyperesolver.h @@ -23,10 +23,6 @@ public: void init(QmltcVisitor *visitor, QQmlJS::AST::Node *program); - // TODO: this shouldn't be exposed. instead, all the custom passes on - // QQmlJSScope types must happen inside Visitor - QQmlJSScope::Ptr root() const { return m_root; } - QQmlJSScope::Ptr scopeForLocation(const QV4::CompiledData::Location &location) const; // returns an import pair {url, modifiable type} for a given \a type |