roza/lib/Node.hpp

42 lines
883 B
C++

#ifndef roza_NODE_HPP
#define roza_NODE_HPP
#include "commons.hpp"
#include "SrcLoc.hpp"
#define NODE_TYPE(G) \
G(NODE_PROG), G(NODE_INSTR), G(NODE_EOI), \
G(NODE_INT)
namespace roza
{
MAKE_ENUM(NODE_TYPE, NodeType);
class Node
{
public:
explicit Node(NodeType type, std::string const& repr, SrcLoc loc);
virtual ~Node();
NodeType type() const { return m_type; }
std::string repr() const { return m_repr; }
SrcLoc loc() const { return m_loc; }
size_t size() const { return m_children.size(); }
std::string string() const;
void add_child(std::shared_ptr<Node> child);
std::shared_ptr<Node> child(size_t index);
Node const& child(size_t index) const;
private:
NodeType m_type;
std::string m_repr;
SrcLoc m_loc;
std::vector<std::shared_ptr<Node>> m_children;
};
}
#endif