This repository has been archived on 2023-09-10. You can view files and clone it, but cannot push or open issues/pull-requests.
2023-09-09 13:09:43 +00:00
|
|
|
#ifndef jk_NODE_HPP
|
|
|
|
#define jk_NODE_HPP
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
#include "Loc.hpp"
|
|
|
|
|
|
|
|
#define NODE_TYPE(G) \
|
|
|
|
G(NODE_PROG), \
|
2023-09-09 22:03:28 +00:00
|
|
|
G(NODE_INT), \
|
2023-09-10 12:39:23 +00:00
|
|
|
G(NODE_BOOL), \
|
2023-09-09 22:03:28 +00:00
|
|
|
G(NODE_OPAR), \
|
|
|
|
G(NODE_CPAR), \
|
|
|
|
G(NODE_IDENT), \
|
2023-09-10 06:06:34 +00:00
|
|
|
G(NODE_DECL), \
|
|
|
|
G(NODE_FUNCALL), \
|
2023-09-10 07:59:51 +00:00
|
|
|
G(NODE_VARDECL), \
|
|
|
|
G(NODE_RARROW), \
|
|
|
|
G(NODE_LAMBDA), \
|
|
|
|
G(NODE_PARAMS), \
|
|
|
|
G(NODE_BODY),
|
|
|
|
|
2023-09-09 22:03:28 +00:00
|
|
|
|
2023-09-09 13:09:43 +00:00
|
|
|
|
|
|
|
namespace jk
|
|
|
|
{
|
|
|
|
JK_ENUM(Node, NODE_TYPE);
|
|
|
|
|
|
|
|
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 const& 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
|