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 24 bool cast(TBasicType newType, const TConstantUnion &constant); 25 setIConst(int i)26 void setIConst(int i) 27 { 28 iConst = i; 29 type = EbtInt; 30 } setUConst(unsigned int u)31 void setUConst(unsigned int u) 32 { 33 uConst = u; 34 type = EbtUInt; 35 } setFConst(float f)36 void setFConst(float f) 37 { 38 fConst = f; 39 type = EbtFloat; 40 } setBConst(bool b)41 void setBConst(bool b) 42 { 43 bConst = b; 44 type = EbtBool; 45 } 46 setYuvCscStandardEXTConst(TYuvCscStandardEXT s)47 void setYuvCscStandardEXTConst(TYuvCscStandardEXT s) 48 { 49 yuvCscStandardEXTConst = s; 50 type = EbtYuvCscStandardEXT; 51 } 52 53 int getIConst() const; 54 unsigned int getUConst() const; 55 float getFConst() const; 56 bool getBConst() const; 57 bool isZero() const; 58 TYuvCscStandardEXT getYuvCscStandardEXTConst() const; 59 60 bool operator==(const int i) const; 61 bool operator==(const unsigned int u) const; 62 bool operator==(const float f) const; 63 bool operator==(const bool b) const; 64 bool operator==(const TYuvCscStandardEXT s) const; 65 bool operator==(const TConstantUnion &constant) const; 66 bool operator!=(const int i) const; 67 bool operator!=(const unsigned int u) const; 68 bool operator!=(const float f) const; 69 bool operator!=(const bool b) const; 70 bool operator!=(const TYuvCscStandardEXT s) const; 71 bool operator!=(const TConstantUnion &constant) const; 72 bool operator>(const TConstantUnion &constant) const; 73 bool operator<(const TConstantUnion &constant) const; 74 static TConstantUnion add(const TConstantUnion &lhs, 75 const TConstantUnion &rhs, 76 TDiagnostics *diag, 77 const TSourceLoc &line); 78 static TConstantUnion sub(const TConstantUnion &lhs, 79 const TConstantUnion &rhs, 80 TDiagnostics *diag, 81 const TSourceLoc &line); 82 static TConstantUnion mul(const TConstantUnion &lhs, 83 const TConstantUnion &rhs, 84 TDiagnostics *diag, 85 const TSourceLoc &line); 86 TConstantUnion operator%(const TConstantUnion &constant) const; 87 static TConstantUnion rshift(const TConstantUnion &lhs, 88 const TConstantUnion &rhs, 89 TDiagnostics *diag, 90 const TSourceLoc &line); 91 static TConstantUnion lshift(const TConstantUnion &lhs, 92 const TConstantUnion &rhs, 93 TDiagnostics *diag, 94 const TSourceLoc &line); 95 TConstantUnion operator&(const TConstantUnion &constant) const; 96 TConstantUnion operator|(const TConstantUnion &constant) const; 97 TConstantUnion operator^(const TConstantUnion &constant) const; 98 TConstantUnion operator&&(const TConstantUnion &constant) const; 99 TConstantUnion operator||(const TConstantUnion &constant) const; 100 getType()101 TBasicType getType() const { return type; } 102 103 private: 104 union 105 { 106 int iConst; // used for ivec, scalar ints 107 unsigned int uConst; // used for uvec, scalar uints 108 bool bConst; // used for bvec, scalar bools 109 float fConst; // used for vec, mat, scalar floats 110 TYuvCscStandardEXT yuvCscStandardEXTConst; 111 }; 112 113 TBasicType type; 114 }; 115 116 } // namespace sh 117 118 #endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_ 119