polserver/pol-core/bscript/compiler/ast/Node.cpp

59 lines
1.3 KiB
C++
Raw Permalink Normal View History

#include "bscript/compiler/ast/Node.h"
2020-08-16 23:03:33 -07:00
namespace Pol::Bscript::Compiler
{
Node::Node( const SourceLocation& source_location, NodeVector children )
: children( std::move( children ) ), source_location( source_location )
2020-08-16 23:03:33 -07:00
{
}
Node::Node( const SourceLocation& source_location, std::unique_ptr<Node> child )
: source_location( source_location )
2020-08-16 23:03:33 -07:00
{
children.reserve( 1 );
children.push_back( std::move( child ) );
}
Node::Node( const SourceLocation& source_location ) : children(), source_location( source_location )
{
}
std::string Node::describe() const
{
std::string w;
2020-08-16 23:03:33 -07:00
describe_to( w );
return w;
2020-08-16 23:03:33 -07:00
}
std::string Node::to_string_tree() const
{
return fmt::to_string( *this );
2020-08-16 23:03:33 -07:00
}
void Node::debug( const std::string& msg ) const
{
source_location.debug( msg );
}
void Node::internal_error( const std::string& msg ) const
{
source_location.internal_error( msg );
}
void Node::describe_tree_to_indented( const Node& node, std::string& w, unsigned indent )
2020-08-16 23:03:33 -07:00
{
w += std::string( indent * 2, ' ' ) + "- ";
2020-08-16 23:03:33 -07:00
node.describe_to( w );
w += "\n";
2020-08-16 23:03:33 -07:00
for ( const auto& child : node.children )
{
if ( child )
describe_tree_to_indented( *child, w, indent + 1 );
2020-08-16 23:03:33 -07:00
else
w += std::string( ( indent + 1 ) * 2, ' ' ) + "- [deleted]\n";
2020-08-16 23:03:33 -07:00
}
}
} // namespace Pol::Bscript::Compiler