aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-03-22 16:04:03 +0100
committerLars Knoll <lars.knoll@qt.io>2018-04-27 08:11:16 +0000
commite07a03365ad07cd4294f487b15a57f31bd0a3d40 (patch)
tree7954c244860da7e424513f967cea91a93ab7172a /src
parent837dd08f65588f7f248150c0cacd1e3ef6c4e91f (diff)
Rename Array/ObjectLiteral to Array/ObjectPattern in the AST
To get a consistent representation in the AST, we need to unify the AST that is generated by theObjectLiterals, ObjectBindingPattern and ObjectAssignmentPattern rules in the grammar. Like this we can avoid having to reparse part of the source code, and instead replace this with consistency checks once we know which of the three grammars are supposed to apply. Change-Id: Ib90f521f9595db6bcad446e40de9b912bab3da7c Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qv4codegen.cpp4
-rw-r--r--src/qml/compiler/qv4codegen_p.h4
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions.cpp8
-rw-r--r--src/qml/compiler/qv4compilerscanfunctions_p.h4
-rw-r--r--src/qml/parser/qqmljs.g14
-rw-r--r--src/qml/parser/qqmljsast.cpp4
-rw-r--r--src/qml/parser/qqmljsast_p.h30
-rw-r--r--src/qml/parser/qqmljsastfwd_p.h4
-rw-r--r--src/qml/parser/qqmljsastvisitor_p.h8
9 files changed, 40 insertions, 40 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp
index 45f54f7eb3..a3adf7793c 100644
--- a/src/qml/compiler/qv4codegen.cpp
+++ b/src/qml/compiler/qv4codegen.cpp
@@ -650,7 +650,7 @@ bool Codegen::visit(Expression *ast)
return false;
}
-bool Codegen::visit(ArrayLiteral *ast)
+bool Codegen::visit(ArrayPattern *ast)
{
if (hasError)
return false;
@@ -1886,7 +1886,7 @@ bool Codegen::visit(NumericLiteral *ast)
return false;
}
-bool Codegen::visit(ObjectLiteral *ast)
+bool Codegen::visit(ObjectPattern *ast)
{
if (hasError)
return false;
diff --git a/src/qml/compiler/qv4codegen_p.h b/src/qml/compiler/qv4codegen_p.h
index 0d11c0c509..28c2a9b4e1 100644
--- a/src/qml/compiler/qv4codegen_p.h
+++ b/src/qml/compiler/qv4codegen_p.h
@@ -555,7 +555,7 @@ protected:
// expressions
bool visit(AST::Expression *ast) override;
- bool visit(AST::ArrayLiteral *ast) override;
+ bool visit(AST::ArrayPattern *ast) override;
bool visit(AST::ArrayMemberExpression *ast) override;
bool visit(AST::BinaryExpression *ast) override;
bool visit(AST::CallExpression *ast) override;
@@ -573,7 +573,7 @@ protected:
bool visit(AST::NotExpression *ast) override;
bool visit(AST::NullExpression *ast) override;
bool visit(AST::NumericLiteral *ast) override;
- bool visit(AST::ObjectLiteral *ast) override;
+ bool visit(AST::ObjectPattern *ast) override;
bool visit(AST::PostDecrementExpression *ast) override;
bool visit(AST::PostIncrementExpression *ast) override;
bool visit(AST::PreDecrementExpression *ast) override;
diff --git a/src/qml/compiler/qv4compilerscanfunctions.cpp b/src/qml/compiler/qv4compilerscanfunctions.cpp
index 57f9105484..b2a5e7ca79 100644
--- a/src/qml/compiler/qv4compilerscanfunctions.cpp
+++ b/src/qml/compiler/qv4compilerscanfunctions.cpp
@@ -175,7 +175,7 @@ bool ScanFunctions::visit(NewMemberExpression *ast)
return true;
}
-bool ScanFunctions::visit(ArrayLiteral *ast)
+bool ScanFunctions::visit(ArrayPattern *ast)
{
int index = 0;
for (ElementList *it = ast->elements; it; it = it->next) {
@@ -268,7 +268,7 @@ void ScanFunctions::endVisit(FunctionExpression *)
leaveEnvironment();
}
-bool ScanFunctions::visit(ObjectLiteral *ast)
+bool ScanFunctions::visit(ObjectPattern *ast)
{
int argc = 0;
for (PropertyDefinitionList *it = ast->properties; it; it = it->next) {
@@ -400,11 +400,11 @@ bool ScanFunctions::enterFunction(Node *ast, const QString &name, FormalParamete
outerContext->hasNestedFunctions = true;
// The identifier of a function expression cannot be referenced from the enclosing environment.
if (enterName) {
- if (!outerContext->addLocalVar(name, Context::FunctionDefinition, AST::VariableScope::Var, expr)) {
+ if (!outerContext->addLocalVar(name, Context::FunctionDefinition, VariableDeclaration::FunctionScope, expr)) {
_cg->throwSyntaxError(ast->firstSourceLocation(), QStringLiteral("Identifier %1 has already been declared").arg(name));
return false;
}
- outerContext->addLocalVar(name, Context::FunctionDefinition, AST::VariableScope::Var, expr);
+ outerContext->addLocalVar(name, Context::FunctionDefinition, VariableDeclaration::FunctionScope, expr);
}
if (name == QLatin1String("arguments"))
outerContext->usesArgumentsObject = Context::ArgumentsObjectNotUsed;
diff --git a/src/qml/compiler/qv4compilerscanfunctions_p.h b/src/qml/compiler/qv4compilerscanfunctions_p.h
index 43fcc36897..8ab6bbbe8d 100644
--- a/src/qml/compiler/qv4compilerscanfunctions_p.h
+++ b/src/qml/compiler/qv4compilerscanfunctions_p.h
@@ -104,7 +104,7 @@ protected:
bool visit(AST::CallExpression *ast) override;
bool visit(AST::NewMemberExpression *ast) override;
- bool visit(AST::ArrayLiteral *ast) override;
+ bool visit(AST::ArrayPattern *ast) override;
bool visit(AST::VariableDeclaration *ast) override;
bool visit(AST::IdentifierExpression *ast) override;
bool visit(AST::ExpressionStatement *ast) override;
@@ -115,7 +115,7 @@ protected:
void endVisit(AST::FunctionExpression *) override;
- bool visit(AST::ObjectLiteral *ast) override;
+ bool visit(AST::ObjectPattern *ast) override;
bool visit(AST::PropertyGetterSetter *ast) override;
void endVisit(AST::PropertyGetterSetter *) override;
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g
index 62e6c962e8..4678b282ec 100644
--- a/src/qml/parser/qqmljs.g
+++ b/src/qml/parser/qqmljs.g
@@ -994,7 +994,7 @@ UiObjectLiteral: T_LBRACE ExpressionStatementLookahead UiPropertyDefinitionList
UiObjectLiteral: T_LBRACE ExpressionStatementLookahead UiPropertyDefinitionList T_COMMA T_RBRACE;
/.
case $rule_number: {
- AST::ObjectLiteral *l = new (pool) AST::ObjectLiteral(sym(3).PropertyDefinitionList->finish());
+ AST::ObjectPattern *l = new (pool) AST::ObjectPattern(sym(3).PropertyDefinitionList->finish());
l->lbraceToken = loc(1);
l->rbraceToken = loc(4);
AST::ExpressionStatement *node = new (pool) AST::ExpressionStatement(l);
@@ -1606,7 +1606,7 @@ RegularExpressionLiteral: T_DIVIDE_EQ;
ArrayLiteral: T_LBRACKET ElisionOpt T_RBRACKET;
/.
case $rule_number: {
- AST::ArrayLiteral *node = new (pool) AST::ArrayLiteral(sym(2).Elision);
+ AST::ArrayPattern *node = new (pool) AST::ArrayPattern(sym(2).Elision);
node->lbracketToken = loc(1);
node->rbracketToken = loc(3);
sym(1).Node = node;
@@ -1616,7 +1616,7 @@ ArrayLiteral: T_LBRACKET ElisionOpt T_RBRACKET;
ArrayLiteral: T_LBRACKET ElementList T_RBRACKET;
/.
case $rule_number: {
- AST::ArrayLiteral *node = new (pool) AST::ArrayLiteral(sym(2).ElementList->finish());
+ AST::ArrayPattern *node = new (pool) AST::ArrayPattern(sym(2).ElementList->finish());
node->lbracketToken = loc(1);
node->rbracketToken = loc(3);
sym(1).Node = node;
@@ -1626,7 +1626,7 @@ ArrayLiteral: T_LBRACKET ElementList T_RBRACKET;
ArrayLiteral: T_LBRACKET ElementList T_COMMA ElisionOpt T_RBRACKET;
/.
case $rule_number: {
- AST::ArrayLiteral *node = new (pool) AST::ArrayLiteral(sym(2).ElementList->finish(), sym(4).Elision);
+ AST::ArrayPattern *node = new (pool) AST::ArrayPattern(sym(2).ElementList->finish(), sym(4).Elision);
node->lbracketToken = loc(1);
node->commaToken = loc(3);
node->rbracketToken = loc(5);
@@ -1718,7 +1718,7 @@ SpreadElement: T_ELLIPSIS AssignmentExpression;
ObjectLiteral: T_LBRACE T_RBRACE;
/.
case $rule_number: {
- AST::ObjectLiteral *node = new (pool) AST::ObjectLiteral();
+ AST::ObjectPattern *node = new (pool) AST::ObjectPattern();
node->lbraceToken = loc(1);
node->rbraceToken = loc(2);
sym(1).Node = node;
@@ -1728,7 +1728,7 @@ ObjectLiteral: T_LBRACE T_RBRACE;
ObjectLiteral: T_LBRACE PropertyDefinitionList T_RBRACE;
/.
case $rule_number: {
- AST::ObjectLiteral *node = new (pool) AST::ObjectLiteral(sym(2).PropertyDefinitionList->finish());
+ AST::ObjectPattern *node = new (pool) AST::ObjectPattern(sym(2).PropertyDefinitionList->finish());
node->lbraceToken = loc(1);
node->rbraceToken = loc(3);
sym(1).Node = node;
@@ -1738,7 +1738,7 @@ ObjectLiteral: T_LBRACE PropertyDefinitionList T_RBRACE;
ObjectLiteral: T_LBRACE PropertyDefinitionList T_COMMA T_RBRACE;
/.
case $rule_number: {
- AST::ObjectLiteral *node = new (pool) AST::ObjectLiteral(sym(2).PropertyDefinitionList->finish());
+ AST::ObjectPattern *node = new (pool) AST::ObjectPattern(sym(2).PropertyDefinitionList->finish());
node->lbraceToken = loc(1);
node->rbraceToken = loc(4);
sym(1).Node = node;
diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp
index 1a2883e148..c27b049e5d 100644
--- a/src/qml/parser/qqmljsast.cpp
+++ b/src/qml/parser/qqmljsast.cpp
@@ -190,7 +190,7 @@ void RegExpLiteral::accept0(Visitor *visitor)
visitor->endVisit(this);
}
-void ArrayLiteral::accept0(Visitor *visitor)
+void ArrayPattern::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(elements, visitor);
@@ -200,7 +200,7 @@ void ArrayLiteral::accept0(Visitor *visitor)
visitor->endVisit(this);
}
-void ObjectLiteral::accept0(Visitor *visitor)
+void ObjectPattern::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
accept(properties, visitor);
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index 4eb93cc203..19f1beb803 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -504,22 +504,22 @@ public:
SourceLocation literalToken;
};
-class QML_PARSER_EXPORT ArrayLiteral: public ExpressionNode
+class QML_PARSER_EXPORT ArrayPattern : public ExpressionNode
{
public:
QQMLJS_DECLARE_AST_NODE(ArrayLiteral)
- ArrayLiteral(Elision *e):
- elements (nullptr), elision (e)
- { kind = K; }
+ ArrayPattern(Elision *e)
+ : elision(e)
+ { kind = K; }
- ArrayLiteral(ElementList *elts):
- elements (elts), elision (nullptr)
- { kind = K; }
+ ArrayPattern(ElementList *elts)
+ : elements(elts)
+ { kind = K; }
- ArrayLiteral(ElementList *elts, Elision *e):
- elements (elts), elision (e)
- { kind = K; }
+ ArrayPattern(ElementList *elts, Elision *e)
+ : elements(elts), elision(e)
+ { kind = K; }
void accept0(Visitor *visitor) override;
@@ -530,22 +530,22 @@ public:
{ return rbracketToken; }
// attributes
- ElementList *elements;
- Elision *elision;
+ ElementList *elements = nullptr;
+ Elision *elision = nullptr;
SourceLocation lbracketToken;
SourceLocation commaToken;
SourceLocation rbracketToken;
};
-class QML_PARSER_EXPORT ObjectLiteral: public ExpressionNode
+class QML_PARSER_EXPORT ObjectPattern : public ExpressionNode
{
public:
QQMLJS_DECLARE_AST_NODE(ObjectLiteral)
- ObjectLiteral()
+ ObjectPattern()
{ kind = K; }
- ObjectLiteral(PropertyDefinitionList *plist):
+ ObjectPattern(PropertyDefinitionList *plist):
properties (plist) { kind = K; }
void accept0(Visitor *visitor) override;
diff --git a/src/qml/parser/qqmljsastfwd_p.h b/src/qml/parser/qqmljsastfwd_p.h
index 0beaed535f..4661c2eb1e 100644
--- a/src/qml/parser/qqmljsastfwd_p.h
+++ b/src/qml/parser/qqmljsastfwd_p.h
@@ -94,8 +94,8 @@ class NumericLiteral;
class StringLiteral;
class TemplateLiteral;
class RegExpLiteral;
-class ArrayLiteral;
-class ObjectLiteral;
+class ArrayPattern;
+class ObjectPattern;
class ElementList;
class Elision;
class PropertyDefinitionList;
diff --git a/src/qml/parser/qqmljsastvisitor_p.h b/src/qml/parser/qqmljsastvisitor_p.h
index 14b5aa135f..a8534ca684 100644
--- a/src/qml/parser/qqmljsastvisitor_p.h
+++ b/src/qml/parser/qqmljsastvisitor_p.h
@@ -137,11 +137,11 @@ public:
virtual bool visit(RegExpLiteral *) { return true; }
virtual void endVisit(RegExpLiteral *) {}
- virtual bool visit(ArrayLiteral *) { return true; }
- virtual void endVisit(ArrayLiteral *) {}
+ virtual bool visit(ArrayPattern *) { return true; }
+ virtual void endVisit(ArrayPattern *) {}
- virtual bool visit(ObjectLiteral *) { return true; }
- virtual void endVisit(ObjectLiteral *) {}
+ virtual bool visit(ObjectPattern *) { return true; }
+ virtual void endVisit(ObjectPattern *) {}
virtual bool visit(ElementList *) { return true; }
virtual void endVisit(ElementList *) {}