Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmljsregistercontent_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
4#ifndef QQMLJSREGISTERCONTENT_P_H
5#define QQMLJSREGISTERCONTENT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16
17#include "qqmljsscope_p.h"
18#include <QtCore/qhash.h>
19#include <QtCore/qstring.h>
20
21#include <variant>
22
24
25class Q_QMLCOMPILER_EXPORT QQmlJSRegisterContent
26{
27public:
63
64 enum { InvalidLookupIndex = -1 };
65
67 bool isValid() const { return !m_storedType.isNull(); }
68
69 QString descriptiveName() const;
70
72 {
73 return a.m_storedType == b.m_storedType && a.m_variant == b.m_variant
74 && a.m_scope == b.m_scope && a.m_content == b.m_content;
75 }
76
78 {
79 return !(a == b);
80 }
81
82 bool isType() const { return m_content.index() == Type; }
83 bool isProperty() const { return m_content.index() == Property; }
84 bool isEnumeration() const { return m_content.index() == Enum; }
85 bool isMethod() const { return m_content.index() == Method; }
86 bool isImportNamespace() const { return m_content.index() == ImportNamespace; }
87 bool isConversion() const { return m_content.index() == Conversion; }
88 bool isList() const;
89
90 bool isWritable() const;
91
92 QQmlJSScope::ConstPtr storedType() const { return m_storedType; }
93 QQmlJSScope::ConstPtr scopeType() const { return m_scope; }
94
96 {
97 return std::get<std::pair<QQmlJSScope::ConstPtr, int>>(m_content).first;
98 }
100 {
101 return std::get<PropertyLookup>(m_content).property;
102 }
103 int baseLookupIndex() const
104 {
105 return std::get<PropertyLookup>(m_content).baseLookupIndex;
106 }
108 {
109 switch (m_content.index()) {
110 case Type:
111 return std::get<std::pair<QQmlJSScope::ConstPtr, int>>(m_content).second;
112 case Property:
113 return std::get<PropertyLookup>(m_content).resultLookupIndex;
114 default:
115 return InvalidLookupIndex;
116 }
117 }
119 {
120 return std::get<std::pair<QQmlJSMetaEnum, QString>>(m_content).first;
121 }
123 {
124 return std::get<std::pair<QQmlJSMetaEnum, QString>>(m_content).second;
125 }
126 QList<QQmlJSMetaMethod> method() const { return std::get<QList<QQmlJSMetaMethod>>(m_content); }
127 uint importNamespace() const { return std::get<uint>(m_content); }
128
130 {
131 return std::get<ConvertedTypes>(m_content).result;
132 }
133
135 {
136 return std::get<ConvertedTypes>(m_content).resultScope;
137 }
138
139 QList<QQmlJSScope::ConstPtr> conversionOrigins() const
140 {
141 return std::get<ConvertedTypes>(m_content).origins;
142 }
143
144 ContentVariant variant() const { return m_variant; }
145
146 friend size_t qHash(const QQmlJSRegisterContent &registerContent, size_t seed = 0)
147 {
148 seed = qHashMulti(seed, registerContent.m_storedType, registerContent.m_content.index(),
149 registerContent.m_scope, registerContent.m_variant);
150 switch (registerContent.m_content.index()) {
151 case Type:
152 return qHash(std::get<std::pair<QQmlJSScope::ConstPtr, int>>(registerContent.m_content),
153 seed);
154 case Property:
155 return qHash(std::get<PropertyLookup>(registerContent.m_content), seed);
156 case Enum:
157 return qHash(std::get<std::pair<QQmlJSMetaEnum, QString>>(registerContent.m_content),
158 seed);
159 case Method:
160 return qHash(std::get<QList<QQmlJSMetaMethod>>(registerContent.m_content), seed);
161 case ImportNamespace:
162 return qHash(std::get<uint>(registerContent.m_content), seed);
163 case Conversion:
164 return qHash(std::get<ConvertedTypes>(registerContent.m_content), seed);
165 }
166
167 Q_UNREACHABLE_RETURN(seed);
168 }
169
170 static QQmlJSRegisterContent create(const QQmlJSScope::ConstPtr &storedType,
172 int resultLookupIndex, ContentVariant variant,
173 const QQmlJSScope::ConstPtr &scope = {});
174
175 static QQmlJSRegisterContent create(const QQmlJSScope::ConstPtr &storedType,
177 int baseLookupIndex, int resultLookupIndex,
178 ContentVariant variant,
179 const QQmlJSScope::ConstPtr &scope);
180
181 static QQmlJSRegisterContent create(const QQmlJSScope::ConstPtr &storedType,
182 const QQmlJSMetaEnum &enumeration,
183 const QString &enumMember, ContentVariant variant,
184 const QQmlJSScope::ConstPtr &scope);
185
186 static QQmlJSRegisterContent create(const QQmlJSScope::ConstPtr &storedType,
187 const QList<QQmlJSMetaMethod> &methods,
188 ContentVariant variant,
189 const QQmlJSScope::ConstPtr &scope);
190
191 static QQmlJSRegisterContent create(const QQmlJSScope::ConstPtr &storedType,
192 uint importNamespaceStringId, ContentVariant variant,
193 const QQmlJSScope::ConstPtr &scope = {});
194
195 static QQmlJSRegisterContent create(const QQmlJSScope::ConstPtr &storedType,
196 const QList<QQmlJSScope::ConstPtr> &origins,
197 const QQmlJSScope::ConstPtr &conversion,
198 const QQmlJSScope::ConstPtr &conversionScope,
199 ContentVariant variant,
200 const QQmlJSScope::ConstPtr &scope = {});
201
203 {
205 result.m_storedType = newStoredType;
206 return result;
207 }
208
210 {
211 // This is not a conversion but a run time cast. It may result in null or undefined.
213 result.m_content = std::make_pair(newContainedType, result.resultLookupIndex());
214 return result;
215 }
216
217private:
218 enum ContentKind { Type, Property, Enum, Method, ImportNamespace, Conversion };
219
220 struct ConvertedTypes
221 {
222 QList<QQmlJSScope::ConstPtr> origins;
224 QQmlJSScope::ConstPtr resultScope;
225
226 friend size_t qHash(const ConvertedTypes &types, size_t seed = 0)
227 {
228 return qHashMulti(seed, types.origins, types.result, types.resultScope);
229 }
230
231 friend bool operator==(const ConvertedTypes &a, const ConvertedTypes &b)
232 {
233 return a.origins == b.origins && a.result == b.result && a.resultScope == b.resultScope;
234 }
235
236 friend bool operator!=(const ConvertedTypes &a, const ConvertedTypes &b)
237 {
238 return !(a == b);
239 }
240 };
241
242 struct PropertyLookup
243 {
245 int baseLookupIndex = InvalidLookupIndex;
246 int resultLookupIndex = InvalidLookupIndex;
247
248 friend size_t qHash(const PropertyLookup &property, size_t seed = 0)
249 {
250 return qHashMulti(
251 seed, property.property, property.baseLookupIndex, property.resultLookupIndex);
252 }
253
254 friend bool operator==(const PropertyLookup &a, const PropertyLookup &b)
255 {
256 return a.baseLookupIndex == b.baseLookupIndex
257 && a.resultLookupIndex == b.resultLookupIndex
258 && a.property == b.property;
259 }
260
261 friend bool operator!=(const PropertyLookup &a, const PropertyLookup &b)
262 {
263 return !(a == b);
264 }
265 };
266
267 using Content = std::variant<
268 std::pair<QQmlJSScope::ConstPtr, int>,
269 PropertyLookup,
270 std::pair<QQmlJSMetaEnum, QString>,
271 QList<QQmlJSMetaMethod>,
272 uint,
273 ConvertedTypes
274 >;
275
277 const QQmlJSScope::ConstPtr &scope, ContentVariant variant)
278 : m_storedType(storedType), m_scope(scope), m_variant(variant)
279 {
280 }
281
282 QQmlJSScope::ConstPtr m_storedType;
283 QQmlJSScope::ConstPtr m_scope;
284 Content m_content;
285 ContentVariant m_variant = Unknown;
286
287 // TODO: Constant string/number/bool/enumval
288};
289
291
292#endif // REGISTERCONTENT_H
static JNINativeMethod methods[]
QQmlJSRegisterContent storedIn(const QQmlJSScope::ConstPtr &newStoredType) const
QQmlJSRegisterContent()=default
QQmlJSScope::ConstPtr conversionResult() const
QQmlJSMetaProperty property() const
QQmlJSScope::ConstPtr scopeType() const
QQmlJSScope::ConstPtr conversionResultScope() const
QList< QQmlJSScope::ConstPtr > conversionOrigins() const
ContentVariant variant() const
friend size_t qHash(const QQmlJSRegisterContent &registerContent, size_t seed=0)
QQmlJSScope::ConstPtr type() const
QQmlJSScope::ConstPtr storedType() const
friend bool operator!=(const QQmlJSRegisterContent &a, const QQmlJSRegisterContent &b)
QQmlJSMetaEnum enumeration() const
QQmlJSRegisterContent castTo(const QQmlJSScope::ConstPtr &newContainedType) const
friend bool operator==(const QQmlJSRegisterContent &a, const QQmlJSRegisterContent &b)
QList< QQmlJSMetaMethod > method() const
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
constexpr bool operator!=(const timespec &t1, const timespec &t2)
static const QCssKnownValue origins[NumKnownOrigins - 1]
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
[7]
GLsizei GLenum GLenum * types
GLenum type
GLint first
GLuint64EXT * result
[6]
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
bool operator==(const QRandomGenerator &rng1, const QRandomGenerator &rng2)
Definition qrandom.cpp:1220
unsigned int uint
Definition qtypes.h:34
const char property[13]
Definition qwizard.cpp:101
QVariant variant
[1]
view create()