diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-11-19 13:04:05 +0100 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-03-30 11:00:24 +0200 |
commit | eb64978d115445b2aecf280a64b4433c69913322 (patch) | |
tree | cc126f54ce8ba84bfad4b7348f78ecae593561f8 /src | |
parent | fdb45a0e2eb5d1963bd2ee9a7f6ebd49f7dfc9ca (diff) |
qmltc: Migrate to new object creation/querying mechanism
Serves two things:
a) Provides faster/more correct object creation model (long-term)
b) Eliminates (more of) prototype's code generation (short-term)
The whole object querying now works implicitly through the
std::array<QObject *> that QQmltcObjectCreationBase provides. The
creation logic is still rather recursive with regards to QML base
types processing - unfortunately, we cannot simplify this part now
as qmltc requires deeper introspection into the imported types
(this in turn requires fiddling with QQmlJSTypeReader and
QDeferredFactory<QQmlJSScope>::create())
Since we now use the new object creation pattern,
prototype/codegenerator no longer needs high-level compilation
methods. So replace prototype's code accordingly with qmltccompiler
bits. We can also de-duplicate enum and property compilation
(aliases are not touched for simplification) from prototype. Methods
and bindings have to rely on prototype and QmlIR at present, their
compilation is moved more-or-less unchanged
Task-number: QTBUG-84368
Change-Id: I584ceb8f2e3c9f3f79530b02d1c88a4f6c2d06c9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp | 2 | ||||
-rw-r--r-- | src/qml/qmltc/qqmltcobjectcreationhelper_p.h | 15 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 5 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor_p.h | 2 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsscope_p.h | 4 |
5 files changed, 10 insertions, 18 deletions
diff --git a/src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp b/src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp index 122084f1d8..0e125a1926 100644 --- a/src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp +++ b/src/qml/doc/snippets/qmltc/special/HelloWorld.qml.cpp @@ -69,7 +69,7 @@ class HelloWorld : public QObject Q_PROPERTY(QString hello WRITE setHello READ hello BINDABLE bindableHello) public: - HelloWorld(QQmlEngine * engine, QObject * parent = nullptr); + HelloWorld(QQmlEngine* engine, QObject* parent = nullptr); Q_SIGNALS: void created(); diff --git a/src/qml/qmltc/qqmltcobjectcreationhelper_p.h b/src/qml/qmltc/qqmltcobjectcreationhelper_p.h index e34bb5506a..6aa37b1e53 100644 --- a/src/qml/qmltc/qqmltcobjectcreationhelper_p.h +++ b/src/qml/qmltc/qqmltcobjectcreationhelper_p.h @@ -70,17 +70,15 @@ class QQmltcObjectCreationHelper QObject **m_data = nullptr; // QObject* array const qsizetype m_size = 0; // size of m_data array, exists for bounds checking const qsizetype m_offset = 0; // global offset into m_data array - const qsizetype m_nonRoot = 1; // addresses the "+ 1" in QQmltcObjectCreationBase::m_objects - qsizetype offset() const { return m_offset + m_nonRoot; } + qsizetype offset() const { return m_offset; } public: /*! Constructs initial "view" from basic data. Supposed to only be called once from QQmltcObjectCreationBase. */ - QQmltcObjectCreationHelper(QObject **data, qsizetype size) - : m_data(data), m_size(size), m_nonRoot(0 /* root object */) + QQmltcObjectCreationHelper(QObject **data, qsizetype size) : m_data(data), m_size(size) { Q_UNUSED(m_size); } @@ -92,7 +90,6 @@ public: QQmltcObjectCreationHelper(const QQmltcObjectCreationHelper *base, qsizetype localOffset) : m_data(base->m_data), m_size(base->m_size), m_offset(base->m_offset + localOffset) { - Q_ASSERT(m_nonRoot == 1); // sanity check - a sub-creator is for non-root object } template<typename T> @@ -113,6 +110,12 @@ public: Q_ASSERT(m_data[i + offset()] == nullptr); // prevent accidental resets m_data[i + offset()] = object; } + + template<typename T> + static constexpr uint typeCount() noexcept + { + return T::q_qmltc_typeCount(); + } }; /*! @@ -125,7 +128,7 @@ template<typename QmltcGeneratedType> class QQmltcObjectCreationBase { // Note: +1 for the document root itself - std::array<QObject *, QmltcGeneratedType::q_qmltc_typeCount + 1> m_objects = {}; + std::array<QObject *, QmltcGeneratedType::q_qmltc_typeCount() + 1> m_objects = {}; public: QQmltcObjectCreationHelper view() diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index 04f34d83a2..deb6b22331 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -112,8 +112,6 @@ QQmlJSImportVisitor::QQmlJSImportVisitor(QQmlJSImporter *importer, QQmlJSLogger } for (const auto &jsGlobVar : jsGlobVars) m_currentScope->insertJSIdentifier(jsGlobVar, globalJavaScript); - - m_runtimeIdCounters.push(0); // global (this document's) runtime id counter } QQmlJSImportVisitor::~QQmlJSImportVisitor() = default; @@ -1255,13 +1253,11 @@ bool QQmlJSImportVisitor::visit(UiInlineComponent *component) m_nextIsInlineComponent = true; m_inlineComponentName = component->name; - m_runtimeIdCounters.push(0); // add new id counter, since counters are component-local return true; } void QQmlJSImportVisitor::endVisit(UiInlineComponent *) { - m_runtimeIdCounters.pop(); m_inlineComponentName = QStringView(); Q_ASSERT(!m_nextIsInlineComponent); } @@ -1576,7 +1572,6 @@ void QQmlJSImportVisitor::handleIdDeclaration(QQmlJS::AST::UiScriptBinding *scri } if (!name.isEmpty()) m_scopesById.insert(name, m_currentScope); - m_currentScope->setRuntimeId(m_runtimeIdCounters.top()++); } bool QQmlJSImportVisitor::visit(UiScriptBinding *scriptBinding) diff --git a/src/qmlcompiler/qqmljsimportvisitor_p.h b/src/qmlcompiler/qqmljsimportvisitor_p.h index f89aa03dc5..69714ced36 100644 --- a/src/qmlcompiler/qqmljsimportvisitor_p.h +++ b/src/qmlcompiler/qqmljsimportvisitor_p.h @@ -290,8 +290,6 @@ protected: QSet<QQmlJSScope::ConstPtr> m_literalScopesToCheck; QQmlJS::SourceLocation m_pendingSignalHandler; - QStack<int> m_runtimeIdCounters; - private: void importBaseModules(); void resolveAliasesAndIds(); diff --git a/src/qmlcompiler/qqmljsscope_p.h b/src/qmlcompiler/qqmljsscope_p.h index 4e692a0d01..da670f0c71 100644 --- a/src/qmlcompiler/qqmljsscope_p.h +++ b/src/qmlcompiler/qqmljsscope_p.h @@ -430,9 +430,6 @@ public: AccessSemantics accessSemantics() const { return m_semantics; } bool isReferenceType() const { return m_semantics == QQmlJSScope::AccessSemantics::Reference; } - void setRuntimeId(int id) { m_runtimeId = id; } - int runtimeId() const { return m_runtimeId; } - bool isIdInCurrentQmlScopes(const QString &id) const; bool isIdInCurrentJSScopes(const QString &id) const; bool isIdInjectedFromSignal(const QString &id) const; @@ -617,7 +614,6 @@ private: AccessSemantics m_semantics = AccessSemantics::Reference; QQmlJS::SourceLocation m_sourceLocation; - int m_runtimeId = -1; // an index counterpart of "foobar" in `id: foobar` }; Q_DECLARE_TYPEINFO(QQmlJSScope::QmlIRCompatibilityBindingData, Q_RELOCATABLE_TYPE); |