diff options
| author | 2019-10-05 12:02:51 -0400 | |
|---|---|---|
| committer | 2019-10-05 12:02:51 -0400 | |
| commit | 47ccfabe18db3691a09f211fc4aec465ee186c2a (patch) | |
| tree | 8bd02e8d5e16dee8522e29d21c711ef98282bb52 /src/video_core/shader/expr.cpp | |
| parent | Merge pull request #2888 from FernandoS27/decompiler2 (diff) | |
| parent | video_core/control_flow: Eliminate variable shadowing warnings (diff) | |
| download | yuzu-47ccfabe18db3691a09f211fc4aec465ee186c2a.tar.gz yuzu-47ccfabe18db3691a09f211fc4aec465ee186c2a.tar.xz yuzu-47ccfabe18db3691a09f211fc4aec465ee186c2a.zip | |
Merge pull request #2944 from lioncash/ast
video_core/shader: Minor changes
Diffstat (limited to 'src/video_core/shader/expr.cpp')
| -rw-r--r-- | src/video_core/shader/expr.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/video_core/shader/expr.cpp b/src/video_core/shader/expr.cpp index ca633ffb1..2647865d4 100644 --- a/src/video_core/shader/expr.cpp +++ b/src/video_core/shader/expr.cpp | |||
| @@ -2,40 +2,51 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | 5 | #include <memory> |
| 8 | #include <variant> | 6 | #include <variant> |
| 9 | 7 | ||
| 10 | #include "video_core/shader/expr.h" | 8 | #include "video_core/shader/expr.h" |
| 11 | 9 | ||
| 12 | namespace VideoCommon::Shader { | 10 | namespace VideoCommon::Shader { |
| 11 | namespace { | ||
| 12 | bool ExprIsBoolean(const Expr& expr) { | ||
| 13 | return std::holds_alternative<ExprBoolean>(*expr); | ||
| 14 | } | ||
| 15 | |||
| 16 | bool ExprBooleanGet(const Expr& expr) { | ||
| 17 | return std::get_if<ExprBoolean>(expr.get())->value; | ||
| 18 | } | ||
| 19 | } // Anonymous namespace | ||
| 13 | 20 | ||
| 14 | bool ExprAnd::operator==(const ExprAnd& b) const { | 21 | bool ExprAnd::operator==(const ExprAnd& b) const { |
| 15 | return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); | 22 | return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); |
| 16 | } | 23 | } |
| 17 | 24 | ||
| 25 | bool ExprAnd::operator!=(const ExprAnd& b) const { | ||
| 26 | return !operator==(b); | ||
| 27 | } | ||
| 28 | |||
| 18 | bool ExprOr::operator==(const ExprOr& b) const { | 29 | bool ExprOr::operator==(const ExprOr& b) const { |
| 19 | return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); | 30 | return (*operand1 == *b.operand1) && (*operand2 == *b.operand2); |
| 20 | } | 31 | } |
| 21 | 32 | ||
| 22 | bool ExprNot::operator==(const ExprNot& b) const { | 33 | bool ExprOr::operator!=(const ExprOr& b) const { |
| 23 | return (*operand1 == *b.operand1); | 34 | return !operator==(b); |
| 24 | } | 35 | } |
| 25 | 36 | ||
| 26 | bool ExprIsBoolean(Expr expr) { | 37 | bool ExprNot::operator==(const ExprNot& b) const { |
| 27 | return std::holds_alternative<ExprBoolean>(*expr); | 38 | return *operand1 == *b.operand1; |
| 28 | } | 39 | } |
| 29 | 40 | ||
| 30 | bool ExprBooleanGet(Expr expr) { | 41 | bool ExprNot::operator!=(const ExprNot& b) const { |
| 31 | return std::get_if<ExprBoolean>(expr.get())->value; | 42 | return !operator==(b); |
| 32 | } | 43 | } |
| 33 | 44 | ||
| 34 | Expr MakeExprNot(Expr first) { | 45 | Expr MakeExprNot(Expr first) { |
| 35 | if (std::holds_alternative<ExprNot>(*first)) { | 46 | if (std::holds_alternative<ExprNot>(*first)) { |
| 36 | return std::get_if<ExprNot>(first.get())->operand1; | 47 | return std::get_if<ExprNot>(first.get())->operand1; |
| 37 | } | 48 | } |
| 38 | return MakeExpr<ExprNot>(first); | 49 | return MakeExpr<ExprNot>(std::move(first)); |
| 39 | } | 50 | } |
| 40 | 51 | ||
| 41 | Expr MakeExprAnd(Expr first, Expr second) { | 52 | Expr MakeExprAnd(Expr first, Expr second) { |
| @@ -45,7 +56,7 @@ Expr MakeExprAnd(Expr first, Expr second) { | |||
| 45 | if (ExprIsBoolean(second)) { | 56 | if (ExprIsBoolean(second)) { |
| 46 | return ExprBooleanGet(second) ? first : second; | 57 | return ExprBooleanGet(second) ? first : second; |
| 47 | } | 58 | } |
| 48 | return MakeExpr<ExprAnd>(first, second); | 59 | return MakeExpr<ExprAnd>(std::move(first), std::move(second)); |
| 49 | } | 60 | } |
| 50 | 61 | ||
| 51 | Expr MakeExprOr(Expr first, Expr second) { | 62 | Expr MakeExprOr(Expr first, Expr second) { |
| @@ -55,14 +66,14 @@ Expr MakeExprOr(Expr first, Expr second) { | |||
| 55 | if (ExprIsBoolean(second)) { | 66 | if (ExprIsBoolean(second)) { |
| 56 | return ExprBooleanGet(second) ? second : first; | 67 | return ExprBooleanGet(second) ? second : first; |
| 57 | } | 68 | } |
| 58 | return MakeExpr<ExprOr>(first, second); | 69 | return MakeExpr<ExprOr>(std::move(first), std::move(second)); |
| 59 | } | 70 | } |
| 60 | 71 | ||
| 61 | bool ExprAreEqual(Expr first, Expr second) { | 72 | bool ExprAreEqual(const Expr& first, const Expr& second) { |
| 62 | return (*first) == (*second); | 73 | return (*first) == (*second); |
| 63 | } | 74 | } |
| 64 | 75 | ||
| 65 | bool ExprAreOpposite(Expr first, Expr second) { | 76 | bool ExprAreOpposite(const Expr& first, const Expr& second) { |
| 66 | if (std::holds_alternative<ExprNot>(*first)) { | 77 | if (std::holds_alternative<ExprNot>(*first)) { |
| 67 | return ExprAreEqual(std::get_if<ExprNot>(first.get())->operand1, second); | 78 | return ExprAreEqual(std::get_if<ExprNot>(first.get())->operand1, second); |
| 68 | } | 79 | } |
| @@ -72,7 +83,7 @@ bool ExprAreOpposite(Expr first, Expr second) { | |||
| 72 | return false; | 83 | return false; |
| 73 | } | 84 | } |
| 74 | 85 | ||
| 75 | bool ExprIsTrue(Expr first) { | 86 | bool ExprIsTrue(const Expr& first) { |
| 76 | if (ExprIsBoolean(first)) { | 87 | if (ExprIsBoolean(first)) { |
| 77 | return ExprBooleanGet(first); | 88 | return ExprBooleanGet(first); |
| 78 | } | 89 | } |