aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4compilercontext_p.h
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2018-07-10 14:52:34 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2018-08-09 13:18:39 +0000
commit82da798499aa8b656e771191332864a703069739 (patch)
tree35cb1d0ef8dd3d949f8b6f6324d19ec577b3f4df /src/qml/compiler/qv4compilercontext_p.h
parent6510046ee32ef69d7f250fd1d829063983f93fdd (diff)
Add initial basic support for ES6 modules
The entry point from the parsing perspective into modules is not QV4::Script but QV4::ExecutionEngine::compileModule. For convenience, the ESModule AST node gets a body, which is the statement list connected between the ModuleItemList items that are not import/export declarations. The QV4::Module allocates a call context where the exported variables are stored as named locals. This will also become the module namespace object. The imports in turn is an array of value pointers that point into the locals array of the context of the imported modules. The default module loading in ExecutionEngine assumes the accessibility of module urls via QFile (so local file system or resource). This is what qmljs also uses and QJSEngine as well via public API in the future. The test runner compiles the modules manually and injects them, because they need to be compiled together with the test harness code. The QML type loader will the mechanism for injection in the future for module imports from .qml files. Change-Id: I93be9cfe54c651fdbd08c5e1d22d58f47284e54f Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4compilercontext_p.h')
-rw-r--r--src/qml/compiler/qv4compilercontext_p.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4compilercontext_p.h b/src/qml/compiler/qv4compilercontext_p.h
index 52c3fc5b05..6a54be2aca 100644
--- a/src/qml/compiler/qv4compilercontext_p.h
+++ b/src/qml/compiler/qv4compilercontext_p.h
@@ -74,7 +74,8 @@ enum class ContextType {
// * function declarations are moved to the return address when encountered
// * return statements are allowed everywhere (like in FunctionCode)
// * variable declarations are treated as true locals (like in FunctionCode)
- Block
+ Block,
+ ESModule
};
struct Context;
@@ -97,6 +98,24 @@ struct Class {
QVector<Method> methods;
};
+struct ExportEntry
+{
+ QString exportName;
+ QString moduleRequest;
+ QString importName;
+ QString localName;
+
+ static bool lessThan(const ExportEntry &lhs, const ExportEntry &rhs)
+ { return lhs.exportName < rhs.exportName; }
+};
+
+struct ImportEntry
+{
+ QString moduleRequest;
+ QString importName;
+ QString localName;
+};
+
struct Module {
Module(bool debugMode)
: debugMode(debugMode)
@@ -117,6 +136,10 @@ struct Module {
QDateTime sourceTimeStamp;
uint unitFlags = 0; // flags merged into CompiledData::Unit::flags
bool debugMode = false;
+ QVector<ExportEntry> localExportEntries;
+ QVector<ExportEntry> indirectExportEntries;
+ QVector<ExportEntry> starExportEntries;
+ QVector<ImportEntry> importEntries;
};
@@ -153,6 +176,8 @@ struct Context {
QQmlJS::AST::FormalParameterList *formals = nullptr;
QStringList arguments;
QStringList locals;
+ QVector<ImportEntry> importEntries;
+ QVector<ExportEntry> exportEntries;
QVector<Context *> nestedContexts;
ControlFlow *controlFlow = nullptr;
@@ -289,7 +314,8 @@ struct Context {
Unresolved,
Global,
Local,
- Stack
+ Stack,
+ Import
};
Type type = Unresolved;
bool isArgOrEval = false;