MCPcopy Create free account
hub / github.com/KhronosGroup/glslang / arraySizeCheck

Method arraySizeCheck

glslang/HLSL/hlslParseHelper.cpp:6855–6886  ·  view source on GitHub ↗

Do size checking for an array type's size.

Source from the content-addressed store, hash-verified

6853// Do size checking for an array type's size.
6854//
6855void HlslParseContext::arraySizeCheck(const TSourceLoc& loc, TIntermTyped* expr, TArraySize& sizePair)
6856{
6857 bool isConst = false;
6858 sizePair.size = 1;
6859 sizePair.node = nullptr;
6860
6861 TIntermConstantUnion* constant = expr->getAsConstantUnion();
6862 if (constant) {
6863 // handle true (non-specialization) constant
6864 sizePair.size = constant->getConstArray()[0].getIConst();
6865 isConst = true;
6866 } else {
6867 // see if it's a specialization constant instead
6868 if (expr->getQualifier().isSpecConstant()) {
6869 isConst = true;
6870 sizePair.node = expr;
6871 TIntermSymbol* symbol = expr->getAsSymbolNode();
6872 if (symbol && symbol->getConstArray().size() > 0)
6873 sizePair.size = symbol->getConstArray()[0].getIConst();
6874 }
6875 }
6876
6877 if (! isConst || (expr->getBasicType() != EbtInt && expr->getBasicType() != EbtUint)) {
6878 error(loc, "array size must be a constant integer expression", "", "");
6879 return;
6880 }
6881
6882 if (sizePair.size <= 0) {
6883 error(loc, "array size must be a positive integer", "", "");
6884 return;
6885 }
6886}
6887
6888//
6889// Require array to be completely sized

Callers 1

acceptArraySpecifierMethod · 0.45

Calls 7

errorFunction · 0.85
getIConstMethod · 0.80
getAsConstantUnionMethod · 0.45
isSpecConstantMethod · 0.45
getAsSymbolNodeMethod · 0.45
sizeMethod · 0.45
getBasicTypeMethod · 0.45

Tested by

no test coverage detected