daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 01df23e | 2014-06-11 10:56:03 -0400 | [diff] [blame^] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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 _CONSTANT_UNION_INCLUDED_ |
| 8 | #define _CONSTANT_UNION_INCLUDED_ |
| 9 | |
alokp@chromium.org | 4e4facd | 2010-06-02 15:21:22 +0000 | [diff] [blame] | 10 | #include <assert.h> |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 11 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 12 | class ConstantUnion { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 13 | public: |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 14 | POOL_ALLOCATOR_NEW_DELETE(); |
apatrick@chromium.org | a1d8059 | 2012-01-25 21:52:10 +0000 | [diff] [blame] | 15 | ConstantUnion() |
| 16 | { |
| 17 | iConst = 0; |
shannon.woods%transgaming.com@gtempaccount.com | c0d0c22 | 2013-04-13 03:29:36 +0000 | [diff] [blame] | 18 | type = EbtVoid; |
apatrick@chromium.org | a1d8059 | 2012-01-25 21:52:10 +0000 | [diff] [blame] | 19 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 20 | |
Nicolas Capens | 01df23e | 2014-06-11 10:56:03 -0400 | [diff] [blame^] | 21 | bool cast(TBasicType newType, const ConstantUnion &constant) |
| 22 | { |
| 23 | switch (newType) |
| 24 | { |
| 25 | case EbtFloat: |
| 26 | switch (constant.type) |
| 27 | { |
| 28 | case EbtInt: setFConst(static_cast<float>(constant.getIConst())); break; |
| 29 | case EbtUInt: setFConst(static_cast<float>(constant.getUConst())); break; |
| 30 | case EbtBool: setFConst(static_cast<float>(constant.getBConst())); break; |
| 31 | case EbtFloat: setFConst(static_cast<float>(constant.getFConst())); break; |
| 32 | default: return false; |
| 33 | } |
| 34 | break; |
| 35 | case EbtInt: |
| 36 | switch (constant.type) |
| 37 | { |
| 38 | case EbtInt: setIConst(static_cast<int>(constant.getIConst())); break; |
| 39 | case EbtUInt: setIConst(static_cast<int>(constant.getUConst())); break; |
| 40 | case EbtBool: setIConst(static_cast<int>(constant.getBConst())); break; |
| 41 | case EbtFloat: setIConst(static_cast<int>(constant.getFConst())); break; |
| 42 | default: return false; |
| 43 | } |
| 44 | break; |
| 45 | case EbtUInt: |
| 46 | switch (constant.type) |
| 47 | { |
| 48 | case EbtInt: setUConst(static_cast<unsigned int>(constant.getIConst())); break; |
| 49 | case EbtUInt: setUConst(static_cast<unsigned int>(constant.getUConst())); break; |
| 50 | case EbtBool: setUConst(static_cast<unsigned int>(constant.getBConst())); break; |
| 51 | case EbtFloat: setUConst(static_cast<unsigned int>(constant.getFConst())); break; |
| 52 | default: return false; |
| 53 | } |
| 54 | break; |
| 55 | case EbtBool: |
| 56 | switch (constant.type) |
| 57 | { |
| 58 | case EbtInt: setBConst(constant.getIConst() != 0); break; |
| 59 | case EbtUInt: setBConst(constant.getUConst() != 0); break; |
| 60 | case EbtBool: setBConst(constant.getBConst()); break; |
| 61 | case EbtFloat: setBConst(constant.getFConst() != 0.0f); break; |
| 62 | default: return false; |
| 63 | } |
| 64 | break; |
| 65 | case EbtStruct: // Struct fields don't get cast |
| 66 | switch (constant.type) |
| 67 | { |
| 68 | case EbtInt: setIConst(constant.getIConst()); break; |
| 69 | case EbtUInt: setUConst(constant.getUConst()); break; |
| 70 | case EbtBool: setBConst(constant.getBConst()); break; |
| 71 | case EbtFloat: setFConst(constant.getFConst()); break; |
| 72 | default: return false; |
| 73 | } |
| 74 | break; |
| 75 | default: |
| 76 | return false; |
| 77 | } |
| 78 | |
| 79 | return true; |
| 80 | } |
| 81 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 82 | void setIConst(int i) {iConst = i; type = EbtInt; } |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 83 | void setUConst(unsigned int u) { uConst = u; type = EbtUInt; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 84 | void setFConst(float f) {fConst = f; type = EbtFloat; } |
| 85 | void setBConst(bool b) {bConst = b; type = EbtBool; } |
| 86 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 87 | int getIConst() const { return iConst; } |
Nicolas Capens | c0f7c61 | 2013-06-05 11:46:09 -0400 | [diff] [blame] | 88 | unsigned int getUConst() const { return uConst; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 89 | float getFConst() const { return fConst; } |
| 90 | bool getBConst() const { return bConst; } |
| 91 | |
| 92 | bool operator==(const int i) const |
| 93 | { |
daniel@transgaming.com | e90a0d5 | 2011-02-18 02:52:06 +0000 | [diff] [blame] | 94 | return i == iConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 95 | } |
| 96 | |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 97 | bool operator==(const unsigned int u) const |
| 98 | { |
| 99 | return u == uConst; |
| 100 | } |
| 101 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 102 | bool operator==(const float f) const |
| 103 | { |
daniel@transgaming.com | e90a0d5 | 2011-02-18 02:52:06 +0000 | [diff] [blame] | 104 | return f == fConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | bool operator==(const bool b) const |
| 108 | { |
daniel@transgaming.com | e90a0d5 | 2011-02-18 02:52:06 +0000 | [diff] [blame] | 109 | return b == bConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 110 | } |
| 111 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 112 | bool operator==(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 113 | { |
| 114 | if (constant.type != type) |
| 115 | return false; |
| 116 | |
| 117 | switch (type) { |
| 118 | case EbtInt: |
daniel@transgaming.com | e90a0d5 | 2011-02-18 02:52:06 +0000 | [diff] [blame] | 119 | return constant.iConst == iConst; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 120 | case EbtUInt: |
| 121 | return constant.uConst == uConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 122 | case EbtFloat: |
daniel@transgaming.com | e90a0d5 | 2011-02-18 02:52:06 +0000 | [diff] [blame] | 123 | return constant.fConst == fConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 124 | case EbtBool: |
daniel@transgaming.com | e90a0d5 | 2011-02-18 02:52:06 +0000 | [diff] [blame] | 125 | return constant.bConst == bConst; |
daniel@transgaming.com | cd3a1b9 | 2011-03-15 18:23:46 +0000 | [diff] [blame] | 126 | default: |
| 127 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 128 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | bool operator!=(const int i) const |
| 132 | { |
| 133 | return !operator==(i); |
| 134 | } |
| 135 | |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 136 | bool operator!=(const unsigned int u) const |
| 137 | { |
| 138 | return !operator==(u); |
| 139 | } |
| 140 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 141 | bool operator!=(const float f) const |
| 142 | { |
| 143 | return !operator==(f); |
| 144 | } |
| 145 | |
| 146 | bool operator!=(const bool b) const |
| 147 | { |
| 148 | return !operator==(b); |
| 149 | } |
| 150 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 151 | bool operator!=(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 152 | { |
| 153 | return !operator==(constant); |
| 154 | } |
| 155 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 156 | bool operator>(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 157 | { |
| 158 | assert(type == constant.type); |
| 159 | switch (type) { |
| 160 | case EbtInt: |
daniel@transgaming.com | b31f35a | 2011-02-11 13:19:35 +0000 | [diff] [blame] | 161 | return iConst > constant.iConst; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 162 | case EbtUInt: |
| 163 | return uConst > constant.uConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 164 | case EbtFloat: |
daniel@transgaming.com | b31f35a | 2011-02-11 13:19:35 +0000 | [diff] [blame] | 165 | return fConst > constant.fConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 166 | default: |
daniel@transgaming.com | b31f35a | 2011-02-11 13:19:35 +0000 | [diff] [blame] | 167 | return false; // Invalid operation, handled at semantic analysis |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 168 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 169 | } |
| 170 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 171 | bool operator<(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 172 | { |
| 173 | assert(type == constant.type); |
| 174 | switch (type) { |
| 175 | case EbtInt: |
daniel@transgaming.com | b31f35a | 2011-02-11 13:19:35 +0000 | [diff] [blame] | 176 | return iConst < constant.iConst; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 177 | case EbtUInt: |
| 178 | return uConst < constant.uConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 179 | case EbtFloat: |
daniel@transgaming.com | b31f35a | 2011-02-11 13:19:35 +0000 | [diff] [blame] | 180 | return fConst < constant.fConst; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 181 | default: |
daniel@transgaming.com | b31f35a | 2011-02-11 13:19:35 +0000 | [diff] [blame] | 182 | return false; // Invalid operation, handled at semantic analysis |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 183 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 184 | } |
| 185 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 186 | ConstantUnion operator+(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 187 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 188 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 189 | assert(type == constant.type); |
| 190 | switch (type) { |
| 191 | case EbtInt: returnValue.setIConst(iConst + constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 192 | case EbtUInt: returnValue.setUConst(uConst + constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 193 | case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break; |
| 194 | default: assert(false && "Default missing"); |
| 195 | } |
| 196 | |
| 197 | return returnValue; |
| 198 | } |
| 199 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 200 | ConstantUnion operator-(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 201 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 202 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 203 | assert(type == constant.type); |
| 204 | switch (type) { |
| 205 | case EbtInt: returnValue.setIConst(iConst - constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 206 | case EbtUInt: returnValue.setUConst(uConst - constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 207 | case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break; |
| 208 | default: assert(false && "Default missing"); |
| 209 | } |
| 210 | |
| 211 | return returnValue; |
| 212 | } |
| 213 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 214 | ConstantUnion operator*(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 215 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 216 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 217 | assert(type == constant.type); |
| 218 | switch (type) { |
| 219 | case EbtInt: returnValue.setIConst(iConst * constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 220 | case EbtUInt: returnValue.setUConst(uConst * constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 221 | case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break; |
| 222 | default: assert(false && "Default missing"); |
| 223 | } |
| 224 | |
| 225 | return returnValue; |
| 226 | } |
| 227 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 228 | ConstantUnion operator%(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 229 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 230 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 231 | assert(type == constant.type); |
| 232 | switch (type) { |
| 233 | case EbtInt: returnValue.setIConst(iConst % constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 234 | case EbtUInt: returnValue.setUConst(uConst % constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 235 | default: assert(false && "Default missing"); |
| 236 | } |
| 237 | |
| 238 | return returnValue; |
| 239 | } |
| 240 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 241 | ConstantUnion operator>>(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 242 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 243 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 244 | assert(type == constant.type); |
| 245 | switch (type) { |
| 246 | case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 247 | case EbtUInt: returnValue.setUConst(uConst >> constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 248 | default: assert(false && "Default missing"); |
| 249 | } |
| 250 | |
| 251 | return returnValue; |
| 252 | } |
| 253 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 254 | ConstantUnion operator<<(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 255 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 256 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 257 | assert(type == constant.type); |
| 258 | switch (type) { |
| 259 | case EbtInt: returnValue.setIConst(iConst << constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 260 | case EbtUInt: returnValue.setUConst(uConst << constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 261 | default: assert(false && "Default missing"); |
| 262 | } |
| 263 | |
| 264 | return returnValue; |
| 265 | } |
| 266 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 267 | ConstantUnion operator&(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 268 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 269 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 270 | assert(type == constant.type); |
| 271 | switch (type) { |
| 272 | case EbtInt: returnValue.setIConst(iConst & constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 273 | case EbtUInt: returnValue.setUConst(uConst & constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 274 | default: assert(false && "Default missing"); |
| 275 | } |
| 276 | |
| 277 | return returnValue; |
| 278 | } |
| 279 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 280 | ConstantUnion operator|(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 281 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 282 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 283 | assert(type == constant.type); |
| 284 | switch (type) { |
| 285 | case EbtInt: returnValue.setIConst(iConst | constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 286 | case EbtUInt: returnValue.setUConst(uConst | constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 287 | default: assert(false && "Default missing"); |
| 288 | } |
| 289 | |
| 290 | return returnValue; |
| 291 | } |
| 292 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 293 | ConstantUnion operator^(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 294 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 295 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 296 | assert(type == constant.type); |
| 297 | switch (type) { |
| 298 | case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break; |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 299 | case EbtUInt: returnValue.setUConst(uConst ^ constant.uConst); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 300 | default: assert(false && "Default missing"); |
| 301 | } |
| 302 | |
| 303 | return returnValue; |
| 304 | } |
| 305 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 306 | ConstantUnion operator&&(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 307 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 308 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 309 | assert(type == constant.type); |
| 310 | switch (type) { |
| 311 | case EbtBool: returnValue.setBConst(bConst && constant.bConst); break; |
| 312 | default: assert(false && "Default missing"); |
| 313 | } |
| 314 | |
| 315 | return returnValue; |
| 316 | } |
| 317 | |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 318 | ConstantUnion operator||(const ConstantUnion& constant) const |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 319 | { |
alokp@chromium.org | 6ff56fd | 2010-05-05 16:37:50 +0000 | [diff] [blame] | 320 | ConstantUnion returnValue; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 321 | assert(type == constant.type); |
| 322 | switch (type) { |
| 323 | case EbtBool: returnValue.setBConst(bConst || constant.bConst); break; |
| 324 | default: assert(false && "Default missing"); |
| 325 | } |
| 326 | |
| 327 | return returnValue; |
| 328 | } |
| 329 | |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 330 | TBasicType getType() const { return type; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 331 | private: |
| 332 | |
| 333 | union { |
| 334 | int iConst; // used for ivec, scalar ints |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 335 | unsigned int uConst; // used for uvec, scalar uints |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 336 | bool bConst; // used for bvec, scalar bools |
| 337 | float fConst; // used for vec, mat, scalar floats |
| 338 | } ; |
| 339 | |
| 340 | TBasicType type; |
| 341 | }; |
| 342 | |
| 343 | #endif // _CONSTANT_UNION_INCLUDED_ |