gfx/angle/src/compiler/ConstantUnion.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 //
     2 // Copyright (c) 2002-2013 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 //
     7 #ifndef _CONSTANT_UNION_INCLUDED_
     8 #define _CONSTANT_UNION_INCLUDED_
    10 #include <assert.h>
    12 class ConstantUnion {
    13 public:
    14     POOL_ALLOCATOR_NEW_DELETE();
    15     ConstantUnion()
    16     {
    17         iConst = 0;
    18         type = EbtVoid;
    19     }
    21     void setIConst(int i) {iConst = i; type = EbtInt; }
    22     void setFConst(float f) {fConst = f; type = EbtFloat; }
    23     void setBConst(bool b) {bConst = b; type = EbtBool; }
    25     int getIConst() { return iConst; }
    26     float getFConst() { return fConst; }
    27     bool getBConst() { return bConst; }
    28     int getIConst() const { return iConst; }
    29     float getFConst() const { return fConst; }
    30     bool getBConst() const { return bConst; }
    32     bool operator==(const int i) const
    33     {
    34         return i == iConst;
    35     }
    37     bool operator==(const float f) const
    38     {
    39         return f == fConst;
    40     }
    42     bool operator==(const bool b) const
    43     {
    44         return b == bConst;
    45     }
    47     bool operator==(const ConstantUnion& constant) const
    48     {
    49         if (constant.type != type)
    50             return false;
    52         switch (type) {
    53         case EbtInt:
    54             return constant.iConst == iConst;
    55         case EbtFloat:
    56             return constant.fConst == fConst;
    57         case EbtBool:
    58             return constant.bConst == bConst;
    59         default:
    60             return false;
    61         }
    62     }
    64     bool operator!=(const int i) const
    65     {
    66         return !operator==(i);
    67     }
    69     bool operator!=(const float f) const
    70     {
    71         return !operator==(f);
    72     }
    74     bool operator!=(const bool b) const
    75     {
    76         return !operator==(b);
    77     }
    79     bool operator!=(const ConstantUnion& constant) const
    80     {
    81         return !operator==(constant);
    82     }
    84     bool operator>(const ConstantUnion& constant) const
    85     { 
    86         assert(type == constant.type);
    87         switch (type) {
    88         case EbtInt:
    89             return iConst > constant.iConst;
    90         case EbtFloat:
    91             return fConst > constant.fConst;
    92         default:
    93             return false;   // Invalid operation, handled at semantic analysis
    94         }
    95     }
    97     bool operator<(const ConstantUnion& constant) const
    98     { 
    99         assert(type == constant.type);
   100         switch (type) {
   101         case EbtInt:
   102             return iConst < constant.iConst;
   103         case EbtFloat:
   104             return fConst < constant.fConst;
   105         default:
   106             return false;   // Invalid operation, handled at semantic analysis
   107         }
   108     }
   110     ConstantUnion operator+(const ConstantUnion& constant) const
   111     { 
   112         ConstantUnion returnValue;
   113         assert(type == constant.type);
   114         switch (type) {
   115         case EbtInt: returnValue.setIConst(iConst + constant.iConst); break;
   116         case EbtFloat: returnValue.setFConst(fConst + constant.fConst); break;
   117         default: assert(false && "Default missing");
   118         }
   120         return returnValue;
   121     }
   123     ConstantUnion operator-(const ConstantUnion& constant) const
   124     { 
   125         ConstantUnion returnValue;
   126         assert(type == constant.type);
   127         switch (type) {
   128         case EbtInt: returnValue.setIConst(iConst - constant.iConst); break;
   129         case EbtFloat: returnValue.setFConst(fConst - constant.fConst); break;
   130         default: assert(false && "Default missing");
   131         }
   133         return returnValue;
   134     }
   136     ConstantUnion operator*(const ConstantUnion& constant) const
   137     { 
   138         ConstantUnion returnValue;
   139         assert(type == constant.type);
   140         switch (type) {
   141         case EbtInt: returnValue.setIConst(iConst * constant.iConst); break;
   142         case EbtFloat: returnValue.setFConst(fConst * constant.fConst); break; 
   143         default: assert(false && "Default missing");
   144         }
   146         return returnValue;
   147     }
   149     ConstantUnion operator%(const ConstantUnion& constant) const
   150     { 
   151         ConstantUnion returnValue;
   152         assert(type == constant.type);
   153         switch (type) {
   154         case EbtInt: returnValue.setIConst(iConst % constant.iConst); break;
   155         default:     assert(false && "Default missing");
   156         }
   158         return returnValue;
   159     }
   161     ConstantUnion operator>>(const ConstantUnion& constant) const
   162     { 
   163         ConstantUnion returnValue;
   164         assert(type == constant.type);
   165         switch (type) {
   166         case EbtInt: returnValue.setIConst(iConst >> constant.iConst); break;
   167         default:     assert(false && "Default missing");
   168         }
   170         return returnValue;
   171     }
   173     ConstantUnion operator<<(const ConstantUnion& constant) const
   174     { 
   175         ConstantUnion returnValue;
   176         assert(type == constant.type);
   177         switch (type) {
   178         case EbtInt: returnValue.setIConst(iConst << constant.iConst); break;
   179         default:     assert(false && "Default missing");
   180         }
   182         return returnValue;
   183     }
   185     ConstantUnion operator&(const ConstantUnion& constant) const
   186     { 
   187         ConstantUnion returnValue;
   188         assert(type == constant.type);
   189         switch (type) {
   190         case EbtInt:  returnValue.setIConst(iConst & constant.iConst); break;
   191         default:     assert(false && "Default missing");
   192         }
   194         return returnValue;
   195     }
   197     ConstantUnion operator|(const ConstantUnion& constant) const
   198     { 
   199         ConstantUnion returnValue;
   200         assert(type == constant.type);
   201         switch (type) {
   202         case EbtInt:  returnValue.setIConst(iConst | constant.iConst); break;
   203         default:     assert(false && "Default missing");
   204         }
   206         return returnValue;
   207     }
   209     ConstantUnion operator^(const ConstantUnion& constant) const
   210     { 
   211         ConstantUnion returnValue;
   212         assert(type == constant.type);
   213         switch (type) {
   214         case EbtInt:  returnValue.setIConst(iConst ^ constant.iConst); break;
   215         default:     assert(false && "Default missing");
   216         }
   218         return returnValue;
   219     }
   221     ConstantUnion operator&&(const ConstantUnion& constant) const
   222     { 
   223         ConstantUnion returnValue;
   224         assert(type == constant.type);
   225         switch (type) {
   226         case EbtBool: returnValue.setBConst(bConst && constant.bConst); break;
   227         default:     assert(false && "Default missing");
   228         }
   230         return returnValue;
   231     }
   233     ConstantUnion operator||(const ConstantUnion& constant) const
   234     { 
   235         ConstantUnion returnValue;
   236         assert(type == constant.type);
   237         switch (type) {
   238         case EbtBool: returnValue.setBConst(bConst || constant.bConst); break;
   239         default:     assert(false && "Default missing");
   240         }
   242         return returnValue;
   243     }
   245     TBasicType getType() const { return type; }
   246 private:
   248     union  {
   249         int iConst;  // used for ivec, scalar ints
   250         bool bConst; // used for bvec, scalar bools
   251         float fConst;   // used for vec, mat, scalar floats
   252     } ;
   254     TBasicType type;
   255 };
   257 #endif // _CONSTANT_UNION_INCLUDED_

mercurial