diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2009-10-14 10:21:04 (GMT) |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2009-10-14 10:21:04 (GMT) |
commit | f410aa58f93b27a5ba1b82e2f3a87d14338e22a4 (patch) | |
tree | 77a9160e504a04a28d31418274055527f456b901 | |
parent | 712ea07c079c8ac9ea0e397638e7547138b4a087 (diff) | |
download | Qt-f410aa58f93b27a5ba1b82e2f3a87d14338e22a4.zip Qt-f410aa58f93b27a5ba1b82e2f3a87d14338e22a4.tar.gz Qt-f410aa58f93b27a5ba1b82e2f3a87d14338e22a4.tar.bz2 |
Don't rewrite expression statements in loops.
-rw-r--r-- | src/declarative/qml/qmlrewrite.cpp | 72 | ||||
-rw-r--r-- | src/declarative/qml/qmlrewrite_p.h | 22 |
2 files changed, 92 insertions, 2 deletions
diff --git a/src/declarative/qml/qmlrewrite.cpp b/src/declarative/qml/qmlrewrite.cpp index a41b571..19b88cc 100644 --- a/src/declarative/qml/qmlrewrite.cpp +++ b/src/declarative/qml/qmlrewrite.cpp @@ -111,12 +111,80 @@ bool RewriteBinding::visit(AST::Block *ast) bool RewriteBinding::visit(AST::ExpressionStatement *ast) { - unsigned startOfExpressionStatement = ast->firstSourceLocation().begin() - _position; - _writer->replace(startOfExpressionStatement, 0, QLatin1String("return ")); + if (_loopStack.isEmpty()) { + unsigned startOfExpressionStatement = ast->firstSourceLocation().begin() - _position; + _writer->replace(startOfExpressionStatement, 0, QLatin1String("return ")); + } return false; } +bool RewriteBinding::visit(AST::DoWhileStatement *ast) +{ + _loopStack.append(ast); + return true; +} + +void RewriteBinding::endVisit(AST::DoWhileStatement *) +{ + _loopStack.removeLast(); +} + +bool RewriteBinding::visit(AST::WhileStatement *ast) +{ + _loopStack.append(ast); + return true; +} + +void RewriteBinding::endVisit(AST::WhileStatement *) +{ + _loopStack.removeLast(); +} + +bool RewriteBinding::visit(AST::ForStatement *ast) +{ + _loopStack.append(ast); + return true; +} + +void RewriteBinding::endVisit(AST::ForStatement *) +{ + _loopStack.removeLast(); +} + +bool RewriteBinding::visit(AST::LocalForStatement *ast) +{ + _loopStack.append(ast); + return true; +} + +void RewriteBinding::endVisit(AST::LocalForStatement *) +{ + _loopStack.removeLast(); +} + +bool RewriteBinding::visit(AST::ForEachStatement *ast) +{ + _loopStack.append(ast); + return true; +} + +void RewriteBinding::endVisit(AST::ForEachStatement *) +{ + _loopStack.removeLast(); +} + +bool RewriteBinding::visit(AST::LocalForEachStatement *ast) +{ + _loopStack.append(ast); + return true; +} + +void RewriteBinding::endVisit(AST::LocalForEachStatement *) +{ + _loopStack.removeLast(); +} + } // namespace QmlRewrite QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlrewrite_p.h b/src/declarative/qml/qmlrewrite_p.h index b6fe017..449b219 100644 --- a/src/declarative/qml/qmlrewrite_p.h +++ b/src/declarative/qml/qmlrewrite_p.h @@ -76,8 +76,30 @@ protected: void accept(AST::Node *node); QString rewrite(QString code, unsigned position, AST::Statement *node); + virtual bool visit(AST::Block *ast); virtual bool visit(AST::ExpressionStatement *ast); + + virtual bool visit(AST::DoWhileStatement *ast); + virtual void endVisit(AST::DoWhileStatement *ast); + + virtual bool visit(AST::WhileStatement *ast); + virtual void endVisit(AST::WhileStatement *ast); + + virtual bool visit(AST::ForStatement *ast); + virtual void endVisit(AST::ForStatement *ast); + + virtual bool visit(AST::LocalForStatement *ast); + virtual void endVisit(AST::LocalForStatement *ast); + + virtual bool visit(AST::ForEachStatement *ast); + virtual void endVisit(AST::ForEachStatement *ast); + + virtual bool visit(AST::LocalForEachStatement *ast); + virtual void endVisit(AST::LocalForEachStatement *ast); + +private: + QList<AST::Statement *> _loopStack; }; } // namespace QmlRewrite |