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
qqmltcvisitor_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
5#ifndef QQMLTCVISITOR_P_H
6#define QQMLTCVISITOR_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <private/qtqmlcompilerglobal_p.h>
20
21#include <QtCore/qspan.h>
22#include <QtCore/qstring.h>
23#include <QtCore/qstringlist.h>
24#include <QtCore/qlist.h>
25
26#include <QtQml/private/qqmlirbuilder_p.h>
27#include <private/qqmljsimportvisitor_p.h>
28#include <private/qqmljslogger_p.h>
29
30QT_BEGIN_NAMESPACE
31
32using namespace Qt::StringLiterals;
33
34Q_DECLARE_LOGGING_CATEGORY(lcQmltcCompiler)
35
36namespace QQmltc {
37
40
42{
43 void findCppIncludes();
44 void postVisitResolve(const QHash<QQmlJSScope::ConstPtr, QList<QQmlJSMetaPropertyBinding>>
45 &qmlIrOrderedBindings);
46 void setupAliases();
47 void checkNamesAndTypes(const QQmlJSScope::ConstPtr &type);
48 QString filePath(const QQmlJSScope::ConstPtr &scope) const;
49
50 QString sourceDirectoryPath(const QString &path) const;
51
53
54public:
55 Visitor(QQmlJSImporter *importer, QQmlJSLogger *logger,
56 const QString &implicitImportDirectory,
57 const QStringList &qmldirFiles = QStringList());
58
59 bool visit(QQmlJS::AST::UiObjectDefinition *) override;
60 void endVisit(QQmlJS::AST::UiObjectDefinition *) override;
61
62 bool visit(QQmlJS::AST::UiObjectBinding *) override;
63 void endVisit(QQmlJS::AST::UiObjectBinding *) override;
64
65 bool visit(QQmlJS::AST::UiScriptBinding *) override;
66
67 bool visit(QQmlJS::AST::UiPublicMember *) override;
68
69 bool visit(QQmlJS::AST::UiInlineComponent *) override;
70
71 void endVisit(QQmlJS::AST::UiProgram *) override;
72
74 qmlTypesWithQmlBases(const InlineComponentOrDocumentRootName &inlinedComponentName) const
75 {
76 return m_qmlTypesWithQmlBases.value(inlinedComponentName);
77 }
78 QSet<QString> cppIncludeFiles() const { return m_cppIncludes; }
79
80 qsizetype creationIndex(const QQmlJSScope::ConstPtr &type) const
81 {
82 Q_ASSERT(type->scopeType() == QQmlSA::ScopeType::QMLScope);
83 return m_creationIndices.value(type, -1);
84 }
85
86 qsizetype typeCount(const InlineComponentOrDocumentRootName &inlineComponent) const
87 {
88 return m_inlineComponentTypeCount.value(inlineComponent);
89 }
90
91 qsizetype qmlComponentIndex(const QQmlJSScope::ConstPtr &type) const
92 {
93 Q_ASSERT(type->scopeType() == QQmlSA::ScopeType::QMLScope);
94 return m_syntheticTypeIndices.value(type, -1);
95 }
96
97 qsizetype qmlIrObjectIndex(const QQmlJSScope::ConstPtr &type) const
98 {
99 Q_ASSERT(type->scopeType() == QQmlSA::ScopeType::QMLScope);
100 Q_ASSERT(m_qmlIrObjectIndices.contains(type));
101 return m_qmlIrObjectIndices.value(type, -1);
102 }
103
104 /*! \internal
105 Returns a runtime index counterpart of `id: foo` for \a type. Returns -1
106 if \a type does not have an id.
107 */
108 int runtimeId(const QQmlJSScope::ConstPtr &type) const
109 {
110 // NB: this function is expected to be called for "pure" types
111 Q_ASSERT(!m_typesWithId.contains(type) || m_typesWithId[type] != -1);
112 return m_typesWithId.value(type, -1);
113 }
114
115 /*! \internal
116 Returns all encountered QML types.
117 */
118 QList<QQmlJSScope::ConstPtr> allQmlTypes() const { return qmlTypes(); }
119
120 /*! \internal
121 Returns QML types which return \c false in
122 \c{isComponentRootElement()}. The QHash key are the enclosing inline component
123 or the root document name when not beloning to any inline component.
124 Called "pure", because these are the ones
125 that are not wrapped into QQmlComponent. Pure QML types can be created
126 through direct constructor invocation.
127 */
129 pureQmlTypes(const InlineComponentOrDocumentRootName &inlineComponent) const
130 {
131 return m_pureQmlTypes[inlineComponent];
132 }
133
134 /*!
135 * \internal
136 * Returns a list of the inline components. This list ends with the document root.
137 */
139 {
140 return m_inlineComponentNames;
141 }
143 inlineComponent(const InlineComponentOrDocumentRootName &inlineComponentName) const
144 {
145 return m_inlineComponents.value(inlineComponentName);
146 }
147
148 /*! \internal
149 Returns \c true when \a type has deferred bindings. Returns \c false
150 otherwise.
151 */
152 bool hasDeferredBindings(const QQmlJSScope::ConstPtr &type) const
153 {
154 return m_typesWithDeferredBindings.contains(type);
155 }
156
157 enum Mode { Import, Compile };
158 void setMode(Mode mode) { m_mode = mode; }
159
160 bool checkCustomParser(const QQmlJSScope::ConstPtr &scope) override;
162
163protected:
164 QStringList m_qmlTypeNames; // names of QML types arranged as a stack
166 /*!
167 * \internal
168 * QML types with composite/QML base types, mapped from inline component name to types
169 */
171 QSet<QString> m_cppIncludes; // all C++ includes found from QQmlJSScope hierarchy
173 m_pureQmlTypes; // the ones not under QQmlComponent
174 /*!
175 * \internal
176 * List of the names of the inline components, useful when iterating over QHash that
177 * uses those names as keys. Ends with the the document root.
178 */
180 /*!
181 * \internal
182 * Map inline component names to the corresponding type, and the document root
183 * name to all types not belonging to any inline component.
184 */
186 /*!
187 * \internal
188 * Map types to their creation indices. Childrens are stored at their creation index in
189 * a QObject* array either in the document root or in the inline component they belong to.
190 * Therefore two types in the same file might have the same creation index, if they belong
191 * to different inline components.
192 */
194 /*!
195 * \internal
196 * Counts the types (pure qml types and explicit/implicit components) per inline component.
197 * Needed to set the size of the QObject* array in the document root or the inline component
198 * they belong to.
199 */
203
205
206 // prefer allQmlTypes or pureQmlTypes. this function is misleading in qmltc
207 QList<QQmlJSScope::ConstPtr> qmlTypes() const { return QQmlJSImportVisitor::qmlTypes(); }
208
210
212
214};
215
216} // namespace QQmltc
217
218QT_END_NAMESPACE
219
220#endif // QQMLTCVISITOR_P_H
qsizetype creationIndex(const QQmlJSScope::ConstPtr &type) const
QHash< QQmlJSScope::ConstPtr, qsizetype > m_qmlIrObjectIndices
void endVisit(QQmlJS::AST::UiObjectDefinition *) override
QList< QQmlJSScope::ConstPtr > pureQmlTypes(const InlineComponentOrDocumentRootName &inlineComponent) const
QQmlJSScope::ConstPtr inlineComponent(const InlineComponentOrDocumentRootName &inlineComponentName) const
QStringList m_qmlTypeNames
qsizetype typeCount(const InlineComponentOrDocumentRootName &inlineComponent) const
QList< QQmlJSScope::ConstPtr > qmlTypes() const
QHash< QQmlJSScope::ConstPtr, qsizetype > m_creationIndices
QList< QQmlJSScope::ConstPtr > qmlTypesWithQmlBases(const InlineComponentOrDocumentRootName &inlinedComponentName) const
QHash< InlineComponentOrDocumentRootName, QQmlJSScope::Ptr > m_inlineComponents
QList< QQmlJSScope::ConstPtr > allQmlTypes() const
Visitor(QQmlJSImporter *importer, QQmlJSLogger *logger, const QString &implicitImportDirectory, const QStringList &qmldirFiles=QStringList())
qsizetype qmlComponentIndex(const QQmlJSScope::ConstPtr &type) const
QSet< QString > m_cppIncludes
void setMode(Mode mode)
qsizetype qmlIrObjectIndex(const QQmlJSScope::ConstPtr &type) const
bool visit(QQmlJS::AST::UiObjectDefinition *) override
bool hasDeferredBindings(const QQmlJSScope::ConstPtr &type) const
QList< InlineComponentOrDocumentRootName > inlineComponentNames() const
QHash< QQmlJSScope::ConstPtr, int > m_typesWithId
QList< InlineComponentOrDocumentRootName > m_inlineComponentNames
int runtimeId(const QQmlJSScope::ConstPtr &type) const
QHash< InlineComponentOrDocumentRootName, qsizetype > m_inlineComponentTypeCount
bool hasSeenCustomParsers() const
QHash< QString, int > m_qmlTypeNameCounts
bool checkCustomParser(const QQmlJSScope::ConstPtr &scope) override
QSet< QQmlJSScope::ConstPtr > m_typesWithDeferredBindings
QHash< QQmlJSScope::ConstPtr, qsizetype > m_syntheticTypeIndices
QSet< QString > cppIncludeFiles() const
QSpan< const QmltcLoggingCategoryOverride > categoryOverrides()