1// Copyright (C) 2020 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
4#ifndef QV4RESOLVEDTYPEREFERNCE_P_H
5#define QV4RESOLVEDTYPEREFERNCE_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 <QtQml/private/qtqmlglobal_p.h>
19#include <QtQml/private/qqmlrefcount_p.h>
20#include <QtQml/private/qqmlpropertycache_p.h>
21#include <QtQml/private/qqmltype_p.h>
22#include <QtQml/private/qv4compileddata_p.h>
23
24QT_BEGIN_NAMESPACE
25
26class QCryptographicHash;
27namespace QV4 {
28
29class ResolvedTypeReference
30{
31 Q_DISABLE_COPY_MOVE(ResolvedTypeReference)
32public:
33 ResolvedTypeReference() = default;
34 ~ResolvedTypeReference()
35 {
36 if (m_stronglyReferencesCompilationUnit && m_compilationUnit)
37 m_compilationUnit->release();
38 }
39
40 QQmlPropertyCache::ConstPtr createPropertyCache();
41 bool addToHash(QCryptographicHash *hash, QHash<quintptr, QByteArray> *checksums);
42
43 void doDynamicTypeCheck();
44
45 QQmlType type() const { return m_type; }
46 void setType(QQmlType type) { m_type = std::move(type); }
47
48 QQmlRefPointer<QV4::CompiledData::CompilationUnit> compilationUnit()
49 {
50 return m_compilationUnit;
51 }
52
53 void setCompilationUnit(QQmlRefPointer<QV4::CompiledData::CompilationUnit> unit)
54 {
55 if (m_compilationUnit == unit.data())
56 return;
57 if (m_stronglyReferencesCompilationUnit) {
58 if (m_compilationUnit)
59 m_compilationUnit->release();
60 m_compilationUnit = unit.take();
61 } else {
62 m_compilationUnit = unit.data();
63 }
64 }
65
66 bool referencesCompilationUnit() const { return m_stronglyReferencesCompilationUnit; }
67 void setReferencesCompilationUnit(bool doReference)
68 {
69 if (doReference == m_stronglyReferencesCompilationUnit)
70 return;
71 m_stronglyReferencesCompilationUnit = doReference;
72 if (!m_compilationUnit)
73 return;
74 if (doReference) {
75 m_compilationUnit->addref();
76 } else if (m_compilationUnit->count() == 1) {
77 m_compilationUnit->release();
78 m_compilationUnit = nullptr;
79 } else {
80 m_compilationUnit->release();
81 }
82 }
83
84 QQmlPropertyCache::ConstPtr typePropertyCache() const { return m_typePropertyCache; }
85 void setTypePropertyCache(QQmlPropertyCache::ConstPtr cache)
86 {
87 m_typePropertyCache = std::move(cache);
88 }
89
90 QTypeRevision version() const { return m_version; }
91 void setVersion(QTypeRevision version) { m_version = version; }
92
93 bool isFullyDynamicType() const { return m_isFullyDynamicType; }
94 void setFullyDynamicType(bool fullyDynamic) { m_isFullyDynamicType = fullyDynamic; }
95
96private:
97 QQmlType m_type;
98 QQmlPropertyCache::ConstPtr m_typePropertyCache;
99 QV4::CompiledData::CompilationUnit *m_compilationUnit = nullptr;
100
101 QTypeRevision m_version = QTypeRevision::zero();
102 // Types such as QQmlPropertyMap can add properties dynamically at run-time and
103 // therefore cannot have a property cache installed when instantiated.
104 bool m_isFullyDynamicType = false;
105 bool m_stronglyReferencesCompilationUnit = true;
106};
107
108} // namespace QV4
109
110QT_END_NAMESPACE
111
112#endif // QV4RESOLVEDTYPEREFERNCE_P_H
113

source code of qtdeclarative/src/qml/jsruntime/qv4resolvedtypereference_p.h