27 #include "node_base.h"
38 std::vector<Node *> m_kids;
41 bool m_loc_was_set_explicitly;
47 Node(
int tag,
const std::string &str,
const std::vector<Node *> &kids);
48 Node(
int tag,
const std::string &str,
const std::initializer_list<Node *> kids);
51 typedef std::vector<Node *>::const_iterator const_iterator;
54 Node(
int tag, std::initializer_list<Node *> kids);
55 Node(
int tag,
const std::vector<Node *> &kids);
56 Node(
int tag,
const std::string &str);
60 int get_tag()
const {
return m_tag; }
61 void set_tag(
int tag) { m_tag = tag; }
63 std::string get_str()
const {
return m_str; }
64 void set_str(
const std::string &str) { m_str = str; }
66 void append_kid(
Node *kid);
67 void prepend_kid(
Node *kid);
68 unsigned get_num_kids()
const {
return unsigned(m_kids.size()); }
69 Node *get_kid(
unsigned index)
const {
return m_kids.at(index); }
70 Node *get_last_kid()
const {
return m_kids.back(); }
75 void set_kid(
unsigned index,
Node *kid) { m_kids.at(index) = kid; }
77 const_iterator cbegin()
const {
return m_kids.cbegin(); }
78 const_iterator cend()
const {
return m_kids.cend(); }
80 void set_loc(
const Location &loc) { m_loc = loc; m_loc_was_set_explicitly =
true; }
81 const Location &get_loc()
const {
return m_loc; }
86 void preorder(Fn fn) {
88 for (
auto i = m_kids.begin(); i != m_kids.end(); ++i) {
95 void each_child(Fn fn)
const {
96 for (
auto i = m_kids.begin(); i != m_kids.end(); ++i) {
Definition: location.h:26
The Node class will inherit from this type, so you can use it to define any attributes and methods th...
Definition: node_base.h:43