polserver/pol-core/bscript/compiler/ast/IndexBinding.cpp
turleypol 1463b76c7c
Includes are now all relative to pol-core basefolder (#906)
* all except pol

* pol and includes under defines

* something weird has happened

* remove own folder from include searchpath

* fixed remaining, adapted include style for external headers

* missing include
2026-07-25 23:01:18 +02:00

52 lines
1.4 KiB
C++

#include "bscript/compiler/ast/IndexBinding.h"
#include <ranges>
#include "bscript/compiler/ast/ElementIndexes.h"
#include "bscript/compiler/ast/Node.h"
#include "bscript/compiler/ast/NodeVisitor.h"
#include "clib/clib.h"
namespace Pol::Bscript::Compiler
{
IndexBinding::IndexBinding( const SourceLocation& loc, std::unique_ptr<ElementIndexes> indices,
std::vector<std::unique_ptr<Node>> bindings )
: Node( loc )
{
children.reserve( bindings.size() + 1 );
children.push_back( std::move( indices ) );
children.insert( children.end(), std::make_move_iterator( bindings.begin() ),
std::make_move_iterator( bindings.end() ) );
}
void IndexBinding::accept( NodeVisitor& visitor )
{
visitor.visit_index_binding( *this );
}
void IndexBinding::describe_to( std::string& w ) const
{
w += "index-binding";
}
ElementIndexes& IndexBinding::indexes()
{
return child<ElementIndexes>( 0 );
}
std::vector<std::reference_wrapper<Node>> IndexBinding::bindings()
{
std::vector<std::reference_wrapper<Node>> params;
for ( auto& param : children | std::views::drop( 1 ) )
{
params.emplace_back( *param.get() );
}
return params;
}
u8 IndexBinding::binding_count() const
{
// Subtract one, for the ElementIndexes at the first child.
return Clib::clamp_convert<u8>( children.size() - 1 );
}
} // namespace Pol::Bscript::Compiler