2020-08-24 01:47:38 -07:00
|
|
|
#include "ReferencedFunctionGatherer.h"
|
|
|
|
|
|
2024-08-14 12:56:36 +02:00
|
|
|
#include "bscript/compiler/ast/ClassParameterDeclaration.h"
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/FunctionCall.h"
|
2024-07-29 22:30:52 +02:00
|
|
|
#include "bscript/compiler/ast/FunctionExpression.h"
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/FunctionReference.h"
|
|
|
|
|
#include "bscript/compiler/ast/UserFunction.h"
|
|
|
|
|
#include "bscript/compiler/model/FunctionLink.h"
|
2020-08-24 01:47:38 -07:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
|
|
|
|
ReferencedFunctionGatherer::ReferencedFunctionGatherer(
|
2020-09-07 12:35:17 -07:00
|
|
|
std::vector<std::unique_ptr<ModuleFunctionDeclaration>>& all_module_function_declarations,
|
|
|
|
|
std::vector<std::unique_ptr<UserFunction>> all_user_functions )
|
2020-08-24 01:47:38 -07:00
|
|
|
{
|
|
|
|
|
for ( auto& mfd : all_module_function_declarations )
|
|
|
|
|
{
|
|
|
|
|
unreferenced_module_function_declarations.insert( mfd.get() );
|
|
|
|
|
}
|
2020-09-07 12:35:17 -07:00
|
|
|
for ( auto& uf : all_user_functions )
|
|
|
|
|
{
|
|
|
|
|
UserFunction* p = uf.get();
|
|
|
|
|
unreferenced_user_functions[p] = std::move( uf );
|
|
|
|
|
}
|
2020-08-24 01:47:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReferencedFunctionGatherer::visit_function_call( FunctionCall& fc )
|
|
|
|
|
{
|
|
|
|
|
visit_children( fc );
|
|
|
|
|
|
|
|
|
|
reference( *fc.function_link );
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 23:20:32 -07:00
|
|
|
void ReferencedFunctionGatherer::visit_function_reference( FunctionReference& fr )
|
|
|
|
|
{
|
|
|
|
|
reference( *fr.function_link );
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-29 22:30:52 +02:00
|
|
|
void ReferencedFunctionGatherer::visit_function_expression( FunctionExpression& fr )
|
|
|
|
|
{
|
|
|
|
|
reference( *fr.function_link );
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-14 12:56:36 +02:00
|
|
|
void ReferencedFunctionGatherer::visit_class_parameter_declaration( ClassParameterDeclaration& cpd )
|
|
|
|
|
{
|
|
|
|
|
reference( *cpd.constructor_link );
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:47:38 -07:00
|
|
|
void ReferencedFunctionGatherer::reference( FunctionLink& link )
|
|
|
|
|
{
|
|
|
|
|
if ( auto mfd = link.module_function_declaration() )
|
|
|
|
|
reference( mfd );
|
2020-09-07 12:35:17 -07:00
|
|
|
else if ( auto uf = link.user_function() )
|
|
|
|
|
reference( uf );
|
2020-08-24 01:47:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ReferencedFunctionGatherer::reference( ModuleFunctionDeclaration* mfd )
|
|
|
|
|
{
|
|
|
|
|
auto itr = unreferenced_module_function_declarations.find( mfd );
|
|
|
|
|
if ( itr != unreferenced_module_function_declarations.end() )
|
|
|
|
|
{
|
|
|
|
|
referenced_module_function_declarations.push_back( mfd );
|
|
|
|
|
unreferenced_module_function_declarations.erase( itr );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-07 12:35:17 -07:00
|
|
|
void ReferencedFunctionGatherer::reference( UserFunction* uf )
|
|
|
|
|
{
|
|
|
|
|
auto itr = unreferenced_user_functions.find( uf );
|
|
|
|
|
if ( itr != unreferenced_user_functions.end() )
|
|
|
|
|
{
|
|
|
|
|
referenced_user_functions.push_back( std::move( ( *itr ).second ) );
|
|
|
|
|
unreferenced_user_functions.erase( itr );
|
|
|
|
|
uf->accept( *this );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<UserFunction>>
|
|
|
|
|
ReferencedFunctionGatherer::take_referenced_user_functions()
|
|
|
|
|
{
|
|
|
|
|
return std::move( referenced_user_functions );
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-24 01:47:38 -07:00
|
|
|
std::vector<ModuleFunctionDeclaration*>
|
|
|
|
|
ReferencedFunctionGatherer::take_referenced_module_function_declarations()
|
|
|
|
|
{
|
|
|
|
|
return std::move( referenced_module_function_declarations );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|