blob: 917c63733d775a2eddb639fb19cbef0a756eac25 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens01df23e2014-06-11 10:56:03 -04002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_CONSTANTUNION_H_
8#define COMPILER_TRANSLATOR_CONSTANTUNION_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009
alokp@chromium.org4e4facd2010-06-02 15:21:22 +000010#include <assert.h>
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000011
Jamie Madill47cb73a2016-09-09 11:41:44 -040012#include "compiler/translator/Common.h"
Jamie Madill6ba6ead2015-05-04 14:21:21 -040013#include "compiler/translator/BaseTypes.h"
14
Jamie Madill47cb73a2016-09-09 11:41:44 -040015class TDiagnostics;
16
17class TConstantUnion
18{
19 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040020 POOL_ALLOCATOR_NEW_DELETE();
Jamie Madill47cb73a2016-09-09 11:41:44 -040021 TConstantUnion();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022
Jamie Madill47cb73a2016-09-09 11:41:44 -040023 bool cast(TBasicType newType, const TConstantUnion &constant);
Nicolas Capens01df23e2014-06-11 10:56:03 -040024
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000025 void setIConst(int i) {iConst = i; type = EbtInt; }
shannonwoods@chromium.org3c9d95a2013-05-30 00:19:46 +000026 void setUConst(unsigned int u) { uConst = u; type = EbtUInt; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000027 void setFConst(float f) {fConst = f; type = EbtFloat; }
28 void setBConst(bool b) {bConst = b; type = EbtBool; }
29
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000030 int getIConst() const { return iConst; }
Nicolas Capensc0f7c612013-06-05 11:46:09 -040031 unsigned int getUConst() const { return uConst; }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000032 float getFConst() const { return fConst; }
33 bool getBConst() const { return bConst; }
34
Jamie Madill47cb73a2016-09-09 11:41:44 -040035 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,
49 TDiagnostics *diag);
50 static TConstantUnion sub(const TConstantUnion &lhs,
51 const TConstantUnion &rhs,
52 TDiagnostics *diag);
53 static TConstantUnion mul(const TConstantUnion &lhs,
54 const TConstantUnion &rhs,
55 TDiagnostics *diag);
56 TConstantUnion operator%(const TConstantUnion &constant) const;
57 TConstantUnion operator>>(const TConstantUnion &constant) const;
58 TConstantUnion operator<<(const TConstantUnion &constant) const;
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;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064
alokp@chromium.org76b82082010-03-24 17:59:39 +000065 TBasicType getType() const { return type; }
Jamie Madill47cb73a2016-09-09 11:41:44 -040066 private:
67 union {
68 int iConst; // used for ivec, scalar ints
69 unsigned int uConst; // used for uvec, scalar uints
70 bool bConst; // used for bvec, scalar bools
71 float fConst; // used for vec, mat, scalar floats
72 };
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000073
74 TBasicType type;
75};
76
Geoff Lang0a73dd82014-11-19 16:18:08 -050077#endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_