2020-09-06 01:22:47 -07:00
|
|
|
#include "ForeachLoop.h"
|
|
|
|
|
|
2024-01-16 17:55:42 +01:00
|
|
|
|
2020-09-06 01:22:47 -07:00
|
|
|
#include <utility>
|
|
|
|
|
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/Block.h"
|
|
|
|
|
#include "bscript/compiler/ast/Expression.h"
|
|
|
|
|
#include "bscript/compiler/ast/NodeVisitor.h"
|
2020-09-06 01:22:47 -07:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
|
|
|
|
ForeachLoop::ForeachLoop( const SourceLocation& source_location, std::string label,
|
|
|
|
|
std::string iterator_name, std::unique_ptr<Expression> expression,
|
|
|
|
|
std::unique_ptr<Block> block )
|
|
|
|
|
: LoopStatement( source_location, std::move( label ) ),
|
|
|
|
|
iterator_name( std::move( iterator_name ) )
|
|
|
|
|
{
|
|
|
|
|
children.reserve( 2 );
|
|
|
|
|
children.push_back( std::move( expression ) );
|
|
|
|
|
children.push_back( std::move( block ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ForeachLoop::accept( NodeVisitor& visitor )
|
|
|
|
|
{
|
|
|
|
|
visitor.visit_foreach_loop( *this );
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 06:51:44 +01:00
|
|
|
void ForeachLoop::describe_to( std::string& w ) const
|
2020-09-06 01:22:47 -07:00
|
|
|
{
|
2024-01-12 06:51:44 +01:00
|
|
|
w += "foreach-loop";
|
2020-09-06 01:22:47 -07:00
|
|
|
if ( !get_label().empty() )
|
2024-01-12 06:51:44 +01:00
|
|
|
fmt::format_to( std::back_inserter( w ), "(label:{})", get_label() );
|
2020-09-06 01:22:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Expression& ForeachLoop::expression()
|
|
|
|
|
{
|
|
|
|
|
return child<Expression>( 0 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Block& ForeachLoop::block()
|
|
|
|
|
{
|
|
|
|
|
return child<Block>( 1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|