2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2021 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2010-03-18 12:06:43 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-03-18 12:06:43 +01:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// W A R N I N G
|
|
|
|
|
// -------------
|
|
|
|
|
//
|
|
|
|
|
// This file is not part of the Qt API. It exists purely as an
|
|
|
|
|
// implementation detail. This header file may change from version to
|
|
|
|
|
// version without notice, or even be removed.
|
|
|
|
|
//
|
|
|
|
|
// We mean it.
|
|
|
|
|
//
|
|
|
|
|
|
2012-07-31 10:12:26 +02:00
|
|
|
#include <QtCore/QUrl>
|
|
|
|
|
#include <QtCore/QHash>
|
|
|
|
|
#include <QtCore/QDebug>
|
2020-11-26 07:32:29 +01:00
|
|
|
|
|
|
|
|
#include <languageutils/componentversion.h>
|
|
|
|
|
|
2020-02-28 17:51:32 +01:00
|
|
|
#include "qmljs/parser/qmljsglobal_p.h"
|
|
|
|
|
#include "qmljs/parser/qmljsengine_p.h"
|
|
|
|
|
#include "qmljs/parser/qmljsdiagnosticmessage_p.h"
|
2012-08-01 07:48:37 +02:00
|
|
|
|
2020-02-28 17:51:32 +01:00
|
|
|
QT_QML_BEGIN_NAMESPACE
|
2010-03-18 12:06:43 +01:00
|
|
|
|
2012-07-31 10:12:26 +02:00
|
|
|
class QmlEngine;
|
2012-08-01 07:48:37 +02:00
|
|
|
class QML_PARSER_EXPORT QmlDirParser
|
2010-03-18 12:06:43 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2020-02-28 17:51:32 +01:00
|
|
|
void clear();
|
2012-07-31 10:12:26 +02:00
|
|
|
bool parse(const QString &source);
|
2010-03-18 12:06:43 +01:00
|
|
|
|
2021-07-06 23:50:30 +02:00
|
|
|
bool hasError() const { return !_errors.isEmpty(); }
|
2020-02-28 17:51:32 +01:00
|
|
|
void setError(const QmlJS::DiagnosticMessage &);
|
|
|
|
|
QList<QmlJS::DiagnosticMessage> errors(const QString &uri) const;
|
2010-03-18 12:06:43 +01:00
|
|
|
|
2021-07-06 23:50:30 +02:00
|
|
|
QString typeNamespace() const { return _typeNamespace; }
|
|
|
|
|
void setTypeNamespace(const QString &s) { _typeNamespace = s; }
|
2012-07-31 10:12:26 +02:00
|
|
|
|
2020-02-28 17:51:32 +01:00
|
|
|
static void checkNonRelative(const char *item, const QString &typeName, const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
if (fileName.startsWith(QLatin1Char('/'))) {
|
|
|
|
|
qWarning() << item << typeName
|
|
|
|
|
<< "is specified with non-relative URL" << fileName << "in a qmldir file."
|
|
|
|
|
<< "URLs in qmldir files should be relative to the qmldir file's directory.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-18 12:06:43 +01:00
|
|
|
struct Plugin
|
|
|
|
|
{
|
2020-02-28 17:51:32 +01:00
|
|
|
Plugin() = default;
|
2010-03-18 12:06:43 +01:00
|
|
|
|
2020-11-26 07:32:29 +01:00
|
|
|
Plugin(const QString &name, const QString &path, bool optional)
|
|
|
|
|
: name(name), path(path), optional(optional)
|
2020-02-28 17:51:32 +01:00
|
|
|
{
|
|
|
|
|
checkNonRelative("Plugin", name, path);
|
|
|
|
|
}
|
2010-03-18 12:06:43 +01:00
|
|
|
|
|
|
|
|
QString name;
|
|
|
|
|
QString path;
|
2020-11-26 07:32:29 +01:00
|
|
|
bool optional = false;
|
2010-03-18 12:06:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Component
|
|
|
|
|
{
|
2020-02-28 17:51:32 +01:00
|
|
|
Component() = default;
|
2010-03-18 12:06:43 +01:00
|
|
|
|
2011-12-07 11:16:26 +01:00
|
|
|
Component(const QString &typeName, const QString &fileName, int majorVersion, int minorVersion)
|
2010-03-25 14:11:23 +01:00
|
|
|
: typeName(typeName), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion),
|
2020-02-28 17:51:32 +01:00
|
|
|
internal(false), singleton(false)
|
|
|
|
|
{
|
|
|
|
|
checkNonRelative("Component", typeName, fileName);
|
|
|
|
|
}
|
2010-03-18 12:06:43 +01:00
|
|
|
|
2011-12-07 11:16:26 +01:00
|
|
|
QString typeName;
|
2010-03-18 12:06:43 +01:00
|
|
|
QString fileName;
|
2018-10-16 15:32:58 +02:00
|
|
|
int majorVersion = 0;
|
|
|
|
|
int minorVersion = 0;
|
|
|
|
|
bool internal = false;
|
|
|
|
|
bool singleton = false;
|
2010-03-18 12:06:43 +01:00
|
|
|
};
|
|
|
|
|
|
2012-07-31 10:12:26 +02:00
|
|
|
struct Script
|
|
|
|
|
{
|
2020-02-28 17:51:32 +01:00
|
|
|
Script() = default;
|
2012-07-31 10:12:26 +02:00
|
|
|
|
|
|
|
|
Script(const QString &nameSpace, const QString &fileName, int majorVersion, int minorVersion)
|
2020-02-28 17:51:32 +01:00
|
|
|
: nameSpace(nameSpace), fileName(fileName), majorVersion(majorVersion), minorVersion(minorVersion)
|
|
|
|
|
{
|
|
|
|
|
checkNonRelative("Script", nameSpace, fileName);
|
|
|
|
|
}
|
2012-07-31 10:12:26 +02:00
|
|
|
|
|
|
|
|
QString nameSpace;
|
|
|
|
|
QString fileName;
|
2018-10-16 15:32:58 +02:00
|
|
|
int majorVersion = 0;
|
|
|
|
|
int minorVersion = 0;
|
2012-07-31 10:12:26 +02:00
|
|
|
};
|
|
|
|
|
|
2020-11-26 07:32:29 +01:00
|
|
|
struct Import
|
|
|
|
|
{
|
|
|
|
|
enum Flag {
|
2022-12-19 14:00:30 +01:00
|
|
|
Default = 0x0,
|
|
|
|
|
Auto = 0x1, // forward the version of the importing module
|
|
|
|
|
Optional = 0x2, // is not automatically imported but only a tooling hint
|
|
|
|
|
OptionalDefault
|
|
|
|
|
= 0x4, // tooling hint only, denotes this entry should be imported by tooling
|
2020-11-26 07:32:29 +01:00
|
|
|
};
|
|
|
|
|
Q_DECLARE_FLAGS(Flags, Flag)
|
|
|
|
|
|
|
|
|
|
Import() = default;
|
|
|
|
|
Import(QString module, LanguageUtils::ComponentVersion version, Flags flags)
|
|
|
|
|
: module(module), version(version), flags(flags)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString module;
|
|
|
|
|
LanguageUtils::ComponentVersion version; // invalid version is latest version, unless Flag::Auto
|
|
|
|
|
Flags flags;
|
2022-12-19 14:00:30 +01:00
|
|
|
|
|
|
|
|
friend bool operator==(const Import &a, const Import &b)
|
|
|
|
|
{
|
|
|
|
|
return a.module == b.module && a.version == b.version && a.flags == b.flags;
|
|
|
|
|
}
|
2020-11-26 07:32:29 +01:00
|
|
|
};
|
|
|
|
|
|
2021-07-06 23:50:30 +02:00
|
|
|
QMultiHash<QString,Component> components() const { return _components; }
|
|
|
|
|
QList<Import> dependencies() const { return _dependencies; }
|
|
|
|
|
QList<Import> imports() const { return _imports; }
|
|
|
|
|
QList<Script> scripts() const { return _scripts; }
|
|
|
|
|
QList<Plugin> plugins() const { return _plugins; }
|
|
|
|
|
bool designerSupported() const { return _designerSupported; }
|
2022-12-19 14:00:30 +01:00
|
|
|
bool isStaticModule() const { return _isStaticModule; }
|
|
|
|
|
bool isSystemModule() const { return _isSystemModule; }
|
2010-03-18 12:06:43 +01:00
|
|
|
|
2021-07-06 23:50:30 +02:00
|
|
|
QStringList typeInfos() const { return _typeInfos; }
|
|
|
|
|
QStringList classNames() const { return _classNames; }
|
|
|
|
|
QString preferredPath() const { return _preferredPath; }
|
2021-12-03 15:49:28 +01:00
|
|
|
QString linkTarget() const { return _linkTarget; }
|
2018-10-16 15:32:58 +02:00
|
|
|
|
2010-03-18 12:06:43 +01:00
|
|
|
private:
|
2016-04-29 11:00:30 +02:00
|
|
|
bool maybeAddComponent(const QString &typeName, const QString &fileName, const QString &version, QHash<QString,Component> &hash, int lineNumber = -1, bool multi = true);
|
2013-01-22 11:15:23 +01:00
|
|
|
void reportError(quint16 line, quint16 column, const QString &message);
|
2010-03-18 12:06:43 +01:00
|
|
|
|
|
|
|
|
private:
|
2016-04-29 11:00:30 +02:00
|
|
|
QList<QmlJS::DiagnosticMessage> _errors;
|
2012-07-31 10:12:26 +02:00
|
|
|
QString _typeNamespace;
|
2021-07-06 23:50:30 +02:00
|
|
|
QString _preferredPath;
|
2020-02-28 17:51:32 +01:00
|
|
|
QMultiHash<QString,Component> _components;
|
2020-11-26 07:32:29 +01:00
|
|
|
QList<Import> _dependencies;
|
|
|
|
|
QList<Import> _imports;
|
2012-07-31 10:12:26 +02:00
|
|
|
QList<Script> _scripts;
|
2010-03-18 12:06:43 +01:00
|
|
|
QList<Plugin> _plugins;
|
2020-02-28 17:51:32 +01:00
|
|
|
bool _designerSupported = false;
|
2022-12-19 14:00:30 +01:00
|
|
|
bool _isStaticModule = false;
|
|
|
|
|
bool _isSystemModule = false;
|
2021-07-06 23:50:30 +02:00
|
|
|
QStringList _typeInfos;
|
|
|
|
|
QStringList _classNames;
|
2021-12-03 15:49:28 +01:00
|
|
|
QString _linkTarget;
|
2010-03-18 12:06:43 +01:00
|
|
|
};
|
|
|
|
|
|
2020-02-28 17:51:32 +01:00
|
|
|
using QmlDirComponents = QMultiHash<QString,QmlDirParser::Component>;
|
|
|
|
|
using QmlDirScripts = QList<QmlDirParser::Script>;
|
|
|
|
|
using QmlDirPlugins = QList<QmlDirParser::Plugin>;
|
2021-07-06 23:50:30 +02:00
|
|
|
using QmlDirImports = QList<QmlDirParser::Import>;
|
2010-03-25 14:11:23 +01:00
|
|
|
|
2012-07-31 10:12:26 +02:00
|
|
|
QDebug &operator<< (QDebug &, const QmlDirParser::Component &);
|
|
|
|
|
QDebug &operator<< (QDebug &, const QmlDirParser::Script &);
|
2010-03-25 14:11:23 +01:00
|
|
|
|
2020-02-28 17:51:32 +01:00
|
|
|
QT_QML_END_NAMESPACE
|
2018-04-05 11:13:53 +03:00
|
|
|
|