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

Side by Side Diff: src/ast/ast.h

Issue 2223843002: [ast][parsing] Variable declaration cleanups. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Use DefaultInitializationFlag in more places. 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 | « no previous file | src/ast/ast.cc » ('j') | src/parsing/parser.cc » ('J')
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_AST_AST_H_ 5 #ifndef V8_AST_AST_H_
6 #define V8_AST_AST_H_ 6 #define V8_AST_AST_H_
7 7
8 #include "src/ast/ast-value-factory.h" 8 #include "src/ast/ast-value-factory.h"
9 #include "src/ast/modules.h" 9 #include "src/ast/modules.h"
10 #include "src/ast/variables.h" 10 #include "src/ast/variables.h"
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 VariableProxy* result_; 490 VariableProxy* result_;
491 FunctionLiteral* represented_function_; 491 FunctionLiteral* represented_function_;
492 }; 492 };
493 493
494 494
495 class Declaration : public AstNode { 495 class Declaration : public AstNode {
496 public: 496 public:
497 VariableProxy* proxy() const { return proxy_; } 497 VariableProxy* proxy() const { return proxy_; }
498 VariableMode mode() const { return mode_; } 498 VariableMode mode() const { return mode_; }
499 Scope* scope() const { return scope_; } 499 Scope* scope() const { return scope_; }
500 InitializationFlag initialization() const;
501 500
502 protected: 501 protected:
503 Declaration(VariableProxy* proxy, VariableMode mode, Scope* scope, int pos, 502 Declaration(VariableProxy* proxy, VariableMode mode, Scope* scope, int pos,
504 NodeType type) 503 NodeType type)
505 : AstNode(pos, type), mode_(mode), proxy_(proxy), scope_(scope) { 504 : AstNode(pos, type), mode_(mode), proxy_(proxy), scope_(scope) {
506 DCHECK(IsDeclaredVariableMode(mode)); 505 DCHECK(IsDeclaredVariableMode(mode));
507 } 506 }
508 507
509 private: 508 private:
510 VariableMode mode_; 509 VariableMode mode_;
511 VariableProxy* proxy_; 510 VariableProxy* proxy_;
512 511
513 // Nested scope from which the declaration originated. 512 // Nested scope from which the declaration originated.
514 Scope* scope_; 513 Scope* scope_;
515 }; 514 };
516 515
517 516
518 class VariableDeclaration final : public Declaration { 517 class VariableDeclaration final : public Declaration {
519 public:
520 InitializationFlag initialization() const { return initialization_; }
521
522 private: 518 private:
523 friend class AstNodeFactory; 519 friend class AstNodeFactory;
524 520
525 VariableDeclaration(VariableProxy* proxy, VariableMode mode, Scope* scope, 521 VariableDeclaration(VariableProxy* proxy, VariableMode mode, Scope* scope,
526 InitializationFlag initialization, int pos) 522 int pos)
527 : Declaration(proxy, mode, scope, pos, kVariableDeclaration), 523 : Declaration(proxy, mode, scope, pos, kVariableDeclaration) {}
528 initialization_(initialization) {}
529
530 InitializationFlag initialization_;
531 }; 524 };
532 525
533 526
534 class FunctionDeclaration final : public Declaration { 527 class FunctionDeclaration final : public Declaration {
535 public: 528 public:
536 FunctionLiteral* fun() const { return fun_; } 529 FunctionLiteral* fun() const { return fun_; }
537 void set_fun(FunctionLiteral* f) { fun_ = f; } 530 void set_fun(FunctionLiteral* f) { fun_ = f; }
538 InitializationFlag initialization() const { return kCreatedInitialized; }
539 531
540 private: 532 private:
541 friend class AstNodeFactory; 533 friend class AstNodeFactory;
542 534
543 FunctionDeclaration(VariableProxy* proxy, VariableMode mode, 535 FunctionDeclaration(VariableProxy* proxy, VariableMode mode,
544 FunctionLiteral* fun, Scope* scope, int pos) 536 FunctionLiteral* fun, Scope* scope, int pos)
545 : Declaration(proxy, mode, scope, pos, kFunctionDeclaration), fun_(fun) { 537 : Declaration(proxy, mode, scope, pos, kFunctionDeclaration), fun_(fun) {
546 DCHECK(mode == VAR || mode == LET || mode == CONST); 538 DCHECK(mode == VAR || mode == LET || mode == CONST);
547 DCHECK(fun != NULL); 539 DCHECK(fun != NULL);
548 } 540 }
(...skipping 2452 matching lines...) Expand 10 before | Expand all | Expand 10 after
3001 2993
3002 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } 2994 AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
3003 void set_ast_value_factory(AstValueFactory* ast_value_factory) { 2995 void set_ast_value_factory(AstValueFactory* ast_value_factory) {
3004 ast_value_factory_ = ast_value_factory; 2996 ast_value_factory_ = ast_value_factory;
3005 zone_ = ast_value_factory->zone(); 2997 zone_ = ast_value_factory->zone();
3006 } 2998 }
3007 2999
3008 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, 3000 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
3009 VariableMode mode, Scope* scope, 3001 VariableMode mode, Scope* scope,
3010 int pos) { 3002 int pos) {
3011 return NewVariableDeclaration( 3003 return new (zone_) VariableDeclaration(proxy, mode, scope, pos);
3012 proxy, mode, scope,
3013 mode == VAR ? kCreatedInitialized : kNeedsInitialization, pos);
3014 }
3015
3016 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
3017 VariableMode mode, Scope* scope,
3018 InitializationFlag init,
3019 int pos) {
3020 return new (zone_) VariableDeclaration(proxy, mode, scope, init, pos);
3021 } 3004 }
3022 3005
3023 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, 3006 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3024 VariableMode mode, 3007 VariableMode mode,
3025 FunctionLiteral* fun, 3008 FunctionLiteral* fun,
3026 Scope* scope, 3009 Scope* scope,
3027 int pos) { 3010 int pos) {
3028 return new (zone_) FunctionDeclaration(proxy, mode, fun, scope, pos); 3011 return new (zone_) FunctionDeclaration(proxy, mode, fun, scope, pos);
3029 } 3012 }
3030 3013
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 : NULL; \ 3470 : NULL; \
3488 } 3471 }
3489 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3472 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3490 #undef DECLARE_NODE_FUNCTIONS 3473 #undef DECLARE_NODE_FUNCTIONS
3491 3474
3492 3475
3493 } // namespace internal 3476 } // namespace internal
3494 } // namespace v8 3477 } // namespace v8
3495 3478
3496 #endif // V8_AST_AST_H_ 3479 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | src/parsing/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698