aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qdeclarativescriptparser.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2011-05-12 11:31:31 +0200
committerRoberto Raggi <roberto.raggi@nokia.com>2011-05-12 11:31:31 +0200
commitf31d94f2d4438106558dede0de1a423cade960a9 (patch)
tree4adc37849f713cf7e343b43fab030630369aa01f /src/declarative/qml/qdeclarativescriptparser.cpp
parent35559a2f00fc9bf609144a6bba3f0a678f61cd12 (diff)
Fix the QML front-end to allow side effects in the initializer.
Task-number: QTBUG-15117
Diffstat (limited to 'src/declarative/qml/qdeclarativescriptparser.cpp')
-rw-r--r--src/declarative/qml/qdeclarativescriptparser.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/declarative/qml/qdeclarativescriptparser.cpp b/src/declarative/qml/qdeclarativescriptparser.cpp
index e9be923053..c2cdbb0d98 100644
--- a/src/declarative/qml/qdeclarativescriptparser.cpp
+++ b/src/declarative/qml/qdeclarativescriptparser.cpp
@@ -127,6 +127,7 @@ protected:
LocationSpan location,
AST::UiObjectInitializer *initializer = 0);
+ QDeclarativeParser::Variant getVariant(AST::Statement *stmt);
QDeclarativeParser::Variant getVariant(AST::ExpressionNode *expr);
LocationSpan location(AST::SourceLocation start, AST::SourceLocation end);
@@ -604,16 +605,16 @@ bool ProcessAST::visit(AST::UiPublicMember *node)
property.location = location(node->firstSourceLocation(),
node->lastSourceLocation());
- if (node->expression) { // default value
+ if (node->statement) { // default value
property.defaultValue = new Property;
property.defaultValue->parent = _stateStack.top().object;
property.defaultValue->location =
- location(node->expression->firstSourceLocation(),
- node->expression->lastSourceLocation());
+ location(node->statement->firstSourceLocation(),
+ node->statement->lastSourceLocation());
QDeclarativeParser::Value *value = new QDeclarativeParser::Value;
- value->location = location(node->expression->firstSourceLocation(),
- node->expression->lastSourceLocation());
- value->value = getVariant(node->expression);
+ value->location = location(node->statement->firstSourceLocation(),
+ node->statement->lastSourceLocation());
+ value->value = getVariant(node->statement);
property.defaultValue->values << value;
}
@@ -658,6 +659,18 @@ bool ProcessAST::visit(AST::UiObjectBinding *node)
return false;
}
+QDeclarativeParser::Variant ProcessAST::getVariant(AST::Statement *stmt)
+{
+ if (stmt) {
+ if (AST::ExpressionStatement *exprStmt = AST::cast<AST::ExpressionStatement *>(stmt))
+ return getVariant(exprStmt->expression);
+
+ return QDeclarativeParser::Variant(asString(stmt), stmt);
+ }
+
+ return QDeclarativeParser::Variant();
+}
+
QDeclarativeParser::Variant ProcessAST::getVariant(AST::ExpressionNode *expr)
{
if (AST::StringLiteral *lit = AST::cast<AST::StringLiteral *>(expr)) {