blob: 075196daa3ff6ad8fdc25f2a07dab2344e82d472 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
shannon.woods%transgaming.com@gtempaccount.com6f273e32013-04-13 03:41:15 +00002// Copyright (c) 2002-2013 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
7#ifndef _TYPES_INCLUDED
8#define _TYPES_INCLUDED
9
Jamie Madill98493dd2013-07-08 14:39:03 -040010#include "common/angleutils.h"
11
Geoff Lang17732822013-08-29 13:46:49 -040012#include "compiler/translator/BaseTypes.h"
13#include "compiler/translator/Common.h"
14#include "compiler/translator/compilerdebug.h"
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000015
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +000016struct TPublicType;
Jamie Madill98493dd2013-07-08 14:39:03 -040017class TType;
Jamie Madillbfa91f42014-06-05 15:45:18 -040018class TSymbol;
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +000019
Jamie Madill98493dd2013-07-08 14:39:03 -040020class TField
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000021{
Zhenyao Mo9eedea02014-05-12 16:02:35 -070022 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -040023 POOL_ALLOCATOR_NEW_DELETE();
Zhenyao Mo9eedea02014-05-12 16:02:35 -070024 TField(TType *type, TString *name, const TSourceLoc &line)
25 : mType(type),
26 mName(name),
27 mLine(line)
28 {
29 }
Jamie Madill98493dd2013-07-08 14:39:03 -040030
31 // TODO(alokp): We should only return const type.
32 // Fix it by tweaking grammar.
Zhenyao Mo9eedea02014-05-12 16:02:35 -070033 TType *type()
34 {
35 return mType;
36 }
37 const TType *type() const
38 {
39 return mType;
40 }
Jamie Madill98493dd2013-07-08 14:39:03 -040041
Zhenyao Mo9eedea02014-05-12 16:02:35 -070042 const TString &name() const
43 {
44 return *mName;
45 }
46 const TSourceLoc &line() const
47 {
48 return mLine;
49 }
Jamie Madill98493dd2013-07-08 14:39:03 -040050
Zhenyao Mo9eedea02014-05-12 16:02:35 -070051 private:
Jamie Madill98493dd2013-07-08 14:39:03 -040052 DISALLOW_COPY_AND_ASSIGN(TField);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070053 TType *mType;
54 TString *mName;
Jamie Madill98493dd2013-07-08 14:39:03 -040055 TSourceLoc mLine;
56};
57
Zhenyao Mo9eedea02014-05-12 16:02:35 -070058typedef TVector<TField *> TFieldList;
59inline TFieldList *NewPoolTFieldList()
Jamie Madill98493dd2013-07-08 14:39:03 -040060{
Zhenyao Mo9eedea02014-05-12 16:02:35 -070061 void *memory = GetGlobalPoolAllocator()->allocate(sizeof(TFieldList));
Jamie Madill98493dd2013-07-08 14:39:03 -040062 return new(memory) TFieldList;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000063}
64
Jamie Madill98493dd2013-07-08 14:39:03 -040065class TFieldListCollection
66{
Zhenyao Mo9eedea02014-05-12 16:02:35 -070067 public:
68 const TString &name() const
69 {
70 return *mName;
71 }
72 const TFieldList &fields() const
73 {
74 return *mFields;
75 }
Jamie Madill98493dd2013-07-08 14:39:03 -040076
Zhenyao Mo9eedea02014-05-12 16:02:35 -070077 const TString &mangledName() const
78 {
Jamie Madill98493dd2013-07-08 14:39:03 -040079 if (mMangledName.empty())
80 mMangledName = buildMangledName();
81 return mMangledName;
82 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -070083 size_t objectSize() const
84 {
Jamie Madill98493dd2013-07-08 14:39:03 -040085 if (mObjectSize == 0)
86 mObjectSize = calculateObjectSize();
87 return mObjectSize;
88 };
89
Zhenyao Mo9eedea02014-05-12 16:02:35 -070090 protected:
91 TFieldListCollection(const TString *name, TFieldList *fields)
Jamie Madill98493dd2013-07-08 14:39:03 -040092 : mName(name),
93 mFields(fields),
Zhenyao Mo9eedea02014-05-12 16:02:35 -070094 mObjectSize(0)
95 {
Jamie Madill98493dd2013-07-08 14:39:03 -040096 }
97 TString buildMangledName() const;
98 size_t calculateObjectSize() const;
99 virtual TString mangledNamePrefix() const = 0;
100
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700101 const TString *mName;
102 TFieldList *mFields;
Jamie Madill98493dd2013-07-08 14:39:03 -0400103
104 mutable TString mMangledName;
105 mutable size_t mObjectSize;
106};
107
108// May also represent interface blocks
109class TStructure : public TFieldListCollection
110{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700111 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -0400112 POOL_ALLOCATOR_NEW_DELETE();
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700113 TStructure(const TString *name, TFieldList *fields)
Jamie Madill98493dd2013-07-08 14:39:03 -0400114 : TFieldListCollection(name, fields),
Jamie Madillbfa91f42014-06-05 15:45:18 -0400115 mDeepestNesting(0),
116 mUniqueId(0)
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700117 {
Jamie Madill98493dd2013-07-08 14:39:03 -0400118 }
119
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700120 int deepestNesting() const
121 {
Jamie Madill98493dd2013-07-08 14:39:03 -0400122 if (mDeepestNesting == 0)
123 mDeepestNesting = calculateDeepestNesting();
124 return mDeepestNesting;
125 }
126 bool containsArrays() const;
127
Zhenyao Moc8f72322014-05-13 15:21:37 -0700128 bool equals(const TStructure &other) const;
129
Jamie Madillbfa91f42014-06-05 15:45:18 -0400130 void setUniqueId(int uniqueId)
131 {
132 mUniqueId = uniqueId;
133 }
134
135 int uniqueId() const
136 {
137 ASSERT(mUniqueId != 0);
138 return mUniqueId;
139 }
140
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700141 private:
Jamie Madill98493dd2013-07-08 14:39:03 -0400142 DISALLOW_COPY_AND_ASSIGN(TStructure);
Zhenyao Moe740add2014-07-18 17:01:01 -0700143
144 // TODO(zmo): Find a way to get rid of the const_cast in function
145 // setName(). At the moment keep this function private so only
146 // friend class RegenerateStructNames may call it.
147 friend class RegenerateStructNames;
148 void setName(const TString &name)
149 {
150 TString *mutableName = const_cast<TString *>(mName);
151 *mutableName = name;
152 }
153
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700154 virtual TString mangledNamePrefix() const
155 {
156 return "struct-";
157 }
Jamie Madill98493dd2013-07-08 14:39:03 -0400158 int calculateDeepestNesting() const;
159
160 mutable int mDeepestNesting;
Jamie Madillbfa91f42014-06-05 15:45:18 -0400161 int mUniqueId;
Jamie Madill98493dd2013-07-08 14:39:03 -0400162};
163
164class TInterfaceBlock : public TFieldListCollection
165{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700166 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -0400167 POOL_ALLOCATOR_NEW_DELETE();
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700168 TInterfaceBlock(const TString *name, TFieldList *fields, const TString *instanceName,
169 int arraySize, const TLayoutQualifier &layoutQualifier)
Jamie Madill98493dd2013-07-08 14:39:03 -0400170 : TFieldListCollection(name, fields),
171 mInstanceName(instanceName),
172 mArraySize(arraySize),
173 mBlockStorage(layoutQualifier.blockStorage),
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700174 mMatrixPacking(layoutQualifier.matrixPacking)
175 {
Jamie Madill98493dd2013-07-08 14:39:03 -0400176 }
177
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700178 const TString &instanceName() const
179 {
180 return *mInstanceName;
181 }
182 bool hasInstanceName() const
183 {
184 return mInstanceName != NULL;
185 }
186 bool isArray() const
187 {
188 return mArraySize > 0;
189 }
190 int arraySize() const
191 {
192 return mArraySize;
193 }
194 TLayoutBlockStorage blockStorage() const
195 {
196 return mBlockStorage;
197 }
198 TLayoutMatrixPacking matrixPacking() const
199 {
200 return mMatrixPacking;
201 }
Jamie Madill98493dd2013-07-08 14:39:03 -0400202
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700203 private:
Jamie Madill98493dd2013-07-08 14:39:03 -0400204 DISALLOW_COPY_AND_ASSIGN(TInterfaceBlock);
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700205 virtual TString mangledNamePrefix() const
206 {
207 return "iblock-";
208 }
Jamie Madill98493dd2013-07-08 14:39:03 -0400209
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700210 const TString *mInstanceName; // for interface block instance names
Jamie Madill98493dd2013-07-08 14:39:03 -0400211 int mArraySize; // 0 if not an array
212 TLayoutBlockStorage mBlockStorage;
213 TLayoutMatrixPacking mMatrixPacking;
214};
215
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000216//
217// Base class for things that have a type.
218//
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000219class TType
220{
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700221 public:
Alok Priyadarshi8156b6b2013-09-23 14:56:58 -0400222 POOL_ALLOCATOR_NEW_DELETE();
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700223 TType()
Nicolas Capensc9508842014-02-14 17:48:50 -0500224 {
225 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700226 TType(TBasicType t, unsigned char ps = 1, unsigned char ss = 1)
227 : type(t), precision(EbpUndefined), qualifier(EvqGlobal),
228 layoutQualifier(TLayoutQualifier::create()),
229 primarySize(ps), secondarySize(ss), array(false), arraySize(0),
230 interfaceBlock(0), structure(0)
231 {
232 }
233 TType(TBasicType t, TPrecision p, TQualifier q = EvqTemporary,
234 unsigned char ps = 1, unsigned char ss = 1, bool a = false)
235 : type(t), precision(p), qualifier(q),
236 layoutQualifier(TLayoutQualifier::create()),
237 primarySize(ps), secondarySize(ss), array(a), arraySize(0),
238 interfaceBlock(0), structure(0)
alokp@chromium.org58e54292010-08-24 21:40:03 +0000239 {
240 }
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000241 explicit TType(const TPublicType &p);
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700242 TType(TStructure *userDef, TPrecision p = EbpUndefined)
243 : type(EbtStruct), precision(p), qualifier(EvqTemporary),
244 layoutQualifier(TLayoutQualifier::create()),
245 primarySize(1), secondarySize(1), array(false), arraySize(0),
246 interfaceBlock(0), structure(userDef)
alokp@chromium.org58e54292010-08-24 21:40:03 +0000247 {
Jamie Madill98493dd2013-07-08 14:39:03 -0400248 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700249 TType(TInterfaceBlock *interfaceBlockIn, TQualifier qualifierIn,
250 TLayoutQualifier layoutQualifierIn, int arraySizeIn)
251 : type(EbtInterfaceBlock), precision(EbpUndefined), qualifier(qualifierIn),
252 layoutQualifier(layoutQualifierIn),
253 primarySize(1), secondarySize(1), array(arraySizeIn > 0), arraySize(arraySizeIn),
254 interfaceBlock(interfaceBlockIn), structure(0)
Jamie Madill98493dd2013-07-08 14:39:03 -0400255 {
alokp@chromium.org58e54292010-08-24 21:40:03 +0000256 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000257
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700258 TBasicType getBasicType() const
259 {
260 return type;
261 }
262 void setBasicType(TBasicType t)
263 {
264 type = t;
265 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000266
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700267 TPrecision getPrecision() const
268 {
269 return precision;
270 }
271 void setPrecision(TPrecision p)
272 {
273 precision = p;
274 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000275
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700276 TQualifier getQualifier() const
277 {
278 return qualifier;
279 }
280 void setQualifier(TQualifier q)
281 {
282 qualifier = q;
283 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000284
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700285 TLayoutQualifier getLayoutQualifier() const
286 {
287 return layoutQualifier;
288 }
289 void setLayoutQualifier(TLayoutQualifier lq)
290 {
291 layoutQualifier = lq;
292 }
Jamie Madilla5efff92013-06-06 11:56:47 -0400293
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700294 int getNominalSize() const
295 {
296 return primarySize;
297 }
298 int getSecondarySize() const
299 {
300 return secondarySize;
301 }
302 int getCols() const
303 {
304 ASSERT(isMatrix());
305 return primarySize;
306 }
307 int getRows() const
308 {
309 ASSERT(isMatrix());
310 return secondarySize;
311 }
312 void setPrimarySize(unsigned char ps)
313 {
314 primarySize = ps;
315 }
316 void setSecondarySize(unsigned char ss)
317 {
318 secondarySize = ss;
319 }
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000320
alokp@chromium.org58e54292010-08-24 21:40:03 +0000321 // Full size of single instance of type
Jamie Madill94bf7f22013-07-08 13:31:15 -0400322 size_t getObjectSize() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000323
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700324 bool isMatrix() const
325 {
326 return primarySize > 1 && secondarySize > 1;
327 }
328 bool isArray() const
329 {
330 return array ? true : false;
331 }
332 int getArraySize() const
333 {
334 return arraySize;
335 }
336 void setArraySize(int s)
337 {
338 array = true;
339 arraySize = s;
340 }
341 void clearArrayness()
342 {
343 array = false;
344 arraySize = 0;
345 }
Jamie Madill98493dd2013-07-08 14:39:03 -0400346
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700347 TInterfaceBlock *getInterfaceBlock() const
348 {
349 return interfaceBlock;
350 }
351 void setInterfaceBlock(TInterfaceBlock *interfaceBlockIn)
352 {
353 interfaceBlock = interfaceBlockIn;
354 }
355 bool isInterfaceBlock() const
356 {
357 return type == EbtInterfaceBlock;
358 }
alokp@chromium.org58e54292010-08-24 21:40:03 +0000359
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700360 bool isVector() const
361 {
362 return primarySize > 1 && secondarySize == 1;
363 }
364 bool isScalar() const
365 {
366 return primarySize == 1 && secondarySize == 1 && !structure;
367 }
368 bool isScalarInt() const
369 {
370 return isScalar() && (type == EbtInt || type == EbtUInt);
371 }
alokp@chromium.org58e54292010-08-24 21:40:03 +0000372
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700373 TStructure *getStruct() const
374 {
375 return structure;
376 }
377 void setStruct(TStructure *s)
378 {
379 structure = s;
380 }
alokp@chromium.org58e54292010-08-24 21:40:03 +0000381
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700382 const TString &getMangledName()
383 {
384 if (mangled.empty())
385 {
Jamie Madill98493dd2013-07-08 14:39:03 -0400386 mangled = buildMangledName();
387 mangled += ';';
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000388 }
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000389
Jamie Madill98493dd2013-07-08 14:39:03 -0400390 return mangled;
shannonwoods@chromium.org5668c5d2013-05-30 00:11:48 +0000391 }
392
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700393 bool sameElementType(const TType &right) const
394 {
395 return type == right.type &&
396 primarySize == right.primarySize &&
397 secondarySize == right.secondarySize &&
398 structure == right.structure;
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000399 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700400 bool operator==(const TType &right) const
401 {
402 return type == right.type &&
403 primarySize == right.primarySize &&
404 secondarySize == right.secondarySize &&
405 array == right.array && (!array || arraySize == right.arraySize) &&
406 structure == right.structure;
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000407 // don't check the qualifier, it's not ever what's being sought after
408 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700409 bool operator!=(const TType &right) const
410 {
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000411 return !operator==(right);
412 }
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700413 bool operator<(const TType &right) const
414 {
415 if (type != right.type)
416 return type < right.type;
417 if (primarySize != right.primarySize)
418 return primarySize < right.primarySize;
419 if (secondarySize != right.secondarySize)
420 return secondarySize < right.secondarySize;
421 if (array != right.array)
422 return array < right.array;
423 if (arraySize != right.arraySize)
424 return arraySize < right.arraySize;
425 if (structure != right.structure)
426 return structure < right.structure;
daniel@transgaming.comc6977ce2010-05-14 17:30:42 +0000427
428 return false;
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000429 }
alokp@chromium.org58e54292010-08-24 21:40:03 +0000430
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700431 const char *getBasicString() const
432 {
433 return ::getBasicString(type);
434 }
435 const char *getPrecisionString() const
436 {
437 return ::getPrecisionString(precision);
438 }
439 const char *getQualifierString() const
440 {
441 return ::getQualifierString(qualifier);
442 }
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000443 TString getCompleteString() const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000444
kbr@chromium.org476541f2011-10-27 21:14:51 +0000445 // If this type is a struct, returns the deepest struct nesting of
446 // any field in the struct. For example:
447 // struct nesting1 {
448 // vec4 position;
449 // };
450 // struct nesting2 {
451 // nesting1 field1;
452 // vec4 field2;
453 // };
454 // For type "nesting2", this method would return 2 -- the number
455 // of structures through which indirection must occur to reach the
456 // deepest field (nesting2.field1.position).
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700457 int getDeepestStructNesting() const
458 {
Jamie Madill98493dd2013-07-08 14:39:03 -0400459 return structure ? structure->deepestNesting() : 0;
460 }
kbr@chromium.org476541f2011-10-27 21:14:51 +0000461
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700462 bool isStructureContainingArrays() const
463 {
Jamie Madill98493dd2013-07-08 14:39:03 -0400464 return structure ? structure->containsArrays() : false;
465 }
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000466
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700467 protected:
Jamie Madill98493dd2013-07-08 14:39:03 -0400468 TString buildMangledName() const;
Jamie Madill94bf7f22013-07-08 13:31:15 -0400469 size_t getStructSize() const;
kbr@chromium.org476541f2011-10-27 21:14:51 +0000470 void computeDeepestStructNesting();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000471
Nicolas Capensef2c2b82013-09-26 10:06:07 -0400472 TBasicType type;
473 TPrecision precision;
474 TQualifier qualifier;
Jamie Madilla5efff92013-06-06 11:56:47 -0400475 TLayoutQualifier layoutQualifier;
Nicolas Capensef2c2b82013-09-26 10:06:07 -0400476 unsigned char primarySize; // size of vector or cols matrix
477 unsigned char secondarySize; // rows of a matrix
478 bool array;
daniel@transgaming.com0578f812010-05-17 09:58:39 +0000479 int arraySize;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000480
Jamie Madill98493dd2013-07-08 14:39:03 -0400481 // 0 unless this is an interface block, or interface block member variable
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700482 TInterfaceBlock *interfaceBlock;
alokp@chromium.org58e54292010-08-24 21:40:03 +0000483
Jamie Madill98493dd2013-07-08 14:39:03 -0400484 // 0 unless this is a struct
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700485 TStructure *structure;
Jamie Madill98493dd2013-07-08 14:39:03 -0400486
487 mutable TString mangled;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000488};
489
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000490//
491// This is a workaround for a problem with the yacc stack, It can't have
492// types that it thinks have non-trivial constructors. It should
493// just be used while recognizing the grammar, not anything else. Pointers
494// could be used, but also trying to avoid lots of memory management overhead.
495//
496// Not as bad as it looks, there is no actual assumption that the fields
497// match up or are name the same or anything like that.
498//
499struct TPublicType
500{
501 TBasicType type;
Jamie Madilla5efff92013-06-06 11:56:47 -0400502 TLayoutQualifier layoutQualifier;
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000503 TQualifier qualifier;
504 TPrecision precision;
Nicolas Capensef2c2b82013-09-26 10:06:07 -0400505 unsigned char primarySize; // size of vector or cols of matrix
506 unsigned char secondarySize; // rows of matrix
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000507 bool array;
508 int arraySize;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700509 TType *userDef;
Jamie Madill075edd82013-07-08 13:30:19 -0400510 TSourceLoc line;
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000511
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700512 void setBasic(TBasicType bt, TQualifier q, const TSourceLoc &ln)
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000513 {
514 type = bt;
Jamie Madilla5efff92013-06-06 11:56:47 -0400515 layoutQualifier = TLayoutQualifier::create();
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000516 qualifier = q;
517 precision = EbpUndefined;
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000518 primarySize = 1;
519 secondarySize = 1;
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000520 array = false;
521 arraySize = 0;
522 userDef = 0;
523 line = ln;
524 }
525
Nicolas Capensef2c2b82013-09-26 10:06:07 -0400526 void setAggregate(unsigned char size)
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000527 {
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000528 primarySize = size;
529 }
530
Nicolas Capensef2c2b82013-09-26 10:06:07 -0400531 void setMatrix(unsigned char c, unsigned char r)
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000532 {
533 ASSERT(c > 1 && r > 1 && c <= 4 && r <= 4);
534 primarySize = c;
535 secondarySize = r;
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000536 }
537
538 void setArray(bool a, int s = 0)
539 {
540 array = a;
541 arraySize = s;
542 }
543
544 bool isStructureContainingArrays() const
545 {
546 if (!userDef)
547 {
548 return false;
549 }
550
551 return userDef->isStructureContainingArrays();
552 }
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000553
554 bool isMatrix() const
555 {
556 return primarySize > 1 && secondarySize > 1;
557 }
558
559 bool isVector() const
560 {
561 return primarySize > 1 && secondarySize == 1;
562 }
563
Shannon Woods3841b8e2013-09-10 18:23:12 -0400564 int getCols() const
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000565 {
566 ASSERT(isMatrix());
567 return primarySize;
568 }
569
Shannon Woods3841b8e2013-09-10 18:23:12 -0400570 int getRows() const
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000571 {
572 ASSERT(isMatrix());
573 return secondarySize;
574 }
575
Shannon Woods3841b8e2013-09-10 18:23:12 -0400576 int getNominalSize() const
shannonwoods@chromium.org09e09882013-05-30 00:18:25 +0000577 {
578 return primarySize;
579 }
580
581 bool isAggregate() const
582 {
583 return array || isMatrix() || isVector();
584 }
daniel@transgaming.com8abd0b72012-09-27 17:46:07 +0000585};
586
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000587#endif // _TYPES_INCLUDED_