diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2022-04-26 10:42:16 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2022-04-28 09:43:36 +0200 |
commit | b497eaf8914ec5690692d108af4babcb9f70f2d0 (patch) | |
tree | ba5d4af423eaffaaa9e834798ca6cb4cb7cf5588 /tools/qmltc/qmltccompilerpieces.h | |
parent | f37c7888d001bc1f39edffbdd52b381c65fc0711 (diff) |
qmltc: Uniquely name internal method that provides QML document URL
To enable unity builds of the generated code we have to name our static
methods in a unique way, so make URL method use QML document url as part
of the name. This should be unique enough since we don't have two
exactly named QML files within a module
Fixes: QTBUG-102765
Pick-to: 6.3
Change-Id: I2618b19709e63149d68efc45b6726e84ba64981f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tools/qmltc/qmltccompilerpieces.h')
-rw-r--r-- | tools/qmltc/qmltccompilerpieces.h | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/tools/qmltc/qmltccompilerpieces.h b/tools/qmltc/qmltccompilerpieces.h index ca4e36d2a3..e65807437e 100644 --- a/tools/qmltc/qmltccompilerpieces.h +++ b/tools/qmltc/qmltccompilerpieces.h @@ -31,6 +31,7 @@ #include <QtCore/qscopeguard.h> #include <QtCore/qstringbuilder.h> +#include <QtCore/qfileinfo.h> #include "qmltcoutputir.h" #include "qmltcvisitor.h" @@ -49,15 +50,15 @@ QT_BEGIN_NAMESPACE struct QmltcCodeGenerator { static const QString privateEngineName; - static const QString urlMethodName; static const QString typeCountName; + QString documentUrl; QmltcVisitor *visitor = nullptr; [[nodiscard]] inline decltype(auto) generate_initCode(QmltcType ¤t, const QQmlJSScope::ConstPtr &type) const; - static inline void generate_initCodeForTopLevelComponent(QmltcType ¤t, - const QQmlJSScope::ConstPtr &type); + inline void generate_initCodeForTopLevelComponent(QmltcType ¤t, + const QQmlJSScope::ConstPtr &type); [[nodiscard]] inline decltype(auto) generate_endInitCode(QmltcType ¤t, const QQmlJSScope::ConstPtr &type) const; @@ -107,6 +108,12 @@ struct QmltcCodeGenerator static QString wrap_qOverload(const QList<QmltcVariable> ¶meters, const QString &overloaded); static QString wrap_addressof(const QString &addressed); + + QString urlMethodName() const + { + QFileInfo fi(documentUrl); + return u"q_qmltc_docUrl_" + fi.fileName().replace(u".qml"_qs, u""_qs).replace(u'.', u'_'); + } }; /*! @@ -203,7 +210,7 @@ inline decltype(auto) QmltcCodeGenerator::generate_initCode(QmltcType ¤t, << QStringLiteral( "context = %1->createInternalContext(%1->compilationUnitFromUrl(%2()), " "context, 0, true);") - .arg(privateEngineName, urlMethodName); + .arg(privateEngineName, urlMethodName()); } else { current.init.body << u"// 1. use current context as this object's context"_qs; current.init.body << u"// context = context;"_qs; @@ -281,7 +288,7 @@ QmltcCodeGenerator::generate_initCodeForTopLevelComponent(QmltcType ¤t, current.init.body << u"// QQmlComponent(engine, compilationUnit, start, parent):"_qs; current.init.body << u"auto compilationUnit = QQmlEnginePrivate::get(engine)->compilationUnitFromUrl(" - + QmltcCodeGenerator::urlMethodName + u"());"; + + QmltcCodeGenerator::urlMethodName() + u"());"; current.init.body << u"d->compilationUnit = compilationUnit;"_qs; current.init.body << u"d->start = 0;"_qs; current.init.body << u"d->url = compilationUnit->finalUrl();"_qs; @@ -339,7 +346,7 @@ QmltcCodeGenerator::generate_endInitCode(QmltcType ¤t, "QQmlEnginePrivate::get(engine)->" "compilationUnitFromUrl(%2()), thisContext);") .arg(QString::number(visitor->qmlIrObjectIndex(type)), - QmltcCodeGenerator::urlMethodName); + QmltcCodeGenerator::urlMethodName()); current.endInit.body << u"}"_qs; } |