2023-09-20 11:31:35 +00:00
|
|
|
#ifndef fk_NODE_HPP
|
|
|
|
#define fk_NODE_HPP
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
#include "Loc.hpp"
|
|
|
|
|
|
|
|
#define NODE_TYPES(G) \
|
2023-09-20 15:17:13 +00:00
|
|
|
G(NODE_MODULE), G(NODE_INT), G(NODE_FLOAT), G(NODE_BOOL), G(NODE_STRING),\
|
2023-09-21 19:17:39 +00:00
|
|
|
G(NODE_IDENT), G(NODE_OPAR), G(NODE_CPAR), G(NODE_CALL), G(NODE_LAMBDA),\
|
2023-09-23 17:21:55 +00:00
|
|
|
G(NODE_RARROW), G(NODE_PARAMS), G(NODE_BODY), G(NODE_NS), G(NODE_IMPORT),\
|
2023-09-23 22:40:08 +00:00
|
|
|
G(NODE_VARDECL), G(NODE_DECL), G(NODE_ARRAY), G(NODE_OSQUARE), \
|
|
|
|
G(NODE_CSQUARE)
|
2023-09-20 11:31:35 +00:00
|
|
|
|
|
|
|
namespace fk
|
|
|
|
{
|
|
|
|
FK_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
|