Revision: 10662
Author: [email protected]
Date: Thu Feb 9 05:39:26 2012
Log: Split AST Declaration class, in preparation for new module
declaration forms.
Turns Declaration into an abstract class, and introduces
VariableDeclaration as a concrete subclass.
[email protected]
BUG=
TEST=
Review URL: https://chromiumcodereview.appspot.com/9348057
http://code.google.com/p/v8/source/detail?r=10662
Modified:
/branches/bleeding_edge/src/arm/full-codegen-arm.cc
/branches/bleeding_edge/src/ast.cc
/branches/bleeding_edge/src/ast.h
/branches/bleeding_edge/src/full-codegen.cc
/branches/bleeding_edge/src/full-codegen.h
/branches/bleeding_edge/src/hydrogen.cc
/branches/bleeding_edge/src/hydrogen.h
/branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
/branches/bleeding_edge/src/parser.cc
/branches/bleeding_edge/src/prettyprinter.cc
/branches/bleeding_edge/src/rewriter.cc
/branches/bleeding_edge/src/x64/full-codegen-x64.cc
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Thu Feb 9 02:19:46
2012
+++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Thu Feb 9 05:39:26
2012
@@ -286,11 +286,11 @@
// For named function expressions, declare the function name as a
// constant.
if (scope()->is_function_scope() && scope()->function() != NULL) {
- int ignored = 0;
VariableProxy* proxy = scope()->function();
ASSERT(proxy->var()->mode() == CONST ||
proxy->var()->mode() == CONST_HARMONY);
- EmitDeclaration(proxy, proxy->var()->mode(), NULL, &ignored);
+ ASSERT(proxy->var()->location() != Variable::UNALLOCATED);
+ EmitDeclaration(proxy, proxy->var()->mode(), NULL);
}
VisitDeclarations(scope()->declarations());
}
@@ -727,8 +727,7 @@
void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
VariableMode mode,
- FunctionLiteral* function,
- int* global_count) {
+ FunctionLiteral* function) {
// If it was not possible to allocate the variable at compile time, we
// need to "declare" it at runtime to make sure it actually exists in the
// local context.
@@ -737,7 +736,7 @@
(mode == CONST || mode == CONST_HARMONY || mode == LET);
switch (variable->location()) {
case Variable::UNALLOCATED:
- ++(*global_count);
+ ++global_count_;
break;
case Variable::PARAMETER:
@@ -820,9 +819,6 @@
}
}
}
-
-
-void FullCodeGenerator::VisitDeclaration(Declaration* decl) { }
void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
=======================================
--- /branches/bleeding_edge/src/ast.cc Thu Feb 9 02:19:46 2012
+++ /branches/bleeding_edge/src/ast.cc Thu Feb 9 05:39:26 2012
@@ -414,9 +414,13 @@
// Inlining support
bool Declaration::IsInlineable() const {
- return proxy()->var()->IsStackAllocated() && fun() == NULL;
+ return proxy()->var()->IsStackAllocated();
}
+bool VariableDeclaration::IsInlineable() const {
+ return Declaration::IsInlineable() && fun() == NULL;
+}
+
//
----------------------------------------------------------------------------
// Recording of type feedback
@@ -990,7 +994,7 @@
increase_node_count(); \
}
-INCREASE_NODE_COUNT(Declaration)
+INCREASE_NODE_COUNT(VariableDeclaration)
INCREASE_NODE_COUNT(Block)
INCREASE_NODE_COUNT(ExpressionStatement)
INCREASE_NODE_COUNT(EmptyStatement)
=======================================
--- /branches/bleeding_edge/src/ast.h Thu Feb 9 02:19:46 2012
+++ /branches/bleeding_edge/src/ast.h Thu Feb 9 05:39:26 2012
@@ -59,6 +59,9 @@
// Nodes of the abstract syntax tree. Only concrete classes are
// enumerated here.
+#define DECLARATION_NODE_LIST(V) \
+ V(VariableDeclaration) \
+
#define STATEMENT_NODE_LIST(V) \
V(Block) \
V(ExpressionStatement) \
@@ -99,7 +102,7 @@
V(ThisFunction)
#define AST_NODE_LIST(V) \
- V(Declaration) \
+ DECLARATION_NODE_LIST(V) \
STATEMENT_NODE_LIST(V) \
EXPRESSION_NODE_LIST(V)
@@ -107,6 +110,7 @@
class AstConstructionVisitor;
template<class> class AstNodeFactory;
class AstVisitor;
+class Declaration;
class BreakableStatement;
class Expression;
class IterationStatement;
@@ -202,6 +206,7 @@
AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
#undef DECLARE_NODE_FUNCTIONS
+ virtual Declaration* AsDeclaration() { return NULL; }
virtual Statement* AsStatement() { return NULL; }
virtual Expression* AsExpression() { return NULL; }
virtual TargetCollector* AsTargetCollector() { return NULL; }
@@ -433,43 +438,63 @@
class Declaration: public AstNode {
public:
- DECLARE_NODE_TYPE(Declaration)
-
VariableProxy* proxy() const { return proxy_; }
VariableMode mode() const { return mode_; }
- FunctionLiteral* fun() const { return fun_; } // may be NULL
- bool IsInlineable() const;
Scope* scope() const { return scope_; }
-
- protected:
- template<class> friend class AstNodeFactory;
-
+ virtual bool IsInlineable() const;
+
+ virtual Declaration* AsDeclaration() { return this; }
+ virtual VariableDeclaration* AsVariableDeclaration() { return NULL; }
+
+ protected:
Declaration(VariableProxy* proxy,
VariableMode mode,
- FunctionLiteral* fun,
Scope* scope)
: proxy_(proxy),
mode_(mode),
- fun_(fun),
scope_(scope) {
ASSERT(mode == VAR ||
mode == CONST ||
mode == CONST_HARMONY ||
mode == LET);
- // At the moment there are no "const functions"'s in JavaScript...
- ASSERT(fun == NULL || mode == VAR || mode == LET);
}
private:
VariableProxy* proxy_;
VariableMode mode_;
- FunctionLiteral* fun_;
// Nested scope from which the declaration originated.
Scope* scope_;
};
+class VariableDeclaration: public Declaration {
+ public:
+ DECLARE_NODE_TYPE(VariableDeclaration)
+
+ virtual VariableDeclaration* AsVariableDeclaration() { return this; }
+
+ FunctionLiteral* fun() const { return fun_; } // may be NULL
+ virtual bool IsInlineable() const;
+
+ protected:
+ template<class> friend class AstNodeFactory;
+
+ VariableDeclaration(VariableProxy* proxy,
+ VariableMode mode,
+ FunctionLiteral* fun,
+ Scope* scope)
+ : Declaration(proxy, mode, scope),
+ fun_(fun) {
+ // At the moment there are no "const functions"'s in JavaScript...
+ ASSERT(fun == NULL || mode == VAR || mode == LET);
+ }
+
+ private:
+ FunctionLiteral* fun_;
+};
+
+
class IterationStatement: public BreakableStatement {
public:
// Type testing & conversion.
@@ -2365,6 +2390,15 @@
#define VISIT_AND_RETURN(NodeType, node) \
visitor_.Visit##NodeType((node)); \
return node;
+
+ VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
+ VariableMode mode,
+ FunctionLiteral* fun,
+ Scope* scope) {
+ VariableDeclaration* decl =
+ new(zone_) VariableDeclaration(proxy, mode, fun, scope);
+ VISIT_AND_RETURN(VariableDeclaration, decl)
+ }
Block* NewBlock(ZoneStringList* labels,
int capacity,
@@ -2373,14 +2407,6 @@
isolate_, labels, capacity, is_initializer_block);
VISIT_AND_RETURN(Block, block)
}
-
- Declaration* NewDeclaration(VariableProxy* proxy,
- VariableMode mode,
- FunctionLiteral* fun,
- Scope* scope) {
- Declaration* decl = new(zone_) Declaration(proxy, mode, fun, scope);
- VISIT_AND_RETURN(Declaration, decl)
- }
#define STATEMENT_WITH_LABELS(NodeType) \
NodeType* New##NodeType(ZoneStringList* labels) { \
=======================================
--- /branches/bleeding_edge/src/full-codegen.cc Thu Feb 9 02:19:46 2012
+++ /branches/bleeding_edge/src/full-codegen.cc Thu Feb 9 05:39:26 2012
@@ -51,7 +51,8 @@
}
-void BreakableStatementChecker::VisitDeclaration(Declaration* decl) {
+void BreakableStatementChecker::VisitVariableDeclaration(
+ VariableDeclaration* decl) {
}
@@ -524,43 +525,49 @@
context->false_label(),
context->fall_through());
}
+
+
+void FullCodeGenerator::VisitVariableDeclaration(VariableDeclaration*
decl) {
+ EmitDeclaration(decl->proxy(), decl->mode(), decl->fun());
+}
void FullCodeGenerator::VisitDeclarations(
ZoneList<Declaration*>* declarations) {
- int length = declarations->length();
- int global_count = 0;
- for (int i = 0; i < length; i++) {
- Declaration* decl = declarations->at(i);
- EmitDeclaration(decl->proxy(), decl->mode(), decl->fun(),
&global_count);
- }
+ int save_global_count = global_count_;
+ global_count_ = 0;
+
+ AstVisitor::VisitDeclarations(declarations);
// Batch declare global functions and variables.
- if (global_count > 0) {
+ if (global_count_ > 0) {
Handle<FixedArray> array =
- isolate()->factory()->NewFixedArray(2 * global_count, TENURED);
+ isolate()->factory()->NewFixedArray(2 * global_count_, TENURED);
+ int length = declarations->length();
for (int j = 0, i = 0; i < length; i++) {
- Declaration* decl = declarations->at(i);
- Variable* var = decl->proxy()->var();
-
- if (var->IsUnallocated()) {
- array->set(j++, *(var->name()));
- if (decl->fun() == NULL) {
- if (var->binding_needs_init()) {
- // In case this binding needs initialization use the hole.
- array->set_the_hole(j++);
+ VariableDeclaration* decl =
declarations->at(i)->AsVariableDeclaration();
+ if (decl != NULL) {
+ Variable* var = decl->proxy()->var();
+
+ if (var->IsUnallocated()) {
+ array->set(j++, *(var->name()));
+ if (decl->fun() == NULL) {
+ if (var->binding_needs_init()) {
+ // In case this binding needs initialization use the hole.
+ array->set_the_hole(j++);
+ } else {
+ array->set_undefined(j++);
+ }
} else {
- array->set_undefined(j++);
- }
- } else {
- Handle<SharedFunctionInfo> function =
- Compiler::BuildFunctionInfo(decl->fun(), script());
- // Check for stack-overflow exception.
- if (function.is_null()) {
- SetStackOverflow();
- return;
- }
- array->set(j++, *function);
+ Handle<SharedFunctionInfo> function =
+ Compiler::BuildFunctionInfo(decl->fun(), script());
+ // Check for stack-overflow exception.
+ if (function.is_null()) {
+ SetStackOverflow();
+ return;
+ }
+ array->set(j++, *function);
+ }
}
}
}
@@ -568,6 +575,8 @@
// declaration the global functions and variables.
DeclareGlobals(array);
}
+
+ global_count_ = save_global_count;
}
=======================================
--- /branches/bleeding_edge/src/full-codegen.h Fri Jan 27 05:03:19 2012
+++ /branches/bleeding_edge/src/full-codegen.h Thu Feb 9 05:39:26 2012
@@ -83,6 +83,7 @@
scope_(NULL),
nesting_stack_(NULL),
loop_depth_(0),
+ global_count_(0),
context_(NULL),
bailout_entries_(0),
stack_checks_(2), // There's always at least one.
@@ -416,10 +417,10 @@
// Platform-specific code for a variable, constant, or function
// declaration. Functions have an initial value.
+ // Increments global_count_ for unallocated variables.
void EmitDeclaration(VariableProxy* proxy,
VariableMode mode,
- FunctionLiteral* function,
- int* global_count);
+ FunctionLiteral* function);
// Platform-specific code for checking the stack limit at the back edge
of
// a loop.
@@ -767,6 +768,7 @@
Label return_label_;
NestedStatement* nesting_stack_;
int loop_depth_;
+ int global_count_;
const ExpressionContext* context_;
ZoneList<BailoutEntry> bailout_entries_;
ZoneList<BailoutEntry> stack_checks_;
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc Thu Feb 9 00:58:19 2012
+++ /branches/bleeding_edge/src/hydrogen.cc Thu Feb 9 05:39:26 2012
@@ -2443,7 +2443,7 @@
// Handle implicit declaration of the function name in named function
// expressions before other declarations.
if (scope->is_function_scope() && scope->function() != NULL) {
- HandleDeclaration(scope->function(), CONST, NULL);
+ HandleVariableDeclaration(scope->function(), CONST, NULL);
}
VisitDeclarations(scope->declarations());
AddSimulate(AstNode::kDeclarationsId);
@@ -6540,14 +6540,14 @@
}
-void HGraphBuilder::VisitDeclaration(Declaration* decl) {
- HandleDeclaration(decl->proxy(), decl->mode(), decl->fun());
+void HGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) {
+ HandleVariableDeclaration(decl->proxy(), decl->mode(), decl->fun());
}
-void HGraphBuilder::HandleDeclaration(VariableProxy* proxy,
- VariableMode mode,
- FunctionLiteral* function) {
+void HGraphBuilder::HandleVariableDeclaration(VariableProxy* proxy,
+ VariableMode mode,
+ FunctionLiteral* function) {
Variable* var = proxy->var();
bool binding_needs_init =
(mode == CONST || mode == CONST_HARMONY || mode == LET);
=======================================
--- /branches/bleeding_edge/src/hydrogen.h Thu Feb 9 00:58:19 2012
+++ /branches/bleeding_edge/src/hydrogen.h Thu Feb 9 05:39:26 2012
@@ -839,9 +839,9 @@
INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_DECLARATION)
#undef INLINE_FUNCTION_GENERATOR_DECLARATION
- void HandleDeclaration(VariableProxy* proxy,
- VariableMode mode,
- FunctionLiteral* function);
+ void HandleVariableDeclaration(VariableProxy* proxy,
+ VariableMode mode,
+ FunctionLiteral* function);
void VisitDelete(UnaryOperation* expr);
void VisitVoid(UnaryOperation* expr);
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Thu Feb 9
02:19:46 2012
+++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Thu Feb 9
05:39:26 2012
@@ -281,11 +281,11 @@
// For named function expressions, declare the function name as a
// constant.
if (scope()->is_function_scope() && scope()->function() != NULL) {
- int ignored = 0;
VariableProxy* proxy = scope()->function();
ASSERT(proxy->var()->mode() == CONST ||
proxy->var()->mode() == CONST_HARMONY);
- EmitDeclaration(proxy, proxy->var()->mode(), NULL, &ignored);
+ ASSERT(proxy->var()->location() != Variable::UNALLOCATED);
+ EmitDeclaration(proxy, proxy->var()->mode(), NULL);
}
VisitDeclarations(scope()->declarations());
}
@@ -701,8 +701,7 @@
void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
VariableMode mode,
- FunctionLiteral* function,
- int* global_count) {
+ FunctionLiteral* function) {
// If it was not possible to allocate the variable at compile time, we
// need to "declare" it at runtime to make sure it actually exists in the
// local context.
@@ -711,7 +710,7 @@
(mode == CONST || mode == CONST_HARMONY || mode == LET);
switch (variable->location()) {
case Variable::UNALLOCATED:
- ++(*global_count);
+ ++global_count_;
break;
case Variable::PARAMETER:
@@ -789,9 +788,6 @@
}
}
}
-
-
-void FullCodeGenerator::VisitDeclaration(Declaration* decl) { }
void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
=======================================
--- /branches/bleeding_edge/src/parser.cc Wed Feb 8 02:53:58 2012
+++ /branches/bleeding_edge/src/parser.cc Thu Feb 9 05:39:26 2012
@@ -1406,7 +1406,7 @@
VariableProxy* proxy = declaration_scope->NewUnresolved(
factory(), name, scanner().location().beg_pos);
declaration_scope->AddDeclaration(
- factory()->NewDeclaration(proxy, mode, fun, top_scope_));
+ factory()->NewVariableDeclaration(proxy, mode, fun, top_scope_));
if ((mode == CONST || mode == CONST_HARMONY) &&
declaration_scope->is_global_scope()) {
@@ -1627,8 +1627,8 @@
// If the variable declaration declares exactly one non-const
-// variable, then *var is set to that variable. In all other cases,
-// *var is untouched; in particular, it is the caller's responsibility
+// variable, then *out is set to that variable. In all other cases,
+// *out is untouched; in particular, it is the caller's responsibility
// to initialize it properly. This mechanism is used for the parsing
// of 'for-in' loops.
Block* Parser::ParseVariableDeclarations(
=======================================
--- /branches/bleeding_edge/src/prettyprinter.cc Wed Feb 8 05:53:24 2012
+++ /branches/bleeding_edge/src/prettyprinter.cc Thu Feb 9 05:39:26 2012
@@ -58,7 +58,7 @@
}
-void PrettyPrinter::VisitDeclaration(Declaration* node) {
+void PrettyPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
Print("var ");
PrintLiteral(node->proxy()->name(), false);
if (node->fun() != NULL) {
@@ -711,7 +711,7 @@
}
-void AstPrinter::VisitDeclaration(Declaration* node) {
+void AstPrinter::VisitVariableDeclaration(VariableDeclaration* node) {
if (node->fun() == NULL) {
// var or const declarations
PrintLiteralWithModeIndented(Variable::Mode2String(node->mode()),
=======================================
--- /branches/bleeding_edge/src/rewriter.cc Wed Feb 8 01:56:33 2012
+++ /branches/bleeding_edge/src/rewriter.cc Thu Feb 9 05:39:26 2012
@@ -209,7 +209,7 @@
// Do nothing:
-void Processor::VisitDeclaration(Declaration* node) {}
+void Processor::VisitVariableDeclaration(VariableDeclaration* node) {}
void Processor::VisitEmptyStatement(EmptyStatement* node) {}
void Processor::VisitReturnStatement(ReturnStatement* node) {}
void Processor::VisitDebuggerStatement(DebuggerStatement* node) {}
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Thu Feb 9 02:19:46
2012
+++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Thu Feb 9 05:39:26
2012
@@ -277,11 +277,11 @@
// For named function expressions, declare the function name as a
// constant.
if (scope()->is_function_scope() && scope()->function() != NULL) {
- int ignored = 0;
VariableProxy* proxy = scope()->function();
ASSERT(proxy->var()->mode() == CONST ||
proxy->var()->mode() == CONST_HARMONY);
- EmitDeclaration(proxy, proxy->var()->mode(), NULL, &ignored);
+ ASSERT(proxy->var()->location() != Variable::UNALLOCATED);
+ EmitDeclaration(proxy, proxy->var()->mode(), NULL);
}
VisitDeclarations(scope()->declarations());
}
@@ -699,8 +699,7 @@
void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy,
VariableMode mode,
- FunctionLiteral* function,
- int* global_count) {
+ FunctionLiteral* function) {
// If it was not possible to allocate the variable at compile time, we
// need to "declare" it at runtime to make sure it actually exists in the
// local context.
@@ -709,7 +708,7 @@
(mode == CONST || mode == CONST_HARMONY || mode == LET);
switch (variable->location()) {
case Variable::UNALLOCATED:
- ++(*global_count);
+ ++global_count_;
break;
case Variable::PARAMETER:
@@ -788,9 +787,6 @@
}
}
}
-
-
-void FullCodeGenerator::VisitDeclaration(Declaration* decl) { }
void FullCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) {
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev