Skip to content

Commit

Permalink
Diagnostics: Keep track of replaced Node from Optimizer; Use canonica…
Browse files Browse the repository at this point in the history
…l path for module path names (#624)

* Keep track of replaced Node from Optimizer

* Use `Clib::FullPath` on module path names
  • Loading branch information
KevinEady committed Feb 26, 2024
1 parent 4902d74 commit 4615416
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 4 additions & 3 deletions pol-core/bscript/compiler/ast/Node.cpp
Expand Up @@ -4,18 +4,19 @@
namespace Pol::Bscript::Compiler
{
Node::Node( const SourceLocation& source_location, NodeVector children )
: children( std::move( children ) ), source_location( source_location )
: children( std::move( children ) ), unoptimized_node(), source_location( source_location )
{
}

Node::Node( const SourceLocation& source_location, std::unique_ptr<Node> child )
: source_location( source_location )
: unoptimized_node(), source_location( source_location )
{
children.reserve( 1 );
children.push_back( std::move( child ) );
}

Node::Node( const SourceLocation& source_location ) : children(), source_location( source_location )
Node::Node( const SourceLocation& source_location )
: children(), unoptimized_node(), source_location( source_location )
{
}

Expand Down
1 change: 1 addition & 0 deletions pol-core/bscript/compiler/ast/Node.h
Expand Up @@ -67,6 +67,7 @@ class Node
}

NodeVector children;
std::unique_ptr<Node> unoptimized_node;

const SourceLocation source_location;

Expand Down
4 changes: 2 additions & 2 deletions pol-core/bscript/compiler/astbuilder/SourceFileProcessor.cpp
Expand Up @@ -42,8 +42,8 @@ void SourceFileProcessor::use_module( const std::string& module_name,
SourceLocation& including_location,
long long* micros_counted )
{
std::string pathname = compilercfg.ModuleDirectory + module_name + ".em";

std::string pathname =
Clib::FullPath( ( compilercfg.ModuleDirectory + module_name + ".em" ).c_str() );
if ( workspace.source_files.find( pathname ) != workspace.source_files.end() )
return;

Expand Down
5 changes: 5 additions & 0 deletions pol-core/bscript/compiler/optimizer/Optimizer.cpp
Expand Up @@ -88,6 +88,11 @@ void Optimizer::visit_children( Node& node )

if ( optimized_replacement )
{
if ( dynamic_cast<Identifier*>( node.children[i].get() ) )
{
optimized_replacement->unoptimized_node.swap( node.children[i] );
}

node.children[i] = std::move( optimized_replacement );
}

Expand Down

0 comments on commit 4615416

Please sign in to comment.