2026-07-25 23:01:18 +02:00
|
|
|
#include "bscript/compiler/ast/VarStatement.h"
|
2020-08-25 00:57:03 -07:00
|
|
|
|
2024-01-16 17:55:42 +01:00
|
|
|
|
2020-08-25 00:57:03 -07:00
|
|
|
#include <utility>
|
|
|
|
|
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/Expression.h"
|
|
|
|
|
#include "bscript/compiler/ast/NodeVisitor.h"
|
2020-08-25 00:57:03 -07:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
2024-08-10 15:27:25 +02:00
|
|
|
VarStatement::VarStatement( const SourceLocation& source_location, std::string scope,
|
|
|
|
|
std::string name, std::unique_ptr<Expression> initializer )
|
|
|
|
|
: Statement( source_location, std::move( initializer ) ),
|
|
|
|
|
scope( std::move( scope ) ),
|
|
|
|
|
name( std::move( name ) )
|
2020-08-25 00:57:03 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-10 15:27:25 +02:00
|
|
|
VarStatement::VarStatement( const SourceLocation& source_location, std::string scope,
|
|
|
|
|
std::string name )
|
|
|
|
|
: Statement( source_location ), scope( std::move( scope ) ), name( std::move( name ) )
|
2020-08-25 00:57:03 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-10 15:27:25 +02:00
|
|
|
VarStatement::VarStatement( const SourceLocation& source_location, std::string scope,
|
|
|
|
|
std::string name, bool initialize_as_empty_array )
|
2020-08-25 00:57:03 -07:00
|
|
|
: Statement( source_location ),
|
2024-08-10 15:27:25 +02:00
|
|
|
scope( std::move( scope ) ),
|
2020-08-25 00:57:03 -07:00
|
|
|
name( std::move( name ) ),
|
|
|
|
|
initialize_as_empty_array( initialize_as_empty_array )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VarStatement::accept( NodeVisitor& visitor )
|
|
|
|
|
{
|
|
|
|
|
visitor.visit_var_statement( *this );
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-12 06:51:44 +01:00
|
|
|
void VarStatement::describe_to( std::string& w ) const
|
2020-08-25 00:57:03 -07:00
|
|
|
{
|
2024-08-10 15:27:25 +02:00
|
|
|
auto scope_prefix = scope.empty() ? "" : fmt::format( "{}::", scope );
|
|
|
|
|
fmt::format_to( std::back_inserter( w ), "var-statement({}{}", scope_prefix, name );
|
2020-08-25 00:57:03 -07:00
|
|
|
if ( initialize_as_empty_array )
|
2024-01-12 06:51:44 +01:00
|
|
|
w += ", initialize-as-empty-array";
|
|
|
|
|
w += ")";
|
2020-08-25 00:57:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Pol::Bscript::Compiler
|