summaryrefslogtreecommitdiff
path: root/src/video_core/shader/expr.cpp
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-10-05 12:02:51 -0400
committerGravatar GitHub2019-10-05 12:02:51 -0400
commit47ccfabe18db3691a09f211fc4aec465ee186c2a (patch)
tree8bd02e8d5e16dee8522e29d21c711ef98282bb52 /src/video_core/shader/expr.cpp
parentMerge pull request #2888 from FernandoS27/decompiler2 (diff)
parentvideo_core/control_flow: Eliminate variable shadowing warnings (diff)
downloadyuzu-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.cpp39
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
12namespace VideoCommon::Shader { 10namespace VideoCommon::Shader {
11namespace {
12bool ExprIsBoolean(const Expr& expr) {
13 return std::holds_alternative<ExprBoolean>(*expr);
14}
15
16bool ExprBooleanGet(const Expr& expr) {
17 return std::get_if<ExprBoolean>(expr.get())->value;
18}
19} // Anonymous namespace
13 20
14bool ExprAnd::operator==(const ExprAnd& b) const { 21bool 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
25bool ExprAnd::operator!=(const ExprAnd& b) const {
26 return !operator==(b);
27}
28
18bool ExprOr::operator==(const ExprOr& b) const { 29bool 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
22bool ExprNot::operator==(const ExprNot& b) const { 33bool ExprOr::operator!=(const ExprOr& b) const {
23 return (*operand1 == *b.operand1); 34 return !operator==(b);
24} 35}
25 36
26bool ExprIsBoolean(Expr expr) { 37bool ExprNot::operator==(const ExprNot& b) const {
27 return std::holds_alternative<ExprBoolean>(*expr); 38 return *operand1 == *b.operand1;
28} 39}
29 40
30bool ExprBooleanGet(Expr expr) { 41bool ExprNot::operator!=(const ExprNot& b) const {
31 return std::get_if<ExprBoolean>(expr.get())->value; 42 return !operator==(b);
32} 43}
33 44
34Expr MakeExprNot(Expr first) { 45Expr 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
41Expr MakeExprAnd(Expr first, Expr second) { 52Expr 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
51Expr MakeExprOr(Expr first, Expr second) { 62Expr 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
61bool ExprAreEqual(Expr first, Expr second) { 72bool ExprAreEqual(const Expr& first, const Expr& second) {
62 return (*first) == (*second); 73 return (*first) == (*second);
63} 74}
64 75
65bool ExprAreOpposite(Expr first, Expr second) { 76bool 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
75bool ExprIsTrue(Expr first) { 86bool ExprIsTrue(const Expr& first) {
76 if (ExprIsBoolean(first)) { 87 if (ExprIsBoolean(first)) {
77 return ExprBooleanGet(first); 88 return ExprBooleanGet(first);
78 } 89 }