Do all the semantic checking for declaring or redeclaring an array, with and without a size, and make the right changes to the symbol table.
| 5713 | // without a size, and make the right changes to the symbol table. |
| 5714 | // |
| 5715 | void TParseContext::declareArray(const TSourceLoc& loc, const TString& identifier, const TType& type, TSymbol*& symbol) |
| 5716 | { |
| 5717 | if (symbol == nullptr) { |
| 5718 | bool currentScope; |
| 5719 | symbol = symbolTable.find(identifier, nullptr, ¤tScope); |
| 5720 | |
| 5721 | if (symbol && builtInName(identifier) && ! symbolTable.atBuiltInLevel()) { |
| 5722 | // bad shader (errors already reported) trying to redeclare a built-in name as an array |
| 5723 | symbol = nullptr; |
| 5724 | return; |
| 5725 | } |
| 5726 | if (symbol == nullptr || ! currentScope) { |
| 5727 | // |
| 5728 | // Successfully process a new definition. |
| 5729 | // (Redeclarations have to take place at the same scope; otherwise they are hiding declarations) |
| 5730 | // |
| 5731 | symbol = new TVariable(&identifier, type); |
| 5732 | symbolTable.insert(*symbol); |
| 5733 | if (symbolTable.atGlobalLevel()) |
| 5734 | trackLinkage(*symbol); |
| 5735 | |
| 5736 | if (! symbolTable.atBuiltInLevel()) { |
| 5737 | if (isIoResizeArray(type)) { |
| 5738 | ioArraySymbolResizeList.push_back(symbol); |
| 5739 | checkIoArraysConsistency(loc, true); |
| 5740 | } else |
| 5741 | fixIoArraySize(loc, symbol->getWritableType()); |
| 5742 | } |
| 5743 | |
| 5744 | return; |
| 5745 | } |
| 5746 | if (symbol->getAsAnonMember()) { |
| 5747 | error(loc, "cannot redeclare a user-block member array", identifier.c_str(), ""); |
| 5748 | symbol = nullptr; |
| 5749 | return; |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | // |
| 5754 | // Process a redeclaration. |
| 5755 | // |
| 5756 | |
| 5757 | if (symbol == nullptr) { |
| 5758 | error(loc, "array variable name expected", identifier.c_str(), ""); |
| 5759 | return; |
| 5760 | } |
| 5761 | |
| 5762 | // redeclareBuiltinVariable() should have already done the copyUp() |
| 5763 | TType& existingType = symbol->getWritableType(); |
| 5764 | |
| 5765 | if (! existingType.isArray()) { |
| 5766 | error(loc, "redeclaring non-array as array", identifier.c_str(), ""); |
| 5767 | return; |
| 5768 | } |
| 5769 | |
| 5770 | if (! existingType.sameElementType(type)) { |
| 5771 | error(loc, "redeclaration of array with a different element type", identifier.c_str(), ""); |
| 5772 | return; |
nothing calls this directly
no test coverage detected