Extend AST with basic module constructs (yet unused).
R=jkummerow@chromium.org BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/9373023 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10663 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
751508d6aa
commit
5498a6345a
@ -995,6 +995,11 @@ CaseClause::CaseClause(Isolate* isolate,
|
||||
}
|
||||
|
||||
INCREASE_NODE_COUNT(VariableDeclaration)
|
||||
INCREASE_NODE_COUNT(ModuleDeclaration)
|
||||
INCREASE_NODE_COUNT(ModuleLiteral)
|
||||
INCREASE_NODE_COUNT(ModuleVariable)
|
||||
INCREASE_NODE_COUNT(ModulePath)
|
||||
INCREASE_NODE_COUNT(ModuleUrl)
|
||||
INCREASE_NODE_COUNT(Block)
|
||||
INCREASE_NODE_COUNT(ExpressionStatement)
|
||||
INCREASE_NODE_COUNT(EmptyStatement)
|
||||
|
148
src/ast.h
148
src/ast.h
@ -61,6 +61,13 @@ namespace internal {
|
||||
|
||||
#define DECLARATION_NODE_LIST(V) \
|
||||
V(VariableDeclaration) \
|
||||
V(ModuleDeclaration) \
|
||||
|
||||
#define MODULE_NODE_LIST(V) \
|
||||
V(ModuleLiteral) \
|
||||
V(ModuleVariable) \
|
||||
V(ModulePath) \
|
||||
V(ModuleUrl)
|
||||
|
||||
#define STATEMENT_NODE_LIST(V) \
|
||||
V(Block) \
|
||||
@ -103,6 +110,7 @@ namespace internal {
|
||||
|
||||
#define AST_NODE_LIST(V) \
|
||||
DECLARATION_NODE_LIST(V) \
|
||||
MODULE_NODE_LIST(V) \
|
||||
STATEMENT_NODE_LIST(V) \
|
||||
EXPRESSION_NODE_LIST(V)
|
||||
|
||||
@ -111,6 +119,7 @@ class AstConstructionVisitor;
|
||||
template<class> class AstNodeFactory;
|
||||
class AstVisitor;
|
||||
class Declaration;
|
||||
class Module;
|
||||
class BreakableStatement;
|
||||
class Expression;
|
||||
class IterationStatement;
|
||||
@ -301,10 +310,6 @@ class Expression: public AstNode {
|
||||
kTest
|
||||
};
|
||||
|
||||
explicit Expression(Isolate* isolate)
|
||||
: id_(GetNextId(isolate)),
|
||||
test_id_(GetNextId(isolate)) {}
|
||||
|
||||
virtual int position() const {
|
||||
UNREACHABLE();
|
||||
return 0;
|
||||
@ -355,6 +360,11 @@ class Expression: public AstNode {
|
||||
unsigned id() const { return id_; }
|
||||
unsigned test_id() const { return test_id_; }
|
||||
|
||||
protected:
|
||||
explicit Expression(Isolate* isolate)
|
||||
: id_(GetNextId(isolate)),
|
||||
test_id_(GetNextId(isolate)) {}
|
||||
|
||||
private:
|
||||
int id_;
|
||||
int test_id_;
|
||||
@ -495,6 +505,108 @@ class VariableDeclaration: public Declaration {
|
||||
};
|
||||
|
||||
|
||||
class ModuleDeclaration: public Declaration {
|
||||
public:
|
||||
DECLARE_NODE_TYPE(ModuleDeclaration)
|
||||
|
||||
Module* module() const { return module_; }
|
||||
|
||||
protected:
|
||||
template<class> friend class AstNodeFactory;
|
||||
|
||||
ModuleDeclaration(VariableProxy* proxy,
|
||||
Module* module,
|
||||
Scope* scope)
|
||||
: Declaration(proxy, LET, scope),
|
||||
module_(module) {
|
||||
}
|
||||
|
||||
private:
|
||||
Module* module_;
|
||||
};
|
||||
|
||||
|
||||
class Module: public AstNode {
|
||||
// TODO(rossberg): stuff to come...
|
||||
protected:
|
||||
Module() {}
|
||||
};
|
||||
|
||||
|
||||
class ModuleLiteral: public Module {
|
||||
public:
|
||||
DECLARE_NODE_TYPE(ModuleLiteral)
|
||||
|
||||
Block* body() const { return body_; }
|
||||
|
||||
protected:
|
||||
template<class> friend class AstNodeFactory;
|
||||
|
||||
ModuleLiteral(Block* body)
|
||||
: body_(body) {
|
||||
}
|
||||
|
||||
private:
|
||||
Block* body_;
|
||||
};
|
||||
|
||||
|
||||
class ModuleVariable: public Module {
|
||||
public:
|
||||
DECLARE_NODE_TYPE(ModuleVariable)
|
||||
|
||||
Variable* var() const { return var_; }
|
||||
|
||||
protected:
|
||||
template<class> friend class AstNodeFactory;
|
||||
|
||||
ModuleVariable(Variable* var)
|
||||
: var_(var) {
|
||||
}
|
||||
|
||||
private:
|
||||
Variable* var_;
|
||||
};
|
||||
|
||||
|
||||
class ModulePath: public Module {
|
||||
public:
|
||||
DECLARE_NODE_TYPE(ModulePath)
|
||||
|
||||
Module* module() const { return module_; }
|
||||
Handle<String> name() const { return name_; }
|
||||
|
||||
protected:
|
||||
template<class> friend class AstNodeFactory;
|
||||
|
||||
ModulePath(Module* module, Handle<String> name)
|
||||
: module_(module),
|
||||
name_(name) {
|
||||
}
|
||||
|
||||
private:
|
||||
Module* module_;
|
||||
Handle<String> name_;
|
||||
};
|
||||
|
||||
|
||||
class ModuleUrl: public Module {
|
||||
public:
|
||||
DECLARE_NODE_TYPE(ModuleUrl)
|
||||
|
||||
Handle<String> url() const { return url_; }
|
||||
|
||||
protected:
|
||||
template<class> friend class AstNodeFactory;
|
||||
|
||||
ModuleUrl(Handle<String> url) : url_(url) {
|
||||
}
|
||||
|
||||
private:
|
||||
Handle<String> url_;
|
||||
};
|
||||
|
||||
|
||||
class IterationStatement: public BreakableStatement {
|
||||
public:
|
||||
// Type testing & conversion.
|
||||
@ -2400,6 +2512,34 @@ class AstNodeFactory BASE_EMBEDDED {
|
||||
VISIT_AND_RETURN(VariableDeclaration, decl)
|
||||
}
|
||||
|
||||
ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
|
||||
Module* module,
|
||||
Scope* scope) {
|
||||
ModuleDeclaration* decl =
|
||||
new(zone_) ModuleDeclaration(proxy, module, scope);
|
||||
VISIT_AND_RETURN(ModuleDeclaration, decl)
|
||||
}
|
||||
|
||||
ModuleLiteral* NewModuleLiteral(Block* body) {
|
||||
ModuleLiteral* module = new(zone_) ModuleLiteral(body);
|
||||
VISIT_AND_RETURN(ModuleLiteral, module)
|
||||
}
|
||||
|
||||
ModuleVariable* NewModuleVariable(Variable* var) {
|
||||
ModuleVariable* module = new(zone_) ModuleVariable(var);
|
||||
VISIT_AND_RETURN(ModuleLiteral, module)
|
||||
}
|
||||
|
||||
ModulePath* NewModulePath(Module* origin, Handle<String> name) {
|
||||
ModulePath* module = new(zone_) ModulePath(origin, name);
|
||||
VISIT_AND_RETURN(ModuleLiteral, module)
|
||||
}
|
||||
|
||||
ModuleUrl* NewModuleUrl(Handle<String> url) {
|
||||
ModuleUrl* module = new(zone_) ModuleUrl(url);
|
||||
VISIT_AND_RETURN(ModuleLiteral, module)
|
||||
}
|
||||
|
||||
Block* NewBlock(ZoneStringList* labels,
|
||||
int capacity,
|
||||
bool is_initializer_block) {
|
||||
|
@ -55,6 +55,23 @@ void BreakableStatementChecker::VisitVariableDeclaration(
|
||||
VariableDeclaration* decl) {
|
||||
}
|
||||
|
||||
void BreakableStatementChecker::VisitModuleDeclaration(
|
||||
ModuleDeclaration* decl) {
|
||||
}
|
||||
|
||||
|
||||
void BreakableStatementChecker::VisitModuleLiteral(ModuleLiteral* module) {
|
||||
}
|
||||
|
||||
void BreakableStatementChecker::VisitModuleVariable(ModuleVariable* module) {
|
||||
}
|
||||
|
||||
void BreakableStatementChecker::VisitModulePath(ModulePath* module) {
|
||||
}
|
||||
|
||||
void BreakableStatementChecker::VisitModuleUrl(ModuleUrl* module) {
|
||||
}
|
||||
|
||||
|
||||
void BreakableStatementChecker::VisitBlock(Block* stmt) {
|
||||
}
|
||||
@ -527,11 +544,6 @@ void FullCodeGenerator::DoTest(const TestContext* context) {
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) {
|
||||
EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::VisitDeclarations(
|
||||
ZoneList<Declaration*>* declarations) {
|
||||
int save_global_count = global_count_;
|
||||
@ -580,6 +592,36 @@ void FullCodeGenerator::VisitDeclarations(
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) {
|
||||
EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::VisitModuleDeclaration(ModuleDeclaration* decl) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::VisitModuleLiteral(ModuleLiteral* module) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::VisitModuleVariable(ModuleVariable* module) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::VisitModulePath(ModulePath* module) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
void FullCodeGenerator::VisitModuleUrl(ModuleUrl* decl) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
int FullCodeGenerator::DeclareGlobalsFlags() {
|
||||
ASSERT(DeclareGlobalsLanguageMode::is_valid(language_mode()));
|
||||
return DeclareGlobalsEvalFlag::encode(is_eval()) |
|
||||
|
@ -6582,6 +6582,31 @@ void HGraphBuilder::HandleVariableDeclaration(VariableProxy* proxy,
|
||||
}
|
||||
|
||||
|
||||
void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* decl) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
void HGraphBuilder::VisitModuleLiteral(ModuleLiteral* module) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
void HGraphBuilder::VisitModuleVariable(ModuleVariable* module) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
void HGraphBuilder::VisitModulePath(ModulePath* module) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
void HGraphBuilder::VisitModuleUrl(ModuleUrl* module) {
|
||||
// TODO(rossberg)
|
||||
}
|
||||
|
||||
|
||||
// Generators for inline runtime functions.
|
||||
// Support for types.
|
||||
void HGraphBuilder::GenerateIsSmi(CallRuntime* call) {
|
||||
|
@ -69,6 +69,38 @@ void PrettyPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
|
||||
}
|
||||
|
||||
|
||||
void PrettyPrinter::VisitModuleDeclaration(ModuleDeclaration* node) {
|
||||
Print("module ");
|
||||
PrintLiteral(node->proxy()->name(), false);
|
||||
Print(" = ");
|
||||
Visit(node->module());
|
||||
Print(";");
|
||||
}
|
||||
|
||||
|
||||
void PrettyPrinter::VisitModuleLiteral(ModuleLiteral* node) {
|
||||
VisitBlock(node->body());
|
||||
}
|
||||
|
||||
|
||||
void PrettyPrinter::VisitModuleVariable(ModuleVariable* node) {
|
||||
PrintLiteral(node->var()->name(), false);
|
||||
}
|
||||
|
||||
|
||||
void PrettyPrinter::VisitModulePath(ModulePath* node) {
|
||||
Visit(node->module());
|
||||
Print(".");
|
||||
PrintLiteral(node->name(), false);
|
||||
}
|
||||
|
||||
|
||||
void PrettyPrinter::VisitModuleUrl(ModuleUrl* node) {
|
||||
Print("at ");
|
||||
PrintLiteral(node->url(), true);
|
||||
}
|
||||
|
||||
|
||||
void PrettyPrinter::VisitExpressionStatement(ExpressionStatement* node) {
|
||||
Visit(node->expression());
|
||||
Print(";");
|
||||
@ -728,6 +760,35 @@ void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
|
||||
}
|
||||
|
||||
|
||||
void AstPrinter::VisitModuleDeclaration(ModuleDeclaration* node) {
|
||||
IndentedScope indent(this, "MODULE");
|
||||
PrintLiteralIndented("NAME", node->proxy()->name(), true);
|
||||
Visit(node->module());
|
||||
}
|
||||
|
||||
|
||||
void AstPrinter::VisitModuleLiteral(ModuleLiteral* node) {
|
||||
VisitBlock(node->body());
|
||||
}
|
||||
|
||||
|
||||
void AstPrinter::VisitModuleVariable(ModuleVariable* node) {
|
||||
PrintLiteralIndented("VARIABLE", node->var()->name(), false);
|
||||
}
|
||||
|
||||
|
||||
void AstPrinter::VisitModulePath(ModulePath* node) {
|
||||
IndentedScope indent(this, "PATH");
|
||||
PrintIndentedVisit("MODULE", node->module());
|
||||
PrintLiteralIndented("NAME", node->name(), false);
|
||||
}
|
||||
|
||||
|
||||
void AstPrinter::VisitModuleUrl(ModuleUrl* node) {
|
||||
PrintLiteralIndented("URL", node->url(), true);
|
||||
}
|
||||
|
||||
|
||||
void AstPrinter::VisitExpressionStatement(ExpressionStatement* node) {
|
||||
Visit(node->expression());
|
||||
}
|
||||
|
@ -210,6 +210,11 @@ void Processor::VisitWithStatement(WithStatement* node) {
|
||||
|
||||
// Do nothing:
|
||||
void Processor::VisitVariableDeclaration(VariableDeclaration* node) {}
|
||||
void Processor::VisitModuleDeclaration(ModuleDeclaration* node) {}
|
||||
void Processor::VisitModuleLiteral(ModuleLiteral* node) {}
|
||||
void Processor::VisitModuleVariable(ModuleVariable* node) {}
|
||||
void Processor::VisitModulePath(ModulePath* node) {}
|
||||
void Processor::VisitModuleUrl(ModuleUrl* node) {}
|
||||
void Processor::VisitEmptyStatement(EmptyStatement* node) {}
|
||||
void Processor::VisitReturnStatement(ReturnStatement* node) {}
|
||||
void Processor::VisitDebuggerStatement(DebuggerStatement* node) {}
|
||||
|
Loading…
Reference in New Issue
Block a user