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

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: 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
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 class ParameterKind {
arv (Not doing code reviews) 2015/04/10 15:08:48 Not sure we need a class for this. Why isn't an en
caitp (gmail) 2015/04/10 15:28:00 I find it more readable, and it should end up bein
caitp (gmail) 2015/04/10 15:56:49 Actually, clang-format isn't keen on this, and it
15 public:
16 enum Kind {
17 NonParameter = -1,
18 Normal,
19 Rest,
20 Optional
21 };
22
23 ParameterKind() : kind_(Normal) {}
24 ParameterKind(Kind k) : kind_(k) {}
25 ParameterKind(const ParameterKind& other) : kind_(other.kind_) {}
26
27 bool operator==(const ParameterKind& other) const {
28 return other.kind_ == kind_;
29 }
30 bool operator==(Kind k) const { return k == kind_; }
31
32 ParameterKind& operator=(const ParameterKind& other) {
33 kind_ = other.kind_;
34 return *this;
35 }
36 ParameterKind& operator=(Kind k) {
37 kind_ = k;
38 return *this;
39 }
40
41 bool isParameter() const { return kind_ != NonParameter; }
42 bool isNormalParameter() const { return kind_ == Normal; }
43 bool isRestParameter() const { return kind_ == Rest; }
44 bool isOptionalParameter() const { return kind_ == Optional; }
45
46 private:
47 Kind kind_;
48 };
49
14 // The AST refers to variables via VariableProxies - placeholders for the actual 50 // The AST refers to variables via VariableProxies - placeholders for the actual
15 // variables. Variables themselves are never directly referred to from the AST, 51 // variables. Variables themselves are never directly referred to from the AST,
16 // they are maintained by scopes, and referred to from VariableProxies and Slots 52 // they are maintained by scopes, and referred to from VariableProxies and Slots
17 // after binding and variable allocation. 53 // after binding and variable allocation.
18 54
19 class Variable: public ZoneObject { 55 class Variable: public ZoneObject {
20 public: 56 public:
21 enum Kind { NORMAL, FUNCTION, THIS, NEW_TARGET, ARGUMENTS }; 57 enum Kind { NORMAL, FUNCTION, THIS, NEW_TARGET, ARGUMENTS };
22 58
23 enum Location { 59 enum Location {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 176 }
141 177
142 bool has_strong_mode_reference() const { return has_strong_mode_reference_; } 178 bool has_strong_mode_reference() const { return has_strong_mode_reference_; }
143 int strong_mode_reference_start_position() const { 179 int strong_mode_reference_start_position() const {
144 return strong_mode_reference_start_position_; 180 return strong_mode_reference_start_position_;
145 } 181 }
146 int strong_mode_reference_end_position() const { 182 int strong_mode_reference_end_position() const {
147 return strong_mode_reference_end_position_; 183 return strong_mode_reference_end_position_;
148 } 184 }
149 185
186 inline void set_parameter_kind(ParameterKind& kind) {
187 // Don't specify ParameterKind multiple times
188 DCHECK(kind.isParameter() && !parameter_kind_.isParameter());
189 parameter_kind_ = kind;
190 }
191
192 inline const ParameterKind& parameter_kind() const {
193 // Only access for function parameters
194 DCHECK(parameter_kind_.isParameter());
195 return parameter_kind_;
196 }
197
198 bool isParameter() const { return parameter_kind_.isParameter(); }
199 bool isRestParameter() const { return parameter_kind_.isRestParameter(); }
200 bool isOptionalParameter() const {
201 return parameter_kind_.isOptionalParameter();
202 }
203
150 private: 204 private:
151 Scope* scope_; 205 Scope* scope_;
152 const AstRawString* name_; 206 const AstRawString* name_;
153 VariableMode mode_; 207 VariableMode mode_;
154 Kind kind_; 208 Kind kind_;
155 Location location_; 209 Location location_;
156 int index_; 210 int index_;
157 int initializer_position_; 211 int initializer_position_;
158 // Tracks whether the variable is bound to a VariableProxy which is in strong 212 // Tracks whether the variable is bound to a VariableProxy which is in strong
159 // mode, and if yes, the source location of the reference. 213 // mode, and if yes, the source location of the reference.
160 bool has_strong_mode_reference_; 214 bool has_strong_mode_reference_;
161 int strong_mode_reference_start_position_; 215 int strong_mode_reference_start_position_;
162 int strong_mode_reference_end_position_; 216 int strong_mode_reference_end_position_;
163 217
164 // If this field is set, this variable references the stored locally bound 218 // If this field is set, this variable references the stored locally bound
165 // variable, but it might be shadowed by variable bindings introduced by 219 // variable, but it might be shadowed by variable bindings introduced by
166 // sloppy 'eval' calls between the reference scope (inclusive) and the 220 // sloppy 'eval' calls between the reference scope (inclusive) and the
167 // binding scope (exclusive). 221 // binding scope (exclusive).
168 Variable* local_if_not_shadowed_; 222 Variable* local_if_not_shadowed_;
169 223
170 // Usage info. 224 // Usage info.
171 bool force_context_allocation_; // set by variable resolver 225 bool force_context_allocation_; // set by variable resolver
172 bool is_used_; 226 bool is_used_;
173 InitializationFlag initialization_flag_; 227 InitializationFlag initialization_flag_;
174 MaybeAssignedFlag maybe_assigned_; 228 MaybeAssignedFlag maybe_assigned_;
229 ParameterKind parameter_kind_;
175 }; 230 };
176 231
177 232
178 } } // namespace v8::internal 233 } } // namespace v8::internal
179 234
180 #endif // V8_VARIABLES_H_ 235 #endif // V8_VARIABLES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698