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-types.h" | 8 #include "src/ast/ast-types.h" |
9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
10 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 502 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
503 | 503 |
504 Block* block_; | 504 Block* block_; |
505 VariableProxy* result_; | 505 VariableProxy* result_; |
506 FunctionLiteral* represented_function_; | 506 FunctionLiteral* represented_function_; |
507 }; | 507 }; |
508 | 508 |
509 | 509 |
510 class Declaration : public AstNode { | 510 class Declaration : public AstNode { |
511 public: | 511 public: |
| 512 typedef ThreadedList<Declaration> List; |
| 513 |
512 VariableProxy* proxy() const { return proxy_; } | 514 VariableProxy* proxy() const { return proxy_; } |
513 Scope* scope() const { return scope_; } | 515 Scope* scope() const { return scope_; } |
514 | 516 |
515 protected: | 517 protected: |
516 Declaration(VariableProxy* proxy, Scope* scope, int pos, NodeType type) | 518 Declaration(VariableProxy* proxy, Scope* scope, int pos, NodeType type) |
517 : AstNode(pos, type), proxy_(proxy), scope_(scope) {} | 519 : AstNode(pos, type), proxy_(proxy), scope_(scope), next_(nullptr) {} |
518 | 520 |
519 static const uint8_t kNextBitFieldIndex = AstNode::kNextBitFieldIndex; | 521 static const uint8_t kNextBitFieldIndex = AstNode::kNextBitFieldIndex; |
520 | 522 |
521 private: | 523 private: |
522 VariableProxy* proxy_; | 524 VariableProxy* proxy_; |
523 | |
524 // Nested scope from which the declaration originated. | 525 // Nested scope from which the declaration originated. |
525 Scope* scope_; | 526 Scope* scope_; |
| 527 // Declarations list threaded through the declarations. |
| 528 Declaration** next() { return &next_; } |
| 529 Declaration* next_; |
| 530 friend List; |
526 }; | 531 }; |
527 | 532 |
528 | 533 |
529 class VariableDeclaration final : public Declaration { | 534 class VariableDeclaration final : public Declaration { |
530 private: | 535 private: |
531 friend class AstNodeFactory; | 536 friend class AstNodeFactory; |
532 | 537 |
533 VariableDeclaration(VariableProxy* proxy, Scope* scope, int pos) | 538 VariableDeclaration(VariableProxy* proxy, Scope* scope, int pos) |
534 : Declaration(proxy, scope, pos, kVariableDeclaration) {} | 539 : Declaration(proxy, scope, pos, kVariableDeclaration) {} |
535 }; | 540 }; |
(...skipping 2415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2951 // ---------------------------------------------------------------------------- | 2956 // ---------------------------------------------------------------------------- |
2952 // Basic visitor | 2957 // Basic visitor |
2953 // Sub-class should parametrize AstVisitor with itself, e.g.: | 2958 // Sub-class should parametrize AstVisitor with itself, e.g.: |
2954 // class SpecificVisitor : public AstVisitor<SpecificVisitor> { ... } | 2959 // class SpecificVisitor : public AstVisitor<SpecificVisitor> { ... } |
2955 | 2960 |
2956 template <class Subclass> | 2961 template <class Subclass> |
2957 class AstVisitor BASE_EMBEDDED { | 2962 class AstVisitor BASE_EMBEDDED { |
2958 public: | 2963 public: |
2959 void Visit(AstNode* node) { impl()->Visit(node); } | 2964 void Visit(AstNode* node) { impl()->Visit(node); } |
2960 | 2965 |
2961 void VisitDeclarations(ZoneList<Declaration*>* declarations) { | 2966 void VisitDeclarations(Declaration::List* declarations) { |
2962 for (int i = 0; i < declarations->length(); i++) { | 2967 for (Declaration* decl : *declarations) Visit(decl); |
2963 Visit(declarations->at(i)); | |
2964 } | |
2965 } | 2968 } |
2966 | 2969 |
2967 void VisitStatements(ZoneList<Statement*>* statements) { | 2970 void VisitStatements(ZoneList<Statement*>* statements) { |
2968 for (int i = 0; i < statements->length(); i++) { | 2971 for (int i = 0; i < statements->length(); i++) { |
2969 Statement* stmt = statements->at(i); | 2972 Statement* stmt = statements->at(i); |
2970 Visit(stmt); | 2973 Visit(stmt); |
2971 if (stmt->IsJump()) break; | 2974 if (stmt->IsJump()) break; |
2972 } | 2975 } |
2973 } | 2976 } |
2974 | 2977 |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3594 : NULL; \ | 3597 : NULL; \ |
3595 } | 3598 } |
3596 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3599 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3597 #undef DECLARE_NODE_FUNCTIONS | 3600 #undef DECLARE_NODE_FUNCTIONS |
3598 | 3601 |
3599 | 3602 |
3600 } // namespace internal | 3603 } // namespace internal |
3601 } // namespace v8 | 3604 } // namespace v8 |
3602 | 3605 |
3603 #endif // V8_AST_AST_H_ | 3606 #endif // V8_AST_AST_H_ |
OLD | NEW |