2020-09-01 22:49:48 -07:00
|
|
|
#include "BinaryOperator.h"
|
|
|
|
|
|
2024-01-16 17:55:42 +01:00
|
|
|
|
2020-09-01 22:49:48 -07:00
|
|
|
#include <utility>
|
|
|
|
|
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/NodeVisitor.h"
|
2020-09-01 22:49:48 -07:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
|
|
|
|
BinaryOperator::BinaryOperator( const SourceLocation& source_location,
|
|
|
|
|
std::unique_ptr<Expression> lhs, std::string op, BTokenId token_id,
|
|
|
|
|
std::unique_ptr<Expression> rhs )
|
|
|
|
|
: Expression( source_location ), op( std::move( op ) ), token_id( token_id )
|
|
|
|
|
{
|
|
|
|
|
children.reserve( 2 );
|
|
|
|
|
children.push_back( std::move( lhs ) );
|
|
|
|
|
children.push_back( std::move( rhs ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BinaryOperator::accept( NodeVisitor& visitor )
|
|
|
|
|
{
|
|
|
|
|
visitor.visit_binary_operator( *this );
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 06:51:44 +01:00
|
|
|
void BinaryOperator::describe_to( std::string& w ) const
|
2020-09-01 22:49:48 -07:00
|
|
|
{
|
2024-01-12 06:51:44 +01:00
|
|
|
fmt::format_to( std::back_inserter( w ), "binary-operator({})", op );
|
2020-09-01 22:49:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Expression& BinaryOperator::lhs()
|
|
|
|
|
{
|
|
|
|
|
return child<Expression>( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Expression& BinaryOperator::rhs()
|
|
|
|
|
{
|
|
|
|
|
return child<Expression>( 1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Expression> BinaryOperator::take_lhs()
|
|
|
|
|
{
|
|
|
|
|
return take_child<Expression>( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<Expression> BinaryOperator::take_rhs()
|
|
|
|
|
{
|
|
|
|
|
return take_child<Expression>( 1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|