Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QQmltc::CodeGenerator Struct Reference

#include <qqmltccompilerpieces_p.h>

Collaboration diagram for QQmltc::CodeGenerator:

Classes

struct  TranslationBindingInfo
struct  PreparedValue

Public Types

using InlineComponentOrDocumentRootName = QQmlJSScope::InlineComponentOrDocumentRootName
using RootDocumentNameType = QQmlJSScope::RootDocumentNameType

Public Member Functions

decltype(auto) generate_initCode (Type &current, const QQmlJSScope::ConstPtr &type) const
void generate_initCodeForTopLevelComponent (Type &current, const QQmlJSScope::ConstPtr &type)
void generate_qmltcInstructionCallCode (Method *function, const QQmlJSScope::ConstPtr &type, const QString &baseInstructionArgs, const QString &childInstructionArgs) const
void generate_endInitCode (Type &current, const QQmlJSScope::ConstPtr &type) const
void generate_setComplexBindingsCode (Type &current, const QQmlJSScope::ConstPtr &type) const
void generate_interfaceCallCode (Method *function, const QQmlJSScope::ConstPtr &type, const QString &interfaceName, const QString &interfaceCall) const
void generate_beginClassCode (Type &current, const QQmlJSScope::ConstPtr &type) const
void generate_completeComponentCode (Type &current, const QQmlJSScope::ConstPtr &type) const
void generate_finalizeComponentCode (Type &current, const QQmlJSScope::ConstPtr &type) const
void generate_handleOnCompletedCode (Type &current, const QQmlJSScope::ConstPtr &type) const
QString generate_typeCount (const InlineComponentOrDocumentRootName &inlinedComponent) const
template<typename Predicate>
QString generate_typeCount (Predicate p, const InlineComponentOrDocumentRootName &inlinedComponent) const
QString urlMethodName () const

Static Public Member Functions

static void generate_assignToProperty (QStringList *block, const QQmlJSScope::ConstPtr &type, const QQmlJSMetaProperty &p, const QString &value, const QString &accessor, bool constructFromQObject=false)
static void generate_assignToListProperty (QStringList *block, const QQmlJSScope::ConstPtr &type, const QQmlJSMetaProperty &p, const QStringList &value, const QString &accessor, QString &qmlListVarName)
static void generate_setIdValue (QStringList *block, const QString &context, qsizetype index, const QString &accessor, const QString &idString)
static void generate_callExecuteRuntimeFunction (QStringList *block, const QString &url, QQmlJSMetaMethod::AbsoluteFunctionIndex index, const QString &accessor, const QString &returnType, const QList< Variable > &parameters={})
static void generate_createBindingOnProperty (QStringList *block, const QString &unitVarName, const QString &scope, qsizetype functionIndex, const QString &target, const QQmlJSScope::ConstPtr &targetType, int propertyIndex, const QQmlJSMetaProperty &p, int valueTypeIndex, const QString &subTarget)
static void generate_createTranslationBindingOnProperty (QStringList *block, const TranslationBindingInfo &info)
static void generate_getCompilationUnitFromUrl ()
static PreparedValue wrap_mismatchingTypeConversion (const QQmlJSMetaProperty &p, QString value)
static PreparedValue wrap_extensionType (const QQmlJSScope::ConstPtr &type, const QQmlJSMetaProperty &p, const QString &accessor)
static QString wrap_privateClass (const QString &accessor, const QQmlJSMetaProperty &p)
static QString wrap_addressof (const QString &addressed)

Public Attributes

QString documentUrl
Visitorvisitor = nullptr

Static Public Attributes

static const QString privateEngineName = u"ePriv"_s
static const QString typeCountName = u"q_qmltc_typeCount"_s

Detailed Description

Helper class that generates code for the output IR. Takes care of complicated, repetitive, nasty logic which is better kept in a single confined place.

Definition at line 41 of file qqmltccompilerpieces_p.h.

Member Typedef Documentation

◆ InlineComponentOrDocumentRootName

◆ RootDocumentNameType

Member Function Documentation

◆ generate_assignToListProperty()

void QQmltc::CodeGenerator::generate_assignToListProperty ( QStringList * block,
const QQmlJSScope::ConstPtr & type,
const QQmlJSMetaProperty & p,
const QStringList & value,
const QString & accessor,
QString & qmlListVarName )
static

Definition at line 89 of file qqmltccompilerpieces.cpp.

◆ generate_assignToProperty()

void QQmltc::CodeGenerator::generate_assignToProperty ( QStringList * block,
const QQmlJSScope::ConstPtr & type,
const QQmlJSMetaProperty & p,
const QString & value,
const QString & accessor,
bool constructFromQObject = false )
static

Definition at line 117 of file qqmltccompilerpieces.cpp.

◆ generate_beginClassCode()

void QQmltc::CodeGenerator::generate_beginClassCode ( Type & current,
const QQmlJSScope::ConstPtr & type ) const
inline

Generates {current.beginClass}'s code. The beginClass method optionally calls QQmlParserStatus::classBegin() when type implements the corresponding interface.

Definition at line 585 of file qqmltccompilerpieces_p.h.

◆ generate_callExecuteRuntimeFunction()

void QQmltc::CodeGenerator::generate_callExecuteRuntimeFunction ( QStringList * block,
const QString & url,
QQmlJSMetaMethod::AbsoluteFunctionIndex index,
const QString & accessor,
const QString & returnType,
const QList< Variable > & parameters = {} )
static

Definition at line 177 of file qqmltccompilerpieces.cpp.

◆ generate_completeComponentCode()

void QQmltc::CodeGenerator::generate_completeComponentCode ( Type & current,
const QQmlJSScope::ConstPtr & type ) const
inline

Generates {current.completeComponent}'s code. The completeComponent method optionally calls QQmlParserStatus::componentComplete() when type implements the corresponding interface.

Definition at line 599 of file qqmltccompilerpieces_p.h.

◆ generate_createBindingOnProperty()

void QQmltc::CodeGenerator::generate_createBindingOnProperty ( QStringList * block,
const QString & unitVarName,
const QString & scope,
qsizetype functionIndex,
const QString & target,
const QQmlJSScope::ConstPtr & targetType,
int propertyIndex,
const QQmlJSMetaProperty & p,
int valueTypeIndex,
const QString & subTarget )
static

Definition at line 214 of file qqmltccompilerpieces.cpp.

◆ generate_createTranslationBindingOnProperty()

void QQmltc::CodeGenerator::generate_createTranslationBindingOnProperty ( QStringList * block,
const TranslationBindingInfo & info )
static

Definition at line 290 of file qqmltccompilerpieces.cpp.

◆ generate_endInitCode()

void QQmltc::CodeGenerator::generate_endInitCode ( Type & current,
const QQmlJSScope::ConstPtr & type ) const
inline

Generates {current.endInit}'s code. The endInit method creates bindings, connects signals with slots and generally performs other within-object initialization. Additionally, the QML document root's endInit calls endInit methods of all the necessary QML types within the document.

Definition at line 449 of file qqmltccompilerpieces_p.h.

◆ generate_finalizeComponentCode()

void QQmltc::CodeGenerator::generate_finalizeComponentCode ( Type & current,
const QQmlJSScope::ConstPtr & type ) const
inline

Generates {current.finalizeComponent}'s code. The finalizeComponent method optionally calls QQmlFinalizerHook::componentFinalized() when type implements the corresponding interface.

Definition at line 614 of file qqmltccompilerpieces_p.h.

◆ generate_getCompilationUnitFromUrl()

void QQmltc::CodeGenerator::generate_getCompilationUnitFromUrl ( )
inlinestatic

◆ generate_handleOnCompletedCode()

void QQmltc::CodeGenerator::generate_handleOnCompletedCode ( Type & current,
const QQmlJSScope::ConstPtr & type ) const
inline

Generates {current.handleOnCompleted}'s code. The handleOnCompleted method optionally calls a Component.onCompleted handler if that is present in type.

Definition at line 629 of file qqmltccompilerpieces_p.h.

◆ generate_initCode()

decltype(auto) QQmltc::CodeGenerator::generate_initCode ( Type & current,
const QQmlJSScope::ConstPtr & type ) const
inlinenodiscard

Generates {current.init}'s code. The init method sets up a QQmlContext for the object and (in case type is a document root) calls other object creation methods, and a user-provided initialization callback, in a well-defined order:

  1. current.beginClass
  2. current.endInit
  3. user-provided initialization function
  4. current.setComplexBindings
  5. current.completeComponent
  6. current.finalizeComponent
  7. current.handleOnCompleted

This function returns a QScopeGuard with the final instructions that have to be generated at a later point, once everything else is compiled.

See also
generate_initCodeForTopLevelComponent

Definition at line 183 of file qqmltccompilerpieces_p.h.

◆ generate_initCodeForTopLevelComponent()

void QQmltc::CodeGenerator::generate_initCodeForTopLevelComponent ( Type & current,
const QQmlJSScope::ConstPtr & type )
inline

Generates {current.init}'s code in case when type is a top-level Component type. The init method in this case mimics QQmlObjectCreator::createComponent() logic.

See also
generate_initCode

Definition at line 352 of file qqmltccompilerpieces_p.h.

◆ generate_interfaceCallCode()

void QQmltc::CodeGenerator::generate_interfaceCallCode ( Method * function,
const QQmlJSScope::ConstPtr & type,
const QString & interfaceName,
const QString & interfaceCall ) const
inline

A generic helper function that generates interface code boilerplate, adding it to a passed function. This is a building block used to generate e.g. QQmlParserStatus API calls.

Definition at line 513 of file qqmltccompilerpieces_p.h.

◆ generate_qmltcInstructionCallCode()

void QQmltc::CodeGenerator::generate_qmltcInstructionCallCode ( Method * function,
const QQmlJSScope::ConstPtr & type,
const QString & baseInstructionArgs,
const QString & childInstructionArgs ) const
inline

A generic helper function that generates special qmltc instruction code boilerplate, adding it to a passed function. This is a building block used to generate e.g. QML_endInit code.

Definition at line 396 of file qqmltccompilerpieces_p.h.

◆ generate_setComplexBindingsCode()

void QQmltc::CodeGenerator::generate_setComplexBindingsCode ( Type & current,
const QQmlJSScope::ConstPtr & type ) const
inline

Generates {current.setComplexBindings}'s code. The setComplexBindings method creates complex bindings (such as script bindings). Additionally, the QML document root's setComplexBindings calls setComplexBindings methods of all the necessary QML types within the document.

Definition at line 491 of file qqmltccompilerpieces_p.h.

◆ generate_setIdValue()

void QQmltc::CodeGenerator::generate_setIdValue ( QStringList * block,
const QString & context,
qsizetype index,
const QString & accessor,
const QString & idString )
static

Definition at line 167 of file qqmltccompilerpieces.cpp.

◆ generate_typeCount() [1/2]

QString QQmltc::CodeGenerator::generate_typeCount ( const InlineComponentOrDocumentRootName & inlinedComponent) const
inline

Definition at line 89 of file qqmltccompilerpieces_p.h.

◆ generate_typeCount() [2/2]

template<typename Predicate>
QString QQmltc::CodeGenerator::generate_typeCount ( Predicate p,
const InlineComponentOrDocumentRootName & inlinedComponent ) const
inline

Generate the constexpr typeCount expression for given inlinedComponent. Leave inlinedComponent empty to generate the expression for the main component.

Generates a constexpr function consisting of a sum of type counts for a current QML document. Predicate p acts as a stop condition to prematurely end the sum generation.

The high-level idea:

Each qmltc-compiled document root has a notion of type count. Type count is a number of types the current QML document contains (except for Component-wrapped types) plus the sum of all type counts of all the QML documents used in the current document: if current document has a type with QML base type, this type's type count is added to the type count of the current document.

To be able to lookup created objects during the creation process, one needs to know an index of each object within the document + an offset of the document. Index comes from QmltcVisitor and is basically a serial number of a type in the document (index < type count of the document root type). The offset is more indirect.

The current document always starts with an offset of 0, each type that has a QML base type also "has a sub-document". Each sub-document has a non-0 offset X, where X is calculated as a sum of the current document's type count and a cumulative type count of all the previous sub-documents that appear before the sub-document of interest:

// A.qml
Item { // offset: 0; number of types == 1 (document root) + 3 (children)
QmlBase1 { } // offset: 4 (number of types in A.qml itself)
QmlBase2 { } // offset: 4 + N, where N == typeCount(QmlBase1.qml)
QmlBase3 { } // offset: (4 + N) + M, where M == typeCount(QmlBase2.qml)
} // typeCount(A.qml) == 4 + N + M + O, where O == typeCount(QmlBase3.qml)
[0]
Definition lalr.h:84

As all objects are put into an array, schematically you can look at it in the following way:

count: 4 N M O
objects: aaaa|xxxxxxxxxxxxx|yyyyyyy|zzz
^ ^ ^ ^
files: | QmlBase1.qml | QmlBase3.qml
A.qml QmlBase2.qml
GLenum GLenum GLsizei count
#define M(_x, _y)

For the object lookup logic itself, see QQmltcObjectCreationHelper

Definition at line 696 of file qqmltccompilerpieces_p.h.

◆ urlMethodName()

QString QQmltc::CodeGenerator::urlMethodName ( ) const
inline

Definition at line 155 of file qqmltccompilerpieces_p.h.

◆ wrap_addressof()

QString QQmltc::CodeGenerator::wrap_addressof ( const QString & addressed)
static

Definition at line 360 of file qqmltccompilerpieces.cpp.

◆ wrap_extensionType()

CodeGenerator::PreparedValue QQmltc::CodeGenerator::wrap_extensionType ( const QQmlJSScope::ConstPtr & type,
const QQmlJSMetaProperty & p,
const QString & accessor )
static

Definition at line 28 of file qqmltccompilerpieces.cpp.

◆ wrap_mismatchingTypeConversion()

CodeGenerator::PreparedValue QQmltc::CodeGenerator::wrap_mismatchingTypeConversion ( const QQmlJSMetaProperty & p,
QString value )
static

Definition at line 320 of file qqmltccompilerpieces.cpp.

◆ wrap_privateClass()

QString QQmltc::CodeGenerator::wrap_privateClass ( const QString & accessor,
const QQmlJSMetaProperty & p )
static

Definition at line 351 of file qqmltccompilerpieces.cpp.

Member Data Documentation

◆ documentUrl

QString QQmltc::CodeGenerator::documentUrl

Definition at line 46 of file qqmltccompilerpieces_p.h.

◆ privateEngineName

const QString QQmltc::CodeGenerator::privateEngineName = u"ePriv"_s
static

Definition at line 43 of file qqmltccompilerpieces_p.h.

◆ typeCountName

const QString QQmltc::CodeGenerator::typeCountName = u"q_qmltc_typeCount"_s
static

Definition at line 44 of file qqmltccompilerpieces_p.h.

◆ visitor

Visitor* QQmltc::CodeGenerator::visitor = nullptr

Definition at line 47 of file qqmltccompilerpieces_p.h.


The documentation for this struct was generated from the following files: