polserver/pol-core/bscript/compiler/ast/IndexBinding.cpp
turleypol fb3faddeae
use c++20 (#799)
* use c++20
* increased used clang version
* compiler report and logfacility use now compile time formatting, which
means that the formatstring gets checked at compile time. (which found 2 errors)
adapted a few places since report only accepts formatting arguments
adapted a few places with logging since char[] is compile time
formatting and string or chr* is runtime formatting
* use std::ranges instead of boost
* disabled pragma_assume vs specific macro (I guess noone cares)
* needed to fix ancient ms exception code
* modernized SpinLock
* removed unused code in ECompile
* replaced std::filesystem::path::u8string with string. It now returns an actual u8string type
* cleanup layers.h added the defines for other layers which where before
  only defined in the pkt
* osmod::OpenConnection and HTTPRequest cleanup: early outs, dont check for pChild which is
  only needed for startscript and placed suspend at the very last
  position

* fix warning

* rebuild cache with new compiler version

* define c++ standard for external libs where possible

* added fixme
2025-08-01 21:40:10 +02:00

52 lines
1.3 KiB
C++

#include "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