2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
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,
|
2019-07-31 17:21:41 +02:00
|
|
|
AST::UiQualifiedId *qmlTypeNameEnd = nullptr) const;
|
2011-07-01 13:51:53 +02:00
|
|
|
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
|