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
qqmldirparser_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 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 QQMLDIRPARSER_P_H
5#define QQMLDIRPARSER_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 <QtCore/QUrl>
19#include <QtCore/QHash>
20#include <QtCore/QDebug>
21#include <QtCore/QTypeRevision>
22#include <private/qtqmlcompilerglobal_p.h>
23#include <private/qqmljsdiagnosticmessage_p.h>
24
25QT_BEGIN_NAMESPACE
26
27class QQmlEngine;
28class Q_QML_COMPILER_EXPORT QQmlDirParser
29{
30public:
31 void clear();
32 bool parse(const QString &source);
33 void disambiguateFileSelectors();
34
35 bool hasError() const { return !_errors.isEmpty(); }
36 void setError(const QQmlJS::DiagnosticMessage &);
37 QList<QQmlJS::DiagnosticMessage> errors(const QString &uri) const;
38
39 bool hasTypeNamespace() const { return !_typeNamespace.isEmpty(); }
40 QString typeNamespace() const { return _typeNamespace; }
41 void setTypeNamespace(const QString &s) { _typeNamespace = s; }
42
43 static void checkNonRelative(const char *item, const QString &typeName, const QString &fileName)
44 {
45 if (fileName.startsWith(QLatin1Char('/'))) {
46 qWarning() << item << typeName
47 << "is specified with non-relative URL" << fileName << "in a qmldir file."
48 << "URLs in qmldir files should be relative to the qmldir file's directory.";
49 }
50 }
51
52 struct Plugin
53 {
54 Plugin() = default;
55
56 Plugin(const QString &name, const QString &path, bool optional)
57 : name(name), path(path), optional(optional)
58 {
59 checkNonRelative("Plugin", name, path);
60 }
61
62 QString name;
63 QString path;
64 bool optional = false;
65 };
66
67 struct Component
68 {
69 Component() = default;
70
71 Component(const QString &typeName, const QString &fileName, QTypeRevision version)
72 : typeName(typeName), fileName(fileName), version(version),
73 internal(false), singleton(false)
74 {
75 checkNonRelative("Component", typeName, fileName);
76 }
77
78 QString typeName;
79 QString fileName;
80 QTypeRevision version = QTypeRevision::zero();
81 bool internal = false;
82 bool singleton = false;
83 };
84
85 struct Script
86 {
87 Script() = default;
88
89 Script(const QString &nameSpace, const QString &fileName, QTypeRevision version)
90 : nameSpace(nameSpace), fileName(fileName), version(version)
91 {
92 checkNonRelative("Script", nameSpace, fileName);
93 }
94
95 QString nameSpace;
96 QString fileName;
97 QTypeRevision version = QTypeRevision::zero();
98 };
99
100 struct Import
101 {
102 enum Flag {
103 Default = 0x0,
104 Auto = 0x1, // forward the version of the importing module
105 Optional = 0x2, // is not automatically imported but only a tooling hint
106 OptionalDefault =
107 0x4, // tooling hint only, denotes this entry should be imported by tooling
108 };
109 Q_DECLARE_FLAGS(Flags, Flag)
110
111 Import() = default;
112 Import(QString module, QTypeRevision version, Flags flags)
113 : module(module), version(version), flags(flags)
114 {
115 }
116
117 QString module;
118 QTypeRevision version; // invalid version is latest version, unless Flag::Auto
119 Flags flags;
120
121 friend bool operator==(const Import &a, const Import &b)
122 {
123 return a.module == b.module && a.version == b.version && a.flags == b.flags;
124 }
125 };
126
127 QMultiHash<QString,Component> components() const { return _components; }
128 QList<Import> dependencies() const { return _dependencies; }
129 QList<Import> imports() const { return _imports; }
130 QList<Script> scripts() const { return _scripts; }
131 QList<Plugin> plugins() const { return _plugins; }
132 bool designerSupported() const { return _designerSupported; }
133
134 // A static module has side effects outside the mere importing of types. We shall not warn
135 // about it being being "unused". The builtins are also a static module.
136 bool isStaticModule() const { return _isStaticModule; }
137
138 // A system module includes the JavaScript root object
139 bool isSystemModule() const { return _isSystemModule; }
140
141 QStringList typeInfos() const { return _typeInfos; }
142 QStringList classNames() const { return _classNames; }
143 QString preferredPath() const { return _preferredPath; }
144 QString linkTarget() const { return _linkTarget; }
145
146private:
147 bool maybeAddComponent(const QString &typeName, const QString &fileName, const QString &version, QHash<QString,Component> &hash, int lineNumber = -1, bool multi = true);
148 void reportError(quint16 line, quint16 column, const QString &message);
149 QString scanQuotedWord(const QChar *&ch, quint16 lineNumber, quint16 columnNumber);
150 void insertComponentOrScript(
151 const QString &name, const QString &fileName, QTypeRevision version);
152
153private:
154 QList<QQmlJS::DiagnosticMessage> _errors;
155 QString _typeNamespace;
156 QString _preferredPath;
157 QMultiHash<QString,Component> _components;
158 QList<Import> _dependencies;
159 QList<Import> _imports;
160 QList<Script> _scripts;
161 QList<Plugin> _plugins;
162 bool _designerSupported = false;
163 bool _isStaticModule = false;
164 bool _isSystemModule = false;
165 QStringList _typeInfos;
166 QStringList _classNames;
167 QString _linkTarget;
168};
169
170using QQmlDirComponents = QMultiHash<QString,QQmlDirParser::Component>;
171using QQmlDirScripts = QList<QQmlDirParser::Script>;
172using QQmlDirPlugins = QList<QQmlDirParser::Plugin>;
173using QQmlDirImports = QList<QQmlDirParser::Import>;
174
175QDebug &operator<< (QDebug &, const QQmlDirParser::Component &);
176QDebug &operator<< (QDebug &, const QQmlDirParser::Script &);
177
178QT_END_NAMESPACE
179
180#endif // QQMLDIRPARSER_P_H
static void scanSpace(const QChar *&ch)
static void disambiguateFileSelectedScripts(QQmlDirScripts *scripts)
static QString scanWord(const QChar *&ch)
static QString pathWithoutFileSelectors(QString path, qsizetype firstPlus)
static void disambiguateFileSelectedComponents(QQmlDirComponents *components)
static void scanToEnd(const QChar *&ch)
static QTypeRevision parseVersion(const QString &str)
static bool canDisambiguate(const QString &fileName1, const QString &fileName2, QString *correctedFileName)
static QT_BEGIN_NAMESPACE int parseInt(QStringView str, bool *ok)
QDataStream & operator<<(QDataStream &stream, const QImage &image)
[0]
Definition qimage.cpp:4006