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
qqmljscontextualtypes_p.h
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
5#ifndef QQMLJSCONTEXTUALTYPES_P_H
6#define QQMLJSCONTEXTUALTYPES_P_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#include <QtCore/qstring.h>
19#include <QtCore/qhash.h>
20#include <private/qqmljsscope_p.h>
21
22#include <QtCore/qtyperevision.h>
23
24#include <optional>
25
26QT_BEGIN_NAMESPACE
27
28namespace QQmlJS {
29
30// note: like QQmlImportInstance::Precedence, except that inline components are 0 and
31// "Precedence::Highest" is 1 instead of 0.
37
39{
41 ContextualType(const ImportedScope<QQmlJSScope::ConstPtr> &type, quint8 precedence)
43 {
44 }
45 ContextualType(const QQmlJSScope::ConstPtr &type, QTypeRevision revision, quint8 precedence)
47 {
48 }
50};
61
62/*! \internal
63 * Maps type names to types and the compile context of the types. The context can be
64 * INTERNAL (for c++ and synthetic jsrootgen types) or QML (for qml types).
65 */
67{
69
71 CompileContext context,
72 const QHash<QString, ContextualType> &types,
73 const QMultiHash<QQmlJSScope::ConstPtr, QString> &names,
74 const QQmlJSScope::ConstPtr &arrayType)
75 : m_types(types)
76 , m_names(names)
77 , m_context(context)
79 {}
80
81 CompileContext context() const { return m_context; }
82 QQmlJSScope::ConstPtr arrayType() const { return m_arrayType; }
83
84 bool hasType(const QString &name) const { return m_types.contains(name); }
85
86 ContextualType type(const QString &name) const { return m_types[name]; }
87 QString name(const QQmlJSScope::ConstPtr &type) const { return m_names[type]; }
88
89 void setType(const QString &name, const ContextualType &type);
90 void setFileSelectedType(const QString &fileSelector, const QString &name,
91 const ContextualType &type);
92 void clearType(const QString &name)
93 {
94 auto &scope = m_types[name].scope;
95 auto it = m_names.find(scope);
96 while (it != m_names.end() && it.key() == scope)
97 it = m_names.erase(it);
98 scope = QQmlJSScope::ConstPtr();
99 }
100
101 bool isNullType(const QString &name) const
102 {
103 const auto it = m_types.constFind(name);
104 return it != m_types.constEnd() && it->scope.isNull();
105 }
106
107 void addTypes(const ContextualTypes &types)
108 {
109 Q_ASSERT(types.m_context == m_context);
110 for (auto it = types.m_types.cbegin(), end = types.m_types.cend(); it != end; ++it) {
111 setType(it.key(), it.value());
112 }
113 for (auto it = types.m_fileSelectedTypes.cbegin(), end = types.m_fileSelectedTypes.cend();
114 it != end; ++it) {
115 setFileSelectedType(it->fileSelector, it.key(), it->type);
116 }
117 }
118
119 const QHash<QString, ContextualType> &types() const { return m_types; }
120 auto fileSelectionsEqualRange(const QString &name) const
121 {
122 return m_fileSelectedTypes.equal_range(name);
123 }
124 bool hasFileSelectors() const { return m_fileSelectedTypes.size() > 0; }
125 Q_QMLCOMPILER_EXPORT FileSelectorInfo
127 const auto &names() const { return m_names; }
128
129 // Selector of the file currently being analysed
130 QString currentFileSelector() const { return m_currentFileSelector; }
131 void setCurrentFileSelector(const QString &selector) { m_currentFileSelector = selector; }
132 std::optional<ContextualType>
133 fileSelectedTypeFor(const QString &name, const QString &selector) const;
134
136 {
137 m_names.clear();
138 m_types.clear();
139 }
140
141private:
142 QHash<QString, ContextualType> m_types;
143 QMultiHash<QString, FileSelectedType> m_fileSelectedTypes;
144 QMultiHash<QQmlJSScope::ConstPtr, QString> m_names;
145 QString m_currentFileSelector;
146 CompileContext m_context;
147
148 // For resolving sequence types
149 QQmlJSScope::ConstPtr m_arrayType;
150};
151}
152
153QT_END_NAMESPACE
154
155#endif // QQMLJSCONTEXTUALTYPES_P_H
Combined button and popup list for selecting options.
ContextualType(const QQmlJSScope::ConstPtr &type, QTypeRevision revision, quint8 precedence)
ContextualType(const ImportedScope< QQmlJSScope::ConstPtr > &type, quint8 precedence)
std::optional< ContextualType > fileSelectedTypeFor(const QString &name, const QString &selector) const
ContextualType type(const QString &name) const
const QHash< QString, ContextualType > & types() const
QString name(const QQmlJSScope::ConstPtr &type) const
void addTypes(const ContextualTypes &types)
auto fileSelectionsEqualRange(const QString &name) const
CompileContext context() const
bool isNullType(const QString &name) const
ContextualTypes(CompileContext context, const QHash< QString, ContextualType > &types, const QMultiHash< QQmlJSScope::ConstPtr, QString > &names, const QQmlJSScope::ConstPtr &arrayType)
void setCurrentFileSelector(const QString &selector)
bool hasType(const QString &name) const
void setType(const QString &name, const ContextualType &type)
QQmlJSScope::ConstPtr arrayType() const
void setFileSelectedType(const QString &fileSelector, const QString &name, const ContextualType &type)
void clearType(const QString &name)
QList< FileSelectedType > fileSelectedTypes