Do size checking for an array type's size.
| 6853 | // Do size checking for an array type's size. |
| 6854 | // |
| 6855 | void 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 |
no test coverage detected