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

Side by Side Diff: src/parsing/parser-base.h

Issue 2166843003: Allocate block scopes in block states when possible (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase Created 4 years, 4 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/parsing/parser.cc ('k') | src/parsing/preparser.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 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 // --------------------------------------------------------------------------- 277 // ---------------------------------------------------------------------------
278 // ScopeState and its subclasses implement the parser's scope stack. 278 // ScopeState and its subclasses implement the parser's scope stack.
279 // ScopeState keeps track of the current scope, and the outer ScopeState. The 279 // ScopeState keeps track of the current scope, and the outer ScopeState. The
280 // parser's scope_state_ points to the top ScopeState. ScopeState's 280 // parser's scope_state_ points to the top ScopeState. ScopeState's
281 // constructor push on the scope stack and the destructors pop. BlockState and 281 // constructor push on the scope stack and the destructors pop. BlockState and
282 // FunctionState are used to hold additional per-block and per-function state. 282 // FunctionState are used to hold additional per-block and per-function state.
283 class ScopeState BASE_EMBEDDED { 283 class ScopeState BASE_EMBEDDED {
284 public: 284 public:
285 V8_INLINE Scope* scope() const { return scope_; } 285 V8_INLINE Scope* scope() const { return scope_; }
286 Zone* zone() const { return scope_->zone(); }
286 287
287 protected: 288 protected:
288 ScopeState(ScopeState** scope_stack, Scope* scope) 289 ScopeState(ScopeState** scope_stack, Scope* scope)
289 : scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) { 290 : scope_stack_(scope_stack), outer_scope_(*scope_stack), scope_(scope) {
290 *scope_stack = this; 291 *scope_stack = this;
291 } 292 }
292 ~ScopeState() { *scope_stack_ = outer_scope_; } 293 ~ScopeState() { *scope_stack_ = outer_scope_; }
293 294
294 Zone* zone() const { return scope_->zone(); }
295
296 private: 295 private:
297 ScopeState** scope_stack_; 296 ScopeState** const scope_stack_;
298 ScopeState* outer_scope_; 297 ScopeState* const outer_scope_;
299 Scope* scope_; 298 Scope* scope_;
300 }; 299 };
301 300
302 class BlockState final : public ScopeState { 301 class BlockState final : public ScopeState {
303 public: 302 public:
304 BlockState(ScopeState** scope_stack, Scope* scope) 303 BlockState(ScopeState** scope_stack, Scope* scope)
305 : ScopeState(scope_stack, scope) {} 304 : ScopeState(scope_stack, scope) {}
305
306 // BlockState(ScopeState**) automatically manages Scope(BLOCK_SCOPE)
307 // allocation.
308 // TODO(verwaest): Move to LazyBlockState class that only allocates the
309 // scope when needed.
310 explicit BlockState(ScopeState** scope_stack)
311 : ScopeState(scope_stack, NewScope(*scope_stack)) {}
312
313 void SetNonlinear() { this->scope()->SetNonlinear(); }
314 void set_start_position(int pos) { this->scope()->set_start_position(pos); }
315 void set_end_position(int pos) { this->scope()->set_end_position(pos); }
316 void set_is_hidden() { this->scope()->set_is_hidden(); }
317 Scope* FinalizedBlockScope() const {
318 return this->scope()->FinalizeBlockScope();
319 }
320 LanguageMode language_mode() const {
321 return this->scope()->language_mode();
322 }
323
324 private:
325 Scope* NewScope(ScopeState* outer_state) {
326 Scope* parent = outer_state->scope();
327 Zone* zone = outer_state->zone();
328 return new (zone) Scope(zone, parent, BLOCK_SCOPE, kNormalFunction);
329 }
306 }; 330 };
307 331
308 struct DestructuringAssignment { 332 struct DestructuringAssignment {
309 public: 333 public:
310 DestructuringAssignment(ExpressionT expression, Scope* scope) 334 DestructuringAssignment(ExpressionT expression, Scope* scope)
311 : assignment(expression), scope(scope) {} 335 : assignment(expression), scope(scope) {}
312 336
313 ExpressionT assignment; 337 ExpressionT assignment;
314 Scope* scope; 338 Scope* scope;
315 }; 339 };
(...skipping 3337 matching lines...) Expand 10 before | Expand all | Expand 10 after
3653 has_seen_constructor_ = true; 3677 has_seen_constructor_ = true;
3654 return; 3678 return;
3655 } 3679 }
3656 } 3680 }
3657 3681
3658 3682
3659 } // namespace internal 3683 } // namespace internal
3660 } // namespace v8 3684 } // namespace v8
3661 3685
3662 #endif // V8_PARSING_PARSER_BASE_H 3686 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698