polserver/pol-core/bscript/compiler/optimizer/UnaryOperatorOptimizer.h
Eric Swanson a77ddd028e
New compiler: Add optimized unary expressions (#244)
Adds:
- UnaryOperator: AST node for unary operators -, ++, --, and so forth
- UnaryOperatorOptimizer: optimizes a unary operator with its operand
  - now integer and float negation, and integer inversion
  - later x[y]++ to a single instruction

Also:
- automatically include basic.em, which includes some parameter defaults like -1.

This allows the compiler to generate output for a hello, world script with the exact same .ecl output as the legacy compiler.
2020-08-26 19:24:47 -07:00

35 lines
791 B
C++

#ifndef POLSERVER_UNARYOPERATOROPTIMIZER_H
#define POLSERVER_UNARYOPERATOROPTIMIZER_H
#include "compiler/ast/NodeVisitor.h"
#include <memory>
namespace Pol::Bscript::Compiler
{
class Expression;
class Identifier;
class IntegerValue;
class FloatValue;
class UnaryOperator;
class UnaryOperatorOptimizer : public NodeVisitor
{
public:
explicit UnaryOperatorOptimizer( UnaryOperator& unary_operator );
std::unique_ptr<Expression> optimize();
void visit_children( Node& ) override;
void visit_float_value( FloatValue& literal ) override;
void visit_integer_value( IntegerValue& literal ) override;
private:
std::unique_ptr<Expression> optimized_result;
UnaryOperator& unary_operator;
};
} // namespace Pol::Bscript::Compiler
#endif // POLSERVER_UNARYOPERATOROPTIMIZER_H