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

Side by Side Diff: src/variables.h

Issue 1053773006: [es6] implement default/optional parameters (WIP / comments) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Experimental not-quite-TDZ support Created 5 years, 8 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/scopes.cc ('k') | src/variables.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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_VARIABLES_H_ 5 #ifndef V8_VARIABLES_H_
6 #define V8_VARIABLES_H_ 6 #define V8_VARIABLES_H_
7 7
8 #include "src/ast-value-factory.h" 8 #include "src/ast-value-factory.h"
9 #include "src/zone.h" 9 #include "src/zone.h"
10 10
11 namespace v8 { 11 namespace v8 {
12 namespace internal { 12 namespace internal {
13 13
14 enum ParameterKind {
15 NotAParameter = -1,
16 NormalParameter,
17 RestParameter,
18 OptionalParameter
19 };
20
14 // The AST refers to variables via VariableProxies - placeholders for the actual 21 // The AST refers to variables via VariableProxies - placeholders for the actual
15 // variables. Variables themselves are never directly referred to from the AST, 22 // variables. Variables themselves are never directly referred to from the AST,
16 // they are maintained by scopes, and referred to from VariableProxies and Slots 23 // they are maintained by scopes, and referred to from VariableProxies and Slots
17 // after binding and variable allocation. 24 // after binding and variable allocation.
18 25
19 class Variable: public ZoneObject { 26 class Variable: public ZoneObject {
20 public: 27 public:
21 enum Kind { NORMAL, FUNCTION, THIS, NEW_TARGET, ARGUMENTS }; 28 enum Kind { NORMAL, FUNCTION, THIS, NEW_TARGET, ARGUMENTS };
22 29
23 enum Location { 30 enum Location {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 147 }
141 148
142 bool has_strong_mode_reference() const { return has_strong_mode_reference_; } 149 bool has_strong_mode_reference() const { return has_strong_mode_reference_; }
143 int strong_mode_reference_start_position() const { 150 int strong_mode_reference_start_position() const {
144 return strong_mode_reference_start_position_; 151 return strong_mode_reference_start_position_;
145 } 152 }
146 int strong_mode_reference_end_position() const { 153 int strong_mode_reference_end_position() const {
147 return strong_mode_reference_end_position_; 154 return strong_mode_reference_end_position_;
148 } 155 }
149 156
157 inline void set_parameter_kind(ParameterKind kind) {
158 // Don't specify ParameterKind multiple times
159 DCHECK(kind != NotAParameter && !isParameter());
160 parameter_kind_ = kind;
161 }
162
163 inline const ParameterKind& parameter_kind() const {
164 // Only access for function parameters
165 DCHECK(isParameter());
166 return parameter_kind_;
167 }
168
169 bool isParameter() const { return parameter_kind_ != NotAParameter; }
170 bool isRestParameter() const { return parameter_kind_ == RestParameter; }
171 bool isOptionalParameter() const {
172 return parameter_kind_ == OptionalParameter;
173 }
174
150 private: 175 private:
151 Scope* scope_; 176 Scope* scope_;
152 const AstRawString* name_; 177 const AstRawString* name_;
153 VariableMode mode_; 178 VariableMode mode_;
154 Kind kind_; 179 Kind kind_;
155 Location location_; 180 Location location_;
156 int index_; 181 int index_;
157 int initializer_position_; 182 int initializer_position_;
158 // Tracks whether the variable is bound to a VariableProxy which is in strong 183 // Tracks whether the variable is bound to a VariableProxy which is in strong
159 // mode, and if yes, the source location of the reference. 184 // mode, and if yes, the source location of the reference.
160 bool has_strong_mode_reference_; 185 bool has_strong_mode_reference_;
161 int strong_mode_reference_start_position_; 186 int strong_mode_reference_start_position_;
162 int strong_mode_reference_end_position_; 187 int strong_mode_reference_end_position_;
163 188
164 // If this field is set, this variable references the stored locally bound 189 // If this field is set, this variable references the stored locally bound
165 // variable, but it might be shadowed by variable bindings introduced by 190 // variable, but it might be shadowed by variable bindings introduced by
166 // sloppy 'eval' calls between the reference scope (inclusive) and the 191 // sloppy 'eval' calls between the reference scope (inclusive) and the
167 // binding scope (exclusive). 192 // binding scope (exclusive).
168 Variable* local_if_not_shadowed_; 193 Variable* local_if_not_shadowed_;
169 194
170 // Usage info. 195 // Usage info.
171 bool force_context_allocation_; // set by variable resolver 196 bool force_context_allocation_; // set by variable resolver
172 bool is_used_; 197 bool is_used_;
173 InitializationFlag initialization_flag_; 198 InitializationFlag initialization_flag_;
174 MaybeAssignedFlag maybe_assigned_; 199 MaybeAssignedFlag maybe_assigned_;
200 ParameterKind parameter_kind_;
175 }; 201 };
176 202
177 203
178 } } // namespace v8::internal 204 } } // namespace v8::internal
179 205
180 #endif // V8_VARIABLES_H_ 206 #endif // V8_VARIABLES_H_
OLDNEW
« no previous file with comments | « src/scopes.cc ('k') | src/variables.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698