Commit b89c0a96 authored by rossberg@chromium.org's avatar rossberg@chromium.org

AST extensions and parsing for import & export declarations.

R=jkummerow@chromium.org
BUG=
TEST=

Review URL: https://chromiumcodereview.appspot.com/9496003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10866 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent b4a0a4dd
...@@ -1008,6 +1008,8 @@ CaseClause::CaseClause(Isolate* isolate, ...@@ -1008,6 +1008,8 @@ CaseClause::CaseClause(Isolate* isolate,
INCREASE_NODE_COUNT(VariableDeclaration) INCREASE_NODE_COUNT(VariableDeclaration)
INCREASE_NODE_COUNT(FunctionDeclaration) INCREASE_NODE_COUNT(FunctionDeclaration)
INCREASE_NODE_COUNT(ModuleDeclaration) INCREASE_NODE_COUNT(ModuleDeclaration)
INCREASE_NODE_COUNT(ImportDeclaration)
INCREASE_NODE_COUNT(ExportDeclaration)
INCREASE_NODE_COUNT(ModuleLiteral) INCREASE_NODE_COUNT(ModuleLiteral)
INCREASE_NODE_COUNT(ModuleVariable) INCREASE_NODE_COUNT(ModuleVariable)
INCREASE_NODE_COUNT(ModulePath) INCREASE_NODE_COUNT(ModulePath)
......
...@@ -63,6 +63,8 @@ namespace internal { ...@@ -63,6 +63,8 @@ namespace internal {
V(VariableDeclaration) \ V(VariableDeclaration) \
V(FunctionDeclaration) \ V(FunctionDeclaration) \
V(ModuleDeclaration) \ V(ModuleDeclaration) \
V(ImportDeclaration) \
V(ExportDeclaration) \
#define MODULE_NODE_LIST(V) \ #define MODULE_NODE_LIST(V) \
V(ModuleLiteral) \ V(ModuleLiteral) \
...@@ -544,6 +546,48 @@ class ModuleDeclaration: public Declaration { ...@@ -544,6 +546,48 @@ class ModuleDeclaration: public Declaration {
}; };
class ImportDeclaration: public Declaration {
public:
DECLARE_NODE_TYPE(ImportDeclaration)
Module* module() const { return module_; }
virtual InitializationFlag initialization() const {
return kCreatedInitialized;
}
protected:
template<class> friend class AstNodeFactory;
ImportDeclaration(VariableProxy* proxy,
Module* module,
Scope* scope)
: Declaration(proxy, LET, scope),
module_(module) {
}
private:
Module* module_;
};
class ExportDeclaration: public Declaration {
public:
DECLARE_NODE_TYPE(ExportDeclaration)
virtual InitializationFlag initialization() const {
return kCreatedInitialized;
}
protected:
template<class> friend class AstNodeFactory;
ExportDeclaration(VariableProxy* proxy,
Scope* scope)
: Declaration(proxy, LET, scope) {
}
};
class Module: public AstNode { class Module: public AstNode {
// TODO(rossberg): stuff to come... // TODO(rossberg): stuff to come...
protected: protected:
...@@ -2580,6 +2624,21 @@ class AstNodeFactory BASE_EMBEDDED { ...@@ -2580,6 +2624,21 @@ class AstNodeFactory BASE_EMBEDDED {
VISIT_AND_RETURN(ModuleDeclaration, decl) VISIT_AND_RETURN(ModuleDeclaration, decl)
} }
ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
Module* module,
Scope* scope) {
ImportDeclaration* decl =
new(zone_) ImportDeclaration(proxy, module, scope);
VISIT_AND_RETURN(ImportDeclaration, decl)
}
ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
Scope* scope) {
ExportDeclaration* decl =
new(zone_) ExportDeclaration(proxy, scope);
VISIT_AND_RETURN(ExportDeclaration, decl)
}
ModuleLiteral* NewModuleLiteral(Block* body) { ModuleLiteral* NewModuleLiteral(Block* body) {
ModuleLiteral* module = new(zone_) ModuleLiteral(body); ModuleLiteral* module = new(zone_) ModuleLiteral(body);
VISIT_AND_RETURN(ModuleLiteral, module) VISIT_AND_RETURN(ModuleLiteral, module)
......
...@@ -63,6 +63,14 @@ void BreakableStatementChecker::VisitModuleDeclaration( ...@@ -63,6 +63,14 @@ void BreakableStatementChecker::VisitModuleDeclaration(
ModuleDeclaration* decl) { ModuleDeclaration* decl) {
} }
void BreakableStatementChecker::VisitImportDeclaration(
ImportDeclaration* decl) {
}
void BreakableStatementChecker::VisitExportDeclaration(
ExportDeclaration* decl) {
}
void BreakableStatementChecker::VisitModuleLiteral(ModuleLiteral* module) { void BreakableStatementChecker::VisitModuleLiteral(ModuleLiteral* module) {
} }
...@@ -622,6 +630,16 @@ void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* decl) { ...@@ -622,6 +630,16 @@ void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* decl) {
} }
void FullCodeGenerator::VisitImportDeclaration(ImportDeclaration* decl) {
EmitDeclaration(decl->proxy(), decl->mode(), NULL);
}
void FullCodeGenerator::VisitExportDeclaration(ExportDeclaration* decl) {
// TODO(rossberg)
}
void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) { void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) {
// TODO(rossberg) // TODO(rossberg)
} }
......
...@@ -6932,7 +6932,17 @@ void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { ...@@ -6932,7 +6932,17 @@ void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) {
void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* decl) { void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* decl) {
// TODO(rossberg) UNREACHABLE();
}
void HGraphBuilder::VisitImportDeclaration(ImportDeclaration* decl) {
UNREACHABLE();
}
void HGraphBuilder::VisitExportDeclaration(ExportDeclaration* decl) {
UNREACHABLE();
} }
......
This diff is collapsed.
...@@ -581,23 +581,26 @@ class Parser { ...@@ -581,23 +581,26 @@ class Parser {
void* ParseSourceElements(ZoneList<Statement*>* processor, void* ParseSourceElements(ZoneList<Statement*>* processor,
int end_token, bool* ok); int end_token, bool* ok);
Statement* ParseModuleElement(ZoneStringList* labels, bool* ok); Statement* ParseModuleElement(ZoneStringList* labels, bool* ok);
Block* ParseModuleDeclaration(bool* ok); Block* ParseModuleDeclaration(ZoneStringList* names, bool* ok);
Module* ParseModule(bool* ok); Module* ParseModule(bool* ok);
Module* ParseModuleLiteral(bool* ok); Module* ParseModuleLiteral(bool* ok);
Module* ParseModulePath(bool* ok); Module* ParseModulePath(bool* ok);
Module* ParseModuleVariable(bool* ok); Module* ParseModuleVariable(bool* ok);
Module* ParseModuleUrl(bool* ok); Module* ParseModuleUrl(bool* ok);
Module* ParseModuleSpecifier(bool* ok);
Block* ParseImportDeclaration(bool* ok); Block* ParseImportDeclaration(bool* ok);
Block* ParseExportDeclaration(bool* ok); Statement* ParseExportDeclaration(bool* ok);
Statement* ParseBlockElement(ZoneStringList* labels, bool* ok); Statement* ParseBlockElement(ZoneStringList* labels, bool* ok);
Statement* ParseStatement(ZoneStringList* labels, bool* ok); Statement* ParseStatement(ZoneStringList* labels, bool* ok);
Statement* ParseFunctionDeclaration(bool* ok); Statement* ParseFunctionDeclaration(ZoneStringList* names, bool* ok);
Statement* ParseNativeDeclaration(bool* ok); Statement* ParseNativeDeclaration(bool* ok);
Block* ParseBlock(ZoneStringList* labels, bool* ok); Block* ParseBlock(ZoneStringList* labels, bool* ok);
Block* ParseVariableStatement(VariableDeclarationContext var_context, Block* ParseVariableStatement(VariableDeclarationContext var_context,
ZoneStringList* names,
bool* ok); bool* ok);
Block* ParseVariableDeclarations(VariableDeclarationContext var_context, Block* ParseVariableDeclarations(VariableDeclarationContext var_context,
VariableDeclarationProperties* decl_props, VariableDeclarationProperties* decl_props,
ZoneStringList* names,
Handle<String>* out, Handle<String>* out,
bool* ok); bool* ok);
Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels,
...@@ -700,6 +703,7 @@ class Parser { ...@@ -700,6 +703,7 @@ class Parser {
void Expect(Token::Value token, bool* ok); void Expect(Token::Value token, bool* ok);
bool Check(Token::Value token); bool Check(Token::Value token);
void ExpectSemicolon(bool* ok); void ExpectSemicolon(bool* ok);
void ExpectContextualKeyword(const char* keyword, bool* ok);
Handle<String> LiteralString(PretenureFlag tenured) { Handle<String> LiteralString(PretenureFlag tenured) {
if (scanner().is_literal_ascii()) { if (scanner().is_literal_ascii()) {
......
...@@ -83,6 +83,22 @@ void PrettyPrinter::VisitModuleDeclaration(ModuleDeclaration* node) { ...@@ -83,6 +83,22 @@ void PrettyPrinter::VisitModuleDeclaration(ModuleDeclaration* node) {
} }
void PrettyPrinter::VisitImportDeclaration(ImportDeclaration* node) {
Print("import ");
PrintLiteral(node->proxy()->name(), false);
Print(" from ");
Visit(node->module());
Print(";");
}
void PrettyPrinter::VisitExportDeclaration(ExportDeclaration* node) {
Print("export ");
PrintLiteral(node->proxy()->name(), false);
Print(";");
}
void PrettyPrinter::VisitModuleLiteral(ModuleLiteral* node) { void PrettyPrinter::VisitModuleLiteral(ModuleLiteral* node) {
VisitBlock(node->body()); VisitBlock(node->body());
} }
...@@ -771,6 +787,19 @@ void AstPrinter::VisitModuleDeclaration(ModuleDeclaration* node) { ...@@ -771,6 +787,19 @@ void AstPrinter::VisitModuleDeclaration(ModuleDeclaration* node) {
} }
void AstPrinter::VisitImportDeclaration(ImportDeclaration* node) {
IndentedScope indent(this, "IMPORT");
PrintLiteralIndented("NAME", node->proxy()->name(), true);
Visit(node->module());
}
void AstPrinter::VisitExportDeclaration(ExportDeclaration* node) {
IndentedScope indent(this, "EXPORT ");
PrintLiteral(node->proxy()->name(), true);
}
void AstPrinter::VisitModuleLiteral(ModuleLiteral* node) { void AstPrinter::VisitModuleLiteral(ModuleLiteral* node) {
VisitBlock(node->body()); VisitBlock(node->body());
} }
......
...@@ -212,6 +212,8 @@ void Processor::VisitWithStatement(WithStatement* node) { ...@@ -212,6 +212,8 @@ void Processor::VisitWithStatement(WithStatement* node) {
void Processor::VisitVariableDeclaration(VariableDeclaration* node) {} void Processor::VisitVariableDeclaration(VariableDeclaration* node) {}
void Processor::VisitFunctionDeclaration(FunctionDeclaration* node) {} void Processor::VisitFunctionDeclaration(FunctionDeclaration* node) {}
void Processor::VisitModuleDeclaration(ModuleDeclaration* node) {} void Processor::VisitModuleDeclaration(ModuleDeclaration* node) {}
void Processor::VisitImportDeclaration(ImportDeclaration* node) {}
void Processor::VisitExportDeclaration(ExportDeclaration* node) {}
void Processor::VisitModuleLiteral(ModuleLiteral* node) {} void Processor::VisitModuleLiteral(ModuleLiteral* node) {}
void Processor::VisitModuleVariable(ModuleVariable* node) {} void Processor::VisitModuleVariable(ModuleVariable* node) {}
void Processor::VisitModulePath(ModulePath* node) {} void Processor::VisitModulePath(ModulePath* node) {}
......
...@@ -36,19 +36,39 @@ module A2 = A; ...@@ -36,19 +36,39 @@ module A2 = A;
module A3 = A2 module A3 = A2
module B { module B {
var x export x
var x, y; export y, z, c, f
var x = 0, y
let x, y var vx
let z = 1 var vx, vy;
var vx = 0, vy
let lx, ly
let lz = 1
const c = 9 const c = 9
function f() {} function f() {}
module C { module C {
let x let x
module D {} module D {}
let y let y
} }
let zz = "" let zz = ""
export var x0
export var x1, x2 = 6, x3
export let y0
export let y1 = 0, y2
export const z0 = 0
export const z1 = 2, z2 = 3
export function f0() {}
export module M1 {}
export module M2 = C.D
export module M3 at "http://where"
import i0 from I
import i1, i2, i3 from I
import i4, i5 from "http://where"
} }
module C1 = B.C; module C1 = B.C;
...@@ -76,6 +96,45 @@ module Z ...@@ -76,6 +96,45 @@ module Z
at at
"file://local" "file://local"
import
x
,
y
from
"file://local"
module Wrap {
export
x
,
y
export
var
v1 = 1
export
let
v2 = 2
export
const
v3 = 3
export
function
f
(
)
{
}
export
module V
{
}
}
// Check that 'module' still works as an identifier. // Check that 'module' still works as an identifier.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment