| 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_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 Loading... |
| 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 2456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3005 | 2997 |
| 3006 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } | 2998 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } |
| 3007 void set_ast_value_factory(AstValueFactory* ast_value_factory) { | 2999 void set_ast_value_factory(AstValueFactory* ast_value_factory) { |
| 3008 ast_value_factory_ = ast_value_factory; | 3000 ast_value_factory_ = ast_value_factory; |
| 3009 zone_ = ast_value_factory->zone(); | 3001 zone_ = ast_value_factory->zone(); |
| 3010 } | 3002 } |
| 3011 | 3003 |
| 3012 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, | 3004 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, |
| 3013 VariableMode mode, Scope* scope, | 3005 VariableMode mode, Scope* scope, |
| 3014 int pos) { | 3006 int pos) { |
| 3015 return NewVariableDeclaration( | 3007 return new (zone_) VariableDeclaration(proxy, mode, scope, pos); |
| 3016 proxy, mode, scope, | |
| 3017 mode == VAR ? kCreatedInitialized : kNeedsInitialization, pos); | |
| 3018 } | |
| 3019 | |
| 3020 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, | |
| 3021 VariableMode mode, Scope* scope, | |
| 3022 InitializationFlag init, | |
| 3023 int pos) { | |
| 3024 return new (zone_) VariableDeclaration(proxy, mode, scope, init, pos); | |
| 3025 } | 3008 } |
| 3026 | 3009 |
| 3027 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, | 3010 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, |
| 3028 VariableMode mode, | 3011 VariableMode mode, |
| 3029 FunctionLiteral* fun, | 3012 FunctionLiteral* fun, |
| 3030 Scope* scope, | 3013 Scope* scope, |
| 3031 int pos) { | 3014 int pos) { |
| 3032 return new (zone_) FunctionDeclaration(proxy, mode, fun, scope, pos); | 3015 return new (zone_) FunctionDeclaration(proxy, mode, fun, scope, pos); |
| 3033 } | 3016 } |
| 3034 | 3017 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3491 : NULL; \ | 3474 : NULL; \ |
| 3492 } | 3475 } |
| 3493 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3476 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 3494 #undef DECLARE_NODE_FUNCTIONS | 3477 #undef DECLARE_NODE_FUNCTIONS |
| 3495 | 3478 |
| 3496 | 3479 |
| 3497 } // namespace internal | 3480 } // namespace internal |
| 3498 } // namespace v8 | 3481 } // namespace v8 |
| 3499 | 3482 |
| 3500 #endif // V8_AST_AST_H_ | 3483 #endif // V8_AST_AST_H_ |
| OLD | NEW |