aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser/qqmljsast.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-02-10 23:22:13 +0100
committerLars Knoll <lars.knoll@qt.io>2018-04-25 17:49:38 +0000
commitda5fffbd34d8be68f8ee4c649881dbb673c9c0a5 (patch)
tree2c4647732d8754f0c9b8573875cb5936639320ca /src/qml/parser/qqmljsast.cpp
parente91d0091e0778ad1379f40d97daa704515bec3d4 (diff)
Partially support binding patterns
Destructuring objects works, but arrays are not yet supported. Change-Id: I61e917e1964e3c719f71b8f11d194e09dfe288c2 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/parser/qqmljsast.cpp')
-rw-r--r--src/qml/parser/qqmljsast.cpp109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp
index b29450c1df..60064319c9 100644
--- a/src/qml/parser/qqmljsast.cpp
+++ b/src/qml/parser/qqmljsast.cpp
@@ -762,6 +762,41 @@ void FunctionExpression::accept0(Visitor *visitor)
visitor->endVisit(this);
}
+QStringList FormalParameterList::formals() const
+{
+ QStringList formals;
+ int i = 0;
+ for (const FormalParameterList *it = this; it; it = it->next) {
+ QString name;
+ if (QQmlJS::AST::BindingElement *b = it->bindingElement()) {
+ name = b->name;
+ } else if (QQmlJS::AST::BindingRestElement *r = it->bindingRestElement()) {
+ name = r->name.toString();
+ }
+ int duplicateIndex = formals.indexOf(name);
+ if (duplicateIndex >= 0) {
+ // change the name of the earlier argument to enforce the lookup semantics from the spec
+ formals[duplicateIndex] += QLatin1String("#") + QString::number(i);
+ }
+ formals += name;
+ ++i;
+ }
+ return formals;
+}
+
+QStringList FormalParameterList::boundNames() const
+{
+ QStringList names;
+ for (const FormalParameterList *it = this; it; it = it->next) {
+ if (QQmlJS::AST::BindingElement *b = it->bindingElement()) {
+ b->boundNames(&names);
+ } else if (QQmlJS::AST::BindingRestElement *r = it->bindingRestElement()) {
+ names += r->name.toString();
+ }
+ }
+ return names;
+}
+
void FormalParameterList::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -771,6 +806,23 @@ void FormalParameterList::accept0(Visitor *visitor)
visitor->endVisit(this);
}
+FormalParameterList *FormalParameterList::finish()
+{
+ FormalParameterList *front = next;
+ next = nullptr;
+
+ int i = 0;
+ for (const FormalParameterList *it = this; it; it = it->next) {
+ QString name;
+ if (QQmlJS::AST::BindingElement *b = it->bindingElement()) {
+ if (b->name.isEmpty())
+ name = QLatin1String("arg#") + QString::number(i);
+ }
+ ++i;
+ }
+ return front;
+}
+
void FunctionBody::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
@@ -1003,6 +1055,63 @@ void TaggedTemplate::accept0(Visitor *visitor)
visitor->endVisit(this);
}
+void BindingRestElement::accept0(Visitor *visitor)
+{
+ if (visitor->visit(this)) {
+ }
+
+ visitor->endVisit(this);
+}
+
+void BindingElement::accept0(Visitor *visitor)
+{
+ if (visitor->visit(this)) {
+ accept(initializer, visitor);
+ }
+
+ visitor->endVisit(this);
+}
+
+void BindingElement::boundNames(QStringList *names)
+{
+ if (binding) {
+ if (BindingElementList *e = elementList())
+ e->boundNames(names);
+ else if (BindingPropertyList *p = propertyList())
+ p->boundNames(names);
+ } else
+ names->append(name);
+}
+
+void BindingElementList::accept0(Visitor *visitor)
+{
+ if (visitor->visit(this)) {
+ }
+
+ visitor->endVisit(this);
+}
+
+void BindingElementList::boundNames(QStringList *names)
+{
+ // ###
+ Q_UNUSED(names);
+
+}
+
+void BindingPropertyList::accept0(Visitor *visitor)
+{
+ if (visitor->visit(this)) {
+ }
+
+ visitor->endVisit(this);
+}
+
+void BindingPropertyList::boundNames(QStringList *names)
+{
+ for (BindingPropertyList *it = this; it; it = it->next)
+ it->binding->boundNames(names);
+}
+
} } // namespace QQmlJS::AST
QT_QML_END_NAMESPACE