OLD | NEW |
---|---|
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_PARSING_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_H |
7 | 7 |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 | 274 |
275 // --------------------------------------------------------------------------- | 275 // --------------------------------------------------------------------------- |
276 // ScopeState and its subclasses implement the parser's scope stack. | 276 // ScopeState and its subclasses implement the parser's scope stack. |
277 // ScopeState keeps track of the current scope, and the outer ScopeState. The | 277 // ScopeState keeps track of the current scope, and the outer ScopeState. The |
278 // parser's scope_state_ points to the top ScopeState. ScopeState's | 278 // parser's scope_state_ points to the top ScopeState. ScopeState's |
279 // constructor push on the scope stack and the destructors pop. BlockState and | 279 // constructor push on the scope stack and the destructors pop. BlockState and |
280 // FunctionState are used to hold additional per-block and per-function state. | 280 // FunctionState are used to hold additional per-block and per-function state. |
281 class ScopeState BASE_EMBEDDED { | 281 class ScopeState BASE_EMBEDDED { |
282 public: | 282 public: |
283 V8_INLINE Scope* scope() const { return scope_; } | 283 V8_INLINE Scope* scope() const { return scope_; } |
284 Zone* zone() const { return scope_->zone(); } | |
284 | 285 |
285 protected: | 286 protected: |
286 ScopeState(ScopeState** scope_stack, Scope* scope) | 287 ScopeState(ScopeState** scope_stack, Scope* scope) |
287 : scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) { | 288 : scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) { |
288 *scope_stack = this; | 289 *scope_stack = this; |
289 } | 290 } |
290 ~ScopeState() { *scope_stack_ = outer_scope_; } | 291 ~ScopeState() { *scope_stack_ = outer_scope_; } |
291 | 292 |
292 Zone* zone() const { return scope_->zone(); } | |
293 | |
294 private: | 293 private: |
295 ScopeState** scope_stack_; | 294 ScopeState** const scope_stack_; |
296 ScopeState* outer_scope_; | 295 ScopeState* const outer_scope_; |
297 Scope* scope_; | 296 Scope* scope_; |
298 }; | 297 }; |
299 | 298 |
300 class BlockState final : public ScopeState { | 299 class BlockState final : public ScopeState { |
adamk
2016/07/21 17:48:05
Can you add a comment here talking about the two c
Toon Verwaest
2016/07/22 11:02:53
Done.
| |
301 public: | 300 public: |
302 BlockState(ScopeState** scope_stack, Scope* scope) | 301 BlockState(ScopeState** scope_stack, Scope* scope) |
303 : ScopeState(scope_stack, scope) {} | 302 : ScopeState(scope_stack, scope) {} |
303 | |
304 explicit BlockState(ScopeState** scope_stack) | |
305 : ScopeState(scope_stack, NewScope(*scope_stack)) {} | |
306 | |
307 void SetNonlinear() { this->scope()->SetNonlinear(); } | |
adamk
2016/07/21 17:48:05
These "this->" prefixes shouldn't needed here and
Toon Verwaest
2016/07/22 11:02:53
They are because the outer class is a templatized
| |
308 void set_start_position(int pos) { this->scope()->set_start_position(pos); } | |
309 void set_end_position(int pos) { this->scope()->set_end_position(pos); } | |
310 void set_is_hidden() { this->scope()->set_is_hidden(); } | |
311 Scope* FinalizedBlockScope() const { | |
312 return this->scope()->FinalizeBlockScope(); | |
313 } | |
314 LanguageMode language_mode() const { | |
315 return this->scope()->language_mode(); | |
316 } | |
317 | |
318 private: | |
319 Scope* NewScope(ScopeState* state) { | |
adamk
2016/07/21 17:48:05
outer_state or parent_state would be clearer here
Toon Verwaest
2016/07/22 11:02:53
Done.
| |
320 Scope* parent = state->scope(); | |
321 Zone* zone = state->zone(); | |
322 return new (zone) Scope(zone, parent, BLOCK_SCOPE, kNormalFunction); | |
323 } | |
304 }; | 324 }; |
305 | 325 |
306 struct DestructuringAssignment { | 326 struct DestructuringAssignment { |
307 public: | 327 public: |
308 DestructuringAssignment(ExpressionT expression, Scope* scope) | 328 DestructuringAssignment(ExpressionT expression, Scope* scope) |
309 : assignment(expression), scope(scope) {} | 329 : assignment(expression), scope(scope) {} |
310 | 330 |
311 ExpressionT assignment; | 331 ExpressionT assignment; |
312 Scope* scope; | 332 Scope* scope; |
313 }; | 333 }; |
(...skipping 3375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3689 has_seen_constructor_ = true; | 3709 has_seen_constructor_ = true; |
3690 return; | 3710 return; |
3691 } | 3711 } |
3692 } | 3712 } |
3693 | 3713 |
3694 | 3714 |
3695 } // namespace internal | 3715 } // namespace internal |
3696 } // namespace v8 | 3716 } // namespace v8 |
3697 | 3717 |
3698 #endif // V8_PARSING_PARSER_BASE_H | 3718 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |