polserver/pol-core/bscript/compiler/optimizer/BinaryOperatorWithStringOptimizer.h
turleypol c0bfd2f820
Escript Optimizer more types and operator (#794)
* compile time optimization:
int with doubles and strings
doubles with ints and strings
strings with ints and doubles

* bool with other types, more unary ops, float branch optimizer

* more tests
fixed bool to dbl compare

* output cleanup
more tests

* optimize string values in if statements, optimize ternary operator

* optimize elvis, addes missing files, code cleanup

* use array to keep unoptimized if branch in funcexpr tests

* missing include

* better readable testdata

* removed file

* optimize while and dowhile loops if predicate is a compile time known
value

* cleaner variant of loop optimization?

* added ConstantPredicateLoop Node used by the optimizer for constant loop
predicates
optimize repeat until loop
change tests to run the loops more then once to be sure they work
correctly

* test break/continue with label for constant-loop

* docs
2025-07-10 22:32:29 +02:00

31 lines
857 B
C++

#ifndef POLSERVER_BINARYOPERATORWITHSTRINGOPTIMIZER_H
#define POLSERVER_BINARYOPERATORWITHSTRINGOPTIMIZER_H
#include "bscript/compiler/ast/NodeVisitor.h"
#include <memory>
namespace Pol::Bscript::Compiler
{
class Expression;
class BinaryOperatorWithStringOptimizer : public NodeVisitor
{
public:
const StringValue& lhs;
const BinaryOperator& op;
std::unique_ptr<Expression> optimized_result;
BinaryOperatorWithStringOptimizer( StringValue& lhs, BinaryOperator& op );
void visit_children( Node& parent ) override;
void visit_string_value( StringValue& rhs ) override;
void visit_float_value( FloatValue& rhs ) override;
void visit_integer_value( IntegerValue& rhs ) override;
void visit_boolean_value( BooleanValue& rhs ) override;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_BINARYOPERATORWITHSTRINGOPTIMIZER_H