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 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 7 | #ifndef COMPILER_TRANSLATOR_CONSTANTUNION_H_ |
| 8 | #define COMPILER_TRANSLATOR_CONSTANTUNION_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 12 | #include "compiler/translator/Common.h" |
Jamie Madill | 6ba6ead | 2015-05-04 14:21:21 -0400 | [diff] [blame] | 13 | #include "compiler/translator/BaseTypes.h" |
| 14 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 15 | class TDiagnostics; |
| 16 | |
| 17 | class TConstantUnion |
| 18 | { |
| 19 | public: |
Alok Priyadarshi | 8156b6b | 2013-09-23 14:56:58 -0400 | [diff] [blame] | 20 | POOL_ALLOCATOR_NEW_DELETE(); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 21 | TConstantUnion(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 22 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 23 | bool cast(TBasicType newType, const TConstantUnion &constant); |
Nicolas Capens | 01df23e | 2014-06-11 10:56:03 -0400 | [diff] [blame] | 24 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 25 | void setIConst(int i) {iConst = i; type = EbtInt; } |
shannonwoods@chromium.org | 3c9d95a | 2013-05-30 00:19:46 +0000 | [diff] [blame] | 26 | void setUConst(unsigned int u) { uConst = u; type = EbtUInt; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 27 | void setFConst(float f) {fConst = f; type = EbtFloat; } |
| 28 | void setBConst(bool b) {bConst = b; type = EbtBool; } |
| 29 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 30 | int getIConst() const { return iConst; } |
Nicolas Capens | c0f7c61 | 2013-06-05 11:46:09 -0400 | [diff] [blame] | 31 | unsigned int getUConst() const { return uConst; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 32 | float getFConst() const { return fConst; } |
| 33 | bool getBConst() const { return bConst; } |
| 34 | |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 35 | bool operator==(const int i) const; |
| 36 | bool operator==(const unsigned int u) const; |
| 37 | bool operator==(const float f) const; |
| 38 | bool operator==(const bool b) const; |
| 39 | bool operator==(const TConstantUnion &constant) const; |
| 40 | bool operator!=(const int i) const; |
| 41 | bool operator!=(const unsigned int u) const; |
| 42 | bool operator!=(const float f) const; |
| 43 | bool operator!=(const bool b) const; |
| 44 | bool operator!=(const TConstantUnion &constant) const; |
| 45 | bool operator>(const TConstantUnion &constant) const; |
| 46 | bool operator<(const TConstantUnion &constant) const; |
| 47 | static TConstantUnion add(const TConstantUnion &lhs, |
| 48 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame^] | 49 | TDiagnostics *diag, |
| 50 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 51 | static TConstantUnion sub(const TConstantUnion &lhs, |
| 52 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame^] | 53 | TDiagnostics *diag, |
| 54 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 55 | static TConstantUnion mul(const TConstantUnion &lhs, |
| 56 | const TConstantUnion &rhs, |
Jamie Madill | 5db69f5 | 2016-09-15 12:47:32 -0400 | [diff] [blame^] | 57 | TDiagnostics *diag, |
| 58 | const TSourceLoc &line); |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 59 | TConstantUnion operator%(const TConstantUnion &constant) const; |
| 60 | TConstantUnion operator>>(const TConstantUnion &constant) const; |
| 61 | TConstantUnion operator<<(const TConstantUnion &constant) const; |
| 62 | TConstantUnion operator&(const TConstantUnion &constant) const; |
| 63 | TConstantUnion operator|(const TConstantUnion &constant) const; |
| 64 | TConstantUnion operator^(const TConstantUnion &constant) const; |
| 65 | TConstantUnion operator&&(const TConstantUnion &constant) const; |
| 66 | TConstantUnion operator||(const TConstantUnion &constant) const; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 67 | |
alokp@chromium.org | 76b8208 | 2010-03-24 17:59:39 +0000 | [diff] [blame] | 68 | TBasicType getType() const { return type; } |
Jamie Madill | 47cb73a | 2016-09-09 11:41:44 -0400 | [diff] [blame] | 69 | private: |
| 70 | union { |
| 71 | int iConst; // used for ivec, scalar ints |
| 72 | unsigned int uConst; // used for uvec, scalar uints |
| 73 | bool bConst; // used for bvec, scalar bools |
| 74 | float fConst; // used for vec, mat, scalar floats |
| 75 | }; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 76 | |
| 77 | TBasicType type; |
| 78 | }; |
| 79 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 80 | #endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_ |