2023-09-27 18:18:05 +00:00
|
|
|
#ifndef wg_NODE_HPP
|
|
|
|
#define wg_NODE_HPP
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
#include "Loc.hpp"
|
|
|
|
|
2023-09-28 19:37:10 +00:00
|
|
|
#define NODE_TYPES(G) \
|
|
|
|
G(NODE_PROG), \
|
|
|
|
G(NODE_IDENT), \
|
|
|
|
G(NODE_HASH), \
|
|
|
|
G(NODE_DIR), \
|
|
|
|
G(NODE_INT), \
|
|
|
|
G(NODE_ADD), G(NODE_SUB), \
|
|
|
|
G(NODE_MUL),G(NODE_DIV), \
|
|
|
|
G(NODE_MOD), G(NODE_OPAR), G(NODE_CPAR), \
|
|
|
|
G(NODE_SEMICOLON), G(NODE_COMMA), G(NODE_CALL), \
|
|
|
|
G(NODE_ARGS), G(NODE_TYPE), G(NODE_RETURN), \
|
|
|
|
G(NODE_FUN), G(NODE_PARAMS), G(NODE_BLOCK), \
|
|
|
|
G(NODE_OBRACE), G(NODE_CBRACE), G(NODE_FUNDECL), \
|
|
|
|
G(NODE_EXTERN), G(NODE_RET)
|
2023-09-27 18:18:05 +00:00
|
|
|
|
|
|
|
namespace wg
|
|
|
|
{
|
|
|
|
WG_ENUM(NodeType, NODE_TYPES);
|
|
|
|
|
|
|
|
class Node
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit Node(NodeType type, std::string const& repr, Loc const& 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::shared_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
|