mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* Update grammar * update prettifier * Update semantic analysis - Move checks for 'super' and non-static to semantic analyzer - Add checks for byref and default * Add, update tests * update escript guide, add tests for examples in guide * update core-changes * Address Discord comments - Update core-changes to explicitly talk about default parameters
58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
#include "FunctionParameterDeclaration.h"
|
|
|
|
#include <utility>
|
|
|
|
#include "bscript/compiler/ast/Expression.h"
|
|
#include "bscript/compiler/ast/NodeVisitor.h"
|
|
#include "clib/logfacility.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
FunctionParameterDeclaration::FunctionParameterDeclaration(
|
|
const SourceLocation& source_location, ScopableName name, bool byref, bool unused,
|
|
bool uninit_default, bool rest, std::unique_ptr<Expression> default_value )
|
|
: Node( source_location, std::move( default_value ) ),
|
|
name( std::move( name ) ),
|
|
byref( byref ),
|
|
unused( unused ),
|
|
uninit_default( uninit_default ),
|
|
rest( rest )
|
|
{
|
|
}
|
|
|
|
FunctionParameterDeclaration::FunctionParameterDeclaration( const SourceLocation& source_location,
|
|
ScopableName name, bool byref,
|
|
bool unused, bool uninit_default,
|
|
bool rest )
|
|
: Node( source_location ),
|
|
name( std::move( name ) ),
|
|
byref( byref ),
|
|
unused( unused ),
|
|
uninit_default( uninit_default ),
|
|
rest( rest )
|
|
{
|
|
}
|
|
|
|
void FunctionParameterDeclaration::accept( NodeVisitor& visitor )
|
|
{
|
|
visitor.visit_function_parameter_declaration( *this );
|
|
}
|
|
|
|
void FunctionParameterDeclaration::describe_to( std::string& w ) const
|
|
{
|
|
fmt::format_to( std::back_inserter( w ), "function-parameter-declaration({}", name.string() );
|
|
if ( rest )
|
|
w += "...";
|
|
if ( byref )
|
|
w += ", byref";
|
|
if ( unused )
|
|
w += ", unused";
|
|
w += ")";
|
|
}
|
|
|
|
Expression* FunctionParameterDeclaration::default_value()
|
|
{
|
|
return children.empty() ? nullptr : &child<Expression>( 0 );
|
|
}
|
|
|
|
} // namespace Pol::Bscript::Compiler
|