Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/ast/scopes.h

Issue 2399833002: Teach Scopes whether they will end up being lazily compiled or not (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ast/ast.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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
422 protected: 428 protected:
423 explicit Scope(Zone* zone); 429 explicit Scope(Zone* zone);
424 430
425 void set_language_mode(LanguageMode language_mode) { 431 void set_language_mode(LanguageMode language_mode) {
426 is_strict_ = is_strict(language_mode); 432 is_strict_ = is_strict(language_mode);
427 } 433 }
428 434
429 private: 435 private:
430 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name, 436 Variable* Declare(Zone* zone, Scope* scope, const AstRawString* name,
431 VariableMode mode, VariableKind kind, 437 VariableMode mode, VariableKind kind,
432 InitializationFlag initialization_flag, 438 InitializationFlag initialization_flag,
433 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) { 439 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned) {
434 bool added; 440 bool added;
435 Variable* var = 441 Variable* var =
436 variables_.Declare(zone, scope, name, mode, kind, initialization_flag, 442 variables_.Declare(zone, scope, name, mode, kind, initialization_flag,
437 maybe_assigned_flag, &added); 443 maybe_assigned_flag, &added);
438 if (added) locals_.Add(var, zone); 444 if (added) locals_.Add(var, zone);
439 return var; 445 return var;
440 } 446 }
441 447
442 // This method should only be invoked on scopes created during parsing (i.e., 448 // This method should only be invoked on scopes created during parsing (i.e.,
443 // not deserialized from a context). Also, since NeedsContext() is only 449 // not deserialized from a context). Also, since NeedsContext() is only
444 // returning a valid result after variables are resolved, NeedsScopeInfo() 450 // returning a valid result after variables are resolved, NeedsScopeInfo()
445 // should also be invoked after resolution. 451 // should also be invoked after resolution.
446 bool NeedsScopeInfo() const { 452 bool NeedsScopeInfo() const {
447 DCHECK(!already_resolved_); 453 DCHECK(!already_resolved_);
448 // A lazily parsed scope doesn't contain enough information to create a 454 // A lazily parsed scope doesn't contain enough information to create a
449 // ScopeInfo from it. 455 // ScopeInfo from it.
450 if (is_lazily_parsed_) return false; 456 if (!ShouldEagerCompile()) return false;
451 // The debugger expects all functions to have scope infos. 457 // The debugger expects all functions to have scope infos.
452 // TODO(jochen|yangguo): Remove this requirement. 458 // TODO(jochen|yangguo): Remove this requirement.
453 if (is_function_scope()) return true; 459 if (is_function_scope()) return true;
454 return NeedsContext(); 460 return NeedsContext();
455 } 461 }
456 462
457 Zone* zone_; 463 Zone* zone_;
458 464
459 // Scope tree. 465 // Scope tree.
460 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL 466 Scope* outer_scope_; // the immediately enclosing outer scope, or NULL
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // Temporary workaround that allows masking of 'this' in debug-evalute scopes. 522 // Temporary workaround that allows masking of 'this' in debug-evalute scopes.
517 bool is_debug_evaluate_scope_ : 1; 523 bool is_debug_evaluate_scope_ : 1;
518 524
519 bool inner_scope_calls_eval_ : 1; 525 bool inner_scope_calls_eval_ : 1;
520 bool force_context_allocation_ : 1; 526 bool force_context_allocation_ : 1;
521 527
522 // True if it holds 'var' declarations. 528 // True if it holds 'var' declarations.
523 bool is_declaration_scope_ : 1; 529 bool is_declaration_scope_ : 1;
524 530
525 bool is_lazily_parsed_ : 1; 531 bool is_lazily_parsed_ : 1;
532 bool should_eager_compile_ : 1;
526 533
527 // Create a non-local variable with a given name. 534 // Create a non-local variable with a given name.
528 // These variables are looked up dynamically at runtime. 535 // These variables are looked up dynamically at runtime.
529 Variable* NonLocal(const AstRawString* name, VariableMode mode); 536 Variable* NonLocal(const AstRawString* name, VariableMode mode);
530 537
531 // Variable resolution. 538 // Variable resolution.
532 // Lookup a variable reference given by name recursively starting with this 539 // 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 540 // 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 541 // executed because of a call to 'eval', the context parameter should be set
535 // to the calling context of 'eval'. 542 // to the calling context of 'eval'.
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 void AllocateModuleVariables(); 888 void AllocateModuleVariables();
882 889
883 private: 890 private:
884 ModuleDescriptor* module_descriptor_; 891 ModuleDescriptor* module_descriptor_;
885 }; 892 };
886 893
887 } // namespace internal 894 } // namespace internal
888 } // namespace v8 895 } // namespace v8
889 896
890 #endif // V8_AST_SCOPES_H_ 897 #endif // V8_AST_SCOPES_H_
OLDNEW
« no previous file with comments | « src/ast/ast.cc ('k') | src/ast/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698