aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/ast.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MoonParser/ast.cpp')
-rw-r--r--MoonParser/ast.cpp26
1 files changed, 4 insertions, 22 deletions
diff --git a/MoonParser/ast.cpp b/MoonParser/ast.cpp
index dbf5d17..852593b 100644
--- a/MoonParser/ast.cpp
+++ b/MoonParser/ast.cpp
@@ -14,12 +14,10 @@ traversal ast_node::traverse(const std::function<traversal (ast_node*)>& func) {
14 return func(this); 14 return func(this);
15} 15}
16 16
17ast_node* ast_node::getByPath(std::initializer_list<std::size_t>) { 17ast_node* ast_node::getByPath(std::initializer_list<size_t>) {
18 return nullptr; 18 return nullptr;
19} 19}
20 20
21void ast_node::eachChild(const std::function<void (ast_node*)>&) { }
22
23bool ast_node::visitChild(const std::function<bool (ast_node*)>&) { 21bool ast_node::visitChild(const std::function<bool (ast_node*)>&) {
24 return false; 22 return false;
25} 23}
@@ -70,13 +68,14 @@ traversal ast_container::traverse(const std::function<traversal (ast_node*)>& fu
70 return traversal::Continue; 68 return traversal::Continue;
71} 69}
72 70
73ast_node* ast_container::getByPath(std::initializer_list<std::size_t> paths) { 71ast_node* ast_container::getByPath(std::initializer_list<size_t> paths) {
74 ast_node* current = this; 72 ast_node* current = this;
75 auto it = paths.begin(); 73 auto it = paths.begin();
76 while (it != paths.end()) { 74 while (it != paths.end()) {
77 ast_node* findNode = nullptr; 75 ast_node* findNode = nullptr;
76 size_t id = *it;
78 current->visitChild([&](ast_node* node) { 77 current->visitChild([&](ast_node* node) {
79 if (node->getId() == *it) { 78 if (node->getId() == id) {
80 findNode = node; 79 findNode = node;
81 return true; 80 return true;
82 } 81 }
@@ -93,23 +92,6 @@ ast_node* ast_container::getByPath(std::initializer_list<std::size_t> paths) {
93 return current; 92 return current;
94} 93}
95 94
96void ast_container::eachChild(const std::function<void (ast_node*)>& func) {
97 const auto& members = this->members();
98 for (auto member : members) {
99 if (_ast_ptr* ptr = ast_cast<_ast_ptr>(member)) {
100 if (ptr->get()) {
101 func(ptr->get());
102 }
103 } else if (_ast_list* list = ast_cast<_ast_list>(member)) {
104 for (auto obj : list->objects()) {
105 if (obj) {
106 func(obj);
107 }
108 }
109 }
110 }
111}
112
113bool ast_container::visitChild(const std::function<bool (ast_node*)>& func) { 95bool ast_container::visitChild(const std::function<bool (ast_node*)>& func) {
114 const auto& members = this->members(); 96 const auto& members = this->members();
115 for (auto member : members) { 97 for (auto member : members) {