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

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

Issue 2664083002: [ignition] desugar async functions/generators/modules in BytecodeGenerator
Patch Set: get rid of lambdas, for better or worse.. Created 3 years, 10 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
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/compiler-specific.h" 8 #include "src/base/compiler-specific.h"
9 #include "src/base/hashmap.h" 9 #include "src/base/hashmap.h"
10 #include "src/globals.h" 10 #include "src/globals.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // from the current outer_scope_'s inner scope list). 145 // from the current outer_scope_'s inner scope list).
146 // Assumes outer_scope_ is non-null. 146 // Assumes outer_scope_ is non-null.
147 void ReplaceOuterScope(Scope* outer_scope); 147 void ReplaceOuterScope(Scope* outer_scope);
148 148
149 // Propagates any eagerly-gathered scope usage flags (such as calls_eval()) 149 // Propagates any eagerly-gathered scope usage flags (such as calls_eval())
150 // to the passed-in scope. 150 // to the passed-in scope.
151 void PropagateUsageFlagsToScope(Scope* other); 151 void PropagateUsageFlagsToScope(Scope* other);
152 152
153 Zone* zone() const { return zone_; } 153 Zone* zone() const { return zone_; }
154 154
155 // --------------------------------------------------------------------------- 155 // ------------------/-------------------------------------------------------- -
156 // Declarations 156 // Declarations
157 157
158 // Lookup a variable in this scope. Returns the variable or NULL if not found. 158 // Lookup a variable in this scope. Returns the variable or NULL if not found.
159 Variable* LookupLocal(const AstRawString* name) { 159 Variable* LookupLocal(const AstRawString* name) {
160 Variable* result = variables_.Lookup(name); 160 Variable* result = variables_.Lookup(name);
161 if (result != nullptr || scope_info_.is_null()) return result; 161 if (result != nullptr || scope_info_.is_null()) return result;
162 return LookupInScopeInfo(name); 162 return LookupInScopeInfo(name);
163 } 163 }
164 164
165 Variable* LookupInScopeInfo(const AstRawString* name); 165 Variable* LookupInScopeInfo(const AstRawString* name);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 // During formal parameter list parsing the scope only contains 421 // During formal parameter list parsing the scope only contains
422 // two variables inserted at initialization: "this" and "arguments". 422 // two variables inserted at initialization: "this" and "arguments".
423 // "this" is an invalid parameter name and "arguments" is invalid parameter 423 // "this" is an invalid parameter name and "arguments" is invalid parameter
424 // name in strict mode. Therefore looking up with the map which includes 424 // name in strict mode. Therefore looking up with the map which includes
425 // "this" and "arguments" in addition to all formal parameters is safe. 425 // "this" and "arguments" in addition to all formal parameters is safe.
426 return variables_.Lookup(name) != NULL; 426 return variables_.Lookup(name) != NULL;
427 } 427 }
428 428
429 int num_var() const { return variables_.occupancy(); } 429 int num_var() const { return variables_.occupancy(); }
430 430
431 bool HasLazilyParsedInnerFunctionScope() const;
432
431 // --------------------------------------------------------------------------- 433 // ---------------------------------------------------------------------------
432 // Debugging. 434 // Debugging.
433 435
434 #ifdef DEBUG 436 #ifdef DEBUG
435 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively 437 void Print(int n = 0); // n = indentation; n < 0 => don't print recursively
436 438
437 // Check that the scope has positions assigned. 439 // Check that the scope has positions assigned.
438 void CheckScopePositions(); 440 void CheckScopePositions();
439 441
440 // Check that all Scopes in the scope tree use the same Zone. 442 // Check that all Scopes in the scope tree use the same Zone.
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 // Declare the function variable for a function literal. This variable 674 // Declare the function variable for a function literal. This variable
673 // is in an intermediate scope between this function scope and the the 675 // is in an intermediate scope between this function scope and the the
674 // outer scope. Only possible for function scopes; at most one variable. 676 // outer scope. Only possible for function scopes; at most one variable.
675 // 677 //
676 // This function needs to be called after all other variables have been 678 // This function needs to be called after all other variables have been
677 // declared in the scope. It will add a variable for {name} to {variables_}; 679 // declared in the scope. It will add a variable for {name} to {variables_};
678 // either the function variable itself, or a non-local in case the function 680 // either the function variable itself, or a non-local in case the function
679 // calls sloppy eval. 681 // calls sloppy eval.
680 Variable* DeclareFunctionVar(const AstRawString* name); 682 Variable* DeclareFunctionVar(const AstRawString* name);
681 683
684 // Declare some special internal variables which must be accessible to
685 // Ignition without ScopeInfo.
686 Variable* DeclareGeneratorObjectVar(const AstRawString* name);
687 Variable* DeclarePromiseVar(const AstRawString* name);
688
682 // Declare a parameter in this scope. When there are duplicated 689 // Declare a parameter in this scope. When there are duplicated
683 // parameters the rightmost one 'wins'. However, the implementation 690 // parameters the rightmost one 'wins'. However, the implementation
684 // expects all parameters to be declared and from left to right. 691 // expects all parameters to be declared and from left to right.
685 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, 692 Variable* DeclareParameter(const AstRawString* name, VariableMode mode,
686 bool is_optional, bool is_rest, bool* is_duplicate, 693 bool is_optional, bool is_rest, bool* is_duplicate,
687 AstValueFactory* ast_value_factory); 694 AstValueFactory* ast_value_factory);
688 695
689 // Declare an implicit global variable in this scope which must be a 696 // Declare an implicit global variable in this scope which must be a
690 // script scope. The variable was introduced (possibly from an inner 697 // script scope. The variable was introduced (possibly from an inner
691 // scope) by a reference to an unresolved variable with no intervening 698 // scope) by a reference to an unresolved variable with no intervening
(...skipping 18 matching lines...) Expand all
710 // The variable corresponding to the 'new.target' value. 717 // The variable corresponding to the 'new.target' value.
711 Variable* new_target_var() { return new_target_; } 718 Variable* new_target_var() { return new_target_; }
712 719
713 // The variable holding the function literal for named function 720 // The variable holding the function literal for named function
714 // literals, or NULL. Only valid for function scopes. 721 // literals, or NULL. Only valid for function scopes.
715 Variable* function_var() const { 722 Variable* function_var() const {
716 DCHECK(is_function_scope()); 723 DCHECK(is_function_scope());
717 return function_; 724 return function_;
718 } 725 }
719 726
727 Variable* generator_object_var() const {
728 DCHECK(is_function_scope() || is_module_scope());
729 return generator_object_;
730 }
731
732 Variable* promise_var() const {
733 DCHECK(is_function_scope());
734 DCHECK(IsAsyncFunction(function_kind_));
735 return promise_;
736 }
737
720 // Parameters. The left-most parameter has index 0. 738 // Parameters. The left-most parameter has index 0.
721 // Only valid for function and module scopes. 739 // Only valid for function and module scopes.
722 Variable* parameter(int index) const { 740 Variable* parameter(int index) const {
723 DCHECK(is_function_scope() || is_module_scope()); 741 DCHECK(is_function_scope() || is_module_scope());
724 return params_[index]; 742 return params_[index];
725 } 743 }
726 744
727 // Returns the number of formal parameters, excluding a possible rest 745 // Returns the number of formal parameters, excluding a possible rest
728 // parameter. Examples: 746 // parameter. Examples:
729 // function foo(a, b) {} ==> 2 747 // function foo(a, b) {} ==> 2
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 // Convenience variable. 884 // Convenience variable.
867 Variable* receiver_; 885 Variable* receiver_;
868 // Function variable, if any; function scopes only. 886 // Function variable, if any; function scopes only.
869 Variable* function_; 887 Variable* function_;
870 // new.target variable, function scopes only. 888 // new.target variable, function scopes only.
871 Variable* new_target_; 889 Variable* new_target_;
872 // Convenience variable; function scopes only. 890 // Convenience variable; function scopes only.
873 Variable* arguments_; 891 Variable* arguments_;
874 // Convenience variable; Subclass constructor only 892 // Convenience variable; Subclass constructor only
875 Variable* this_function_; 893 Variable* this_function_;
894
895 // Generator object, if any; generator function scopes and module scopes only.
896 Variable* generator_object_;
897 // Promise, if any; async function scopes only.
898 Variable* promise_;
876 }; 899 };
877 900
878 class ModuleScope final : public DeclarationScope { 901 class ModuleScope final : public DeclarationScope {
879 public: 902 public:
880 ModuleScope(DeclarationScope* script_scope, 903 ModuleScope(DeclarationScope* script_scope,
881 AstValueFactory* ast_value_factory); 904 AstValueFactory* ast_value_factory);
882 905
883 // Deserialization. 906 // Deserialization.
884 // The generated ModuleDescriptor does not preserve all information. In 907 // The generated ModuleDescriptor does not preserve all information. In
885 // particular, its module_requests map will be empty because we no longer need 908 // particular, its module_requests map will be empty because we no longer need
(...skipping 11 matching lines...) Expand all
897 void AllocateModuleVariables(); 920 void AllocateModuleVariables();
898 921
899 private: 922 private:
900 ModuleDescriptor* module_descriptor_; 923 ModuleDescriptor* module_descriptor_;
901 }; 924 };
902 925
903 } // namespace internal 926 } // namespace internal
904 } // namespace v8 927 } // namespace v8
905 928
906 #endif // V8_AST_SCOPES_H_ 929 #endif // V8_AST_SCOPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698