Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmljsimporter_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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 QQMLJSIMPORTER_P_H
5#define QQMLJSIMPORTER_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 <private/qtqmlcompilerexports_p.h>
18
19#include "qqmljsscope_p.h"
21#include <QtQml/private/qqmldirparser_p.h>
22
23#include <memory>
24
26
28class QQmlJSLogger;
29class Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSImporter
30{
31public:
33
35 bool useOptionalImports = false);
36
37 QQmlJSResourceFileMapper *resourceFileMapper() const { return m_mapper; }
39
40 QQmlJSResourceFileMapper *metaDataMapper() const { return m_metaDataMapper; }
42
43 ImportedTypes importBuiltins();
44 void importQmldirs(const QStringList &qmltypesFiles);
45
46 QQmlJSScope::Ptr importFile(const QString &file);
47 ImportedTypes importDirectory(const QString &directory, const QString &prefix = QString());
48
49 // ### qmltc needs this. once re-written, we no longer need to expose this
50 QHash<QString, QQmlJSScope::Ptr> importedFiles() const { return m_importedFiles; }
51
52 ImportedTypes importModule(const QString &module, const QString &prefix = QString(),
53 QTypeRevision version = QTypeRevision(),
54 QStringList *staticModuleList = nullptr);
55
56 ImportedTypes builtinInternalNames();
57
59 {
60 const auto result = std::move(m_warnings);
61 m_warnings.clear();
62 return result;
63 }
64
66 {
67 const auto result = std::move(m_globalWarnings);
68 m_globalWarnings.clear();
69 return result;
70 }
71
72 QStringList importPaths() const { return m_importPaths; }
73 void setImportPaths(const QStringList &importPaths);
74
75 void clearCache();
76
77 QQmlJSScope::ConstPtr jsGlobalObject() const;
78
79 std::unique_ptr<QQmlJSImportVisitor>
80 makeImportVisitor(const QQmlJSScope::Ptr &target, QQmlJSImporter *importer,
81 QQmlJSLogger *logger, const QString &implicitImportDirectory,
82 const QStringList &qmldirFiles = QStringList());
85 const QString &, const QStringList &);
86 void setImportVisitorCreator(ImportVisitorCreator create) { m_createImportVisitor = create; }
87
88private:
89 friend class QDeferredFactory<QQmlJSScope>;
90
91 struct AvailableTypes
92 {
93 AvailableTypes(ImportedTypes builtins)
94 : cppNames(std::move(builtins))
95 , qmlNames(QQmlJSScope::ContextualTypes::QML, {}, cppNames.arrayType())
96 {
97 }
98
99 // C++ names used in qmltypes files for non-composite types
100 ImportedTypes cppNames;
101
102 // Names the importing component sees, including any prefixes
103 ImportedTypes qmlNames;
104
105 // Static modules included here
106 QStringList staticModules;
107
108 // Whether a system module has been imported
109 bool hasSystemModule = false;
110 };
111
112 struct Import {
114 bool isStaticModule = false;
115 bool isSystemModule = false;
116
120 QList<QQmlDirParser::Import> dependencies;
121 };
122
123 AvailableTypes builtinImportHelper();
124 bool importHelper(const QString &module, AvailableTypes *types,
125 const QString &prefix = QString(), QTypeRevision version = QTypeRevision(),
126 bool isDependency = false, bool isFile = false);
127 void processImport(const QQmlJSScope::Import &importDescription, const Import &import,
128 AvailableTypes *types);
129 void importDependencies(const QQmlJSImporter::Import &import, AvailableTypes *types,
130 const QString &prefix = QString(),
131 QTypeRevision version = QTypeRevision(), bool isDependency = false);
132 void readQmltypes(const QString &filename, QList<QQmlJSExportedScope> *objects,
133 QList<QQmlDirParser::Import> *dependencies);
134 Import readQmldir(const QString &dirname);
135 Import readDirectory(const QString &directory);
136
137 QQmlJSScope::Ptr localFile2ScopeTree(const QString &filePath);
138 static void setQualifiedNamesOn(const Import &import);
139
140 QStringList m_importPaths;
141
144 QHash<QString, Import> m_seenQmldirFiles;
145
146 QHash<QString, QQmlJSScope::Ptr> m_importedFiles;
147 QList<QQmlJS::DiagnosticMessage> m_globalWarnings;
149 std::optional<AvailableTypes> m_builtins;
150
151 QQmlJSResourceFileMapper *m_mapper = nullptr;
152 QQmlJSResourceFileMapper *m_metaDataMapper = nullptr;
153 bool m_useOptionalImports;
154
155 ImportVisitorCreator m_createImportVisitor = nullptr;
156};
157
159
160#endif // QQMLJSIMPORTER_P_H
\inmodule QtCore
Definition qhash.h:818
Definition qlist.h:74
QQmlJSImportVisitor *(*)(const QQmlJSScope::Ptr &, QQmlJSImporter *, QQmlJSLogger *, const QString &, const QStringList &) ImportVisitorCreator
QStringList importPaths() const
QHash< QString, QQmlJSScope::Ptr > importedFiles() const
QList< QQmlJS::DiagnosticMessage > takeWarnings()
QList< QQmlJS::DiagnosticMessage > takeGlobalWarnings()
void setMetaDataMapper(QQmlJSResourceFileMapper *mapper)
void setResourceFileMapper(QQmlJSResourceFileMapper *mapper)
QQmlJSResourceFileMapper * resourceFileMapper() const
QQmlJSResourceFileMapper * metaDataMapper() const
Tracks the types for the QmlCompiler.
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
Combined button and popup list for selecting options.
GLsizei GLenum GLenum * types
GLenum target
GLuint name
GLuint64EXT * result
[6]
QFile file
[0]
QDataWidgetMapper * mapper
[0]
view create()