mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* all except pol * pol and includes under defines * something weird has happened * remove own folder from include searchpath * fixed remaining, adapted include style for external headers * missing include
74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
#include "bscript/compiler/optimizer/BinaryOperatorOptimizer.h"
|
|
|
|
#include "bscript/compiler/ast/BinaryOperator.h"
|
|
#include "bscript/compiler/ast/BinaryOperatorShortCircuit.h"
|
|
#include "bscript/compilercfg.h"
|
|
|
|
#include "bscript/compiler/optimizer/BinaryOperatorShortCircuitOptimizer.h"
|
|
#include "bscript/compiler/optimizer/BinaryOperatorWithBooleanOptimizer.h"
|
|
#include "bscript/compiler/optimizer/BinaryOperatorWithFloatOptimizer.h"
|
|
#include "bscript/compiler/optimizer/BinaryOperatorWithIntegerOptimizer.h"
|
|
#include "bscript/compiler/optimizer/BinaryOperatorWithStringOptimizer.h"
|
|
#include "bscript/compiler/optimizer/ShortCircuitCombiner.h"
|
|
|
|
namespace Pol::Bscript::Compiler
|
|
{
|
|
BinaryOperatorOptimizer::BinaryOperatorOptimizer( BinaryOperator& op, Report& report )
|
|
: op( op ), report( report )
|
|
{
|
|
}
|
|
|
|
std::unique_ptr<Expression> BinaryOperatorOptimizer::optimize()
|
|
{
|
|
op.lhs().accept( *this );
|
|
|
|
// second parse step
|
|
if ( compilercfg.ShortCircuitEvaluation )
|
|
{
|
|
BinaryOperatorShortCircuitOptimizer shortcircuit{ report };
|
|
if ( !optimized_result )
|
|
op.accept( shortcircuit );
|
|
else
|
|
optimized_result->accept( shortcircuit );
|
|
if ( shortcircuit.optimized_result )
|
|
{
|
|
optimized_result = std::move( shortcircuit.optimized_result );
|
|
// third parse step
|
|
ShortCircuitCombiner combiner{ report };
|
|
optimized_result->accept( combiner );
|
|
}
|
|
}
|
|
return std::move( optimized_result );
|
|
}
|
|
|
|
void BinaryOperatorOptimizer::visit_children( Node& ) {}
|
|
|
|
void BinaryOperatorOptimizer::visit_boolean_value( BooleanValue& lhs )
|
|
{
|
|
BinaryOperatorWithBooleanOptimizer optimizer( lhs, op, report );
|
|
op.rhs().accept( optimizer );
|
|
optimized_result = std::move( optimizer.optimized_result );
|
|
}
|
|
|
|
void BinaryOperatorOptimizer::visit_float_value( FloatValue& lhs )
|
|
{
|
|
BinaryOperatorWithFloatOptimizer optimizer( lhs, op, report );
|
|
op.rhs().accept( optimizer );
|
|
optimized_result = std::move( optimizer.optimized_result );
|
|
}
|
|
|
|
void BinaryOperatorOptimizer::visit_integer_value( IntegerValue& lhs )
|
|
{
|
|
BinaryOperatorWithIntegerOptimizer optimizer( lhs, op, report );
|
|
op.rhs().accept( optimizer );
|
|
optimized_result = std::move( optimizer.optimized_result );
|
|
}
|
|
|
|
void BinaryOperatorOptimizer::visit_string_value( StringValue& lhs )
|
|
{
|
|
BinaryOperatorWithStringOptimizer optimizer( lhs, op );
|
|
op.rhs().accept( optimizer );
|
|
optimized_result = std::move( optimizer.optimized_result );
|
|
}
|
|
|
|
} // namespace Pol::Bscript::Compiler
|