#pragma once #include #include #include #include "ICommonExpression.h" #include "CommonExpressionValue.h" namespace menu { // https://en.cppreference.com/w/cpp/language/operator_precedence enum class OperationPrecedence { MULTIPLICATION_DIVISION_REMAINDER = 1, ADDITION_SUBTRACTION = 2, BITWISE_SHIFT = 3, RELATIONAL_GREATER_LESS_THAN = 4, RELATIONAL_EQUALS = 5, BITWISE_AND = 6, BITWISE_OR = 8, LOGICAL_AND = 9, LOGICAL_OR = 10 }; class CommonExpressionBinaryOperationType { public: using evaluation_function_t = std::function; std::string m_syntax; OperationPrecedence m_precedence; evaluation_function_t m_evaluation_function; private: CommonExpressionBinaryOperationType(std::string syntax, OperationPrecedence precedence, evaluation_function_t evaluationFunction); static const CommonExpressionBinaryOperationType OPERATION_ADD; static const CommonExpressionBinaryOperationType OPERATION_SUBTRACT; static const CommonExpressionBinaryOperationType OPERATION_MULTIPLY; static const CommonExpressionBinaryOperationType OPERATION_DIVIDE; static const CommonExpressionBinaryOperationType OPERATION_REMAINDER; static const CommonExpressionBinaryOperationType OPERATION_BITWISE_AND; static const CommonExpressionBinaryOperationType OPERATION_BITWISE_OR; static const CommonExpressionBinaryOperationType OPERATION_SHIFT_LEFT; static const CommonExpressionBinaryOperationType OPERATION_SHIFT_RIGHT; static const CommonExpressionBinaryOperationType OPERATION_GREATER_THAN; static const CommonExpressionBinaryOperationType OPERATION_GREATER_EQUAL_THAN; static const CommonExpressionBinaryOperationType OPERATION_LESS_THAN; static const CommonExpressionBinaryOperationType OPERATION_LESS_EQUAL_THAN; static const CommonExpressionBinaryOperationType OPERATION_EQUALS; static const CommonExpressionBinaryOperationType OPERATION_NOT_EQUAL; static const CommonExpressionBinaryOperationType OPERATION_AND; static const CommonExpressionBinaryOperationType OPERATION_OR; static const CommonExpressionBinaryOperationType* const ALL_OPERATION_TYPES[]; }; class CommonExpressionBinaryOperation final : public ICommonExpression { public: std::unique_ptr m_operand1; std::unique_ptr m_operand2; const CommonExpressionBinaryOperationType* m_operation_type; CommonExpressionBinaryOperation(std::unique_ptr operand1, std::unique_ptr operand2, const CommonExpressionBinaryOperationType* operationType); _NODISCARD bool Operand1NeedsParenthesis() const; _NODISCARD bool Operand2NeedsParenthesis() const; bool IsStatic() override; CommonExpressionValue Evaluate() override; }; }