diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2018-12-30 11:51:12 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2019-10-11 17:13:58 -0500 |
| commit | bf63f85d732db2fdab169823f2cf8a5fcbde0ec4 (patch) | |
| tree | 2879c641ca412bfcae6c22bc10b2b0f07ab0577d /Source/Core/InputCommon/ControlReference/ExpressionParser.cpp | |
| parent | f3192ca06de1007545bf6c3a49ddc83fb615a642 (diff) | |
ExpressionParser: Add multiplication and division operators. (division by zero evaluates as zero). Don't clamp result of addition operator. Clamping will be done later.
Diffstat (limited to 'Source/Core/InputCommon/ControlReference/ExpressionParser.cpp')
| -rw-r--r-- | Source/Core/InputCommon/ControlReference/ExpressionParser.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp index 81760aff2b..2ca7efd98a 100644 --- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp +++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp @@ -28,6 +28,8 @@ enum TokenType TOK_OR, TOK_NOT, TOK_ADD, + TOK_MUL, + TOK_DIV, TOK_CONTROL, TOK_LITERAL, }; @@ -44,6 +46,10 @@ inline std::string OpName(TokenType op) return "Not"; case TOK_ADD: return "Add"; + case TOK_MUL: + return "Mul"; + case TOK_DIV: + return "Div"; default: assert(false); return ""; @@ -78,6 +84,10 @@ public: return "!"; case TOK_ADD: return "+"; + case TOK_MUL: + return "*"; + case TOK_DIV: + return "/"; case TOK_CONTROL: return "Device(" + data + ")"; case TOK_LITERAL: @@ -170,6 +180,10 @@ public: return Token(TOK_NOT); case '+': return Token(TOK_ADD); + case '*': + return Token(TOK_MUL); + case '/': + return Token(TOK_DIV); case '\'': return GetLiteral(); case '`': @@ -266,7 +280,14 @@ public: case TOK_OR: return std::max(lhsValue, rhsValue); case TOK_ADD: - return std::min(lhsValue + rhsValue, 1.0); + return lhsValue + rhsValue; + case TOK_MUL: + return lhsValue * rhsValue; + case TOK_DIV: + { + const ControlState result = lhsValue / rhsValue; + return std::isinf(result) ? 0.0 : result; + } default: assert(false); return 0; @@ -508,6 +529,8 @@ private: case TOK_AND: case TOK_OR: case TOK_ADD: + case TOK_MUL: + case TOK_DIV: return true; default: return false; |
