2026-07-25 23:01:18 +02:00
|
|
|
#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 )
|
2024-01-12 06:51:44 +01:00
|
|
|
: 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 )
|
2024-01-12 06:51:44 +01:00
|
|
|
: 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
|
|
|
|
|
{
|
2024-01-12 06:51:44 +01:00
|
|
|
std::string w;
|
2020-08-16 23:03:33 -07:00
|
|
|
describe_to( w );
|
2024-01-12 06:51:44 +01:00
|
|
|
return w;
|
2020-08-16 23:03:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Node::to_string_tree() const
|
|
|
|
|
{
|
2024-01-12 06:51:44 +01:00
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 06:51:44 +01:00
|
|
|
void Node::describe_tree_to_indented( const Node& node, std::string& w, unsigned indent )
|
2020-08-16 23:03:33 -07:00
|
|
|
{
|
2024-01-12 06:51:44 +01:00
|
|
|
w += std::string( indent * 2, ' ' ) + "- ";
|
2020-08-16 23:03:33 -07:00
|
|
|
node.describe_to( w );
|
2024-01-12 06:51:44 +01:00
|
|
|
w += "\n";
|
2020-08-16 23:03:33 -07:00
|
|
|
for ( const auto& child : node.children )
|
|
|
|
|
{
|
|
|
|
|
if ( child )
|
2024-01-12 06:51:44 +01:00
|
|
|
describe_tree_to_indented( *child, w, indent + 1 );
|
2020-08-16 23:03:33 -07:00
|
|
|
else
|
2024-01-12 06:51:44 +01:00
|
|
|
w += std::string( ( indent + 1 ) * 2, ' ' ) + "- [deleted]\n";
|
2020-08-16 23:03:33 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|