Commit 859b0342 by John Kessenich

Types: Fix #1290: Rationalize and correct "mixed" style array dimensioning.

There a couple functional problems, which when reduced down also led to some good simplifications and rationalization. So, this commit: - corrects "mixed" functionality: int[A] f[B] -> f[B][A] - correct multi-identifier decls: int[A] f[B], g[C] -> f and g are independently sized. - increases symmetry between different places in the code that do this - makes fewer ways to do the same thing; several methods are just gone now - makes more clear when something is copied or shared
parent 1c3ab274
...@@ -2607,8 +2607,8 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty ...@@ -2607,8 +2607,8 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
// Use a dummy glslang type for querying internal strides of // Use a dummy glslang type for querying internal strides of
// arrays of arrays, but using just a one-dimensional array. // arrays of arrays, but using just a one-dimensional array.
glslang::TType simpleArrayType(type, 0); // deference type of the array glslang::TType simpleArrayType(type, 0); // deference type of the array
while (simpleArrayType.getArraySizes().getNumDims() > 1) while (simpleArrayType.getArraySizes()->getNumDims() > 1)
simpleArrayType.getArraySizes().dereference(); simpleArrayType.getArraySizes()->dereference();
// Will compute the higher-order strides here, rather than making a whole // Will compute the higher-order strides here, rather than making a whole
// pile of types and doing repetitive recursion on their contents. // pile of types and doing repetitive recursion on their contents.
......
...@@ -19,6 +19,7 @@ ERROR: 0:34: 'a4' : redefinition ...@@ -19,6 +19,7 @@ ERROR: 0:34: 'a4' : redefinition
ERROR: 0:35: 'arrays of arrays' : not supported with this profile: none ERROR: 0:35: 'arrays of arrays' : not supported with this profile: none
ERROR: 0:36: 'arrays of arrays' : not supported with this profile: none ERROR: 0:36: 'arrays of arrays' : not supported with this profile: none
ERROR: 0:37: 'arrays of arrays' : not supported with this profile: none ERROR: 0:37: 'arrays of arrays' : not supported with this profile: none
ERROR: 0:37: 'arrays of arrays' : not supported with this profile: none
ERROR: 0:38: 'arrays of arrays' : not supported with this profile: none ERROR: 0:38: 'arrays of arrays' : not supported with this profile: none
ERROR: 0:39: 'arrays of arrays' : not supported with this profile: none ERROR: 0:39: 'arrays of arrays' : not supported with this profile: none
ERROR: 0:40: 'arrays of arrays' : not supported with this profile: none ERROR: 0:40: 'arrays of arrays' : not supported with this profile: none
...@@ -78,7 +79,7 @@ ERROR: 0:192: 'assign' : l-value required (can't modify a const) ...@@ -78,7 +79,7 @@ ERROR: 0:192: 'assign' : l-value required (can't modify a const)
ERROR: 0:195: 'gl_ModelViewMatrix' : identifiers starting with "gl_" are reserved ERROR: 0:195: 'gl_ModelViewMatrix' : identifiers starting with "gl_" are reserved
ERROR: 0:200: 'token pasting (##)' : not supported for this version or the enabled extensions ERROR: 0:200: 'token pasting (##)' : not supported for this version or the enabled extensions
ERROR: 0:203: 'token pasting (##)' : not supported for this version or the enabled extensions ERROR: 0:203: 'token pasting (##)' : not supported for this version or the enabled extensions
ERROR: 79 compilation errors. No code generated. ERROR: 80 compilation errors. No code generated.
Shader version: 120 Shader version: 120
......
...@@ -26,6 +26,7 @@ ERROR: 0:101: 'arrays of arrays' : not supported for this version or the enabled ...@@ -26,6 +26,7 @@ ERROR: 0:101: 'arrays of arrays' : not supported for this version or the enabled
ERROR: 0:102: 'arrays of arrays' : not supported for this version or the enabled extensions ERROR: 0:102: 'arrays of arrays' : not supported for this version or the enabled extensions
ERROR: 0:102: 'arrays of arrays' : not supported for this version or the enabled extensions ERROR: 0:102: 'arrays of arrays' : not supported for this version or the enabled extensions
ERROR: 0:103: 'arrays of arrays' : not supported for this version or the enabled extensions ERROR: 0:103: 'arrays of arrays' : not supported for this version or the enabled extensions
ERROR: 0:103: 'arrays of arrays' : not supported for this version or the enabled extensions
ERROR: 0:100: 'arrays of arrays' : not supported for this version or the enabled extensions ERROR: 0:100: 'arrays of arrays' : not supported for this version or the enabled extensions
ERROR: 0:100: 'array-of-array of block' : not supported with this profile: es ERROR: 0:100: 'array-of-array of block' : not supported with this profile: es
ERROR: 0:111: 'variable indexing fragment shader output array' : not supported with this profile: es ERROR: 0:111: 'variable indexing fragment shader output array' : not supported with this profile: es
...@@ -44,7 +45,7 @@ ERROR: 0:157: 'invariant' : can only apply to an output ...@@ -44,7 +45,7 @@ ERROR: 0:157: 'invariant' : can only apply to an output
ERROR: 0:158: 'invariant' : can only apply to an output ERROR: 0:158: 'invariant' : can only apply to an output
ERROR: 0:160: 'imageBuffer' : Reserved word. ERROR: 0:160: 'imageBuffer' : Reserved word.
ERROR: 0:160: '' : syntax error, unexpected IMAGEBUFFER, expecting COMMA or SEMICOLON ERROR: 0:160: '' : syntax error, unexpected IMAGEBUFFER, expecting COMMA or SEMICOLON
ERROR: 45 compilation errors. No code generated. ERROR: 46 compilation errors. No code generated.
Shader version: 300 Shader version: 300
...@@ -392,7 +393,7 @@ ERROR: node is still EOpNull! ...@@ -392,7 +393,7 @@ ERROR: node is still EOpNull!
0:? 'sc' ( out lowp 3-component vector of float) 0:? 'sc' ( out lowp 3-component vector of float)
0:? 'sf' ( out lowp float) 0:? 'sf' ( out lowp float)
0:? 'arrayedSampler' ( uniform 5-element array of lowp sampler2D) 0:? 'arrayedSampler' ( uniform 5-element array of lowp sampler2D)
0:? 'multiInst' (layout( column_major shared) uniform 2-element array of 3-element array of block{layout( column_major shared) uniform 2-element array of mediump int a, layout( column_major shared) uniform 2-element array of 3-element array of mediump int b, layout( column_major shared) uniform 2-element array of 3-element array of mediump int c}) 0:? 'multiInst' (layout( column_major shared) uniform 2-element array of 3-element array of block{layout( column_major shared) uniform 3-element array of 2-element array of mediump int a, layout( column_major shared) uniform 2-element array of 3-element array of mediump int b, layout( column_major shared) uniform 2-element array of 3-element array of mediump int c})
0:? 'colors' ( out 4-element array of lowp 4-component vector of float) 0:? 'colors' ( out 4-element array of lowp 4-component vector of float)
0:? 'st1' ( uniform structure{ global mediump int i, global lowp sampler2D s}) 0:? 'st1' ( uniform structure{ global mediump int i, global lowp sampler2D s})
0:? 'st2' ( uniform structure{ global mediump int i, global lowp sampler2D s}) 0:? 'st2' ( uniform structure{ global mediump int i, global lowp sampler2D s})
...@@ -623,7 +624,7 @@ ERROR: node is still EOpNull! ...@@ -623,7 +624,7 @@ ERROR: node is still EOpNull!
0:? 'sc' ( out lowp 3-component vector of float) 0:? 'sc' ( out lowp 3-component vector of float)
0:? 'sf' ( out lowp float) 0:? 'sf' ( out lowp float)
0:? 'arrayedSampler' ( uniform 5-element array of lowp sampler2D) 0:? 'arrayedSampler' ( uniform 5-element array of lowp sampler2D)
0:? 'multiInst' (layout( column_major shared) uniform 2-element array of 3-element array of block{layout( column_major shared) uniform 2-element array of mediump int a, layout( column_major shared) uniform 2-element array of 3-element array of mediump int b, layout( column_major shared) uniform 2-element array of 3-element array of mediump int c}) 0:? 'multiInst' (layout( column_major shared) uniform 2-element array of 3-element array of block{layout( column_major shared) uniform 3-element array of 2-element array of mediump int a, layout( column_major shared) uniform 2-element array of 3-element array of mediump int b, layout( column_major shared) uniform 2-element array of 3-element array of mediump int c})
0:? 'colors' ( out 4-element array of lowp 4-component vector of float) 0:? 'colors' ( out 4-element array of lowp 4-component vector of float)
0:? 'st1' ( uniform structure{ global mediump int i, global lowp sampler2D s}) 0:? 'st1' ( uniform structure{ global mediump int i, global lowp sampler2D s})
0:? 'st2' ( uniform structure{ global mediump int i, global lowp sampler2D s}) 0:? 'st2' ( uniform structure{ global mediump int i, global lowp sampler2D s})
......
mixedArrayDecls.frag
ERROR: 0:30: '' : syntax error, unexpected LEFT_PAREN, expecting COMMA or SEMICOLON
ERROR: 1 compilation errors. No code generated.
Shader version: 450
ERROR: node is still EOpNull!
0:16 Function Definition: foo(i1[14][15][6]; ( global 14-element array of 15-element array of 6-element array of int)
0:16 Function Parameters:
0:16 'p' ( in 14-element array of 15-element array of 6-element array of int)
0:16 Sequence
0:16 Branch: Return with expression
0:16 'p' ( in 14-element array of 15-element array of 6-element array of int)
0:18 Function Definition: main( ( global void)
0:18 Function Parameters:
0:20 Sequence
0:20 direct index ( temp 14-element array of int)
0:20 'g' ( global unsized 4-element array of 14-element array of int)
0:20 Constant:
0:20 3 (const int)
0:21 direct index ( temp 14-element array of int)
0:21 'h' ( global unsized 3-element array of 14-element array of int)
0:21 Constant:
0:21 2 (const int)
0:24 Function Definition: bar( ( global 4-element array of 3-element array of 2-element array of float)
0:24 Function Parameters:
0:? Sequence
0:24 Branch: Return with expression
0:24 'a' ( temp 4-element array of 3-element array of 2-element array of float)
0:? Linker Objects
0:? 's' ( global structure{ global 2-element array of 3-element array of int a, global 5-element array of 3-element array of int b})
0:? 'c' ( global 4-element array of 5-element array of int)
0:? 'd' ( global 8-element array of 5-element array of int)
0:? 'e' ( global 11-element array of 9-element array of int)
0:? 'f' ( global 13-element array of 9-element array of int)
0:? 'g' ( global unsized 4-element array of 14-element array of int)
0:? 'h' ( global unsized 3-element array of 14-element array of int)
0:? 'inbinst' ( in 4-element array of 5-element array of 6-element array of block{ in 8-element array of 9-element array of 7-element array of float f})
0:? 'barm' ( global 4-element array of 3-element array of 2-element array of float)
Linked fragment stage:
Shader version: 450
ERROR: node is still EOpNull!
0:18 Function Definition: main( ( global void)
0:18 Function Parameters:
0:20 Sequence
0:20 direct index ( temp 14-element array of int)
0:20 'g' ( global 4-element array of 14-element array of int)
0:20 Constant:
0:20 3 (const int)
0:21 direct index ( temp 14-element array of int)
0:21 'h' ( global 3-element array of 14-element array of int)
0:21 Constant:
0:21 2 (const int)
0:? Linker Objects
0:? 's' ( global structure{ global 2-element array of 3-element array of int a, global 5-element array of 3-element array of int b})
0:? 'c' ( global 4-element array of 5-element array of int)
0:? 'd' ( global 8-element array of 5-element array of int)
0:? 'e' ( global 11-element array of 9-element array of int)
0:? 'f' ( global 13-element array of 9-element array of int)
0:? 'g' ( global 4-element array of 14-element array of int)
0:? 'h' ( global 3-element array of 14-element array of int)
0:? 'inbinst' ( in 4-element array of 5-element array of 6-element array of block{ in 8-element array of 9-element array of 7-element array of float f})
0:? 'barm' ( global 4-element array of 3-element array of 2-element array of float)
#version 450
struct S {
int[3] a[2], b[5];
};
S s;
int[5] c[4], d[8];
int[9] e[], f[];
int e[11][9];
int f[13][9];
int[14] g[], h[];
int [14][15][6] foo(int[6] p[14][15]) { return p; }
void main()
{
g[3];
h[2];
}
float[4][3][2] bar() { float[3][2] a[4]; return a; }
in inbname {
float[7] f[8][9];
} inbinst[4][5][6];
float[3][2] barm[4]() { float[3][2] a[4]; return a; } // ERROR
...@@ -1315,31 +1315,9 @@ public: ...@@ -1315,31 +1315,9 @@ public:
void makeVector() { vector1 = true; } void makeVector() { vector1 = true; }
// Merge type from parent, where a parentType is at the beginning of a declaration,
// establishing some characteristics for all subsequent names, while this type
// is on the individual names.
void mergeType(const TPublicType& parentType)
{
// arrayness is currently the only child aspect that has to be preserved
basicType = parentType.basicType;
vectorSize = parentType.vectorSize;
matrixCols = parentType.matrixCols;
matrixRows = parentType.matrixRows;
vector1 = false; // TPublicType is only GLSL which so far has no vec1
qualifier = parentType.qualifier;
sampler = parentType.sampler;
if (parentType.arraySizes)
newArraySizes(*parentType.arraySizes);
if (parentType.userDef) {
structure = parentType.userDef->getWritableStruct();
setTypeName(parentType.userDef->getTypeName());
}
}
virtual void hideMember() { basicType = EbtVoid; vectorSize = 1; } virtual void hideMember() { basicType = EbtVoid; vectorSize = 1; }
virtual bool hiddenMember() const { return basicType == EbtVoid; } virtual bool hiddenMember() const { return basicType == EbtVoid; }
virtual void setTypeName(const TString& n) { typeName = NewPoolTString(n.c_str()); }
virtual void setFieldName(const TString& n) { fieldName = NewPoolTString(n.c_str()); } virtual void setFieldName(const TString& n) { fieldName = NewPoolTString(n.c_str()); }
virtual const TString& getTypeName() const virtual const TString& getTypeName() const
{ {
...@@ -1369,7 +1347,7 @@ public: ...@@ -1369,7 +1347,7 @@ public:
virtual bool isArrayOfArrays() const { return arraySizes != nullptr && 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 const TArraySizes* getArraySizes() const { return arraySizes; } virtual const TArraySizes* getArraySizes() const { return arraySizes; }
virtual TArraySizes& getArraySizes() { assert(arraySizes != nullptr); return *arraySizes; } virtual TArraySizes* getArraySizes() { return arraySizes; }
virtual bool isScalar() const { return ! isVector() && ! isMatrix() && ! isStruct() && ! isArray(); } virtual bool isScalar() const { return ! isVector() && ! isMatrix() && ! isStruct() && ! isArray(); }
virtual bool isScalarOrVec1() const { return isScalar() || vector1; } virtual bool isScalarOrVec1() const { return isScalar() || vector1; }
...@@ -1503,22 +1481,33 @@ public: ...@@ -1503,22 +1481,33 @@ public:
assert(type.arraySizes != nullptr); assert(type.arraySizes != nullptr);
*arraySizes = *type.arraySizes; *arraySizes = *type.arraySizes;
} }
void newArraySizes(const TArraySizes& s) void copyArraySizes(const TArraySizes& s)
{ {
// For setting a fresh new set of array sizes, not yet worrying about sharing. // For setting a fresh new set of array sizes, not yet worrying about sharing.
arraySizes = new TArraySizes; arraySizes = new TArraySizes;
*arraySizes = s; *arraySizes = s;
} }
void transferArraySizes(TArraySizes* s)
{
// For setting an already allocated set of sizes that this type can use
// (no copy made).
arraySizes = s;
}
void clearArraySizes() void clearArraySizes()
{ {
arraySizes = 0; arraySizes = nullptr;
} }
void addArrayOuterSizes(const TArraySizes& s)
// Add inner array sizes, to any existing sizes, via copy; the
// sizes passed in can still be reused for other purposes.
void copyArrayInnerSizes(const TArraySizes* s)
{ {
if (arraySizes == nullptr) if (s != nullptr) {
newArraySizes(s); if (arraySizes == nullptr)
else copyArraySizes(*s);
arraySizes->addOuterSizes(s); else
arraySizes->addInnerSizes(*s);
}
} }
void changeOuterArraySize(int s) { arraySizes->changeOuterSize(s); } void changeOuterArraySize(int s) { arraySizes->changeOuterSize(s); }
void setImplicitArraySize(int s) { arraySizes->setImplicitSize(s); } void setImplicitArraySize(int s) { arraySizes->setImplicitSize(s); }
......
...@@ -130,10 +130,10 @@ struct TSmallArrayVector { ...@@ -130,10 +130,10 @@ struct TSmallArrayVector {
sizes->push_back(pair); sizes->push_back(pair);
} }
void push_front(const TSmallArrayVector& newDims) void push_back(const TSmallArrayVector& newDims)
{ {
alloc(); alloc();
sizes->insert(sizes->begin(), newDims.sizes->begin(), newDims.sizes->end()); sizes->insert(sizes->end(), newDims.sizes->begin(), newDims.sizes->end());
} }
void pop_front() void pop_front()
...@@ -252,6 +252,7 @@ struct TArraySizes { ...@@ -252,6 +252,7 @@ struct TArraySizes {
void addInnerSize(int s) { addInnerSize((unsigned)s, nullptr); } void addInnerSize(int s) { addInnerSize((unsigned)s, nullptr); }
void addInnerSize(int s, TIntermTyped* n) { sizes.push_back((unsigned)s, n); } void addInnerSize(int s, TIntermTyped* n) { sizes.push_back((unsigned)s, n); }
void addInnerSize(TArraySize pair) { sizes.push_back(pair.size, pair.node); } void addInnerSize(TArraySize pair) { sizes.push_back(pair.size, pair.node); }
void addInnerSizes(const TArraySizes& s) { sizes.push_back(s.sizes); }
void changeOuterSize(int s) { sizes.changeFront((unsigned)s); } void changeOuterSize(int s) { sizes.changeFront((unsigned)s); }
int getImplicitSize() const { return (int)implicitArraySize; } int getImplicitSize() const { return (int)implicitArraySize; }
void setImplicitSize(int s) { implicitArraySize = s; } void setImplicitSize(int s) { implicitArraySize = s; }
...@@ -288,7 +289,6 @@ struct TArraySizes { ...@@ -288,7 +289,6 @@ struct TArraySizes {
} }
bool isImplicit() const { return getOuterSize() == UnsizedArraySize || isInnerImplicit(); } bool isImplicit() const { return getOuterSize() == UnsizedArraySize || isInnerImplicit(); }
void addOuterSizes(const TArraySizes& s) { sizes.push_front(s.sizes); }
void dereference() { sizes.pop_front(); } void dereference() { sizes.pop_front(); }
void copyDereferenced(const TArraySizes& rhs) void copyDereferenced(const TArraySizes& rhs)
{ {
......
...@@ -7981,9 +7981,9 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion ...@@ -7981,9 +7981,9 @@ void TBuiltIns::identifyBuiltIns(int version, EProfile profile, const SpvVersion
if (version == 100 || IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && profile != EEsProfile && version < 420)) { if (version == 100 || IncludeLegacy(version, profile, spvVersion) || (! ForwardCompatibility && profile != EEsProfile && version < 420)) {
TPrecisionQualifier pq = profile == EEsProfile ? EpqMedium : EpqNone; TPrecisionQualifier pq = profile == EEsProfile ? EpqMedium : EpqNone;
TType fragData(EbtFloat, EvqFragColor, pq, 4); TType fragData(EbtFloat, EvqFragColor, pq, 4);
TArraySizes& arraySizes = *new TArraySizes; TArraySizes* arraySizes = new TArraySizes;
arraySizes.addInnerSize(resources.maxDrawBuffers); arraySizes->addInnerSize(resources.maxDrawBuffers);
fragData.newArraySizes(arraySizes); fragData.transferArraySizes(arraySizes);
symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData)); symbolTable.insert(*new TVariable(NewPoolTString("gl_FragData"), fragData));
SpecialQualifier("gl_FragData", EvqFragColor, EbvFragData, symbolTable); SpecialQualifier("gl_FragData", EvqFragColor, EbvFragData, symbolTable);
} }
......
...@@ -341,10 +341,7 @@ public: ...@@ -341,10 +341,7 @@ public:
void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&); void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
void structArrayCheck(const TSourceLoc&, const TType& structure); void structArrayCheck(const TSourceLoc&, const TType& structure);
void arraySizesCheck(const TSourceLoc&, const TQualifier&, TArraySizes*, bool initializer, bool lastMember); void arraySizesCheck(const TSourceLoc&, const TQualifier&, TArraySizes*, bool initializer, bool lastMember);
void arrayOfArrayVersionCheck(const TSourceLoc&); void arrayOfArrayVersionCheck(const TSourceLoc&, const TArraySizes*);
void arrayDimCheck(const TSourceLoc&, const TArraySizes* sizes1, const TArraySizes* sizes2);
void arrayDimCheck(const TSourceLoc&, const TType*, const TArraySizes*);
void arrayDimMerge(TType& type, const TArraySizes* sizes);
bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType); bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType);
void boolCheck(const TSourceLoc&, const TIntermTyped*); void boolCheck(const TSourceLoc&, const TIntermTyped*);
void boolCheck(const TSourceLoc&, const TPublicType&); void boolCheck(const TSourceLoc&, const TPublicType&);
......
...@@ -934,13 +934,15 @@ parameter_declarator ...@@ -934,13 +934,15 @@ parameter_declarator
parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type"); parseContext.profileRequires($1.loc, EEsProfile, 300, 0, "arrayed type");
parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes); parseContext.arraySizeRequiredCheck($1.loc, *$1.arraySizes);
} }
parseContext.arrayDimCheck($2.loc, $1.arraySizes, $3.arraySizes); TType* type = new TType($1);
type->transferArraySizes($3.arraySizes);
type->copyArrayInnerSizes($1.arraySizes);
parseContext.arrayOfArrayVersionCheck($2.loc, type->getArraySizes());
parseContext.arraySizeRequiredCheck($3.loc, *$3.arraySizes); parseContext.arraySizeRequiredCheck($3.loc, *$3.arraySizes);
parseContext.reservedErrorCheck($2.loc, *$2.string); parseContext.reservedErrorCheck($2.loc, *$2.string);
TParameter param = { $2.string, new TType($1)}; TParameter param = { $2.string, type };
parseContext.arrayDimMerge(*param.type, $3.arraySizes);
$$.loc = $2.loc; $$.loc = $2.loc;
$$.param = param; $$.param = param;
...@@ -1075,7 +1077,7 @@ fully_specified_type ...@@ -1075,7 +1077,7 @@ fully_specified_type
} }
if ($2.arraySizes && parseContext.arrayQualifierError($2.loc, $1.qualifier)) if ($2.arraySizes && parseContext.arrayQualifierError($2.loc, $1.qualifier))
$2.arraySizes = 0; $2.arraySizes = nullptr;
parseContext.checkNoShaderLayouts($2.loc, $1.shaderQualifiers); parseContext.checkNoShaderLayouts($2.loc, $1.shaderQualifiers);
$2.shaderQualifiers.merge($1.shaderQualifiers); $2.shaderQualifiers.merge($1.shaderQualifiers);
...@@ -1352,7 +1354,7 @@ type_specifier ...@@ -1352,7 +1354,7 @@ type_specifier
$$.qualifier.precision = parseContext.getDefaultPrecision($$); $$.qualifier.precision = parseContext.getDefaultPrecision($$);
} }
| type_specifier_nonarray array_specifier { | type_specifier_nonarray array_specifier {
parseContext.arrayDimCheck($2.loc, $2.arraySizes, 0); parseContext.arrayOfArrayVersionCheck($2.loc, $2.arraySizes);
$$ = $1; $$ = $1;
$$.qualifier.precision = parseContext.getDefaultPrecision($$); $$.qualifier.precision = parseContext.getDefaultPrecision($$);
$$.arraySizes = $2.arraySizes; $$.arraySizes = $2.arraySizes;
...@@ -3110,8 +3112,12 @@ struct_declaration ...@@ -3110,8 +3112,12 @@ struct_declaration
parseContext.precisionQualifierCheck($1.loc, $1.basicType, $1.qualifier); parseContext.precisionQualifierCheck($1.loc, $1.basicType, $1.qualifier);
for (unsigned int i = 0; i < $$->size(); ++i) { for (unsigned int i = 0; i < $$->size(); ++i) {
parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $1.arraySizes); TType type($1);
(*$$)[i].type->mergeType($1); type.setFieldName((*$$)[i].type->getFieldName());
type.transferArraySizes((*$$)[i].type->getArraySizes());
type.copyArrayInnerSizes($1.arraySizes);
parseContext.arrayOfArrayVersionCheck((*$$)[i].loc, type.getArraySizes());
(*$$)[i].type->shallowCopy(type);
} }
} }
| type_qualifier type_specifier struct_declarator_list SEMICOLON { | type_qualifier type_specifier struct_declarator_list SEMICOLON {
...@@ -3131,8 +3137,12 @@ struct_declaration ...@@ -3131,8 +3137,12 @@ struct_declaration
parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier); parseContext.precisionQualifierCheck($2.loc, $2.basicType, $2.qualifier);
for (unsigned int i = 0; i < $$->size(); ++i) { for (unsigned int i = 0; i < $$->size(); ++i) {
parseContext.arrayDimCheck($1.loc, (*$$)[i].type, $2.arraySizes); TType type($2);
(*$$)[i].type->mergeType($2); type.setFieldName((*$$)[i].type->getFieldName());
type.transferArraySizes((*$$)[i].type->getArraySizes());
type.copyArrayInnerSizes($2.arraySizes);
parseContext.arrayOfArrayVersionCheck((*$$)[i].loc, type.getArraySizes());
(*$$)[i].type->shallowCopy(type);
} }
} }
; ;
...@@ -3154,12 +3164,12 @@ struct_declarator ...@@ -3154,12 +3164,12 @@ struct_declarator
$$.type->setFieldName(*$1.string); $$.type->setFieldName(*$1.string);
} }
| IDENTIFIER array_specifier { | IDENTIFIER array_specifier {
parseContext.arrayDimCheck($1.loc, $2.arraySizes, 0); parseContext.arrayOfArrayVersionCheck($1.loc, $2.arraySizes);
$$.type = new TType(EbtVoid); $$.type = new TType(EbtVoid);
$$.loc = $1.loc; $$.loc = $1.loc;
$$.type->setFieldName(*$1.string); $$.type->setFieldName(*$1.string);
$$.type->newArraySizes(*$2.arraySizes); $$.type->transferArraySizes($2.arraySizes);
} }
; ;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/* A Bison parser, made by GNU Bison 3.0.4. */ /* A Bison parser, made by GNU Bison 3.0. */
/* Bison interface for Yacc-like parsers in C /* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -437,7 +437,7 @@ extern int yydebug; ...@@ -437,7 +437,7 @@ extern int yydebug;
/* Value type. */ /* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef union YYSTYPE YYSTYPE;
union YYSTYPE union YYSTYPE
{ {
#line 70 "MachineIndependent/glslang.y" /* yacc.c:1909 */ #line 70 "MachineIndependent/glslang.y" /* yacc.c:1909 */
...@@ -477,8 +477,6 @@ union YYSTYPE ...@@ -477,8 +477,6 @@ union YYSTYPE
#line 479 "MachineIndependent/glslang_tab.cpp.h" /* yacc.c:1909 */ #line 479 "MachineIndependent/glslang_tab.cpp.h" /* yacc.c:1909 */
}; };
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1 # define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_DECLARED 1
#endif #endif
......
...@@ -199,6 +199,7 @@ INSTANTIATE_TEST_CASE_P( ...@@ -199,6 +199,7 @@ INSTANTIATE_TEST_CASE_P(
"loopsArtificial.frag", "loopsArtificial.frag",
"matrix.frag", "matrix.frag",
"matrix2.frag", "matrix2.frag",
"mixedArrayDecls.frag",
"newTexture.frag", "newTexture.frag",
"Operations.frag", "Operations.frag",
"overlongLiteral.frag", "overlongLiteral.frag",
......
...@@ -436,28 +436,20 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList) ...@@ -436,28 +436,20 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList)
if (declaredType.getQualifier().storage == EvqTemporary && parseContext.symbolTable.atGlobalLevel()) if (declaredType.getQualifier().storage == EvqTemporary && parseContext.symbolTable.atGlobalLevel())
declaredType.getQualifier().storage = EvqUniform; declaredType.getQualifier().storage = EvqUniform;
// recognize array_specifier
TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes);
// We can handle multiple variables per type declaration, so // We can handle multiple variables per type declaration, so
// the number of types can expand when arrayness is different. // the number of types can expand when arrayness is different.
TType variableType; TType variableType;
variableType.shallowCopy(declaredType); variableType.shallowCopy(declaredType);
// recognize array_specifier // In the most general case, arrayness is potentially coming both from the
TArraySizes* arraySizes = nullptr; // declared type and from the variable: "int[] a[];" or just one or the other.
acceptArraySpecifier(arraySizes); // Merge it all to the variableType, so all arrayness is part of the variableType.
variableType.transferArraySizes(arraySizes);
// Fix arrayness in the variableType variableType.copyArrayInnerSizes(declaredType.getArraySizes());
if (declaredType.isImplicitlySizedArray()) {
// Because "int[] a = int[2](...), b = int[3](...)" makes two arrays a and b
// of different sizes, for this case sharing the shallow copy of arrayness
// with the parseType oversubscribes it, so get a deep copy of the arrayness.
variableType.newArraySizes(declaredType.getArraySizes());
}
if (arraySizes || variableType.isArray()) {
// In the most general case, arrayness is potentially coming both from the
// declared type and from the variable: "int[] a[];" or just one or the other.
// Merge it all to the variableType, so all arrayness is part of the variableType.
parseContext.arrayDimMerge(variableType, arraySizes);
}
// samplers accept immediate sampler state // samplers accept immediate sampler state
if (variableType.getBasicType() == EbtSampler) { if (variableType.getBasicType() == EbtSampler) {
...@@ -487,8 +479,7 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList) ...@@ -487,8 +479,7 @@ bool HlslGrammar::acceptDeclaration(TIntermNode*& nodeList)
else if (variableType.getBasicType() == EbtBlock) { else if (variableType.getBasicType() == EbtBlock) {
if (expressionNode) if (expressionNode)
parseContext.error(idToken.loc, "buffer aliasing not yet supported", "block initializer", ""); parseContext.error(idToken.loc, "buffer aliasing not yet supported", "block initializer", "");
parseContext.declareBlock(idToken.loc, variableType, fullName, parseContext.declareBlock(idToken.loc, variableType, fullName);
variableType.isArray() ? &variableType.getArraySizes() : nullptr);
parseContext.declareStructBufferCounter(idToken.loc, variableType, *fullName); parseContext.declareStructBufferCounter(idToken.loc, variableType, *fullName);
} else { } else {
if (variableType.getQualifier().storage == EvqUniform && ! variableType.containsOpaque()) { if (variableType.getQualifier().storage == EvqUniform && ! variableType.containsOpaque()) {
...@@ -1036,7 +1027,7 @@ bool HlslGrammar::acceptTessellationPatchTemplateType(TType& type) ...@@ -1036,7 +1027,7 @@ bool HlslGrammar::acceptTessellationPatchTemplateType(TType& type)
TArraySizes* arraySizes = new TArraySizes; TArraySizes* arraySizes = new TArraySizes;
arraySizes->addInnerSize(size->getAsConstantUnion()->getConstArray()[0].getIConst()); arraySizes->addInnerSize(size->getAsConstantUnion()->getConstArray()[0].getIConst());
type.newArraySizes(*arraySizes); type.transferArraySizes(arraySizes);
type.getQualifier().builtIn = patchType; type.getQualifier().builtIn = patchType;
if (! acceptTokenClass(EHTokRightAngle)) { if (! acceptTokenClass(EHTokRightAngle)) {
...@@ -2295,9 +2286,9 @@ bool HlslGrammar::acceptStructBufferType(TType& type) ...@@ -2295,9 +2286,9 @@ bool HlslGrammar::acceptStructBufferType(TType& type)
// Create an unsized array out of that type. // Create an unsized array out of that type.
// TODO: does this work if it's already an array type? // TODO: does this work if it's already an array type?
TArraySizes unsizedArray; TArraySizes* unsizedArray = new TArraySizes;
unsizedArray.addInnerSize(UnsizedArraySize); unsizedArray->addInnerSize(UnsizedArraySize);
templateType->newArraySizes(unsizedArray); templateType->transferArraySizes(unsizedArray);
templateType->getQualifier().storage = storage; templateType->getQualifier().storage = storage;
// field name is canonical for all structbuffers // field name is canonical for all structbuffers
...@@ -2395,7 +2386,7 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList, TIntermNode* ...@@ -2395,7 +2386,7 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList, TIntermNode*
TArraySizes* arraySizes = nullptr; TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes); acceptArraySpecifier(arraySizes);
if (arraySizes) if (arraySizes)
typeList->back().type->newArraySizes(*arraySizes); typeList->back().type->transferArraySizes(arraySizes);
acceptPostDecls(member.type->getQualifier()); acceptPostDecls(member.type->getQualifier());
...@@ -2583,7 +2574,7 @@ bool HlslGrammar::acceptParameterDeclaration(TFunction& function) ...@@ -2583,7 +2574,7 @@ bool HlslGrammar::acceptParameterDeclaration(TFunction& function)
return false; return false;
} }
type->newArraySizes(*arraySizes); type->transferArraySizes(arraySizes);
} }
// post_decls // post_decls
...@@ -2954,7 +2945,7 @@ bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node) ...@@ -2954,7 +2945,7 @@ bool HlslGrammar::acceptUnaryExpression(TIntermTyped*& node)
TArraySizes* arraySizes = nullptr; TArraySizes* arraySizes = nullptr;
acceptArraySpecifier(arraySizes); acceptArraySpecifier(arraySizes);
if (arraySizes != nullptr) if (arraySizes != nullptr)
castType.newArraySizes(*arraySizes); castType.transferArraySizes(arraySizes);
TSourceLoc loc = token.loc; TSourceLoc loc = token.loc;
if (acceptTokenClass(EHTokRightParen)) { if (acceptTokenClass(EHTokRightParen)) {
// We've matched "(type)" now, get the expression to cast // We've matched "(type)" now, get the expression to cast
......
...@@ -126,7 +126,6 @@ public: ...@@ -126,7 +126,6 @@ public:
void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&); void arraySizeCheck(const TSourceLoc&, TIntermTyped* expr, TArraySize&);
void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&); void arraySizeRequiredCheck(const TSourceLoc&, const TArraySizes&);
void structArrayCheck(const TSourceLoc&, const TType& structure); void structArrayCheck(const TSourceLoc&, const TType& structure);
void arrayDimMerge(TType& type, const TArraySizes* sizes);
bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType); bool voidErrorCheck(const TSourceLoc&, const TString&, TBasicType);
void globalQualifierFix(const TSourceLoc&, TQualifier&); void globalQualifierFix(const TSourceLoc&, TQualifier&);
bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType); bool structQualifierErrorCheck(const TSourceLoc&, const TPublicType& pType);
...@@ -154,7 +153,7 @@ public: ...@@ -154,7 +153,7 @@ public:
TIntermTyped* convertArray(TIntermTyped*, const TType&); TIntermTyped* convertArray(TIntermTyped*, const TType&);
TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&); TIntermTyped* constructAggregate(TIntermNode*, const TType&, int, const TSourceLoc&);
TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset); TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermTyped*, const TSourceLoc&, bool subset);
void declareBlock(const TSourceLoc&, TType&, const TString* instanceName = 0, TArraySizes* arraySizes = 0); void declareBlock(const TSourceLoc&, TType&, const TString* instanceName = 0);
void declareStructBufferCounter(const TSourceLoc& loc, const TType& bufferType, const TString& name); void declareStructBufferCounter(const TSourceLoc& loc, const TType& bufferType, const TString& name);
void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation); void fixBlockLocations(const TSourceLoc&, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation);
void fixBlockXfbOffsets(TQualifier&, TTypeList&); void fixBlockXfbOffsets(TQualifier&, TTypeList&);
......
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