2020-09-07 09:53:24 -07:00
|
|
|
#include "BranchSelector.h"
|
|
|
|
|
|
|
|
|
|
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/Expression.h"
|
|
|
|
|
#include "bscript/compiler/ast/NodeVisitor.h"
|
|
|
|
|
#include "bscript/compiler/model/FlowControlLabel.h"
|
2020-09-07 09:53:24 -07:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
|
|
|
|
BranchSelector::BranchSelector( const SourceLocation& source_location, BranchType branch_type,
|
|
|
|
|
std::unique_ptr<Expression> predicate )
|
|
|
|
|
: Node( source_location, std::move( predicate ) ),
|
|
|
|
|
branch_type( branch_type ),
|
|
|
|
|
flow_control_label( std::make_shared<FlowControlLabel>() )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BranchSelector::BranchSelector( const SourceLocation& source_location, BranchType branch_type )
|
|
|
|
|
: Node( source_location ),
|
|
|
|
|
branch_type( branch_type ),
|
|
|
|
|
flow_control_label( std::make_shared<FlowControlLabel>() )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BranchSelector::accept( NodeVisitor& visitor )
|
|
|
|
|
{
|
|
|
|
|
visitor.visit_branch_selector( *this );
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 06:51:44 +01:00
|
|
|
void BranchSelector::describe_to( std::string& w ) const
|
2020-09-07 09:53:24 -07:00
|
|
|
{
|
2024-01-12 06:51:44 +01:00
|
|
|
fmt::format_to( std::back_inserter( w ), "branch-selector({})", fmt::underlying( branch_type ) );
|
2020-09-07 09:53:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Expression* BranchSelector::predicate()
|
|
|
|
|
{
|
|
|
|
|
return children.empty() ? nullptr : &child<Expression>( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|