diff options
Diffstat (limited to 'src/declarative/qml/qmlscriptparser.cpp')
-rw-r--r-- | src/declarative/qml/qmlscriptparser.cpp | 79 |
1 files changed, 32 insertions, 47 deletions
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 169e2ea..4de9e40 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -74,8 +74,8 @@ protected: AST::SourceLocation typeLocation, LocationSpan location, AST::UiObjectInitializer *initializer = 0); - QString getPrimitive(const QByteArray &propertyName, AST::ExpressionNode *expr); - void defineProperty(const QString &propertyName, const LocationSpan &location, const QString &primitive); + + QmlParser::Variant getVariant(AST::ExpressionNode *expr); LocationSpan location(AST::SourceLocation start, AST::SourceLocation end); LocationSpan location(AST::UiQualifiedId *); @@ -305,15 +305,22 @@ Object *ProcessAST::defineObjectBinding(int line, QString propertyName = asString(scriptBinding->qualifiedId); if (propertyName == QLatin1String("script")) { QString script; + if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) { - script = getPrimitive("script", stmt->expression); + script = getVariant(stmt->expression).asScript(); } else { script = asString(scriptBinding->statement); } LocationSpan l = this->location(scriptBinding->statement->firstSourceLocation(), scriptBinding->statement->lastSourceLocation()); - defineProperty(QLatin1String("script"), l, script); + + _stateStack.pushProperty(QLatin1String("script"), l); + Value *value = new Value; + value->value = QmlParser::Variant(script); + value->location = l; + currentProperty()->addValue(value); + _stateStack.pop(); } else { accept(it->member); } @@ -342,16 +349,6 @@ LocationSpan ProcessAST::location(AST::SourceLocation start, AST::SourceLocation return rv; } -void ProcessAST::defineProperty(const QString &propertyName, const LocationSpan &location, const QString &primitive) -{ - _stateStack.pushProperty(propertyName, location); - Value *value = new Value; - value->primitive = primitive; - value->location = location; - currentProperty()->addValue(value); - _stateStack.pop(); -} - // UiProgram: UiImportListOpt UiObjectMemberList ; bool ProcessAST::visit(AST::UiProgram *node) { @@ -436,7 +433,7 @@ bool ProcessAST::visit(AST::UiPublicMember *node) Value *value = new Value; value->location = location(node->expression->firstSourceLocation(), node->expression->lastSourceLocation()); - value->primitive = getPrimitive("value", node->expression); + value->value = getVariant(node->expression); property.defaultValue->values << value; } @@ -480,30 +477,25 @@ bool ProcessAST::visit(AST::UiObjectBinding *node) return false; } -QString ProcessAST::getPrimitive(const QByteArray &propertyName, AST::ExpressionNode *expr) +QmlParser::Variant ProcessAST::getVariant(AST::ExpressionNode *expr) { - QString primitive; + QmlParser::Variant rv; - if (isSignalProperty(propertyName)) { - primitive = asString(expr); - } else if (propertyName == "id" && expr && expr->kind == AST::Node::Kind_IdentifierExpression) { - primitive = asString(expr); - } else if (AST::StringLiteral *lit = AST::cast<AST::StringLiteral *>(expr)) { + if (AST::StringLiteral *lit = AST::cast<AST::StringLiteral *>(expr)) { // hack: emulate weird XML feature that string literals are not quoted. //This needs to be fixed in the qmlcompiler once xml goes away. - primitive = lit->value->asString(); - } else if (expr->kind == AST::Node::Kind_TrueLiteral - || expr->kind == AST::Node::Kind_FalseLiteral - || expr->kind == AST::Node::Kind_NumericLiteral - ) { - primitive = asString(expr); + rv = QmlParser::Variant(lit->value->asString()); + } else if (expr->kind == AST::Node::Kind_TrueLiteral) { + rv = QmlParser::Variant(true); + } else if (expr->kind == AST::Node::Kind_FalseLiteral) { + rv = QmlParser::Variant(false); + } else if(AST::NumericLiteral *lit = AST::cast<AST::NumericLiteral *>(expr)) { + rv = QmlParser::Variant(lit->value); } else { - // create a binding - primitive += QLatin1Char('{'); - primitive += asString(expr); - primitive += QLatin1Char('}'); + rv = QmlParser::Variant(asString(expr), QmlParser::Variant::Script); } - return primitive; + + return rv; } @@ -519,25 +511,18 @@ bool ProcessAST::visit(AST::UiScriptBinding *node) } Property *prop = currentProperty(); - QString primitive; + + QmlParser::Variant primitive; if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(node->statement)) { - primitive = getPrimitive(prop->name, stmt->expression); - } else if (isSignalProperty(prop->name)) { - if (AST::Block *block = AST::cast<AST::Block *>(node->statement)) { - const int start = block->lbraceToken.offset + block->rbraceToken.length; - primitive += _contents.mid(start, block->rbraceToken.offset - start); - } else { - primitive += asString(node->statement); - } + primitive = getVariant(stmt->expression); } else { // do binding - primitive += QLatin1Char('{'); - primitive += asString(node->statement); - primitive += QLatin1Char('}'); + primitive = QmlParser::Variant(asString(node->statement), + QmlParser::Variant::Script); } Value *v = new Value; - v->primitive = primitive; + v->value = primitive; v->location = location(node->statement->firstSourceLocation(), node->statement->lastSourceLocation()); @@ -616,7 +601,7 @@ bool ProcessAST::visit(AST::UiSourceElement *node) Value *value = new Value; value->location = location(node->firstSourceLocation(), node->lastSourceLocation()); - value->primitive = source; + value->value = QmlParser::Variant(source); obj->getDefaultProperty()->addValue(value); } |