diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-03-22 16:34:05 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-04-27 08:11:28 +0000 |
commit | 02252ae08dc36ba44f65fb932c428849c7369299 (patch) | |
tree | 5c7627b08cce5bfa2df5e04b3427bcc93ef2b2fe /src/qml/compiler/qv4compilerscanfunctions.cpp | |
parent | e07a03365ad07cd4294f487b15a57f31bd0a3d40 (diff) |
Rework the AST for Literals and destructuring expressions
Array/ObjectLiterals and destructuring expressions are
syntactically very similar. In some cases (when using
a destructuring expression as the lhs of an assigment),
the parser needs to convert the literal into a destructuring
expression.
To support these, use the same data structures for both in
the AST. Those Patterns can be converted with little
additional work from a Literal to an AssignmentPattern and
be used in all places where we need destructuring in addition
to literals.
Change-Id: I177599b46eab0f6e8cb2a40c3b3b11ed00a07d6a
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilerscanfunctions.cpp')
-rw-r--r-- | src/qml/compiler/qv4compilerscanfunctions.cpp | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp index b2a5e7ca79..217c077dc0 100644 --- a/src/qml/compiler/qv4compilerscanfunctions.cpp +++ b/src/qml/compiler/qv4compilerscanfunctions.cpp @@ -178,7 +178,7 @@ bool ScanFunctions::visit(NewMemberExpression *ast) bool ScanFunctions::visit(ArrayPattern *ast) { int index = 0; - for (ElementList *it = ast->elements; it; it = it->next) { + for (PatternElementList *it = ast->elements; it; it = it->next) { for (Elision *elision = it->elision; elision; elision = elision->next) ++index; ++index; @@ -270,31 +270,27 @@ void ScanFunctions::endVisit(FunctionExpression *) bool ScanFunctions::visit(ObjectPattern *ast) { - int argc = 0; - for (PropertyDefinitionList *it = ast->properties; it; it = it->next) { - QString key = it->assignment->name->asString(); - if (QV4::String::toArrayIndex(key) != UINT_MAX) - ++argc; - ++argc; - if (AST::cast<AST::PropertyGetterSetter *>(it->assignment)) - ++argc; - } - _context->maxNumberOfArguments = qMax(_context->maxNumberOfArguments, argc); - TemporaryBoolAssignment allowFuncDecls(_allowFuncDecls, true); Node::accept(ast->properties, this); return false; } -bool ScanFunctions::visit(PropertyGetterSetter *ast) +bool ScanFunctions::visit(PatternProperty *ast) { - TemporaryBoolAssignment allowFuncDecls(_allowFuncDecls, true); - return enterFunction(ast, QString(), ast->formals, ast->functionBody, /*enterName */ false); + Q_UNUSED(ast); + // ### Shouldn't be required anymore +// if (ast->type == PatternProperty::Getter || ast->type == PatternProperty::Setter) { +// TemporaryBoolAssignment allowFuncDecls(_allowFuncDecls, true); +// return enterFunction(ast, QString(), ast->formals, ast->functionBody, /*enterName */ false); +// } + return true; } -void ScanFunctions::endVisit(PropertyGetterSetter *) +void ScanFunctions::endVisit(PatternProperty *) { - leaveEnvironment(); + // ### +// if (ast->type == PatternProperty::Getter || ast->type == PatternProperty::Setter) +// leaveEnvironment(); } bool ScanFunctions::visit(FunctionDeclaration *ast) |