Merge pull request #814 from steve-lunarg/contains

Refactor TType::contains* methods (nonfunctional)
This commit is contained in:
John Kessenich 2017-04-03 10:07:47 -06:00 committed by GitHub
commit fa84001ad7

View File

@ -43,6 +43,8 @@
#include "../Public/ShaderLang.h" #include "../Public/ShaderLang.h"
#include "arrays.h" #include "arrays.h"
#include <algorithm>
namespace glslang { namespace glslang {
const int GlslangMaxTypeLength = 200; // TODO: need to print block/struct one member per line, so this can stay bounded const int GlslangMaxTypeLength = 200; // TODO: need to print block/struct one member per line, so this can stay bounded
@ -1382,92 +1384,57 @@ public:
return !isPerVertexAndBuiltIn(language); return !isPerVertexAndBuiltIn(language);
} }
// return true if this type contains any subtype which satisfies the given predicate.
template <typename P>
bool contains(P predicate) const
{
if (predicate(this))
return true;
const auto hasa = [predicate](const TTypeLoc& tl) { return tl.type->contains(predicate); };
return structure && std::any_of(structure->begin(), structure->end(), hasa);
}
// Recursively checks if the type contains the given basic type // Recursively checks if the type contains the given basic type
virtual bool containsBasicType(TBasicType checkType) const virtual bool containsBasicType(TBasicType checkType) const
{ {
if (basicType == checkType) return contains([checkType](const TType* t) { return t->basicType == checkType; } );
return true;
if (! structure)
return false;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsBasicType(checkType))
return true;
}
return false;
} }
// Recursively check the structure for any arrays, needed for some error checks // Recursively check the structure for any arrays, needed for some error checks
virtual bool containsArray() const virtual bool containsArray() const
{ {
if (isArray()) return contains([](const TType* t) { return t->isArray(); } );
return true;
if (structure == nullptr)
return false;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsArray())
return true;
}
return false;
} }
// 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 == nullptr) return contains([this](const TType* t) { return t != this && t->isStruct(); } );
return false;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->structure)
return true;
}
return false;
} }
// Recursively check the structure for any implicitly-sized arrays, needed for triggering a copyUp(). // Recursively check the structure for any implicitly-sized arrays, needed for triggering a copyUp().
virtual bool containsImplicitlySizedArray() const virtual bool containsImplicitlySizedArray() const
{ {
if (isImplicitlySizedArray()) return contains([](const TType* t) { return t->isImplicitlySizedArray(); } );
return true;
if (structure == nullptr)
return false;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsImplicitlySizedArray())
return true;
}
return false;
} }
virtual bool containsOpaque() const virtual bool containsOpaque() const
{ {
if (isOpaque()) return contains([](const TType* t) { return t->isOpaque(); } );
return true;
if (! structure)
return false;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsOpaque())
return true;
}
return false;
} }
// Recursively checks if the type contains an interstage IO builtin // Recursively checks if the type contains an interstage IO builtin
virtual bool containsBuiltInInterstageIO(EShLanguage language) const virtual bool containsBuiltInInterstageIO(EShLanguage language) const
{ {
if (isBuiltInInterstageIO(language)) return contains([language](const TType* t) { return t->isBuiltInInterstageIO(language); } );
return true;
if (! structure)
return false;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsBuiltInInterstageIO(language))
return true;
}
return false;
} }
virtual bool containsNonOpaque() const virtual bool containsNonOpaque() const
{ {
// list all non-opaque types const auto nonOpaque = [](const TType* t) {
switch (basicType) { switch (t->basicType) {
case EbtVoid: case EbtVoid:
case EbtFloat: case EbtFloat:
case EbtDouble: case EbtDouble:
@ -1481,28 +1448,16 @@ public:
case EbtBool: case EbtBool:
return true; return true;
default: default:
break;
}
if (! structure)
return false; return false;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsNonOpaque())
return true;
} }
return false; };
return contains(nonOpaque);
} }
virtual bool containsSpecializationSize() const virtual bool containsSpecializationSize() const
{ {
if (isArray() && arraySizes->containsNode()) return contains([](const TType* t) { return t->isArray() && t->arraySizes->containsNode(); } );
return true;
if (! structure)
return false;
for (unsigned int i = 0; i < structure->size(); ++i) {
if ((*structure)[i].type->containsSpecializationSize())
return true;
}
return false;
} }
// Array editing methods. Array descriptors can be shared across // Array editing methods. Array descriptors can be shared across