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());
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;
const int idIndex = p->aliasIdValueIndex;
const int targetObjectIndex = _idToObjectIndex.value(idIndex, -1);
- if (targetObjectIndex == -1)
- COMPILE_EXCEPTION(p, tr("Invalid alias reference. Unable to find id \"%1\"").arg(stringAt(idIndex)));
+ if (targetObjectIndex == -1) {
+ recordError(p->aliasLocation, tr("Invalid alias reference. Unable to find id \"%1\"").arg(stringAt(idIndex)));
+ return false;
+ }
const int targetId = _objectIndexToIdInScope->value(targetObjectIndex, -1);
Q_ASSERT(targetId != -1);
QtQml::PropertyResolver resolver(targetCache);
QQmlPropertyData *targetProperty = resolver.property(property.toString());
- if (!targetProperty || targetProperty->coreIndex > 0x0000FFFF)
- COMPILE_EXCEPTION(p, tr("Invalid alias location"));
+ if (!targetProperty || targetProperty->coreIndex > 0x0000FFFF) {
+ recordError(p->aliasLocation, tr("Invalid alias location"));
+ return false;
+ }
propIdx = targetProperty->coreIndex;
type = targetProperty->propType;
if (!subProperty.isEmpty()) {
QQmlValueType *valueType = QQmlValueTypeFactory::valueType(type);
- if (!valueType)
- COMPILE_EXCEPTION(p, tr("Invalid alias location"));
+ if (!valueType) {
+ recordError(p->aliasLocation, tr("Invalid alias location"));
+ return false;
+ }
propType = type;
int valueTypeIndex =
valueType->metaObject()->indexOfProperty(subProperty.toString().toUtf8().constData());
- if (valueTypeIndex == -1)
- COMPILE_EXCEPTION(p, tr("Invalid alias location"));
+ if (valueTypeIndex == -1) {
+ recordError(p->aliasLocation, tr("Invalid alias location"));
+ return false;
+ }
Q_ASSERT(valueTypeIndex <= 0x0000FFFF);
propIdx |= (valueTypeIndex << 16);