2020-08-10 00:42:37 -07:00
|
|
|
#include "CompilerWorkspaceBuilder.h"
|
|
|
|
|
|
|
|
|
|
#include "compiler/LegacyFunctionOrder.h"
|
|
|
|
|
#include "compiler/Profile.h"
|
|
|
|
|
#include "compiler/Report.h"
|
2020-08-17 22:53:03 -07:00
|
|
|
#include "compiler/ast/Statement.h"
|
|
|
|
|
#include "compiler/ast/TopLevelStatements.h"
|
2020-08-14 23:01:19 -07:00
|
|
|
#include "compiler/astbuilder/BuilderWorkspace.h"
|
2020-08-18 23:32:57 -07:00
|
|
|
#include "compiler/astbuilder/SourceFileProcessor.h"
|
2020-08-14 13:54:20 -07:00
|
|
|
#include "compiler/file/SourceFile.h"
|
2020-08-10 00:42:37 -07:00
|
|
|
#include "compiler/file/SourceFileIdentifier.h"
|
|
|
|
|
#include "compiler/file/SourceLocation.h"
|
|
|
|
|
#include "compiler/model/CompilerWorkspace.h"
|
|
|
|
|
|
2020-08-10 03:20:29 -07:00
|
|
|
namespace Pol::Bscript::Compiler
|
2020-08-10 00:42:37 -07:00
|
|
|
{
|
2020-08-16 17:22:16 -07:00
|
|
|
CompilerWorkspaceBuilder::CompilerWorkspaceBuilder( SourceFileCache& em_cache,
|
|
|
|
|
SourceFileCache& inc_cache,
|
|
|
|
|
Profile& profile, Report& report )
|
|
|
|
|
: em_cache( em_cache ), inc_cache( inc_cache ), profile( profile ), report( report )
|
2020-08-10 00:42:37 -07:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<CompilerWorkspace> CompilerWorkspaceBuilder::build(
|
2020-08-14 13:54:20 -07:00
|
|
|
const std::string& pathname, const LegacyFunctionOrder* /*legacy_function_order*/ )
|
2020-08-10 00:42:37 -07:00
|
|
|
{
|
|
|
|
|
auto compiler_workspace = std::make_unique<CompilerWorkspace>();
|
2020-08-16 17:22:16 -07:00
|
|
|
BuilderWorkspace workspace( *compiler_workspace, em_cache, inc_cache, profile, report );
|
2020-08-10 00:42:37 -07:00
|
|
|
|
|
|
|
|
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 {};
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 23:32:57 -07:00
|
|
|
SourceFileProcessor src_processor( *ident, workspace, true );
|
|
|
|
|
|
2020-08-10 00:42:37 -07:00
|
|
|
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;
|
2020-08-10 00:42:37 -07:00
|
|
|
|
2020-08-17 22:53:03 -07:00
|
|
|
compiler_workspace->top_level_statements =
|
|
|
|
|
std::make_unique<TopLevelStatements>( source_location );
|
|
|
|
|
|
2020-08-26 19:24:47 -07:00
|
|
|
src_processor.use_module( "basic", source_location );
|
2020-08-23 15:01:39 -07:00
|
|
|
src_processor.use_module( "basicio", source_location );
|
2020-08-18 23:32:57 -07:00
|
|
|
src_processor.process_source( *sf );
|
|
|
|
|
|
2020-08-10 00:42:37 -07:00
|
|
|
return compiler_workspace;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 03:20:29 -07:00
|
|
|
} // namespace Pol::Bscript::Compiler
|