blob: d148d2c15fad1d1ef2f55d39f793c5631339bd08 [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,
Jamie Madill5db69f52016-09-15 12:47:32 -040049 TDiagnostics *diag,
50 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040051 static TConstantUnion sub(const TConstantUnion &lhs,
52 const TConstantUnion &rhs,
Jamie Madill5db69f52016-09-15 12:47:32 -040053 TDiagnostics *diag,
54 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040055 static TConstantUnion mul(const TConstantUnion &lhs,
56 const TConstantUnion &rhs,
Jamie Madill5db69f52016-09-15 12:47:32 -040057 TDiagnostics *diag,
58 const TSourceLoc &line);
Jamie Madill47cb73a2016-09-09 11:41:44 -040059 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.com4f39fd92010-03-08 20:26:45 +000067
alokp@chromium.org76b82082010-03-24 17:59:39 +000068 TBasicType getType() const { return type; }
Jamie Madill47cb73a2016-09-09 11:41:44 -040069 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.com4f39fd92010-03-08 20:26:45 +000076
77 TBasicType type;
78};
79
Geoff Lang0a73dd82014-11-19 16:18:08 -050080#endif // COMPILER_TRANSLATOR_CONSTANTUNION_H_