summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/compiler/Types.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/compiler/Types.h')
-rw-r--r--src/3rdparty/angle/src/compiler/Types.h240
1 files changed, 96 insertions, 144 deletions
diff --git a/src/3rdparty/angle/src/compiler/Types.h b/src/3rdparty/angle/src/compiler/Types.h
index 854bb44c07..505fa8e3bf 100644
--- a/src/3rdparty/angle/src/compiler/Types.h
+++ b/src/3rdparty/angle/src/compiler/Types.h
@@ -7,30 +7,85 @@
#ifndef _TYPES_INCLUDED
#define _TYPES_INCLUDED
+#include "common/angleutils.h"
+
#include "compiler/BaseTypes.h"
#include "compiler/Common.h"
#include "compiler/debug.h"
-class TType;
struct TPublicType;
+class TType;
-//
-// Need to have association of line numbers to types in a list for building structs.
-//
-struct TTypeLine {
- TType* type;
- int line;
+class TField
+{
+public:
+ POOL_ALLOCATOR_NEW_DELETE();
+ TField(TType* type, TString* name) : mType(type), mName(name) {}
+
+ // TODO(alokp): We should only return const type.
+ // Fix it by tweaking grammar.
+ TType* type() { return mType; }
+ const TType* type() const { return mType; }
+
+ const TString& name() const { return *mName; }
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(TField);
+ TType* mType;
+ TString* mName;
};
-typedef TVector<TTypeLine> TTypeList;
-inline TTypeList* NewPoolTTypeList()
+typedef TVector<TField*> TFieldList;
+inline TFieldList* NewPoolTFieldList()
{
- void* memory = GlobalPoolAllocator.allocate(sizeof(TTypeList));
- return new(memory) TTypeList;
+ void* memory = GetGlobalPoolAllocator()->allocate(sizeof(TFieldList));
+ return new(memory) TFieldList;
}
-typedef TMap<TTypeList*, TTypeList*> TStructureMap;
-typedef TMap<TTypeList*, TTypeList*>::iterator TStructureMapIterator;
+class TStructure
+{
+public:
+ POOL_ALLOCATOR_NEW_DELETE();
+ TStructure(TString* name, TFieldList* fields)
+ : mName(name),
+ mFields(fields),
+ mObjectSize(0),
+ mDeepestNesting(0) {
+ }
+
+ const TString& name() const { return *mName; }
+ const TFieldList& fields() const { return *mFields; }
+
+ const TString& mangledName() const {
+ if (mMangledName.empty())
+ mMangledName = buildMangledName();
+ return mMangledName;
+ }
+ size_t objectSize() const {
+ if (mObjectSize == 0)
+ mObjectSize = calculateObjectSize();
+ return mObjectSize;
+ };
+ int deepestNesting() const {
+ if (mDeepestNesting == 0)
+ mDeepestNesting = calculateDeepestNesting();
+ return mDeepestNesting;
+ }
+ bool containsArrays() const;
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(TStructure);
+ TString buildMangledName() const;
+ size_t calculateObjectSize() const;
+ int calculateDeepestNesting() const;
+
+ TString* mName;
+ TFieldList* mFields;
+
+ mutable TString mMangledName;
+ mutable size_t mObjectSize;
+ mutable int mDeepestNesting;
+};
//
// Base class for things that have a type.
@@ -38,72 +93,16 @@ typedef TMap<TTypeList*, TTypeList*>::iterator TStructureMapIterator;
class TType
{
public:
- POOL_ALLOCATOR_NEW_DELETE(GlobalPoolAllocator)
+ POOL_ALLOCATOR_NEW_DELETE();
TType() {}
TType(TBasicType t, TPrecision p, TQualifier q = EvqTemporary, int s = 1, bool m = false, bool a = false) :
- type(t), precision(p), qualifier(q), size(s), matrix(m), array(a), arraySize(0),
- maxArraySize(0), arrayInformationType(0), structure(0), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0), typeName(0)
+ type(t), precision(p), qualifier(q), size(s), matrix(m), array(a), arraySize(0), structure(0)
{
}
explicit TType(const TPublicType &p);
- TType(TTypeList* userDef, const TString& n, TPrecision p = EbpUndefined) :
- type(EbtStruct), precision(p), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0),
- maxArraySize(0), arrayInformationType(0), structure(userDef), structureSize(0), deepestStructNesting(0), fieldName(0), mangled(0)
- {
- typeName = NewPoolTString(n.c_str());
- }
-
- void copyType(const TType& copyOf, TStructureMap& remapper)
+ TType(TStructure* userDef, TPrecision p = EbpUndefined) :
+ type(EbtStruct), precision(p), qualifier(EvqTemporary), size(1), matrix(false), array(false), arraySize(0), structure(userDef)
{
- type = copyOf.type;
- precision = copyOf.precision;
- qualifier = copyOf.qualifier;
- size = copyOf.size;
- matrix = copyOf.matrix;
- array = copyOf.array;
- arraySize = copyOf.arraySize;
-
- TStructureMapIterator iter;
- if (copyOf.structure) {
- if ((iter = remapper.find(structure)) == remapper.end()) {
- // create the new structure here
- structure = NewPoolTTypeList();
- for (unsigned int i = 0; i < copyOf.structure->size(); ++i) {
- TTypeLine typeLine;
- typeLine.line = (*copyOf.structure)[i].line;
- typeLine.type = (*copyOf.structure)[i].type->clone(remapper);
- structure->push_back(typeLine);
- }
- } else {
- structure = iter->second;
- }
- } else
- structure = 0;
-
- fieldName = 0;
- if (copyOf.fieldName)
- fieldName = NewPoolTString(copyOf.fieldName->c_str());
- typeName = 0;
- if (copyOf.typeName)
- typeName = NewPoolTString(copyOf.typeName->c_str());
-
- mangled = 0;
- if (copyOf.mangled)
- mangled = NewPoolTString(copyOf.mangled->c_str());
-
- structureSize = copyOf.structureSize;
- maxArraySize = copyOf.maxArraySize;
- deepestStructNesting = copyOf.deepestStructNesting;
- assert(copyOf.arrayInformationType == 0);
- arrayInformationType = 0; // arrayInformationType should not be set for builtIn symbol table level
- }
-
- TType* clone(TStructureMap& remapper)
- {
- TType *newType = new TType();
- newType->copyType(*this, remapper);
-
- return newType;
}
TBasicType getBasicType() const { return type; }
@@ -119,34 +118,18 @@ public:
int getNominalSize() const { return size; }
void setNominalSize(int s) { size = s; }
// Full size of single instance of type
- int getObjectSize() const
- {
- int totalSize;
-
- if (getBasicType() == EbtStruct)
- totalSize = getStructSize();
- else if (matrix)
- totalSize = size * size;
- else
- totalSize = size;
-
- if (isArray())
- totalSize *= std::max(getArraySize(), getMaxArraySize());
-
- return totalSize;
- }
+ size_t getObjectSize() const;
int elementRegisterCount() const
{
- TTypeList *structure = getStruct();
-
if (structure)
{
+ const TFieldList &fields = getStruct()->fields();
int registerCount = 0;
- for (size_t i = 0; i < structure->size(); i++)
+ for (size_t i = 0; i < fields.size(); i++)
{
- registerCount += (*structure)[i].type->totalRegisterCount();
+ registerCount += fields[i]->type()->totalRegisterCount();
}
return registerCount;
@@ -179,47 +162,20 @@ public:
bool isArray() const { return array ? true : false; }
int getArraySize() const { return arraySize; }
void setArraySize(int s) { array = true; arraySize = s; }
- int getMaxArraySize () const { return maxArraySize; }
- void setMaxArraySize (int s) { maxArraySize = s; }
- void clearArrayness() { array = false; arraySize = 0; maxArraySize = 0; }
- void setArrayInformationType(TType* t) { arrayInformationType = t; }
- TType* getArrayInformationType() const { return arrayInformationType; }
+ void clearArrayness() { array = false; arraySize = 0; }
bool isVector() const { return size > 1 && !matrix; }
bool isScalar() const { return size == 1 && !matrix && !structure; }
- TTypeList* getStruct() const { return structure; }
- void setStruct(TTypeList* s) { structure = s; computeDeepestStructNesting(); }
-
- const TString& getTypeName() const
- {
- assert(typeName);
- return *typeName;
- }
- void setTypeName(const TString& n)
- {
- typeName = NewPoolTString(n.c_str());
- }
-
- bool isField() const { return fieldName != 0; }
- const TString& getFieldName() const
- {
- assert(fieldName);
- return *fieldName;
- }
- void setFieldName(const TString& n)
- {
- fieldName = NewPoolTString(n.c_str());
- }
+ TStructure* getStruct() const { return structure; }
+ void setStruct(TStructure* s) { structure = s; }
- TString& getMangledName() {
- if (!mangled) {
- mangled = NewPoolTString("");
- buildMangledName(*mangled);
- *mangled += ';' ;
+ const TString& getMangledName() const {
+ if (mangled.empty()) {
+ mangled = buildMangledName();
+ mangled += ';';
}
-
- return *mangled;
+ return mangled;
}
bool sameElementType(const TType& right) const {
@@ -267,14 +223,16 @@ public:
// For type "nesting2", this method would return 2 -- the number
// of structures through which indirection must occur to reach the
// deepest field (nesting2.field1.position).
- int getDeepestStructNesting() const { return deepestStructNesting; }
+ int getDeepestStructNesting() const {
+ return structure ? structure->deepestNesting() : 0;
+ }
- bool isStructureContainingArrays() const;
+ bool isStructureContainingArrays() const {
+ return structure ? structure->containsArrays() : false;
+ }
-protected:
- void buildMangledName(TString&);
- int getStructSize() const;
- void computeDeepestStructNesting();
+private:
+ TString buildMangledName() const;
TBasicType type : 6;
TPrecision precision;
@@ -283,16 +241,10 @@ protected:
unsigned int matrix : 1;
unsigned int array : 1;
int arraySize;
- int maxArraySize;
- TType* arrayInformationType;
- TTypeList* structure; // 0 unless this is a struct
- mutable int structureSize;
- int deepestStructNesting;
+ TStructure* structure; // 0 unless this is a struct
- TString *fieldName; // for structure field names
- TString *mangled;
- TString *typeName; // for structure field type name
+ mutable TString mangled;
};
//
@@ -314,9 +266,9 @@ struct TPublicType
bool array;
int arraySize;
TType* userDef;
- int line;
+ TSourceLoc line;
- void setBasic(TBasicType bt, TQualifier q, int ln = 0)
+ void setBasic(TBasicType bt, TQualifier q, const TSourceLoc& ln)
{
type = bt;
qualifier = q;