aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltyperegistrar/qqmltypesclassdescription_p.h
blob: 60aafb948fc53d80bc67961b73b6df27364b8a8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#ifndef QMLTYPESCLASSDESCRIPTION_P_H
#define QMLTYPESCLASSDESCRIPTION_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <private/qmetatypesjsonprocessor_p.h>

#include <QtCore/qstring.h>
#include <QtCore/qcbormap.h>
#include <QtCore/qvector.h>
#include <QtCore/qset.h>
#include <QtCore/qversionnumber.h>

QT_BEGIN_NAMESPACE

struct FoundType
{
    enum Origin {
        Unknown,
        OwnTypes,
        ForeignTypes,
    };

    FoundType() = default;
    FoundType(const MetaType &single, Origin origin);

    MetaType native;
    MetaType javaScript;

    Origin nativeOrigin = Unknown;
    Origin javaScriptOrigin = Unknown;

    operator bool() const { return !native.isEmpty() || !javaScript.isEmpty(); }

    MetaType select(const MetaType &category, QAnyStringView relation) const;

};

struct QmlTypesClassDescription
{
    // All the string views in this class are based on string data in the JSON they are parsed from.
    // You must keep the relevant QCborValues alive while the QmlTypesClassDescription exists.

    MetaType resolvedClass;
    QAnyStringView file;
    QAnyStringView className;
    QList<QAnyStringView> primitiveAliases;
    QList<QAnyStringView> elementNames;
    QAnyStringView defaultProp;
    QAnyStringView parentProp;
    QAnyStringView superClass;
    QAnyStringView attachedType;
    QAnyStringView javaScriptExtensionType;
    QAnyStringView nativeExtensionType;
    QAnyStringView sequenceValueType;
    QAnyStringView accessSemantics;
    QList<QTypeRevision> revisions;
    QTypeRevision addedInRevision;
    QTypeRevision removedInRevision;
    bool isCreatable = true;
    bool isStructured = false;
    bool isSingleton = false;
    bool hasCustomParser = false;
    bool isRootClass = false;
    bool extensionIsJavaScript = false;
    bool extensionIsNamespace = false;
    bool registerEnumClassesScoped = false;
    QList<QAnyStringView> implementsInterfaces;
    QList<QAnyStringView> deferredNames;
    QList<QAnyStringView> immediateNames;

    enum CollectMode {
        TopLevel,
        SuperClass,
        RelatedType
    };

    void collect(
            const MetaType &classDef, const QVector<MetaType> &types,
            const QVector<MetaType> &foreign, CollectMode mode, QTypeRevision defaultRevision);
    FoundType collectRelated(
            QAnyStringView related, const QVector<MetaType> &types,
            const QVector<MetaType> &foreign, QTypeRevision defaultRevision,
            const QList<QAnyStringView> &namespaces);

    static FoundType findType(
            const QVector<MetaType> &types, const QVector<MetaType> &foreign,
            const QAnyStringView &name, const QList<QAnyStringView> &namespaces);

    void collectLocalAnonymous(
            const MetaType &classDef, const QVector<MetaType> &types,
            const QVector<MetaType> &foreign, QTypeRevision defaultRevision);


private:
    void collectSuperClasses(
            const MetaType &classDef, const QVector<MetaType> &types,
            const QVector<MetaType> &foreign, CollectMode mode, QTypeRevision defaultRevision);
    void collectInterfaces(const MetaType &classDef);
};

struct ResolvedTypeAlias
{
    ResolvedTypeAlias(QAnyStringView alias);

    QAnyStringView type;
    bool isList = false;
    bool isPointer = false;
    bool isConstant = false;
};

QT_END_NAMESPACE
#endif // QMLTYPESCLASSDESCRIPTION_P_H