This repository has been archived on 2024-03-07. You can view files and clone it, but cannot push or open issues/pull-requests.
2023-09-27 18:18:05 +00:00
|
|
|
#include "Node.hpp"
|
|
|
|
|
|
|
|
namespace wg
|
|
|
|
{
|
|
|
|
/*explicit*/ Node::Node(NodeType type, std::string const& repr, Loc const& loc)
|
|
|
|
: m_type { type }
|
|
|
|
, m_repr { repr }
|
|
|
|
, m_loc { loc }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*virtual*/ Node::~Node()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node::add_child(std::shared_ptr<Node> child)
|
|
|
|
{
|
|
|
|
m_children.push_back(child);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<Node> Node::child(size_t index) const
|
|
|
|
{
|
2023-09-28 19:37:10 +00:00
|
|
|
WG_ASSERT(index < size(), "Cannot get child node of '"
|
|
|
|
+ string()
|
|
|
|
+ "'");
|
2023-09-27 18:18:05 +00:00
|
|
|
return m_children.at(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Node::string() const
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << (NodeTypeStr[m_type] + strlen("NODE_"));
|
|
|
|
|
|
|
|
if (!m_repr.empty())
|
|
|
|
{
|
|
|
|
ss << "[" << m_repr << "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size() > 0)
|
|
|
|
{
|
|
|
|
ss << "(";
|
|
|
|
|
|
|
|
std::string sep;
|
|
|
|
|
|
|
|
for (auto child: m_children)
|
|
|
|
{
|
|
|
|
ss << sep << child->string();
|
|
|
|
sep = ",";
|
|
|
|
}
|
|
|
|
|
|
|
|
ss << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|