aboutsummaryrefslogtreecommitdiff
path: root/MoonParser/ast.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'MoonParser/ast.cpp')
-rw-r--r--MoonParser/ast.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/MoonParser/ast.cpp b/MoonParser/ast.cpp
index 090f5ee..739e02c 100644
--- a/MoonParser/ast.cpp
+++ b/MoonParser/ast.cpp
@@ -11,6 +11,13 @@ static ast_container *_current = 0;
11int ast_type_id = 0; 11int ast_type_id = 0;
12 12
13 13
14bool ast_node::visit(const std::function<bool (ast_node*)>& begin,
15 const std::function<bool (ast_node*)>& end)
16{
17 return begin(this) || end(this);
18}
19
20
14/** sets the container under construction to be this. 21/** sets the container under construction to be this.
15 */ 22 */
16ast_container::ast_container() { 23ast_container::ast_container() {
@@ -41,6 +48,28 @@ void ast_container::construct(ast_stack &st) {
41 } 48 }
42} 49}
43 50
51bool ast_container::visit(const std::function<bool (ast_node*)>& begin,
52 const std::function<bool (ast_node*)>& end)
53{
54 bool result = begin(this);
55 if (result) return true;
56 const auto& members = this->members();
57 for (auto member : members) {
58 if (_ast_ptr* ptr = ast_cast<_ast_ptr>(member)) {
59 if (ptr->get() && ptr->get()->visit(begin, end)) {
60 return true;
61 }
62 } else if (_ast_list* list = ast_cast<_ast_list>(member)) {
63 for (auto obj : list->objects()) {
64 if (obj->visit(begin, end)) {
65 return true;
66 }
67 }
68 }
69 }
70 return end(this);
71}
72
44 73
45//register the AST member to the current container. 74//register the AST member to the current container.
46void ast_member::_init() { 75void ast_member::_init() {