2013-10-16 15:08:27 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2013-10-16 15:08:27 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2013-10-16 15:08:27 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2013-10-16 15:08:27 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2013-10-16 15:08:27 +02:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef QMLJSIMPORTCACHE_H
|
|
|
|
|
#define QMLJSIMPORTCACHE_H
|
|
|
|
|
|
2015-03-04 16:46:23 +01:00
|
|
|
#include "qmljsconstants.h"
|
2014-07-22 19:06:44 +02:00
|
|
|
#include "qmljsdialect.h"
|
2013-10-16 15:08:27 +02:00
|
|
|
|
|
|
|
|
#include <languageutils/componentversion.h>
|
|
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QStringList>
|
|
|
|
|
#include <QList>
|
|
|
|
|
#include <QMap>
|
|
|
|
|
#include <QSet>
|
|
|
|
|
#include <QSharedPointer>
|
|
|
|
|
|
2014-06-27 22:11:09 +02:00
|
|
|
#include <functional>
|
|
|
|
|
|
2013-10-16 15:08:27 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QCryptographicHash;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
|
|
|
|
namespace QmlJS {
|
|
|
|
|
class ImportInfo;
|
2015-03-04 16:46:23 +01:00
|
|
|
class ViewerContext;
|
2014-02-11 21:55:42 +02:00
|
|
|
namespace Internal { class ImportDependenciesPrivate; }
|
2013-10-16 15:08:27 +02:00
|
|
|
class ImportDependencies;
|
|
|
|
|
|
|
|
|
|
// match strenght wrt to the selectors of a ViewerContext
|
|
|
|
|
// this is valid only within a ViewerContext
|
|
|
|
|
class QMLJS_EXPORT ImportMatchStrength
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit ImportMatchStrength() {}
|
|
|
|
|
ImportMatchStrength(QList<int> match);
|
|
|
|
|
|
|
|
|
|
int compareMatch(const ImportMatchStrength &o) const;
|
|
|
|
|
|
|
|
|
|
bool hasNoMatch();
|
|
|
|
|
|
|
|
|
|
bool hasMatch();
|
|
|
|
|
private:
|
|
|
|
|
friend bool operator ==(const ImportMatchStrength &m1, const ImportMatchStrength &m2);
|
|
|
|
|
QList<int> m_match;
|
|
|
|
|
};
|
|
|
|
|
bool operator ==(const ImportMatchStrength &m1, const ImportMatchStrength &m2);
|
|
|
|
|
bool operator !=(const ImportMatchStrength &m1, const ImportMatchStrength &m2);
|
|
|
|
|
bool operator <(const ImportMatchStrength &m1, const ImportMatchStrength &m2);
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief The ImportKey class represent an import (or export), and can be used as hash key
|
|
|
|
|
*
|
|
|
|
|
* This represent only what is to be imported, *not* how (i.e. no as clause)
|
2013-11-13 16:31:04 +01:00
|
|
|
*
|
|
|
|
|
* Order is defined so that files in the same directory are contiguous, and different
|
|
|
|
|
* ImportKind are separated.
|
|
|
|
|
* This is used to efficiently iterate just on library imports, or just on a directory
|
|
|
|
|
* while preserving space.
|
2013-10-16 15:08:27 +02:00
|
|
|
*/
|
|
|
|
|
class QMLJS_EXPORT ImportKey
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum DirCompareInfo {
|
|
|
|
|
SameDir,
|
|
|
|
|
FirstInSecond,
|
|
|
|
|
SecondInFirst,
|
|
|
|
|
Different,
|
|
|
|
|
Incompatible
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
explicit ImportKey();
|
|
|
|
|
explicit ImportKey(const ImportInfo &info);
|
2013-11-13 16:31:04 +01:00
|
|
|
ImportKey(ImportType::Enum type, const QString &path,
|
|
|
|
|
int majorVersion = LanguageUtils::ComponentVersion::NoVersion,
|
|
|
|
|
int minorVersion = LanguageUtils::ComponentVersion::NoVersion);
|
2013-10-16 15:08:27 +02:00
|
|
|
|
|
|
|
|
ImportType::Enum type;
|
|
|
|
|
QStringList splitPath;
|
|
|
|
|
int majorVersion;
|
|
|
|
|
int minorVersion;
|
|
|
|
|
|
|
|
|
|
QString path() const;
|
2014-07-17 12:29:37 +02:00
|
|
|
QString libraryQualifiedPath() const;
|
2013-10-16 15:08:27 +02:00
|
|
|
|
|
|
|
|
void addToHash(QCryptographicHash &hash) const;
|
|
|
|
|
ImportKey flatKey() const;
|
|
|
|
|
|
|
|
|
|
// wrap QList in a special type?
|
|
|
|
|
ImportMatchStrength matchImport(const ImportKey &o, const ViewerContext &vContext) const;
|
|
|
|
|
int compare(const ImportKey &other) const;
|
|
|
|
|
bool isDirectoryLike() const;
|
|
|
|
|
DirCompareInfo compareDir(const ImportKey &other) const;
|
2013-11-19 10:42:57 +01:00
|
|
|
QString toString() const;
|
2013-10-16 15:08:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
uint qHash(const ImportKey &info);
|
|
|
|
|
bool operator ==(const ImportKey &i1, const ImportKey &i2);
|
|
|
|
|
bool operator !=(const ImportKey &i1, const ImportKey &i2);
|
|
|
|
|
bool operator <(const ImportKey &i1, const ImportKey &i2);
|
|
|
|
|
|
|
|
|
|
class QMLJS_EXPORT Export
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-03 12:38:23 +02:00
|
|
|
static const QString LibraryTypeName;
|
2013-10-16 15:08:27 +02:00
|
|
|
Export();
|
2014-07-03 12:38:23 +02:00
|
|
|
Export(ImportKey exportName, QString pathRequired, bool intrinsic = false,
|
|
|
|
|
const QString &typeName = LibraryTypeName);
|
2013-10-16 15:08:27 +02:00
|
|
|
ImportKey exportName;
|
|
|
|
|
QString pathRequired;
|
2014-07-03 12:38:23 +02:00
|
|
|
QString typeName;
|
2013-10-16 15:08:27 +02:00
|
|
|
bool intrinsic;
|
|
|
|
|
bool visibleInVContext(const ViewerContext &vContext) const;
|
|
|
|
|
};
|
|
|
|
|
bool operator ==(const Export &i1, const Export &i2);
|
|
|
|
|
bool operator !=(const Export &i1, const Export &i2);
|
|
|
|
|
|
|
|
|
|
class QMLJS_EXPORT CoreImport
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CoreImport();
|
2013-11-13 16:31:04 +01:00
|
|
|
CoreImport(const QString &importId, const QList<Export> &possibleExports = QList<Export>(),
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect language = Dialect::Qml, const QByteArray &fingerprint = QByteArray());
|
2013-10-16 15:08:27 +02:00
|
|
|
QString importId;
|
|
|
|
|
QList<Export> possibleExports;
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect language;
|
2013-10-16 15:08:27 +02:00
|
|
|
QByteArray fingerprint;
|
|
|
|
|
bool valid();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QMLJS_EXPORT DependencyInfo
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef QSharedPointer<const DependencyInfo> ConstPtr;
|
|
|
|
|
typedef QSharedPointer<DependencyInfo> Ptr;
|
|
|
|
|
|
|
|
|
|
QByteArray calculateFingerprint(const ImportDependencies &deps);
|
|
|
|
|
|
|
|
|
|
ImportKey rootImport;
|
|
|
|
|
QSet<QString> allCoreImports;
|
|
|
|
|
QSet<ImportKey> allImports;
|
|
|
|
|
QByteArray fingerprint;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class QMLJS_EXPORT MatchedImport
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MatchedImport();
|
2013-11-13 16:31:04 +01:00
|
|
|
MatchedImport(ImportMatchStrength matchStrength, ImportKey importKey,
|
|
|
|
|
const QString &coreImportId);
|
2013-10-16 15:08:27 +02:00
|
|
|
|
|
|
|
|
ImportMatchStrength matchStrength;
|
|
|
|
|
ImportKey importKey;
|
|
|
|
|
QString coreImportId;
|
|
|
|
|
int compare(const MatchedImport &o) const;
|
|
|
|
|
};
|
|
|
|
|
bool operator ==(const MatchedImport &m1, const MatchedImport &m2);
|
|
|
|
|
bool operator !=(const MatchedImport &m1, const MatchedImport &m2);
|
|
|
|
|
bool operator <(const MatchedImport &m1, const MatchedImport &m2);
|
|
|
|
|
|
|
|
|
|
class QMLJS_EXPORT ImportDependencies
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef QMap<ImportKey, QList<MatchedImport> > ImportElements;
|
|
|
|
|
|
|
|
|
|
explicit ImportDependencies();
|
|
|
|
|
~ImportDependencies();
|
|
|
|
|
|
|
|
|
|
void filter(const ViewerContext &vContext);
|
|
|
|
|
|
|
|
|
|
CoreImport coreImport(const QString &importId) const;
|
|
|
|
|
void iterateOnCandidateImports(const ImportKey &key, const ViewerContext &vContext,
|
2014-06-27 22:11:09 +02:00
|
|
|
std::function<bool(const ImportMatchStrength &,
|
2013-10-16 15:08:27 +02:00
|
|
|
const Export &,
|
|
|
|
|
const CoreImport &)> const &iterF) const;
|
|
|
|
|
ImportElements candidateImports(const ImportKey &key, const ViewerContext &vContext) const;
|
|
|
|
|
|
|
|
|
|
QList<DependencyInfo::ConstPtr> createDependencyInfos(const ImportKey &mainDoc,
|
|
|
|
|
const ViewerContext &vContext) const;
|
|
|
|
|
|
|
|
|
|
void addCoreImport(const CoreImport &import);
|
|
|
|
|
void removeCoreImport(const QString &importId);
|
|
|
|
|
|
|
|
|
|
void addExport(const QString &importId, const ImportKey &importKey,
|
2014-07-03 12:38:23 +02:00
|
|
|
const QString &requiredPath, const QString &typeName = Export::LibraryTypeName);
|
2013-10-16 15:08:27 +02:00
|
|
|
void removeExport(const QString &importId, const ImportKey &importKey,
|
2014-07-03 12:38:23 +02:00
|
|
|
const QString &requiredPath, const QString &typeName = Export::LibraryTypeName);
|
2013-10-16 15:08:27 +02:00
|
|
|
|
|
|
|
|
void iterateOnCoreImports(const ViewerContext &vContext,
|
2014-06-27 22:11:09 +02:00
|
|
|
std::function<bool(const CoreImport &)> const &iterF) const;
|
2013-10-16 15:08:27 +02:00
|
|
|
void iterateOnLibraryImports(const ViewerContext &vContext,
|
2014-06-27 22:11:09 +02:00
|
|
|
std::function<bool(const ImportMatchStrength &,
|
2013-10-16 15:08:27 +02:00
|
|
|
const Export &,
|
|
|
|
|
const CoreImport &)> const &iterF) const;
|
|
|
|
|
void iterateOnSubImports(const ImportKey &baseKey, const ViewerContext &vContext,
|
2014-06-27 22:11:09 +02:00
|
|
|
std::function<bool(const ImportMatchStrength &,
|
2013-10-16 15:08:27 +02:00
|
|
|
const Export &,
|
|
|
|
|
const CoreImport &)> const &iterF) const;
|
|
|
|
|
|
|
|
|
|
QSet<ImportKey> libraryImports(const ViewerContext &viewContext) const;
|
|
|
|
|
QSet<ImportKey> subdirImports(const ImportKey &baseKey, const ViewerContext &viewContext) const;
|
2013-11-26 09:55:34 +01:00
|
|
|
void checkConsistency() const;
|
2013-10-16 15:08:27 +02:00
|
|
|
private:
|
2013-11-21 11:26:18 +01:00
|
|
|
void removeImportCacheEntry(const ImportKey &importKey, const QString &importId);
|
|
|
|
|
|
2013-10-16 15:08:27 +02:00
|
|
|
QMap<ImportKey, QStringList> m_importCache;
|
|
|
|
|
QMap<QString, CoreImport> m_coreImports;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace QmlJS
|
|
|
|
|
|
|
|
|
|
#endif // QMLJSIMPORTCACHE_H
|