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
qqmlprivate.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
5#ifndef QQMLPRIVATE_H
6#define QQMLPRIVATE_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 <QtQml/qjsprimitivevalue.h>
20#include <QtQml/qjsvalue.h>
21#include <QtQml/qqmllist.h>
22#include <QtQml/qqmlparserstatus.h>
23#include <QtQml/qqmlpropertyvaluesource.h>
24#include <QtQml/qtqmlglobal.h>
25
26#include <QtCore/qdatetime.h>
27#include <QtCore/qdebug.h>
28#include <QtCore/qglobal.h>
29#include <QtCore/qmetasequence.h>
30#include <QtCore/qmetaobject.h>
31#include <QtCore/qpointer.h>
32#include <QtCore/qurl.h>
33#include <QtCore/qtyperevision.h>
34#include <QtCore/qvariant.h>
35#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 3
36#include <QtCore/qversionnumber.h>
37#endif
38
39#include <functional>
40#include <limits>
41#include <type_traits>
42
43QT_BEGIN_NAMESPACE
44
45class QQmlPropertyValueInterceptor;
46class QQmlContextData;
47class QQmlFinalizerHook;
48
49namespace QQmlPrivate {
50struct CachedQmlUnit;
51template<typename A>
52using QQmlAttachedPropertiesFunc = A *(*)(QObject *);
53}
54
55namespace QV4 {
56struct ExecutionEngine;
57struct MarkStack;
58class ExecutableCompilationUnit;
59namespace CompiledData {
60struct Unit;
61struct CompilationUnit;
62using LookupValidationFn = bool (*)(QQmlEngine *engine, CompilationUnit *cu);
63}
64}
65namespace QmlIR {
66struct Document;
67typedef void (*IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *);
68}
69
70using QQmlAttachedPropertiesFunc = QQmlPrivate::QQmlAttachedPropertiesFunc<QObject>;
71
72inline size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed = 0)
73{
74 return qHash(quintptr(func), seed);
75}
76
77template <typename TYPE>
79{
80public:
81 enum {
83 };
84};
85
86
87class QJSEngine;
88class QQmlEngine;
89class QQmlCustomParser;
91
92class QQmlV4Function;
94using QQmlV4ExecutionEnginePtr = QV4::ExecutionEngine *;
95
96template<class T>
97QQmlCustomParser *qmlCreateCustomParser()
98{
99 return nullptr;
100}
101
102namespace QQmlPrivate
103{
105 template<typename T>
106 class QQmlElement final : public T
107 {
108 public:
109 // Not defaulted so that it can be specialized
111
112 ~QQmlElement() override {
113 QQmlPrivate::qdeclarativeelement_destructor(this);
114 }
115 static void operator delete(void *ptr) {
116 // We allocate memory from this class in QQmlType::create
117 // along with some additional memory.
118 // So we override the operator delete in order to avoid the
119 // sized operator delete to be called with a different size than
120 // the size that was allocated.
121 ::operator delete (ptr);
122 }
123#ifdef Q_CC_MSVC
124 static void operator delete(void *, void *) {
125 // Deliberately empty placement delete operator.
126 // Silences MSVC warning C4291: no matching operator delete found
127 // On MinGW it causes -Wmismatched-new-delete, though.
128 }
129#endif
130 };
131
140
141 template<typename T, typename WrapperT = T, typename = std::void_t<>>
143 {
144 static constexpr bool value = false;
145 };
146
147 template<typename T, typename WrapperT>
149 static_cast<QQmlEngine *>(nullptr),
150 static_cast<QJSEngine *>(nullptr)))>>
151 {
152 static constexpr bool value = std::is_same_v<
153 decltype(WrapperT::create(static_cast<QQmlEngine *>(nullptr),
154 static_cast<QJSEngine *>(nullptr))), T *>;
155 };
156
157 template<typename>
159
160 template<typename Ret, typename Class>
161 struct QmlMarkerFunction<Ret (Class::*)()>
162 {
163 using ClassType = Class;
164 };
165
166 template<typename T, typename Marker>
167 using QmlTypeHasMarker = std::is_same<T, typename QmlMarkerFunction<Marker>::ClassType>;
168
169 template<class T>
171 {
172 private:
173 template<class U>
174 static auto test(int) -> std::enable_if_t<
175 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_uncreatable)>::value
176 && bool(U::QmlIsUncreatable::yes),
177 std::true_type>;
178
179 template<class U>
180 static auto test(...) -> std::false_type;
181
182 public:
183 static constexpr bool Value = decltype(test<T>(0))::value;
184 };
185
186 template<typename T, typename WrapperT>
188 {
189 if constexpr (!std::is_base_of<QObject, T>::value)
191 if constexpr (QmlUncreatable<WrapperT>::Value)
193 if constexpr (!std::is_same_v<T, WrapperT> && HasSingletonFactory<T, WrapperT>::value)
195 if constexpr (std::is_default_constructible<T>::value)
197 if constexpr (HasSingletonFactory<T>::value)
199
201 }
202
203 template<typename T>
204 void createInto(void *memory, void *) { new (memory) QQmlElement<T>; }
205
206 template<typename T, typename WrapperT, SingletonConstructionMode Mode>
208 {
209 Q_UNUSED(q);
210 Q_UNUSED(j);
211 if constexpr (Mode == SingletonConstructionMode::Constructor)
212 return new T;
213 else if constexpr (Mode == SingletonConstructionMode::Factory)
214 return T::create(q, j);
215 else if constexpr (Mode == SingletonConstructionMode::FactoryWrapper)
216 return WrapperT::create(q, j);
217 else
218 return nullptr;
219 }
220
221 template<typename T>
222 QObject *createParent(QObject *p) { return new T(p); }
223
224 using CreateIntoFunction = void (*)(void *, void *);
228
229 template<typename T, typename WrapperT = T,
230 SingletonConstructionMode Mode = singletonConstructionMode<T, WrapperT>()>
232
233 template<typename T, typename WrapperT>
235 {
237 = QQmlPrivate::createInto<T>;
239 = QQmlPrivate::createSingletonInstance<
241 };
242
243 template<typename T, typename WrapperT>
245 {
246 static constexpr CreateIntoFunction createInto = nullptr;
248 };
249
250 template<typename T, typename WrapperT>
252 {
253 static constexpr CreateIntoFunction createInto = nullptr;
255 = QQmlPrivate::createSingletonInstance<
257 };
258
259 template<typename T, typename WrapperT>
261 {
262 static constexpr CreateIntoFunction createInto = nullptr;
264 = QQmlPrivate::createSingletonInstance<
266 };
267
268 template<typename T, typename WrapperT>
270 {
271 static constexpr CreateIntoFunction createInto = nullptr;
273 = QQmlPrivate::createSingletonInstance<
275 };
276
277 template<typename T,
281
282 template<typename T>
283 struct ExtendedType<T, false, false>
284 {
285 static constexpr const CreateParentFunction createParent = nullptr;
286 static const QMetaObject *staticMetaObject() { return nullptr; }
287 };
288
289 // If it's a QObject, we actually want an error if the ctor or the metaobject is missing.
290 template<typename T>
291 struct ExtendedType<T, true, false>
292 {
294 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
295 };
296
297 // If it's a Q_GADGET, we don't want the ctor.
298 template<typename T>
299 struct ExtendedType<T, false, true>
300 {
301 static constexpr const CreateParentFunction createParent = nullptr;
302 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
303 };
304
305 template<typename F, typename Result = void>
307 {
308 static constexpr const Result (*create)(const QJSValue &) = nullptr;
309 };
310
311 template<typename F>
312 struct ValueTypeFactory<F, std::void_t<decltype(F::create(QJSValue()))>>
313 {
314 static decltype(F::create(QJSValue())) create(const QJSValue &params)
315 {
316 return F::create(params);
317 }
318 };
319
320 template<typename T, typename F,
321 bool HasCtor = std::is_constructible_v<T, QJSValue>,
322 bool HasFactory = std::is_constructible_v<
323 QVariant, decltype(ValueTypeFactory<F>::create(QJSValue()))>>
324 struct ValueType;
325
326 template<typename T, typename F>
327 struct ValueType<T, F, false, false>
328 {
329 static constexpr const CreateValueTypeFunction create = nullptr;
330 };
331
332 template<typename T, typename F, bool HasCtor>
333 struct ValueType<T, F, HasCtor, true>
334 {
335 static QVariant create(const QJSValue &params)
336 {
337 return F::create(params);
338 }
339 };
340
341 template<typename T, typename F>
342 struct ValueType<T, F, true, false>
343 {
344 static QVariant create(const QJSValue &params)
345 {
346 return QVariant::fromValue(T(params));
347 }
348 };
349
350 template<class From, class To, int N>
352 {
353 static inline int cast() { return -1; }
354 };
355
356 template<class From, class To>
357 struct StaticCastSelectorClass<From, To, sizeof(int)>
358 {
359 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
360 };
361
362 template<class From, class To>
364 {
365 typedef int yes_type;
366 typedef char no_type;
367
368 static yes_type checkType(To *);
369 static no_type checkType(...);
370
371 static inline int cast()
372 {
373 return StaticCastSelectorClass<From, To, sizeof(checkType(reinterpret_cast<From *>(0)))>::cast();
374 }
375 };
376
377 // You can prevent subclasses from using the same attached type by specialzing this.
378 // This is reserved for internal types, though.
379 template<class T, class A>
381 {
382 using Type = A;
383 };
384
385 template<class T, class = std::void_t<>, bool OldStyle = QQmlTypeInfo<T>::hasAttachedProperties>
387 {
388 using Type = void;
390 static const QMetaObject *staticMetaObject() { return nullptr; }
391 static Func attachedPropertiesFunc() { return nullptr; }
392 };
393
394 // Defined inline via QML_ATTACHED
395 template<class T>
396 struct QmlAttached<T, std::void_t<typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type>, false>
397 {
398 // Normal attached properties
399 template <typename Parent, typename Attached>
406
407 // Disabled via OverridableAttachedType
408 template<typename Parent>
409 struct Properties<Parent, void>
410 {
412 static const QMetaObject *staticMetaObject() { return nullptr; }
413 static Func attachedPropertiesFunc() { return nullptr; }
414 };
415
416 using Type = typename std::conditional<
418 typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type, void>::type;
419 using Func = typename Properties<T, Type>::Func;
420
422 {
423 return Properties<T, Type>::staticMetaObject();
424 }
425
427 {
429 }
430 };
431
432 // Separately defined via QQmlTypeInfo
433 template<class T>
434 struct QmlAttached<T, std::void_t<decltype(T::qmlAttachedProperties)>, true>
435 {
436 using Type = typename std::remove_pointer<decltype(T::qmlAttachedProperties(nullptr))>::type;
438
439 static const QMetaObject *staticMetaObject() { return &Type::staticMetaObject; }
441 };
442
443 // This is necessary because both the type containing a default template parameter and the type
444 // instantiating the template need to have access to the default template parameter type. In
445 // this case that's T::QmlAttachedType. The QML_FOREIGN macro needs to befriend specific other
446 // types. Therefore we need some kind of "accessor". Because of compiler bugs in gcc and clang,
447 // we cannot befriend attachedPropertiesFunc() directly. Wrapping the actual access into another
448 // struct "fixes" that. For convenience we still want the free standing functions in addition.
449 template<class T>
451 {
453 {
454 return QQmlAttachedPropertiesFunc<QObject>(QmlAttached<T>::attachedPropertiesFunc());
455 }
456
458 {
459 return QmlAttached<T>::staticMetaObject();
460 }
461 };
462
463 template<typename T>
465 {
466 return QmlAttachedAccessor<T>::attachedPropertiesFunc();
467 }
468
469 template<typename T>
471 {
472 return QmlAttachedAccessor<T>::staticMetaObject();
473 }
474
476 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
477
479
487
488 bool has(StructVersion v) const { return structVersion >= int(v); }
489
491
495 // The second parameter of create is for userdata
496 void (*create)(void *, void *);
497 void *userdata;
499
500 // ### Qt7: Get rid of this. It can be covered by creationMethod below.
501 QVariant (*createValueType)(const QJSValue &);
502
503 const char *uri;
505 const char *elementName;
507
510
514
517
518 QQmlCustomParser *customParser;
519
522
524 // If this is extended ensure "version" is bumped!!!
525 };
526
561
573
576
577 AutoParentFunction function;
578 };
579
598
616
624
632
635 const char *uri;
637
638 // ### Qt7: Remove typeName. It's ignored because the only valid name is "list",
639 // and that's automatic.
640 const char *typeName;
641
645 };
646
658
660 {
661 virtual ~AOTTrackedLocalsStorage() = default;
662 virtual void markObjects(QV4::MarkStack *markStack) const = 0;
663 };
664
665 struct Q_QML_EXPORT AOTCompiledContext {
667
671 union {
674 };
675
676 QObject *thisObject() const;
677 QQmlEngine *qmlEngine() const;
678
679 QJSValue jsMetaType(int index) const;
680 void setInstructionPointer(int offset) const;
681 void setLocals(const AOTTrackedLocalsStorage *locals) const;
682 void setReturnValueUndefined() const;
683
684 static void mark(QObject *object, QV4::MarkStack *markStack);
685 static void mark(const QVariant &variant, QV4::MarkStack *markStack);
686 template<typename T>
687 static void mark(T, QV4::MarkStack *) {}
688
689 // Run QQmlPropertyCapture::captureProperty() without retrieving the value.
690 bool captureLookup(uint index, QObject *object) const;
692 void captureTranslation() const;
695 void storeNameSloppy(uint nameIndex, void *value, QMetaType type) const;
697
699
700 void writeToConsole(
702 const QLoggingCategory *loggingCategory) const;
703
706 int ctorIndex, void **args) const;
707#if QT_QML_REMOVED_SINCE(6, 9)
710 int ctorIndex, void *ctorArg) const;
711#endif
712
713 // Those are explicit arguments to the Date() ctor, not implicit coercions.
722
724 double year, double month, double day = 1,
725 double hours = 0, double minutes = 0, double seconds = 0, double msecs = 0) const;
726
727 // All of these lookup functions should be used as follows:
728 //
729 // while (!fooBarLookup(...)) {
730 // setInstructionPointer(...);
731 // initFooBarLookup(...);
732 // if (engine->hasException()) {
733 // ...
734 // break;
735 // }
736 // }
737 //
738 // The bool-returning *Lookup functions exclusively run the happy path and return false if
739 // that fails in any way. The failure may either be in the lookup structs not being
740 // initialized or an exception being thrown.
741 // The init*Lookup functions initialize the lookup structs and amend any exceptions
742 // previously thrown with line numbers. They might also throw their own exceptions. If an
743 // exception is present after the initialization there is no way to carry out the lookup and
744 // the exception should be propagated. If not, the original lookup can be tried again.
745
746 bool callQmlContextPropertyLookup(uint index, void **args, int argc) const;
748
749#if QT_QML_REMOVED_SINCE(6, 9)
751 uint index, void **args, const QMetaType *types, int argc) const;
753#endif
754
755 bool loadContextIdLookup(uint index, void *target) const;
757
758 bool callObjectPropertyLookup(uint index, QObject *object, void **args, int argc) const;
762
763#if QT_QML_REMOVED_SINCE(6, 9)
765 uint index, QObject *object, void **args, const QMetaType *types, int argc) const;
767
768 bool callGlobalLookup(uint index, void **args, const QMetaType *types, int argc) const;
769 void initCallGlobalLookup(uint index) const;
770
771 bool loadGlobalLookup(uint index, void *target, QMetaType type) const;
772 void initLoadGlobalLookup(uint index) const;
773#endif
774
775 bool loadGlobalLookup(uint index, void *target) const;
777
781#if QT_QML_REMOVED_SINCE(6, 9)
783#endif
784
785 bool loadSingletonLookup(uint index, void *target) const;
787
788 bool loadAttachedLookup(uint index, QObject *object, void *target) const;
790
791 bool loadTypeLookup(uint index, void *target) const;
793
794 bool getObjectLookup(uint index, QObject *object, void *target) const;
798#if QT_QML_REMOVED_SINCE(6, 9)
800#endif
801
802 bool getValueLookup(uint index, void *value, void *target) const;
803 bool writeBackValueLookup(uint index, void *value, void *source) const;
805#if QT_QML_REMOVED_SINCE(6, 9)
807#endif
808
809 bool getEnumLookup(uint index, void *target) const;
810#if QT_QML_REMOVED_SINCE(6, 6)
811 bool getEnumLookup(uint index, int *target) const;
812#endif
814 const char *enumerator, const char *enumValue) const;
815
816 bool setObjectLookup(uint index, QObject *object, void *value) const;
819#if QT_QML_REMOVED_SINCE(6, 9)
821#endif
822
823 bool setValueLookup(uint index, void *target, void *value) const;
826#if QT_QML_REMOVED_SINCE(6, 9)
828#endif
829
830 bool callValueLookup(uint index, void *target, void **args, int argc) const;
833
840
842 {
843 // This does not cover everything you can possibly wrap into a QVariant.
844 // However, since we only _promise_ to handle single objects, this is OK.
846 return;
847
848 if (QObject *object = *static_cast<QObject *const *>(variant.constData()))
850 }
851
852 template<typename Value>
854 };
855
859 void (*signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes);
860 void (*functionPtr)(const AOTCompiledContext *context, void **argv);
861 };
862
863#if QT_DEPRECATED_SINCE(6, 6)
864 QT_DEPRECATED_VERSION_X(6, 6, "Use AOTCompiledFunction instead")
866#endif
867
873
874 typedef const CachedQmlUnit *(*QmlUnitCacheLookupFunction)(const QUrl &url);
877 QmlUnitCacheLookupFunction lookupCachedQmlUnit;
878 };
879
893
896
897#if QT_DEPRECATED_SINCE(6, 3)
899 {
902 bool alreadyCalled = false;
903 };
904#endif
905
906 struct Q_QML_EXPORT SingletonInstanceFunctor
907 {
909
911
912 // Not a QPointer, so that you cannot assign it to a different
913 // engine when the first one is deleted.
914 // That would mess up the QML contexts.
916 };
917
918 static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset = -1)
919 {
920 if (!metaObject || !key)
921 return -1;
922
923 const int offset = metaObject->classInfoOffset();
924 const int start = (startOffset == -1)
925 ? (metaObject->classInfoCount() + offset - 1)
926 : startOffset;
927 for (int i = start; i >= offset; --i)
928 if (qstrcmp(key, metaObject->classInfo(i).name()) == 0) {
929 return i;
930 }
931 return -1;
932 }
933
934 inline const char *classInfo(const QMetaObject *metaObject, const char *key)
935 {
936 return metaObject->classInfo(indexOfOwnClassInfo(metaObject, key)).value();
937 }
938
939 inline QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key,
940 QTypeRevision defaultValue = QTypeRevision())
941 {
942 const int index = indexOfOwnClassInfo(metaObject, key);
943 return (index == -1) ? defaultValue
944 : QTypeRevision::fromEncodedVersion(
945 QLatin1StringView(metaObject->classInfo(index).value()).toInt());
946 }
947
949
950 inline bool boolClassInfo(const QMetaObject *metaObject, const char *key,
951 bool defaultValue = false)
952 {
953 const int index = indexOfOwnClassInfo(metaObject, key);
954 if (index == -1)
955 return defaultValue;
956 return qstrcmp(metaObject->classInfo(index).value(), "true") == 0;
957 }
958
959 // These detector classes are using a somehow "old school" SFINAE
960 // approach (overloaded test() functions, rather than void_t
961 // and similar more modern constructs) to avoid hitting GCC/MSVC
962 // bugs; be careful when refactoring these. In particular, make sure
963 // that they still work with private members even if you befriend
964 // the detector.
965
966 template<class T>
968 {
969 private:
970 template<class U>
971 static auto test(int) -> std::conditional_t<
972 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_extended)>::value,
973 typename U::QmlExtendedType *,
974 void *
975 >;
976
977 template<class U>
978 static auto test(...) -> void *;
979
980 public:
981 // Some compilers complain if we have functions return abstract types.
982 // So we add pointers in the above, and remove the pointer here.
983 using Type = std::remove_pointer_t<decltype(test<T>(0))>;
984 };
985
986 template<class T>
988 {
989 private:
990 template<class U>
991 static constexpr auto metaObjectImpl(int) ->
992 decltype((void)U::qmlExtendedNamespace(), static_cast<const QMetaObject *>(nullptr))
993 {
994 if constexpr (QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_extendedNamespace)>::value)
995 return U::qmlExtendedNamespace();
996 else
997 return nullptr;
998 }
999
1000 template<class U>
1001 static constexpr auto metaObjectImpl(...) -> const QMetaObject *
1002 {
1003 return nullptr;
1004 }
1005
1006 public:
1007 static constexpr const QMetaObject *metaObject() { return metaObjectImpl<T>(0); }
1008 };
1009
1010 template<class T>
1012 {
1013 private:
1014 template<class U>
1015 static auto test(int) -> std::conditional_t<
1016 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_foreign)>::value,
1017 typename U::QmlForeignType *,
1018 U *
1019 >;
1020
1021 template<class U>
1022 static auto test(...) -> U *;
1023
1024 public:
1025 using Type = std::remove_pointer_t<decltype(test<T>(0))>;
1026 };
1027
1028 template<class T>
1030 {
1031 private:
1032 template<class U>
1033 static auto test(int) -> std::enable_if_t<
1034 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_anonymous)>::value
1035 && bool(U::QmlIsAnonymous::yes),
1036 std::true_type
1037 >;
1038
1039 template<class U>
1040 static auto test(...) -> std::false_type;
1041
1042 public:
1043 static constexpr bool Value = decltype(test<T>(0))::value;
1044 };
1045
1046 template <class T>
1048 {
1049 private:
1050 template<class U>
1051 static auto test(int) -> std::enable_if_t<
1052 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_singleton)>::value
1053 && bool(U::QmlIsSingleton::yes),
1054 std::true_type
1055 >;
1056
1057 template<class U>
1058 static auto test(...) -> std::false_type;
1059
1060 public:
1061 static constexpr bool Value = decltype(test<T>(0))::value;
1062 };
1063
1064 template<class T>
1066 {
1067 private:
1068 template<class U>
1069 static auto test_impl(int) -> std::bool_constant<bool(U::QmlIsSequence::yes)>;
1070
1071 template<class U>
1072 static auto test_impl(...) -> std::false_type;
1073
1074 template<class U>
1075 static constexpr bool test() {
1076 if constexpr (decltype(test_impl<U>(0))::value) {
1077 static_assert((std::is_same_v<typename U::QmlSequenceValueType,
1078 typename QmlResolved<U>::Type::value_type>));
1079 return true;
1080 }
1081 return false;
1082 }
1083
1084 public:
1085 static constexpr bool Value = test<T>();
1086 };
1087
1088 template<class T>
1090 {
1091 private:
1092 template<class U>
1093 static auto test(int) ->
1094 decltype((void)qobject_interface_iid<U *>(), std::bool_constant<bool(U::QmlIsInterface::yes)>{});
1095
1096 template<class U>
1097 static auto test(...) -> std::false_type;
1098
1099 public:
1100 static constexpr bool Value = decltype(test<T>(0))::value;
1101 };
1102
1103 template<class T, typename = std::void_t<>>
1105 {
1106 static const QMetaObject *staticMetaObject() { return nullptr; }
1107 };
1108
1109 template<class T>
1111 {
1112 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
1113 };
1114
1115 template<class T>
1117 {
1118 static constexpr bool hasAcceptableCtors()
1119 {
1120 if constexpr (!std::is_default_constructible_v<T>)
1121 return false;
1122 else if constexpr (std::is_base_of_v<QObject, T>)
1123 return true;
1124 else
1125 return std::is_copy_constructible_v<T>;
1126 }
1127
1128 static constexpr QMetaType self()
1129 {
1130 if constexpr (std::is_base_of_v<QObject, T>)
1131 return QMetaType::fromType<T*>();
1132 else
1133 return QMetaType::fromType<T>();
1134 }
1135
1136 static constexpr QMetaType list()
1137 {
1138 if constexpr (std::is_base_of_v<QObject, T>)
1139 return QMetaType::fromType<QQmlListProperty<T>>();
1140 else
1141 return QMetaType::fromType<QList<T>>();
1142 }
1143
1144 static constexpr QMetaSequence sequence()
1145 {
1146 if constexpr (std::is_base_of_v<QObject, T>)
1147 return QMetaSequence();
1148 else
1149 return QMetaSequence::fromContainer<QList<T>>();
1150 }
1151
1152 static constexpr int size()
1153 {
1154 return sizeof(T);
1155 }
1156 };
1157
1158 template<>
1159 struct QmlMetaType<void>
1160 {
1161 static constexpr bool hasAcceptableCtors() { return true; }
1162 static constexpr QMetaType self() { return QMetaType(); }
1163 static constexpr QMetaType list() { return QMetaType(); }
1164 static constexpr QMetaSequence sequence() { return QMetaSequence(); }
1165 static constexpr int size() { return 0; }
1166 };
1167
1168 template<typename T, typename E, typename WrapperT = T>
1169 void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor,
1170 const QMetaObject *classInfoMetaObject,
1171 QList<int> *qmlTypeIds, const QMetaObject *extension)
1172 {
1173 static_assert(std::is_base_of_v<QObject, T>);
1175 0,
1176
1177 uri,
1178 QTypeRevision::fromMajorVersion(versionMajor),
1179
1180 Constructors<T, WrapperT>::createSingletonInstance,
1181
1182 StaticMetaObject<T>::staticMetaObject(),
1183 classInfoMetaObject,
1184
1185 QmlMetaType<T>::self(),
1186
1187 ExtendedType<E>::createParent,
1188 extension ? extension : ExtendedType<E>::staticMetaObject(),
1189
1190 qmlTypeIds
1191 };
1192
1193 qmlregister(SingletonAndRevisionsRegistration, &api);
1194 }
1195
1196 template<typename T, typename E>
1197 void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor,
1198 const QMetaObject *classInfoMetaObject,
1199 QList<int> *qmlTypeIds, const QMetaObject *extension,
1200 bool forceAnonymous = false)
1201 {
1203 3,
1204 QmlMetaType<T>::self(),
1205 QmlMetaType<T>::list(),
1206 QmlMetaType<T>::size(),
1207 Constructors<T>::createInto,
1208 nullptr,
1209 ValueType<T, E>::create,
1210
1211 uri,
1212 QTypeRevision::fromMajorVersion(versionMajor),
1213
1214 StaticMetaObject<T>::staticMetaObject(),
1215 classInfoMetaObject,
1216
1217 attachedPropertiesFunc<T>(),
1218 attachedPropertiesMetaObject<T>(),
1219
1220 StaticCastSelector<T, QQmlParserStatus>::cast(),
1221 StaticCastSelector<T, QQmlPropertyValueSource>::cast(),
1222 StaticCastSelector<T, QQmlPropertyValueInterceptor>::cast(),
1223
1224 ExtendedType<E>::createParent,
1225 extension ? extension : ExtendedType<E>::staticMetaObject(),
1226
1227 &qmlCreateCustomParser<T>,
1228 qmlTypeIds,
1229 StaticCastSelector<T, QQmlFinalizerHook>::cast(),
1230
1231 forceAnonymous,
1232 QmlMetaType<T>::sequence(),
1233 };
1234
1235 // Initialize the extension so that we can find it by name or ID.
1236 qMetaTypeId<E>();
1237
1238 qmlregister(TypeAndRevisionsRegistration, &type);
1239 }
1240
1241 template<typename T>
1242 void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor,
1243 const QMetaObject *classInfoMetaObject,
1244 QList<int> *qmlTypeIds)
1245 {
1247 0,
1248 uri,
1249 QTypeRevision::fromMajorVersion(versionMajor),
1250 classInfoMetaObject,
1251 QMetaType::fromType<T>(),
1252 QMetaSequence::fromContainer<T>(),
1253 qmlTypeIds
1254 };
1255
1257 }
1258
1259 template<>
1261 const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject,
1262 QList<int> *qmlTypeIds, const QMetaObject *, bool);
1263
1265 const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
1266 {
1267 return {
1268 /*.revision=*/ 0,
1269 /*.alignment=*/ 0,
1270 /*.size=*/ 0,
1271 /*.flags=*/ 0,
1272 /*.typeId=*/ QBasicAtomicInt(),
1273 /*.metaObject=*/ metaObjectFunction,
1274 /*.name=*/ name,
1275 /*.defaultCtr=*/ nullptr,
1276 /*.copyCtr=*/ nullptr,
1277 /*.moveCtr=*/ nullptr,
1278 /*.dtor=*/ nullptr,
1279 /*.equals*/ nullptr,
1280 /*.lessThan*/ nullptr,
1281 /*.debugStream=*/ nullptr,
1282 /*.dataStreamOut=*/ nullptr,
1283 /*.dataStreamIn=*/ nullptr,
1284 /*.legacyRegisterOp=*/ nullptr
1285 };
1286 }
1287
1288 Q_QML_EXPORT QObject *qmlExtendedObject(QObject *, int);
1289
1295
1296 Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type);
1297
1298 Q_QML_EXPORT QMetaType compositeMetaType(
1300 Q_QML_EXPORT QMetaType compositeMetaType(
1302 Q_QML_EXPORT QMetaType compositeListMetaType(
1304 Q_QML_EXPORT QMetaType compositeListMetaType(
1306
1308 // TODO they are used...
1309 [[maybe_unused]] static constexpr QLatin1StringView s_thisCuModule("##THIS_CU_MODULE##");
1310 [[maybe_unused]] static constexpr QLatin1StringView s_thisCuType("##THIS_CU_TYPE##");
1311
1312 enum struct IsComposite : bool { Yes, No };
1313 enum struct IsIC : bool { Yes, No };
1314 enum struct IsFlag : bool { Yes, No };
1315 enum struct IsSignal : bool { Yes, No };
1316
1317 struct Type
1318 {
1319 QString module;
1320 QString name;
1321 QString icNameOrExtensionTypeName; // composite ? icName : extensionTypeName
1324
1325 friend bool comparesEqual(const Type &lhs, const Type &rhs) noexcept
1326 {
1327 return lhs.module == rhs.module && lhs.name == rhs.name
1328 && lhs.icNameOrExtensionTypeName == rhs.icNameOrExtensionTypeName
1329 && lhs.isComposite == rhs.isComposite
1331 }
1333 friend size_t qHash(const Type &type, size_t seed = 0)
1334 {
1336 }
1337 };
1338
1339 struct Lookup
1340 {
1342 QString member;
1343 QString enumName;
1344
1345 friend bool comparesEqual(const Lookup &lhs, const Lookup &rhs) noexcept
1346 {
1347 return lhs.base == rhs.base && lhs.member == rhs.member && lhs.enumName == rhs.enumName;
1348 }
1350 friend size_t qHash(const Lookup &lookup, size_t seed = 0)
1351 {
1353 }
1354 };
1355
1357 {
1360 };
1361
1367
1369 {
1371 std::vector<Type> types; // return then parameter types
1374 };
1375
1378
1379 Q_QML_EXPORT
1380 bool validateLookupSignature(QQmlEngine *engine, QV4::CompiledData::CompilationUnit *cu,
1381 const Lookup &lookup, const Signature &signature);
1382} // namespace AOTLookupValidation
1383
1384} // namespace QQmlPrivate
1385
1386QT_END_NAMESPACE
1387
1388Q_DECLARE_OPAQUE_POINTER(QQmlV4FunctionPtr)
1389Q_DECLARE_OPAQUE_POINTER(QQmlV4ExecutionEnginePtr)
1390
1391#endif // QQMLPRIVATE_H
void operator delete(void *)
friend class QJSEngine
static void operator delete(void *ptr)
@ hasAttachedProperties
Definition qqmlprivate.h:82
static constexpr QLatin1StringView s_thisCuModule("##THIS_CU_MODULE##")
static constexpr QLatin1StringView s_thisCuType("##THIS_CU_TYPE##")
Q_QML_EXPORT bool validateLookupSignature(QQmlEngine *engine, QV4::CompiledData::CompilationUnit *cu, const Lookup &lookup, const Signature &signature)
Definition qqml.cpp:3446
QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key, QTypeRevision defaultValue=QTypeRevision())
QObject * createParent(QObject *p)
A *(*)(QObject *) QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:52
constexpr QtPrivate::QMetaTypeInterface metaTypeForNamespace(const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
void(*)(void *, void *) CreateIntoFunction
std::is_same< T, typename QmlMarkerFunction< Marker >::ClassType > QmlTypeHasMarker
QObject * createSingletonInstance(QQmlEngine *q, QJSEngine *j)
void Q_QML_EXPORT qmlRegisterTypeAndRevisions< QQmlTypeNotAvailable, void >(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *, bool)
Definition qqml.cpp:1123
static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset=-1)
void createInto(void *memory, void *)
void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds)
Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type)
Definition qqml.cpp:173
@ CompositeSingletonRegistration
@ SingletonRegistration
@ SequentialContainerRegistration
@ SequentialContainerAndRevisionsRegistration
@ QmlUnitCacheHookRegistration
@ CompositeRegistration
@ SingletonAndRevisionsRegistration
@ InterfaceRegistration
@ AutoParentRegistration
@ TypeAndRevisionsRegistration
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
@ UnconstructibleSingleton
constexpr SingletonConstructionMode singletonConstructionMode()
const QMetaObject * attachedPropertiesMetaObject()
const char * classInfo(const QMetaObject *metaObject, const char *key)
void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *extension)
bool boolClassInfo(const QMetaObject *metaObject, const char *key, bool defaultValue=false)
void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *extension, bool forceAnonymous=false)
Combined button and popup list for selecting options.
bool(*)(QQmlEngine *engine, CompilationUnit *cu) LookupValidationFn
Definition qqmlprivate.h:62
DECLARE_HEAP_OBJECT(DynamicFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(BoundFunction, JavaScriptFunctionObject)
DECLARE_HEAP_OBJECT(ConstructorFunction, ScriptFunction)
DECLARE_HEAP_OBJECT(FunctionObject, Object)
DECLARE_HEAP_OBJECT(JavaScriptFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(MemberFunction, ArrowFunction)
DECLARE_HEAP_OBJECT(ScriptFunction, ArrowFunction)
Definition qjsvalue.h:24
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
void(* IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *)
Definition qqmlprivate.h:67
size_t qHash(QByteArrayView key, size_t seed) noexcept
Definition qhash.cpp:876
QQmlCustomParser * qmlCreateCustomParser()
Definition qqmlprivate.h:97
QV4::ExecutionEngine * QQmlV4ExecutionEnginePtr
Definition qqmlprivate.h:94
QQmlV4Function * QQmlV4FunctionPtr
Definition qqmlprivate.h:93
DEFINE_OBJECT_VTABLE(SharedArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBuffer)
DEFINE_OBJECT_VTABLE(SharedArrayBuffer)
#define V4_NEEDS_DESTROY
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
#define RETURN_UNDEFINED()
void(* functionPtr)(const AOTCompiledContext *context, void **argv)
void(* signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes)
friend bool comparesEqual(const Lookup &lhs, const Lookup &rhs) noexcept
friend bool comparesEqual(const Type &lhs, const Type &rhs) noexcept
virtual ~AOTTrackedLocalsStorage()=default
virtual void markObjects(QV4::MarkStack *markStack) const =0
QV4::CompiledData::LookupValidationFn validateLookupSignatures
const AOTCompiledFunction * aotCompiledFunctions
const QV4::CompiledData::Unit * qmlData
static const QMetaObject * staticMetaObject()
static constexpr const CreateParentFunction createParent
static constexpr bool value
static constexpr bool Value
static QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
static const QMetaObject * staticMetaObject()
static Func attachedPropertiesFunc()
static const QMetaObject * staticMetaObject()
static constexpr const QMetaObject * metaObject()
static constexpr bool Value
static constexpr QMetaSequence sequence()
static constexpr QMetaType self()
static constexpr bool hasAcceptableCtors()
static constexpr QMetaType list()
static constexpr int size()
static constexpr QMetaType list()
static constexpr QMetaSequence sequence()
static constexpr QMetaType self()
static constexpr bool hasAcceptableCtors()
static constexpr int size()
static constexpr bool Value
static constexpr bool Value
static constexpr bool Value
QmlUnitCacheLookupFunction lookupCachedQmlUnit
std::function< QObject *(QQmlEngine *, QJSEngine *)> qObjectApi
std::function< QObject *(QQmlEngine *, QJSEngine *)> qObjectApi
QObject *(* extensionObjectCreate)(QObject *)
std::function< QJSValue(QQmlEngine *, QJSEngine *)> scriptApi
const QMetaObject * extensionMetaObject
const QMetaObject * instanceMetaObject
QObject *(* extensionObjectCreate)(QObject *)
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunction
QVariant(* createValueType)(const QJSValue &)
const QMetaObject * extensionMetaObject
const QMetaObject * classInfoMetaObject
const QMetaObject * attachedPropertiesMetaObject
QQmlCustomParser * customParser
void(* create)(void *, void *)
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunction
QVariant(* createValueType)(const QJSValue &)
const QMetaObject * extensionMetaObject
QObject *(* extensionObjectCreate)(QObject *)
const QMetaObject * metaObject
const QMetaObject * attachedPropertiesMetaObject
bool has(StructVersion v) const
ValueTypeCreationMethod creationMethod
static no_type checkType(...)
static yes_type checkType(To *)
static const QMetaObject * staticMetaObject()
static QVariant create(const QJSValue &params)
static constexpr const CreateValueTypeFunction create
static QVariant create(const QJSValue &params)
static ReturnedValue method_isView(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static void virtualCallWithMetaTypes(const FunctionObject *f, QObject *thisObject, void **a, const QMetaType *types, int argc)
static ReturnedValue virtualCall(const QV4::FunctionObject *f, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static QQmlRefPointer< ExecutableCompilationUnit > parse(ExecutionEngine *engine, const Value *argv, int argc, Type t=Type_Function)
static ReturnedValue method_bind(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_call(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_hasInstance(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_apply(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name=nullptr)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionEngine *engine, qsizetype index, VTable::Call call)
void init(QV4::ExecutionEngine *engine)
Heap::InternalClass * classForConstructor() const
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc, bool shared)