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

Side by Side Diff: src/scopes.h

Issue 1127063003: [es6] implement default parameters via desugaring (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Don't AllocateParameter() if hasParameterExpressions is true Created 5 years, 7 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_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); 129 bool is_rest, bool* is_duplicate, int pos);
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
185 // --------------------------------------------------------------------------- 189 // ---------------------------------------------------------------------------
186 // Illegal redeclaration support. 190 // Illegal redeclaration support.
187 191
188 // Set an expression node that will be executed when the scope is 192 // Set an expression node that will be executed when the scope is
189 // entered. We only keep track of one illegal redeclaration node per 193 // entered. We only keep track of one illegal redeclaration node per
190 // scope - the first one - so if you try to set it multiple times 194 // scope - the first one - so if you try to set it multiple times
191 // the additional requests will be silently ignored. 195 // the additional requests will be silently ignored.
192 void SetIllegalRedeclaration(Expression* expression); 196 void SetIllegalRedeclaration(Expression* expression);
193 197
194 // Visit the illegal redeclaration expression. Do not call if the 198 // Visit the illegal redeclaration expression. Do not call if the
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 365
362 // The variable holding the function literal for named function 366 // The variable holding the function literal for named function
363 // literals, or NULL. Only valid for function scopes. 367 // literals, or NULL. Only valid for function scopes.
364 VariableDeclaration* function() const { 368 VariableDeclaration* function() const {
365 DCHECK(is_function_scope()); 369 DCHECK(is_function_scope());
366 return function_; 370 return function_;
367 } 371 }
368 372
369 // Parameters. The left-most parameter has index 0. 373 // Parameters. The left-most parameter has index 0.
370 // Only valid for function scopes. 374 // Only valid for function scopes.
371 Variable* parameter(int index) const { 375 Variable* parameter(int index) const {
adamk 2015/05/26 20:34:02 Is this called anywhere (besides your new caller i
caitp (gmail) 2015/05/26 20:59:11 Yes, it's called in function prologues to move par
adamk 2015/05/26 21:38:07 Thanks for the pointer, I see how my git grep miss
372 DCHECK(is_function_scope()); 376 DCHECK(is_function_scope());
373 return params_[index]; 377 return params_[index];
374 } 378 }
375 379
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
376 // Returns the default function arity --- does not include rest parameters. 387 // Returns the default function arity --- does not include rest parameters.
377 int default_function_length() const { 388 int default_function_length() const {
378 int count = params_.length(); 389 int count = params_.length();
379 if (rest_index_ >= 0) { 390 if (rest_index_ >= 0) {
380 DCHECK(count > 0); 391 DCHECK(count > 0);
381 DCHECK(is_function_scope()); 392 DCHECK(is_function_scope());
382 --count; 393 --count;
383 } 394 }
384 return count; 395 return count;
385 } 396 }
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 // All user-declared variables (incl. parameters). For script scopes 557 // All user-declared variables (incl. parameters). For script scopes
547 // variables may be implicitly 'declared' by being used (possibly in 558 // variables may be implicitly 'declared' by being used (possibly in
548 // an inner scope) with no intervening with statements or eval calls. 559 // an inner scope) with no intervening with statements or eval calls.
549 VariableMap variables_; 560 VariableMap variables_;
550 // Compiler-allocated (user-invisible) internals. 561 // Compiler-allocated (user-invisible) internals.
551 ZoneList<Variable*> internals_; 562 ZoneList<Variable*> internals_;
552 // Compiler-allocated (user-invisible) temporaries. 563 // Compiler-allocated (user-invisible) temporaries.
553 ZoneList<Variable*> temps_; 564 ZoneList<Variable*> temps_;
554 // Parameter list in source order. 565 // Parameter list in source order.
555 ZoneList<Variable*> params_; 566 ZoneList<Variable*> params_;
567 ZoneList<int> param_positions_;
556 // Variables that must be looked up dynamically. 568 // Variables that must be looked up dynamically.
557 DynamicScopePart* dynamics_; 569 DynamicScopePart* dynamics_;
558 // Unresolved variables referred to from this scope. 570 // Unresolved variables referred to from this scope.
559 ZoneList<VariableProxy*> unresolved_; 571 ZoneList<VariableProxy*> unresolved_;
560 // Declarations. 572 // Declarations.
561 ZoneList<Declaration*> decls_; 573 ZoneList<Declaration*> decls_;
562 // Convenience variable. 574 // Convenience variable.
563 Variable* receiver_; 575 Variable* receiver_;
564 // Function variable, if any; function scopes only. 576 // Function variable, if any; function scopes only.
565 VariableDeclaration* function_; 577 VariableDeclaration* function_;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 // The number of modules (including nested ones). 630 // The number of modules (including nested ones).
619 int num_modules_; 631 int num_modules_;
620 632
621 // 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.
622 Variable* module_var_; 634 Variable* module_var_;
623 635
624 // Rest parameter 636 // Rest parameter
625 Variable* rest_parameter_; 637 Variable* rest_parameter_;
626 int rest_index_; 638 int rest_index_;
627 639
640 bool has_parameter_expressions_;
641
628 // Serialized scope info support. 642 // Serialized scope info support.
629 Handle<ScopeInfo> scope_info_; 643 Handle<ScopeInfo> scope_info_;
630 bool already_resolved() { return already_resolved_; } 644 bool already_resolved() { return already_resolved_; }
631 645
632 // Create a non-local variable with a given name. 646 // Create a non-local variable with a given name.
633 // These variables are looked up dynamically at runtime. 647 // These variables are looked up dynamically at runtime.
634 Variable* NonLocal(const AstRawString* name, VariableMode mode); 648 Variable* NonLocal(const AstRawString* name, VariableMode mode);
635 649
636 // Variable resolution. 650 // Variable resolution.
637 // Possible results of a recursive variable lookup telling if and how a 651 // Possible results of a recursive variable lookup telling if and how a
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 PendingCompilationErrorHandler pending_error_handler_; 767 PendingCompilationErrorHandler pending_error_handler_;
754 768
755 // For tracking which classes are declared consecutively. Needed for strong 769 // For tracking which classes are declared consecutively. Needed for strong
756 // mode. 770 // mode.
757 int class_declaration_group_start_; 771 int class_declaration_group_start_;
758 }; 772 };
759 773
760 } } // namespace v8::internal 774 } } // namespace v8::internal
761 775
762 #endif // V8_SCOPES_H_ 776 #endif // V8_SCOPES_H_
OLDNEW
« src/parser.cc ('K') | « src/preparser.cc ('k') | src/scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698