14f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com//
201df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
34f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com// Use of this source code is governed by a BSD-style license that can be
44f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com// found in the LICENSE file.
54f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com//
64f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
74f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com#ifndef _CONSTANT_UNION_INCLUDED_
84f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com#define _CONSTANT_UNION_INCLUDED_
94f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
104e4facd4a1120f77e35b53cd4ba7d5a8adefddcfalokp@chromium.org#include <assert.h>
114f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
126ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.orgclass ConstantUnion {
134f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.compublic:
148156b6be065905c22db8f5dc3ab0fb715b0e1b52Alok Priyadarshi    POOL_ALLOCATOR_NEW_DELETE();
15a1d8059d676046ff9a35e15341866f1e93944132apatrick@chromium.org    ConstantUnion()
16a1d8059d676046ff9a35e15341866f1e93944132apatrick@chromium.org    {
17a1d8059d676046ff9a35e15341866f1e93944132apatrick@chromium.org        iConst = 0;
18c0d0c22525de629665afcb6a2cd2e366a45aa26cshannon.woods%transgaming.com@gtempaccount.com        type = EbtVoid;
19a1d8059d676046ff9a35e15341866f1e93944132apatrick@chromium.org    }
204f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2101df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens    bool cast(TBasicType newType, const ConstantUnion &constant)
2201df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens    {
2301df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens        switch (newType)
2401df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens        {
2501df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens          case EbtFloat:
2601df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            switch (constant.type)
2701df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            {
2801df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtInt:   setFConst(static_cast<float>(constant.getIConst())); break;
2901df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtUInt:  setFConst(static_cast<float>(constant.getUConst())); break;
3001df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtBool:  setFConst(static_cast<float>(constant.getBConst())); break;
3101df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtFloat: setFConst(static_cast<float>(constant.getFConst())); break;
3201df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              default:       return false;
3301df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            }
3401df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            break;
3501df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens          case EbtInt:
3601df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            switch (constant.type)
3701df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            {
3801df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtInt:   setIConst(static_cast<int>(constant.getIConst())); break;
3901df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtUInt:  setIConst(static_cast<int>(constant.getUConst())); break;
4001df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtBool:  setIConst(static_cast<int>(constant.getBConst())); break;
4101df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtFloat: setIConst(static_cast<int>(constant.getFConst())); break;
4201df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              default:       return false;
4301df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            }
4401df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            break;
4501df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens          case EbtUInt:
4601df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            switch (constant.type)
4701df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            {
4801df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtInt:   setUConst(static_cast<unsigned int>(constant.getIConst())); break;
4901df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtUInt:  setUConst(static_cast<unsigned int>(constant.getUConst())); break;
5001df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtBool:  setUConst(static_cast<unsigned int>(constant.getBConst())); break;
5101df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtFloat: setUConst(static_cast<unsigned int>(constant.getFConst())); break;
5201df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              default:       return false;
5301df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            }
5401df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            break;
5501df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens          case EbtBool:
5601df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            switch (constant.type)
5701df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            {
5801df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtInt:   setBConst(constant.getIConst() != 0);    break;
5901df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtUInt:  setBConst(constant.getUConst() != 0);    break;
6001df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtBool:  setBConst(constant.getBConst());         break;
6101df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtFloat: setBConst(constant.getFConst() != 0.0f); break;
6201df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              default:       return false;
6301df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            }
6401df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            break;
6501df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens          case EbtStruct:    // Struct fields don't get cast
6601df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            switch (constant.type)
6701df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            {
6801df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtInt:   setIConst(constant.getIConst()); break;
6901df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtUInt:  setUConst(constant.getUConst()); break;
7001df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtBool:  setBConst(constant.getBConst()); break;
7101df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              case EbtFloat: setFConst(constant.getFConst()); break;
7201df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens              default:       return false;
7301df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            }
7401df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            break;
7501df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens          default:
7601df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens            return false;
7701df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens        }
7801df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens
7901df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens        return true;
8001df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens    }
8101df23e7473eb6d1b9ed2f8a7b4b5996e1f1da59Nicolas Capens
824f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    void setIConst(int i) {iConst = i; type = EbtInt; }
833c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org    void setUConst(unsigned int u) { uConst = u; type = EbtUInt; }
844f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    void setFConst(float f) {fConst = f; type = EbtFloat; }
854f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    void setBConst(bool b) {bConst = b; type = EbtBool; }
864f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
874f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    int getIConst() const { return iConst; }
88c0f7c61980ebe66cb6493bf7616a4379f4ddda0aNicolas Capens    unsigned int getUConst() const { return uConst; }
894f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    float getFConst() const { return fConst; }
904f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    bool getBConst() const { return bConst; }
914f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
924f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    bool operator==(const int i) const
934f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
94e90a0d5a9bea7905a60b8ee104dbfbe192533703daniel@transgaming.com        return i == iConst;
954f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
964f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
973c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org    bool operator==(const unsigned int u) const
983c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org    {
993c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        return u == uConst;
1003c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org    }
1013c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org
1024f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    bool operator==(const float f) const
1034f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
104e90a0d5a9bea7905a60b8ee104dbfbe192533703daniel@transgaming.com        return f == fConst;
1054f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1064f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1074f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    bool operator==(const bool b) const
1084f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
109e90a0d5a9bea7905a60b8ee104dbfbe192533703daniel@transgaming.com        return b == bConst;
1104f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1114f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1126ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    bool operator==(const ConstantUnion& constant) const
1134f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
1144f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        if (constant.type != type)
1154f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com            return false;
1164f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1174f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
1184f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt:
119e90a0d5a9bea7905a60b8ee104dbfbe192533703daniel@transgaming.com            return constant.iConst == iConst;
1203c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt:
1213c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org            return constant.uConst == uConst;
1224f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtFloat:
123e90a0d5a9bea7905a60b8ee104dbfbe192533703daniel@transgaming.com            return constant.fConst == fConst;
1244f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtBool:
125e90a0d5a9bea7905a60b8ee104dbfbe192533703daniel@transgaming.com            return constant.bConst == bConst;
126cd3a1b946453a0345de403bd7ec31fa27987b1fcdaniel@transgaming.com        default:
127cd3a1b946453a0345de403bd7ec31fa27987b1fcdaniel@transgaming.com            return false;
1284f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
1294f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1304f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1314f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    bool operator!=(const int i) const
1324f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
1334f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return !operator==(i);
1344f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1354f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1363c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org    bool operator!=(const unsigned int u) const
1373c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org    {
1383c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        return !operator==(u);
1393c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org    }
1403c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org
1414f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    bool operator!=(const float f) const
1424f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
1434f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return !operator==(f);
1444f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1454f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1464f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    bool operator!=(const bool b) const
1474f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
1484f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return !operator==(b);
1494f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1504f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1516ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    bool operator!=(const ConstantUnion& constant) const
1524f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
1534f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return !operator==(constant);
1544f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1554f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1566ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    bool operator>(const ConstantUnion& constant) const
1574f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
1584f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
1594f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
1604f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt:
161b31f35abe60439a8ca2a0ee43640fabfe866f39adaniel@transgaming.com            return iConst > constant.iConst;
1623c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt:
1633c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org            return uConst > constant.uConst;
1644f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtFloat:
165b31f35abe60439a8ca2a0ee43640fabfe866f39adaniel@transgaming.com            return fConst > constant.fConst;
1664f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:
167b31f35abe60439a8ca2a0ee43640fabfe866f39adaniel@transgaming.com            return false;   // Invalid operation, handled at semantic analysis
1684f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
1694f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1704f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1716ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    bool operator<(const ConstantUnion& constant) const
1724f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
1734f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
1744f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
1754f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt:
176b31f35abe60439a8ca2a0ee43640fabfe866f39adaniel@transgaming.com            return iConst < constant.iConst;
1773c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt:
1783c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org            return uConst < constant.uConst;
1794f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtFloat:
180b31f35abe60439a8ca2a0ee43640fabfe866f39adaniel@transgaming.com            return fConst < constant.fConst;
1814f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:
182b31f35abe60439a8ca2a0ee43640fabfe866f39adaniel@transgaming.com            return false;   // Invalid operation, handled at semantic analysis
1834f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
1844f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1854f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1866ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator+(const ConstantUnion& constant) const
1874f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
1886ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
1894f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
1904f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
1914f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
1923c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt: returnValue.setUConst(uConst + constant.uConst); break;
1934f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break;
1944f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default: assert(false && "Default missing");
1954f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
1964f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
1974f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
1984f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
1994f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2006ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator-(const ConstantUnion& constant) const
2014f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
2026ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
2034f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
2044f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
2054f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
2063c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt: returnValue.setUConst(uConst - constant.uConst); break;
2074f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break;
2084f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default: assert(false && "Default missing");
2094f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
2104f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2114f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
2124f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
2134f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2146ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator*(const ConstantUnion& constant) const
2154f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
2166ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
2174f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
2184f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
2194f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
2203c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt: returnValue.setUConst(uConst * constant.uConst); break;
2214f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break;
2224f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default: assert(false && "Default missing");
2234f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
2244f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2254f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
2264f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
2274f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2286ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator%(const ConstantUnion& constant) const
2294f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
2306ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
2314f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
2324f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
2334f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
2343c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt: returnValue.setUConst(uConst % constant.uConst); break;
2354f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:     assert(false && "Default missing");
2364f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
2374f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2384f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
2394f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
2404f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2416ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator>>(const ConstantUnion& constant) const
2424f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
2436ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
2444f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
2454f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
2464f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
2473c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt: returnValue.setUConst(uConst >> constant.uConst); break;
2484f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:     assert(false && "Default missing");
2494f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
2504f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2514f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
2524f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
2534f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2546ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator<<(const ConstantUnion& constant) const
2554f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
2566ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
2574f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
2584f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
2594f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
2603c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt: returnValue.setUConst(uConst << constant.uConst); break;
2614f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:     assert(false && "Default missing");
2624f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
2634f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2644f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
2654f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
2664f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2676ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator&(const ConstantUnion& constant) const
2684f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
2696ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
2704f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
2714f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
2724f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt:  returnValue.setIConst(iConst & constant.iConst); break;
2733c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt:  returnValue.setUConst(uConst & constant.uConst); break;
2744f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:     assert(false && "Default missing");
2754f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
2764f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2774f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
2784f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
2794f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2806ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator|(const ConstantUnion& constant) const
2814f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
2826ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
2834f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
2844f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
2854f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt:  returnValue.setIConst(iConst | constant.iConst); break;
2863c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt:  returnValue.setUConst(uConst | constant.uConst); break;
2874f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:     assert(false && "Default missing");
2884f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
2894f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2904f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
2914f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
2924f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
2936ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator^(const ConstantUnion& constant) const
2944f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
2956ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
2964f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
2974f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
2984f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtInt:  returnValue.setIConst(iConst ^ constant.iConst); break;
2993c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        case EbtUInt:  returnValue.setUConst(uConst ^ constant.uConst); break;
3004f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:     assert(false && "Default missing");
3014f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
3024f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
3034f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
3044f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
3054f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
3066ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator&&(const ConstantUnion& constant) const
3074f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
3086ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
3094f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
3104f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
3114f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
3124f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:     assert(false && "Default missing");
3134f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
3144f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
3154f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
3164f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
3174f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
3186ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org    ConstantUnion operator||(const ConstantUnion& constant) const
3194f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    {
3206ff56fd489bde0e36f9c3938618208b0e9c9de7dalokp@chromium.org        ConstantUnion returnValue;
3214f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        assert(type == constant.type);
3224f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        switch (type) {
3234f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
3244f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        default:     assert(false && "Default missing");
3254f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        }
3264f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
3274f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        return returnValue;
3284f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    }
3294f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
33076b820852b116d79187e5af5457a45065f656bdaalokp@chromium.org    TBasicType getType() const { return type; }
3314f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.comprivate:
3324f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
3334f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    union  {
3344f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        int iConst;  // used for ivec, scalar ints
3353c9d95a8d97eae397220445cc975b4109a67078bshannonwoods@chromium.org        unsigned int uConst; // used for uvec, scalar uints
3364f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        bool bConst; // used for bvec, scalar bools
3374f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com        float fConst;   // used for vec, mat, scalar floats
3384f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    } ;
3394f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
3404f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com    TBasicType type;
3414f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com};
3424f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com
3434f39fd99568ce175f04b5ed72062bfed0fa41803daniel@transgaming.com#endif // _CONSTANT_UNION_INCLUDED_
344