2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-07-01 13:51:53 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-07-01 13:51:53 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-07-01 13:51:53 +02: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.
|
2011-07-01 13:51:53 +02: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.
|
2011-07-01 13:51:53 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-07-01 13:51:53 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2011-07-01 13:51:53 +02:00
|
|
|
|
|
|
|
|
#include "qmljs_global.h"
|
2015-03-04 16:46:23 +01:00
|
|
|
#include "qmljsdocument.h"
|
|
|
|
|
#include "qmljsinterpreter.h"
|
2013-10-16 15:08:27 +02:00
|
|
|
#include "qmljsviewercontext.h"
|
2011-07-01 13:51:53 +02:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QSharedPointer>
|
2011-07-01 13:51:53 +02:00
|
|
|
|
|
|
|
|
namespace QmlJS {
|
|
|
|
|
|
|
|
|
|
class Document;
|
|
|
|
|
class Snapshot;
|
2011-07-13 15:04:27 +02:00
|
|
|
class Context;
|
|
|
|
|
typedef QSharedPointer<const Context> ContextPtr;
|
|
|
|
|
|
2011-07-12 14:55:27 +02:00
|
|
|
// shared among threads, completely threadsafe
|
2011-07-01 13:51:53 +02:00
|
|
|
class QMLJS_EXPORT Context
|
|
|
|
|
{
|
2011-07-13 15:04:27 +02:00
|
|
|
Q_DISABLE_COPY(Context)
|
2011-07-01 13:51:53 +02:00
|
|
|
public:
|
|
|
|
|
typedef QHash<const Document *, QSharedPointer<const Imports> > ImportsPerDocument;
|
|
|
|
|
|
|
|
|
|
// Context takes ownership of valueOwner
|
2013-10-16 15:08:27 +02:00
|
|
|
static ContextPtr create(const Snapshot &snapshot, ValueOwner *valueOwner,
|
2014-07-17 12:29:37 +02:00
|
|
|
const ImportsPerDocument &imports, const ViewerContext &viewerContext);
|
2011-07-01 13:51:53 +02:00
|
|
|
~Context();
|
|
|
|
|
|
2011-07-13 15:04:27 +02:00
|
|
|
ContextPtr ptr() const;
|
|
|
|
|
|
2011-07-01 13:51:53 +02:00
|
|
|
ValueOwner *valueOwner() const;
|
|
|
|
|
Snapshot snapshot() const;
|
2014-07-17 12:29:37 +02:00
|
|
|
ViewerContext viewerContext() const;
|
2011-07-01 13:51:53 +02:00
|
|
|
|
|
|
|
|
const Imports *imports(const Document *doc) const;
|
|
|
|
|
|
|
|
|
|
const ObjectValue *lookupType(const Document *doc, AST::UiQualifiedId *qmlTypeName,
|
|
|
|
|
AST::UiQualifiedId *qmlTypeNameEnd = 0) const;
|
|
|
|
|
const ObjectValue *lookupType(const Document *doc, const QStringList &qmlTypeName) const;
|
|
|
|
|
const Value *lookupReference(const Value *value) const;
|
|
|
|
|
|
|
|
|
|
QString defaultPropertyName(const ObjectValue *object) const;
|
|
|
|
|
|
|
|
|
|
private:
|
2011-07-13 15:04:27 +02:00
|
|
|
// Context takes ownership of valueOwner
|
2013-10-16 15:08:27 +02:00
|
|
|
Context(const Snapshot &snapshot, ValueOwner *valueOwner, const ImportsPerDocument &imports,
|
2014-07-17 12:29:37 +02:00
|
|
|
const ViewerContext &viewerContext);
|
2011-07-13 15:04:27 +02:00
|
|
|
|
2011-07-01 13:51:53 +02:00
|
|
|
Snapshot _snapshot;
|
|
|
|
|
QSharedPointer<ValueOwner> _valueOwner;
|
|
|
|
|
ImportsPerDocument _imports;
|
2013-10-16 15:08:27 +02:00
|
|
|
ViewerContext _vContext;
|
2011-07-13 15:04:27 +02:00
|
|
|
QWeakPointer<const Context> _ptr;
|
2011-07-12 14:55:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// for looking up references
|
|
|
|
|
class QMLJS_EXPORT ReferenceContext
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// implicit conversion ok
|
2011-07-13 15:04:27 +02:00
|
|
|
ReferenceContext(const ContextPtr &context);
|
2011-07-12 14:55:27 +02:00
|
|
|
|
|
|
|
|
const Value *lookupReference(const Value *value);
|
|
|
|
|
|
2011-07-13 15:04:27 +02:00
|
|
|
const ContextPtr &context() const;
|
|
|
|
|
operator const ContextPtr &() const;
|
2011-07-01 13:51:53 +02:00
|
|
|
|
2011-07-12 14:55:27 +02:00
|
|
|
private:
|
2018-11-15 19:21:12 +01:00
|
|
|
const ContextPtr m_context;
|
2011-07-12 14:55:27 +02:00
|
|
|
QList<const Reference *> m_references;
|
2011-07-01 13:51:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace QmlJS
|