2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-01-18 13:13:34 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2016-01-15 14:58:39 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QList>
|
|
|
|
|
#include <QSharedPointer>
|
|
|
|
|
#include <QString>
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2011-01-04 17:04:44 +01:00
|
|
|
#include <languageutils/fakemetaobject.h>
|
|
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
#include "qmljsdialect.h"
|
2010-03-18 15:43:33 +01:00
|
|
|
#include "parser/qmldirparser_p.h"
|
2015-03-04 16:46:23 +01:00
|
|
|
#include "parser/qmljsastfwd_p.h"
|
2010-01-18 16:15:23 +01:00
|
|
|
#include "qmljs_global.h"
|
2013-11-06 14:17:23 +01:00
|
|
|
#include "qmljsconstants.h"
|
2013-10-16 15:08:27 +02:00
|
|
|
#include "qmljsimportdependencies.h"
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
namespace QmlJS {
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2010-02-02 15:55:17 +01:00
|
|
|
class Bind;
|
2015-03-04 16:46:23 +01:00
|
|
|
class DiagnosticMessage;
|
|
|
|
|
class Engine;
|
2010-02-16 10:36:09 +01:00
|
|
|
class Snapshot;
|
2013-10-16 15:08:27 +02:00
|
|
|
class ImportDependencies;
|
2010-02-02 15:55:17 +01:00
|
|
|
|
2010-01-18 16:15:23 +01:00
|
|
|
class QMLJS_EXPORT Document
|
2010-01-18 13:13:34 +01:00
|
|
|
{
|
2015-03-04 16:46:23 +01:00
|
|
|
Q_DISABLE_COPY(Document)
|
2010-01-18 13:13:34 +01:00
|
|
|
public:
|
2011-11-03 13:47:03 +01:00
|
|
|
typedef QSharedPointer<const Document> Ptr;
|
|
|
|
|
typedef QSharedPointer<Document> MutablePtr;
|
2010-01-18 13:13:34 +01:00
|
|
|
protected:
|
2014-07-22 19:06:44 +02:00
|
|
|
Document(const QString &fileName, Dialect language);
|
2010-01-18 13:13:34 +01:00
|
|
|
|
|
|
|
|
public:
|
2010-01-18 16:15:23 +01:00
|
|
|
~Document();
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2014-07-22 19:06:44 +02:00
|
|
|
static MutablePtr create(const QString &fileName, Dialect language);
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2011-05-04 11:12:45 +02:00
|
|
|
Document::Ptr ptr() const;
|
|
|
|
|
|
2010-03-29 12:56:25 +02:00
|
|
|
bool isQmlDocument() const;
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect language() const;
|
|
|
|
|
void setLanguage(Dialect l);
|
2010-03-29 12:56:25 +02:00
|
|
|
|
2013-11-13 16:31:04 +01:00
|
|
|
QString importId() const;
|
|
|
|
|
QByteArray fingerprint() const;
|
2010-02-03 15:59:15 +01:00
|
|
|
AST::UiProgram *qmlProgram() const;
|
|
|
|
|
AST::Program *jsProgram() const;
|
|
|
|
|
AST::ExpressionNode *expression() const;
|
|
|
|
|
AST::Node *ast() const;
|
2010-01-19 10:16:57 +01:00
|
|
|
|
2010-11-23 12:57:48 +01:00
|
|
|
const QmlJS::Engine *engine() const;
|
|
|
|
|
|
2010-02-03 15:59:15 +01:00
|
|
|
QList<DiagnosticMessage> diagnosticMessages() const;
|
2010-01-18 13:13:34 +01:00
|
|
|
|
|
|
|
|
QString source() const;
|
|
|
|
|
void setSource(const QString &source);
|
|
|
|
|
|
2010-03-29 12:56:25 +02:00
|
|
|
bool parse();
|
2010-01-18 13:13:34 +01:00
|
|
|
bool parseQml();
|
|
|
|
|
bool parseJavaScript();
|
2010-01-22 10:26:25 +01:00
|
|
|
bool parseExpression();
|
2010-01-18 13:13:34 +01:00
|
|
|
|
|
|
|
|
bool isParsedCorrectly() const
|
|
|
|
|
{ return _parsedCorrectly; }
|
|
|
|
|
|
2010-02-03 15:59:15 +01:00
|
|
|
Bind *bind() const;
|
2010-02-02 15:55:17 +01:00
|
|
|
|
2010-07-07 17:52:02 +02:00
|
|
|
int editorRevision() const;
|
|
|
|
|
void setEditorRevision(int revision);
|
2010-01-25 14:18:53 +01:00
|
|
|
|
2010-02-11 10:19:41 +01:00
|
|
|
QString fileName() const;
|
|
|
|
|
QString path() const;
|
|
|
|
|
QString componentName() const;
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2017-10-19 17:14:12 +02:00
|
|
|
QList<AST::SourceLocation> jsDirectives() const;
|
|
|
|
|
|
2010-02-08 21:37:59 +01:00
|
|
|
private:
|
|
|
|
|
bool parse_helper(int kind);
|
|
|
|
|
|
2010-01-18 13:13:34 +01:00
|
|
|
private:
|
|
|
|
|
QmlJS::Engine *_engine;
|
2010-02-03 15:59:15 +01:00
|
|
|
AST::Node *_ast;
|
|
|
|
|
Bind *_bind;
|
2010-01-18 13:13:34 +01:00
|
|
|
QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
|
|
|
|
|
QString _fileName;
|
|
|
|
|
QString _path;
|
|
|
|
|
QString _componentName;
|
|
|
|
|
QString _source;
|
2017-10-19 17:14:12 +02:00
|
|
|
QList<AST::SourceLocation> _jsdirectives;
|
2011-05-04 11:12:45 +02:00
|
|
|
QWeakPointer<Document> _ptr;
|
2013-11-13 16:31:04 +01:00
|
|
|
QByteArray _fingerprint;
|
2011-09-09 10:55:11 +02:00
|
|
|
int _editorRevision;
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect _language;
|
2012-12-06 12:11:12 +01:00
|
|
|
bool _parsedCorrectly;
|
2010-02-16 10:36:09 +01:00
|
|
|
|
|
|
|
|
// for documentFromSource
|
|
|
|
|
friend class Snapshot;
|
2010-01-18 13:13:34 +01:00
|
|
|
};
|
|
|
|
|
|
2011-10-12 08:36:02 +02:00
|
|
|
class QMLJS_EXPORT ModuleApiInfo
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QString uri;
|
|
|
|
|
LanguageUtils::ComponentVersion version;
|
|
|
|
|
QString cppName;
|
2013-11-13 16:31:04 +01:00
|
|
|
|
|
|
|
|
void addToHash(QCryptographicHash &hash) const;
|
2011-10-12 08:36:02 +02:00
|
|
|
};
|
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
class QMLJS_EXPORT LibraryInfo
|
|
|
|
|
{
|
2010-11-24 09:30:46 +01:00
|
|
|
public:
|
2011-05-12 15:29:00 +02:00
|
|
|
enum PluginTypeInfoStatus {
|
|
|
|
|
NoTypeInfo,
|
2010-11-24 09:30:46 +01:00
|
|
|
DumpDone,
|
2011-05-12 15:29:00 +02:00
|
|
|
DumpError,
|
|
|
|
|
TypeInfoFileDone,
|
|
|
|
|
TypeInfoFileError
|
2010-11-24 09:30:46 +01:00
|
|
|
};
|
|
|
|
|
|
2011-05-27 14:51:30 +02:00
|
|
|
enum Status {
|
|
|
|
|
NotScanned,
|
|
|
|
|
NotFound,
|
|
|
|
|
Found
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-24 09:30:46 +01:00
|
|
|
private:
|
2011-05-27 14:51:30 +02:00
|
|
|
Status _status;
|
2010-03-18 15:43:33 +01:00
|
|
|
QList<QmlDirParser::Component> _components;
|
|
|
|
|
QList<QmlDirParser::Plugin> _plugins;
|
2011-09-02 13:25:08 +02:00
|
|
|
QList<QmlDirParser::TypeInfo> _typeinfos;
|
2011-01-04 17:04:44 +01:00
|
|
|
typedef QList<LanguageUtils::FakeMetaObject::ConstPtr> FakeMetaObjectList;
|
2010-06-09 14:27:30 +02:00
|
|
|
FakeMetaObjectList _metaObjects;
|
2011-10-12 08:36:02 +02:00
|
|
|
QList<ModuleApiInfo> _moduleApis;
|
2016-02-26 17:28:30 +01:00
|
|
|
QStringList _dependencies;
|
2013-11-13 16:31:04 +01:00
|
|
|
QByteArray _fingerprint;
|
2010-11-24 09:30:46 +01:00
|
|
|
|
2011-05-12 15:29:00 +02:00
|
|
|
PluginTypeInfoStatus _dumpStatus;
|
2010-11-24 09:30:46 +01:00
|
|
|
QString _dumpError;
|
2010-03-18 15:43:33 +01:00
|
|
|
|
|
|
|
|
public:
|
2011-05-27 14:51:30 +02:00
|
|
|
explicit LibraryInfo(Status status = NotScanned);
|
2013-11-13 16:31:04 +01:00
|
|
|
explicit LibraryInfo(const QmlDirParser &parser, const QByteArray &fingerprint = QByteArray());
|
2010-03-18 15:43:33 +01:00
|
|
|
~LibraryInfo();
|
|
|
|
|
|
2013-11-13 16:31:04 +01:00
|
|
|
QByteArray calculateFingerprint() const;
|
|
|
|
|
void updateFingerprint();
|
|
|
|
|
QByteArray fingerprint() const
|
|
|
|
|
{ return _fingerprint; }
|
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
QList<QmlDirParser::Component> components() const
|
|
|
|
|
{ return _components; }
|
|
|
|
|
|
|
|
|
|
QList<QmlDirParser::Plugin> plugins() const
|
|
|
|
|
{ return _plugins; }
|
|
|
|
|
|
2011-09-02 13:25:08 +02:00
|
|
|
QList<QmlDirParser::TypeInfo> typeInfos() const
|
|
|
|
|
{ return _typeinfos; }
|
|
|
|
|
|
2010-06-09 14:27:30 +02:00
|
|
|
FakeMetaObjectList metaObjects() const
|
|
|
|
|
{ return _metaObjects; }
|
|
|
|
|
|
|
|
|
|
void setMetaObjects(const FakeMetaObjectList &objects)
|
|
|
|
|
{ _metaObjects = objects; }
|
|
|
|
|
|
2011-10-12 08:36:02 +02:00
|
|
|
QList<ModuleApiInfo> moduleApis() const
|
|
|
|
|
{ return _moduleApis; }
|
|
|
|
|
|
|
|
|
|
void setModuleApis(const QList<ModuleApiInfo> &apis)
|
|
|
|
|
{ _moduleApis = apis; }
|
|
|
|
|
|
2016-02-26 17:28:30 +01:00
|
|
|
QStringList dependencies() const
|
|
|
|
|
{ return _dependencies; }
|
|
|
|
|
|
|
|
|
|
void setDependencies(const QStringList &deps)
|
|
|
|
|
{ _dependencies = deps; }
|
|
|
|
|
|
2010-03-18 15:43:33 +01:00
|
|
|
bool isValid() const
|
2011-05-27 14:51:30 +02:00
|
|
|
{ return _status == Found; }
|
|
|
|
|
|
|
|
|
|
bool wasScanned() const
|
|
|
|
|
{ return _status != NotScanned; }
|
2010-10-14 14:44:50 +02:00
|
|
|
|
2013-11-19 10:42:57 +01:00
|
|
|
bool wasFound() const
|
|
|
|
|
{ return _status != NotFound; }
|
|
|
|
|
|
2011-05-12 15:29:00 +02:00
|
|
|
PluginTypeInfoStatus pluginTypeInfoStatus() const
|
2010-11-24 09:30:46 +01:00
|
|
|
{ return _dumpStatus; }
|
|
|
|
|
|
2011-05-12 15:29:00 +02:00
|
|
|
QString pluginTypeInfoError() const
|
2010-11-24 09:30:46 +01:00
|
|
|
{ return _dumpError; }
|
2010-10-14 14:44:50 +02:00
|
|
|
|
2011-05-12 15:29:00 +02:00
|
|
|
void setPluginTypeInfoStatus(PluginTypeInfoStatus dumped, const QString &error = QString())
|
2010-11-24 09:30:46 +01:00
|
|
|
{ _dumpStatus = dumped; _dumpError = error; }
|
2010-03-18 15:43:33 +01:00
|
|
|
};
|
|
|
|
|
|
2010-01-26 17:23:18 +01:00
|
|
|
class QMLJS_EXPORT Snapshot
|
2010-01-18 13:13:34 +01:00
|
|
|
{
|
2014-08-28 14:56:23 +02:00
|
|
|
typedef QHash<QString, Document::Ptr> Base;
|
2010-04-01 11:27:49 +02:00
|
|
|
QHash<QString, Document::Ptr> _documents;
|
2010-08-31 10:23:48 +02:00
|
|
|
QHash<QString, QList<Document::Ptr> > _documentsByPath;
|
2010-04-01 11:27:49 +02:00
|
|
|
QHash<QString, LibraryInfo> _libraries;
|
2013-10-16 15:08:27 +02:00
|
|
|
ImportDependencies _dependencies;
|
2010-01-26 17:23:18 +01:00
|
|
|
|
2010-01-18 13:13:34 +01:00
|
|
|
public:
|
|
|
|
|
Snapshot();
|
2013-10-16 15:08:27 +02:00
|
|
|
Snapshot(const Snapshot &o);
|
2010-01-18 13:13:34 +01:00
|
|
|
~Snapshot();
|
|
|
|
|
|
2014-08-28 14:56:23 +02:00
|
|
|
typedef Base::iterator iterator;
|
|
|
|
|
typedef Base::const_iterator const_iterator;
|
2010-01-26 17:23:18 +01:00
|
|
|
|
|
|
|
|
const_iterator begin() const { return _documents.begin(); }
|
|
|
|
|
const_iterator end() const { return _documents.end(); }
|
|
|
|
|
|
2011-08-16 14:11:30 +02:00
|
|
|
void insert(const Document::Ptr &document, bool allowInvalid = false);
|
2010-03-18 15:43:33 +01:00
|
|
|
void insertLibraryInfo(const QString &path, const LibraryInfo &info);
|
2010-05-18 13:40:35 +02:00
|
|
|
void remove(const QString &fileName);
|
2010-01-18 13:13:34 +01:00
|
|
|
|
2013-10-16 15:08:27 +02:00
|
|
|
const ImportDependencies *importDependencies() const;
|
|
|
|
|
ImportDependencies *importDependencies();
|
|
|
|
|
|
2010-04-01 14:42:39 +02:00
|
|
|
Document::Ptr document(const QString &fileName) const;
|
|
|
|
|
QList<Document::Ptr> documentsInDirectory(const QString &path) const;
|
|
|
|
|
LibraryInfo libraryInfo(const QString &path) const;
|
2010-03-18 15:43:33 +01:00
|
|
|
|
2011-11-03 13:47:03 +01:00
|
|
|
Document::MutablePtr documentFromSource(const QString &code,
|
2011-09-09 10:55:11 +02:00
|
|
|
const QString &fileName,
|
2014-07-22 19:06:44 +02:00
|
|
|
Dialect language) const;
|
2010-01-18 13:13:34 +01:00
|
|
|
};
|
|
|
|
|
|
2010-09-23 15:09:06 +02:00
|
|
|
} // namespace QmlJS
|