QmlJS: Remove LookupContext.

Use Context or ScopeChain instead.

Change-Id: I2489477eac08774ba41710ee81876aab11b5af24
Reviewed-on: http://codereview.qt.nokia.com/1699
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
Christian Kamm
2011-08-08 12:26:22 +02:00
parent 76be300202
commit ff092f79b3
22 changed files with 155 additions and 362 deletions

View File

@@ -18,7 +18,6 @@ HEADERS += \
$$PWD/qmljslink.h \
$$PWD/qmljscheck.h \
$$PWD/qmljsscopebuilder.h \
$$PWD/qmljslookupcontext.h \
$$PWD/qmljslineinfo.h \
$$PWD/qmljscompletioncontextfinder.h \
$$PWD/qmljsmodelmanagerinterface.h \
@@ -42,7 +41,6 @@ SOURCES += \
$$PWD/qmljslink.cpp \
$$PWD/qmljscheck.cpp \
$$PWD/qmljsscopebuilder.cpp \
$$PWD/qmljslookupcontext.cpp \
$$PWD/qmljslineinfo.cpp \
$$PWD/qmljscompletioncontextfinder.cpp \
$$PWD/qmljsmodelmanagerinterface.cpp \

View File

@@ -37,8 +37,8 @@
#include "qmljs_global.h"
#include <qmljs/qmljsdocument.h>
#include <qmljs/parser/qmljsastfwd_p.h>
#include <qmljs/qmljslookupcontext.h>
namespace TextEditor {
class BaseTextEditor;
@@ -46,6 +46,10 @@ class BaseTextEditor;
namespace QmlJS {
namespace Interpreter {
class ScopeChain;
}
class QMLJS_EXPORT IContextPane : public QObject
{
Q_OBJECT
@@ -53,7 +57,7 @@ class QMLJS_EXPORT IContextPane : public QObject
public:
IContextPane(QObject *parent = 0) : QObject(parent) {}
virtual ~IContextPane() {}
virtual void apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, LookupContext::Ptr lookupContext, AST::Node *node, bool update, bool force = false) = 0;
virtual void apply(TextEditor::BaseTextEditor *editor, Document::Ptr document, const Interpreter::ScopeChain *scopeChain, AST::Node *node, bool update, bool force = false) = 0;
virtual void setEnabled(bool) = 0;
virtual bool isAvailable(TextEditor::BaseTextEditor *editor, Document::Ptr document, AST::Node *node) = 0;
virtual QWidget* widget() = 0;

View File

@@ -1,135 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#include "qmljslookupcontext.h"
#include "qmljscontext.h"
#include "qmljslink.h"
#include "qmljsscopebuilder.h"
#include "qmljsmodelmanagerinterface.h"
#include "qmljsevaluate.h"
#include "qmljsscopechain.h"
#include "qmljscontext.h"
using namespace QmlJS;
class QmlJS::LookupContextData
{
public:
LookupContextData(Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path)
: doc(doc)
, context(Link(snapshot,
ModelManagerInterface::instance()->importPaths(),
ModelManagerInterface::instance()->builtins(doc))())
, scopeChain(doc, context)
{
ScopeBuilder scopeBuilder(&scopeChain);
scopeBuilder.push(path);
}
LookupContextData(Document::Ptr doc,
const Interpreter::ContextPtr &context,
const QList<AST::Node *> &path)
: doc(doc)
, context(context)
, scopeChain(doc, context)
{
ScopeBuilder scopeBuilder(&scopeChain);
scopeBuilder.push(path);
}
Document::Ptr doc;
Interpreter::ContextPtr context;
Interpreter::ScopeChain scopeChain;
};
LookupContext::LookupContext(Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path)
: d(new LookupContextData(doc, snapshot, path))
{
}
LookupContext::LookupContext(const Document::Ptr doc,
const Interpreter::ContextPtr &context,
const QList<AST::Node *> &path)
: d(new LookupContextData(doc, context, path))
{
}
LookupContext::~LookupContext()
{
}
LookupContext::Ptr LookupContext::create(Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path)
{
Ptr ptr(new LookupContext(doc, snapshot, path));
return ptr;
}
LookupContext::Ptr LookupContext::create(const Document::Ptr doc,
const Interpreter::ContextPtr &context,
const QList<AST::Node *> &path)
{
Ptr ptr(new LookupContext(doc, context, path));
return ptr;
}
const Interpreter::Value *LookupContext::evaluate(AST::Node *node) const
{
Evaluate check(&d->scopeChain);
return check(node);
}
Document::Ptr LookupContext::document() const
{
return d->doc;
}
Snapshot LookupContext::snapshot() const
{
return d->context->snapshot();
}
// the engine is only guaranteed to live as long as the LookupContext
Interpreter::ValueOwner *LookupContext::valueOwner() const
{
return d->context->valueOwner();
}
// the context is only guaranteed to live as long as the LookupContext
const Interpreter::ContextPtr &LookupContext::context() const
{
return d->context;
}
const Interpreter::ScopeChain &LookupContext::scopeChain() const
{
return d->scopeChain;
}

View File

@@ -1,90 +0,0 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this file.
** Please review the following information to ensure the GNU Lesser General
** Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
#ifndef QMLJSLOOKUPCONTEXT_H
#define QMLJSLOOKUPCONTEXT_H
#include "qmljsdocument.h"
#include "parser/qmljsastfwd_p.h"
#include <QtCore/QSharedPointer>
#include <QtCore/QScopedPointer>
namespace QmlJS {
class LookupContextData;
namespace Interpreter {
class Value;
class Context;
typedef QSharedPointer<const Context> ContextPtr;
class ValueOwner;
class ScopeChain;
}
class QMLJS_EXPORT LookupContext
{
Q_DISABLE_COPY(LookupContext)
LookupContext(const Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path);
LookupContext(const Document::Ptr doc,
const Interpreter::ContextPtr &context,
const QList<AST::Node *> &path);
public:
~LookupContext();
typedef QSharedPointer<LookupContext> Ptr;
// consider using SemanticInfo::lookupContext instead, it's faster
static Ptr create(const Document::Ptr doc, const Snapshot &snapshot,
const QList<AST::Node *> &path);
static Ptr create(const Document::Ptr doc,
const Interpreter::ContextPtr &context,
const QList<AST::Node *> &path);
const Interpreter::Value *evaluate(AST::Node *node) const;
Document::Ptr document() const;
Snapshot snapshot() const;
Interpreter::ValueOwner *valueOwner() const;
const Interpreter::ContextPtr &context() const;
const Interpreter::ScopeChain &scopeChain() const;
private:
QScopedPointer<LookupContextData> d;
};
} // namespace QmlJS
#endif // QMLJSLOOKUPCONTEXT_H

View File

@@ -32,6 +32,7 @@
#include "qmljsscopechain.h"
#include "qmljsbind.h"
#include "qmljsevaluate.h"
using namespace QmlJS;
using namespace QmlJS::Interpreter;
@@ -101,6 +102,12 @@ const Value * ScopeChain::lookup(const QString &name, const ObjectValue **foundI
return m_context->valueOwner()->undefinedValue();
}
const Value *ScopeChain::evaluate(AST::Node *node) const
{
Evaluate evaluator(this);
return evaluator(node);
}
const ObjectValue *ScopeChain::globalScope() const
{
return m_globalScope;

View File

@@ -79,6 +79,7 @@ public:
const ContextPtr &context() const;
const Value *lookup(const QString &name, const ObjectValue **foundInScope = 0) const;
const Value *evaluate(AST::Node *node) const;
const ObjectValue *globalScope() const;
void setGlobalScope(const ObjectValue *globalScope);