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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
411 // Check that all Scopes in the scope tree use the same Zone. | 411 // Check that all Scopes in the scope tree use the same Zone. |
412 void CheckZones(); | 412 void CheckZones(); |
413 #endif | 413 #endif |
414 | 414 |
415 // Retrieve `IsSimpleParameterList` of current or outer function. | 415 // Retrieve `IsSimpleParameterList` of current or outer function. |
416 bool HasSimpleParameters(); | 416 bool HasSimpleParameters(); |
417 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } | 417 void set_is_debug_evaluate_scope() { is_debug_evaluate_scope_ = true; } |
418 bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; } | 418 bool is_debug_evaluate_scope() const { return is_debug_evaluate_scope_; } |
419 | 419 |
420 bool is_lazily_parsed() const { return is_lazily_parsed_; } | 420 bool is_lazily_parsed() const { return is_lazily_parsed_; } |
421 bool should_compile_lazily() const { | |
422 return is_lazily_parsed_ || should_compile_lazily_; | |
423 } | |
424 | |
425 // Marks this scope and all inner scopes (except for inner function scopes) | |
426 // as lazy. | |
marja
2016/10/06 11:53:06
Why "except for inner function scopes"?
If we com
jochen (gone - plz use gerrit)
2016/10/06 15:05:04
yeah, but not the other way round... if we compile
| |
427 void SetShouldCompileLazily(bool is_lazy); | |
421 | 428 |
422 protected: | 429 protected: |
423 explicit Scope(Zone* zone); | 430 explicit Scope(Zone* zone); |
424 | 431 |
425 void set_language_mode(LanguageMode language_mode) { | 432 void set_language_mode(LanguageMode language_mode) { |
426 is_strict_ = is_strict(language_mode); | 433 is_strict_ = is_strict(language_mode); |
427 } | 434 } |
428 | 435 |
429 private: | 436 private: |
430 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, | 437 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, |
431 VariableMode mode, VariableKind kind, | 438 VariableMode mode, VariableKind kind, |
432 InitializationFlag initialization_flag, | 439 InitializationFlag initialization_flag, |
433 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { | 440 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { |
434 bool added; | 441 bool added; |
435 Variable* var = | 442 Variable* var = |
436 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, | 443 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, |
437 maybe_assigned_flag, &added); | 444 maybe_assigned_flag, &added); |
438 if (added) locals_.Add(var, zone); | 445 if (added) locals_.Add(var, zone); |
439 return var; | 446 return var; |
440 } | 447 } |
441 | 448 |
442 // This method should only be invoked on scopes created during parsing (i.e., | 449 // This method should only be invoked on scopes created during parsing (i.e., |
443 // not deserialized from a context). Also, since NeedsContext() is only | 450 // not deserialized from a context). Also, since NeedsContext() is only |
444 // returning a valid result after variables are resolved, NeedsScopeInfo() | 451 // returning a valid result after variables are resolved, NeedsScopeInfo() |
445 // should also be invoked after resolution. | 452 // should also be invoked after resolution. |
446 bool NeedsScopeInfo() const { | 453 bool NeedsScopeInfo() const { |
447 DCHECK(!already_resolved_); | 454 DCHECK(!already_resolved_); |
448 // A lazily parsed scope doesn't contain enough information to create a | 455 // A lazily parsed scope doesn't contain enough information to create a |
449 // ScopeInfo from it. | 456 // ScopeInfo from it. |
450 if (is_lazily_parsed_) return false; | 457 if (should_compile_lazily()) return false; |
451 // The debugger expects all functions to have scope infos. | 458 // The debugger expects all functions to have scope infos. |
452 // TODO(jochen|yangguo): Remove this requirement. | 459 // TODO(jochen|yangguo): Remove this requirement. |
453 if (is_function_scope()) return true; | 460 if (is_function_scope()) return true; |
454 return NeedsContext(); | 461 return NeedsContext(); |
455 } | 462 } |
456 | 463 |
457 Zone* zone_; | 464 Zone* zone_; |
458 | 465 |
459 // Scope tree. | 466 // Scope tree. |
460 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL | 467 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. | 523 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. |
517 bool is_debug_evaluate_scope_ : 1; | 524 bool is_debug_evaluate_scope_ : 1; |
518 | 525 |
519 bool inner_scope_calls_eval_ : 1; | 526 bool inner_scope_calls_eval_ : 1; |
520 bool force_context_allocation_ : 1; | 527 bool force_context_allocation_ : 1; |
521 | 528 |
522 // True if it holds 'var' declarations. | 529 // True if it holds 'var' declarations. |
523 bool is_declaration_scope_ : 1; | 530 bool is_declaration_scope_ : 1; |
524 | 531 |
525 bool is_lazily_parsed_ : 1; | 532 bool is_lazily_parsed_ : 1; |
533 bool should_compile_lazily_ : 1; | |
526 | 534 |
527 // Create a non-local variable with a given name. | 535 // Create a non-local variable with a given name. |
528 // These variables are looked up dynamically at runtime. | 536 // These variables are looked up dynamically at runtime. |
529 Variable* NonLocal(const AstRawString* name, VariableMode mode); | 537 Variable* NonLocal(const AstRawString* name, VariableMode mode); |
530 | 538 |
531 // Variable resolution. | 539 // Variable resolution. |
532 // Lookup a variable reference given by name recursively starting with this | 540 // Lookup a variable reference given by name recursively starting with this |
533 // scope, and stopping when reaching the outer_scope_end scope. If the code is | 541 // scope, and stopping when reaching the outer_scope_end scope. If the code is |
534 // executed because of a call to 'eval', the context parameter should be set | 542 // executed because of a call to 'eval', the context parameter should be set |
535 // to the calling context of 'eval'. | 543 // to the calling context of 'eval'. |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
884 void AllocateModuleVariables(); | 892 void AllocateModuleVariables(); |
885 | 893 |
886 private: | 894 private: |
887 ModuleDescriptor* module_descriptor_; | 895 ModuleDescriptor* module_descriptor_; |
888 }; | 896 }; |
889 | 897 |
890 } // namespace internal | 898 } // namespace internal |
891 } // namespace v8 | 899 } // namespace v8 |
892 | 900 |
893 #endif // V8_AST_SCOPES_H_ | 901 #endif // V8_AST_SCOPES_H_ |
OLD | NEW |