| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQml module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QQMLDIRPARSER_P_H |
| 41 | #define QQMLDIRPARSER_P_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include <QtCore/QUrl> |
| 55 | #include <QtCore/QHash> |
| 56 | #include <QtCore/QDebug> |
| 57 | #include <private/qtqmlcompilerglobal_p.h> |
| 58 | #include <private/qqmljsengine_p.h> |
| 59 | #include <private/qqmljsdiagnosticmessage_p.h> |
| 60 | |
| 61 | QT_BEGIN_NAMESPACE |
| 62 | |
| 63 | class QQmlEngine; |
| 64 | class Q_QMLCOMPILER_PRIVATE_EXPORT QQmlDirParser |
| 65 | { |
| 66 | public: |
| 67 | void clear(); |
| 68 | bool parse(const QString &source); |
| 69 | |
| 70 | bool hasError() const; |
| 71 | void setError(const QQmlJS::DiagnosticMessage &); |
| 72 | QList<QQmlJS::DiagnosticMessage> errors(const QString &uri) const; |
| 73 | |
| 74 | QString typeNamespace() const; |
| 75 | void setTypeNamespace(const QString &s); |
| 76 | |
| 77 | static void checkNonRelative(const char *item, const QString &typeName, const QString &fileName) |
| 78 | { |
| 79 | if (fileName.startsWith(c: QLatin1Char('/'))) { |
| 80 | qWarning() << item << typeName |
| 81 | << "is specified with non-relative URL" << fileName << "in a qmldir file." |
| 82 | << "URLs in qmldir files should be relative to the qmldir file's directory." ; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | struct Plugin |
| 87 | { |
| 88 | Plugin() = default; |
| 89 | |
| 90 | Plugin(const QString &name, const QString &path) |
| 91 | : name(name), path(path) |
| 92 | { |
| 93 | checkNonRelative(item: "Plugin" , typeName: name, fileName: path); |
| 94 | } |
| 95 | |
| 96 | QString name; |
| 97 | QString path; |
| 98 | }; |
| 99 | |
| 100 | struct Component |
| 101 | { |
| 102 | Component() = default; |
| 103 | |
| 104 | Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion) |
| 105 | : typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion), |
| 106 | internal(false), singleton(false) |
| 107 | { |
| 108 | checkNonRelative(item: "Component" , typeName, fileName); |
| 109 | } |
| 110 | |
| 111 | QString typeName; |
| 112 | QString fileName; |
| 113 | int majorVersion = 0; |
| 114 | int minorVersion = 0; |
| 115 | bool internal = false; |
| 116 | bool singleton = false; |
| 117 | }; |
| 118 | |
| 119 | struct Script |
| 120 | { |
| 121 | Script() = default; |
| 122 | |
| 123 | Script(const QString &nameSpace, const QString &fileName, int majorVersion, int minorVersion) |
| 124 | : nameSpace(nameSpace), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion) |
| 125 | { |
| 126 | checkNonRelative(item: "Script" , typeName: nameSpace, fileName); |
| 127 | } |
| 128 | |
| 129 | QString nameSpace; |
| 130 | QString fileName; |
| 131 | int majorVersion = 0; |
| 132 | int minorVersion = 0; |
| 133 | }; |
| 134 | |
| 135 | QMultiHash<QString,Component> components() const; |
| 136 | QHash<QString,Component> dependencies() const; |
| 137 | QStringList imports() const; |
| 138 | QList<Script> scripts() const; |
| 139 | QList<Plugin> plugins() const; |
| 140 | bool designerSupported() const; |
| 141 | |
| 142 | struct TypeInfo |
| 143 | { |
| 144 | TypeInfo() = default; |
| 145 | TypeInfo(const QString &fileName) |
| 146 | : fileName(fileName) {} |
| 147 | |
| 148 | QString fileName; |
| 149 | }; |
| 150 | |
| 151 | QList<TypeInfo> typeInfos() const; |
| 152 | |
| 153 | QString className() const; |
| 154 | |
| 155 | private: |
| 156 | bool maybeAddComponent(const QString &typeName, const QString &fileName, const QString &version, QHash<QString,Component> &hash, int lineNumber = -1, bool multi = true); |
| 157 | void reportError(quint16 line, quint16 column, const QString &message); |
| 158 | |
| 159 | private: |
| 160 | QList<QQmlJS::DiagnosticMessage> _errors; |
| 161 | QString _typeNamespace; |
| 162 | QMultiHash<QString,Component> _components; |
| 163 | QHash<QString,Component> _dependencies; |
| 164 | QStringList _imports; |
| 165 | QList<Script> _scripts; |
| 166 | QList<Plugin> _plugins; |
| 167 | bool _designerSupported = false; |
| 168 | QList<TypeInfo> _typeInfos; |
| 169 | QString _className; |
| 170 | }; |
| 171 | |
| 172 | using QQmlDirComponents = QMultiHash<QString,QQmlDirParser::Component>; |
| 173 | using QQmlDirScripts = QList<QQmlDirParser::Script>; |
| 174 | using QQmlDirPlugins = QList<QQmlDirParser::Plugin>; |
| 175 | |
| 176 | QDebug &operator<< (QDebug &, const QQmlDirParser::Component &); |
| 177 | QDebug &operator<< (QDebug &, const QQmlDirParser::Script &); |
| 178 | |
| 179 | QT_END_NAMESPACE |
| 180 | |
| 181 | #endif // QQMLDIRPARSER_P_H |
| 182 | |