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

Side by Side Diff: src/scopes.h

Issue 1163853002: Revert of [es6] implement default parameters via desugaring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 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/preparser.cc ('k') | src/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_SCOPES_H_ 5 #ifndef V8_SCOPES_H_
6 #define V8_SCOPES_H_ 6 #define V8_SCOPES_H_
7 7
8 #include "src/ast.h" 8 #include "src/ast.h"
9 #include "src/pending-compilation-error-handler.h" 9 #include "src/pending-compilation-error-handler.h"
10 #include "src/zone.h" 10 #include "src/zone.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // outer scope. Only possible for function scopes; at most one variable. 119 // outer scope. Only possible for function scopes; at most one variable.
120 void DeclareFunctionVar(VariableDeclaration* declaration) { 120 void DeclareFunctionVar(VariableDeclaration* declaration) {
121 DCHECK(is_function_scope()); 121 DCHECK(is_function_scope());
122 function_ = declaration; 122 function_ = declaration;
123 } 123 }
124 124
125 // Declare a parameter in this scope. When there are duplicated 125 // Declare a parameter in this scope. When there are duplicated
126 // parameters the rightmost one 'wins'. However, the implementation 126 // parameters the rightmost one 'wins'. However, the implementation
127 // expects all parameters to be declared and from left to right. 127 // expects all parameters to be declared and from left to right.
128 Variable* DeclareParameter(const AstRawString* name, VariableMode mode, 128 Variable* DeclareParameter(const AstRawString* name, VariableMode mode,
129 bool is_rest, bool* is_duplicate, int pos); 129 bool is_rest, bool* is_duplicate);
130 130
131 // Declare a local variable in this scope. If the variable has been 131 // Declare a local variable in this scope. If the variable has been
132 // declared before, the previously declared variable is returned. 132 // declared before, the previously declared variable is returned.
133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode, 133 Variable* DeclareLocal(const AstRawString* name, VariableMode mode,
134 InitializationFlag init_flag, Variable::Kind kind, 134 InitializationFlag init_flag, Variable::Kind kind,
135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned, 135 MaybeAssignedFlag maybe_assigned_flag = kNotAssigned,
136 int declaration_group_start = -1); 136 int declaration_group_start = -1);
137 137
138 // Declare an implicit global variable in this scope which must be a 138 // Declare an implicit global variable in this scope which must be a
139 // script scope. The variable was introduced (possibly from an inner 139 // script scope. The variable was introduced (possibly from an inner
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // for printing and cannot be used to find the variable. In particular, 175 // for printing and cannot be used to find the variable. In particular,
176 // the only way to get hold of the temporary is by keeping the Variable* 176 // the only way to get hold of the temporary is by keeping the Variable*
177 // around. The name should not clash with a legitimate variable names. 177 // around. The name should not clash with a legitimate variable names.
178 Variable* NewTemporary(const AstRawString* name); 178 Variable* NewTemporary(const AstRawString* name);
179 179
180 // Adds the specific declaration node to the list of declarations in 180 // Adds the specific declaration node to the list of declarations in
181 // this scope. The declarations are processed as part of entering 181 // this scope. The declarations are processed as part of entering
182 // the scope; see codegen.cc:ProcessDeclarations. 182 // the scope; see codegen.cc:ProcessDeclarations.
183 void AddDeclaration(Declaration* declaration); 183 void AddDeclaration(Declaration* declaration);
184 184
185 // Formal parameters may be re-declared as lexical declarations in order to
186 // support TDZ semantics specified in ECMAScript 6.
187 void UndeclareParametersForExpressions();
188
189 // --------------------------------------------------------------------------- 185 // ---------------------------------------------------------------------------
190 // Illegal redeclaration support. 186 // Illegal redeclaration support.
191 187
192 // Set an expression node that will be executed when the scope is 188 // Set an expression node that will be executed when the scope is
193 // entered. We only keep track of one illegal redeclaration node per 189 // entered. We only keep track of one illegal redeclaration node per
194 // scope - the first one - so if you try to set it multiple times 190 // scope - the first one - so if you try to set it multiple times
195 // the additional requests will be silently ignored. 191 // the additional requests will be silently ignored.
196 void SetIllegalRedeclaration(Expression* expression); 192 void SetIllegalRedeclaration(Expression* expression);
197 193
198 // Visit the illegal redeclaration expression. Do not call if the 194 // Visit the illegal redeclaration expression. Do not call if the
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 return function_; 366 return function_;
371 } 367 }
372 368
373 // Parameters. The left-most parameter has index 0. 369 // Parameters. The left-most parameter has index 0.
374 // Only valid for function scopes. 370 // Only valid for function scopes.
375 Variable* parameter(int index) const { 371 Variable* parameter(int index) const {
376 DCHECK(is_function_scope()); 372 DCHECK(is_function_scope());
377 return params_[index]; 373 return params_[index];
378 } 374 }
379 375
380 // TODO(caitp): This probably won't work when BindingPatterns are supported
381 // in function parameters. Need a better way.
382 int parameter_position(int index) const {
383 DCHECK(is_function_scope());
384 return param_positions_[index];
385 }
386
387 // Returns the default function arity --- does not include rest parameters. 376 // Returns the default function arity --- does not include rest parameters.
388 int default_function_length() const { 377 int default_function_length() const {
389 int count = params_.length(); 378 int count = params_.length();
390 if (rest_index_ >= 0) { 379 if (rest_index_ >= 0) {
391 DCHECK(count > 0); 380 DCHECK(count > 0);
392 DCHECK(is_function_scope()); 381 DCHECK(is_function_scope());
393 --count; 382 --count;
394 } 383 }
395 return count; 384 return count;
396 } 385 }
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // All user-declared variables (incl. parameters). For script scopes 556 // All user-declared variables (incl. parameters). For script scopes
568 // variables may be implicitly 'declared' by being used (possibly in 557 // variables may be implicitly 'declared' by being used (possibly in
569 // an inner scope) with no intervening with statements or eval calls. 558 // an inner scope) with no intervening with statements or eval calls.
570 VariableMap variables_; 559 VariableMap variables_;
571 // Compiler-allocated (user-invisible) internals. 560 // Compiler-allocated (user-invisible) internals.
572 ZoneList<Variable*> internals_; 561 ZoneList<Variable*> internals_;
573 // Compiler-allocated (user-invisible) temporaries. 562 // Compiler-allocated (user-invisible) temporaries.
574 ZoneList<Variable*> temps_; 563 ZoneList<Variable*> temps_;
575 // Parameter list in source order. 564 // Parameter list in source order.
576 ZoneList<Variable*> params_; 565 ZoneList<Variable*> params_;
577 ZoneList<int> param_positions_;
578 // Variables that must be looked up dynamically. 566 // Variables that must be looked up dynamically.
579 DynamicScopePart* dynamics_; 567 DynamicScopePart* dynamics_;
580 // Unresolved variables referred to from this scope. 568 // Unresolved variables referred to from this scope.
581 ZoneList<VariableProxy*> unresolved_; 569 ZoneList<VariableProxy*> unresolved_;
582 // Declarations. 570 // Declarations.
583 ZoneList<Declaration*> decls_; 571 ZoneList<Declaration*> decls_;
584 // Convenience variable. 572 // Convenience variable.
585 Variable* receiver_; 573 Variable* receiver_;
586 // Function variable, if any; function scopes only. 574 // Function variable, if any; function scopes only.
587 VariableDeclaration* function_; 575 VariableDeclaration* function_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // The number of modules (including nested ones). 630 // The number of modules (including nested ones).
643 int num_modules_; 631 int num_modules_;
644 632
645 // For module scopes, the host scope's internal variable binding this module. 633 // For module scopes, the host scope's internal variable binding this module.
646 Variable* module_var_; 634 Variable* module_var_;
647 635
648 // Rest parameter 636 // Rest parameter
649 Variable* rest_parameter_; 637 Variable* rest_parameter_;
650 int rest_index_; 638 int rest_index_;
651 639
652 bool has_parameter_expressions_;
653
654 // Serialized scope info support. 640 // Serialized scope info support.
655 Handle<ScopeInfo> scope_info_; 641 Handle<ScopeInfo> scope_info_;
656 bool already_resolved() { return already_resolved_; } 642 bool already_resolved() { return already_resolved_; }
657 643
658 // Create a non-local variable with a given name. 644 // Create a non-local variable with a given name.
659 // These variables are looked up dynamically at runtime. 645 // These variables are looked up dynamically at runtime.
660 Variable* NonLocal(const AstRawString* name, VariableMode mode); 646 Variable* NonLocal(const AstRawString* name, VariableMode mode);
661 647
662 // Variable resolution. 648 // Variable resolution.
663 // Possible results of a recursive variable lookup telling if and how a 649 // Possible results of a recursive variable lookup telling if and how a
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 PendingCompilationErrorHandler pending_error_handler_; 765 PendingCompilationErrorHandler pending_error_handler_;
780 766
781 // For tracking which classes are declared consecutively. Needed for strong 767 // For tracking which classes are declared consecutively. Needed for strong
782 // mode. 768 // mode.
783 int class_declaration_group_start_; 769 int class_declaration_group_start_;
784 }; 770 };
785 771
786 } } // namespace v8::internal 772 } } // namespace v8::internal
787 773
788 #endif // V8_SCOPES_H_ 774 #endif // V8_SCOPES_H_
OLDNEW
« no previous file with comments | « src/preparser.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698