2020-08-23 15:01:39 -07:00
|
|
|
#include "Function.h"
|
|
|
|
|
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/FunctionBody.h"
|
|
|
|
|
#include "bscript/compiler/ast/FunctionParameterDeclaration.h"
|
|
|
|
|
#include "bscript/compiler/ast/FunctionParameterList.h"
|
2020-08-23 15:01:39 -07:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
2020-08-31 18:46:27 -07:00
|
|
|
Function::Function( const SourceLocation& source_location, std::string name,
|
|
|
|
|
std::unique_ptr<FunctionParameterList> parameter_list,
|
|
|
|
|
std::unique_ptr<FunctionBody> body )
|
|
|
|
|
: Node( source_location ), name( std::move( name ) )
|
|
|
|
|
{
|
|
|
|
|
children.reserve( 2 );
|
|
|
|
|
children.push_back( std::move( parameter_list ) );
|
|
|
|
|
children.push_back( std::move( body ) );
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-23 15:01:39 -07:00
|
|
|
Function::Function( const SourceLocation& source_location, std::string name,
|
|
|
|
|
std::unique_ptr<FunctionParameterList> parameter_list )
|
|
|
|
|
: Node( source_location, std::move( parameter_list ) ), name( std::move( name ) )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned Function::parameter_count() const
|
|
|
|
|
{
|
2024-01-12 06:51:44 +01:00
|
|
|
return static_cast<unsigned>( children.at( 0 )->children.size() );
|
2020-08-23 15:01:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::reference_wrapper<FunctionParameterDeclaration>> Function::parameters()
|
|
|
|
|
{
|
|
|
|
|
std::vector<std::reference_wrapper<FunctionParameterDeclaration>> params;
|
|
|
|
|
auto& param_list = child<FunctionParameterList>( 0 );
|
|
|
|
|
for ( auto& param : param_list.children )
|
|
|
|
|
{
|
|
|
|
|
params.emplace_back( *static_cast<FunctionParameterDeclaration*>( param.get() ) );
|
|
|
|
|
}
|
|
|
|
|
return params;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|