forked from qt-creator/qt-creator
QmlJS: Allow lookups on const Contexts. Pass const Contexts where ok.
In preparation for caching Contexts. Reviewed-by: Erik Verbruggen
This commit is contained in:
@@ -84,7 +84,7 @@ Interpreter::ObjectValue *Bind::findQmlObject(AST::Node *node) const
|
||||
}
|
||||
|
||||
bool Bind::usesQmlPrototype(ObjectValue *prototype,
|
||||
Context *context) const
|
||||
const Context *context) const
|
||||
{
|
||||
foreach (ObjectValue *object, _qmlObjects.values()) {
|
||||
const ObjectValue *resolvedPrototype = object->prototype(context);
|
||||
|
@@ -66,7 +66,7 @@ public:
|
||||
|
||||
Interpreter::ObjectValue *findQmlObject(AST::Node *node) const;
|
||||
bool usesQmlPrototype(Interpreter::ObjectValue *prototype,
|
||||
Interpreter::Context *context) const;
|
||||
const Interpreter::Context *context) const;
|
||||
|
||||
Interpreter::ObjectValue *findFunctionScope(AST::FunctionDeclaration *node) const;
|
||||
bool isGroupedPropertyBinding(AST::Node *node) const;
|
||||
|
@@ -36,7 +36,7 @@
|
||||
using namespace QmlJS;
|
||||
using namespace QmlJS::Interpreter;
|
||||
|
||||
Evaluate::Evaluate(Context *context)
|
||||
Evaluate::Evaluate(const Context *context)
|
||||
: _engine(context->engine()),
|
||||
_context(context),
|
||||
_scope(_engine->globalObject()),
|
||||
|
@@ -46,7 +46,7 @@ namespace Interpreter {
|
||||
class QMLJS_EXPORT Evaluate: protected AST::Visitor
|
||||
{
|
||||
public:
|
||||
Evaluate(Interpreter::Context *context);
|
||||
Evaluate(const Interpreter::Context *context);
|
||||
virtual ~Evaluate();
|
||||
|
||||
const Interpreter::Value *operator()(AST::Node *ast);
|
||||
@@ -156,7 +156,7 @@ protected:
|
||||
private:
|
||||
QmlJS::Document::Ptr _doc;
|
||||
Interpreter::Engine *_engine;
|
||||
Interpreter::Context *_context;
|
||||
const Interpreter::Context *_context;
|
||||
const Interpreter::ObjectValue *_scope;
|
||||
const Interpreter::Value *_result;
|
||||
};
|
||||
|
@@ -1455,7 +1455,7 @@ void Context::setTypeEnvironment(const QmlJS::Document *doc, const ObjectValue *
|
||||
_typeEnvironments[doc->fileName()] = typeEnvironment;
|
||||
}
|
||||
|
||||
const Value *Context::lookup(const QString &name)
|
||||
const Value *Context::lookup(const QString &name) const
|
||||
{
|
||||
QList<const ObjectValue *> scopes = _scopeChain.all();
|
||||
for (int index = scopes.size() - 1; index != -1; --index) {
|
||||
@@ -1469,7 +1469,7 @@ const Value *Context::lookup(const QString &name)
|
||||
return _engine->undefinedValue();
|
||||
}
|
||||
|
||||
const ObjectValue *Context::lookupType(const QmlJS::Document *doc, UiQualifiedId *qmlTypeName)
|
||||
const ObjectValue *Context::lookupType(const QmlJS::Document *doc, UiQualifiedId *qmlTypeName) const
|
||||
{
|
||||
const ObjectValue *objectValue = typeEnvironment(doc);
|
||||
if (!objectValue)
|
||||
@@ -1489,7 +1489,7 @@ const ObjectValue *Context::lookupType(const QmlJS::Document *doc, UiQualifiedId
|
||||
return objectValue;
|
||||
}
|
||||
|
||||
const ObjectValue *Context::lookupType(const QmlJS::Document *doc, const QStringList &qmlTypeName)
|
||||
const ObjectValue *Context::lookupType(const QmlJS::Document *doc, const QStringList &qmlTypeName) const
|
||||
{
|
||||
const ObjectValue *objectValue = typeEnvironment(doc);
|
||||
|
||||
@@ -1507,7 +1507,7 @@ const ObjectValue *Context::lookupType(const QmlJS::Document *doc, const QString
|
||||
return objectValue;
|
||||
}
|
||||
|
||||
const Value *Context::lookupReference(const Reference *reference)
|
||||
const Value *Context::lookupReference(const Reference *reference) const
|
||||
{
|
||||
if (_referenceStack.contains(reference))
|
||||
return 0;
|
||||
@@ -1579,7 +1579,7 @@ void Reference::accept(ValueVisitor *visitor) const
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
const Value *Reference::value(Context *) const
|
||||
const Value *Reference::value(const Context *) const
|
||||
{
|
||||
return _engine->undefinedValue();
|
||||
}
|
||||
@@ -1663,7 +1663,7 @@ void ObjectValue::setClassName(const QString &className)
|
||||
_className = className;
|
||||
}
|
||||
|
||||
const ObjectValue *ObjectValue::prototype(Context *context) const
|
||||
const ObjectValue *ObjectValue::prototype(const Context *context) const
|
||||
{
|
||||
const ObjectValue *prototypeObject = value_cast<const ObjectValue *>(_prototype);
|
||||
if (! prototypeObject) {
|
||||
@@ -1700,7 +1700,7 @@ void ObjectValue::accept(ValueVisitor *visitor) const
|
||||
visitor->visit(this);
|
||||
}
|
||||
|
||||
const Value *ObjectValue::property(const QString &name, Context *context) const
|
||||
const Value *ObjectValue::property(const QString &name, const Context *context) const
|
||||
{
|
||||
return lookupMember(name, context);
|
||||
}
|
||||
@@ -1736,7 +1736,7 @@ void ObjectValue::processMembers(MemberProcessor *processor) const
|
||||
}
|
||||
}
|
||||
|
||||
const Value *ObjectValue::lookupMember(const QString &name, Context *context, bool examinePrototypes) const
|
||||
const Value *ObjectValue::lookupMember(const QString &name, const Context *context, bool examinePrototypes) const
|
||||
{
|
||||
if (const Value *m = _members.value(name))
|
||||
return m;
|
||||
@@ -1931,7 +1931,7 @@ const Value *Function::argument(int index) const
|
||||
return _arguments.at(index);
|
||||
}
|
||||
|
||||
const Value *Function::property(const QString &name, Context *context) const
|
||||
const Value *Function::property(const QString &name, const Context *context) const
|
||||
{
|
||||
if (name == "length")
|
||||
return engine()->numberValue();
|
||||
@@ -2955,7 +2955,7 @@ ASTVariableReference::~ASTVariableReference()
|
||||
{
|
||||
}
|
||||
|
||||
const Value *ASTVariableReference::value(Context *context) const
|
||||
const Value *ASTVariableReference::value(const Context *context) const
|
||||
{
|
||||
Evaluate check(context);
|
||||
return check(_ast->expression);
|
||||
@@ -3034,7 +3034,7 @@ UiQualifiedId *QmlPrototypeReference::qmlTypeName() const
|
||||
return _qmlTypeName;
|
||||
}
|
||||
|
||||
const Value *QmlPrototypeReference::value(Context *context) const
|
||||
const Value *QmlPrototypeReference::value(const Context *context) const
|
||||
{
|
||||
return context->lookupType(_doc, _qmlTypeName);
|
||||
}
|
||||
@@ -3061,7 +3061,7 @@ bool ASTPropertyReference::getSourceLocation(QString *fileName, int *line, int *
|
||||
return true;
|
||||
}
|
||||
|
||||
const Value *ASTPropertyReference::value(Context *context) const
|
||||
const Value *ASTPropertyReference::value(const Context *context) const
|
||||
{
|
||||
if (_ast->expression
|
||||
&& (!_ast->memberType || _ast->memberType->asString() == QLatin1String("variant"))) {
|
||||
@@ -3096,7 +3096,7 @@ bool ASTSignalReference::getSourceLocation(QString *fileName, int *line, int *co
|
||||
return true;
|
||||
}
|
||||
|
||||
const Value *ASTSignalReference::value(Context *) const
|
||||
const Value *ASTSignalReference::value(const Context *) const
|
||||
{
|
||||
return engine()->undefinedValue();
|
||||
}
|
||||
|
@@ -281,10 +281,10 @@ public:
|
||||
const ObjectValue *typeEnvironment(const Document *doc) const;
|
||||
void setTypeEnvironment(const Document *doc, const ObjectValue *typeEnvironment);
|
||||
|
||||
const Value *lookup(const QString &name);
|
||||
const ObjectValue *lookupType(const Document *doc, AST::UiQualifiedId *qmlTypeName);
|
||||
const ObjectValue *lookupType(const Document *doc, const QStringList &qmlTypeName);
|
||||
const Value *lookupReference(const Reference *reference);
|
||||
const Value *lookup(const QString &name) const;
|
||||
const ObjectValue *lookupType(const Document *doc, AST::UiQualifiedId *qmlTypeName) const;
|
||||
const ObjectValue *lookupType(const Document *doc, const QStringList &qmlTypeName) const;
|
||||
const Value *lookupReference(const Reference *reference) const;
|
||||
|
||||
const Value *property(const ObjectValue *object, const QString &name) const;
|
||||
void setProperty(const ObjectValue *object, const QString &name, const Value *value);
|
||||
@@ -304,7 +304,9 @@ private:
|
||||
ScopeChain _scopeChain;
|
||||
int _qmlScopeObjectIndex;
|
||||
bool _qmlScopeObjectSet;
|
||||
QList<const Reference *> _referenceStack;
|
||||
|
||||
// for avoiding reference cycles during lookup
|
||||
mutable QList<const Reference *> _referenceStack;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT Reference: public Value
|
||||
@@ -320,7 +322,7 @@ public:
|
||||
virtual void accept(ValueVisitor *) const;
|
||||
|
||||
private:
|
||||
virtual const Value *value(Context *context) const;
|
||||
virtual const Value *value(const Context *context) const;
|
||||
|
||||
Engine *_engine;
|
||||
friend class Context;
|
||||
@@ -353,16 +355,16 @@ public:
|
||||
QString className() const;
|
||||
void setClassName(const QString &className);
|
||||
|
||||
const ObjectValue *prototype(Context *context) const;
|
||||
const ObjectValue *prototype(const Context *context) const;
|
||||
void setPrototype(const Value *prototype);
|
||||
|
||||
virtual void processMembers(MemberProcessor *processor) const;
|
||||
|
||||
virtual const Value *property(const QString &name, Context *context) const;
|
||||
virtual const Value *property(const QString &name, const Context *context) const;
|
||||
virtual void setProperty(const QString &name, const Value *value);
|
||||
virtual void removeProperty(const QString &name);
|
||||
|
||||
virtual const Value *lookupMember(const QString &name, Context *context, bool examinePrototypes = true) const;
|
||||
virtual const Value *lookupMember(const QString &name, const Context *context, bool examinePrototypes = true) const;
|
||||
|
||||
// Value interface
|
||||
virtual const ObjectValue *asObjectValue() const;
|
||||
@@ -487,7 +489,7 @@ public:
|
||||
void setReturnValue(const Value *returnValue);
|
||||
|
||||
// ObjectValue interface
|
||||
virtual const Value *property(const QString &name, Context *context) const;
|
||||
virtual const Value *property(const QString &name, const Context *context) const;
|
||||
|
||||
// FunctionValue interface
|
||||
virtual const Value *returnValue() const;
|
||||
@@ -748,7 +750,7 @@ public:
|
||||
AST::UiQualifiedId *qmlTypeName() const;
|
||||
|
||||
private:
|
||||
virtual const Value *value(Context *context) const;
|
||||
virtual const Value *value(const Context *context) const;
|
||||
|
||||
AST::UiQualifiedId *_qmlTypeName;
|
||||
const Document *_doc;
|
||||
@@ -763,7 +765,7 @@ public:
|
||||
virtual ~ASTVariableReference();
|
||||
|
||||
private:
|
||||
virtual const Value *value(Context *context) const;
|
||||
virtual const Value *value(const Context *context) const;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT ASTFunctionValue: public FunctionValue
|
||||
@@ -803,7 +805,7 @@ public:
|
||||
virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
||||
|
||||
private:
|
||||
virtual const Value *value(Context *context) const;
|
||||
virtual const Value *value(const Context *context) const;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT ASTSignalReference: public Reference
|
||||
@@ -822,7 +824,7 @@ public:
|
||||
virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
||||
|
||||
private:
|
||||
virtual const Value *value(Context *context) const;
|
||||
virtual const Value *value(const Context *context) const;
|
||||
};
|
||||
|
||||
class QMLJS_EXPORT ASTObjectValue: public ObjectValue
|
||||
|
@@ -82,7 +82,7 @@ Interpreter::Engine *LookupContext::engine() const
|
||||
return &d->interp;
|
||||
}
|
||||
|
||||
Interpreter::Context *LookupContext::context() const
|
||||
const Interpreter::Context *LookupContext::context() const
|
||||
{
|
||||
return &d->context;
|
||||
}
|
||||
|
@@ -60,7 +60,7 @@ public:
|
||||
|
||||
const Interpreter::Value *evaluate(AST::Node *node) const;
|
||||
Interpreter::Engine *engine() const;
|
||||
Interpreter::Context *context() const;
|
||||
const Interpreter::Context *context() const;
|
||||
|
||||
private:
|
||||
QScopedPointer<LookupContextData> d;
|
||||
|
@@ -194,7 +194,7 @@ const Value *ScopeBuilder::scopeObjectLookup(AST::UiQualifiedId *id)
|
||||
}
|
||||
|
||||
|
||||
const ObjectValue *ScopeBuilder::isPropertyChangesObject(Context *context,
|
||||
const ObjectValue *ScopeBuilder::isPropertyChangesObject(const Context *context,
|
||||
const ObjectValue *object)
|
||||
{
|
||||
const ObjectValue *prototype = object;
|
||||
|
@@ -56,7 +56,7 @@ public:
|
||||
void push(const QList<AST::Node *> &nodes);
|
||||
void pop();
|
||||
|
||||
static const Interpreter::ObjectValue *isPropertyChangesObject(Interpreter::Context *context, const Interpreter::ObjectValue *object);
|
||||
static const Interpreter::ObjectValue *isPropertyChangesObject(const Interpreter::Context *context, const Interpreter::ObjectValue *object);
|
||||
|
||||
private:
|
||||
void setQmlScopeObject(AST::Node *node);
|
||||
|
@@ -168,11 +168,11 @@ class EnumerateProperties: private Interpreter::MemberProcessor
|
||||
QHash<QString, const Interpreter::Value *> _properties;
|
||||
bool _globalCompletion;
|
||||
bool _enumerateGeneratedSlots;
|
||||
Interpreter::Context *_context;
|
||||
const Interpreter::Context *_context;
|
||||
const Interpreter::ObjectValue *_currentObject;
|
||||
|
||||
public:
|
||||
EnumerateProperties(Interpreter::Context *context)
|
||||
EnumerateProperties(const Interpreter::Context *context)
|
||||
: _globalCompletion(false),
|
||||
_enumerateGeneratedSlots(false),
|
||||
_context(context),
|
||||
@@ -692,7 +692,7 @@ int CodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
||||
|
||||
const QList<AST::Node *> path = semanticInfo.astPath(editor->position());
|
||||
LookupContext::Ptr lookupContext = LookupContext::create(document, snapshot, path);
|
||||
Interpreter::Context *context = lookupContext->context();
|
||||
const Interpreter::Context *context = lookupContext->context();
|
||||
|
||||
// Search for the operator that triggered the completion.
|
||||
QChar completionOperator;
|
||||
|
@@ -251,7 +251,7 @@ void HoverHandler::operateTooltip(TextEditor::ITextEditor *editor, const QPoint
|
||||
}
|
||||
|
||||
QString HoverHandler::prettyPrint(const QmlJS::Interpreter::Value *value,
|
||||
QmlJS::Interpreter::Context *context)
|
||||
const QmlJS::Interpreter::Context *context)
|
||||
{
|
||||
if (! value)
|
||||
return QString();
|
||||
|
@@ -75,7 +75,7 @@ private:
|
||||
QmlJS::AST::Node *node);
|
||||
|
||||
QString prettyPrint(const QmlJS::Interpreter::Value *value,
|
||||
QmlJS::Interpreter::Context *context);
|
||||
const QmlJS::Interpreter::Context *context);
|
||||
|
||||
QmlJS::ModelManagerInterface *m_modelManager;
|
||||
QColor m_colorTip;
|
||||
|
@@ -108,7 +108,7 @@ QmlOutlineItem &QmlOutlineItem::copyValues(const QmlOutlineItem &other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
QString QmlOutlineItem::prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Context *context) const
|
||||
QString QmlOutlineItem::prettyPrint(const QmlJS::Interpreter::Value *value, const QmlJS::Interpreter::Context *context) const
|
||||
{
|
||||
if (! value)
|
||||
return QString();
|
||||
|
@@ -46,7 +46,7 @@ public:
|
||||
QmlOutlineItem ©Values(const QmlOutlineItem &other); // so that we can assign all values at onc
|
||||
|
||||
private:
|
||||
QString prettyPrint(const QmlJS::Interpreter::Value *value, QmlJS::Interpreter::Context *context) const;
|
||||
QString prettyPrint(const QmlJS::Interpreter::Value *value, const QmlJS::Interpreter::Context *context) const;
|
||||
|
||||
QmlOutlineModel *m_outlineModel;
|
||||
QmlJS::AST::Node *m_node;
|
||||
|
Reference in New Issue
Block a user