QmlJS:SimpleReader: adding support for arrays

Also adding test.

Change-Id: Idaf0aeacbb6f78e5c8404db740c2a8b7b297dad2
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
Thomas Hartmann
2012-11-09 11:23:32 +01:00
parent cb02dd812a
commit 6cf321a316
3 changed files with 64 additions and 8 deletions

View File

@@ -232,12 +232,12 @@ void SimpleAbstractStreamReader::readProperty(AST::UiScriptBinding *uiScriptBind
setSourceLocation(uiScriptBinding->firstSourceLocation());
const QString name = toString(uiScriptBinding->qualifiedId);
const QVariant value = parseProperty(uiScriptBinding);
const QVariant value = parsePropertyScriptBinding(uiScriptBinding);
propertyDefinition(name, value);
}
QVariant SimpleAbstractStreamReader::parseProperty(AST::UiScriptBinding *uiScriptBinding)
QVariant SimpleAbstractStreamReader::parsePropertyScriptBinding(AST::UiScriptBinding *uiScriptBinding)
{
Q_ASSERT(uiScriptBinding);
@@ -247,23 +247,39 @@ QVariant SimpleAbstractStreamReader::parseProperty(AST::UiScriptBinding *uiScrip
return QVariant();
}
AST::StringLiteral *stringLiteral = AST::cast<AST::StringLiteral *>(expStmt->expression);
return parsePropertyExpression(expStmt->expression);
}
QVariant SimpleAbstractStreamReader::parsePropertyExpression(AST::ExpressionNode *expressionNode)
{
Q_ASSERT(expressionNode);
AST::ArrayLiteral *arrayLiteral = AST::cast<AST::ArrayLiteral *>(expressionNode);
if (arrayLiteral) {
QList<QVariant> variantList;
for (AST::ElementList *it = arrayLiteral->elements; it; it = it->next)
variantList << parsePropertyExpression(it->expression);
return variantList;
}
AST::StringLiteral *stringLiteral = AST::cast<AST::StringLiteral *>(expressionNode);
if (stringLiteral)
return stringLiteral->value.toString();
AST::TrueLiteral *trueLiteral = AST::cast<AST::TrueLiteral *>(expStmt->expression);
AST::TrueLiteral *trueLiteral = AST::cast<AST::TrueLiteral *>(expressionNode);
if (trueLiteral)
return true;
AST::FalseLiteral *falseLiteral = AST::cast<AST::FalseLiteral *>(expStmt->expression);
AST::FalseLiteral *falseLiteral = AST::cast<AST::FalseLiteral *>(expressionNode);
if (falseLiteral)
return false;
AST::NumericLiteral *numericLiteral = AST::cast<AST::NumericLiteral *>(expStmt->expression);
AST::NumericLiteral *numericLiteral = AST::cast<AST::NumericLiteral *>(expressionNode);
if (numericLiteral)
return numericLiteral->value;
addError(tr("Expected expression statement to be a literal"), uiScriptBinding->statement->firstSourceLocation());
addError(tr("Expected expression statement to be a literal"), expressionNode->firstSourceLocation());
return QVariant();
}