blob: fe2e9eca72483e8ae6a97a5f52454ca2bde3e746 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens1fbc2872014-01-03 14:12:09 -05002// 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_SYMBOLTABLE_H_
8#define COMPILER_TRANSLATOR_SYMBOLTABLE_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009
10//
11// Symbol table for parsing. Has these design characteristics:
12//
13// * Same symbol table can be used to compile many shaders, to preserve
14// effort of creating and loading with the large numbers of built-in
15// symbols.
16//
17// * Name mangling will be used to give each function a unique name
18// so that symbol table lookups are never ambiguous. This allows
19// a simpler symbol table structure.
20//
21// * Pushing and popping of scope, so symbol table will really be a stack
22// of symbol tables. Searched from the top, with new inserts going into
23// the top.
24//
25// * Constants: Compile time constant symbols will keep their values
26// in the symbol table. The parser can substitute constants at parse
27// time, including doing constant folding and constant propagation.
28//
29// * No temporaries: Temporaries made from operations (+, --, .xy, etc.)
30// are tracked in the intermediate representation, not the symbol table.
31//
32
alokp@chromium.org4e4facd2010-06-02 15:21:22 +000033#include <assert.h>
Zhenyao Mo94ac7b72014-10-15 18:22:08 -070034#include <set>
alokp@chromium.orge4249f02010-07-26 18:13:52 +000035
Jamie Madill703cdd62013-07-08 15:07:30 -040036#include "common/angleutils.h"
Geoff Lang17732822013-08-29 13:46:49 -040037#include "compiler/translator/InfoSink.h"
Jamie Madillb1a85f42014-08-19 15:23:24 -040038#include "compiler/translator/IntermNode.h"
alokp@chromium.org43884872010-03-30 00:08:52 +000039
Zhenyao Mo9eedea02014-05-12 16:02:35 -070040// Symbol base class. (Can build functions or variables out of these...)
Jamie Madillf0d10f82015-03-31 12:56:52 -040041class TSymbol : angle::NonCopyable
Zhenyao Mo9eedea02014-05-12 16:02:35 -070042{
43 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040044 POOL_ALLOCATOR_NEW_DELETE();
Zhenyao Mo9eedea02014-05-12 16:02:35 -070045 TSymbol(const TString *n)
46 : uniqueId(0),
47 name(n)
48 {
49 }
50 virtual ~TSymbol()
51 {
52 // don't delete name, it's from the pool
53 }
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040054
Zhenyao Mo9eedea02014-05-12 16:02:35 -070055 const TString &getName() const
56 {
57 return *name;
58 }
59 virtual const TString &getMangledName() const
60 {
61 return getName();
62 }
63 virtual bool isFunction() const
64 {
65 return false;
66 }
67 virtual bool isVariable() const
68 {
69 return false;
70 }
71 void setUniqueId(int id)
72 {
73 uniqueId = id;
74 }
75 int getUniqueId() const
76 {
77 return uniqueId;
78 }
79 void relateToExtension(const TString &ext)
80 {
81 extension = ext;
82 }
83 const TString &getExtension() const
84 {
85 return extension;
86 }
Nicolas Capensba60ad32013-06-04 15:55:47 -040087
Zhenyao Mo9eedea02014-05-12 16:02:35 -070088 private:
Zhenyao Mo9eedea02014-05-12 16:02:35 -070089 int uniqueId; // For real comparing during code generation
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000090 const TString *name;
Jamie Madill2aeb26a2013-07-08 14:02:55 -040091 TString extension;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000092};
93
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000094// Variable class, meaning a symbol that's not a function.
95//
96// There could be a separate class heirarchy for Constant variables;
97// Only one of int, bool, or float, (or none) is correct for
98// any particular use, but it's easy to do this way, and doesn't
99// seem worth having separate classes, and "getConst" can't simply return
100// different values for different types polymorphically, so this is
101// just simple and pragmatic.
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700102class TVariable : public TSymbol
103{
104 public:
105 TVariable(const TString *name, const TType &t, bool uT = false)
106 : TSymbol(name),
107 type(t),
108 userType(uT),
109 unionArray(0)
110 {
111 }
112 virtual ~TVariable()
113 {
114 }
115 virtual bool isVariable() const
116 {
117 return true;
118 }
119 TType &getType()
120 {
121 return type;
122 }
123 const TType &getType() const
124 {
125 return type;
126 }
127 bool isUserType() const
128 {
129 return userType;
130 }
131 void setQualifier(TQualifier qualifier)
132 {
133 type.setQualifier(qualifier);
134 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135
Jamie Madill6ba6ead2015-05-04 14:21:21 -0400136 TConstantUnion *getConstPointer()
alokp@chromium.org43884872010-03-30 00:08:52 +0000137 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000138 if (!unionArray)
Jamie Madill6ba6ead2015-05-04 14:21:21 -0400139 unionArray = new TConstantUnion[type.getObjectSize()];
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000140
141 return unionArray;
142 }
143
Jamie Madill6ba6ead2015-05-04 14:21:21 -0400144 TConstantUnion *getConstPointer() const
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700145 {
146 return unionArray;
147 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000148
Jamie Madill6ba6ead2015-05-04 14:21:21 -0400149 void shareConstPointer(TConstantUnion *constArray)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000150 {
alokp@chromium.org6c82caf2010-10-14 16:08:56 +0000151 if (unionArray == constArray)
152 return;
153
154 delete[] unionArray;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000155 unionArray = constArray;
156 }
alokp@chromium.org43884872010-03-30 00:08:52 +0000157
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700158 private:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000159 TType type;
160 bool userType;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700161 // we are assuming that Pool Allocator will free the memory
162 // allocated to unionArray when this object is destroyed.
Jamie Madill6ba6ead2015-05-04 14:21:21 -0400163 TConstantUnion *unionArray;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000164};
165
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700166// Immutable version of TParameter.
167struct TConstParameter
168{
169 TConstParameter()
170 : name(nullptr),
171 type(nullptr)
172 {
173 }
174 explicit TConstParameter(const TString *n)
175 : name(n),
176 type(nullptr)
177 {
178 }
179 explicit TConstParameter(const TType *t)
180 : name(nullptr),
181 type(t)
182 {
183 }
184 TConstParameter(const TString *n, const TType *t)
185 : name(n),
186 type(t)
187 {
188 }
189
190 // Both constructor arguments must be const.
191 TConstParameter(TString *n, TType *t) = delete;
192 TConstParameter(const TString *n, TType *t) = delete;
193 TConstParameter(TString *n, const TType *t) = delete;
194
195 const TString *name;
196 const TType *type;
197};
198
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000199// The function sub-class of symbols and the parser will need to
200// share this definition of a function parameter.
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700201struct TParameter
202{
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700203 // Destructively converts to TConstParameter.
204 // This method resets name and type to nullptrs to make sure
205 // their content cannot be modified after the call.
206 TConstParameter turnToConst()
207 {
208 const TString *constName = name;
209 const TType *constType = type;
210 name = nullptr;
211 type = nullptr;
212 return TConstParameter(constName, constType);
213 }
214
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000215 TString *name;
Nicolas Capensbd10cf52013-06-20 09:51:51 -0400216 TType *type;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000217};
218
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000219// The function sub-class of a symbol.
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700220class TFunction : public TSymbol
221{
222 public:
223 TFunction(TOperator o)
224 : TSymbol(0),
225 returnType(TType(EbtVoid, EbpUndefined)),
226 op(o),
227 defined(false)
228 {
229 }
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500230 TFunction(const TString *name, const TType &retType, TOperator tOp = EOpNull, const char *ext = "")
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700231 : TSymbol(name),
232 returnType(retType),
233 mangledName(TFunction::mangleName(*name)),
234 op(tOp),
235 defined(false)
236 {
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500237 relateToExtension(ext);
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700238 }
alokp@chromium.org43884872010-03-30 00:08:52 +0000239 virtual ~TFunction();
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700240 virtual bool isFunction() const
241 {
242 return true;
243 }
alokp@chromium.org43884872010-03-30 00:08:52 +0000244
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700245 static TString mangleName(const TString &name)
246 {
247 return name + '(';
248 }
249 static TString unmangleName(const TString &mangledName)
alokp@chromium.org43884872010-03-30 00:08:52 +0000250 {
251 return TString(mangledName.c_str(), mangledName.find_first_of('('));
252 }
253
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700254 void addParameter(const TConstParameter &p)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000255 {
256 parameters.push_back(p);
257 mangledName = mangledName + p.type->getMangledName();
258 }
alokp@chromium.org43884872010-03-30 00:08:52 +0000259
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700260 const TString &getMangledName() const
261 {
262 return mangledName;
263 }
264 const TType &getReturnType() const
265 {
266 return returnType;
267 }
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000268
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700269 TOperator getBuiltInOp() const
270 {
271 return op;
272 }
alokp@chromium.org8815d7f2010-09-09 17:30:03 +0000273
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700274 void setDefined()
275 {
276 defined = true;
277 }
278 bool isDefined()
279 {
280 return defined;
281 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000282
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700283 size_t getParamCount() const
284 {
285 return parameters.size();
286 }
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700287 const TConstParameter &getParam(size_t i) const
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700288 {
289 return parameters[i];
290 }
alokp@chromium.org43884872010-03-30 00:08:52 +0000291
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700292 private:
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700293 typedef TVector<TConstParameter> TParamList;
alokp@chromium.org43884872010-03-30 00:08:52 +0000294 TParamList parameters;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000295 TType returnType;
296 TString mangledName;
297 TOperator op;
298 bool defined;
299};
300
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000301// Interface block name sub-symbol
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000302class TInterfaceBlockName : public TSymbol
303{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700304 public:
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000305 TInterfaceBlockName(const TString *name)
306 : TSymbol(name)
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700307 {
308 }
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000309
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700310 virtual ~TInterfaceBlockName()
311 {
312 }
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000313};
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000314
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700315class TSymbolTableLevel
316{
317 public:
318 typedef TMap<TString, TSymbol *> tLevel;
alokp@chromium.org43884872010-03-30 00:08:52 +0000319 typedef tLevel::const_iterator const_iterator;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000320 typedef const tLevel::value_type tLevelPair;
321 typedef std::pair<tLevel::iterator, bool> tInsertResult;
322
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700323 TSymbolTableLevel()
324 {
325 }
alokp@chromium.org43884872010-03-30 00:08:52 +0000326 ~TSymbolTableLevel();
327
Nicolas Capensadfffe42014-06-17 02:13:36 -0400328 bool insert(TSymbol *symbol);
Nicolas Capensbd10cf52013-06-20 09:51:51 -0400329
Olli Etuahob2983c92015-03-18 14:02:46 +0200330 // Insert a function using its unmangled name as the key.
331 bool insertUnmangled(TFunction *function);
332
Jamie Madillbfa91f42014-06-05 15:45:18 -0400333 TSymbol *find(const TString &name) const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000334
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700335 protected:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000336 tLevel level;
337};
338
Gus Fernandez964df492014-10-13 11:54:39 -0700339// Define ESymbolLevel as int rather than an enum since level can go
340// above GLOBAL_LEVEL and cause atBuiltInLevel() to fail if the
341// compiler optimizes the >= of the last element to ==.
342typedef int ESymbolLevel;
343const int COMMON_BUILTINS = 0;
344const int ESSL1_BUILTINS = 1;
345const int ESSL3_BUILTINS = 2;
346const int LAST_BUILTIN_LEVEL = ESSL3_BUILTINS;
347const int GLOBAL_LEVEL = 3;
shannonwoods@chromium.org6e10a0e2013-05-30 00:02:13 +0000348
Jamie Madillf0d10f82015-03-31 12:56:52 -0400349class TSymbolTable : angle::NonCopyable
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700350{
351 public:
Nicolas Capensbd10cf52013-06-20 09:51:51 -0400352 TSymbolTable()
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700353 : mGlobalInvariant(false)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000354 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000355 // The symbol table cannot be used until push() is called, but
356 // the lack of an initial call to push() can be used to detect
357 // that the symbol table has not been preloaded with built-ins.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000358 }
359
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400360 ~TSymbolTable();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000361
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000362 // When the symbol table is initialized with the built-ins, there should
363 // 'push' calls, so that built-ins are at level 0 and the shader
364 // globals are at level 1.
Zhenyao Moe740add2014-07-18 17:01:01 -0700365 bool isEmpty() const
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700366 {
367 return table.empty();
368 }
Zhenyao Moe740add2014-07-18 17:01:01 -0700369 bool atBuiltInLevel() const
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700370 {
371 return currentLevel() <= LAST_BUILTIN_LEVEL;
372 }
Zhenyao Moe740add2014-07-18 17:01:01 -0700373 bool atGlobalLevel() const
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700374 {
375 return currentLevel() <= GLOBAL_LEVEL;
376 }
alokp@chromium.org43884872010-03-30 00:08:52 +0000377 void push()
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000378 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000379 table.push_back(new TSymbolTableLevel);
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400380 precisionStack.push_back(new PrecisionStackLevel);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000381 }
382
alokp@chromium.org43884872010-03-30 00:08:52 +0000383 void pop()
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400384 {
385 delete table.back();
386 table.pop_back();
387
388 delete precisionStack.back();
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000389 precisionStack.pop_back();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000390 }
391
Nicolas Capensadfffe42014-06-17 02:13:36 -0400392 bool declare(TSymbol *symbol)
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000393 {
394 return insert(currentLevel(), symbol);
395 }
396
Nicolas Capensadfffe42014-06-17 02:13:36 -0400397 bool insert(ESymbolLevel level, TSymbol *symbol)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000398 {
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000399 return table[level]->insert(symbol);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000400 }
alokp@chromium.org43884872010-03-30 00:08:52 +0000401
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500402 bool insert(ESymbolLevel level, const char *ext, TSymbol *symbol)
403 {
404 symbol->relateToExtension(ext);
405 return table[level]->insert(symbol);
406 }
407
Nicolas Capens49a88872013-06-20 09:54:03 -0400408 bool insertConstInt(ESymbolLevel level, const char *name, int value)
409 {
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700410 TVariable *constant = new TVariable(
411 NewPoolTString(name), TType(EbtInt, EbpUndefined, EvqConst, 1));
Nicolas Capens49a88872013-06-20 09:54:03 -0400412 constant->getConstPointer()->setIConst(value);
Nicolas Capensadfffe42014-06-17 02:13:36 -0400413 return insert(level, constant);
Nicolas Capens49a88872013-06-20 09:54:03 -0400414 }
415
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700416 void insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, const TType *rvalue, const char *name,
417 const TType *ptype1, const TType *ptype2 = 0, const TType *ptype3 = 0, const TType *ptype4 = 0, const TType *ptype5 = 0);
Nicolas Capens759b9942014-02-14 17:57:14 -0500418
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700419 void insertBuiltIn(ESymbolLevel level, const TType *rvalue, const char *name,
420 const TType *ptype1, const TType *ptype2 = 0, const TType *ptype3 = 0, const TType *ptype4 = 0, const TType *ptype5 = 0)
Nicolas Capens482907e2015-02-23 16:56:33 -0500421 {
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500422 insertBuiltIn(level, EOpNull, "", rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5);
423 }
424
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700425 void insertBuiltIn(ESymbolLevel level, const char *ext, const TType *rvalue, const char *name,
426 const TType *ptype1, const TType *ptype2 = 0, const TType *ptype3 = 0, const TType *ptype4 = 0, const TType *ptype5 = 0)
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500427 {
428 insertBuiltIn(level, EOpNull, ext, rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5);
429 }
430
Dmitry Skibaefa3d8e2015-06-22 14:52:10 -0700431 void insertBuiltIn(ESymbolLevel level, TOperator op, const TType *rvalue, const char *name,
432 const TType *ptype1, const TType *ptype2 = 0, const TType *ptype3 = 0, const TType *ptype4 = 0, const TType *ptype5 = 0)
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500433 {
434 insertBuiltIn(level, op, "", rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5);
Nicolas Capens482907e2015-02-23 16:56:33 -0500435 }
436
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700437 TSymbol *find(const TString &name, int shaderVersion,
Zhenyao Moe740add2014-07-18 17:01:01 -0700438 bool *builtIn = NULL, bool *sameScope = NULL) const;
439 TSymbol *findBuiltIn(const TString &name, int shaderVersion) const;
shannonwoods@chromium.org6e10a0e2013-05-30 00:02:13 +0000440
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700441 TSymbolTableLevel *getOuterLevel()
442 {
shannonwoods@chromium.org6e10a0e2013-05-30 00:02:13 +0000443 assert(currentLevel() >= 1);
daniel@transgaming.com5dd6d092012-03-20 20:10:28 +0000444 return table[currentLevel() - 1];
445 }
446
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400447 void dump(TInfoSink &infoSink) const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000448
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700449 bool setDefaultPrecision(const TPublicType &type, TPrecision prec)
450 {
Zhenyao Moed14b792014-05-08 11:21:07 -0700451 if (!SupportsPrecision(type.type))
Zhenyao Moa5a1dfc2013-09-23 14:57:03 -0400452 return false;
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000453 if (type.isAggregate())
shannon.woods@transgaming.comd25a6b32013-02-28 23:19:13 +0000454 return false; // Not allowed to set for aggregate types
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000455 int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700456 // Uses map operator [], overwrites the current value
457 (*precisionStack[indexOfLastElement])[type.type] = prec;
shannon.woods@transgaming.comd25a6b32013-02-28 23:19:13 +0000458 return true;
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000459 }
460
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700461 // Searches down the precisionStack for a precision qualifier
462 // for the specified TBasicType
Zhenyao Moe740add2014-07-18 17:01:01 -0700463 TPrecision getDefaultPrecision(TBasicType type) const;
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000464
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700465 // This records invariant varyings declared through
466 // "invariant varying_name;".
Jamie Madill2c433252014-12-03 12:36:54 -0500467 void addInvariantVarying(const std::string &originalName)
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700468 {
469 mInvariantVaryings.insert(originalName);
470 }
471 // If this returns false, the varying could still be invariant
472 // if it is set as invariant during the varying variable
473 // declaration - this piece of information is stored in the
474 // variable's type, not here.
Jamie Madill2c433252014-12-03 12:36:54 -0500475 bool isVaryingInvariant(const std::string &originalName) const
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700476 {
477 return (mGlobalInvariant ||
478 mInvariantVaryings.count(originalName) > 0);
479 }
480
481 void setGlobalInvariant() { mGlobalInvariant = true; }
482 bool getGlobalInvariant() const { return mGlobalInvariant; }
483
Jamie Madillbfa91f42014-06-05 15:45:18 -0400484 static int nextUniqueId()
485 {
486 return ++uniqueIdCounter;
487 }
488
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700489 private:
490 ESymbolLevel currentLevel() const
491 {
492 return static_cast<ESymbolLevel>(table.size() - 1);
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000493 }
494
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700495 std::vector<TSymbolTableLevel *> table;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400496 typedef TMap<TBasicType, TPrecision> PrecisionStackLevel;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700497 std::vector< PrecisionStackLevel *> precisionStack;
Jamie Madillbfa91f42014-06-05 15:45:18 -0400498
Jamie Madill2c433252014-12-03 12:36:54 -0500499 std::set<std::string> mInvariantVaryings;
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700500 bool mGlobalInvariant;
501
Jamie Madillbfa91f42014-06-05 15:45:18 -0400502 static int uniqueIdCounter;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000503};
504
Geoff Lang0a73dd82014-11-19 16:18:08 -0500505#endif // COMPILER_TRANSLATOR_SYMBOLTABLE_H_