2026-07-25 23:01:18 +02:00
|
|
|
#include "bscript/compiler/astbuilder/TreeBuilder.h"
|
2020-08-18 03:07:51 -07:00
|
|
|
|
2021-08-28 22:26:15 +02:00
|
|
|
#include "bscript/compiler/Antlr4Inc.h"
|
2021-02-25 16:53:22 +01:00
|
|
|
#include "bscript/compiler/ast/ValueConsumer.h"
|
|
|
|
|
#include "bscript/compiler/astbuilder/BuilderWorkspace.h"
|
|
|
|
|
#include "bscript/compiler/file/SourceLocation.h"
|
2020-08-18 03:07:51 -07:00
|
|
|
|
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
|
|
|
{
|
|
|
|
|
TreeBuilder::TreeBuilder( const SourceFileIdentifier& source_file_identifier,
|
|
|
|
|
BuilderWorkspace& workspace )
|
|
|
|
|
: report( workspace.report ),
|
|
|
|
|
source_file_identifier( source_file_identifier ),
|
|
|
|
|
workspace( workspace )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 08:19:05 -07:00
|
|
|
std::unique_ptr<Expression> TreeBuilder::consume_expression_result(
|
|
|
|
|
std::unique_ptr<Expression> expression )
|
|
|
|
|
{
|
|
|
|
|
return std::make_unique<ValueConsumer>( expression->source_location, std::move( expression ) );
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 03:07:51 -07:00
|
|
|
SourceLocation TreeBuilder::location_for( antlr4::ParserRuleContext& ctx ) const
|
|
|
|
|
{
|
|
|
|
|
return SourceLocation( &source_file_identifier, ctx );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SourceLocation TreeBuilder::location_for( antlr4::tree::TerminalNode& ctx ) const
|
|
|
|
|
{
|
|
|
|
|
return SourceLocation( &source_file_identifier, ctx );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string TreeBuilder::text( antlr4::tree::TerminalNode* terminal )
|
|
|
|
|
{
|
|
|
|
|
return terminal->getSymbol()->getText();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-10 15:27:25 +02:00
|
|
|
std::string TreeBuilder::text( antlr4::Token* token )
|
|
|
|
|
{
|
|
|
|
|
return token->getText();
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 03:07:51 -07:00
|
|
|
} // namespace Pol::Bscript::Compiler
|