1 // 2 // Copyright 2002 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #ifndef COMPILER_TRANSLATOR_CONSTANTUNION_H_ 8 #define COMPILER_TRANSLATOR_CONSTANTUNION_H_ 9 10 #include "compiler/translator/BaseTypes.h" 11 #include "compiler/translator/Common.h" 12 13 namespace sh 14 { 15 16 class TDiagnostics; 17 18 class TConstantUnion 19 { 20 public: 21 POOL_ALLOCATOR_NEW_DELETE 22 TConstantUnion(); 23 TConstantUnion(int i); 24 TConstantUnion(unsigned int u); 25 TConstantUnion(float f); 26 TConstantUnion(bool b); 27 28 bool cast(TBasicType newType, const TConstantUnion &constant); 29 setIConst(int i)30 void setIConst(int i) 31 { 32 iConst = i; 33 type = EbtInt; 34 } setUConst(unsigned int u)35 void setUConst(unsigned int u) 36 { 37 uConst = u; 38 type = EbtUInt; 39 } setFConst(float f)40 void setFConst(float f) 41 { 42 fConst = f; 43 type = EbtFloat; 44 } setBConst(bool b)45 void setBConst(bool b) 46 { 47 bConst = b; 48 type = EbtBool; 49 } 50 setYuvCscStandardEXTConst(TYuvCscStandardEXT s)51 void setYuvCscStandardEXTConst(TYuvCscStandardEXT s) 52 { 53 yuvCscStandardEXTConst = s; 54 type = EbtYuvCscStandardEXT; 55 } 56 57 int getIConst() const; 58 unsigned int getUConst() const; 59 float getFConst() const; 60 bool getBConst() const; 61 bool isZero() const; 62 TYuvCscStandardEXT getYuvCscStandardEXTConst() const; 63 64 bool operator==(const int i) const; 65 bool operator==(const unsigned int u) const; 66 bool operator==(const float f) const; 67 bool operator==(const bool b) const; 68 bool operator==(const TYuvCscStandardEXT s) const; 69 bool operator==(const TConstantUnion &constant) const; 70 bool operator!=(const int i) const; 71 bool operator!=(const unsigned int u) const; 72 bool operator!=(const float f) const; 73 bool operator!=(const bool b) const; 74 bool operator!=(const TYuvCscStandardEXT s) const; 75 bool operator!=(const TConstantUnion &constant) const; 76 bool operator>(const TConstantUnion &constant) const; 77 bool operator<(const TConstantUnion &constant) const; 78 static TConstantUnion add(const TConstantUnion &lhs, 79 const TConstantUnion &rhs, 80 TDiagnostics *diag, 81 const TSourceLoc &line); 82 static TConstantUnion sub(const TConstantUnion &lhs, 83 const TConstantUnion &rhs, 84 TDiagnostics *diag, 85 const TSourceLoc &line); 86 static TConstantUnion mul(const TConstantUnion &lhs, 87 const TConstantUnion &rhs, 88 TDiagnostics *diag, 89 const TSourceLoc &line); 90 TConstantUnion operator%(const TConstantUnion &constant) const; 91 static TConstantUnion rshift(const TConstantUnion &lhs, 92 const TConstantUnion &rhs, 93 TDiagnostics *diag, 94 const TSourceLoc &line); 95 static TConstantUnion lshift(const TConstantUnion &lhs, 96 const TConstantUnion &rhs, 97 TDiagnostics *diag, 98 const TSourceLoc &line); 99 TConstantUnion operator&(const TConstantUnion &constant) const; 100 TConstantUnion operator|(const TConstantUnion &constant) const; 101 TConstantUnion operator^(const TConstantUnion &constant) const; 102 TConstantUnion operator&&(const TConstantUnion &constant) const; 103 TConstantUnion operator||(const TConstantUnion &constant) const; 104 getType()105 TBasicType getType() const { return type; } 106 107 private: 108 union 109 { 110 int iConst; // used for ivec, scalar ints 111 unsigned int uConst; // used for uvec, scalar uints 112 bool bConst; // used for bvec, scalar bools 113 float fConst; // used for vec, mat, scalar floats 114 TYuvCscStandardEXT yuvCscStandardEXTConst; 115 }; 116 117 TBasicType type; 118 }; 119 120 } // namespace sh 121 122 #endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_ 123