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/qv4executablecompilationunit_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 propertyCache() const;
41 QQmlPropertyCache::ConstPtr createPropertyCache();
42 bool addToHash(QCryptographicHash *hash, QHash<quintptr, QByteArray> *checksums);
43
44 void doDynamicTypeCheck();
45
46 QQmlType type() const { return m_type; }
47 void setType(QQmlType type) { m_type = std::move(type); }
48
49 QQmlRefPointer<QV4::ExecutableCompilationUnit> compilationUnit() { return m_compilationUnit; }
50 void setCompilationUnit(QQmlRefPointer<QV4::ExecutableCompilationUnit> unit)
51 {
52 if (m_compilationUnit == unit.data())
53 return;
54 if (m_stronglyReferencesCompilationUnit) {
55 if (m_compilationUnit)
56 m_compilationUnit->release();
57 m_compilationUnit = unit.take();
58 } else {
59 m_compilationUnit = unit.data();
60 }
61 }
62
63 bool referencesCompilationUnit() const { return m_stronglyReferencesCompilationUnit; }
64 void setReferencesCompilationUnit(bool doReference)
65 {
66 if (doReference == m_stronglyReferencesCompilationUnit)
67 return;
68 m_stronglyReferencesCompilationUnit = doReference;
69 if (!m_compilationUnit)
70 return;
71 if (doReference) {
72 m_compilationUnit->addref();
73 } else if (m_compilationUnit->count() == 1) {
74 m_compilationUnit->release();
75 m_compilationUnit = nullptr;
76 } else {
77 m_compilationUnit->release();
78 }
79 }
80
81 QQmlPropertyCache::ConstPtr typePropertyCache() const { return m_typePropertyCache; }
82 void setTypePropertyCache(QQmlPropertyCache::ConstPtr cache)
83 {
84 m_typePropertyCache = std::move(cache);
85 }
86
87 QTypeRevision version() const { return m_version; }
88 void setVersion(QTypeRevision version) { m_version = version; }
89
90 bool isFullyDynamicType() const { return m_isFullyDynamicType; }
91 void setFullyDynamicType(bool fullyDynamic) { m_isFullyDynamicType = fullyDynamic; }
92
93private:
94 QQmlType m_type;
95 QQmlPropertyCache::ConstPtr m_typePropertyCache;
96 QV4::ExecutableCompilationUnit *m_compilationUnit = nullptr;
97
98 QTypeRevision m_version = QTypeRevision::zero();
99 // Types such as QQmlPropertyMap can add properties dynamically at run-time and
100 // therefore cannot have a property cache installed when instantiated.
101 bool m_isFullyDynamicType = false;
102 bool m_stronglyReferencesCompilationUnit = true;
103};
104
105} // namespace QV4
106
107QT_END_NAMESPACE
108
109#endif // QV4RESOLVEDTYPEREFERNCE_P_H
110

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