mirror of
				https://github.com/Laupetin/OpenAssetTools.git
				synced 2025-10-30 18:17:15 +00:00 
			
		
		
		
	Add expression parsing for menu parser
This commit is contained in:
		| @@ -385,11 +385,32 @@ const CommonExpressionBinaryOperationType CommonExpressionBinaryOperationType::O | ||||
|     } | ||||
| ); | ||||
|  | ||||
| CommonExpressionBinaryOperation::CommonExpressionBinaryOperation(std::unique_ptr<ICommonExpression> operand1, std::unique_ptr<ICommonExpression> operand2, | ||||
|                                                                  const CommonExpressionBinaryOperationType* operationType) | ||||
|     : m_operand1(std::move(operand1)), | ||||
|       m_operand2(std::move(operand2)), | ||||
|       m_operation_type(operationType) | ||||
| const CommonExpressionBinaryOperationType* const CommonExpressionBinaryOperationType::ALL_OPERATION_TYPES[static_cast<int>(BinaryOperationId::COUNT)] | ||||
| { | ||||
|     &OPERATION_ADD, | ||||
|     &OPERATION_SUBTRACT, | ||||
|     &OPERATION_MULTIPLY, | ||||
|     &OPERATION_DIVIDE, | ||||
|     &OPERATION_REMAINDER, | ||||
|     &OPERATION_BITWISE_AND, | ||||
|     &OPERATION_BITWISE_OR, | ||||
|     &OPERATION_SHIFT_LEFT, | ||||
|     &OPERATION_SHIFT_RIGHT, | ||||
|     &OPERATION_GREATER_THAN, | ||||
|     &OPERATION_GREATER_EQUAL_THAN, | ||||
|     &OPERATION_LESS_THAN, | ||||
|     &OPERATION_LESS_EQUAL_THAN, | ||||
|     &OPERATION_EQUALS, | ||||
|     &OPERATION_NOT_EQUAL, | ||||
|     &OPERATION_AND, | ||||
|     &OPERATION_OR | ||||
| }; | ||||
|  | ||||
| CommonExpressionBinaryOperation::CommonExpressionBinaryOperation(const CommonExpressionBinaryOperationType* operationType, std::unique_ptr<ICommonExpression> operand1, | ||||
|                                                                  std::unique_ptr<ICommonExpression> operand2) | ||||
|     : m_operation_type(operationType), | ||||
|       m_operand1(std::move(operand1)), | ||||
|       m_operand2(std::move(operand2)) | ||||
| { | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -23,6 +23,29 @@ namespace menu | ||||
|         LOGICAL_OR = 10 | ||||
|     }; | ||||
|  | ||||
|     enum class BinaryOperationId | ||||
|     { | ||||
|         ADD, | ||||
|         SUBTRACT, | ||||
|         MULTIPLY, | ||||
|         DIVIDE, | ||||
|         REMAINDER, | ||||
|         BITWISE_AND, | ||||
|         BITWISE_OR, | ||||
|         SHIFT_LEFT, | ||||
|         SHIFT_RIGHT, | ||||
|         GREATER_THAN, | ||||
|         GREATER_EQUAL_THAN, | ||||
|         LESS_THAN, | ||||
|         LESS_EQUAL_THAN, | ||||
|         EQUALS, | ||||
|         NOT_EQUAL, | ||||
|         AND, | ||||
|         OR, | ||||
|  | ||||
|         COUNT | ||||
|     }; | ||||
|  | ||||
|     class CommonExpressionBinaryOperationType | ||||
|     { | ||||
|     public: | ||||
| @@ -35,6 +58,7 @@ namespace menu | ||||
|     private: | ||||
|         CommonExpressionBinaryOperationType(std::string syntax, OperationPrecedence precedence, evaluation_function_t evaluationFunction); | ||||
|  | ||||
|     public: | ||||
|         static const CommonExpressionBinaryOperationType OPERATION_ADD; | ||||
|         static const CommonExpressionBinaryOperationType OPERATION_SUBTRACT; | ||||
|         static const CommonExpressionBinaryOperationType OPERATION_MULTIPLY; | ||||
| @@ -53,19 +77,19 @@ namespace menu | ||||
|         static const CommonExpressionBinaryOperationType OPERATION_AND; | ||||
|         static const CommonExpressionBinaryOperationType OPERATION_OR; | ||||
|  | ||||
|         static const CommonExpressionBinaryOperationType* const ALL_OPERATION_TYPES[]; | ||||
|         static const CommonExpressionBinaryOperationType* const ALL_OPERATION_TYPES[static_cast<int>(BinaryOperationId::COUNT)]; | ||||
|     }; | ||||
|  | ||||
|     class CommonExpressionBinaryOperation final : public ICommonExpression | ||||
|     { | ||||
|     public: | ||||
|         const CommonExpressionBinaryOperationType* m_operation_type; | ||||
|         std::unique_ptr<ICommonExpression> m_operand1; | ||||
|         std::unique_ptr<ICommonExpression> m_operand2; | ||||
|         const CommonExpressionBinaryOperationType* m_operation_type; | ||||
|  | ||||
|         CommonExpressionBinaryOperation(std::unique_ptr<ICommonExpression> operand1, | ||||
|                                         std::unique_ptr<ICommonExpression> operand2, | ||||
|                                         const CommonExpressionBinaryOperationType* operationType); | ||||
|         CommonExpressionBinaryOperation(const CommonExpressionBinaryOperationType* operationType, | ||||
|                                         std::unique_ptr<ICommonExpression> operand1, | ||||
|                                         std::unique_ptr<ICommonExpression> operand2); | ||||
|  | ||||
|         _NODISCARD bool Operand1NeedsParenthesis() const; | ||||
|         _NODISCARD bool Operand2NeedsParenthesis() const; | ||||
|   | ||||
| @@ -31,9 +31,15 @@ const CommonExpressionUnaryOperationType CommonExpressionUnaryOperationType::OPE | ||||
|     } | ||||
| ); | ||||
|  | ||||
| CommonExpressionUnaryOperation::CommonExpressionUnaryOperation(std::unique_ptr<ICommonExpression> operand, const CommonExpressionUnaryOperationType* operationType) | ||||
|     : m_operand(std::move(operand)), | ||||
|       m_operation_type(operationType) | ||||
| const CommonExpressionUnaryOperationType* const CommonExpressionUnaryOperationType::ALL_OPERATION_TYPES[static_cast<int>(UnaryOperationId::COUNT)] | ||||
| { | ||||
|     &OPERATION_NOT, | ||||
|     &OPERATION_BITWISE_NOT, | ||||
| }; | ||||
|  | ||||
| CommonExpressionUnaryOperation::CommonExpressionUnaryOperation(const CommonExpressionUnaryOperationType* operationType, std::unique_ptr<ICommonExpression> operand) | ||||
|     : m_operation_type(operationType), | ||||
|       m_operand(std::move(operand)) | ||||
| { | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -9,6 +9,14 @@ | ||||
|  | ||||
| namespace menu | ||||
| { | ||||
|     enum class UnaryOperationId | ||||
|     { | ||||
|         NOT, | ||||
|         BITWISE_NOT, | ||||
|  | ||||
|         COUNT | ||||
|     }; | ||||
|  | ||||
|     class CommonExpressionUnaryOperationType | ||||
|     { | ||||
|     public: | ||||
| @@ -20,20 +28,20 @@ namespace menu | ||||
|     private: | ||||
|         CommonExpressionUnaryOperationType(std::string syntax, evaluation_function_t evaluationFunction); | ||||
|  | ||||
|     public: | ||||
|         static const CommonExpressionUnaryOperationType OPERATION_NOT; | ||||
|         static const CommonExpressionUnaryOperationType OPERATION_BITWISE_NOT; | ||||
|  | ||||
|         static const CommonExpressionUnaryOperationType* const ALL_OPERATION_TYPES[]; | ||||
|         static const CommonExpressionUnaryOperationType* const ALL_OPERATION_TYPES[static_cast<int>(UnaryOperationId::COUNT)]; | ||||
|     }; | ||||
|  | ||||
|     class CommonExpressionUnaryOperation final : public ICommonExpression | ||||
|     { | ||||
|     public: | ||||
|         std::unique_ptr<ICommonExpression> m_operand; | ||||
|         const CommonExpressionUnaryOperationType* m_operation_type; | ||||
|         std::unique_ptr<ICommonExpression> m_operand; | ||||
|  | ||||
|         CommonExpressionUnaryOperation(std::unique_ptr<ICommonExpression> operand, | ||||
|             const CommonExpressionUnaryOperationType* operationType); | ||||
|         CommonExpressionUnaryOperation(const CommonExpressionUnaryOperationType* operationType, std::unique_ptr<ICommonExpression> operand); | ||||
|  | ||||
|         _NODISCARD bool OperandNeedsParenthesis() const; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user