mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
Adds enough to build the AST nodes for the module function declarations in a .em file. Adds: - Function: base class for module function declarations and user functions - FunctionParameterDeclaration: declaration for a function parameter, as well as its default value if any - FunctionParameterList: just a holder for function parameter declarations - ModuleFunctionDeclaration: for function declarations in .em files - FunctionResolver: hooks up function calls to module functions or user functions - ModuleProcessor: a visitor for processing const declarations and module function declarations (const declarations are yet to come from the main branch)
30 lines
No EOL
941 B
C++
30 lines
No EOL
941 B
C++
#include "Function.h"
|
|
|
|
#include "compiler/ast/FunctionParameterDeclaration.h"
|
|
#include "compiler/ast/FunctionParameterList.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
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
|
|
{
|
|
return static_cast<unsigned>(children.at( 0 )->children.size());
|
|
}
|
|
|
|
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
|