Commit b3548358 by John Kessenich

Array of Array prep: Turn a batch of 0's into nullptr or UnsizedArraySize.

Added some const as well. This will remove camouflage of the next commit, which will add the bulk of Array of Array semantics and functionality. (Note the basic grammar and data structure is already in place.)
parent 6726cccc
...@@ -419,13 +419,13 @@ class TConstUnionArray { ...@@ -419,13 +419,13 @@ class TConstUnionArray {
public: public:
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator()) POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TConstUnionArray() : unionArray(0) { } TConstUnionArray() : unionArray(nullptr) { }
virtual ~TConstUnionArray() { } virtual ~TConstUnionArray() { }
explicit TConstUnionArray(int size) explicit TConstUnionArray(int size)
{ {
if (size == 0) if (size == 0)
unionArray = 0; unionArray = nullptr;
else else
unionArray = new TConstUnionVector(size); unionArray = new TConstUnionVector(size);
} }
...@@ -473,7 +473,7 @@ public: ...@@ -473,7 +473,7 @@ public:
return sum; return sum;
} }
bool empty() const { return unionArray == 0; } bool empty() const { return unionArray == nullptr; }
protected: protected:
typedef TVector<TConstUnion> TConstUnionVector; typedef TVector<TConstUnion> TConstUnionVector;
......
...@@ -804,8 +804,8 @@ public: ...@@ -804,8 +804,8 @@ public:
vectorSize = 1; vectorSize = 1;
matrixRows = 0; matrixRows = 0;
matrixCols = 0; matrixCols = 0;
arraySizes = 0; arraySizes = nullptr;
userDef = 0; userDef = nullptr;
loc = l; loc = l;
} }
...@@ -840,7 +840,7 @@ public: ...@@ -840,7 +840,7 @@ public:
bool isScalar() const bool isScalar() const
{ {
return matrixCols == 0 && vectorSize == 1 && arraySizes == 0 && userDef == 0; return matrixCols == 0 && vectorSize == 1 && arraySizes == nullptr && userDef == nullptr;
} }
bool isImage() const bool isImage() const
...@@ -858,8 +858,8 @@ public: ...@@ -858,8 +858,8 @@ public:
// for "empty" type (no args) or simple scalar/vector/matrix // for "empty" type (no args) or simple scalar/vector/matrix
explicit TType(TBasicType t = EbtVoid, TStorageQualifier q = EvqTemporary, int vs = 1, int mc = 0, int mr = 0) : explicit TType(TBasicType t = EbtVoid, TStorageQualifier q = EvqTemporary, int vs = 1, int mc = 0, int mr = 0) :
basicType(t), vectorSize(vs), matrixCols(mc), matrixRows(mr), arraySizes(0), basicType(t), vectorSize(vs), matrixCols(mc), matrixRows(mr), arraySizes(nullptr),
structure(0), fieldName(0), typeName(0) structure(nullptr), fieldName(nullptr), typeName(nullptr)
{ {
sampler.clear(); sampler.clear();
qualifier.clear(); qualifier.clear();
...@@ -867,8 +867,8 @@ public: ...@@ -867,8 +867,8 @@ public:
} }
// for explicit precision qualifier // for explicit precision qualifier
TType(TBasicType t, TStorageQualifier q, TPrecisionQualifier p, int vs = 1, int mc = 0, int mr = 0) : TType(TBasicType t, TStorageQualifier q, TPrecisionQualifier p, int vs = 1, int mc = 0, int mr = 0) :
basicType(t), vectorSize(vs), matrixCols(mc), matrixRows(mr), arraySizes(0), basicType(t), vectorSize(vs), matrixCols(mc), matrixRows(mr), arraySizes(nullptr),
structure(0), fieldName(0), typeName(0) structure(nullptr), fieldName(nullptr), typeName(nullptr)
{ {
sampler.clear(); sampler.clear();
qualifier.clear(); qualifier.clear();
...@@ -879,7 +879,7 @@ public: ...@@ -879,7 +879,7 @@ public:
// for turning a TPublicType into a TType // for turning a TPublicType into a TType
explicit TType(const TPublicType& p) : explicit TType(const TPublicType& p) :
basicType(p.basicType), vectorSize(p.vectorSize), matrixCols(p.matrixCols), matrixRows(p.matrixRows), arraySizes(p.arraySizes), basicType(p.basicType), vectorSize(p.vectorSize), matrixCols(p.matrixCols), matrixRows(p.matrixRows), arraySizes(p.arraySizes),
structure(0), fieldName(0), typeName(0) structure(nullptr), fieldName(nullptr), typeName(nullptr)
{ {
if (basicType == EbtSampler) if (basicType == EbtSampler)
sampler = p.sampler; sampler = p.sampler;
...@@ -910,7 +910,7 @@ public: ...@@ -910,7 +910,7 @@ public:
// for making structures, ... // for making structures, ...
TType(TTypeList* userDef, const TString& n) : TType(TTypeList* userDef, const TString& n) :
basicType(EbtStruct), vectorSize(1), matrixCols(0), matrixRows(0), basicType(EbtStruct), vectorSize(1), matrixCols(0), matrixRows(0),
arraySizes(0), structure(userDef), fieldName(0) arraySizes(nullptr), structure(userDef), fieldName(nullptr)
{ {
sampler.clear(); sampler.clear();
qualifier.clear(); qualifier.clear();
...@@ -919,7 +919,7 @@ public: ...@@ -919,7 +919,7 @@ public:
// For interface blocks // For interface blocks
TType(TTypeList* userDef, const TString& n, const TQualifier& q) : TType(TTypeList* userDef, const TString& n, const TQualifier& q) :
basicType(EbtBlock), vectorSize(1), matrixCols(0), matrixRows(0), basicType(EbtBlock), vectorSize(1), matrixCols(0), matrixRows(0),
qualifier(q), arraySizes(0), structure(userDef), fieldName(0) qualifier(q), arraySizes(nullptr), structure(userDef), fieldName(nullptr)
{ {
sampler.clear(); sampler.clear();
typeName = NewPoolTString(n.c_str()); typeName = NewPoolTString(n.c_str());
...@@ -1000,7 +1000,7 @@ public: ...@@ -1000,7 +1000,7 @@ public:
virtual void dereference(bool rowMajor = false) virtual void dereference(bool rowMajor = false)
{ {
if (arraySizes) if (arraySizes)
arraySizes = 0; arraySizes = nullptr;
else if (matrixCols > 0) { else if (matrixCols > 0) {
if (rowMajor) if (rowMajor)
vectorSize = matrixCols; vectorSize = matrixCols;
...@@ -1039,17 +1039,17 @@ public: ...@@ -1039,17 +1039,17 @@ public:
virtual int getMatrixCols() const { return matrixCols; } virtual int getMatrixCols() const { return matrixCols; }
virtual int getMatrixRows() const { return matrixRows; } virtual int getMatrixRows() const { return matrixRows; }
virtual int getArraySize() const { return arraySizes->getOuterSize(); } virtual int getArraySize() const { return arraySizes->getOuterSize(); }
virtual bool isArrayOfArrays() const { return arraySizes && arraySizes->getNumDims() > 1; } virtual bool isArrayOfArrays() const { return arraySizes != nullptr && arraySizes->getNumDims() > 1; }
virtual int getImplicitArraySize() const { return arraySizes->getImplicitSize(); } virtual int getImplicitArraySize() const { return arraySizes->getImplicitSize(); }
virtual bool isScalar() const { return vectorSize == 1 && ! isStruct() && ! isArray(); } virtual bool isScalar() const { return vectorSize == 1 && ! isStruct() && ! isArray(); }
virtual bool isVector() const { return vectorSize > 1; } virtual bool isVector() const { return vectorSize > 1; }
virtual bool isMatrix() const { return matrixCols ? true : false; } virtual bool isMatrix() const { return matrixCols ? true : false; }
virtual bool isArray() const { return arraySizes != 0; } virtual bool isArray() const { return arraySizes != nullptr; }
virtual bool isImplicitlySizedArray() const { return isArray() && ! getArraySize() && qualifier.storage != EvqBuffer; } virtual bool isExplicitlySizedArray() const { return isArray() && getArraySize() != UnsizedArraySize; }
virtual bool isExplicitlySizedArray() const { return isArray() && getArraySize(); } virtual bool isImplicitlySizedArray() const { return isArray() && getArraySize() == UnsizedArraySize && qualifier.storage != EvqBuffer; }
virtual bool isRuntimeSizedArray() const { return isArray() && ! getArraySize() && qualifier.storage == EvqBuffer; } virtual bool isRuntimeSizedArray() const { return isArray() && getArraySize() == UnsizedArraySize && qualifier.storage == EvqBuffer; }
virtual bool isStruct() const { return structure != 0; } virtual bool isStruct() const { return structure != nullptr; }
virtual bool isImage() const { return basicType == EbtSampler && getSampler().image; } virtual bool isImage() const { return basicType == EbtSampler && getSampler().image; }
// Recursively checks if the type contains the given basic type // Recursively checks if the type contains the given basic type
...@@ -1071,7 +1071,7 @@ public: ...@@ -1071,7 +1071,7 @@ public:
{ {
if (isArray()) if (isArray())
return true; return true;
if (! structure) if (structure == nullptr)
return false; return false;
for (unsigned int i = 0; i < structure->size(); ++i) { for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsArray()) if ((*structure)[i].type->containsArray())
...@@ -1083,7 +1083,7 @@ public: ...@@ -1083,7 +1083,7 @@ public:
// Check the structure for any structures, needed for some error checks // Check the structure for any structures, needed for some error checks
virtual bool containsStructure() const virtual bool containsStructure() const
{ {
if (! structure) if (structure == nullptr)
return false; return false;
for (unsigned int i = 0; i < structure->size(); ++i) { for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->structure) if ((*structure)[i].type->structure)
...@@ -1097,7 +1097,7 @@ public: ...@@ -1097,7 +1097,7 @@ public:
{ {
if (isImplicitlySizedArray()) if (isImplicitlySizedArray())
return true; return true;
if (! structure) if (structure == nullptr)
return false; return false;
for (unsigned int i = 0; i < structure->size(); ++i) { for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsImplicitlySizedArray()) if ((*structure)[i].type->containsImplicitlySizedArray())
...@@ -1242,11 +1242,10 @@ public: ...@@ -1242,11 +1242,10 @@ public:
p += snprintf(p, end - p, "writeonly "); p += snprintf(p, end - p, "writeonly ");
p += snprintf(p, end - p, "%s ", getStorageQualifierString()); p += snprintf(p, end - p, "%s ", getStorageQualifierString());
if (arraySizes) { if (arraySizes) {
if (arraySizes->getOuterSize() == 0) { if (arraySizes->getOuterSize() == UnsizedArraySize) {
p += snprintf(p, end - p, "implicitly-sized array of "); p += snprintf(p, end - p, "implicitly-sized array of ");
} else { } else {
for(int i = 0; i < (int)arraySizes->getNumDims() ; ++i) { for(int i = 0; i < (int)arraySizes->getNumDims() ; ++i) {
// p += snprintf(p, end - p, "%s%d", (i == 0 ? "" : "x"), arraySizes->sizes[numDimensions-1-i]);
p += snprintf(p, end - p, "%d-element array of ", (*arraySizes)[i]); p += snprintf(p, end - p, "%d-element array of ", (*arraySizes)[i]);
} }
} }
...@@ -1337,12 +1336,12 @@ public: ...@@ -1337,12 +1336,12 @@ public:
// //
bool sameStructType(const TType& right) const bool sameStructType(const TType& right) const
{ {
// Most commonly, they are both 0, or the same pointer to the same actual structure // Most commonly, they are both nullptr, or the same pointer to the same actual structure
if (structure == right.structure) if (structure == right.structure)
return true; return true;
// Both being 0 was caught above, now they both have to be structures of the same number of elements // Both being nullptr was caught above, now they both have to be structures of the same number of elements
if (structure == 0 || right.structure == 0 || if (structure == nullptr || right.structure == nullptr ||
structure->size() != right.structure->size()) structure->size() != right.structure->size())
return false; return false;
...@@ -1371,7 +1370,7 @@ public: ...@@ -1371,7 +1370,7 @@ public:
// See if two type's arrayness match // See if two type's arrayness match
bool sameArrayness(const TType& right) const bool sameArrayness(const TType& right) const
{ {
return ((arraySizes == 0 && right.arraySizes == 0) || return ((arraySizes == nullptr && right.arraySizes == nullptr) ||
(arraySizes && right.arraySizes && *arraySizes == *right.arraySizes)); (arraySizes && right.arraySizes && *arraySizes == *right.arraySizes));
} }
...@@ -1410,8 +1409,8 @@ protected: ...@@ -1410,8 +1409,8 @@ protected:
TSampler sampler; TSampler sampler;
TQualifier qualifier; TQualifier qualifier;
TArraySizes* arraySizes; // 0 unless an array; can be shared across types TArraySizes* arraySizes; // nullptr unless an array; can be shared across types
TTypeList* structure; // 0 unless this is a struct; can be shared across types TTypeList* structure; // nullptr unless this is a struct; can be shared across types
TString *fieldName; // for structure field names TString *fieldName; // for structure field names
TString *typeName; // for structure type name TString *typeName; // for structure type name
}; };
......
...@@ -43,6 +43,10 @@ ...@@ -43,6 +43,10 @@
namespace glslang { namespace glslang {
// This is used to mean there is no size yet, it is waiting to get a size from somewhere else.
// Historically, this is not fully encapsulated, trying to catch them all...
const int UnsizedArraySize = 0;
// //
// TSmallArrayVector is used as the container for the set of sizes in TArraySizes. // TSmallArrayVector is used as the container for the set of sizes in TArraySizes.
// It has generic-container semantics, while TArraySizes has array-of-array semantics. // It has generic-container semantics, while TArraySizes has array-of-array semantics.
...@@ -56,7 +60,7 @@ struct TSmallArrayVector { ...@@ -56,7 +60,7 @@ struct TSmallArrayVector {
// //
POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator()) POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
TSmallArrayVector() : sizes(0) { } TSmallArrayVector() : sizes(nullptr) { }
virtual ~TSmallArrayVector() { dealloc(); } virtual ~TSmallArrayVector() { dealloc(); }
// For breaking into two non-shared copies, independently modifiable. // For breaking into two non-shared copies, independently modifiable.
...@@ -72,14 +76,14 @@ struct TSmallArrayVector { ...@@ -72,14 +76,14 @@ struct TSmallArrayVector {
return *this; return *this;
} }
int size() int size() const
{ {
if (sizes == nullptr) if (sizes == nullptr)
return 0; return 0;
return (int)sizes->size(); return (int)sizes->size();
} }
unsigned int front() unsigned int front() const
{ {
assert(sizes != nullptr && sizes->size() > 0); assert(sizes != nullptr && sizes->size() > 0);
return sizes->front(); return sizes->front();
...@@ -97,13 +101,13 @@ struct TSmallArrayVector { ...@@ -97,13 +101,13 @@ struct TSmallArrayVector {
sizes->push_back(e); sizes->push_back(e);
} }
unsigned int operator[](int i) unsigned int operator[](int i) const
{ {
assert(sizes && (int)sizes->size() > i); assert(sizes && (int)sizes->size() > i);
return (*sizes)[i]; return (*sizes)[i];
} }
bool operator==(const TSmallArrayVector& rhs) bool operator==(const TSmallArrayVector& rhs) const
{ {
if (sizes == nullptr && rhs.sizes == nullptr) if (sizes == nullptr && rhs.sizes == nullptr)
return true; return true;
...@@ -150,14 +154,14 @@ struct TArraySizes { ...@@ -150,14 +154,14 @@ struct TArraySizes {
} }
// translate from array-of-array semantics to container semantics // translate from array-of-array semantics to container semantics
int getNumDims() { return sizes.size(); } int getNumDims() const { return sizes.size(); }
int getOuterSize() { return sizes.front(); } int getOuterSize() const { return sizes.front(); }
void setOuterSize(int s) { sizes.push_back((unsigned)s); } void setOuterSize(int s) { sizes.push_back((unsigned)s); }
void changeOuterSize(int s) { sizes.changeFront((unsigned)s); } void changeOuterSize(int s) { sizes.changeFront((unsigned)s); }
int getImplicitSize() { return (int)implicitArraySize; } int getImplicitSize() const { return (int)implicitArraySize; }
void setImplicitSize(int s) { implicitArraySize = s; } void setImplicitSize(int s) { implicitArraySize = s; }
int operator[](int i) { return sizes[i]; } int operator[](int i) const { return sizes[i]; }
bool operator==(const TArraySizes& rhs) { return sizes == rhs.sizes; } bool operator==(const TArraySizes& rhs) const { return sizes == rhs.sizes; }
protected: protected:
TSmallArrayVector sizes; TSmallArrayVector sizes;
......
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits. // For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run). // For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "2.3.704" #define GLSLANG_REVISION "2.3.706"
#define GLSLANG_DATE "06-Aug-2015" #define GLSLANG_DATE "09-Aug-2015"
...@@ -295,8 +295,8 @@ namespace { ...@@ -295,8 +295,8 @@ namespace {
// A single global usable by all threads, by all versions, by all languages. // A single global usable by all threads, by all versions, by all languages.
// After a single process-level initialization, this is read only and thread safe // After a single process-level initialization, this is read only and thread safe
std::unordered_map<std::string, int>* KeywordMap = 0; std::unordered_map<std::string, int>* KeywordMap = nullptr;
std::unordered_set<std::string>* ReservedSet = 0; std::unordered_set<std::string>* ReservedSet = nullptr;
}; };
...@@ -304,7 +304,7 @@ namespace glslang { ...@@ -304,7 +304,7 @@ namespace glslang {
void TScanContext::fillInKeywordMap() void TScanContext::fillInKeywordMap()
{ {
if (KeywordMap != 0) { if (KeywordMap != nullptr) {
// this is really an error, as this should called only once per process // this is really an error, as this should called only once per process
// but, the only risk is if two threads called simultaneously // but, the only risk is if two threads called simultaneously
return; return;
...@@ -522,9 +522,9 @@ void TScanContext::fillInKeywordMap() ...@@ -522,9 +522,9 @@ void TScanContext::fillInKeywordMap()
void TScanContext::deleteKeywordMap() void TScanContext::deleteKeywordMap()
{ {
delete KeywordMap; delete KeywordMap;
KeywordMap = 0; KeywordMap = nullptr;
delete ReservedSet; delete ReservedSet;
ReservedSet = 0; ReservedSet = nullptr;
} }
int TScanContext::tokenize(TPpContext* pp, TParserToken& token) int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
...@@ -533,7 +533,7 @@ int TScanContext::tokenize(TPpContext* pp, TParserToken& token) ...@@ -533,7 +533,7 @@ int TScanContext::tokenize(TPpContext* pp, TParserToken& token)
parserToken = &token; parserToken = &token;
TPpToken ppToken; TPpToken ppToken;
tokenText = pp->tokenize(&ppToken); tokenText = pp->tokenize(&ppToken);
if (tokenText == 0) if (tokenText == nullptr)
return 0; return 0;
loc = ppToken.loc; loc = ppToken.loc;
......
...@@ -133,7 +133,7 @@ void TParseContext::inductiveLoopBodyCheck(TIntermNode* body, int loopId, TSymbo ...@@ -133,7 +133,7 @@ void TParseContext::inductiveLoopBodyCheck(TIntermNode* body, int loopId, TSymbo
{ {
TInductiveTraverser it(loopId, symbolTable); TInductiveTraverser it(loopId, symbolTable);
if (! body) if (body == nullptr)
return; return;
body->traverse(&it); body->traverse(&it);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment