44 lines
973 B
C++
44 lines
973 B
C++
|
#ifndef sk_NODE_HPP
|
||
|
#define sk_NODE_HPP
|
||
|
|
||
|
#include "commons.hpp"
|
||
|
#include "Loc.hpp"
|
||
|
|
||
|
#define NODE_TYPE(G) \
|
||
|
G(NODE_PROG), \
|
||
|
G(NODE_INT), \
|
||
|
G(NODE_FLOAT), \
|
||
|
G(NODE_BOOL), \
|
||
|
G(NODE_STRING),
|
||
|
|
||
|
namespace sk
|
||
|
{
|
||
|
SK_ENUM(Node, NODE_TYPE);
|
||
|
|
||
|
class Node
|
||
|
{
|
||
|
public:
|
||
|
explicit Node(NodeType type, std::string const repr, Loc loc);
|
||
|
virtual ~Node();
|
||
|
|
||
|
NodeType type() const { return m_type; }
|
||
|
std::string repr() const { return m_repr; }
|
||
|
Loc loc() const { return m_loc; }
|
||
|
size_t size() const { return m_children.size(); }
|
||
|
|
||
|
void add_child(std::shared_ptr<Node> child);
|
||
|
std::weak_ptr<Node> child(size_t index) const;
|
||
|
|
||
|
std::string string() const;
|
||
|
|
||
|
private:
|
||
|
NodeType m_type;
|
||
|
std::string m_repr;
|
||
|
Loc m_loc;
|
||
|
|
||
|
std::vector<std::shared_ptr<Node>> m_children;
|
||
|
};
|
||
|
}
|
||
|
|
||
|
#endif
|