RetroArch
ConstantUnion.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2013 LunarG, Inc.
4 // Copyright (C) 2017 ARM Limited.
5 //
6 // All rights reserved.
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions
10 // are met:
11 //
12 // Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above
16 // copyright notice, this list of conditions and the following
17 // disclaimer in the documentation and/or other materials provided
18 // with the distribution.
19 //
20 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
21 // contributors may be used to endorse or promote products derived
22 // from this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 // POSSIBILITY OF SUCH DAMAGE.
36 //
37 
38 #ifndef _CONSTANT_UNION_INCLUDED_
39 #define _CONSTANT_UNION_INCLUDED_
40 
41 #include "../Include/Common.h"
42 #include "../Include/BaseTypes.h"
43 
44 namespace glslang {
45 
46 class TConstUnion {
47 public:
49 
51 
52  void setI8Const(signed char i)
53  {
54  i8Const = i;
55  type = EbtInt8;
56  }
57 
58  void setU8Const(unsigned char u)
59  {
60  u8Const = u;
61  type = EbtUint8;
62  }
63 
64  void setI16Const(signed short i)
65  {
66  i16Const = i;
67  type = EbtInt16;
68  }
69 
70  void setU16Const(unsigned short u)
71  {
72  u16Const = u;
73  type = EbtUint16;
74  }
75 
76  void setIConst(int i)
77  {
78  iConst = i;
79  type = EbtInt;
80  }
81 
82  void setUConst(unsigned int u)
83  {
84  uConst = u;
85  type = EbtUint;
86  }
87 
88  void setI64Const(long long i64)
89  {
90  i64Const = i64;
91  type = EbtInt64;
92  }
93 
94  void setU64Const(unsigned long long u64)
95  {
96  u64Const = u64;
97  type = EbtUint64;
98  }
99 
100  void setDConst(double d)
101  {
102  dConst = d;
103  type = EbtDouble;
104  }
105 
106  void setBConst(bool b)
107  {
108  bConst = b;
109  type = EbtBool;
110  }
111 
112  void setSConst(const TString* s)
113  {
114  sConst = s;
115  type = EbtString;
116  }
117 
118  signed char getI8Const() const { return i8Const; }
119  unsigned char getU8Const() const { return u8Const; }
120  signed short getI16Const() const { return i16Const; }
121  unsigned short getU16Const() const { return u16Const; }
122  int getIConst() const { return iConst; }
123  unsigned int getUConst() const { return uConst; }
124  long long getI64Const() const { return i64Const; }
125  unsigned long long getU64Const() const { return u64Const; }
126  double getDConst() const { return dConst; }
127  bool getBConst() const { return bConst; }
128  const TString* getSConst() const { return sConst; }
129 
130  bool operator==(const signed char i) const
131  {
132  if (i == i8Const)
133  return true;
134 
135  return false;
136  }
137 
138  bool operator==(const unsigned char u) const
139  {
140  if (u == u8Const)
141  return true;
142 
143  return false;
144  }
145 
146  bool operator==(const signed short i) const
147  {
148  if (i == i16Const)
149  return true;
150 
151  return false;
152  }
153 
154  bool operator==(const unsigned short u) const
155  {
156  if (u == u16Const)
157  return true;
158 
159  return false;
160  }
161 
162  bool operator==(const int i) const
163  {
164  if (i == iConst)
165  return true;
166 
167  return false;
168  }
169 
170  bool operator==(const unsigned int u) const
171  {
172  if (u == uConst)
173  return true;
174 
175  return false;
176  }
177 
178  bool operator==(const long long i64) const
179  {
180  if (i64 == i64Const)
181  return true;
182 
183  return false;
184  }
185 
186  bool operator==(const unsigned long long u64) const
187  {
188  if (u64 == u64Const)
189  return true;
190 
191  return false;
192  }
193 
194  bool operator==(const double d) const
195  {
196  if (d == dConst)
197  return true;
198 
199  return false;
200  }
201 
202  bool operator==(const bool b) const
203  {
204  if (b == bConst)
205  return true;
206 
207  return false;
208  }
209 
210  bool operator==(const TConstUnion& constant) const
211  {
212  if (constant.type != type)
213  return false;
214 
215  switch (type) {
216  case EbtInt16:
217  if (constant.i16Const == i16Const)
218  return true;
219 
220  break;
221  case EbtUint16:
222  if (constant.u16Const == u16Const)
223  return true;
224 
225  break;
226  case EbtInt8:
227  if (constant.i8Const == i8Const)
228  return true;
229 
230  break;
231  case EbtUint8:
232  if (constant.u8Const == u8Const)
233  return true;
234 
235  break;
236  case EbtInt:
237  if (constant.iConst == iConst)
238  return true;
239 
240  break;
241  case EbtUint:
242  if (constant.uConst == uConst)
243  return true;
244 
245  break;
246  case EbtInt64:
247  if (constant.i64Const == i64Const)
248  return true;
249 
250  break;
251  case EbtUint64:
252  if (constant.u64Const == u64Const)
253  return true;
254 
255  break;
256  case EbtDouble:
257  if (constant.dConst == dConst)
258  return true;
259 
260  break;
261  case EbtBool:
262  if (constant.bConst == bConst)
263  return true;
264 
265  break;
266  default:
267  assert(false && "Default missing");
268  }
269 
270  return false;
271  }
272 
273  bool operator!=(const signed char i) const
274  {
275  return !operator==(i);
276  }
277 
278  bool operator!=(const unsigned char u) const
279  {
280  return !operator==(u);
281  }
282 
283  bool operator!=(const signed short i) const
284  {
285  return !operator==(i);
286  }
287 
288  bool operator!=(const unsigned short u) const
289  {
290  return !operator==(u);
291  }
292 
293  bool operator!=(const int i) const
294  {
295  return !operator==(i);
296  }
297 
298  bool operator!=(const unsigned int u) const
299  {
300  return !operator==(u);
301  }
302 
303  bool operator!=(const long long i) const
304  {
305  return !operator==(i);
306  }
307 
308  bool operator!=(const unsigned long long u) const
309  {
310  return !operator==(u);
311  }
312 
313  bool operator!=(const float f) const
314  {
315  return !operator==(f);
316  }
317 
318  bool operator!=(const bool b) const
319  {
320  return !operator==(b);
321  }
322 
323  bool operator!=(const TConstUnion& constant) const
324  {
325  return !operator==(constant);
326  }
327 
328  bool operator>(const TConstUnion& constant) const
329  {
330  assert(type == constant.type);
331  switch (type) {
332  case EbtInt8:
333  if (i8Const > constant.i8Const)
334  return true;
335 
336  return false;
337  case EbtUint8:
338  if (u8Const > constant.u8Const)
339  return true;
340 
341  return false;
342  case EbtInt16:
343  if (i16Const > constant.i16Const)
344  return true;
345 
346  return false;
347  case EbtUint16:
348  if (u16Const > constant.u16Const)
349  return true;
350 
351  return false;
352  case EbtInt:
353  if (iConst > constant.iConst)
354  return true;
355 
356  return false;
357  case EbtUint:
358  if (uConst > constant.uConst)
359  return true;
360 
361  return false;
362  case EbtInt64:
363  if (i64Const > constant.i64Const)
364  return true;
365 
366  return false;
367  case EbtUint64:
368  if (u64Const > constant.u64Const)
369  return true;
370 
371  return false;
372  case EbtDouble:
373  if (dConst > constant.dConst)
374  return true;
375 
376  return false;
377  default:
378  assert(false && "Default missing");
379  return false;
380  }
381  }
382 
383  bool operator<(const TConstUnion& constant) const
384  {
385  assert(type == constant.type);
386  switch (type) {
387  case EbtInt8:
388  if (i8Const < constant.i8Const)
389  return true;
390 
391  return false;
392  case EbtUint8:
393  if (u8Const < constant.u8Const)
394  return true;
395 
396  return false;
397  case EbtInt16:
398  if (i16Const < constant.i16Const)
399  return true;
400 
401  return false;
402  case EbtUint16:
403  if (u16Const < constant.u16Const)
404  return true;
405 
406  return false;
407  case EbtInt:
408  if (iConst < constant.iConst)
409  return true;
410 
411  return false;
412  case EbtUint:
413  if (uConst < constant.uConst)
414  return true;
415 
416  return false;
417  case EbtInt64:
418  if (i64Const < constant.i64Const)
419  return true;
420 
421  return false;
422  case EbtUint64:
423  if (u64Const < constant.u64Const)
424  return true;
425 
426  return false;
427  case EbtDouble:
428  if (dConst < constant.dConst)
429  return true;
430 
431  return false;
432  default:
433  assert(false && "Default missing");
434  return false;
435  }
436  }
437 
438  TConstUnion operator+(const TConstUnion& constant) const
439  {
440  TConstUnion returnValue;
441  assert(type == constant.type);
442  switch (type) {
443  case EbtInt8: returnValue.setI8Const(i8Const + constant.i8Const); break;
444  case EbtInt16: returnValue.setI16Const(i16Const + constant.i16Const); break;
445  case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
446  case EbtInt64: returnValue.setI64Const(i64Const + constant.i64Const); break;
447  case EbtUint8: returnValue.setU8Const(u8Const + constant.u8Const); break;
448  case EbtUint16: returnValue.setU16Const(u16Const + constant.u16Const); break;
449  case EbtUint: returnValue.setUConst(uConst + constant.uConst); break;
450  case EbtUint64: returnValue.setU64Const(u64Const + constant.u64Const); break;
451  case EbtDouble: returnValue.setDConst(dConst + constant.dConst); break;
452  default: assert(false && "Default missing");
453  }
454 
455  return returnValue;
456  }
457 
458  TConstUnion operator-(const TConstUnion& constant) const
459  {
460  TConstUnion returnValue;
461  assert(type == constant.type);
462  switch (type) {
463  case EbtInt8: returnValue.setI8Const(i8Const - constant.i8Const); break;
464  case EbtInt16: returnValue.setI16Const(i16Const - constant.i16Const); break;
465  case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
466  case EbtInt64: returnValue.setI64Const(i64Const - constant.i64Const); break;
467  case EbtUint8: returnValue.setU8Const(u8Const - constant.u8Const); break;
468  case EbtUint16: returnValue.setU16Const(u16Const - constant.u16Const); break;
469  case EbtUint: returnValue.setUConst(uConst - constant.uConst); break;
470  case EbtUint64: returnValue.setU64Const(u64Const - constant.u64Const); break;
471  case EbtDouble: returnValue.setDConst(dConst - constant.dConst); break;
472  default: assert(false && "Default missing");
473  }
474 
475  return returnValue;
476  }
477 
478  TConstUnion operator*(const TConstUnion& constant) const
479  {
480  TConstUnion returnValue;
481  assert(type == constant.type);
482  switch (type) {
483  case EbtInt8: returnValue.setI8Const(i8Const * constant.i8Const); break;
484  case EbtInt16: returnValue.setI16Const(i16Const * constant.i16Const); break;
485  case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
486  case EbtInt64: returnValue.setI64Const(i64Const * constant.i64Const); break;
487  case EbtUint8: returnValue.setU8Const(u8Const * constant.u8Const); break;
488  case EbtUint16: returnValue.setU16Const(u16Const * constant.u16Const); break;
489  case EbtUint: returnValue.setUConst(uConst * constant.uConst); break;
490  case EbtUint64: returnValue.setU64Const(u64Const * constant.u64Const); break;
491  case EbtDouble: returnValue.setDConst(dConst * constant.dConst); break;
492  default: assert(false && "Default missing");
493  }
494 
495  return returnValue;
496  }
497 
498  TConstUnion operator%(const TConstUnion& constant) const
499  {
500  TConstUnion returnValue;
501  assert(type == constant.type);
502  switch (type) {
503  case EbtInt8: returnValue.setI8Const(i8Const % constant.i8Const); break;
504  case EbtInt16: returnValue.setI8Const(i8Const % constant.i16Const); break;
505  case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
506  case EbtInt64: returnValue.setI64Const(i64Const % constant.i64Const); break;
507  case EbtUint8: returnValue.setU8Const(u8Const % constant.u8Const); break;
508  case EbtUint16: returnValue.setU16Const(u16Const % constant.u16Const); break;
509  case EbtUint: returnValue.setUConst(uConst % constant.uConst); break;
510  case EbtUint64: returnValue.setU64Const(u64Const % constant.u64Const); break;
511  default: assert(false && "Default missing");
512  }
513 
514  return returnValue;
515  }
516 
517  TConstUnion operator>>(const TConstUnion& constant) const
518  {
519  TConstUnion returnValue;
520  switch (type) {
521  case EbtInt8:
522  switch (constant.type) {
523  case EbtInt8: returnValue.setI8Const(i8Const >> constant.i8Const); break;
524  case EbtUint8: returnValue.setI8Const(i8Const >> constant.u8Const); break;
525  case EbtInt16: returnValue.setI8Const(i8Const >> constant.i16Const); break;
526  case EbtUint16: returnValue.setI8Const(i8Const >> constant.u16Const); break;
527  case EbtInt: returnValue.setI8Const(i8Const >> constant.iConst); break;
528  case EbtUint: returnValue.setI8Const(i8Const >> constant.uConst); break;
529  case EbtInt64: returnValue.setI8Const(i8Const >> constant.i64Const); break;
530  case EbtUint64: returnValue.setI8Const(i8Const >> constant.u64Const); break;
531  default: assert(false && "Default missing");
532  }
533  break;
534  case EbtUint8:
535  switch (constant.type) {
536  case EbtInt8: returnValue.setU8Const(u8Const >> constant.i8Const); break;
537  case EbtUint8: returnValue.setU8Const(u8Const >> constant.u8Const); break;
538  case EbtInt16: returnValue.setU8Const(u8Const >> constant.i16Const); break;
539  case EbtUint16: returnValue.setU8Const(u8Const >> constant.u16Const); break;
540  case EbtInt: returnValue.setU8Const(u8Const >> constant.iConst); break;
541  case EbtUint: returnValue.setU8Const(u8Const >> constant.uConst); break;
542  case EbtInt64: returnValue.setU8Const(u8Const >> constant.i64Const); break;
543  case EbtUint64: returnValue.setU8Const(u8Const >> constant.u64Const); break;
544  default: assert(false && "Default missing");
545  }
546  break;
547  case EbtInt16:
548  switch (constant.type) {
549  case EbtInt8: returnValue.setI16Const(i16Const >> constant.i8Const); break;
550  case EbtUint8: returnValue.setI16Const(i16Const >> constant.u8Const); break;
551  case EbtInt16: returnValue.setI16Const(i16Const >> constant.i16Const); break;
552  case EbtUint16: returnValue.setI16Const(i16Const >> constant.u16Const); break;
553  case EbtInt: returnValue.setI16Const(i16Const >> constant.iConst); break;
554  case EbtUint: returnValue.setI16Const(i16Const >> constant.uConst); break;
555  case EbtInt64: returnValue.setI16Const(i16Const >> constant.i64Const); break;
556  case EbtUint64: returnValue.setI16Const(i16Const >> constant.u64Const); break;
557  default: assert(false && "Default missing");
558  }
559  break;
560  case EbtUint16:
561  switch (constant.type) {
562  case EbtInt8: returnValue.setU16Const(u16Const >> constant.i8Const); break;
563  case EbtUint8: returnValue.setU16Const(u16Const >> constant.u8Const); break;
564  case EbtInt16: returnValue.setU16Const(u16Const >> constant.i16Const); break;
565  case EbtUint16: returnValue.setU16Const(u16Const >> constant.u16Const); break;
566  case EbtInt: returnValue.setU16Const(u16Const >> constant.iConst); break;
567  case EbtUint: returnValue.setU16Const(u16Const >> constant.uConst); break;
568  case EbtInt64: returnValue.setU16Const(u16Const >> constant.i64Const); break;
569  case EbtUint64: returnValue.setU16Const(u16Const >> constant.u64Const); break;
570  default: assert(false && "Default missing");
571  }
572  break;
573  case EbtInt:
574  switch (constant.type) {
575  case EbtInt8: returnValue.setIConst(iConst >> constant.i8Const); break;
576  case EbtUint8: returnValue.setIConst(iConst >> constant.u8Const); break;
577  case EbtInt16: returnValue.setIConst(iConst >> constant.i16Const); break;
578  case EbtUint16: returnValue.setIConst(iConst >> constant.u16Const); break;
579  case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
580  case EbtUint: returnValue.setIConst(iConst >> constant.uConst); break;
581  case EbtInt64: returnValue.setIConst(iConst >> constant.i64Const); break;
582  case EbtUint64: returnValue.setIConst(iConst >> constant.u64Const); break;
583  default: assert(false && "Default missing");
584  }
585  break;
586  case EbtUint:
587  switch (constant.type) {
588  case EbtInt8: returnValue.setUConst(uConst >> constant.i8Const); break;
589  case EbtUint8: returnValue.setUConst(uConst >> constant.u8Const); break;
590  case EbtInt16: returnValue.setUConst(uConst >> constant.i16Const); break;
591  case EbtUint16: returnValue.setUConst(uConst >> constant.u16Const); break;
592  case EbtInt: returnValue.setUConst(uConst >> constant.iConst); break;
593  case EbtUint: returnValue.setUConst(uConst >> constant.uConst); break;
594  case EbtInt64: returnValue.setUConst(uConst >> constant.i64Const); break;
595  case EbtUint64: returnValue.setUConst(uConst >> constant.u64Const); break;
596  default: assert(false && "Default missing");
597  }
598  break;
599  case EbtInt64:
600  switch (constant.type) {
601  case EbtInt8: returnValue.setI64Const(i64Const >> constant.i8Const); break;
602  case EbtUint8: returnValue.setI64Const(i64Const >> constant.u8Const); break;
603  case EbtInt16: returnValue.setI64Const(i64Const >> constant.i16Const); break;
604  case EbtUint16: returnValue.setI64Const(i64Const >> constant.u16Const); break;
605  case EbtInt: returnValue.setI64Const(i64Const >> constant.iConst); break;
606  case EbtUint: returnValue.setI64Const(i64Const >> constant.uConst); break;
607  case EbtInt64: returnValue.setI64Const(i64Const >> constant.i64Const); break;
608  case EbtUint64: returnValue.setI64Const(i64Const >> constant.u64Const); break;
609  default: assert(false && "Default missing");
610  }
611  break;
612  case EbtUint64:
613  switch (constant.type) {
614  case EbtInt8: returnValue.setU64Const(u64Const >> constant.i8Const); break;
615  case EbtUint8: returnValue.setU64Const(u64Const >> constant.u8Const); break;
616  case EbtInt16: returnValue.setU64Const(u64Const >> constant.i16Const); break;
617  case EbtUint16: returnValue.setU64Const(u64Const >> constant.u16Const); break;
618  case EbtInt: returnValue.setU64Const(u64Const >> constant.iConst); break;
619  case EbtUint: returnValue.setU64Const(u64Const >> constant.uConst); break;
620  case EbtInt64: returnValue.setU64Const(u64Const >> constant.i64Const); break;
621  case EbtUint64: returnValue.setU64Const(u64Const >> constant.u64Const); break;
622  default: assert(false && "Default missing");
623  }
624  break;
625  default: assert(false && "Default missing");
626  }
627 
628  return returnValue;
629  }
630 
631  TConstUnion operator<<(const TConstUnion& constant) const
632  {
633  TConstUnion returnValue;
634  switch (type) {
635  case EbtInt8:
636  switch (constant.type) {
637  case EbtInt8: returnValue.setI8Const(i8Const << constant.i8Const); break;
638  case EbtUint8: returnValue.setI8Const(i8Const << constant.u8Const); break;
639  case EbtInt16: returnValue.setI8Const(i8Const << constant.i16Const); break;
640  case EbtUint16: returnValue.setI8Const(i8Const << constant.u16Const); break;
641  case EbtInt: returnValue.setI8Const(i8Const << constant.iConst); break;
642  case EbtUint: returnValue.setI8Const(i8Const << constant.uConst); break;
643  case EbtInt64: returnValue.setI8Const(i8Const << constant.i64Const); break;
644  case EbtUint64: returnValue.setI8Const(i8Const << constant.u64Const); break;
645  default: assert(false && "Default missing");
646  }
647  break;
648  case EbtUint8:
649  switch (constant.type) {
650  case EbtInt8: returnValue.setU8Const(u8Const << constant.i8Const); break;
651  case EbtUint8: returnValue.setU8Const(u8Const << constant.u8Const); break;
652  case EbtInt16: returnValue.setU8Const(u8Const << constant.i16Const); break;
653  case EbtUint16: returnValue.setU8Const(u8Const << constant.u16Const); break;
654  case EbtInt: returnValue.setU8Const(u8Const << constant.iConst); break;
655  case EbtUint: returnValue.setU8Const(u8Const << constant.uConst); break;
656  case EbtInt64: returnValue.setU8Const(u8Const << constant.i64Const); break;
657  case EbtUint64: returnValue.setU8Const(u8Const << constant.u64Const); break;
658  default: assert(false && "Default missing");
659  }
660  break;
661  case EbtInt16:
662  switch (constant.type) {
663  case EbtInt8: returnValue.setI16Const(i16Const << constant.i8Const); break;
664  case EbtUint8: returnValue.setI16Const(i16Const << constant.u8Const); break;
665  case EbtInt16: returnValue.setI16Const(i16Const << constant.i16Const); break;
666  case EbtUint16: returnValue.setI16Const(i16Const << constant.u16Const); break;
667  case EbtInt: returnValue.setI16Const(i16Const << constant.iConst); break;
668  case EbtUint: returnValue.setI16Const(i16Const << constant.uConst); break;
669  case EbtInt64: returnValue.setI16Const(i16Const << constant.i64Const); break;
670  case EbtUint64: returnValue.setI16Const(i16Const << constant.u64Const); break;
671  default: assert(false && "Default missing");
672  }
673  break;
674  case EbtUint16:
675  switch (constant.type) {
676  case EbtInt8: returnValue.setU16Const(u16Const << constant.i8Const); break;
677  case EbtUint8: returnValue.setU16Const(u16Const << constant.u8Const); break;
678  case EbtInt16: returnValue.setU16Const(u16Const << constant.i16Const); break;
679  case EbtUint16: returnValue.setU16Const(u16Const << constant.u16Const); break;
680  case EbtInt: returnValue.setU16Const(u16Const << constant.iConst); break;
681  case EbtUint: returnValue.setU16Const(u16Const << constant.uConst); break;
682  case EbtInt64: returnValue.setU16Const(u16Const << constant.i64Const); break;
683  case EbtUint64: returnValue.setU16Const(u16Const << constant.u64Const); break;
684  default: assert(false && "Default missing");
685  }
686  break;
687  case EbtInt:
688  switch (constant.type) {
689  case EbtInt8: returnValue.setIConst(iConst << constant.i8Const); break;
690  case EbtUint8: returnValue.setIConst(iConst << constant.u8Const); break;
691  case EbtInt16: returnValue.setIConst(iConst << constant.i16Const); break;
692  case EbtUint16: returnValue.setIConst(iConst << constant.u16Const); break;
693  case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
694  case EbtUint: returnValue.setIConst(iConst << constant.uConst); break;
695  case EbtInt64: returnValue.setIConst(iConst << constant.i64Const); break;
696  case EbtUint64: returnValue.setIConst(iConst << constant.u64Const); break;
697  default: assert(false && "Default missing");
698  }
699  break;
700  case EbtUint:
701  switch (constant.type) {
702  case EbtInt8: returnValue.setUConst(uConst << constant.i8Const); break;
703  case EbtUint8: returnValue.setUConst(uConst << constant.u8Const); break;
704  case EbtInt16: returnValue.setUConst(uConst << constant.i16Const); break;
705  case EbtUint16: returnValue.setUConst(uConst << constant.u16Const); break;
706  case EbtInt: returnValue.setUConst(uConst << constant.iConst); break;
707  case EbtUint: returnValue.setUConst(uConst << constant.uConst); break;
708  case EbtInt64: returnValue.setUConst(uConst << constant.i64Const); break;
709  case EbtUint64: returnValue.setUConst(uConst << constant.u64Const); break;
710  default: assert(false && "Default missing");
711  }
712  break;
713  case EbtInt64:
714  switch (constant.type) {
715  case EbtInt8: returnValue.setI64Const(i64Const << constant.i8Const); break;
716  case EbtUint8: returnValue.setI64Const(i64Const << constant.u8Const); break;
717  case EbtInt16: returnValue.setI64Const(i64Const << constant.i16Const); break;
718  case EbtUint16: returnValue.setI64Const(i64Const << constant.u16Const); break;
719  case EbtInt: returnValue.setI64Const(i64Const << constant.iConst); break;
720  case EbtUint: returnValue.setI64Const(i64Const << constant.uConst); break;
721  case EbtInt64: returnValue.setI64Const(i64Const << constant.i64Const); break;
722  case EbtUint64: returnValue.setI64Const(i64Const << constant.u64Const); break;
723  default: assert(false && "Default missing");
724  }
725  break;
726  case EbtUint64:
727  switch (constant.type) {
728  case EbtInt8: returnValue.setU64Const(u64Const << constant.i8Const); break;
729  case EbtUint8: returnValue.setU64Const(u64Const << constant.u8Const); break;
730  case EbtInt16: returnValue.setU64Const(u64Const << constant.i16Const); break;
731  case EbtUint16: returnValue.setU64Const(u64Const << constant.u16Const); break;
732  case EbtInt: returnValue.setU64Const(u64Const << constant.iConst); break;
733  case EbtUint: returnValue.setU64Const(u64Const << constant.uConst); break;
734  case EbtInt64: returnValue.setU64Const(u64Const << constant.i64Const); break;
735  case EbtUint64: returnValue.setU64Const(u64Const << constant.u64Const); break;
736  default: assert(false && "Default missing");
737  }
738  break;
739  default: assert(false && "Default missing");
740  }
741 
742  return returnValue;
743  }
744 
745  TConstUnion operator&(const TConstUnion& constant) const
746  {
747  TConstUnion returnValue;
748  assert(type == constant.type);
749  switch (type) {
750  case EbtInt8: returnValue.setI8Const(i8Const & constant.i8Const); break;
751  case EbtUint8: returnValue.setU8Const(u8Const & constant.u8Const); break;
752  case EbtInt16: returnValue.setI16Const(i16Const & constant.i16Const); break;
753  case EbtUint16: returnValue.setU16Const(u16Const & constant.u16Const); break;
754  case EbtInt: returnValue.setIConst(iConst & constant.iConst); break;
755  case EbtUint: returnValue.setUConst(uConst & constant.uConst); break;
756  case EbtInt64: returnValue.setI64Const(i64Const & constant.i64Const); break;
757  case EbtUint64: returnValue.setU64Const(u64Const & constant.u64Const); break;
758  default: assert(false && "Default missing");
759  }
760 
761  return returnValue;
762  }
763 
764  TConstUnion operator|(const TConstUnion& constant) const
765  {
766  TConstUnion returnValue;
767  assert(type == constant.type);
768  switch (type) {
769  case EbtInt8: returnValue.setI8Const(i8Const | constant.i8Const); break;
770  case EbtUint8: returnValue.setU8Const(u8Const | constant.u8Const); break;
771  case EbtInt16: returnValue.setI16Const(i16Const | constant.i16Const); break;
772  case EbtUint16: returnValue.setU16Const(u16Const | constant.u16Const); break;
773  case EbtInt: returnValue.setIConst(iConst | constant.iConst); break;
774  case EbtUint: returnValue.setUConst(uConst | constant.uConst); break;
775  case EbtInt64: returnValue.setI64Const(i64Const | constant.i64Const); break;
776  case EbtUint64: returnValue.setU64Const(u64Const | constant.u64Const); break;
777  default: assert(false && "Default missing");
778  }
779 
780  return returnValue;
781  }
782 
783  TConstUnion operator^(const TConstUnion& constant) const
784  {
785  TConstUnion returnValue;
786  assert(type == constant.type);
787  switch (type) {
788  case EbtInt8: returnValue.setI8Const(i8Const ^ constant.i8Const); break;
789  case EbtUint8: returnValue.setU8Const(u8Const ^ constant.u8Const); break;
790  case EbtInt16: returnValue.setI16Const(i16Const ^ constant.i16Const); break;
791  case EbtUint16: returnValue.setU16Const(u16Const ^ constant.u16Const); break;
792  case EbtInt: returnValue.setIConst(iConst ^ constant.iConst); break;
793  case EbtUint: returnValue.setUConst(uConst ^ constant.uConst); break;
794  case EbtInt64: returnValue.setI64Const(i64Const ^ constant.i64Const); break;
795  case EbtUint64: returnValue.setU64Const(u64Const ^ constant.u64Const); break;
796  default: assert(false && "Default missing");
797  }
798 
799  return returnValue;
800  }
801 
803  {
804  TConstUnion returnValue;
805  switch (type) {
806  case EbtInt8: returnValue.setI8Const(~i8Const); break;
807  case EbtUint8: returnValue.setU8Const(~u8Const); break;
808  case EbtInt16: returnValue.setI16Const(~i16Const); break;
809  case EbtUint16: returnValue.setU16Const(~u16Const); break;
810  case EbtInt: returnValue.setIConst(~iConst); break;
811  case EbtUint: returnValue.setUConst(~uConst); break;
812  case EbtInt64: returnValue.setI64Const(~i64Const); break;
813  case EbtUint64: returnValue.setU64Const(~u64Const); break;
814  default: assert(false && "Default missing");
815  }
816 
817  return returnValue;
818  }
819 
820  TConstUnion operator&&(const TConstUnion& constant) const
821  {
822  TConstUnion returnValue;
823  assert(type == constant.type);
824  switch (type) {
825  case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
826  default: assert(false && "Default missing");
827  }
828 
829  return returnValue;
830  }
831 
832  TConstUnion operator||(const TConstUnion& constant) const
833  {
834  TConstUnion returnValue;
835  assert(type == constant.type);
836  switch (type) {
837  case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
838  default: assert(false && "Default missing");
839  }
840 
841  return returnValue;
842  }
843 
844  TBasicType getType() const { return type; }
845 
846 private:
847  union {
848  signed char i8Const; // used for i8vec, scalar int8s
849  unsigned char u8Const; // used for u8vec, scalar uint8s
850  signed short i16Const; // used for i16vec, scalar int16s
851  unsigned short u16Const; // used for u16vec, scalar uint16s
852  int iConst; // used for ivec, scalar ints
853  unsigned int uConst; // used for uvec, scalar uints
854  long long i64Const; // used for i64vec, scalar int64s
855  unsigned long long u64Const; // used for u64vec, scalar uint64s
856  bool bConst; // used for bvec, scalar bools
857  double dConst; // used for vec, dvec, mat, dmat, scalar floats and doubles
858  const TString* sConst; // string constant
859  };
860 
862 };
863 
864 // Encapsulate having a pointer to an array of TConstUnion,
865 // which only needs to be allocated if its size is going to be
866 // bigger than 0.
867 //
868 // One convenience is being able to use [] to go inside the array, instead
869 // of C++ assuming it as an array of pointers to vectors.
870 //
871 // General usage is that the size is known up front, and it is
872 // created once with the proper size.
873 //
875 public:
877 
878  TConstUnionArray() : unionArray(nullptr) { }
879  virtual ~TConstUnionArray() { }
880 
881  explicit TConstUnionArray(int size)
882  {
883  if (size == 0)
884  unionArray = nullptr;
885  else
887  }
890  {
892  for (int i = 0; i < size; ++i)
893  (*unionArray)[i] = a[start + i];
894  }
895 
896  // Use this constructor for a smear operation
898  {
900  }
901 
902  int size() const { return unionArray ? (int)unionArray->size() : 0; }
903  TConstUnion& operator[](size_t index) { return (*unionArray)[index]; }
904  const TConstUnion& operator[](size_t index) const { return (*unionArray)[index]; }
905  bool operator==(const TConstUnionArray& rhs) const
906  {
907  // this includes the case that both are unallocated
908  if (unionArray == rhs.unionArray)
909  return true;
910 
911  if (! unionArray || ! rhs.unionArray)
912  return false;
913 
914  return *unionArray == *rhs.unionArray;
915  }
916  bool operator!=(const TConstUnionArray& rhs) const { return ! operator==(rhs); }
917 
918  double dot(const TConstUnionArray& rhs)
919  {
920  assert(rhs.unionArray->size() == unionArray->size());
921  double sum = 0.0;
922 
923  for (size_t comp = 0; comp < unionArray->size(); ++comp)
924  sum += (*this)[comp].getDConst() * rhs[comp].getDConst();
925 
926  return sum;
927  }
928 
929  bool empty() const { return unionArray == nullptr; }
930 
931 protected:
934 };
935 
936 } // end namespace glslang
937 
938 #endif // _CONSTANT_UNION_INCLUDED_
TVector< TConstUnion > TConstUnionVector
Definition: ConstantUnion.h:932
int iConst
Definition: ConstantUnion.h:852
signed short i16Const
Definition: ConstantUnion.h:850
double dot(const TConstUnionArray &rhs)
Definition: ConstantUnion.h:918
Definition: BaseTypes.h:58
void setBConst(bool b)
Definition: ConstantUnion.h:106
int size() const
Definition: ConstantUnion.h:902
Definition: BaseTypes.h:53
bool operator!=(const TConstUnion &constant) const
Definition: ConstantUnion.h:323
GLuint GLfloat * val
Definition: glext.h:7847
Definition: BaseTypes.h:55
bool operator!=(const unsigned long long u) const
Definition: ConstantUnion.h:308
bool operator==(const int i) const
Definition: ConstantUnion.h:162
bool operator<(const TConstUnion &constant) const
Definition: ConstantUnion.h:383
TConstUnionArray(const TConstUnionArray &a)
Definition: ConstantUnion.h:888
const TString * getSConst() const
Definition: ConstantUnion.h:128
Definition: BaseTypes.h:49
GLuint start
Definition: glext.h:6292
Definition: BaseTypes.h:52
unsigned char u8Const
Definition: ConstantUnion.h:849
signed char i8Const
Definition: ConstantUnion.h:848
unsigned short getU16Const() const
Definition: ConstantUnion.h:121
int getIConst() const
Definition: ConstantUnion.h:122
void setUConst(unsigned int u)
Definition: ConstantUnion.h:82
GLsizeiptr size
Definition: glext.h:6559
bool empty() const
Definition: ConstantUnion.h:929
GLfloat f
Definition: glext.h:8207
void setSConst(const TString *s)
Definition: ConstantUnion.h:112
bool operator!=(const unsigned char u) const
Definition: ConstantUnion.h:278
GLdouble s
Definition: glext.h:6390
TConstUnion operator~() const
Definition: ConstantUnion.h:802
bool operator==(const signed char i) const
Definition: ConstantUnion.h:130
Definition: ConstantUnion.h:46
void setU8Const(unsigned char u)
Definition: ConstantUnion.h:58
void setI64Const(long long i64)
Definition: ConstantUnion.h:88
TConstUnionArray(const TConstUnionArray &a, int start, int size)
Definition: ConstantUnion.h:889
long long getI64Const() const
Definition: ConstantUnion.h:124
bool operator==(const TConstUnion &constant) const
Definition: ConstantUnion.h:210
TConstUnion operator<<(const TConstUnion &constant) const
Definition: ConstantUnion.h:631
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
bool operator==(const unsigned long long u64) const
Definition: ConstantUnion.h:186
bool operator!=(const signed short i) const
Definition: ConstantUnion.h:283
double dConst
Definition: ConstantUnion.h:857
TPoolAllocator & GetThreadPoolAllocator()
Definition: PoolAlloc.cpp:47
Definition: BaseTypes.h:51
Definition: BaseTypes.h:56
TBasicType type
Definition: ConstantUnion.h:861
GLenum type
Definition: glext.h:6233
bool operator!=(const signed char i) const
Definition: ConstantUnion.h:273
bool operator!=(const unsigned short u) const
Definition: ConstantUnion.h:288
long long i64Const
Definition: ConstantUnion.h:854
bool operator>(const TConstUnion &constant) const
Definition: ConstantUnion.h:328
void setI16Const(signed short i)
Definition: ConstantUnion.h:64
unsigned short u16Const
Definition: ConstantUnion.h:851
unsigned int uConst
Definition: ConstantUnion.h:853
bool operator==(const signed short i) const
Definition: ConstantUnion.h:146
const TString * sConst
Definition: ConstantUnion.h:858
bool operator==(const TConstUnionArray &rhs) const
Definition: ConstantUnion.h:905
TConstUnion operator+(const TConstUnion &constant) const
Definition: ConstantUnion.h:438
#define POOL_ALLOCATOR_NEW_DELETE(A)
Definition: Common.h:112
TBasicType getType() const
Definition: ConstantUnion.h:844
unsigned char getU8Const() const
Definition: ConstantUnion.h:119
TConstUnion operator||(const TConstUnion &constant) const
Definition: ConstantUnion.h:832
bool operator==(const unsigned int u) const
Definition: ConstantUnion.h:170
bool getBConst() const
Definition: ConstantUnion.h:127
TConstUnionArray(int size, const TConstUnion &val)
Definition: ConstantUnion.h:897
bool operator==(const bool b) const
Definition: ConstantUnion.h:202
TConstUnionArray(int size)
Definition: ConstantUnion.h:881
TConstUnion operator*(const TConstUnion &constant) const
Definition: ConstantUnion.h:478
void setI8Const(signed char i)
Definition: ConstantUnion.h:52
TConstUnion operator>>(const TConstUnion &constant) const
Definition: ConstantUnion.h:517
signed short getI16Const() const
Definition: ConstantUnion.h:120
bool bConst
Definition: ConstantUnion.h:856
TConstUnion operator-(const TConstUnion &constant) const
Definition: ConstantUnion.h:458
double getDConst() const
Definition: ConstantUnion.h:126
Definition: arrays.h:46
unsigned int getUConst() const
Definition: ConstantUnion.h:123
Definition: BaseTypes.h:66
GLuint index
Definition: glext.h:6671
void setU16Const(unsigned short u)
Definition: ConstantUnion.h:70
bool operator!=(const int i) const
Definition: ConstantUnion.h:293
const TConstUnion & operator[](size_t index) const
Definition: ConstantUnion.h:904
uint64_t u64
64bit unsigned integer
Definition: gctypes.h:20
TConstUnion operator|(const TConstUnion &constant) const
Definition: ConstantUnion.h:764
bool operator!=(const long long i) const
Definition: ConstantUnion.h:303
bool operator==(const double d) const
Definition: ConstantUnion.h:194
TConstUnion operator &&(const TConstUnion &constant) const
Definition: ConstantUnion.h:820
TConstUnion operator^(const TConstUnion &constant) const
Definition: ConstantUnion.h:783
bool operator!=(const float f) const
Definition: ConstantUnion.h:313
TBasicType
Definition: BaseTypes.h:46
bool operator==(const unsigned short u) const
Definition: ConstantUnion.h:154
signed char getI8Const() const
Definition: ConstantUnion.h:118
bool operator!=(const bool b) const
Definition: ConstantUnion.h:318
Definition: BaseTypes.h:59
TConstUnionVector * unionArray
Definition: ConstantUnion.h:933
Definition: ConstantUnion.h:874
bool operator!=(const TConstUnionArray &rhs) const
Definition: ConstantUnion.h:916
bool operator==(const unsigned char u) const
Definition: ConstantUnion.h:138
Definition: BaseTypes.h:54
bool operator!=(const unsigned int u) const
Definition: ConstantUnion.h:298
bool operator==(const long long i64) const
Definition: ConstantUnion.h:178
TConstUnion & operator[](size_t index)
Definition: ConstantUnion.h:903
TConstUnion operator &(const TConstUnion &constant) const
Definition: ConstantUnion.h:745
Definition: Common.h:175
void setDConst(double d)
Definition: ConstantUnion.h:100
void setIConst(int i)
Definition: ConstantUnion.h:76
virtual ~TConstUnionArray()
Definition: ConstantUnion.h:879
unsigned long long getU64Const() const
Definition: ConstantUnion.h:125
Definition: lobject.h:303
TConstUnion operator%(const TConstUnion &constant) const
Definition: ConstantUnion.h:498
Definition: BaseTypes.h:57
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844
void setU64Const(unsigned long long u64)
Definition: ConstantUnion.h:94
unsigned long long u64Const
Definition: ConstantUnion.h:855