| 1 | // Copyright (C) 2019 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 QMLTYPESCLASSDESCRIPTION_P_H |
| 5 | #define QMLTYPESCLASSDESCRIPTION_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 | |
| 18 | #include <private/qmetatypesjsonprocessor_p.h> |
| 19 | |
| 20 | #include <QtCore/qstring.h> |
| 21 | #include <QtCore/qcbormap.h> |
| 22 | #include <QtCore/qvector.h> |
| 23 | #include <QtCore/qset.h> |
| 24 | #include <QtCore/qversionnumber.h> |
| 25 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | struct FoundType |
| 29 | { |
| 30 | enum Origin { |
| 31 | Unknown, |
| 32 | OwnTypes, |
| 33 | ForeignTypes, |
| 34 | }; |
| 35 | |
| 36 | FoundType() = default; |
| 37 | FoundType(const MetaType &single, Origin origin); |
| 38 | |
| 39 | MetaType native; |
| 40 | MetaType javaScript; |
| 41 | |
| 42 | Origin nativeOrigin = Unknown; |
| 43 | Origin javaScriptOrigin = Unknown; |
| 44 | |
| 45 | operator bool() const { return !native.isEmpty() || !javaScript.isEmpty(); } |
| 46 | |
| 47 | MetaType select(const MetaType &category, QAnyStringView relation) const; |
| 48 | |
| 49 | }; |
| 50 | |
| 51 | struct QmlTypesClassDescription |
| 52 | { |
| 53 | // All the string views in this class are based on string data in the JSON they are parsed from. |
| 54 | // You must keep the relevant QCborValues alive while the QmlTypesClassDescription exists. |
| 55 | |
| 56 | MetaType resolvedClass; |
| 57 | QAnyStringView file; |
| 58 | QAnyStringView className; |
| 59 | QList<QAnyStringView> primitiveAliases; |
| 60 | QList<QAnyStringView> elementNames; |
| 61 | QAnyStringView defaultProp; |
| 62 | QAnyStringView parentProp; |
| 63 | QAnyStringView superClass; |
| 64 | QAnyStringView attachedType; |
| 65 | QAnyStringView javaScriptExtensionType; |
| 66 | QAnyStringView nativeExtensionType; |
| 67 | QAnyStringView sequenceValueType; |
| 68 | QAnyStringView accessSemantics; |
| 69 | QList<QTypeRevision> revisions; |
| 70 | QTypeRevision addedInRevision; |
| 71 | QTypeRevision removedInRevision; |
| 72 | bool isCreatable = true; |
| 73 | bool isStructured = false; |
| 74 | bool isSingleton = false; |
| 75 | bool hasCustomParser = false; |
| 76 | bool isRootClass = false; |
| 77 | bool extensionIsJavaScript = false; |
| 78 | bool extensionIsNamespace = false; |
| 79 | bool enforcesScopedEnums = false; |
| 80 | QList<QAnyStringView> implementsInterfaces; |
| 81 | QList<QAnyStringView> deferredNames; |
| 82 | QList<QAnyStringView> immediateNames; |
| 83 | |
| 84 | enum CollectMode { |
| 85 | TopLevel, |
| 86 | SuperClass, |
| 87 | RelatedType |
| 88 | }; |
| 89 | |
| 90 | void collect( |
| 91 | const MetaType &classDef, const QVector<MetaType> &types, |
| 92 | const QVector<MetaType> &foreign, CollectMode mode, QTypeRevision defaultRevision); |
| 93 | FoundType collectRelated( |
| 94 | QAnyStringView related, const QVector<MetaType> &types, |
| 95 | const QVector<MetaType> &foreign, QTypeRevision defaultRevision, |
| 96 | const QList<QAnyStringView> &namespaces); |
| 97 | |
| 98 | static FoundType findType( |
| 99 | const QVector<MetaType> &types, const QVector<MetaType> &foreign, |
| 100 | const QAnyStringView &name, const QList<QAnyStringView> &namespaces); |
| 101 | |
| 102 | void collectLocalAnonymous( |
| 103 | const MetaType &classDef, const QVector<MetaType> &types, |
| 104 | const QVector<MetaType> &foreign, QTypeRevision defaultRevision); |
| 105 | |
| 106 | |
| 107 | private: |
| 108 | void collectSuperClasses( |
| 109 | const MetaType &classDef, const QVector<MetaType> &types, |
| 110 | const QVector<MetaType> &foreign, CollectMode mode, QTypeRevision defaultRevision); |
| 111 | void collectInterfaces(const MetaType &classDef); |
| 112 | |
| 113 | void handleRegisterEnumClassesUnscoped(const MetaType &classDef, QAnyStringView value); |
| 114 | }; |
| 115 | |
| 116 | struct ResolvedTypeAlias |
| 117 | { |
| 118 | ResolvedTypeAlias(QAnyStringView alias, const QList<UsingDeclaration> &usingDeclarations); |
| 119 | |
| 120 | QAnyStringView type; |
| 121 | bool isList = false; |
| 122 | bool isPointer = false; |
| 123 | bool isConstant = false; |
| 124 | |
| 125 | private: |
| 126 | void handleVoid(); |
| 127 | void handleList(); |
| 128 | void handlePointer(); |
| 129 | void handleConst(); |
| 130 | }; |
| 131 | |
| 132 | QT_END_NAMESPACE |
| 133 | #endif // QMLTYPESCLASSDESCRIPTION_P_H |
| 134 | |