| 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 | 404 |
| 405 // Check that all Scopes in the scope tree use the same Zone. | 405 // Check that all Scopes in the scope tree use the same Zone. |
| 406 void CheckZones(); | 406 void CheckZones(); |
| 407 #endif | 407 #endif |
| 408 | 408 |
| 409 // Retrieve `IsSimpleParameterList` of current or outer function. | 409 // Retrieve `IsSimpleParameterList` of current or outer function. |
| 410 bool HasSimpleParameters(); | 410 bool HasSimpleParameters(); |
| 411 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } | 411 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } |
| 412 bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; } | 412 bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; } |
| 413 | 413 |
| 414 void set_is_lazily_parsed(bool is_lazily_parsed) { |
| 415 is_lazily_parsed_ = is_lazily_parsed; |
| 416 } |
| 417 |
| 414 protected: | 418 protected: |
| 415 explicit Scope(Zone* zone); | 419 explicit Scope(Zone* zone); |
| 416 | 420 |
| 417 void set_language_mode(LanguageMode language_mode) { | 421 void set_language_mode(LanguageMode language_mode) { |
| 418 is_strict_ = is_strict(language_mode); | 422 is_strict_ = is_strict(language_mode); |
| 419 } | 423 } |
| 420 | 424 |
| 421 private: | 425 private: |
| 422 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 426 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
| 423 VariableMode mode, VariableKind kind, | 427 VariableMode mode, VariableKind kind, |
| 424 InitializationFlag initialization_flag, | 428 InitializationFlag initialization_flag, |
| 425 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { | 429 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { |
| 426 bool added; | 430 bool added; |
| 427 Variable* var = | 431 Variable* var = |
| 428 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, | 432 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, |
| 429 maybe_assigned_flag, &added); | 433 maybe_assigned_flag, &added); |
| 430 if (added) locals_.Add(var, zone); | 434 if (added) locals_.Add(var, zone); |
| 431 return var; | 435 return var; |
| 432 } | 436 } |
| 433 | 437 |
| 434 // This method should only be invoked on scopes created during parsing (i.e., | 438 // This method should only be invoked on scopes created during parsing (i.e., |
| 435 // not deserialized from a context). Also, since NeedsContext() is only | 439 // not deserialized from a context). Also, since NeedsContext() is only |
| 436 // returning a valid result after variables are resolved, NeedsScopeInfo() | 440 // returning a valid result after variables are resolved, NeedsScopeInfo() |
| 437 // should also be invoked after resolution. | 441 // should also be invoked after resolution. |
| 438 bool NeedsScopeInfo() const { | 442 bool NeedsScopeInfo() const { |
| 439 DCHECK(!already_resolved_); | 443 DCHECK(!already_resolved_); |
| 444 // A lazily parsed scope doesn't contain enough information to create a |
| 445 // ScopeInfo from it. |
| 446 if (is_lazily_parsed_) return false; |
| 440 return NeedsContext() || is_script_scope() || is_function_scope() || | 447 return NeedsContext() || is_script_scope() || is_function_scope() || |
| 441 is_eval_scope() || is_module_scope(); | 448 is_eval_scope() || is_module_scope(); |
| 442 } | 449 } |
| 443 | 450 |
| 444 Zone* zone_; | 451 Zone* zone_; |
| 445 | 452 |
| 446 // Scope tree. | 453 // Scope tree. |
| 447 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 454 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
| 448 Scope* inner_scope_; // an inner scope of this scope | 455 Scope* inner_scope_; // an inner scope of this scope |
| 449 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. | 456 Scope* sibling_; // a sibling inner scope of the outer scope of this scope. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 bool is_hidden_ : 1; | 506 bool is_hidden_ : 1; |
| 500 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. | 507 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. |
| 501 bool is_debug_evaluate_scope_ : 1; | 508 bool is_debug_evaluate_scope_ : 1; |
| 502 | 509 |
| 503 bool inner_scope_calls_eval_ : 1; | 510 bool inner_scope_calls_eval_ : 1; |
| 504 bool force_context_allocation_ : 1; | 511 bool force_context_allocation_ : 1; |
| 505 | 512 |
| 506 // True if it holds 'var' declarations. | 513 // True if it holds 'var' declarations. |
| 507 bool is_declaration_scope_ : 1; | 514 bool is_declaration_scope_ : 1; |
| 508 | 515 |
| 516 bool is_lazily_parsed_ : 1; |
| 517 |
| 509 // Create a non-local variable with a given name. | 518 // Create a non-local variable with a given name. |
| 510 // These variables are looked up dynamically at runtime. | 519 // These variables are looked up dynamically at runtime. |
| 511 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 520 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
| 512 | 521 |
| 513 // Variable resolution. | 522 // Variable resolution. |
| 514 // Lookup a variable reference given by name recursively starting with this | 523 // Lookup a variable reference given by name recursively starting with this |
| 515 // scope, and stopping when reaching the outer_scope_end scope. If the code is | 524 // scope, and stopping when reaching the outer_scope_end scope. If the code is |
| 516 // executed because of a call to 'eval', the context parameter should be set | 525 // executed because of a call to 'eval', the context parameter should be set |
| 517 // to the calling context of 'eval'. | 526 // to the calling context of 'eval'. |
| 518 // {declare_free} indicates whether nullptr should be returned for free | 527 // {declare_free} indicates whether nullptr should be returned for free |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 863 void AllocateModuleVariables(); | 872 void AllocateModuleVariables(); |
| 864 | 873 |
| 865 private: | 874 private: |
| 866 ModuleDescriptor* module_descriptor_; | 875 ModuleDescriptor* module_descriptor_; |
| 867 }; | 876 }; |
| 868 | 877 |
| 869 } // namespace internal | 878 } // namespace internal |
| 870 } // namespace v8 | 879 } // namespace v8 |
| 871 | 880 |
| 872 #endif // V8_AST_SCOPES_H_ | 881 #endif // V8_AST_SCOPES_H_ |
| OLD | NEW |