diff options
| author | Nagi5Yeq <wu@x-nagi.com> | 2020-05-29 00:17:00 +0800 |
|---|---|---|
| committer | Nagi5Yeq <wu@x-nagi.com> | 2020-05-29 00:17:00 +0800 |
| commit | f15a071f6d599d2a21083dfb041b18db8d482949 (patch) | |
| tree | a1b33b6ffe36f14a990dcfe5b9c5e593703d7ae0 /node | |
| parent | d4e6ae6f8237f18d9d0b51e7a6404118dffb709f (diff) | |
remove ListNode, use std::move in AST building
Diffstat (limited to 'node')
| -rw-r--r-- | node/BaseNode.hh | 11 | ||||
| -rw-r--r-- | node/StatementNode.cc | 9 | ||||
| -rw-r--r-- | node/StatementNode.hh | 10 |
3 files changed, 17 insertions, 13 deletions
diff --git a/node/BaseNode.hh b/node/BaseNode.hh index 71b0925..7fdb135 100644 --- a/node/BaseNode.hh +++ b/node/BaseNode.hh @@ -15,17 +15,6 @@ class BaseNode { Context* context_; }; -template <typename T, class Base = BaseNode> class ListNode : public Base { - public: - ListNode(Context* context) - : Base(context) {} - void Append(T child) { childs_.push_back(child); } - virtual Value CodeGen(); - - private: - std::list<T> childs_; -}; - class FunctionNode; class ProgramNode : public BaseNode { diff --git a/node/StatementNode.cc b/node/StatementNode.cc index 5eb17b2..c585e46 100644 --- a/node/StatementNode.cc +++ b/node/StatementNode.cc @@ -1,7 +1,14 @@ #include "StatementNode.hh" namespace pcc { -template <> Value StatementListNode::CodeGen() { +StatementListNode::StatementListNode(Context* context) + : BaseNode(context) {} + +void StatementListNode::Append(std::shared_ptr<BaseNode> child) { + childs_.push_back(child); +} + +Value StatementListNode::CodeGen() { Value result = nullptr; for (auto& child : childs_) { result = child->CodeGen(); diff --git a/node/StatementNode.hh b/node/StatementNode.hh index 1bd0cb6..5dea2ea 100644 --- a/node/StatementNode.hh +++ b/node/StatementNode.hh @@ -7,7 +7,15 @@ #include "ExprNode.hh" namespace pcc { -using StatementListNode = ListNode<std::shared_ptr<BaseNode>>; +class StatementListNode : public BaseNode { + public: + StatementListNode(Context* context); + void Append(std::shared_ptr<BaseNode> child); + virtual Value CodeGen(); + + private: + std::list<std::shared_ptr<BaseNode>> childs_; +}; class EmptyStatementNode : public BaseNode { public: |
