From 876fa09febc19b637d651db830699dfd528fe121 Mon Sep 17 00:00:00 2001 From: "fschneider@chromium.org" Date: Tue, 11 Oct 2011 08:41:19 +0000 Subject: [PATCH] Move declaration of SerializedScopeInfo from variables.h to objects.h This eliminates compile-errors when assigning Handle to Handle in a place where the declaration was not available because variables.h was not included. As a result I had to also move the enum Variable::Mode to v8globals.h and rename it to VariableMode. Review URL: http://codereview.chromium.org/8221004 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@9575 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/arm/full-codegen-arm.cc | 38 ++++++++--------- src/ast.h | 12 +++--- src/contexts.cc | 20 ++++----- src/full-codegen.cc | 2 +- src/full-codegen.h | 2 +- src/hydrogen.cc | 26 ++++++------ src/hydrogen.h | 2 +- src/ia32/full-codegen-ia32.cc | 40 +++++++++--------- src/objects.cc | 2 +- src/objects.h | 62 +++++++++++++++++++++++++++ src/parser.cc | 45 +++++++++----------- src/parser.h | 2 +- src/scopeinfo.cc | 20 ++++----- src/scopeinfo.h | 79 ++++------------------------------- src/scopes.cc | 52 +++++++++++------------ src/scopes.h | 12 +++--- src/v8globals.h | 33 ++++++++++++++- src/variables.cc | 4 +- src/variables.h | 36 ++-------------- src/x64/full-codegen-x64.cc | 39 ++++++++--------- 20 files changed, 255 insertions(+), 273 deletions(-) diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index f9a880f56..8e3c020e2 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -269,7 +269,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { // constant. if (scope()->is_function_scope() && scope()->function() != NULL) { int ignored = 0; - EmitDeclaration(scope()->function(), Variable::CONST, NULL, &ignored); + EmitDeclaration(scope()->function(), CONST, NULL, &ignored); } VisitDeclarations(scope()->declarations()); } @@ -711,7 +711,7 @@ void FullCodeGenerator::PrepareForBailoutBeforeSplit(State state, void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, - Variable::Mode mode, + VariableMode mode, FunctionLiteral* function, int* global_count) { // If it was not possible to allocate the variable at compile time, we @@ -729,7 +729,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, Comment cmnt(masm_, "[ Declaration"); VisitForAccumulatorValue(function); __ str(result_register(), StackOperand(variable)); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { Comment cmnt(masm_, "[ Declaration"); __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); __ str(ip, StackOperand(variable)); @@ -763,7 +763,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); PrepareForBailoutForId(proxy->id(), NO_REGISTERS); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { Comment cmnt(masm_, "[ Declaration"); __ LoadRoot(ip, Heap::kTheHoleValueRootIndex); __ str(ip, ContextOperand(cp, variable->index())); @@ -776,10 +776,8 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, Comment cmnt(masm_, "[ Declaration"); __ mov(r2, Operand(variable->name())); // Declaration nodes are always introduced in one of three modes. - ASSERT(mode == Variable::VAR || - mode == Variable::CONST || - mode == Variable::LET); - PropertyAttributes attr = (mode == Variable::CONST) ? READ_ONLY : NONE; + ASSERT(mode == VAR || mode == CONST || mode == LET); + PropertyAttributes attr = (mode == CONST) ? READ_ONLY : NONE; __ mov(r1, Operand(Smi::FromInt(attr))); // Push initial value, if any. // Note: For variables we must not push an initial value (such as @@ -789,7 +787,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, __ Push(cp, r2, r1); // Push initial value for function declaration. VisitForStackValue(function); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { __ LoadRoot(r0, Heap::kTheHoleValueRootIndex); __ Push(cp, r2, r1, r0); } else { @@ -1219,18 +1217,18 @@ void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, // introducing variables. In those cases, we do not want to // perform a runtime call for all variables in the scope // containing the eval. - if (var->mode() == Variable::DYNAMIC_GLOBAL) { + if (var->mode() == DYNAMIC_GLOBAL) { EmitLoadGlobalCheckExtensions(var, typeof_state, slow); __ jmp(done); - } else if (var->mode() == Variable::DYNAMIC_LOCAL) { + } else if (var->mode() == DYNAMIC_LOCAL) { Variable* local = var->local_if_not_shadowed(); __ ldr(r0, ContextSlotOperandCheckExtensions(local, slow)); - if (local->mode() == Variable::CONST || - local->mode() == Variable::LET) { + if (local->mode() == CONST || + local->mode() == LET) { __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); - if (local->mode() == Variable::CONST) { + if (local->mode() == CONST) { __ LoadRoot(r0, Heap::kUndefinedValueRootIndex, eq); - } else { // Variable::LET + } else { // LET __ b(ne, done); __ mov(r0, Operand(var->name())); __ push(r0); @@ -1268,13 +1266,13 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { Comment cmnt(masm_, var->IsContextSlot() ? "Context variable" : "Stack variable"); - if (var->mode() != Variable::LET && var->mode() != Variable::CONST) { + if (var->mode() != LET && var->mode() != CONST) { context()->Plug(var); } else { // Let and const need a read barrier. GetVar(r0, var); __ CompareRoot(r0, Heap::kTheHoleValueRootIndex); - if (var->mode() == Variable::LET) { + if (var->mode() == LET) { Label done; __ b(ne, &done); __ mov(r0, Operand(var->name())); @@ -1875,7 +1873,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); } - } else if (var->mode() == Variable::LET && op != Token::INIT_LET) { + } else if (var->mode() == LET && op != Token::INIT_LET) { // Non-initializing assignment to let variable needs a write barrier. if (var->IsLookupSlot()) { __ push(r0); // Value. @@ -1905,7 +1903,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, } } - } else if (var->mode() != Variable::CONST) { + } else if (var->mode() != CONST) { // Assignment to var or initializing assignment to let. if (var->IsStackAllocated() || var->IsContextSlot()) { MemOperand location = VarOperand(var, r1); @@ -2190,7 +2188,7 @@ void FullCodeGenerator::VisitCall(Call* expr) { // context lookup in the runtime system. Label done; Variable* var = proxy->var(); - if (!var->IsUnallocated() && var->mode() == Variable::DYNAMIC_GLOBAL) { + if (!var->IsUnallocated() && var->mode() == DYNAMIC_GLOBAL) { Label slow; EmitLoadGlobalCheckExtensions(var, NOT_INSIDE_TYPEOF, &slow); // Push the function and resolve eval. diff --git a/src/ast.h b/src/ast.h index 00cfd7fe6..0efc4835c 100644 --- a/src/ast.h +++ b/src/ast.h @@ -398,31 +398,29 @@ class Block: public BreakableStatement { class Declaration: public AstNode { public: Declaration(VariableProxy* proxy, - Variable::Mode mode, + VariableMode mode, FunctionLiteral* fun, Scope* scope) : proxy_(proxy), mode_(mode), fun_(fun), scope_(scope) { - ASSERT(mode == Variable::VAR || - mode == Variable::CONST || - mode == Variable::LET); + ASSERT(mode == VAR || mode == CONST || mode == LET); // At the moment there are no "const functions"'s in JavaScript... - ASSERT(fun == NULL || mode == Variable::VAR || mode == Variable::LET); + ASSERT(fun == NULL || mode == VAR || mode == LET); } DECLARE_NODE_TYPE(Declaration) VariableProxy* proxy() const { return proxy_; } - Variable::Mode mode() const { return mode_; } + VariableMode mode() const { return mode_; } FunctionLiteral* fun() const { return fun_; } // may be NULL virtual bool IsInlineable() const; Scope* scope() const { return scope_; } private: VariableProxy* proxy_; - Variable::Mode mode_; + VariableMode mode_; FunctionLiteral* fun_; // Nested scope from which the declaration originated. diff --git a/src/contexts.cc b/src/contexts.cc index 007d30de3..0cda43049 100644 --- a/src/contexts.cc +++ b/src/contexts.cc @@ -145,7 +145,7 @@ Handle Context::Lookup(Handle name, scope_info = Handle( SerializedScopeInfo::cast(context->extension()), isolate); } - Variable::Mode mode; + VariableMode mode; int slot_index = scope_info->ContextSlotIndex(*name, &mode); ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); if (slot_index >= 0) { @@ -161,23 +161,23 @@ Handle Context::Lookup(Handle name, // declared variables that were introduced through declaration nodes) // must not appear here. switch (mode) { - case Variable::INTERNAL: // Fall through. - case Variable::VAR: + case INTERNAL: // Fall through. + case VAR: *attributes = NONE; *binding_flags = MUTABLE_IS_INITIALIZED; break; - case Variable::LET: + case LET: *attributes = NONE; *binding_flags = MUTABLE_CHECK_INITIALIZED; break; - case Variable::CONST: + case CONST: *attributes = READ_ONLY; *binding_flags = IMMUTABLE_CHECK_INITIALIZED; break; - case Variable::DYNAMIC: - case Variable::DYNAMIC_GLOBAL: - case Variable::DYNAMIC_LOCAL: - case Variable::TEMPORARY: + case DYNAMIC: + case DYNAMIC_GLOBAL: + case DYNAMIC_LOCAL: + case TEMPORARY: UNREACHABLE(); break; } @@ -245,7 +245,7 @@ bool Context::GlobalIfNotShadowedByEval(Handle name) { // Check non-parameter locals. Handle scope_info( context->closure()->shared()->scope_info()); - Variable::Mode mode; + VariableMode mode; int index = scope_info->ContextSlotIndex(*name, &mode); ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); if (index >= 0) return false; diff --git a/src/full-codegen.cc b/src/full-codegen.cc index b02c1df54..083675d13 100644 --- a/src/full-codegen.cc +++ b/src/full-codegen.cc @@ -520,7 +520,7 @@ void FullCodeGenerator::VisitDeclarations( if (var->IsUnallocated()) { array->set(j++, *(var->name())); if (decl->fun() == NULL) { - if (var->mode() == Variable::CONST) { + if (var->mode() == CONST) { // In case this is const property use the hole. array->set_the_hole(j++); } else { diff --git a/src/full-codegen.h b/src/full-codegen.h index 6958daeb8..081192a54 100644 --- a/src/full-codegen.h +++ b/src/full-codegen.h @@ -423,7 +423,7 @@ class FullCodeGenerator: public AstVisitor { // Platform-specific code for a variable, constant, or function // declaration. Functions have an initial value. void EmitDeclaration(VariableProxy* proxy, - Variable::Mode mode, + VariableMode mode, FunctionLiteral* function, int* global_count); diff --git a/src/hydrogen.cc b/src/hydrogen.cc index cd97df595..2d471cc29 100644 --- a/src/hydrogen.cc +++ b/src/hydrogen.cc @@ -2311,7 +2311,7 @@ HGraph* HGraphBuilder::CreateGraph() { // 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(), Variable::CONST, NULL); + HandleDeclaration(scope->function(), CONST, NULL); } VisitDeclarations(scope->declarations()); AddSimulate(AstNode::kDeclarationsId); @@ -3141,7 +3141,7 @@ void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) { ASSERT(current_block() != NULL); ASSERT(current_block()->HasPredecessor()); Variable* variable = expr->var(); - if (variable->mode() == Variable::LET) { + if (variable->mode() == LET) { return Bailout("reference to let variable"); } switch (variable->location()) { @@ -3188,7 +3188,7 @@ void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) { case Variable::PARAMETER: case Variable::LOCAL: { HValue* value = environment()->Lookup(variable); - if (variable->mode() == Variable::CONST && + if (variable->mode() == CONST && value == graph()->GetConstantHole()) { return Bailout("reference to uninitialized const variable"); } @@ -3196,7 +3196,7 @@ void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) { } case Variable::CONTEXT: { - if (variable->mode() == Variable::CONST) { + if (variable->mode() == CONST) { return Bailout("reference to const context slot"); } HValue* context = BuildContextChainWalk(variable); @@ -3663,7 +3663,7 @@ void HGraphBuilder::HandleCompoundAssignment(Assignment* expr) { if (proxy != NULL) { Variable* var = proxy->var(); - if (var->mode() == Variable::CONST || var->mode() == Variable::LET) { + if (var->mode() == CONST || var->mode() == LET) { return Bailout("unsupported let or const compound assignment"); } @@ -3808,7 +3808,7 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { HandlePropertyAssignment(expr); } else if (proxy != NULL) { Variable* var = proxy->var(); - if (var->mode() == Variable::CONST) { + if (var->mode() == CONST) { if (expr->op() != Token::INIT_CONST) { return Bailout("non-initializer assignment to const"); } @@ -3819,7 +3819,7 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { // variables (e.g. initialization inside a loop). HValue* old_value = environment()->Lookup(var); AddInstruction(new HUseConst(old_value)); - } else if (var->mode() == Variable::LET) { + } else if (var->mode() == LET) { return Bailout("unsupported assignment to let"); } @@ -3847,7 +3847,7 @@ void HGraphBuilder::VisitAssignment(Assignment* expr) { } case Variable::CONTEXT: { - ASSERT(var->mode() != Variable::CONST); + ASSERT(var->mode() != CONST); // Bail out if we try to mutate a parameter value in a function using // the arguments object. We do not (yet) correctly handle the // arguments property of the function. @@ -5403,7 +5403,7 @@ void HGraphBuilder::VisitCountOperation(CountOperation* expr) { if (proxy != NULL) { Variable* var = proxy->var(); - if (var->mode() == Variable::CONST) { + if (var->mode() == CONST) { return Bailout("unsupported count operation with const"); } // Argument of the count operation is a variable, not a property. @@ -5977,9 +5977,9 @@ void HGraphBuilder::VisitDeclaration(Declaration* decl) { void HGraphBuilder::HandleDeclaration(VariableProxy* proxy, - Variable::Mode mode, + VariableMode mode, FunctionLiteral* function) { - if (mode == Variable::LET) return Bailout("unsupported let declaration"); + if (mode == LET) return Bailout("unsupported let declaration"); Variable* var = proxy->var(); switch (var->location()) { case Variable::UNALLOCATED: @@ -5987,9 +5987,9 @@ void HGraphBuilder::HandleDeclaration(VariableProxy* proxy, case Variable::PARAMETER: case Variable::LOCAL: case Variable::CONTEXT: - if (mode == Variable::CONST || function != NULL) { + if (mode == CONST || function != NULL) { HValue* value = NULL; - if (mode == Variable::CONST) { + if (mode == CONST) { value = graph()->GetConstantHole(); } else { VisitForValue(function); diff --git a/src/hydrogen.h b/src/hydrogen.h index 8b507c26b..b66042c2c 100644 --- a/src/hydrogen.h +++ b/src/hydrogen.h @@ -782,7 +782,7 @@ class HGraphBuilder: public AstVisitor { #undef INLINE_FUNCTION_GENERATOR_DECLARATION void HandleDeclaration(VariableProxy* proxy, - Variable::Mode mode, + VariableMode mode, FunctionLiteral* function); void VisitDelete(UnaryOperation* expr); diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc index 594aae18b..ed6886fd6 100644 --- a/src/ia32/full-codegen-ia32.cc +++ b/src/ia32/full-codegen-ia32.cc @@ -266,7 +266,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { // constant. if (scope()->is_function_scope() && scope()->function() != NULL) { int ignored = 0; - EmitDeclaration(scope()->function(), Variable::CONST, NULL, &ignored); + EmitDeclaration(scope()->function(), CONST, NULL, &ignored); } VisitDeclarations(scope()->declarations()); } @@ -704,7 +704,7 @@ void FullCodeGenerator::PrepareForBailoutBeforeSplit(State state, void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, - Variable::Mode mode, + VariableMode mode, FunctionLiteral* function, int* global_count) { // If it was not possible to allocate the variable at compile time, we @@ -722,7 +722,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, Comment cmnt(masm_, "[ Declaration"); VisitForAccumulatorValue(function); __ mov(StackOperand(variable), result_register()); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { Comment cmnt(masm_, "[ Declaration"); __ mov(StackOperand(variable), Immediate(isolate()->factory()->the_hole_value())); @@ -754,7 +754,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); PrepareForBailoutForId(proxy->id(), NO_REGISTERS); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { Comment cmnt(masm_, "[ Declaration"); __ mov(ContextOperand(esi, variable->index()), Immediate(isolate()->factory()->the_hole_value())); @@ -768,10 +768,8 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, __ push(esi); __ push(Immediate(variable->name())); // Declaration nodes are always introduced in one of three modes. - ASSERT(mode == Variable::VAR || - mode == Variable::CONST || - mode == Variable::LET); - PropertyAttributes attr = (mode == Variable::CONST) ? READ_ONLY : NONE; + ASSERT(mode == VAR || mode == CONST || mode == LET); + PropertyAttributes attr = (mode == CONST) ? READ_ONLY : NONE; __ push(Immediate(Smi::FromInt(attr))); // Push initial value, if any. // Note: For variables we must not push an initial value (such as @@ -780,7 +778,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, increment_stack_height(3); if (function != NULL) { VisitForStackValue(function); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { __ push(Immediate(isolate()->factory()->the_hole_value())); increment_stack_height(); } else { @@ -1201,19 +1199,19 @@ void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, // introducing variables. In those cases, we do not want to // perform a runtime call for all variables in the scope // containing the eval. - if (var->mode() == Variable::DYNAMIC_GLOBAL) { + if (var->mode() == DYNAMIC_GLOBAL) { EmitLoadGlobalCheckExtensions(var, typeof_state, slow); __ jmp(done); - } else if (var->mode() == Variable::DYNAMIC_LOCAL) { + } else if (var->mode() == DYNAMIC_LOCAL) { Variable* local = var->local_if_not_shadowed(); __ mov(eax, ContextSlotOperandCheckExtensions(local, slow)); - if (local->mode() == Variable::CONST || - local->mode() == Variable::LET) { + if (local->mode() == CONST || + local->mode() == LET) { __ cmp(eax, isolate()->factory()->the_hole_value()); __ j(not_equal, done); - if (local->mode() == Variable::CONST) { + if (local->mode() == CONST) { __ mov(eax, isolate()->factory()->undefined_value()); - } else { // Variable::LET + } else { // LET __ push(Immediate(var->name())); __ CallRuntime(Runtime::kThrowReferenceError, 1); } @@ -1249,7 +1247,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { Comment cmnt(masm_, var->IsContextSlot() ? "Context variable" : "Stack variable"); - if (var->mode() != Variable::LET && var->mode() != Variable::CONST) { + if (var->mode() != LET && var->mode() != CONST) { context()->Plug(var); } else { // Let and const need a read barrier. @@ -1257,10 +1255,10 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { GetVar(eax, var); __ cmp(eax, isolate()->factory()->the_hole_value()); __ j(not_equal, &done, Label::kNear); - if (var->mode() == Variable::LET) { + if (var->mode() == LET) { __ push(Immediate(var->name())); __ CallRuntime(Runtime::kThrowReferenceError, 1); - } else { // Variable::CONST + } else { // CONST __ mov(eax, isolate()->factory()->undefined_value()); } __ bind(&done); @@ -1866,7 +1864,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); } - } else if (var->mode() == Variable::LET && op != Token::INIT_LET) { + } else if (var->mode() == LET && op != Token::INIT_LET) { // Non-initializing assignment to let variable needs a write barrier. if (var->IsLookupSlot()) { __ push(eax); // Value. @@ -1892,7 +1890,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, } } - } else if (var->mode() != Variable::CONST) { + } else if (var->mode() != CONST) { // Assignment to var or initializing assignment to let. if (var->IsStackAllocated() || var->IsContextSlot()) { MemOperand location = VarOperand(var, ecx); @@ -2191,7 +2189,7 @@ void FullCodeGenerator::VisitCall(Call* expr) { // context lookup in the runtime system. Label done; Variable* var = proxy->var(); - if (!var->IsUnallocated() && var->mode() == Variable::DYNAMIC_GLOBAL) { + if (!var->IsUnallocated() && var->mode() == DYNAMIC_GLOBAL) { Label slow; EmitLoadGlobalCheckExtensions(var, NOT_INSIDE_TYPEOF, &slow); // Push the function and resolve eval. diff --git a/src/objects.cc b/src/objects.cc index a2a327664..604460a6d 100644 --- a/src/objects.cc +++ b/src/objects.cc @@ -12182,7 +12182,7 @@ int BreakPointInfo::GetBreakPointCount() { // Multiple break points. return FixedArray::cast(break_point_objects())->length(); } -#endif +#endif // ENABLE_DEBUGGER_SUPPORT } } // namespace v8::internal diff --git a/src/objects.h b/src/objects.h index d7e0b1d54..79ceabc76 100644 --- a/src/objects.h +++ b/src/objects.h @@ -3011,6 +3011,68 @@ class JSFunctionResultCache: public FixedArray { }; +// This object provides quick access to scope info details for runtime +// routines w/o the need to explicitly create a ScopeInfo object. +class SerializedScopeInfo : public FixedArray { + public : + static SerializedScopeInfo* cast(Object* object) { + ASSERT(object->IsSerializedScopeInfo()); + return reinterpret_cast(object); + } + + // Does this scope call eval? + bool CallsEval(); + + // Is this scope a strict mode scope? + bool IsStrictMode(); + + // Return the number of stack slots for code. + int NumberOfStackSlots(); + + // Return the number of context slots for code. + int NumberOfContextSlots(); + + // Return if this has context slots besides MIN_CONTEXT_SLOTS; + bool HasHeapAllocatedLocals(); + + // Lookup support for serialized scope info. Returns the + // the stack slot index for a given slot name if the slot is + // present; otherwise returns a value < 0. The name must be a symbol + // (canonicalized). + int StackSlotIndex(String* name); + + // Lookup support for serialized scope info. Returns the + // context slot index for a given slot name if the slot is present; otherwise + // returns a value < 0. The name must be a symbol (canonicalized). + // If the slot is present and mode != NULL, sets *mode to the corresponding + // mode for that variable. + int ContextSlotIndex(String* name, VariableMode* mode); + + // Lookup support for serialized scope info. Returns the + // parameter index for a given parameter name if the parameter is present; + // otherwise returns a value < 0. The name must be a symbol (canonicalized). + int ParameterIndex(String* name); + + // Lookup support for serialized scope info. Returns the + // function context slot index if the function name is present (named + // function expressions, only), otherwise returns a value < 0. The name + // must be a symbol (canonicalized). + int FunctionContextSlotIndex(String* name); + + static Handle Create(Scope* scope); + + // Serializes empty scope info. + static SerializedScopeInfo* Empty(); + + private: + Object** ContextEntriesAddr(); + + Object** ParameterEntriesAddr(); + + Object** StackSlotEntriesAddr(); +}; + + // The cache for maps used by normalized (dictionary mode) objects. // Such maps do not have property descriptors, so a typical program // needs very limited number of distinct normalized maps. diff --git a/src/parser.cc b/src/parser.cc index 17ee5fcaa..9a9081e1d 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -1345,7 +1345,7 @@ Statement* Parser::ParseStatement(ZoneStringList* labels, bool* ok) { VariableProxy* Parser::Declare(Handle name, - Variable::Mode mode, + VariableMode mode, FunctionLiteral* fun, bool resolve, bool* ok) { @@ -1363,7 +1363,7 @@ VariableProxy* Parser::Declare(Handle name, // Similarly, strict mode eval scope does not leak variable declarations to // the caller's scope so we declare all locals, too. - Scope* declaration_scope = mode == Variable::LET ? top_scope_ + Scope* declaration_scope = mode == LET ? top_scope_ : top_scope_->DeclarationScope(); if (declaration_scope->is_function_scope() || declaration_scope->is_strict_mode_eval_scope() || @@ -1385,11 +1385,11 @@ VariableProxy* Parser::Declare(Handle name, // // because the var declaration is hoisted to the function scope where 'x' // is already bound. - if ((mode != Variable::VAR) || (var->mode() != Variable::VAR)) { + if ((mode != VAR) || (var->mode() != VAR)) { // We only have vars, consts and lets in declarations. - ASSERT(var->mode() == Variable::VAR || - var->mode() == Variable::CONST || - var->mode() == Variable::LET); + ASSERT(var->mode() == VAR || + var->mode() == CONST || + var->mode() == LET); if (harmony_block_scoping_) { // In harmony mode we treat re-declarations as early errors. See // ES5 16 for a definition of early errors. @@ -1400,8 +1400,8 @@ VariableProxy* Parser::Declare(Handle name, *ok = false; return NULL; } - const char* type = (var->mode() == Variable::VAR) ? "var" : - (var->mode() == Variable::CONST) ? "const" : "let"; + const char* type = (var->mode() == VAR) ? "var" : + (var->mode() == CONST) ? "const" : "let"; Handle type_string = isolate()->factory()->NewStringFromUtf8(CStrVector(type), TENURED); Expression* expression = @@ -1434,14 +1434,10 @@ VariableProxy* Parser::Declare(Handle name, new(zone()) Declaration(proxy, mode, fun, top_scope_)); // For global const variables we bind the proxy to a variable. - if (mode == Variable::CONST && declaration_scope->is_global_scope()) { + if (mode == CONST && declaration_scope->is_global_scope()) { ASSERT(resolve); // should be set by all callers Variable::Kind kind = Variable::NORMAL; - var = new(zone()) Variable(declaration_scope, - name, - Variable::CONST, - true, - kind); + var = new(zone()) Variable(declaration_scope, name, CONST, true, kind); } // If requested and we have a local variable, bind the proxy to the variable @@ -1524,7 +1520,7 @@ Statement* Parser::ParseNativeDeclaration(bool* ok) { // other functions are setup when entering the surrounding scope. SharedFunctionInfoLiteral* lit = new(zone()) SharedFunctionInfoLiteral(isolate(), shared); - VariableProxy* var = Declare(name, Variable::VAR, NULL, true, CHECK_OK); + VariableProxy* var = Declare(name, VAR, NULL, true, CHECK_OK); return new(zone()) ExpressionStatement(new(zone()) Assignment( isolate(), Token::INIT_VAR, var, lit, RelocInfo::kNoPosition)); } @@ -1546,7 +1542,7 @@ Statement* Parser::ParseFunctionDeclaration(bool* ok) { // Even if we're not at the top-level of the global or a function // scope, we treat is as such and introduce the function with it's // initial value upon entering the corresponding scope. - Variable::Mode mode = harmony_block_scoping_ ? Variable::LET : Variable::VAR; + VariableMode mode = harmony_block_scoping_ ? LET : VAR; Declare(name, mode, fun, true, CHECK_OK); return EmptyStatement(); } @@ -1651,7 +1647,7 @@ Block* Parser::ParseVariableDeclarations(VariableDeclarationContext var_context, // VariableDeclarations :: // ('var' | 'const') (Identifier ('=' AssignmentExpression)?)+[','] - Variable::Mode mode = Variable::VAR; + VariableMode mode = VAR; // True if the binding needs initialization. 'let' and 'const' declared // bindings are created uninitialized by their declaration nodes and // need initialization. 'var' declared bindings are always initialized @@ -1668,7 +1664,7 @@ Block* Parser::ParseVariableDeclarations(VariableDeclarationContext var_context, *ok = false; return NULL; } - mode = Variable::CONST; + mode = CONST; is_const = true; needs_init = true; init_op = Token::INIT_CONST; @@ -1681,14 +1677,14 @@ Block* Parser::ParseVariableDeclarations(VariableDeclarationContext var_context, *ok = false; return NULL; } - mode = Variable::LET; + mode = LET; needs_init = true; init_op = Token::INIT_LET; } else { UNREACHABLE(); // by current callers } - Scope* declaration_scope = mode == Variable::LET + Scope* declaration_scope = (mode == LET) ? top_scope_ : top_scope_->DeclarationScope(); // The scope of a var/const declared variable anywhere inside a function // is the entire function (ECMA-262, 3rd, 10.1.3, and 12.2). Thus we can @@ -1879,7 +1875,7 @@ Block* Parser::ParseVariableDeclarations(VariableDeclarationContext var_context, // as the declaration. Thus dynamic lookups are unnecessary even if the // block scope is inside a with. if (value != NULL) { - bool in_with = mode == Variable::VAR ? inside_with() : false; + bool in_with = (mode == VAR) ? inside_with() : false; VariableProxy* proxy = initialization_scope->NewUnresolved(name, in_with); Assignment* assignment = @@ -2253,8 +2249,7 @@ TryStatement* Parser::ParseTryStatement(bool* ok) { if (top_scope_->is_strict_mode()) { catch_scope->EnableStrictMode(); } - Variable::Mode mode = harmony_block_scoping_ - ? Variable::LET : Variable::VAR; + VariableMode mode = harmony_block_scoping_ ? LET : VAR; catch_variable = catch_scope->DeclareLocal(name, mode); Scope* saved_scope = top_scope_; @@ -3763,9 +3758,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle function_name, } top_scope_->DeclareParameter(param_name, - harmony_block_scoping_ - ? Variable::LET - : Variable::VAR); + harmony_block_scoping_ ? LET : VAR); num_parameters++; if (num_parameters > kMaxNumFunctionParameters) { ReportMessageAt(scanner().location(), "too_many_parameters", diff --git a/src/parser.h b/src/parser.h index d834ed10d..2c41c8a52 100644 --- a/src/parser.h +++ b/src/parser.h @@ -651,7 +651,7 @@ class Parser { void CheckConflictingVarDeclarations(Scope* scope, bool* ok); // Parser support - VariableProxy* Declare(Handle name, Variable::Mode mode, + VariableProxy* Declare(Handle name, VariableMode mode, FunctionLiteral* fun, bool resolve, bool* ok); diff --git a/src/scopeinfo.cc b/src/scopeinfo.cc index ad31ca47c..1aa51603d 100644 --- a/src/scopeinfo.cc +++ b/src/scopeinfo.cc @@ -138,7 +138,7 @@ ScopeInfo::ScopeInfo(Scope* scope) ASSERT(proxy->var()->index() - Context::MIN_CONTEXT_SLOTS == context_modes_.length()); context_slots_.Add(FACTORY->empty_symbol()); - context_modes_.Add(Variable::INTERNAL); + context_modes_.Add(INTERNAL); } } } @@ -216,7 +216,7 @@ static Object** ReadList(Object** p, List, Allocator >* list) { template static Object** ReadList(Object** p, List, Allocator>* list, - List* modes) { + List* modes) { ASSERT(list->is_empty()); int n; p = ReadInt(p, &n); @@ -226,7 +226,7 @@ static Object** ReadList(Object** p, p = ReadSymbol(p, &s); p = ReadInt(p, &m); list->Add(s); - modes->Add(static_cast(m)); + modes->Add(static_cast(m)); } return p; } @@ -285,7 +285,7 @@ static Object** WriteList(Object** p, List, Allocator >* list) { template static Object** WriteList(Object** p, List, Allocator>* list, - List* modes) { + List* modes) { const int n = list->length(); p = WriteInt(p, n); for (int i = 0; i < n; i++) { @@ -456,7 +456,7 @@ int SerializedScopeInfo::StackSlotIndex(String* name) { return -1; } -int SerializedScopeInfo::ContextSlotIndex(String* name, Variable::Mode* mode) { +int SerializedScopeInfo::ContextSlotIndex(String* name, VariableMode* mode) { ASSERT(name->IsSymbol()); Isolate* isolate = GetIsolate(); int result = isolate->context_slot_cache()->Lookup(this, name, mode); @@ -473,7 +473,7 @@ int SerializedScopeInfo::ContextSlotIndex(String* name, Variable::Mode* mode) { ASSERT(((p - p0) & 1) == 0); int v; ReadInt(p + 1, &v); - Variable::Mode mode_value = static_cast(v); + VariableMode mode_value = static_cast(v); if (mode != NULL) *mode = mode_value; result = static_cast((p - p0) >> 1) + Context::MIN_CONTEXT_SLOTS; isolate->context_slot_cache()->Update(this, name, mode_value, result); @@ -482,7 +482,7 @@ int SerializedScopeInfo::ContextSlotIndex(String* name, Variable::Mode* mode) { p += 2; } } - isolate->context_slot_cache()->Update(this, name, Variable::INTERNAL, -1); + isolate->context_slot_cache()->Update(this, name, INTERNAL, -1); return -1; } @@ -540,7 +540,7 @@ int ContextSlotCache::Hash(Object* data, String* name) { int ContextSlotCache::Lookup(Object* data, String* name, - Variable::Mode* mode) { + VariableMode* mode) { int index = Hash(data, name); Key& key = keys_[index]; if ((key.data == data) && key.name->Equals(name)) { @@ -554,7 +554,7 @@ int ContextSlotCache::Lookup(Object* data, void ContextSlotCache::Update(Object* data, String* name, - Variable::Mode mode, + VariableMode mode, int slot_index) { String* symbol; ASSERT(slot_index > kNotFound); @@ -581,7 +581,7 @@ void ContextSlotCache::Clear() { void ContextSlotCache::ValidateEntry(Object* data, String* name, - Variable::Mode mode, + VariableMode mode, int slot_index) { String* symbol; if (HEAP->LookupSymbolIfExists(name, &symbol)) { diff --git a/src/scopeinfo.h b/src/scopeinfo.h index 40c5c8a68..03f321be7 100644 --- a/src/scopeinfo.h +++ b/src/scopeinfo.h @@ -97,70 +97,7 @@ class ScopeInfo BASE_EMBEDDED { List, Allocator > parameters_; List, Allocator > stack_slots_; List, Allocator > context_slots_; - List context_modes_; -}; - - -// This object provides quick access to scope info details for runtime -// routines w/o the need to explicitly create a ScopeInfo object. -class SerializedScopeInfo : public FixedArray { - public : - - static SerializedScopeInfo* cast(Object* object) { - ASSERT(object->IsSerializedScopeInfo()); - return reinterpret_cast(object); - } - - // Does this scope call eval? - bool CallsEval(); - - // Is this scope a strict mode scope? - bool IsStrictMode(); - - // Return the number of stack slots for code. - int NumberOfStackSlots(); - - // Return the number of context slots for code. - int NumberOfContextSlots(); - - // Return if this has context slots besides MIN_CONTEXT_SLOTS; - bool HasHeapAllocatedLocals(); - - // Lookup support for serialized scope info. Returns the - // the stack slot index for a given slot name if the slot is - // present; otherwise returns a value < 0. The name must be a symbol - // (canonicalized). - int StackSlotIndex(String* name); - - // Lookup support for serialized scope info. Returns the - // context slot index for a given slot name if the slot is present; otherwise - // returns a value < 0. The name must be a symbol (canonicalized). - // If the slot is present and mode != NULL, sets *mode to the corresponding - // mode for that variable. - int ContextSlotIndex(String* name, Variable::Mode* mode); - - // Lookup support for serialized scope info. Returns the - // parameter index for a given parameter name if the parameter is present; - // otherwise returns a value < 0. The name must be a symbol (canonicalized). - int ParameterIndex(String* name); - - // Lookup support for serialized scope info. Returns the - // function context slot index if the function name is present (named - // function expressions, only), otherwise returns a value < 0. The name - // must be a symbol (canonicalized). - int FunctionContextSlotIndex(String* name); - - static Handle Create(Scope* scope); - - // Serializes empty scope info. - static SerializedScopeInfo* Empty(); - - private: - inline Object** ContextEntriesAddr(); - - inline Object** ParameterEntriesAddr(); - - inline Object** StackSlotEntriesAddr(); + List context_modes_; }; @@ -174,12 +111,12 @@ class ContextSlotCache { // If absent, kNotFound is returned. int Lookup(Object* data, String* name, - Variable::Mode* mode); + VariableMode* mode); // Update an element in the cache. void Update(Object* data, String* name, - Variable::Mode mode, + VariableMode mode, int slot_index); // Clear the cache. @@ -201,7 +138,7 @@ class ContextSlotCache { #ifdef DEBUG void ValidateEntry(Object* data, String* name, - Variable::Mode mode, + VariableMode mode, int slot_index); #endif @@ -212,7 +149,7 @@ class ContextSlotCache { }; struct Value { - Value(Variable::Mode mode, int index) { + Value(VariableMode mode, int index) { ASSERT(ModeField::is_valid(mode)); ASSERT(IndexField::is_valid(index)); value_ = ModeField::encode(mode) | IndexField::encode(index); @@ -224,14 +161,14 @@ class ContextSlotCache { uint32_t raw() { return value_; } - Variable::Mode mode() { return ModeField::decode(value_); } + VariableMode mode() { return ModeField::decode(value_); } int index() { return IndexField::decode(value_); } // Bit fields in value_ (type, shift, size). Must be public so the // constants can be embedded in generated code. - class ModeField: public BitField {}; - class IndexField: public BitField {}; + class ModeField: public BitField {}; + class IndexField: public BitField {}; private: uint32_t value_; }; diff --git a/src/scopes.cc b/src/scopes.cc index d5a7a9f9c..e67b7f826 100644 --- a/src/scopes.cc +++ b/src/scopes.cc @@ -85,7 +85,7 @@ VariableMap::~VariableMap() {} Variable* VariableMap::Declare(Scope* scope, Handle name, - Variable::Mode mode, + VariableMode mode, bool is_valid_lhs, Variable::Kind kind) { HashMap::Entry* p = HashMap::Lookup(name.location(), name->Hash(), true); @@ -179,7 +179,7 @@ Scope::Scope(Scope* inner_scope, Handle catch_variable_name) ++num_var_or_const_; Variable* variable = variables_.Declare(this, catch_variable_name, - Variable::VAR, + VAR, true, // Valid left-hand side. Variable::NORMAL); AllocateHeapSlot(variable); @@ -310,7 +310,7 @@ void Scope::Initialize(bool inside_with) { Variable* var = variables_.Declare(this, isolate_->factory()->this_symbol(), - Variable::VAR, + VAR, false, Variable::THIS); var->AllocateTo(Variable::PARAMETER, -1); @@ -323,7 +323,7 @@ void Scope::Initialize(bool inside_with) { // allocated during variable allocation. variables_.Declare(this, isolate_->factory()->arguments_symbol(), - Variable::VAR, + VAR, true, Variable::ARGUMENTS); } @@ -373,11 +373,11 @@ Variable* Scope::LocalLookup(Handle name) { ASSERT(scope_info_->StackSlotIndex(*name) < 0); // Check context slot lookup. - Variable::Mode mode; + VariableMode mode; int index = scope_info_->ContextSlotIndex(*name, &mode); if (index < 0) { // Check parameters. - mode = Variable::VAR; + mode = VAR; index = scope_info_->ParameterIndex(*name); if (index < 0) { // Check the function name. @@ -407,13 +407,13 @@ Variable* Scope::Lookup(Handle name) { Variable* Scope::DeclareFunctionVar(Handle name) { ASSERT(is_function_scope() && function_ == NULL); Variable* function_var = - new Variable(this, name, Variable::CONST, true, Variable::NORMAL); + new Variable(this, name, CONST, true, Variable::NORMAL); function_ = new(isolate_->zone()) VariableProxy(isolate_, function_var); return function_var; } -void Scope::DeclareParameter(Handle name, Variable::Mode mode) { +void Scope::DeclareParameter(Handle name, VariableMode mode) { ASSERT(!already_resolved()); ASSERT(is_function_scope()); Variable* var = @@ -422,14 +422,12 @@ void Scope::DeclareParameter(Handle name, Variable::Mode mode) { } -Variable* Scope::DeclareLocal(Handle name, Variable::Mode mode) { +Variable* Scope::DeclareLocal(Handle name, VariableMode mode) { ASSERT(!already_resolved()); // This function handles VAR and CONST modes. DYNAMIC variables are // introduces during variable allocation, INTERNAL variables are allocated // explicitly, and TEMPORARY variables are allocated via NewTemporary(). - ASSERT(mode == Variable::VAR || - mode == Variable::CONST || - mode == Variable::LET); + ASSERT(mode == VAR || mode == CONST || mode == LET); ++num_var_or_const_; return variables_.Declare(this, name, mode, true, Variable::NORMAL); } @@ -437,7 +435,7 @@ Variable* Scope::DeclareLocal(Handle name, Variable::Mode mode) { Variable* Scope::DeclareGlobal(Handle name) { ASSERT(is_global_scope()); - return variables_.Declare(this, name, Variable::DYNAMIC_GLOBAL, + return variables_.Declare(this, name, DYNAMIC_GLOBAL, true, Variable::NORMAL); } @@ -473,7 +471,7 @@ Variable* Scope::NewTemporary(Handle name) { ASSERT(!already_resolved()); Variable* var = new Variable(this, name, - Variable::TEMPORARY, + TEMPORARY, true, Variable::NORMAL); temps_.Add(var); @@ -505,13 +503,13 @@ Declaration* Scope::CheckConflictingVarDeclarations() { int length = decls_.length(); for (int i = 0; i < length; i++) { Declaration* decl = decls_[i]; - if (decl->mode() != Variable::VAR) continue; + if (decl->mode() != VAR) continue; Handle name = decl->proxy()->name(); bool cond = true; for (Scope* scope = decl->scope(); cond ; scope = scope->outer_scope_) { // There is a conflict if there exists a non-VAR binding. Variable* other_var = scope->variables_.Lookup(name); - if (other_var != NULL && other_var->mode() != Variable::VAR) { + if (other_var != NULL && other_var->mode() != VAR) { return decl; } @@ -779,9 +777,9 @@ void Scope::Print(int n) { Indent(n1, "// dynamic vars\n"); if (dynamics_ != NULL) { - PrintMap(n1, dynamics_->GetMap(Variable::DYNAMIC)); - PrintMap(n1, dynamics_->GetMap(Variable::DYNAMIC_LOCAL)); - PrintMap(n1, dynamics_->GetMap(Variable::DYNAMIC_GLOBAL)); + PrintMap(n1, dynamics_->GetMap(DYNAMIC)); + PrintMap(n1, dynamics_->GetMap(DYNAMIC_LOCAL)); + PrintMap(n1, dynamics_->GetMap(DYNAMIC_GLOBAL)); } // Print inner scopes (disable by providing negative n). @@ -797,7 +795,7 @@ void Scope::Print(int n) { #endif // DEBUG -Variable* Scope::NonLocal(Handle name, Variable::Mode mode) { +Variable* Scope::NonLocal(Handle name, VariableMode mode) { if (dynamics_ == NULL) dynamics_ = new DynamicScopePart(); VariableMap* map = dynamics_->GetMap(mode); Variable* var = map->Lookup(name); @@ -903,7 +901,7 @@ void Scope::ResolveVariable(Scope* global_scope, // Note that we must do a lookup anyway, because if we find one, // we must mark that variable as potentially accessed from this // inner scope (the property may not be in the 'with' object). - var = NonLocal(proxy->name(), Variable::DYNAMIC); + var = NonLocal(proxy->name(), DYNAMIC); } else { // We are not inside a local 'with' statement. @@ -926,13 +924,13 @@ void Scope::ResolveVariable(Scope* global_scope, } else if (scope_inside_with_) { // If we are inside a with statement we give up and look up // the variable at runtime. - var = NonLocal(proxy->name(), Variable::DYNAMIC); + var = NonLocal(proxy->name(), DYNAMIC); } else if (invalidated_local != NULL) { // No with statements are involved and we found a local // variable that might be shadowed by eval introduced // variables. - var = NonLocal(proxy->name(), Variable::DYNAMIC_LOCAL); + var = NonLocal(proxy->name(), DYNAMIC_LOCAL); var->set_local_if_not_shadowed(invalidated_local); } else if (outer_scope_is_eval_scope_) { @@ -942,10 +940,10 @@ void Scope::ResolveVariable(Scope* global_scope, // variable is global if it is not shadowed by eval-introduced // variables. if (context->GlobalIfNotShadowedByEval(proxy->name())) { - var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL); + var = NonLocal(proxy->name(), DYNAMIC_GLOBAL); } else { - var = NonLocal(proxy->name(), Variable::DYNAMIC); + var = NonLocal(proxy->name(), DYNAMIC); } } else { @@ -953,7 +951,7 @@ void Scope::ResolveVariable(Scope* global_scope, // is not executed with a call to eval. We know that this // variable is global unless it is shadowed by eval-introduced // variables. - var = NonLocal(proxy->name(), Variable::DYNAMIC_GLOBAL); + var = NonLocal(proxy->name(), DYNAMIC_GLOBAL); } } } @@ -1040,7 +1038,7 @@ bool Scope::MustAllocateInContext(Variable* var) { // // Exceptions: temporary variables are never allocated in a context; // catch-bound variables are always allocated in a context. - if (var->mode() == Variable::TEMPORARY) return false; + if (var->mode() == TEMPORARY) return false; if (is_catch_scope() || is_block_scope()) return true; return var->is_accessed_from_inner_scope() || scope_calls_eval_ || diff --git a/src/scopes.h b/src/scopes.h index 2917a63bb..7e789b8bd 100644 --- a/src/scopes.h +++ b/src/scopes.h @@ -50,7 +50,7 @@ class VariableMap: public HashMap { Variable* Declare(Scope* scope, Handle name, - Variable::Mode mode, + VariableMode mode, bool is_valid_lhs, Variable::Kind kind); @@ -64,8 +64,8 @@ class VariableMap: public HashMap { // and setup time for scopes that don't need them. class DynamicScopePart : public ZoneObject { public: - VariableMap* GetMap(Variable::Mode mode) { - int index = mode - Variable::DYNAMIC; + VariableMap* GetMap(VariableMode mode) { + int index = mode - DYNAMIC; ASSERT(index >= 0 && index < 3); return &maps_[index]; } @@ -135,11 +135,11 @@ class Scope: public ZoneObject { // Declare a parameter in this scope. When there are duplicated // parameters the rightmost one 'wins'. However, the implementation // expects all parameters to be declared and from left to right. - void DeclareParameter(Handle name, Variable::Mode mode); + void DeclareParameter(Handle name, VariableMode mode); // Declare a local variable in this scope. If the variable has been // declared before, the previously declared variable is returned. - Variable* DeclareLocal(Handle name, Variable::Mode mode); + Variable* DeclareLocal(Handle name, VariableMode mode); // Declare an implicit global variable in this scope which must be a // global scope. The variable was introduced (possibly from an inner @@ -406,7 +406,7 @@ class Scope: public ZoneObject { // Create a non-local variable with a given name. // These variables are looked up dynamically at runtime. - Variable* NonLocal(Handle name, Variable::Mode mode); + Variable* NonLocal(Handle name, VariableMode mode); // Variable resolution. Variable* LookupRecursive(Handle name, diff --git a/src/v8globals.h b/src/v8globals.h index bd3d02b47..09d26d2f1 100644 --- a/src/v8globals.h +++ b/src/v8globals.h @@ -496,7 +496,7 @@ enum StrictModeFlag { // Used to specify if a macro instruction must perform a smi check on tagged // values. enum SmiCheckType { - DONT_DO_SMI_CHECK = 0, + DONT_DO_SMI_CHECK, DO_SMI_CHECK }; @@ -504,7 +504,7 @@ enum SmiCheckType { // Used to specify whether a receiver is implicitly or explicitly // provided to a call. enum CallKind { - CALL_AS_METHOD = 0, + CALL_AS_METHOD, CALL_AS_FUNCTION }; @@ -518,6 +518,35 @@ const uint64_t kHoleNanInt64 = const uint64_t kLastNonNaNInt64 = (static_cast(kNaNOrInfinityLowerBoundUpper32) << 32); + +enum VariableMode { + // User declared variables: + VAR, // declared via 'var', and 'function' declarations + + CONST, // declared via 'const' declarations + + LET, // declared via 'let' declarations + + // Variables introduced by the compiler: + DYNAMIC, // always require dynamic lookup (we don't know + // the declaration) + + DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the + // variable is global unless it has been shadowed + // by an eval-introduced variable + + DYNAMIC_LOCAL, // requires dynamic lookup, but we know that the + // variable is local and where it is unless it + // has been shadowed by an eval-introduced + // variable + + INTERNAL, // like VAR, but not user-visible (may or may not + // be in a context) + + TEMPORARY // temporary variables (not user-visible), never + // in a context +}; + } } // namespace v8::internal #endif // V8_V8GLOBALS_H_ diff --git a/src/variables.cc b/src/variables.cc index 971061b05..076cdc0a4 100644 --- a/src/variables.cc +++ b/src/variables.cc @@ -37,7 +37,7 @@ namespace internal { // ---------------------------------------------------------------------------- // Implementation Variable. -const char* Variable::Mode2String(Mode mode) { +const char* Variable::Mode2String(VariableMode mode) { switch (mode) { case VAR: return "VAR"; case CONST: return "CONST"; @@ -55,7 +55,7 @@ const char* Variable::Mode2String(Mode mode) { Variable::Variable(Scope* scope, Handle name, - Mode mode, + VariableMode mode, bool is_valid_LHS, Kind kind) : scope_(scope), diff --git a/src/variables.h b/src/variables.h index 56c8dabd3..612d8d33c 100644 --- a/src/variables.h +++ b/src/variables.h @@ -40,34 +40,6 @@ namespace internal { class Variable: public ZoneObject { public: - enum Mode { - // User declared variables: - VAR, // declared via 'var', and 'function' declarations - - CONST, // declared via 'const' declarations - - LET, // declared via 'let' declarations - - // Variables introduced by the compiler: - DYNAMIC, // always require dynamic lookup (we don't know - // the declaration) - - DYNAMIC_GLOBAL, // requires dynamic lookup, but we know that the - // variable is global unless it has been shadowed - // by an eval-introduced variable - - DYNAMIC_LOCAL, // requires dynamic lookup, but we know that the - // variable is local and where it is unless it - // has been shadowed by an eval-introduced - // variable - - INTERNAL, // like VAR, but not user-visible (may or may not - // be in a context) - - TEMPORARY // temporary variables (not user-visible), never - // in a context - }; - enum Kind { NORMAL, THIS, @@ -103,12 +75,12 @@ class Variable: public ZoneObject { Variable(Scope* scope, Handle name, - Mode mode, + VariableMode mode, bool is_valid_lhs, Kind kind); // Printing support - static const char* Mode2String(Mode mode); + static const char* Mode2String(VariableMode mode); bool IsValidLeftHandSide() { return is_valid_LHS_; } @@ -119,7 +91,7 @@ class Variable: public ZoneObject { Scope* scope() const { return scope_; } Handle name() const { return name_; } - Mode mode() const { return mode_; } + VariableMode mode() const { return mode_; } bool is_accessed_from_inner_scope() const { return is_accessed_from_inner_scope_; } @@ -177,7 +149,7 @@ class Variable: public ZoneObject { private: Scope* scope_; Handle name_; - Mode mode_; + VariableMode mode_; Kind kind_; Location location_; int index_; diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc index 92732fa3c..e5c0c35b9 100644 --- a/src/x64/full-codegen-x64.cc +++ b/src/x64/full-codegen-x64.cc @@ -254,7 +254,7 @@ void FullCodeGenerator::Generate(CompilationInfo* info) { // constant. if (scope()->is_function_scope() && scope()->function() != NULL) { int ignored = 0; - EmitDeclaration(scope()->function(), Variable::CONST, NULL, &ignored); + EmitDeclaration(scope()->function(), CONST, NULL, &ignored); } VisitDeclarations(scope()->declarations()); } @@ -677,7 +677,7 @@ void FullCodeGenerator::PrepareForBailoutBeforeSplit(State state, void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, - Variable::Mode mode, + VariableMode mode, FunctionLiteral* function, int* global_count) { // If it was not possible to allocate the variable at compile time, we @@ -695,7 +695,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, Comment cmnt(masm_, "[ Declaration"); VisitForAccumulatorValue(function); __ movq(StackOperand(variable), result_register()); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { Comment cmnt(masm_, "[ Declaration"); __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); __ movq(StackOperand(variable), kScratchRegister); @@ -728,7 +728,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, EMIT_REMEMBERED_SET, OMIT_SMI_CHECK); PrepareForBailoutForId(proxy->id(), NO_REGISTERS); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { Comment cmnt(masm_, "[ Declaration"); __ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex); __ movq(ContextOperand(rsi, variable->index()), kScratchRegister); @@ -742,10 +742,8 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, __ push(rsi); __ Push(variable->name()); // Declaration nodes are always introduced in one of three modes. - ASSERT(mode == Variable::VAR || - mode == Variable::CONST || - mode == Variable::LET); - PropertyAttributes attr = (mode == Variable::CONST) ? READ_ONLY : NONE; + ASSERT(mode == VAR || mode == CONST || mode == LET); + PropertyAttributes attr = (mode == CONST) ? READ_ONLY : NONE; __ Push(Smi::FromInt(attr)); // Push initial value, if any. // Note: For variables we must not push an initial value (such as @@ -753,7 +751,7 @@ void FullCodeGenerator::EmitDeclaration(VariableProxy* proxy, // must not destroy the current value. if (function != NULL) { VisitForStackValue(function); - } else if (mode == Variable::CONST || mode == Variable::LET) { + } else if (mode == CONST || mode == LET) { __ PushRoot(Heap::kTheHoleValueRootIndex); } else { __ Push(Smi::FromInt(0)); // Indicates no initial value. @@ -1178,19 +1176,18 @@ void FullCodeGenerator::EmitDynamicLookupFastCase(Variable* var, // introducing variables. In those cases, we do not want to // perform a runtime call for all variables in the scope // containing the eval. - if (var->mode() == Variable::DYNAMIC_GLOBAL) { + if (var->mode() == DYNAMIC_GLOBAL) { EmitLoadGlobalCheckExtensions(var, typeof_state, slow); __ jmp(done); - } else if (var->mode() == Variable::DYNAMIC_LOCAL) { + } else if (var->mode() == DYNAMIC_LOCAL) { Variable* local = var->local_if_not_shadowed(); __ movq(rax, ContextSlotOperandCheckExtensions(local, slow)); - if (local->mode() == Variable::CONST || - local->mode() == Variable::LET) { + if (local->mode() == CONST || local->mode() == LET) { __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); __ j(not_equal, done); - if (local->mode() == Variable::CONST) { + if (local->mode() == CONST) { __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); - } else { // Variable::LET + } else { // LET __ Push(var->name()); __ CallRuntime(Runtime::kThrowReferenceError, 1); } @@ -1224,7 +1221,7 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { case Variable::LOCAL: case Variable::CONTEXT: { Comment cmnt(masm_, var->IsContextSlot() ? "Context slot" : "Stack slot"); - if (var->mode() != Variable::LET && var->mode() != Variable::CONST) { + if (var->mode() != LET && var->mode() != CONST) { context()->Plug(var); } else { // Let and const need a read barrier. @@ -1232,10 +1229,10 @@ void FullCodeGenerator::EmitVariableLoad(VariableProxy* proxy) { GetVar(rax, var); __ CompareRoot(rax, Heap::kTheHoleValueRootIndex); __ j(not_equal, &done, Label::kNear); - if (var->mode() == Variable::LET) { + if (var->mode() == LET) { __ Push(var->name()); __ CallRuntime(Runtime::kThrowReferenceError, 1); - } else { // Variable::CONST + } else { // CONST __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); } __ bind(&done); @@ -1782,7 +1779,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, __ CallRuntime(Runtime::kInitializeConstContextSlot, 3); } - } else if (var->mode() == Variable::LET && op != Token::INIT_LET) { + } else if (var->mode() == LET && op != Token::INIT_LET) { // Non-initializing assignment to let variable needs a write barrier. if (var->IsLookupSlot()) { __ push(rax); // Value. @@ -1808,7 +1805,7 @@ void FullCodeGenerator::EmitVariableAssignment(Variable* var, } } - } else if (var->mode() != Variable::CONST) { + } else if (var->mode() != CONST) { // Assignment to var or initializing assignment to let. if (var->IsStackAllocated() || var->IsContextSlot()) { MemOperand location = VarOperand(var, rcx); @@ -2077,7 +2074,7 @@ void FullCodeGenerator::VisitCall(Call* expr) { // context lookup in the runtime system. Label done; Variable* var = proxy->var(); - if (!var->IsUnallocated() && var->mode() == Variable::DYNAMIC_GLOBAL) { + if (!var->IsUnallocated() && var->mode() == DYNAMIC_GLOBAL) { Label slow; EmitLoadGlobalCheckExtensions(var, NOT_INSIDE_TYPEOF, &slow); // Push the function and resolve eval. -- 2.34.1