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

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: 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 int pos, bool is_rest, bool* is_duplicate);
arv (Not doing code reviews) 2015/05/06 20:32:38 keep pos at end for consistency
caitp (gmail) 2015/05/06 20:42:55 Acknowledged.
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
140 // scope) by a reference to an unresolved variable with no intervening 140 // scope) by a reference to an unresolved variable with no intervening
141 // with statements or eval calls. 141 // with statements or eval calls.
142 Variable* DeclareDynamicGlobal(const AstRawString* name); 142 Variable* DeclareDynamicGlobal(const AstRawString* name);
143 143
144 void ShadowParametersForExpressions();
145
144 // Create a new unresolved variable. 146 // Create a new unresolved variable.
145 VariableProxy* NewUnresolved(AstNodeFactory* factory, 147 VariableProxy* NewUnresolved(AstNodeFactory* factory,
146 const AstRawString* name, 148 const AstRawString* name,
147 int start_position = RelocInfo::kNoPosition, 149 int start_position = RelocInfo::kNoPosition,
148 int end_position = RelocInfo::kNoPosition) { 150 int end_position = RelocInfo::kNoPosition) {
149 // Note that we must not share the unresolved variables with 151 // Note that we must not share the unresolved variables with
150 // the same name because they may be removed selectively via 152 // the same name because they may be removed selectively via
151 // RemoveUnresolved(). 153 // RemoveUnresolved().
152 DCHECK(!already_resolved()); 154 DCHECK(!already_resolved());
153 VariableProxy* proxy = factory->NewVariableProxy( 155 VariableProxy* proxy = factory->NewVariableProxy(
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return function_; 360 return function_;
359 } 361 }
360 362
361 // Parameters. The left-most parameter has index 0. 363 // Parameters. The left-most parameter has index 0.
362 // Only valid for function scopes. 364 // Only valid for function scopes.
363 Variable* parameter(int index) const { 365 Variable* parameter(int index) const {
364 DCHECK(is_function_scope()); 366 DCHECK(is_function_scope());
365 return params_[index]; 367 return params_[index];
366 } 368 }
367 369
370 int parameter_position(int index) const {
371 DCHECK(is_function_scope());
372 return param_positions_[index];
373 }
374
368 // Returns the default function arity --- does not include rest parameters. 375 // Returns the default function arity --- does not include rest parameters.
369 int default_function_length() const { 376 int default_function_length() const {
370 int count = params_.length(); 377 int count = params_.length();
371 if (rest_index_ >= 0) { 378 if (rest_index_ >= 0) {
372 DCHECK(count > 0); 379 DCHECK(count > 0);
373 DCHECK(is_function_scope()); 380 DCHECK(is_function_scope());
374 --count; 381 --count;
375 } 382 }
376 return count; 383 return count;
377 } 384 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 // All user-declared variables (incl. parameters). For script scopes 544 // All user-declared variables (incl. parameters). For script scopes
538 // variables may be implicitly 'declared' by being used (possibly in 545 // variables may be implicitly 'declared' by being used (possibly in
539 // an inner scope) with no intervening with statements or eval calls. 546 // an inner scope) with no intervening with statements or eval calls.
540 VariableMap variables_; 547 VariableMap variables_;
541 // Compiler-allocated (user-invisible) internals. 548 // Compiler-allocated (user-invisible) internals.
542 ZoneList<Variable*> internals_; 549 ZoneList<Variable*> internals_;
543 // Compiler-allocated (user-invisible) temporaries. 550 // Compiler-allocated (user-invisible) temporaries.
544 ZoneList<Variable*> temps_; 551 ZoneList<Variable*> temps_;
545 // Parameter list in source order. 552 // Parameter list in source order.
546 ZoneList<Variable*> params_; 553 ZoneList<Variable*> params_;
554 ZoneList<int> param_positions_;
547 // Variables that must be looked up dynamically. 555 // Variables that must be looked up dynamically.
548 DynamicScopePart* dynamics_; 556 DynamicScopePart* dynamics_;
549 // Unresolved variables referred to from this scope. 557 // Unresolved variables referred to from this scope.
550 ZoneList<VariableProxy*> unresolved_; 558 ZoneList<VariableProxy*> unresolved_;
551 // Declarations. 559 // Declarations.
552 ZoneList<Declaration*> decls_; 560 ZoneList<Declaration*> decls_;
553 // Convenience variable. 561 // Convenience variable.
554 Variable* receiver_; 562 Variable* receiver_;
555 // Function variable, if any; function scopes only. 563 // Function variable, if any; function scopes only.
556 VariableDeclaration* function_; 564 VariableDeclaration* function_;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 PendingCompilationErrorHandler pending_error_handler_; 753 PendingCompilationErrorHandler pending_error_handler_;
746 754
747 // For tracking which classes are declared consecutively. Needed for strong 755 // For tracking which classes are declared consecutively. Needed for strong
748 // mode. 756 // mode.
749 int class_declaration_group_start_; 757 int class_declaration_group_start_;
750 }; 758 };
751 759
752 } } // namespace v8::internal 760 } } // namespace v8::internal
753 761
754 #endif // V8_SCOPES_H_ 762 #endif // V8_SCOPES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698