From ed1321a4f95d4ecbbd96794ec355cfc7984cfb2d Mon Sep 17 00:00:00 2001 From: Christian Kamm <christian.d.kamm@nokia.com> Date: Mon, 8 Aug 2011 10:54:48 +0200 Subject: [PATCH] QmlJS: Resolve references while evaluating expressions. Task-number: QTCREATORBUG-5752 Change-Id: Ibcdaac039a5e862d7a8f03f58c8bf017b544e436 Reviewed-on: http://codereview.qt.nokia.com/2736 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com> --- src/libs/qmljs/qmljsevaluate.cpp | 13 +++++++++---- src/libs/qmljs/qmljsevaluate.h | 5 ++++- src/plugins/qmljseditor/qmljscompletionassist.cpp | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/libs/qmljs/qmljsevaluate.cpp b/src/libs/qmljs/qmljsevaluate.cpp index 955ef7dc562..410d3d3a383 100644 --- a/src/libs/qmljs/qmljsevaluate.cpp +++ b/src/libs/qmljs/qmljsevaluate.cpp @@ -52,6 +52,11 @@ Evaluate::~Evaluate() } const Interpreter::Value *Evaluate::operator()(AST::Node *ast) +{ + return value(ast); +} + +const Interpreter::Value *Evaluate::value(AST::Node *ast) { const Value *result = reference(ast); @@ -304,7 +309,7 @@ bool Evaluate::visit(AST::FieldMemberExpression *ast) if (! ast->name) return false; - if (const Interpreter::Value *base = _valueOwner->convertToObject(reference(ast->base))) { + if (const Interpreter::Value *base = _valueOwner->convertToObject(value(ast->base))) { if (const Interpreter::ObjectValue *obj = base->asObjectValue()) { _result = obj->lookupMember(ast->name->asString(), _context); } @@ -315,7 +320,7 @@ bool Evaluate::visit(AST::FieldMemberExpression *ast) bool Evaluate::visit(AST::NewMemberExpression *ast) { - if (const FunctionValue *ctor = value_cast<const FunctionValue *>(reference(ast->base))) { + if (const FunctionValue *ctor = value_cast<const FunctionValue *>(value(ast->base))) { _result = ctor->construct(); } return false; @@ -323,7 +328,7 @@ bool Evaluate::visit(AST::NewMemberExpression *ast) bool Evaluate::visit(AST::NewExpression *ast) { - if (const FunctionValue *ctor = value_cast<const FunctionValue *>(reference(ast->expression))) { + if (const FunctionValue *ctor = value_cast<const FunctionValue *>(value(ast->expression))) { _result = ctor->construct(); } return false; @@ -331,7 +336,7 @@ bool Evaluate::visit(AST::NewExpression *ast) bool Evaluate::visit(AST::CallExpression *ast) { - if (const Interpreter::Value *base = reference(ast->base)) { + if (const Interpreter::Value *base = value(ast->base)) { if (const Interpreter::FunctionValue *obj = base->asFunctionValue()) { _result = obj->returnValue(); } diff --git a/src/libs/qmljs/qmljsevaluate.h b/src/libs/qmljs/qmljsevaluate.h index ab69404c2ca..b7fc24fabe3 100644 --- a/src/libs/qmljs/qmljsevaluate.h +++ b/src/libs/qmljs/qmljsevaluate.h @@ -52,9 +52,12 @@ public: Evaluate(const Interpreter::Context *context); virtual ~Evaluate(); - // evaluate ast in the given context + // same as value() const Interpreter::Value *operator()(AST::Node *ast); + // evaluate ast in the given context, resolving references + const Interpreter::Value *value(AST::Node *ast); + // evaluate, but stop when encountering a Reference const Interpreter::Value *reference(AST::Node *ast); diff --git a/src/plugins/qmljseditor/qmljscompletionassist.cpp b/src/plugins/qmljseditor/qmljscompletionassist.cpp index 1784c3cb9d8..031447eb5f8 100644 --- a/src/plugins/qmljseditor/qmljscompletionassist.cpp +++ b/src/plugins/qmljseditor/qmljscompletionassist.cpp @@ -616,7 +616,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const IAssistInterface Interpreter::ValueOwner *interp = lookupContext->valueOwner(); const Interpreter::Value *value = interp->convertToObject(lookupContext->evaluate(expression)); - //qDebug() << "type:" << interp.typeId(value); + //qDebug() << "type:" << interp->typeId(value); if (value && completionOperator == QLatin1Char('.')) { // member completion EnumerateProperties enumerateProperties(context); -- GitLab