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