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
22QT_BEGIN_NAMESPACE
23
24namespace QQmlJS {
25/*! \internal
26 * Maps type names to types and the compile context of the types. The context can be
27 * INTERNAL (for c++ and synthetic jsrootgen types) or QML (for qml types).
28 */
30{
32
43
44 CompileContext context() const { return m_context; }
45 QQmlJSScope::ConstPtr arrayType() const { return m_arrayType; }
46
47 bool hasType(const QString &name) const { return m_types.contains(name); }
48
49 ImportedScope<QQmlJSScope::ConstPtr> type(const QString &name) const { return m_types[name]; }
50 QString name(const QQmlJSScope::ConstPtr &type) const { return m_names[type]; }
51
52 void setType(const QString &name, const ImportedScope<QQmlJSScope::ConstPtr> &type)
53 {
54 if (!name.startsWith(u'$'))
55 m_names.insert(type.scope, name);
56 m_types.insert(name, type);
57 }
58 void clearType(const QString &name)
59 {
60 auto &scope = m_types[name].scope;
61 auto it = m_names.find(scope);
62 while (it != m_names.end() && it.key() == scope)
63 it = m_names.erase(it);
64 scope = QQmlJSScope::ConstPtr();
65 }
66
67 bool isNullType(const QString &name) const
68 {
69 const auto it = m_types.constFind(name);
70 return it != m_types.constEnd() && it->scope.isNull();
71 }
72
74 {
75 Q_ASSERT(types.m_context == m_context);
76 insertNames(types);
77 m_types.insert(std::move(types.m_types));
78 }
79
80 void addTypes(const ContextualTypes &types)
81 {
82 Q_ASSERT(types.m_context == m_context);
83 insertNames(types);
84 m_types.insert(types.m_types);
85 }
86
88 const auto &names() const { return m_names; }
89
91 {
92 m_names.clear();
93 m_types.clear();
94 }
95
96private:
97 void insertNames(const ContextualTypes &types) {
99 it != end; ++it) {
100 const QString &name = it.key();
101 if (!name.startsWith(u'$'))
103 }
104 }
105
107 QMultiHash<QQmlJSScope::ConstPtr, QString> m_names;
108 CompileContext m_context;
109
110 // For resolving sequence types
111 QQmlJSScope::ConstPtr m_arrayType;
112};
113}
114
115QT_END_NAMESPACE
116
117#endif // QQMLJSCONTEXTUALTYPES_P_H
friend bool operator==(const Import &a, const Import &b)
QString prefix() const
bool isValid() const
QTypeRevision version() const
QString name() const
bool isDependency() const
Import()=default
bool isFile() const
friend size_t qHash(const Import &key, size_t seed=0) noexcept
Import(QString prefix, QString name, QTypeRevision version, bool isFile, bool isDependency)
static QStringList aliases(const QQmlJSScope::ConstPtr &scope)
static const QLatin1String JsrootDotQmltypes
static bool isVersionAllowed(const QQmlJSScope::Export &exportEntry, const QQmlJS::Import &importDescription)
static bool isComposite(const QQmlJSScope::ConstPtr &scope)
static QString resolvePreferredPath(const QString &qmldirPath, const QString &prefer, QQmlJSResourceFileMapper *mapper)
static const QString prefixedName(const QString &prefix, const QString &name)
static const QLatin1String SlashQmldir
static QString internalName(const QQmlJSScope::ConstPtr &scope)
static bool fileSelectedScopesAreCompatibleHeuristic(const QQmlJSScope::ConstPtr &scope1, const QQmlJSScope::ConstPtr &scope2)
static const QLatin1String PluginsDotQmltypes
QQmlJSImporterFlag
@ UseOptionalImports
@ PreferQmlFilesFromSourceFolder
@ TolerateFileSelectors
QString name(const QQmlJSScope::ConstPtr &type) const
void addTypes(ContextualTypes &&types)
void addTypes(const ContextualTypes &types)
ContextualTypes(CompileContext context, const QHash< QString, ImportedScope< QQmlJSScope::ConstPtr > > &types, const QMultiHash< QQmlJSScope::ConstPtr, QString > &names, const QQmlJSScope::ConstPtr &arrayType)
CompileContext context() const
bool isNullType(const QString &name) const
ImportedScope< QQmlJSScope::ConstPtr > type(const QString &name) const
bool hasType(const QString &name) const
QQmlJSScope::ConstPtr arrayType() const
void setType(const QString &name, const ImportedScope< QQmlJSScope::ConstPtr > &type)
void clearType(const QString &name)