From 2967e68f9a3bae4f5a2865ac901b08d8b6f0f0f1 Mon Sep 17 00:00:00 2001 From: Roberto Raggi Date: Thu, 15 Oct 2009 10:18:09 +0200 Subject: Simplified the bindings rewriter. The rewriter needs to know if an ExpressionStatement is part of a loop and an integer is definitely enough for that. --- src/declarative/qml/qmlrewrite.cpp | 27 ++++++++++++++------------- src/declarative/qml/qmlrewrite_p.h | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/declarative/qml/qmlrewrite.cpp b/src/declarative/qml/qmlrewrite.cpp index 19b88cc..43b2529 100644 --- a/src/declarative/qml/qmlrewrite.cpp +++ b/src/declarative/qml/qmlrewrite.cpp @@ -71,6 +71,7 @@ QString RewriteBinding::rewrite(QString code, unsigned position, TextWriter w; _writer = &w; _position = position; + _inLoop = 0; accept(node); @@ -111,7 +112,7 @@ bool RewriteBinding::visit(AST::Block *ast) bool RewriteBinding::visit(AST::ExpressionStatement *ast) { - if (_loopStack.isEmpty()) { + if (! _inLoop) { unsigned startOfExpressionStatement = ast->firstSourceLocation().begin() - _position; _writer->replace(startOfExpressionStatement, 0, QLatin1String("return ")); } @@ -121,68 +122,68 @@ bool RewriteBinding::visit(AST::ExpressionStatement *ast) bool RewriteBinding::visit(AST::DoWhileStatement *ast) { - _loopStack.append(ast); + ++_inLoop; return true; } void RewriteBinding::endVisit(AST::DoWhileStatement *) { - _loopStack.removeLast(); + --_inLoop; } bool RewriteBinding::visit(AST::WhileStatement *ast) { - _loopStack.append(ast); + ++_inLoop; return true; } void RewriteBinding::endVisit(AST::WhileStatement *) { - _loopStack.removeLast(); + --_inLoop; } bool RewriteBinding::visit(AST::ForStatement *ast) { - _loopStack.append(ast); + ++_inLoop; return true; } void RewriteBinding::endVisit(AST::ForStatement *) { - _loopStack.removeLast(); + --_inLoop; } bool RewriteBinding::visit(AST::LocalForStatement *ast) { - _loopStack.append(ast); + ++_inLoop; return true; } void RewriteBinding::endVisit(AST::LocalForStatement *) { - _loopStack.removeLast(); + --_inLoop; } bool RewriteBinding::visit(AST::ForEachStatement *ast) { - _loopStack.append(ast); + ++_inLoop; return true; } void RewriteBinding::endVisit(AST::ForEachStatement *) { - _loopStack.removeLast(); + --_inLoop; } bool RewriteBinding::visit(AST::LocalForEachStatement *ast) { - _loopStack.append(ast); + ++_inLoop; return true; } void RewriteBinding::endVisit(AST::LocalForEachStatement *) { - _loopStack.removeLast(); + --_inLoop; } } // namespace QmlRewrite diff --git a/src/declarative/qml/qmlrewrite_p.h b/src/declarative/qml/qmlrewrite_p.h index 449b219..59057d5 100644 --- a/src/declarative/qml/qmlrewrite_p.h +++ b/src/declarative/qml/qmlrewrite_p.h @@ -99,7 +99,7 @@ protected: virtual void endVisit(AST::LocalForEachStatement *ast); private: - QList _loopStack; + int _inLoop; }; } // namespace QmlRewrite -- cgit v0.12