Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
4#ifndef QQMLJSCONTEXTUALTYPES_P_H
5#define QQMLJSCONTEXTUALTYPES_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#include <QtCore/qstring.h>
18#include <QtCore/qhash.h>
19#include <private/qqmljsscope_p.h>
20
22
23namespace QQmlJS {
29{
31
34 const QHash<QString, ImportedScope<QQmlJSScope::ConstPtr>> types,
36 : m_types(types)
37 , m_context(context)
38 , m_arrayType(arrayType)
39 {}
40
41 CompileContext context() const { return m_context; }
42 QQmlJSScope::ConstPtr arrayType() const { return m_arrayType; }
43
44 bool hasType(const QString &name) const { return m_types.contains(name); }
45
46 ImportedScope<QQmlJSScope::ConstPtr> type(const QString &name) const { return m_types[name]; }
47 QString name(const QQmlJSScope::ConstPtr &type) const { return m_names[type]; }
48
49 void setType(const QString &name, const ImportedScope<QQmlJSScope::ConstPtr> &type)
50 {
51 if (!name.startsWith(u'$'))
52 m_names.insert(type.scope, name);
53 m_types.insert(name, type);
54 }
55 void clearType(const QString &name)
56 {
57 auto &scope = m_types[name].scope;
58 auto it = m_names.constFind(scope);
59 while (it != m_names.constEnd() && it.key() == scope)
60 it = m_names.erase(it);
61 scope = QQmlJSScope::ConstPtr();
62 }
63
64 bool isNullType(const QString &name) const
65 {
66 const auto it = m_types.constFind(name);
67 return it != m_types.constEnd() && it->scope.isNull();
68 }
69
71 {
72 Q_ASSERT(types.m_context == m_context);
73 insertNames(types);
74 m_types.insert(std::move(types.m_types));
75 }
76
78 {
79 Q_ASSERT(types.m_context == m_context);
80 insertNames(types);
81 m_types.insert(types.m_types);
82 }
83
84 const QHash<QString, ImportedScope<QQmlJSScope::ConstPtr>> &types() const { return m_types; }
85
87 {
88 m_names.clear();
89 m_types.clear();
90 }
91
92private:
93 void insertNames(const ContextualTypes &types) {
94 for (auto it = types.m_types.constBegin(), end = types.m_types.constEnd();
95 it != end; ++it) {
96 const QString &name = it.key();
97 if (!name.startsWith(u'$'))
98 m_names.insert(it->scope, name);
99 }
100 }
101
102 QHash<QString, ImportedScope<QQmlJSScope::ConstPtr>> m_types;
103 QMultiHash<QQmlJSScope::ConstPtr, QString> m_names;
104 CompileContext m_context;
105
106 // For resolving sequence types
107 QQmlJSScope::ConstPtr m_arrayType;
108};
109}
110
112
113#endif // QQMLJSCONTEXTUALTYPES_P_H
\inmodule QtCore
Definition qhash.h:820
QDeferredSharedPointer< const QQmlJSScope > ConstPtr
const_iterator constBegin() const noexcept
Definition qset.h:139
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QSet< QString >::iterator it
Combined button and popup list for selecting options.
GLuint GLuint end
GLsizei GLenum GLenum * types
GLenum type
GLuint name
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QString name(const QQmlJSScope::ConstPtr &type) const
const QHash< QString, ImportedScope< QQmlJSScope::ConstPtr > > & types() const
void addTypes(ContextualTypes &&types)
void addTypes(const ContextualTypes &types)
CompileContext context() const
bool isNullType(const QString &name) const
ImportedScope< QQmlJSScope::ConstPtr > type(const QString &name) const
bool hasType(const QString &name) const
ContextualTypes(CompileContext context, const QHash< QString, ImportedScope< QQmlJSScope::ConstPtr > > types, const QQmlJSScope::ConstPtr &arrayType)
QQmlJSScope::ConstPtr arrayType() const
void setType(const QString &name, const ImportedScope< QQmlJSScope::ConstPtr > &type)
void clearType(const QString &name)