From 34093064feedcf3c918d482d9cd9121b06d804a4 Mon Sep 17 00:00:00 2001
From: Christian Kamm <christian.d.kamm@nokia.com>
Date: Tue, 23 Nov 2010 14:15:50 +0100
Subject: [PATCH] QmlJS: Make evaluator understand expression statements.

Reviewed-by: Erik Verbruggen
---
 src/libs/qmljs/qmljsbind.cpp             |  8 --------
 src/libs/qmljs/qmljsbind.h               |  2 --
 src/libs/qmljs/qmljsevaluate.cpp         |  2 +-
 src/libs/qmljs/qmljsscopebuilder.cpp     | 17 +++++++----------
 src/plugins/qmljseditor/quicktoolbar.cpp | 18 ++++++++----------
 5 files changed, 16 insertions(+), 31 deletions(-)

diff --git a/src/libs/qmljs/qmljsbind.cpp b/src/libs/qmljs/qmljsbind.cpp
index 249a22edb34..4bc2f193e71 100644
--- a/src/libs/qmljs/qmljsbind.cpp
+++ b/src/libs/qmljs/qmljsbind.cpp
@@ -197,14 +197,6 @@ QString Bind::toString(UiQualifiedId *qualifiedId, QChar delimiter)
     return result;
 }
 
-ExpressionNode *Bind::expression(UiScriptBinding *ast) const
-{
-    if (ExpressionStatement *statement = cast<ExpressionStatement *>(ast->statement))
-        return statement->expression;
-
-    return 0;
-}
-
 ObjectValue *Bind::bindObject(UiQualifiedId *qualifiedTypeNameId, UiObjectInitializer *initializer)
 {
     ObjectValue *parentObjectValue = 0;
diff --git a/src/libs/qmljs/qmljsbind.h b/src/libs/qmljs/qmljsbind.h
index 0ca726e4f4f..a8b85b96ce1 100644
--- a/src/libs/qmljs/qmljsbind.h
+++ b/src/libs/qmljs/qmljsbind.h
@@ -91,8 +91,6 @@ protected:
     Interpreter::ObjectValue *switchObjectValue(Interpreter::ObjectValue *newObjectValue);
     Interpreter::ObjectValue *bindObject(AST::UiQualifiedId *qualifiedTypeNameId, AST::UiObjectInitializer *initializer);
 
-    AST::ExpressionNode *expression(AST::UiScriptBinding *ast) const;
-
 private:
     Document *_doc;
     Interpreter::Engine _engine;
diff --git a/src/libs/qmljs/qmljsevaluate.cpp b/src/libs/qmljs/qmljsevaluate.cpp
index 21c98a4d4c0..15cfd0e44a3 100644
--- a/src/libs/qmljs/qmljsevaluate.cpp
+++ b/src/libs/qmljs/qmljsevaluate.cpp
@@ -450,7 +450,7 @@ bool Evaluate::visit(AST::EmptyStatement *)
 
 bool Evaluate::visit(AST::ExpressionStatement *)
 {
-    return false;
+    return true;
 }
 
 bool Evaluate::visit(AST::IfStatement *)
diff --git a/src/libs/qmljs/qmljsscopebuilder.cpp b/src/libs/qmljs/qmljsscopebuilder.cpp
index 477f82db3b2..77b6dcc5cbf 100644
--- a/src/libs/qmljs/qmljsscopebuilder.cpp
+++ b/src/libs/qmljs/qmljsscopebuilder.cpp
@@ -238,16 +238,13 @@ void ScopeBuilder::setQmlScopeObject(Node *node)
                     if (scriptBinding->qualifiedId && scriptBinding->qualifiedId->name
                             && scriptBinding->qualifiedId->name->asString() == QLatin1String("target")
                             && ! scriptBinding->qualifiedId->next) {
-                        // ### make Evaluate understand statements.
-                        if (ExpressionStatement *expStmt = cast<ExpressionStatement *>(scriptBinding->statement)) {
-                            Evaluate evaluator(_context);
-                            const Value *targetValue = evaluator(expStmt->expression);
-
-                            if (const ObjectValue *target = value_cast<const ObjectValue *>(targetValue)) {
-                                scopeChain.qmlScopeObjects.prepend(target);
-                            } else {
-                                scopeChain.qmlScopeObjects.clear();
-                            }
+                        Evaluate evaluator(_context);
+                        const Value *targetValue = evaluator(scriptBinding->statement);
+
+                        if (const ObjectValue *target = value_cast<const ObjectValue *>(targetValue)) {
+                            scopeChain.qmlScopeObjects.prepend(target);
+                        } else {
+                            scopeChain.qmlScopeObjects.clear();
                         }
                     }
                 }
diff --git a/src/plugins/qmljseditor/quicktoolbar.cpp b/src/plugins/qmljseditor/quicktoolbar.cpp
index bdc622d16c0..b53344a75ce 100644
--- a/src/plugins/qmljseditor/quicktoolbar.cpp
+++ b/src/plugins/qmljseditor/quicktoolbar.cpp
@@ -43,16 +43,14 @@ static inline const Interpreter::ObjectValue * getPropertyChangesTarget(Node *no
         for (UiObjectMemberList *members = initializer->members; members; members = members->next) {
             if (UiScriptBinding *scriptBinding = cast<UiScriptBinding *>(members->member)) {
                 if (scriptBinding->qualifiedId
-                    && scriptBinding->qualifiedId->name->asString() == QLatin1String("target")
-                    && ! scriptBinding->qualifiedId->next) {
-                    if (ExpressionStatement *expressionStatement = cast<ExpressionStatement *>(scriptBinding->statement)) {
-                        Evaluate evaluator(lookupContext->context());
-                        const Interpreter::Value *targetValue = evaluator(expressionStatement->expression);
-                        if (const Interpreter::ObjectValue *targetObject = Interpreter::value_cast<const Interpreter::ObjectValue *>(targetValue)) {
-                            return targetObject;
-                        } else {
-                            return 0;
-                        }
+                        && scriptBinding->qualifiedId->name->asString() == QLatin1String("target")
+                        && ! scriptBinding->qualifiedId->next) {
+                    Evaluate evaluator(lookupContext->context());
+                    const Interpreter::Value *targetValue = evaluator(scriptBinding->statement);
+                    if (const Interpreter::ObjectValue *targetObject = Interpreter::value_cast<const Interpreter::ObjectValue *>(targetValue)) {
+                        return targetObject;
+                    } else {
+                        return 0;
                     }
                 }
             }
-- 
GitLab