polserver/pol-core/bscript/compiler/astbuilder/ModuleProcessor.cpp
Eric Swanson 6ce9c38de3
Add support for const declarations (#264)
Adds:
- analyzer/Constants: holds constant name -> value for lookup
- ast/ConstDeclaration: AST node for a const declaration
- optimizer/ConstValidator: validates that an optimized expression is valid to use as a constant.

the Optimizer converts Identifiers that refer to a constant to the optimized constant value.
2020-09-01 00:54:24 -07:00

43 lines
1.5 KiB
C++

#include "ModuleProcessor.h"
#include "compiler/Profile.h"
#include "compiler/ast/ConstDeclaration.h"
#include "compiler/ast/ModuleFunctionDeclaration.h"
#include "compiler/astbuilder/BuilderWorkspace.h"
#include "compiler/file/SourceFile.h"
#include "compiler/model/CompilerWorkspace.h"
namespace Pol::Bscript::Compiler
{
ModuleProcessor::ModuleProcessor( const SourceFileIdentifier& source_file_identifier,
BuilderWorkspace& workspace, std::string modulename )
: profile( workspace.profile ),
report( workspace.report ),
source_file_identifier( source_file_identifier ),
workspace( workspace ),
tree_builder( source_file_identifier, workspace ),
modulename( std::move( modulename ) )
{
}
antlrcpp::Any ModuleProcessor::visitModuleDeclarationStatement(
EscriptGrammar::EscriptParser::ModuleDeclarationStatementContext* ctx )
{
if ( auto moduleFunctionDeclaration = ctx->moduleFunctionDeclaration() )
{
auto ast =
tree_builder.module_function_declaration( moduleFunctionDeclaration, modulename );
workspace.function_resolver.register_module_function( ast.get() );
workspace.compiler_workspace.module_function_declarations.push_back( std::move( ast ) );
}
else if ( auto constStatement = ctx->constStatement() )
{
workspace.compiler_workspace.const_declarations.push_back(
tree_builder.const_declaration( constStatement ) );
}
return antlrcpp::Any();
}
} // namespace Pol::Bscript::Compiler