mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* Grammar updates - Make class parameters required * Add ClassLink; wip with `super()` calls in ctors * More AST nodes as ScopableNames - (function call) Argument - FunctionParameterDeclaration * Add support for ambiguity handling * Add few more tests * Handle returns in constructors - Semantic analysis to error on returning a value - Introduce specific emitter method for returning from constructor - Various tests * Refactor super building to pre-semantic analysis * Adding several tests, some are TODO - found an issue with function resolver and funcrefs, fix later * Address self-review comments * Fix funcref global func references, tests
58 lines
2.2 KiB
C++
58 lines
2.2 KiB
C++
#include "ModuleDeclarationBuilder.h"
|
|
|
|
#include "bscript/compiler/ast/Expression.h"
|
|
#include "bscript/compiler/ast/FunctionParameterDeclaration.h"
|
|
#include "bscript/compiler/ast/FunctionParameterList.h"
|
|
#include "bscript/compiler/ast/ModuleFunctionDeclaration.h"
|
|
#include "bscript/compiler/model/ScopableName.h"
|
|
|
|
using EscriptGrammar::EscriptParser;
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
ModuleDeclarationBuilder::ModuleDeclarationBuilder(
|
|
const SourceFileIdentifier& source_file_identifier, BuilderWorkspace& workspace )
|
|
: SimpleStatementBuilder( source_file_identifier, workspace )
|
|
{
|
|
}
|
|
|
|
std::unique_ptr<ModuleFunctionDeclaration> ModuleDeclarationBuilder::module_function_declaration(
|
|
EscriptParser::ModuleFunctionDeclarationContext* ctx, std::string module_name )
|
|
{
|
|
std::string name = text( ctx->IDENTIFIER() );
|
|
std::vector<std::unique_ptr<FunctionParameterDeclaration>> parameters;
|
|
|
|
if ( auto param_list = ctx->moduleFunctionParameterList() )
|
|
{
|
|
for ( auto param : param_list->moduleFunctionParameter() )
|
|
{
|
|
ScopableName parameter_name( ScopeName::None, text( param->IDENTIFIER() ) );
|
|
std::unique_ptr<FunctionParameterDeclaration> parameter_declaration;
|
|
bool byref = false;
|
|
bool unused = false;
|
|
bool rest = false;
|
|
|
|
if ( auto expr_ctx = param->expression() )
|
|
{
|
|
auto default_value = expression( expr_ctx );
|
|
parameter_declaration = std::make_unique<FunctionParameterDeclaration>(
|
|
location_for( *param ), std::move( parameter_name ), byref, unused, rest,
|
|
std::move( default_value ) );
|
|
}
|
|
else
|
|
{
|
|
parameter_declaration = std::make_unique<FunctionParameterDeclaration>(
|
|
location_for( *param ), std::move( parameter_name ), byref, unused, rest );
|
|
}
|
|
parameters.push_back( std::move( parameter_declaration ) );
|
|
}
|
|
}
|
|
|
|
auto source_location = location_for( *ctx );
|
|
auto parameter_list =
|
|
std::make_unique<FunctionParameterList>( source_location, std::move( parameters ) );
|
|
return std::make_unique<ModuleFunctionDeclaration>(
|
|
source_location, std::move( module_name ), std::move( name ), std::move( parameter_list ) );
|
|
}
|
|
|
|
} // namespace Pol::Bscript::Compiler
|