Skip to content

Commit 3933d7d

Browse files
authored
Fix scope definition in ES 100. (KhronosGroup#2379)
* Remove image2DShadow and other 3 tokens. Refine codes. Remove image2DShadow and other 3 tokens. Refine codes. * 110scope.vert has redefinition part of what's removed from 100scope.vert
1 parent f8a5602 commit 3933d7d

File tree

6 files changed

+91
-26
lines changed

6 files changed

+91
-26
lines changed

Test/100scope.vert

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
int f(int a, int b, int c)
44
{
5-
int a = b; // ERROR, redefinition
5+
int a = b;
66

77
{
88
float a = float(a) + 1.0;

Test/baseResults/100scope.vert.out

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
100scope.vert
2-
ERROR: 0:5: 'a' : redefinition
32
ERROR: 0:17: 'b' : function name is redeclaration of existing name
43
ERROR: 0:20: 'c' : redefinition
54
ERROR: 0:22: 'f' : redefinition
@@ -13,7 +12,7 @@ ERROR: 0:57: 'z' : undeclared identifier
1312
ERROR: 0:57: 'z' : redefinition
1413
ERROR: 0:73: 'degrees' : can't use function syntax on variable
1514
ERROR: 0:76: 'vertex-shader struct output' : not supported for this version or the enabled extensions
16-
ERROR: 14 compilation errors. No code generated.
15+
ERROR: 13 compilation errors. No code generated.
1716

1817

1918
Shader version: 100
@@ -23,18 +22,22 @@ ERROR: node is still EOpNull!
2322
0:3 'a' ( in highp int)
2423
0:3 'b' ( in highp int)
2524
0:3 'c' ( in highp int)
26-
0:? Sequence
25+
0:5 Sequence
26+
0:5 Sequence
27+
0:5 move second child to first child ( temp highp int)
28+
0:5 'a' ( temp highp int)
29+
0:5 'b' ( in highp int)
2730
0:8 Sequence
2831
0:8 Sequence
2932
0:8 move second child to first child ( temp highp float)
3033
0:8 'a' ( temp highp float)
3134
0:8 add ( temp highp float)
3235
0:8 Convert int to float ( temp highp float)
33-
0:8 'a' ( in highp int)
36+
0:8 'a' ( temp highp int)
3437
0:8 Constant:
3538
0:8 1.000000
3639
0:11 Branch: Return with expression
37-
0:11 'a' ( in highp int)
40+
0:11 'a' ( temp highp int)
3841
0:25 Function Definition: cos(f1; ( global highp float)
3942
0:25 Function Parameters:
4043
0:25 'x' ( in highp float)
@@ -138,18 +141,22 @@ ERROR: node is still EOpNull!
138141
0:3 'a' ( in highp int)
139142
0:3 'b' ( in highp int)
140143
0:3 'c' ( in highp int)
141-
0:? Sequence
144+
0:5 Sequence
145+
0:5 Sequence
146+
0:5 move second child to first child ( temp highp int)
147+
0:5 'a' ( temp highp int)
148+
0:5 'b' ( in highp int)
142149
0:8 Sequence
143150
0:8 Sequence
144151
0:8 move second child to first child ( temp highp float)
145152
0:8 'a' ( temp highp float)
146153
0:8 add ( temp highp float)
147154
0:8 Convert int to float ( temp highp float)
148-
0:8 'a' ( in highp int)
155+
0:8 'a' ( temp highp int)
149156
0:8 Constant:
150157
0:8 1.000000
151158
0:11 Branch: Return with expression
152-
0:11 'a' ( in highp int)
159+
0:11 'a' ( temp highp int)
153160
0:36 Function Definition: main( ( global void)
154161
0:36 Function Parameters:
155162
0:? Sequence

glslang/MachineIndependent/ParseHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class TParseContextBase : public TParseVersions {
8484
scopeMangler("::"),
8585
symbolTable(symbolTable),
8686
statementNestingLevel(0), loopNestingLevel(0), structNestingLevel(0), controlFlowNestingLevel(0),
87+
currentFunctionType(nullptr),
8788
postEntryPointReturn(false),
8889
contextPragma(true, false),
8990
beginInvocationInterlockCount(0), endInvocationInterlockCount(0),

glslang/MachineIndependent/glslang.m4

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,6 +3842,14 @@ function_definition
38423842
: function_prototype {
38433843
$1.function = parseContext.handleFunctionDeclarator($1.loc, *$1.function, false /* not prototype */);
38443844
$1.intermNode = parseContext.handleFunctionDefinition($1.loc, *$1.function);
3845+
3846+
// For ES 100 only, according to ES shading language 100 spec: A function
3847+
// body has a scope nested inside the function's definition.
3848+
if (parseContext.profile == EEsProfile && parseContext.version == 100)
3849+
{
3850+
parseContext.symbolTable.push();
3851+
++parseContext.statementNestingLevel;
3852+
}
38453853
}
38463854
compound_statement_no_new_scope {
38473855
// May be best done as post process phase on intermediate code
@@ -3857,6 +3865,17 @@ function_definition
38573865
$$->getAsAggregate()->setOptimize(parseContext.contextPragma.optimize);
38583866
$$->getAsAggregate()->setDebug(parseContext.contextPragma.debug);
38593867
$$->getAsAggregate()->setPragmaTable(parseContext.contextPragma.pragmaTable);
3868+
3869+
// Set currentFunctionType to empty pointer when goes outside of the function
3870+
parseContext.currentFunctionType = nullptr;
3871+
3872+
// For ES 100 only, according to ES shading language 100 spec: A function
3873+
// body has a scope nested inside the function's definition.
3874+
if (parseContext.profile == EEsProfile && parseContext.version == 100)
3875+
{
3876+
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
3877+
--parseContext.statementNestingLevel;
3878+
}
38603879
}
38613880
;
38623881

glslang/MachineIndependent/glslang.y

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3842,6 +3842,14 @@ function_definition
38423842
: function_prototype {
38433843
$1.function = parseContext.handleFunctionDeclarator($1.loc, *$1.function, false /* not prototype */);
38443844
$1.intermNode = parseContext.handleFunctionDefinition($1.loc, *$1.function);
3845+
3846+
// For ES 100 only, according to ES shading language 100 spec: A function
3847+
// body has a scope nested inside the function's definition.
3848+
if (parseContext.profile == EEsProfile && parseContext.version == 100)
3849+
{
3850+
parseContext.symbolTable.push();
3851+
++parseContext.statementNestingLevel;
3852+
}
38453853
}
38463854
compound_statement_no_new_scope {
38473855
// May be best done as post process phase on intermediate code
@@ -3857,6 +3865,17 @@ function_definition
38573865
$$->getAsAggregate()->setOptimize(parseContext.contextPragma.optimize);
38583866
$$->getAsAggregate()->setDebug(parseContext.contextPragma.debug);
38593867
$$->getAsAggregate()->setPragmaTable(parseContext.contextPragma.pragmaTable);
3868+
3869+
// Set currentFunctionType to empty pointer when goes outside of the function
3870+
parseContext.currentFunctionType = nullptr;
3871+
3872+
// For ES 100 only, according to ES shading language 100 spec: A function
3873+
// body has a scope nested inside the function's definition.
3874+
if (parseContext.profile == EEsProfile && parseContext.version == 100)
3875+
{
3876+
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
3877+
--parseContext.statementNestingLevel;
3878+
}
38603879
}
38613880
;
38623881

glslang/MachineIndependent/glslang_tab.cpp

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,8 @@ static const yytype_uint16 yyrline[] =
10121012
3603, 3611, 3615, 3628, 3632, 3639, 3639, 3659, 3662, 3668,
10131013
3680, 3692, 3696, 3703, 3703, 3718, 3718, 3734, 3734, 3755,
10141014
3758, 3764, 3767, 3773, 3777, 3784, 3789, 3794, 3801, 3804,
1015-
3813, 3817, 3826, 3829, 3833, 3842, 3842, 3865, 3871, 3874,
1016-
3879, 3882
1015+
3813, 3817, 3826, 3829, 3833, 3842, 3842, 3884, 3890, 3893,
1016+
3898, 3901
10171017
};
10181018
#endif
10191019

@@ -10298,12 +10298,20 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1029810298
{
1029910299
(yyvsp[0].interm).function = parseContext.handleFunctionDeclarator((yyvsp[0].interm).loc, *(yyvsp[0].interm).function, false /* not prototype */);
1030010300
(yyvsp[0].interm).intermNode = parseContext.handleFunctionDefinition((yyvsp[0].interm).loc, *(yyvsp[0].interm).function);
10301+
10302+
// For ES 100 only, according to ES shading language 100 spec: A function
10303+
// body has a scope nested inside the function's definition.
10304+
if (parseContext.profile == EEsProfile && parseContext.version == 100)
10305+
{
10306+
parseContext.symbolTable.push();
10307+
++parseContext.statementNestingLevel;
10308+
}
1030110309
}
10302-
#line 10303 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
10310+
#line 10311 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
1030310311
break;
1030410312

1030510313
case 586:
10306-
#line 3846 "MachineIndependent/glslang.y" /* yacc.c:1646 */
10314+
#line 3854 "MachineIndependent/glslang.y" /* yacc.c:1646 */
1030710315
{
1030810316
// May be best done as post process phase on intermediate code
1030910317
if (parseContext.currentFunctionType->getBasicType() != EbtVoid && ! parseContext.functionReturnsValue)
@@ -10318,53 +10326,64 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1031810326
(yyval.interm.intermNode)->getAsAggregate()->setOptimize(parseContext.contextPragma.optimize);
1031910327
(yyval.interm.intermNode)->getAsAggregate()->setDebug(parseContext.contextPragma.debug);
1032010328
(yyval.interm.intermNode)->getAsAggregate()->setPragmaTable(parseContext.contextPragma.pragmaTable);
10329+
10330+
// Set currentFunctionType to empty pointer when goes outside of the function
10331+
parseContext.currentFunctionType = nullptr;
10332+
10333+
// For ES 100 only, according to ES shading language 100 spec: A function
10334+
// body has a scope nested inside the function's definition.
10335+
if (parseContext.profile == EEsProfile && parseContext.version == 100)
10336+
{
10337+
parseContext.symbolTable.pop(&parseContext.defaultPrecision[0]);
10338+
--parseContext.statementNestingLevel;
10339+
}
1032110340
}
10322-
#line 10323 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
10341+
#line 10342 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
1032310342
break;
1032410343

1032510344
case 587:
10326-
#line 3865 "MachineIndependent/glslang.y" /* yacc.c:1646 */
10345+
#line 3884 "MachineIndependent/glslang.y" /* yacc.c:1646 */
1032710346
{
1032810347
(yyval.interm.attributes) = (yyvsp[-2].interm.attributes);
1032910348
parseContext.requireExtensions((yyvsp[-4].lex).loc, 1, &E_GL_EXT_control_flow_attributes, "attribute");
1033010349
}
10331-
#line 10332 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
10350+
#line 10351 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
1033210351
break;
1033310352

1033410353
case 588:
10335-
#line 3871 "MachineIndependent/glslang.y" /* yacc.c:1646 */
10354+
#line 3890 "MachineIndependent/glslang.y" /* yacc.c:1646 */
1033610355
{
1033710356
(yyval.interm.attributes) = (yyvsp[0].interm.attributes);
1033810357
}
10339-
#line 10340 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
10358+
#line 10359 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
1034010359
break;
1034110360

1034210361
case 589:
10343-
#line 3874 "MachineIndependent/glslang.y" /* yacc.c:1646 */
10362+
#line 3893 "MachineIndependent/glslang.y" /* yacc.c:1646 */
1034410363
{
1034510364
(yyval.interm.attributes) = parseContext.mergeAttributes((yyvsp[-2].interm.attributes), (yyvsp[0].interm.attributes));
1034610365
}
10347-
#line 10348 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
10366+
#line 10367 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
1034810367
break;
1034910368

1035010369
case 590:
10351-
#line 3879 "MachineIndependent/glslang.y" /* yacc.c:1646 */
10370+
#line 3898 "MachineIndependent/glslang.y" /* yacc.c:1646 */
1035210371
{
1035310372
(yyval.interm.attributes) = parseContext.makeAttributes(*(yyvsp[0].lex).string);
1035410373
}
10355-
#line 10356 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
10374+
#line 10375 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
1035610375
break;
1035710376

1035810377
case 591:
10359-
#line 3882 "MachineIndependent/glslang.y" /* yacc.c:1646 */
10378+
#line 3901 "MachineIndependent/glslang.y" /* yacc.c:1646 */
1036010379
{
1036110380
(yyval.interm.attributes) = parseContext.makeAttributes(*(yyvsp[-3].lex).string, (yyvsp[-1].interm.intermTypedNode));
1036210381
}
10363-
#line 10364 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
10382+
#line 10383 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
1036410383
break;
1036510384

1036610385

10367-
#line 10368 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
10386+
#line 10387 "MachineIndependent/glslang_tab.cpp" /* yacc.c:1646 */
1036810387
default: break;
1036910388
}
1037010389
/* User semantic actions sometimes alter yychar, and that requires
@@ -10592,5 +10611,5 @@ YYSTYPE yylval YY_INITIAL_VALUE (= yyval_default);
1059210611
#endif
1059310612
return yyresult;
1059410613
}
10595-
#line 3887 "MachineIndependent/glslang.y" /* yacc.c:1906 */
10614+
#line 3906 "MachineIndependent/glslang.y" /* yacc.c:1906 */
1059610615

0 commit comments

Comments
 (0)