OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/ast/scopes.h" | 5 #include "src/ast/scopes.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 DCHECK(is_declaration_scope()); | 368 DCHECK(is_declaration_scope()); |
369 return static_cast<const DeclarationScope*>(this); | 369 return static_cast<const DeclarationScope*>(this); |
370 } | 370 } |
371 | 371 |
372 int Scope::num_parameters() const { | 372 int Scope::num_parameters() const { |
373 return is_declaration_scope() ? AsDeclarationScope()->num_parameters() : 0; | 373 return is_declaration_scope() ? AsDeclarationScope()->num_parameters() : 0; |
374 } | 374 } |
375 | 375 |
376 bool Scope::Analyze(ParseInfo* info) { | 376 bool Scope::Analyze(ParseInfo* info) { |
377 DCHECK(info->literal() != NULL); | 377 DCHECK(info->literal() != NULL); |
378 DCHECK(info->scope() == NULL); | |
379 DeclarationScope* scope = info->literal()->scope(); | 378 DeclarationScope* scope = info->literal()->scope(); |
380 DeclarationScope* top = scope; | 379 DeclarationScope* top = scope; |
381 | 380 |
382 // Traverse the scope tree up to the first unresolved scope or the global | 381 // Traverse the scope tree up to the first unresolved scope or the global |
383 // scope and start scope resolution and variable allocation from that scope. | 382 // scope and start scope resolution and variable allocation from that scope. |
384 // Such a scope is always a closure-scope, so always skip to the next closure | 383 // Such a scope is always a closure-scope, so always skip to the next closure |
385 // scope. | 384 // scope. |
386 while (!top->is_script_scope() && | 385 while (!top->is_script_scope() && |
387 !top->outer_scope()->already_resolved()) { | 386 !top->outer_scope()->already_resolved()) { |
388 top = top->outer_scope()->GetClosureScope(); | 387 top = top->outer_scope()->GetClosureScope(); |
389 } | 388 } |
390 | 389 |
391 // Allocate the variables. | 390 // Allocate the variables. |
392 { | 391 { |
393 AstNodeFactory ast_node_factory(info->ast_value_factory()); | 392 AstNodeFactory ast_node_factory(info->ast_value_factory()); |
394 if (!top->AllocateVariables(info, &ast_node_factory)) return false; | 393 if (!top->AllocateVariables(info, &ast_node_factory)) return false; |
395 } | 394 } |
396 | 395 |
397 #ifdef DEBUG | 396 #ifdef DEBUG |
398 if (info->script_is_native() ? FLAG_print_builtin_scopes | 397 if (info->script_is_native() ? FLAG_print_builtin_scopes |
399 : FLAG_print_scopes) { | 398 : FLAG_print_scopes) { |
400 scope->Print(); | 399 scope->Print(); |
401 } | 400 } |
402 scope->CheckScopePositions(); | 401 scope->CheckScopePositions(); |
403 scope->CheckZones(); | 402 scope->CheckZones(); |
404 #endif | 403 #endif |
405 | 404 |
406 info->set_scope(scope); | |
407 return true; | 405 return true; |
408 } | 406 } |
409 | 407 |
410 void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { | 408 void DeclarationScope::DeclareThis(AstValueFactory* ast_value_factory) { |
411 DCHECK(!already_resolved()); | 409 DCHECK(!already_resolved()); |
412 DCHECK(is_declaration_scope()); | 410 DCHECK(is_declaration_scope()); |
413 DCHECK(has_this_declaration()); | 411 DCHECK(has_this_declaration()); |
414 | 412 |
415 bool subclass_constructor = IsSubclassConstructor(function_kind_); | 413 bool subclass_constructor = IsSubclassConstructor(function_kind_); |
416 Variable* var = variables_.Declare( | 414 Variable* var = variables_.Declare( |
(...skipping 1371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1788 function != NULL && function->proxy()->var()->IsContextSlot(); | 1786 function != NULL && function->proxy()->var()->IsContextSlot(); |
1789 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - | 1787 return num_heap_slots() - Context::MIN_CONTEXT_SLOTS - num_global_slots() - |
1790 (is_function_var_in_context ? 1 : 0); | 1788 (is_function_var_in_context ? 1 : 0); |
1791 } | 1789 } |
1792 | 1790 |
1793 | 1791 |
1794 int Scope::ContextGlobalCount() const { return num_global_slots(); } | 1792 int Scope::ContextGlobalCount() const { return num_global_slots(); } |
1795 | 1793 |
1796 } // namespace internal | 1794 } // namespace internal |
1797 } // namespace v8 | 1795 } // namespace v8 |
OLD | NEW |