daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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 | // |
| 8 | // Symbol table for parsing. Most functionaliy and main ideas |
| 9 | // are documented in the header file. |
| 10 | // |
| 11 | |
apatrick@chromium.org | e057c5d | 2012-01-26 19:18:24 +0000 | [diff] [blame] | 12 | #if defined(_MSC_VER) |
| 13 | #pragma warning(disable: 4718) |
| 14 | #endif |
| 15 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 16 | #include "compiler/translator/SymbolTable.h" |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 17 | #include "compiler/translator/Cache.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 18 | |
apatrick@chromium.org | 8187fa8 | 2010-06-15 22:09:28 +0000 | [diff] [blame] | 19 | #include <stdio.h> |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 20 | #include <algorithm> |
| 21 | |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 22 | int TSymbolTable::uniqueIdCounter = 0; |
Nicolas Capens | bd10cf5 | 2013-06-20 09:51:51 -0400 | [diff] [blame] | 23 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 24 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 25 | // Functions have buried pointers to delete. |
| 26 | // |
| 27 | TFunction::~TFunction() |
| 28 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 29 | for (TParamList::iterator i = parameters.begin(); i != parameters.end(); ++i) |
| 30 | delete (*i).type; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Dmitry Skiba | 5883220 | 2015-07-06 16:11:13 -0700 | [diff] [blame] | 33 | const TString *TFunction::buildMangledName() const |
| 34 | { |
Cooper Partin | 149e6e6 | 2015-08-07 16:18:18 -0700 | [diff] [blame] | 35 | std::string newName = mangleName(getName()).c_str(); |
Dmitry Skiba | 5883220 | 2015-07-06 16:11:13 -0700 | [diff] [blame] | 36 | |
| 37 | for (const auto &p : parameters) |
| 38 | { |
Cooper Partin | 149e6e6 | 2015-08-07 16:18:18 -0700 | [diff] [blame] | 39 | newName += p.type->getMangledName().c_str(); |
Dmitry Skiba | 5883220 | 2015-07-06 16:11:13 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Cooper Partin | 149e6e6 | 2015-08-07 16:18:18 -0700 | [diff] [blame] | 42 | return NewPoolTString(newName.c_str()); |
Dmitry Skiba | 5883220 | 2015-07-06 16:11:13 -0700 | [diff] [blame] | 43 | } |
| 44 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 45 | // |
| 46 | // Symbol table levels are a map of pointers to symbols that have to be deleted. |
| 47 | // |
| 48 | TSymbolTableLevel::~TSymbolTableLevel() |
| 49 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 50 | for (tLevel::iterator it = level.begin(); it != level.end(); ++it) |
| 51 | delete (*it).second; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 54 | bool TSymbolTableLevel::insert(TSymbol *symbol) |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 55 | { |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 56 | symbol->setUniqueId(TSymbolTable::nextUniqueId()); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 57 | |
| 58 | // returning true means symbol was added to the table |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 59 | tInsertResult result = level.insert(tLevelPair(symbol->getMangledName(), symbol)); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 60 | |
| 61 | return result.second; |
| 62 | } |
| 63 | |
Olli Etuaho | b2983c9 | 2015-03-18 14:02:46 +0200 | [diff] [blame] | 64 | bool TSymbolTableLevel::insertUnmangled(TFunction *function) |
| 65 | { |
| 66 | function->setUniqueId(TSymbolTable::nextUniqueId()); |
| 67 | |
| 68 | // returning true means symbol was added to the table |
| 69 | tInsertResult result = level.insert(tLevelPair(function->getName(), function)); |
| 70 | |
| 71 | return result.second; |
| 72 | } |
| 73 | |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 74 | TSymbol *TSymbolTableLevel::find(const TString &name) const |
| 75 | { |
| 76 | tLevel::const_iterator it = level.find(name); |
| 77 | if (it == level.end()) |
| 78 | return 0; |
| 79 | else |
| 80 | return (*it).second; |
| 81 | } |
| 82 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 83 | TSymbol *TSymbolTable::find(const TString &name, int shaderVersion, |
| 84 | bool *builtIn, bool *sameScope) const |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 85 | { |
| 86 | int level = currentLevel(); |
| 87 | TSymbol *symbol; |
| 88 | |
| 89 | do |
| 90 | { |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame^] | 91 | if (level == ESSL3_1_BUILTINS && shaderVersion != 310) |
| 92 | level--; |
| 93 | if (level == ESSL3_BUILTINS && shaderVersion < 300) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 94 | level--; |
| 95 | if (level == ESSL1_BUILTINS && shaderVersion != 100) |
| 96 | level--; |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 97 | |
| 98 | symbol = table[level]->find(name); |
| 99 | } |
| 100 | while (symbol == 0 && --level >= 0); |
| 101 | |
| 102 | if (builtIn) |
| 103 | *builtIn = (level <= LAST_BUILTIN_LEVEL); |
| 104 | if (sameScope) |
| 105 | *sameScope = (level == currentLevel()); |
| 106 | |
| 107 | return symbol; |
| 108 | } |
| 109 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 110 | TSymbol *TSymbolTable::findBuiltIn( |
| 111 | const TString &name, int shaderVersion) const |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 112 | { |
| 113 | for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--) |
| 114 | { |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame^] | 115 | if (level == ESSL3_1_BUILTINS && shaderVersion != 310) |
| 116 | level--; |
| 117 | if (level == ESSL3_BUILTINS && shaderVersion < 300) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 118 | level--; |
| 119 | if (level == ESSL1_BUILTINS && shaderVersion != 100) |
| 120 | level--; |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 121 | |
| 122 | TSymbol *symbol = table[level]->find(name); |
| 123 | |
| 124 | if (symbol) |
| 125 | return symbol; |
| 126 | } |
| 127 | |
| 128 | return 0; |
| 129 | } |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 130 | |
| 131 | TSymbolTable::~TSymbolTable() |
| 132 | { |
| 133 | while (table.size() > 0) |
| 134 | pop(); |
| 135 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 136 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 137 | bool IsGenType(const TType *type) |
| 138 | { |
| 139 | if (type) |
| 140 | { |
| 141 | TBasicType basicType = type->getBasicType(); |
| 142 | return basicType == EbtGenType || basicType == EbtGenIType || basicType == EbtGenUType || basicType == EbtGenBType; |
| 143 | } |
| 144 | |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | bool IsVecType(const TType *type) |
| 149 | { |
| 150 | if (type) |
| 151 | { |
| 152 | TBasicType basicType = type->getBasicType(); |
| 153 | return basicType == EbtVec || basicType == EbtIVec || basicType == EbtUVec || basicType == EbtBVec; |
| 154 | } |
| 155 | |
| 156 | return false; |
| 157 | } |
| 158 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 159 | const TType *SpecificType(const TType *type, int size) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 160 | { |
| 161 | ASSERT(size >= 1 && size <= 4); |
| 162 | |
| 163 | if (!type) |
| 164 | { |
| 165 | return nullptr; |
| 166 | } |
| 167 | |
| 168 | ASSERT(!IsVecType(type)); |
| 169 | |
| 170 | switch(type->getBasicType()) |
| 171 | { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 172 | case EbtGenType: return TCache::getType(EbtFloat, static_cast<unsigned char>(size)); |
| 173 | case EbtGenIType: return TCache::getType(EbtInt, static_cast<unsigned char>(size)); |
| 174 | case EbtGenUType: return TCache::getType(EbtUInt, static_cast<unsigned char>(size)); |
| 175 | case EbtGenBType: return TCache::getType(EbtBool, static_cast<unsigned char>(size)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 176 | default: return type; |
| 177 | } |
| 178 | } |
| 179 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 180 | const TType *VectorType(const TType *type, int size) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 181 | { |
| 182 | ASSERT(size >= 2 && size <= 4); |
| 183 | |
| 184 | if (!type) |
| 185 | { |
| 186 | return nullptr; |
| 187 | } |
| 188 | |
| 189 | ASSERT(!IsGenType(type)); |
| 190 | |
| 191 | switch(type->getBasicType()) |
| 192 | { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 193 | case EbtVec: return TCache::getType(EbtFloat, static_cast<unsigned char>(size)); |
| 194 | case EbtIVec: return TCache::getType(EbtInt, static_cast<unsigned char>(size)); |
| 195 | case EbtUVec: return TCache::getType(EbtUInt, static_cast<unsigned char>(size)); |
| 196 | case EbtBVec: return TCache::getType(EbtBool, static_cast<unsigned char>(size)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 197 | default: return type; |
| 198 | } |
| 199 | } |
| 200 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 201 | void TSymbolTable::insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, const TType *rvalue, const char *name, |
| 202 | const TType *ptype1, const TType *ptype2, const TType *ptype3, const TType *ptype4, const TType *ptype5) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 203 | { |
| 204 | if (ptype1->getBasicType() == EbtGSampler2D) |
| 205 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 206 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 207 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 208 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); |
| 209 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5); |
| 210 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 211 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 212 | else if (ptype1->getBasicType() == EbtGSampler3D) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 213 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 214 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 215 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 216 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); |
| 217 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5); |
| 218 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 219 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 220 | else if (ptype1->getBasicType() == EbtGSamplerCube) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 221 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 222 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 223 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 224 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); |
| 225 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5); |
| 226 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 227 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 228 | else if (ptype1->getBasicType() == EbtGSampler2DArray) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 229 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 230 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 231 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 232 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); |
| 233 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5); |
| 234 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 235 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 236 | else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3)) |
| 237 | { |
| 238 | ASSERT(!ptype4 && !ptype5); |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 239 | insertUnmangledBuiltIn(name); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 240 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 1), name, SpecificType(ptype1, 1), SpecificType(ptype2, 1), SpecificType(ptype3, 1)); |
| 241 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 2), name, SpecificType(ptype1, 2), SpecificType(ptype2, 2), SpecificType(ptype3, 2)); |
| 242 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 3), name, SpecificType(ptype1, 3), SpecificType(ptype2, 3), SpecificType(ptype3, 3)); |
| 243 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 4), name, SpecificType(ptype1, 4), SpecificType(ptype2, 4), SpecificType(ptype3, 4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 244 | } |
| 245 | else if (IsVecType(rvalue) || IsVecType(ptype1) || IsVecType(ptype2) || IsVecType(ptype3)) |
| 246 | { |
| 247 | ASSERT(!ptype4 && !ptype5); |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 248 | insertUnmangledBuiltIn(name); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 249 | insertBuiltIn(level, op, ext, VectorType(rvalue, 2), name, VectorType(ptype1, 2), VectorType(ptype2, 2), VectorType(ptype3, 2)); |
| 250 | insertBuiltIn(level, op, ext, VectorType(rvalue, 3), name, VectorType(ptype1, 3), VectorType(ptype2, 3), VectorType(ptype3, 3)); |
| 251 | insertBuiltIn(level, op, ext, VectorType(rvalue, 4), name, VectorType(ptype1, 4), VectorType(ptype2, 4), VectorType(ptype3, 4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 252 | } |
| 253 | else |
| 254 | { |
Dmitry Skiba | 7f17a50 | 2015-06-22 15:08:39 -0700 | [diff] [blame] | 255 | TFunction *function = new TFunction(NewPoolTString(name), rvalue, op, ext); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 256 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 257 | function->addParameter(TConstParameter(ptype1)); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 258 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 259 | if (ptype2) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 260 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 261 | function->addParameter(TConstParameter(ptype2)); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 262 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 263 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 264 | if (ptype3) |
| 265 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 266 | function->addParameter(TConstParameter(ptype3)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | if (ptype4) |
| 270 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 271 | function->addParameter(TConstParameter(ptype4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | if (ptype5) |
| 275 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 276 | function->addParameter(TConstParameter(ptype5)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 277 | } |
| 278 | |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 279 | ASSERT(hasUnmangledBuiltIn(name)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 280 | insert(level, function); |
| 281 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 284 | TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 285 | { |
| 286 | if (!SupportsPrecision(type)) |
| 287 | return EbpUndefined; |
| 288 | |
| 289 | // unsigned integers use the same precision as signed |
| 290 | TBasicType baseType = (type == EbtUInt) ? EbtInt : type; |
| 291 | |
| 292 | int level = static_cast<int>(precisionStack.size()) - 1; |
| 293 | assert(level >= 0); // Just to be safe. Should not happen. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 294 | // If we dont find anything we return this. Some types don't have predefined default precision. |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 295 | TPrecision prec = EbpUndefined; |
| 296 | while (level >= 0) |
| 297 | { |
| 298 | PrecisionStackLevel::iterator it = precisionStack[level]->find(baseType); |
| 299 | if (it != precisionStack[level]->end()) |
| 300 | { |
| 301 | prec = (*it).second; |
| 302 | break; |
| 303 | } |
| 304 | level--; |
| 305 | } |
| 306 | return prec; |
| 307 | } |