summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlparser.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-11-29 10:46:00 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-11-29 10:46:00 (GMT)
commitd406a899943c6d56d921bc290a009415a3c4eba5 (patch)
treec48f12180910251b4572cb3600a72332ff5f34f5 /src/declarative/qml/qmlparser.cpp
parent696b55195f1ad40a077683dbc533c73baf1536ee (diff)
downloadQt-d406a899943c6d56d921bc290a009415a3c4eba5.zip
Qt-d406a899943c6d56d921bc290a009415a3c4eba5.tar.gz
Qt-d406a899943c6d56d921bc290a009415a3c4eba5.tar.bz2
Support array-literal Script::source values
Diffstat (limited to 'src/declarative/qml/qmlparser.cpp')
-rw-r--r--src/declarative/qml/qmlparser.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp
index ee69b14..402c93e 100644
--- a/src/declarative/qml/qmlparser.cpp
+++ b/src/declarative/qml/qmlparser.cpp
@@ -54,10 +54,13 @@
#include "private/qmetaobjectbuilder_p.h"
#include <private/qmlvmemetaobject_p.h>
#include <private/qmlcompiler_p.h>
+#include "parser/qmljsast_p.h"
+#include "parser/qmljsengine_p.h"
#include <QtDebug>
QT_BEGIN_NAMESPACE
+using namespace QmlJS;
using namespace QmlParser;
QmlParser::Object::Object()
@@ -327,4 +330,55 @@ QmlJS::AST::Node *QmlParser::Variant::asAST() const
return 0;
}
+bool QmlParser::Variant::isStringList() const
+{
+ if (isString())
+ return true;
+
+ if (type() != Script || !n)
+ return false;
+
+ AST::ArrayLiteral *array = AST::cast<AST::ArrayLiteral *>(n);
+ if (!array)
+ return false;
+
+ AST::ElementList *elements = array->elements;
+
+ while (elements) {
+
+ if (!AST::cast<AST::StringLiteral *>(elements->expression))
+ return false;
+
+ elements = elements->next;
+ }
+
+ return true;
+}
+
+QStringList QmlParser::Variant::asStringList() const
+{
+ QStringList rv;
+ if (isString()) {
+ rv << asString();
+ return rv;
+ }
+
+ AST::ArrayLiteral *array = AST::cast<AST::ArrayLiteral *>(n);
+ if (!array)
+ return rv;
+
+ AST::ElementList *elements = array->elements;
+ while (elements) {
+
+ AST::StringLiteral *string = AST::cast<AST::StringLiteral *>(elements->expression);
+ if (!string)
+ return QStringList();
+ rv.append(string->value->asString());
+
+ elements = elements->next;
+ }
+
+ return rv;
+}
+
QT_END_NAMESPACE