polserver/pol-core/bscript/compiler/astbuilder/CompilerWorkspaceBuilder.cpp

64 lines
2.2 KiB
C++
Raw Permalink Normal View History

#include "CompilerWorkspaceBuilder.h"
#include "compiler/LegacyFunctionOrder.h"
#include "compiler/Profile.h"
#include "compiler/Report.h"
#include "compiler/ast/Statement.h"
#include "compiler/ast/TopLevelStatements.h"
2020-08-14 23:01:19 -07:00
#include "compiler/astbuilder/BuilderWorkspace.h"
#include "compiler/astbuilder/SourceFileProcessor.h"
2020-08-14 13:54:20 -07:00
#include "compiler/file/SourceFile.h"
#include "compiler/file/SourceFileIdentifier.h"
#include "compiler/file/SourceLocation.h"
#include "compiler/model/CompilerWorkspace.h"
namespace Pol::Bscript::Compiler
{
CompilerWorkspaceBuilder::CompilerWorkspaceBuilder( SourceFileCache& em_cache,
SourceFileCache& inc_cache,
Profile& profile, Report& report )
: em_cache( em_cache ), inc_cache( inc_cache ), profile( profile ), report( report )
{
}
std::unique_ptr<CompilerWorkspace> CompilerWorkspaceBuilder::build(
2020-08-14 13:54:20 -07:00
const std::string& pathname, const LegacyFunctionOrder* /*legacy_function_order*/ )
{
auto compiler_workspace = std::make_unique<CompilerWorkspace>();
BuilderWorkspace workspace( *compiler_workspace, em_cache, inc_cache, profile, report );
auto ident = std::make_unique<SourceFileIdentifier>( 0, pathname );
2020-08-14 13:54:20 -07:00
SourceLocation source_location( ident.get(), 0, 0 );
if ( SourceFile::enforced_case_sensitivity_mismatch( source_location, pathname, report ) )
{
report.error( *ident, "Refusing to load '", pathname, "'.\n" );
return {};
}
auto sf = SourceFile::load( *ident, profile, report );
if ( !sf || report.error_count() )
{
report.error( *ident, "Unable to load '", pathname, "'.\n" );
return {};
}
SourceFileProcessor src_processor( *ident, workspace, true );
workspace.compiler_workspace.referenced_source_file_identifiers.push_back( std::move( ident ) );
2020-08-14 13:54:20 -07:00
workspace.source_files[sf->pathname] = sf;
compiler_workspace->top_level_statements =
std::make_unique<TopLevelStatements>( source_location );
src_processor.use_module( "basic", source_location );
src_processor.use_module( "basicio", source_location );
src_processor.process_source( *sf );
return compiler_workspace;
}
} // namespace Pol::Bscript::Compiler