| 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 #ifndef V8_AST_SCOPES_H_ | 5 #ifndef V8_AST_SCOPES_H_ |
| 6 #define V8_AST_SCOPES_H_ | 6 #define V8_AST_SCOPES_H_ |
| 7 | 7 |
| 8 #include "src/base/hashmap.h" | 8 #include "src/base/hashmap.h" |
| 9 #include "src/globals.h" | 9 #include "src/globals.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 // Find the first function, script, eval or (declaration) block scope. This is | 362 // Find the first function, script, eval or (declaration) block scope. This is |
| 363 // the scope where var declarations will be hoisted to in the implementation. | 363 // the scope where var declarations will be hoisted to in the implementation. |
| 364 DeclarationScope* GetDeclarationScope(); | 364 DeclarationScope* GetDeclarationScope(); |
| 365 | 365 |
| 366 // Find the first non-block declaration scope. This should be either a script, | 366 // Find the first non-block declaration scope. This should be either a script, |
| 367 // function, or eval scope. Same as DeclarationScope(), but skips declaration | 367 // function, or eval scope. Same as DeclarationScope(), but skips declaration |
| 368 // "block" scopes. Used for differentiating associated function objects (i.e., | 368 // "block" scopes. Used for differentiating associated function objects (i.e., |
| 369 // the scope for which a function prologue allocates a context) or declaring | 369 // the scope for which a function prologue allocates a context) or declaring |
| 370 // temporaries. | 370 // temporaries. |
| 371 DeclarationScope* GetClosureScope(); | 371 DeclarationScope* GetClosureScope(); |
| 372 const DeclarationScope* GetClosureScope() const; |
| 372 | 373 |
| 373 // Find the first (non-arrow) function or script scope. This is where | 374 // Find the first (non-arrow) function or script scope. This is where |
| 374 // 'this' is bound, and what determines the function kind. | 375 // 'this' is bound, and what determines the function kind. |
| 375 DeclarationScope* GetReceiverScope(); | 376 DeclarationScope* GetReceiverScope(); |
| 376 | 377 |
| 377 // Find the module scope, assuming there is one. | 378 // Find the module scope, assuming there is one. |
| 378 ModuleScope* GetModuleScope(); | 379 ModuleScope* GetModuleScope(); |
| 379 | 380 |
| 380 // Find the innermost outer scope that needs a context. | 381 // Find the innermost outer scope that needs a context. |
| 381 Scope* GetOuterScopeWithContext(); | 382 Scope* GetOuterScopeWithContext(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 410 | 411 |
| 411 // Check that all Scopes in the scope tree use the same Zone. | 412 // Check that all Scopes in the scope tree use the same Zone. |
| 412 void CheckZones(); | 413 void CheckZones(); |
| 413 #endif | 414 #endif |
| 414 | 415 |
| 415 // Retrieve `IsSimpleParameterList` of current or outer function. | 416 // Retrieve `IsSimpleParameterList` of current or outer function. |
| 416 bool HasSimpleParameters(); | 417 bool HasSimpleParameters(); |
| 417 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } | 418 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } |
| 418 bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; } | 419 bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; } |
| 419 | 420 |
| 420 bool is_lazily_parsed() const { return is_lazily_parsed_; } | |
| 421 | |
| 422 bool ShouldEagerCompile() const; | |
| 423 | |
| 424 // Marks this scope and all inner scopes (except for inner function scopes) | |
| 425 // such that they get eagerly compiled. | |
| 426 void SetShouldEagerCompile(); | |
| 427 | |
| 428 protected: | 421 protected: |
| 429 explicit Scope(Zone* zone); | 422 explicit Scope(Zone* zone); |
| 430 | 423 |
| 431 void set_language_mode(LanguageMode language_mode) { | 424 void set_language_mode(LanguageMode language_mode) { |
| 432 is_strict_ = is_strict(language_mode); | 425 is_strict_ = is_strict(language_mode); |
| 433 } | 426 } |
| 434 | 427 |
| 435 private: | 428 private: |
| 436 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 429 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
| 437 VariableMode mode, VariableKind kind, | 430 VariableMode mode, VariableKind kind, |
| 438 InitializationFlag initialization_flag, | 431 InitializationFlag initialization_flag, |
| 439 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { | 432 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { |
| 440 bool added; | 433 bool added; |
| 441 Variable* var = | 434 Variable* var = |
| 442 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, | 435 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, |
| 443 maybe_assigned_flag, &added); | 436 maybe_assigned_flag, &added); |
| 444 if (added) locals_.Add(var, zone); | 437 if (added) locals_.Add(var, zone); |
| 445 return var; | 438 return var; |
| 446 } | 439 } |
| 447 | 440 |
| 448 // This method should only be invoked on scopes created during parsing (i.e., | 441 // This method should only be invoked on scopes created during parsing (i.e., |
| 449 // not deserialized from a context). Also, since NeedsContext() is only | 442 // not deserialized from a context). Also, since NeedsContext() is only |
| 450 // returning a valid result after variables are resolved, NeedsScopeInfo() | 443 // returning a valid result after variables are resolved, NeedsScopeInfo() |
| 451 // should also be invoked after resolution. | 444 // should also be invoked after resolution. |
| 452 bool NeedsScopeInfo() const { | 445 bool NeedsScopeInfo() const; |
| 453 DCHECK(!already_resolved_); | |
| 454 // A lazily parsed scope doesn't contain enough information to create a | |
| 455 // ScopeInfo from it. | |
| 456 if (!ShouldEagerCompile()) return false; | |
| 457 // The debugger expects all functions to have scope infos. | |
| 458 // TODO(jochen|yangguo): Remove this requirement. | |
| 459 if (is_function_scope()) return true; | |
| 460 return NeedsContext(); | |
| 461 } | |
| 462 | 446 |
| 463 Zone* zone_; | 447 Zone* zone_; |
| 464 | 448 |
| 465 // Scope tree. | 449 // Scope tree. |
| 466 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 450 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
| 467 Scope* inner_scope_; // an inner scope of this scope | 451 Scope* inner_scope_; // an inner scope of this scope |
| 468 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. | 452 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. |
| 469 | 453 |
| 470 // The variables declared in this scope: | 454 // The variables declared in this scope: |
| 471 // | 455 // |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 bool is_hidden_ : 1; | 505 bool is_hidden_ : 1; |
| 522 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. | 506 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. |
| 523 bool is_debug_evaluate_scope_ : 1; | 507 bool is_debug_evaluate_scope_ : 1; |
| 524 | 508 |
| 525 bool inner_scope_calls_eval_ : 1; | 509 bool inner_scope_calls_eval_ : 1; |
| 526 bool force_context_allocation_ : 1; | 510 bool force_context_allocation_ : 1; |
| 527 | 511 |
| 528 // True if it holds 'var' declarations. | 512 // True if it holds 'var' declarations. |
| 529 bool is_declaration_scope_ : 1; | 513 bool is_declaration_scope_ : 1; |
| 530 | 514 |
| 531 bool is_lazily_parsed_ : 1; | |
| 532 bool should_eager_compile_ : 1; | |
| 533 | |
| 534 // Create a non-local variable with a given name. | 515 // Create a non-local variable with a given name. |
| 535 // These variables are looked up dynamically at runtime. | 516 // These variables are looked up dynamically at runtime. |
| 536 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 517 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
| 537 | 518 |
| 538 // Variable resolution. | 519 // Variable resolution. |
| 539 // Lookup a variable reference given by name recursively starting with this | 520 // Lookup a variable reference given by name recursively starting with this |
| 540 // scope, and stopping when reaching the outer_scope_end scope. If the code is | 521 // scope, and stopping when reaching the outer_scope_end scope. If the code is |
| 541 // executed because of a call to 'eval', the context parameter should be set | 522 // executed because of a call to 'eval', the context parameter should be set |
| 542 // to the calling context of 'eval'. | 523 // to the calling context of 'eval'. |
| 543 Variable* LookupRecursive(VariableProxy* proxy, Scope* outer_scope_end); | 524 Variable* LookupRecursive(VariableProxy* proxy, Scope* outer_scope_end); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 // Does this scope access "super" property (super.foo). | 610 // Does this scope access "super" property (super.foo). |
| 630 bool uses_super_property() const { return scope_uses_super_property_; } | 611 bool uses_super_property() const { return scope_uses_super_property_; } |
| 631 | 612 |
| 632 bool NeedsHomeObject() const { | 613 bool NeedsHomeObject() const { |
| 633 return scope_uses_super_property_ || | 614 return scope_uses_super_property_ || |
| 634 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || | 615 (inner_scope_calls_eval_ && (IsConciseMethod(function_kind()) || |
| 635 IsAccessorFunction(function_kind()) || | 616 IsAccessorFunction(function_kind()) || |
| 636 IsClassConstructor(function_kind()))); | 617 IsClassConstructor(function_kind()))); |
| 637 } | 618 } |
| 638 | 619 |
| 620 bool is_lazily_parsed() const { return is_lazily_parsed_; } |
| 621 bool ShouldEagerCompile() const; |
| 622 void set_should_eager_compile(); |
| 623 |
| 639 void SetScriptScopeInfo(Handle<ScopeInfo> scope_info) { | 624 void SetScriptScopeInfo(Handle<ScopeInfo> scope_info) { |
| 640 DCHECK(is_script_scope()); | 625 DCHECK(is_script_scope()); |
| 641 DCHECK(scope_info_.is_null()); | 626 DCHECK(scope_info_.is_null()); |
| 642 scope_info_ = scope_info; | 627 scope_info_ = scope_info; |
| 643 } | 628 } |
| 644 | 629 |
| 645 bool asm_module() const { return asm_module_; } | 630 bool asm_module() const { return asm_module_; } |
| 646 void set_asm_module(); | 631 void set_asm_module(); |
| 647 bool asm_function() const { return asm_function_; } | 632 bool asm_function() const { return asm_function_; } |
| 648 void set_asm_function() { asm_module_ = true; } | 633 void set_asm_function() { asm_module_ = true; } |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 bool asm_module_ : 1; | 817 bool asm_module_ : 1; |
| 833 // This scope's outer context is an asm module. | 818 // This scope's outer context is an asm module. |
| 834 bool asm_function_ : 1; | 819 bool asm_function_ : 1; |
| 835 bool force_eager_compilation_ : 1; | 820 bool force_eager_compilation_ : 1; |
| 836 // This function scope has a rest parameter. | 821 // This function scope has a rest parameter. |
| 837 bool has_rest_ : 1; | 822 bool has_rest_ : 1; |
| 838 // This scope has a parameter called "arguments". | 823 // This scope has a parameter called "arguments". |
| 839 bool has_arguments_parameter_ : 1; | 824 bool has_arguments_parameter_ : 1; |
| 840 // This scope uses "super" property ('super.foo'). | 825 // This scope uses "super" property ('super.foo'). |
| 841 bool scope_uses_super_property_ : 1; | 826 bool scope_uses_super_property_ : 1; |
| 827 bool should_eager_compile_ : 1; |
| 828 bool is_lazily_parsed_ : 1; |
| 842 | 829 |
| 843 // Parameter list in source order. | 830 // Parameter list in source order. |
| 844 ZoneList<Variable*> params_; | 831 ZoneList<Variable*> params_; |
| 845 // Map of function names to lists of functions defined in sloppy blocks | 832 // Map of function names to lists of functions defined in sloppy blocks |
| 846 SloppyBlockFunctionMap sloppy_block_function_map_; | 833 SloppyBlockFunctionMap sloppy_block_function_map_; |
| 847 // Convenience variable. | 834 // Convenience variable. |
| 848 Variable* receiver_; | 835 Variable* receiver_; |
| 849 // Function variable, if any; function scopes only. | 836 // Function variable, if any; function scopes only. |
| 850 Variable* function_; | 837 Variable* function_; |
| 851 // new.target variable, function scopes only. | 838 // new.target variable, function scopes only. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 878 void AllocateModuleVariables(); | 865 void AllocateModuleVariables(); |
| 879 | 866 |
| 880 private: | 867 private: |
| 881 ModuleDescriptor* module_descriptor_; | 868 ModuleDescriptor* module_descriptor_; |
| 882 }; | 869 }; |
| 883 | 870 |
| 884 } // namespace internal | 871 } // namespace internal |
| 885 } // namespace v8 | 872 } // namespace v8 |
| 886 | 873 |
| 887 #endif // V8_AST_SCOPES_H_ | 874 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |