aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser/qqmljsast_p.h
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_p.h
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_p.h')
-rw-r--r--src/qml/parser/qqmljsast_p.h180
1 files changed, 159 insertions, 21 deletions
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index 36eabec82e..6142b00712 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -205,6 +205,10 @@ public:
Kind_WhileStatement,
Kind_WithStatement,
Kind_NestedExpression,
+ Kind_BindingElement,
+ Kind_BindingElementList,
+ Kind_BindingPropertyList,
+ Kind_BindingRestElement,
Kind_UiArrayBinding,
Kind_UiImport,
@@ -2064,6 +2068,119 @@ public:
SourceLocation rbraceToken;
};
+class QML_PARSER_EXPORT BindingRestElement : public Node
+{
+public:
+ QQMLJS_DECLARE_AST_NODE(BindingRestElement)
+
+ BindingRestElement(const QStringRef &n)
+ : name(n)
+ { kind = K; }
+
+ void accept0(Visitor *visitor) override;
+
+ SourceLocation firstSourceLocation() const override
+ { return identifierToken; }
+
+ SourceLocation lastSourceLocation() const override
+ { return identifierToken; }
+
+// attributes
+ SourceLocation identifierToken;
+ QStringRef name;
+};
+
+class QML_PARSER_EXPORT BindingElement : public Node
+{
+public:
+ QQMLJS_DECLARE_AST_NODE(BindingElement)
+
+ BindingElement(const QStringRef &n, ExpressionNode *i = nullptr)
+ : name(n.toString()), initializer(i)
+ { kind = K; }
+
+ BindingElement(Node *binding, ExpressionNode *i = nullptr)
+ : binding(binding), initializer(i)
+ { kind = K; }
+
+ void accept0(Visitor *visitor) override;
+
+ SourceLocation firstSourceLocation() const override
+ { return identifierToken; }
+
+ SourceLocation lastSourceLocation() const override
+ { return initializer ? initializer->lastSourceLocation() : (binding ? binding->lastSourceLocation() : identifierToken); }
+
+ BindingElementList *elementList() const { return cast<BindingElementList *>(binding); }
+ BindingPropertyList *propertyList() const { return cast<BindingPropertyList *>(binding); }
+
+ void boundNames(QStringList *names);
+
+// attributes
+ SourceLocation identifierToken;
+ Node *binding = nullptr;
+ QString name;
+ ExpressionNode *initializer = nullptr;
+};
+
+class QML_PARSER_EXPORT BindingElementList : public Node
+{
+public:
+ QQMLJS_DECLARE_AST_NODE(BindingElementList)
+
+ BindingElementList()
+ { kind = K; }
+
+ void accept0(Visitor *visitor) override;
+
+ void boundNames(QStringList *names);
+
+ SourceLocation firstSourceLocation() const override
+ { return loc; }
+
+ SourceLocation lastSourceLocation() const override
+ { return loc; }
+
+ SourceLocation loc;
+};
+
+class QML_PARSER_EXPORT BindingPropertyList : public Node
+{
+public:
+ QQMLJS_DECLARE_AST_NODE(BindingPropertyList)
+
+ BindingPropertyList(PropertyName *n, BindingElement *e)
+ : propertyName(n), binding(e), next(this)
+ { kind = K; }
+
+ void accept0(Visitor *visitor) override;
+
+ void boundNames(QStringList *names);
+
+ BindingPropertyList *append(BindingPropertyList *n) {
+ n->next = next;
+ next = n;
+ return n;
+ }
+
+ inline BindingPropertyList *finish ()
+ {
+ BindingPropertyList *front = next;
+ next = 0;
+ return front;
+ }
+
+ SourceLocation firstSourceLocation() const override
+ { return propertyName->firstSourceLocation(); }
+
+ SourceLocation lastSourceLocation() const override
+ { return next ? next->lastSourceLocation() : binding->lastSourceLocation(); }
+
+ PropertyName *propertyName;
+ BindingElement *binding;
+ BindingPropertyList *next;
+};
+
class QML_PARSER_EXPORT FunctionDeclaration: public FunctionExpression
{
public:
@@ -2081,16 +2198,16 @@ class QML_PARSER_EXPORT FormalParameterList: public Node
public:
QQMLJS_DECLARE_AST_NODE(FormalParameterList)
- FormalParameterList(const QStringRef &n)
- : name(n), next(this)
- { kind = K; }
-
- FormalParameterList(FormalParameterList *previous, const QStringRef &n):
- name (n)
+ FormalParameterList(FormalParameterList *previous, Node *p)
+ : param(p)
{
kind = K;
- next = previous->next;
- previous->next = this;
+ if (previous) {
+ next = previous->next;
+ previous->next = this;
+ } else {
+ next = this;
+ }
}
FormalParameterList *append(FormalParameterList *n) {
@@ -2099,39 +2216,60 @@ public:
return n;
}
+ BindingRestElement *bindingRestElement() const {
+ return cast<BindingRestElement *>(param);
+ }
+
+ BindingElement *bindingElement() const {
+ return cast<BindingElement *>(param);
+ }
+
bool isSimpleParameterList()
{
AST::FormalParameterList *formals = this;
while (formals) {
- if (formals->isRest || formals->initializer)
+ if (formals->bindingRestElement())
+ return false;
+ BindingElement *e = formals->bindingElement();
+ Q_ASSERT(e);
+ if (e->initializer || e->binding)
return false;
formals = formals->next;
}
return true;
}
+ bool containsName(const QString &name) const {
+ for (const FormalParameterList *it = this; it; it = it->next) {
+ if (QQmlJS::AST::BindingElement *b = it->bindingElement()) {
+ // ### handle binding patterns
+ if (b->name == name)
+ return true;
+ } else if (QQmlJS::AST::BindingRestElement *r = it->bindingRestElement()) {
+ if (r->name == name)
+ return true;
+ }
+ }
+ return false;
+ }
+
+ QStringList formals() const;
+
+ QStringList boundNames() const;
void accept0(Visitor *visitor) override;
SourceLocation firstSourceLocation() const override
- { return identifierToken; }
+ { return param->firstSourceLocation(); }
SourceLocation lastSourceLocation() const override
- { return next ? next->lastSourceLocation() : identifierToken; }
+ { return next ? next->lastSourceLocation() : param->lastSourceLocation(); }
- inline FormalParameterList *finish ()
- {
- FormalParameterList *front = next;
- next = nullptr;
- return front;
- }
+ FormalParameterList *finish();
// attributes
- QStringRef name;
- bool isRest = false;
- ExpressionNode *initializer = nullptr;
+ Node *param = nullptr;
FormalParameterList *next;
- SourceLocation identifierToken;
};
class QML_PARSER_EXPORT SourceElement: public Node