diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmltc/qmltccompiler.cpp | 14 | ||||
-rw-r--r-- | tools/qmltc/qmltccompilerpieces.h | 5 |
2 files changed, 8 insertions, 11 deletions
diff --git a/tools/qmltc/qmltccompiler.cpp b/tools/qmltc/qmltccompiler.cpp index 7f4c6c0af4..a241cf0715 100644 --- a/tools/qmltc/qmltccompiler.cpp +++ b/tools/qmltc/qmltccompiler.cpp @@ -603,17 +603,9 @@ void QmltcCompiler::compileAlias(QmltcType ¤t, const QQmlJSMetaProperty &a Q_ASSERT(id >= 0); // since the type is found by id, it must have an id AliasResolutionFrame queryIdFrame {}; - queryIdFrame.prologue << u"auto context = QQmlData::get(%1)->outerContext;"_s.arg( - AliasResolutionFrame::inVar); - // there's a special case: when `this` type has compiled QML type as - // a base type and it is not a root, it has a non-root first - // context, so we need to step one level up - if (QQmlJSUtils::hasCompositeBase(owner) && owner != m_visitor->result()) { - Q_ASSERT(!owner->baseTypeName().isEmpty()); - queryIdFrame.prologue - << u"// `this` is special: not a root and its base type is compiled"_s; - queryIdFrame.prologue << u"context = context->parent().data();"_s; - } + Q_ASSERT(frames.top().outVar == u"this"_s); // so inVar would be "this" as well + queryIdFrame.prologue << u"auto context = %1::q_qmltc_thisContext;"_s.arg( + owner->internalName()); // doing the above allows us to lookup id object by index (fast) queryIdFrame.outVar = u"alias_objectById_" + aliasExprBits.front(); // unique enough diff --git a/tools/qmltc/qmltccompilerpieces.h b/tools/qmltc/qmltccompilerpieces.h index 545e347caf..6d4912f883 100644 --- a/tools/qmltc/qmltccompilerpieces.h +++ b/tools/qmltc/qmltccompilerpieces.h @@ -232,6 +232,11 @@ inline decltype(auto) QmltcCodeGenerator::generate_initCode(QmltcType ¤t, current.init.body << u"context->setContextObject(this);"_s; } + // context is this document's context. we must remember it in each type + current.variables.emplaceBack(u"QQmlRefPointer<QQmlContextData>"_s, u"q_qmltc_thisContext"_s, + u"nullptr"_s); + current.init.body << u"%1::q_qmltc_thisContext = context;"_s.arg(type->internalName()); + if (int id = visitor->runtimeId(type); id >= 0) { current.init.body << u"// 3. set id since it is provided"_s; QString idString = visitor->addressableScopes().id(type); |