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