Resolve issue #700: allow initializers on struct members.

This commit is contained in:
John Kessenich 2017-02-02 15:16:20 -07:00
parent 32fd5d26e3
commit 18adbdbbb8
4 changed files with 35 additions and 2 deletions

View File

@ -1,4 +1,7 @@
hlsl.init.frag hlsl.init.frag
WARNING: 0:40: 'typedef' : struct-member initializers ignored
WARNING: 0:40: 'typedef' : struct-member initializers ignored
Shader version: 450 Shader version: 450
gl_FragCoord origin is upper left gl_FragCoord origin is upper left
0:? Sequence 0:? Sequence
@ -152,6 +155,7 @@ gl_FragCoord origin is upper left
0:? 'single2' (global structure{temp 2-component vector of uint v}) 0:? 'single2' (global structure{temp 2-component vector of uint v})
0:? 'single3' (global structure{temp structure{temp int f} s1}) 0:? 'single3' (global structure{temp structure{temp int f} s1})
0:? 'single4' (global structure{temp structure{temp 2-component vector of uint v} s1}) 0:? 'single4' (global structure{temp structure{temp 2-component vector of uint v} s1})
0:? 'anon@0' (layout(row_major std140 ) uniform block{layout(row_major std140 ) uniform float a, layout(row_major std140 ) uniform float b, layout(row_major std140 ) uniform float c})
Linked fragment stage: Linked fragment stage:
@ -310,10 +314,11 @@ gl_FragCoord origin is upper left
0:? 'single2' (global structure{temp 2-component vector of uint v}) 0:? 'single2' (global structure{temp 2-component vector of uint v})
0:? 'single3' (global structure{temp structure{temp int f} s1}) 0:? 'single3' (global structure{temp structure{temp int f} s1})
0:? 'single4' (global structure{temp structure{temp 2-component vector of uint v} s1}) 0:? 'single4' (global structure{temp structure{temp 2-component vector of uint v} s1})
0:? 'anon@0' (layout(row_major std140 ) uniform block{layout(row_major std140 ) uniform float a, layout(row_major std140 ) uniform float b, layout(row_major std140 ) uniform float c})
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 97 // Id's are bound by 100
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
@ -361,8 +366,18 @@ gl_FragCoord origin is upper left
Name 90 "input" Name 90 "input"
Name 95 "c4" Name 95 "c4"
Name 96 "b5" Name 96 "b5"
Name 97 "Constants"
MemberName 97(Constants) 0 "a"
MemberName 97(Constants) 1 "b"
MemberName 97(Constants) 2 "c"
Name 99 ""
Decorate 88(@entryPointOutput) Location 0 Decorate 88(@entryPointOutput) Location 0
Decorate 90(input) Location 0 Decorate 90(input) Location 0
MemberDecorate 97(Constants) 0 Offset 0
MemberDecorate 97(Constants) 1 Offset 4
MemberDecorate 97(Constants) 2 Offset 8
Decorate 97(Constants) Block
Decorate 99 DescriptorSet 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeFloat 32 6: TypeFloat 32
@ -437,6 +452,9 @@ gl_FragCoord origin is upper left
90(input): 89(ptr) Variable Input 90(input): 89(ptr) Variable Input
95(c4): 22(ptr) Variable Private 95(c4): 22(ptr) Variable Private
96(b5): 22(ptr) Variable Private 96(b5): 22(ptr) Variable Private
97(Constants): TypeStruct 6(float) 6(float) 6(float)
98: TypePointer Uniform 97(Constants)
99: 98(ptr) Variable Uniform
4(ShaderFunction): 2 Function None 3 4(ShaderFunction): 2 Function None 3
5: Label 5: Label
62(a2): 61(ptr) Variable Function 62(a2): 61(ptr) Variable Function

View File

@ -34,3 +34,8 @@ float4 ShaderFunction(float4 input) : COLOR0
return input * a1; return input * a1;
} }
cbuffer Constants
{
float a = 1.0f, b, c = 2.0f;
};

View File

@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits. // For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run). // For the date, it uses the current date (when then script is run).
#define GLSLANG_REVISION "Overload400-PrecQual.1804" #define GLSLANG_REVISION "Overload400-PrecQual.1805"
#define GLSLANG_DATE "02-Feb-2017" #define GLSLANG_DATE "02-Feb-2017"

View File

@ -1758,6 +1758,16 @@ bool HlslGrammar::acceptStructDeclarationList(TTypeList*& typeList)
acceptPostDecls(member.type->getQualifier()); acceptPostDecls(member.type->getQualifier());
// EQUAL assignment_expression
if (acceptTokenClass(EHTokAssign)) {
parseContext.warn(idToken.loc, "struct-member initializers ignored", "typedef", "");
TIntermTyped* expressionNode = nullptr;
if (! acceptAssignmentExpression(expressionNode)) {
expected("initializer");
return false;
}
}
// success on seeing the SEMICOLON coming up // success on seeing the SEMICOLON coming up
if (peekTokenClass(EHTokSemicolon)) if (peekTokenClass(EHTokSemicolon))
break; break;