Commit ff092f79 authored by Christian Kamm's avatar Christian Kamm

QmlJS: Remove LookupContext.

Use Context or ScopeChain instead.

Change-Id: I2489477eac08774ba41710ee81876aab11b5af24
Reviewed-on: http://codereview.qt.nokia.com/1699Reviewed-by: default avatarFawzi Mohamed <fawzi.mohamed@nokia.com>
parent 76be3002
......@@ -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 \
......
......@@ -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;
......
/**************************************************************************
**
** 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;
}
/**************************************************************************
**
** 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
......@@ -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;
......
......@@ -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);
......
......@@ -51,6 +51,9 @@ namespace QmlJS {
class DiagnosticMessage;
class LookupContext;
class Document;
namespace Interpreter {
class ScopeChain;
}
}
......@@ -186,7 +189,7 @@ public:
bool renameId(const QString& oldId, const QString& newId);
QmlJS::LookupContext *lookupContext() const;
const QmlJS::Interpreter::ScopeChain &scopeChain() const;
QmlJS::Document *document() const;
QString convertTypeToImportAlias(const QString &type) const;
......
......@@ -46,10 +46,10 @@
#include <QDeclarativeEngine>
#include <QDeclarativeComponent>
#include <qmljs/qmljslookupcontext.h>
#include <qmljs/qmljsdocument.h>
#include <qmljs/qmljscontext.h>
#include <qmljs/qmljsbind.h>
#include <qmljs/qmljsscopechain.h>
#include <qmljs/parser/qmljsast_p.h>
#include <languageutils/fakemetaobject.h>
#include <private/qdeclarativemetatype_p.h>
......@@ -135,7 +135,7 @@ static inline bool isValueType(const QString &type)
return objectValuesList.contains(type);
}
const Interpreter::QmlObjectValue *findQmlPrototype(const Interpreter::ObjectValue *ov, LookupContext *context)
const Interpreter::QmlObjectValue *findQmlPrototype(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context)
{
if (!ov)
return 0;
......@@ -144,15 +144,15 @@ const Interpreter::QmlObjectValue *findQmlPrototype(const Interpreter::ObjectVal
if (qmlValue)
return qmlValue;
return findQmlPrototype(ov->prototype(context->context()), context);
return findQmlPrototype(ov->prototype(context), context);
}
QStringList prototypes(const Interpreter::ObjectValue *ov, LookupContext::Ptr context, bool versions = false)
QStringList prototypes(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context, bool versions = false)
{
QStringList list;
if (!ov)
return list;
ov = ov->prototype(context->context());
ov = ov->prototype(context);
while (ov) {
const Interpreter::QmlObjectValue * qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(ov);
if (qmlValue) {
......@@ -170,14 +170,14 @@ QStringList prototypes(const Interpreter::ObjectValue *ov, LookupContext::Ptr co
list << ov->className();
}
}
ov = ov->prototype(context->context());
ov = ov->prototype(context);
}
return list;
}
QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, LookupContext *context, bool local = false);
QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context, bool local = false);
QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupContext *context, bool local = false)
QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, const Interpreter::ContextPtr &context, bool local = false)
{
QList<PropertyInfo> list;
if (!ov)
......@@ -192,7 +192,7 @@ QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupCon
QString name = property.first;
if (!ov->isWritable(name) && ov->isPointer(name)) {
//dot property
const Interpreter::QmlObjectValue * qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(ov->lookupMember(name, context->context()));
const Interpreter::QmlObjectValue * qmlValue = dynamic_cast<const Interpreter::QmlObjectValue *>(ov->lookupMember(name, context));
if (qmlValue) {
QList<PropertyInfo> dotProperties = getQmlTypes(qmlValue, context);
foreach (const PropertyInfo &propertyInfo, dotProperties) {
......@@ -204,7 +204,7 @@ QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupCon
}
}
if (isValueType(ov->propertyType(name))) {
const Interpreter::ObjectValue *dotObjectValue = dynamic_cast<const Interpreter::ObjectValue *>(ov->lookupMember(name, context->context()));
const Interpreter::ObjectValue *dotObjectValue = dynamic_cast<const Interpreter::ObjectValue *>(ov->lookupMember(name, context));
if (dotObjectValue) {
QList<PropertyInfo> dotProperties = getObjectTypes(dotObjectValue, context);
foreach (const PropertyInfo &propertyInfo, dotProperties) {
......@@ -222,7 +222,7 @@ QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupCon
}
if (!local) {
const Interpreter::ObjectValue* prototype = ov->prototype(context->context());
const Interpreter::ObjectValue* prototype = ov->prototype(context);
const Interpreter::QmlObjectValue * qmlObjectValue = dynamic_cast<const Interpreter::QmlObjectValue *>(prototype);
......@@ -236,7 +236,7 @@ QList<PropertyInfo> getQmlTypes(const Interpreter::QmlObjectValue *ov, LookupCon
return list;
}
QList<PropertyInfo> getTypes(const Interpreter::ObjectValue *ov, LookupContext *context, bool local = false)
QList<PropertyInfo> getTypes(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context, bool local = false)
{
QList<PropertyInfo> list;
......@@ -251,7 +251,7 @@ QList<PropertyInfo> getTypes(const Interpreter::ObjectValue *ov, LookupContext *
return list;
}
QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, LookupContext *context, bool local)
QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, const Interpreter::ContextPtr &context, bool local)
{
QList<PropertyInfo> list;
if (!ov)
......@@ -262,7 +262,7 @@ QList<PropertyInfo> getObjectTypes(const Interpreter::ObjectValue *ov, LookupCon
list << processor.properties();
if (!local) {
const Interpreter::ObjectValue* prototype = ov->prototype(context->context());
const Interpreter::ObjectValue* prototype = ov->prototype(context);
const Interpreter::QmlObjectValue * qmlObjectValue = dynamic_cast<const Interpreter::QmlObjectValue *>(prototype);
......@@ -381,7 +381,7 @@ private:
QSet<QString> m_prototypeCacheNegatives;
//storing the pointer would not be save
QmlJS::LookupContext *lookupContext() const;
QmlJS::Interpreter::ContextPtr context() const;
QmlJS::Document *document() const;
QPointer<Model> m_model;
......@@ -423,11 +423,11 @@ NodeMetaInfoPrivate::NodeMetaInfoPrivate(Model *model, QString type, int maj, in
m_minorVersion(min), m_isValid(false), m_isComponent(false),
m_model(model)
{
if (lookupContext()) {
if (context()) {
const Interpreter::QmlObjectValue *objectValue = getQmlObjectValue();
if (objectValue) {
setupPropertyInfo(getTypes(objectValue, lookupContext()));
setupLocalPropertyInfo(getTypes(objectValue, lookupContext(), true));
setupPropertyInfo(getTypes(objectValue, context()));
setupLocalPropertyInfo(getTypes(objectValue, context(), true));
m_defaultPropertyName = objectValue->defaultPropertyName();
setupPrototypes();
m_isValid = true;
......@@ -442,9 +442,9 @@ NodeMetaInfoPrivate::NodeMetaInfoPrivate(Model *model, QString type, int maj, in
} else {
m_isComponent = true;
}
setupPropertyInfo(getTypes(objectValue, lookupContext()));
setupLocalPropertyInfo(getTypes(objectValue, lookupContext(), true));
m_defaultPropertyName = lookupContext()->context()->defaultPropertyName(objectValue);
setupPropertyInfo(getTypes(objectValue, context()));
setupLocalPropertyInfo(getTypes(objectValue, context(), true));
m_defaultPropertyName = context()->defaultPropertyName(objectValue);
setupPrototypes();
m_isValid = true;
}
......@@ -466,7 +466,7 @@ static inline QString getUrlFromType(const QString& typeName)
const QmlJS::Interpreter::QmlObjectValue *NodeMetaInfoPrivate::getQmlObjectValue() const
{
QmlJS::Interpreter::QmlObjectValue * value = lookupContext()->valueOwner()->cppQmlTypes().typeByQualifiedName(lookupName());
QmlJS::Interpreter::QmlObjectValue * value = context()->valueOwner()->cppQmlTypes().typeByQualifiedName(lookupName());
if (value)
return value;
......@@ -490,14 +490,12 @@ const QmlJS::Interpreter::QmlObjectValue *NodeMetaInfoPrivate::getQmlObjectValue
LanguageUtils::ComponentVersion version(9999, 9999);
//get the correct version
Document::Ptr doc = lookupContext()->document();
const Interpreter::Context *context = lookupContext()->context().data();
Interpreter::ImportInfo importInfo = context->imports(doc.data())->info(fullQualifiedImportAliasType(), context);
Interpreter::ImportInfo importInfo = context()->imports(document())->info(fullQualifiedImportAliasType(), context().data());
if (importInfo.isValid())
version = importInfo.version();
QList<Interpreter::QmlObjectValue *> qmlObjectValues = lookupContext()->valueOwner()->cppQmlTypes().typesForImport(package, version);
QList<Interpreter::QmlObjectValue *> qmlObjectValues = context()->valueOwner()->cppQmlTypes().typesForImport(package, version);
const Interpreter::QmlObjectValue *qmlValue = 0;
foreach (Interpreter::QmlObjectValue *value, qmlObjectValues) {
if (value->className() == type)
......@@ -525,15 +523,15 @@ const QmlJS::Interpreter::QmlObjectValue *NodeMetaInfoPrivate::getQmlObjectValue
const QmlJS::Interpreter::ObjectValue *NodeMetaInfoPrivate::getObjectValue() const
{
return lookupContext()->context()->lookupType(document(), lookupNameComponent());
return context()->lookupType(document(), lookupNameComponent());
}
QmlJS::LookupContext *NodeMetaInfoPrivate::lookupContext() const
QmlJS::Interpreter::ContextPtr NodeMetaInfoPrivate::context() const
{
if (m_model && m_model->rewriterView()) {
return m_model->rewriterView()->lookupContext();
return m_model->rewriterView()->scopeChain().context();
}
return 0;
return QmlJS::Interpreter::ContextPtr(0);
}
QmlJS::Document *NodeMetaInfoPrivate::document() const
......@@ -670,7 +668,7 @@ bool NodeMetaInfoPrivate::isPropertyEnum(const QString &propertyName) const
}
QList<const Interpreter::ObjectValue *> objects;
objects = Interpreter::PrototypeIterator(getNearestQmlObjectValue(), lookupContext()->context()).all();
objects = Interpreter::PrototypeIterator(getNearestQmlObjectValue(), context()).all();
//We have to run the prototype chain
foreach (const Interpreter::ObjectValue *ov, objects) {
......@@ -706,7 +704,7 @@ QString NodeMetaInfoPrivate::propertyEnumScope(const QString &propertyName) cons
}
QList<const Interpreter::ObjectValue *> objects;
objects = Interpreter::PrototypeIterator(getNearestQmlObjectValue(), lookupContext()->context()).all();
objects = Interpreter::PrototypeIterator(getNearestQmlObjectValue(), context()).all();
//We have to run the prototype chain
foreach (const Interpreter::ObjectValue *ov, objects) {
......@@ -849,7 +847,7 @@ QStringList NodeMetaInfoPrivate::lookupNameComponent() const
bool NodeMetaInfoPrivate::isValid() const
{
return m_isValid && lookupContext() && document();
return m_isValid && context() && document();
}
QString NodeMetaInfoPrivate::propertyType(const QString &propertyName) const
......@@ -863,9 +861,9 @@ void NodeMetaInfoPrivate::setupPrototypes()
{
QList<const Interpreter::ObjectValue *> objects;
if (m_isComponent)
objects = Interpreter::PrototypeIterator(getObjectValue(), lookupContext()->context()).all();
objects = Interpreter::PrototypeIterator(getObjectValue(), context()).all();
else
objects = Interpreter::PrototypeIterator(getQmlObjectValue(), lookupContext()->context()).all();
objects = Interpreter::PrototypeIterator(getQmlObjectValue(), context()).all();
foreach (const Interpreter::ObjectValue *ov, objects) {
TypeDescription description;
description.className = ov->className();
......@@ -878,7 +876,7 @@ void NodeMetaInfoPrivate::setupPrototypes()
description.className = qmlValue->packageName() + '.' + description.className;
m_prototypes.append(description);
} else {
if (lookupContext()->context()->lookupType(document(), QStringList() << ov->className()))
if (context()->lookupType(document(), QStringList() << ov->className()))
m_prototypes.append(description);
}
}
......@@ -893,7 +891,7 @@ QList<TypeDescription> NodeMetaInfoPrivate::prototypes() const
const QmlJS::Interpreter::QmlObjectValue *NodeMetaInfoPrivate::getNearestQmlObjectValue() const
{
if (m_isComponent)
return findQmlPrototype(getObjectValue(), lookupContext());
return findQmlPrototype(getObjectValue(), context());
return getQmlObjectValue();
}
......
......@@ -624,9 +624,9 @@ bool RewriterView::renameId(const QString& oldId, const QString& newId)
return false;
}
QmlJS::LookupContext *RewriterView::lookupContext() const
const QmlJS::Interpreter::ScopeChain &RewriterView::scopeChain() const
{
return textToModelMerger()->lookupContext();
return textToModelMerger()->scopeChain();
}
QmlJS::Document *RewriterView::document() const
......
......@@ -340,7 +340,6 @@ public:
, m_scopeChain(doc, m_context)
, m_scopeBuilder(&m_scopeChain)
{
m_lookupContext = LookupContext::create(doc, m_context, QList<AST::Node*>());
}
~ReadingContext()
......@@ -384,7 +383,7 @@ public:
majorVersion = ComponentVersion::NoVersion;
minorVersion = ComponentVersion::NoVersion;
const Interpreter::Imports *imports = m_lookupContext->