diff options
author | Simon Hausmann <simon.hausmann@digia.com> | 2013-09-30 09:41:35 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-30 18:23:17 +0200 |
commit | 23793482e9b187441203fb629b459245c504dfba (patch) | |
tree | 193d26239f7235ed2d0926f63b97b5b532c3b48b /src/qml/compiler | |
parent | 7df73c27121149c36a6c8a21850d85728ea79ad5 (diff) |
Fix invalid alias error reporting in new compiler
Match exactly the VME code path by reporting the right type of error
as well as the right hand side of the alias binding if necessary.
Change-Id: I35d192a20641e0acbf25d20f3dc5fb53cc7cbae5
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator.cpp | 55 | ||||
-rw-r--r-- | src/qml/compiler/qqmlcodegenerator_p.h | 2 | ||||
-rw-r--r-- | src/qml/compiler/qv4compileddata_p.h | 1 |
3 files changed, 52 insertions, 6 deletions
diff --git a/src/qml/compiler/qqmlcodegenerator.cpp b/src/qml/compiler/qqmlcodegenerator.cpp index b257d2d44e..2394b07cdf 100644 --- a/src/qml/compiler/qqmlcodegenerator.cpp +++ b/src/qml/compiler/qqmlcodegenerator.cpp @@ -634,15 +634,33 @@ bool QQmlCodeGenerator::visit(AST::UiPublicMember *node) if (!node->statement && !node->binding) COMPILE_EXCEPTION(loc, tr("No property alias location")); + AST::SourceLocation rhsLoc; + if (node->binding) + rhsLoc = node->binding->firstSourceLocation(); + else if (node->statement) + rhsLoc = node->statement->firstSourceLocation(); + else + rhsLoc = node->semicolonToken; + property->aliasLocation.line = rhsLoc.startLine; + property->aliasLocation.column = rhsLoc.startColumn; + QStringList alias; - if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement*>(node->statement)) - alias = astNodeToStringList(stmt->expression); - if (node->binding || alias.isEmpty()) - COMPILE_EXCEPTION(loc, tr("Invalid alias location")); + if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement*>(node->statement)) { + alias = astNodeToStringList(stmt->expression); + if (alias.isEmpty()) { + if (isStatementNodeScript(node->statement)) { + COMPILE_EXCEPTION(rhsLoc, tr("Invalid alias reference. An alias reference must be specified as <id>, <id>.<property> or <id>.<value property>.<property>")); + } else { + COMPILE_EXCEPTION(rhsLoc, tr("Invalid alias location")); + } + } + } else { + COMPILE_EXCEPTION(rhsLoc, tr("Invalid alias reference. An alias reference must be specified as <id>, <id>.<property> or <id>.<value property>.<property>")); + } - if (alias.count() < 1 || alias.count() > 3) - COMPILE_EXCEPTION(loc, tr("Invalid alias reference. An alias reference must be specified as <id>, <id>.<property> or <id>.<value property>.<property>")); + if (alias.count() < 1 || alias.count() > 3) + COMPILE_EXCEPTION(rhsLoc, tr("Invalid alias reference. An alias reference must be specified as <id>, <id>.<property> or <id>.<value property>.<property>")); property->aliasIdValueIndex = registerString(alias.first()); @@ -987,6 +1005,31 @@ QQmlScript::LocationSpan QQmlCodeGenerator::location(AST::SourceLocation start, return rv; } +bool QQmlCodeGenerator::isStatementNodeScript(AST::Statement *statement) +{ + if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(statement)) { + AST::ExpressionNode *expr = stmt->expression; + if (AST::StringLiteral *lit = AST::cast<AST::StringLiteral *>(expr)) + return false; + else if (expr->kind == AST::Node::Kind_TrueLiteral) + return false; + else if (expr->kind == AST::Node::Kind_FalseLiteral) + return false; + else if (AST::NumericLiteral *lit = AST::cast<AST::NumericLiteral *>(expr)) + return false; + else { + + if (AST::UnaryMinusExpression *unaryMinus = AST::cast<AST::UnaryMinusExpression *>(expr)) { + if (AST::NumericLiteral *lit = AST::cast<AST::NumericLiteral *>(unaryMinus->expression)) { + return false; + } + } + } + } + + return true; +} + QV4::CompiledData::QmlUnit *QmlUnitGenerator::generate(ParsedQML &output) { jsUnitGenerator = &output.jsGenerator; diff --git a/src/qml/compiler/qqmlcodegenerator_p.h b/src/qml/compiler/qqmlcodegenerator_p.h index 9273892d7c..ec75c38160 100644 --- a/src/qml/compiler/qqmlcodegenerator_p.h +++ b/src/qml/compiler/qqmlcodegenerator_p.h @@ -247,6 +247,8 @@ public: QString stringAt(int index) const { return jsGenerator->strings.at(index); } + static bool isStatementNodeScript(AST::Statement *statement); + QList<QQmlError> errors; QList<QV4::CompiledData::Import*> _imports; diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h index 91860864d0..5159ac5a06 100644 --- a/src/qml/compiler/qv4compileddata_p.h +++ b/src/qml/compiler/qv4compileddata_p.h @@ -336,6 +336,7 @@ struct Property quint32 aliasPropertyValueIndex; quint32 flags; // readonly Location location; + Location aliasLocation; // If type == Alias }; struct Object |