2020-08-31 18:46:27 -07:00
|
|
|
#include "UserFunction.h"
|
|
|
|
|
|
2024-01-16 17:55:42 +01:00
|
|
|
|
2020-08-31 18:46:27 -07:00
|
|
|
#include <utility>
|
|
|
|
|
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/FunctionBody.h"
|
|
|
|
|
#include "bscript/compiler/ast/FunctionParameterList.h"
|
|
|
|
|
#include "bscript/compiler/ast/NodeVisitor.h"
|
2024-08-18 11:03:01 +02:00
|
|
|
#include "bscript/compiler/model/ClassLink.h"
|
2020-08-31 18:46:27 -07:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
2024-07-29 22:30:52 +02:00
|
|
|
UserFunction::UserFunction( const SourceLocation& source_location, bool exported, bool expression,
|
2024-08-11 23:01:38 +02:00
|
|
|
UserFunctionType type, std::string scope, std::string name,
|
2024-08-10 15:27:25 +02:00
|
|
|
std::unique_ptr<FunctionParameterList> parameter_list,
|
2020-08-31 18:46:27 -07:00
|
|
|
std::unique_ptr<FunctionBody> body,
|
2024-08-18 11:03:01 +02:00
|
|
|
const SourceLocation& endfunction_location,
|
|
|
|
|
std::shared_ptr<ClassLink> class_link )
|
2024-08-11 23:01:38 +02:00
|
|
|
: Function( source_location, std::move( scope ), std::move( name ), std::move( parameter_list ),
|
2024-01-12 06:51:44 +01:00
|
|
|
std::move( body ) ),
|
|
|
|
|
exported( exported ),
|
2024-07-29 22:30:52 +02:00
|
|
|
expression( expression ),
|
2024-08-10 15:27:25 +02:00
|
|
|
type( type ),
|
2024-08-18 11:03:01 +02:00
|
|
|
endfunction_location( endfunction_location ),
|
|
|
|
|
class_link( std::move( class_link ) )
|
2020-08-31 18:46:27 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UserFunction::accept( NodeVisitor& visitor )
|
|
|
|
|
{
|
|
|
|
|
visitor.visit_user_function( *this );
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 06:51:44 +01:00
|
|
|
void UserFunction::describe_to( std::string& w ) const
|
2020-08-31 18:46:27 -07:00
|
|
|
{
|
2024-01-12 06:51:44 +01:00
|
|
|
fmt::format_to( std::back_inserter( w ), "user-function({})", name );
|
2020-08-31 18:46:27 -07:00
|
|
|
}
|
|
|
|
|
|
2024-07-29 22:30:52 +02:00
|
|
|
unsigned UserFunction::capture_count() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<unsigned>( capture_variable_scope_info.variables.size() );
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 18:46:27 -07:00
|
|
|
FunctionBody& UserFunction::body()
|
|
|
|
|
{
|
|
|
|
|
return child<FunctionBody>( 1 );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|