aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/parser
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-08-14 13:39:01 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-14 17:45:56 +0000
commit24a098793481c5e173e4271f775c96a37f0e6e1c (patch)
tree2688ff8d3c46076b3cb87e883f734df9d3bf87c7 /src/qml/parser
parent929ef25efd402368a9f154b61aa96b4b01a02ce2 (diff)
Simplify ES module body handling
Now that ImportDeclaration and ExportDeclaration are also statements in the AST, we can get rid of the ModuleItemList in the AST. We keep it in the grammar, but map it to a statement list. Change-Id: I4cab29fe9b075e88454fe3b194126f728000856a Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/parser')
-rw-r--r--src/qml/parser/qqmljs.g23
-rw-r--r--src/qml/parser/qqmljsast.cpp37
-rw-r--r--src/qml/parser/qqmljsast_p.h54
-rw-r--r--src/qml/parser/qqmljsastfwd_p.h1
4 files changed, 16 insertions, 99 deletions
diff --git a/src/qml/parser/qqmljs.g b/src/qml/parser/qqmljs.g
index faf465e7b9..8d85a006aa 100644
--- a/src/qml/parser/qqmljs.g
+++ b/src/qml/parser/qqmljs.g
@@ -287,7 +287,6 @@ public:
AST::PatternProperty *PatternProperty;
AST::PatternPropertyList *PatternPropertyList;
AST::ClassElementList *ClassElementList;
- AST::ModuleItemList *ModuleItemList;
AST::ImportClause *ImportClause;
AST::FromClause *FromClause;
AST::NameSpaceImport *NameSpaceImport;
@@ -3991,43 +3990,47 @@ ScriptBody: StatementList;
Module: ModuleBodyOpt;
/. case $rule_number: {
- sym(1).Node = new (pool) AST::ESModule(sym(1).ModuleItemList, pool);
+ sym(1).Node = new (pool) AST::ESModule(sym(1).StatementList);
} break;
./
ModuleBody: ModuleItemList;
/.
case $rule_number: {
- sym(1).ModuleItemList = sym(1).ModuleItemList->finish();
+ sym(1).StatementList = sym(1).StatementList->finish();
} break;
./
ModuleBodyOpt: ;
/.
case $rule_number: {
- sym(1).ModuleItemList = nullptr;
+ sym(1).StatementList = nullptr;
} break;
./
ModuleBodyOpt: ModuleBody;
ModuleItemList: ModuleItem;
-/.
- case $rule_number: {
- sym(1).ModuleItemList = new (pool) AST::ModuleItemList(sym(1).Node);
- } break;
-./
ModuleItemList: ModuleItemList ModuleItem;
/.
case $rule_number: {
- sym(1).ModuleItemList = new (pool) AST::ModuleItemList(sym(1).ModuleItemList, sym(2).Node);
+ sym(1).StatementList = sym(1).StatementList->append(sym(2).StatementList);
} break;
./
ModuleItem: ImportDeclaration T_AUTOMATIC_SEMICOLON;
+/. case $rule_number: Q_FALLTHROUGH(); ./
ModuleItem: ImportDeclaration T_SEMICOLON;
+/. case $rule_number: Q_FALLTHROUGH(); ./
ModuleItem: ExportDeclaration T_AUTOMATIC_SEMICOLON;
+/. case $rule_number: Q_FALLTHROUGH(); ./
ModuleItem: ExportDeclaration T_SEMICOLON;
+/.
+ case $rule_number: {
+ sym(1).StatementList = new (pool) AST::StatementList(sym(1).Node);
+ } break;
+./
+
ModuleItem: StatementListItem;
ImportDeclaration: T_IMPORT ImportClause FromClause;
diff --git a/src/qml/parser/qqmljsast.cpp b/src/qml/parser/qqmljsast.cpp
index ca4317a9a6..9484b53a39 100644
--- a/src/qml/parser/qqmljsast.cpp
+++ b/src/qml/parser/qqmljsast.cpp
@@ -1162,45 +1162,10 @@ void ExportDeclaration::accept0(Visitor *visitor)
visitor->endVisit(this);
}
-void ModuleItemList::accept0(Visitor *)
-{
- // See ESModule::accept0
- Q_UNREACHABLE();
-}
-
-StatementList *ModuleItemList::buildStatementList(MemoryPool *pool) const
-{
- StatementList *statements = nullptr;
- for (const ModuleItemList *item = this; item; item = item->next) {
- AST::StatementList *listItem = AST::cast<AST::StatementList*>(item->item);
- if (!listItem) {
- if (AST::ExportDeclaration *exportDecl = AST::cast<AST::ExportDeclaration*>(item->item))
- listItem = new (pool) AST::StatementList(exportDecl);
- else if (AST::ImportDeclaration *importDecl = AST::cast<AST::ImportDeclaration*>(item->item))
- listItem = new (pool) AST::StatementList(importDecl);
- else
- continue;
- }
- if (statements)
- statements = statements->append(listItem);
- else
- statements = listItem;
- }
- if (statements)
- statements = statements->finish();
- return statements;
-}
-
-
void ESModule::accept0(Visitor *visitor)
{
if (visitor->visit(this)) {
- // We don't accept the ModuleItemList (body) as instead the statement list items
- // as well as the import/export declarations are linked together in the statement
- // list. That way they are processed in correct order and can be used with the codegen's
- // defineFunction() that expects a statement list.
- // accept(body, visitor);
- accept(statements, visitor);
+ accept(body, visitor);
}
visitor->endVisit(this);
diff --git a/src/qml/parser/qqmljsast_p.h b/src/qml/parser/qqmljsast_p.h
index 1429d784c6..c74bf60a99 100644
--- a/src/qml/parser/qqmljsast_p.h
+++ b/src/qml/parser/qqmljsast_p.h
@@ -188,7 +188,6 @@ public:
Kind_ExportsList,
Kind_ExportClause,
Kind_ExportDeclaration,
- Kind_ModuleItemList,
Kind_NewExpression,
Kind_NewMemberExpression,
Kind_NotExpression,
@@ -2722,63 +2721,15 @@ public:
bool exportDefault = false;
};
-class QML_PARSER_EXPORT ModuleItemList: public Node
-{
-public:
- QQMLJS_DECLARE_AST_NODE(ModuleItemList)
-
- ModuleItemList(Node *item)
- : item(item)
- {
- kind = K;
- next = this;
- }
-
- ModuleItemList(ModuleItemList *previous, Node *item)
- : item(item)
- {
- kind = K;
- if (previous) {
- next = previous->next;
- previous->next = this;
- } else {
- next = this;
- }
- }
-
- ModuleItemList *finish()
- {
- ModuleItemList *head = next;
- next = nullptr;
- return head;
- }
-
- StatementList *buildStatementList(MemoryPool *pool) const;
-
- void accept0(Visitor *) override;
-
- SourceLocation firstSourceLocation() const override
- { return item->firstSourceLocation(); }
-
- SourceLocation lastSourceLocation() const override
- { return next ? next->lastSourceLocation() : item->lastSourceLocation(); }
-
-// attributes
- Node *item; // ImportDeclaration, ExportDeclaration or StatementList
- ModuleItemList *next;
-};
-
class QML_PARSER_EXPORT ESModule: public Node
{
public:
QQMLJS_DECLARE_AST_NODE(Module)
- ESModule(ModuleItemList *body, MemoryPool *pool)
+ ESModule(StatementList *body)
: body(body)
{
kind = K;
- if (body)
- statements = body->buildStatementList(pool);
}
void accept0(Visitor *visitor) override;
@@ -2790,8 +2741,7 @@ public:
{ return body ? body->lastSourceLocation() : SourceLocation(); }
// attributes
- ModuleItemList *body;
- StatementList *statements = nullptr;
+ StatementList *body;
};
class QML_PARSER_EXPORT DebuggerStatement: public Statement
diff --git a/src/qml/parser/qqmljsastfwd_p.h b/src/qml/parser/qqmljsastfwd_p.h
index f94ec1dbff..996264db59 100644
--- a/src/qml/parser/qqmljsastfwd_p.h
+++ b/src/qml/parser/qqmljsastfwd_p.h
@@ -172,7 +172,6 @@ class ImportClause;
class FromClause;
class ImportDeclaration;
class ModuleItem;
-class ModuleItemList;
class ESModule;
class DebuggerStatement;
class NestedExpression;