mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* Update grammar * WIP with tracking classes - Refactor AvailableUserFunction to AvailableParseTree - Track ClassDeclarationContexts similarly to user functions * Skeleton AST + tracking * Finish up AST building * Implement AST building - TODO decide better name for UserFunctionBuilder/Visitor, since it does both user functions and classes * Update Prettifier * Crude, first-round semantic analysis + codegen - Currently, no real difference from regular functions * Move class var statements to top level statements * Add semantic analysis for base class existence * Introduce ClassInstance AST node for generating `this` parameter * Skeleton create class instance instruction * Default ctor; 'this' byref; Error if multiple same baseclass * Update grammar for scoped funcrefs and scoped identifiers * Update prettifier, builders for scoped funcref, identifiers * Fix CI issues - Styling - Shadowing * Add grammar tests for scope; Remove scope from switch label * Final draft todos - Rename `VarStatement::class_name` to `scope` - Comment why identifiers dont have scopes in enum declarations - Remove code comment
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#include "TreeBuilder.h"
|
|
|
|
#include "bscript/compiler/Antlr4Inc.h"
|
|
#include "bscript/compiler/ast/ValueConsumer.h"
|
|
#include "bscript/compiler/astbuilder/BuilderWorkspace.h"
|
|
#include "bscript/compiler/file/SourceLocation.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
TreeBuilder::TreeBuilder( const SourceFileIdentifier& source_file_identifier,
|
|
BuilderWorkspace& workspace )
|
|
: report( workspace.report ),
|
|
source_file_identifier( source_file_identifier ),
|
|
workspace( workspace )
|
|
{
|
|
}
|
|
|
|
std::unique_ptr<Expression> TreeBuilder::consume_expression_result(
|
|
std::unique_ptr<Expression> expression )
|
|
{
|
|
return std::make_unique<ValueConsumer>( expression->source_location, std::move( expression ) );
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
std::string TreeBuilder::text( antlr4::Token* token )
|
|
{
|
|
return token->getText();
|
|
}
|
|
|
|
} // namespace Pol::Bscript::Compiler
|