Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
b10feabc
Commit
b10feabc
authored
Jun 28, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Front-end: Non-functional: Move return-value handling from .y to .cpp.
This is to make the real change needed in the next commit easier.
parent
10119719
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
51 deletions
+42
-51
ParseHelper.cpp
glslang/MachineIndependent/ParseHelper.cpp
+20
-0
ParseHelper.h
glslang/MachineIndependent/ParseHelper.h
+1
-0
glslang.y
glslang/MachineIndependent/glslang.y
+1
-16
glslang_tab.cpp
glslang/MachineIndependent/glslang_tab.cpp
+20
-35
No files found.
glslang/MachineIndependent/ParseHelper.cpp
View file @
b10feabc
...
@@ -1199,6 +1199,26 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction
...
@@ -1199,6 +1199,26 @@ TIntermTyped* TParseContext::handleFunctionCall(const TSourceLoc& loc, TFunction
return
result
;
return
result
;
}
}
TIntermNode
*
TParseContext
::
handleReturnValue
(
const
TSourceLoc
&
loc
,
TIntermTyped
*
value
)
{
functionReturnsValue
=
true
;
if
(
currentFunctionType
->
getBasicType
()
==
EbtVoid
)
{
error
(
loc
,
"void function cannot return a value"
,
"return"
,
""
);
return
intermediate
.
addBranch
(
EOpReturn
,
loc
);
}
else
if
(
*
currentFunctionType
!=
value
->
getType
())
{
TIntermTyped
*
converted
=
intermediate
.
addConversion
(
EOpReturn
,
*
currentFunctionType
,
value
);
if
(
converted
)
{
if
(
version
<
420
)
warn
(
loc
,
"type conversion on return values was not explicitly allowed until version 420"
,
"return"
,
""
);
return
intermediate
.
addBranch
(
EOpReturn
,
converted
,
loc
);
}
else
{
error
(
loc
,
"type does not match, or is not convertible to, the function's return type"
,
"return"
,
""
);
return
intermediate
.
addBranch
(
EOpReturn
,
value
,
loc
);
}
}
else
return
intermediate
.
addBranch
(
EOpReturn
,
value
,
loc
);
}
// See if the operation is being done in an illegal location.
// See if the operation is being done in an illegal location.
void
TParseContext
::
checkLocation
(
const
TSourceLoc
&
loc
,
TOperator
op
)
void
TParseContext
::
checkLocation
(
const
TSourceLoc
&
loc
,
TOperator
op
)
{
{
...
...
glslang/MachineIndependent/ParseHelper.h
View file @
b10feabc
...
@@ -197,6 +197,7 @@ public:
...
@@ -197,6 +197,7 @@ public:
TFunction
*
handleFunctionDeclarator
(
const
TSourceLoc
&
,
TFunction
&
function
,
bool
prototype
);
TFunction
*
handleFunctionDeclarator
(
const
TSourceLoc
&
,
TFunction
&
function
,
bool
prototype
);
TIntermAggregate
*
handleFunctionDefinition
(
const
TSourceLoc
&
,
TFunction
&
);
TIntermAggregate
*
handleFunctionDefinition
(
const
TSourceLoc
&
,
TFunction
&
);
TIntermTyped
*
handleFunctionCall
(
const
TSourceLoc
&
,
TFunction
*
,
TIntermNode
*
);
TIntermTyped
*
handleFunctionCall
(
const
TSourceLoc
&
,
TFunction
*
,
TIntermNode
*
);
TIntermNode
*
handleReturnValue
(
const
TSourceLoc
&
,
TIntermTyped
*
);
void
checkLocation
(
const
TSourceLoc
&
,
TOperator
);
void
checkLocation
(
const
TSourceLoc
&
,
TOperator
);
TIntermTyped
*
handleLengthMethod
(
const
TSourceLoc
&
,
TFunction
*
,
TIntermNode
*
);
TIntermTyped
*
handleLengthMethod
(
const
TSourceLoc
&
,
TFunction
*
,
TIntermNode
*
);
void
addInputArgumentConversions
(
const
TFunction
&
,
TIntermNode
*&
)
const
;
void
addInputArgumentConversions
(
const
TFunction
&
,
TIntermNode
*&
)
const
;
...
...
glslang/MachineIndependent/glslang.y
View file @
b10feabc
...
@@ -2633,22 +2633,7 @@ jump_statement
...
@@ -2633,22 +2633,7 @@ jump_statement
parseContext.postMainReturn = true;
parseContext.postMainReturn = true;
}
}
| RETURN expression SEMICOLON {
| RETURN expression SEMICOLON {
parseContext.functionReturnsValue = true;
$$ = parseContext.handleReturnValue($1.loc, $2);
if (parseContext.currentFunctionType->getBasicType() == EbtVoid) {
parseContext.error($1.loc, "void function cannot return a value", "return", "");
$$ = parseContext.intermediate.addBranch(EOpReturn, $1.loc);
} else if (*(parseContext.currentFunctionType) != $2->getType()) {
TIntermTyped* converted = parseContext.intermediate.addConversion(EOpReturn, *parseContext.currentFunctionType, $2);
if (converted) {
if (parseContext.version < 420)
parseContext.warn($1.loc, "type conversion on return values was not explicitly allowed until version 420", "return", "");
$$ = parseContext.intermediate.addBranch(EOpReturn, converted, $1.loc);
} else {
parseContext.error($1.loc, "type does not match, or is not convertible to, the function's return type", "return", "");
$$ = parseContext.intermediate.addBranch(EOpReturn, $2, $1.loc);
}
} else
$$ = parseContext.intermediate.addBranch(EOpReturn, $2, $1.loc);
}
}
| DISCARD SEMICOLON {
| DISCARD SEMICOLON {
parseContext.requireStage($1.loc, EShLangFragment, "discard");
parseContext.requireStage($1.loc, EShLangFragment, "discard");
...
...
glslang/MachineIndependent/glslang_tab.cpp
View file @
b10feabc
...
@@ -827,8 +827,8 @@ static const yytype_uint16 yyrline[] =
...
@@ -827,8 +827,8 @@ static const yytype_uint16 yyrline[] =
2399
,
2399
,
2413
,
2416
,
2424
,
2432
,
2443
,
2444
,
2448
,
2455
,
2399
,
2399
,
2413
,
2416
,
2424
,
2432
,
2443
,
2444
,
2448
,
2455
,
2459
,
2467
,
2471
,
2484
,
2484
,
2504
,
2507
,
2513
,
2525
,
2537
,
2459
,
2467
,
2471
,
2484
,
2484
,
2504
,
2507
,
2513
,
2525
,
2537
,
2537
,
2552
,
2552
,
2568
,
2568
,
2589
,
2592
,
2598
,
2601
,
2607
,
2537
,
2552
,
2552
,
2568
,
2568
,
2589
,
2592
,
2598
,
2601
,
2607
,
2611
,
2618
,
2623
,
2628
,
2635
,
26
53
,
2662
,
2666
,
2673
,
2676
,
2611
,
2618
,
2623
,
2628
,
2635
,
26
38
,
2647
,
2651
,
2658
,
2661
,
26
82
,
2682
26
67
,
2667
};
};
#endif
#endif
...
@@ -7360,80 +7360,65 @@ yyreduce:
...
@@ -7360,80 +7360,65 @@ yyreduce:
case
414
:
case
414
:
#line 2635 "MachineIndependent/glslang.y"
/* yacc.c:1646 */
#line 2635 "MachineIndependent/glslang.y"
/* yacc.c:1646 */
{
{
parseContext
.
functionReturnsValue
=
true
;
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
handleReturnValue
((
yyvsp
[
-
2
].
lex
).
loc
,
(
yyvsp
[
-
1
].
interm
.
intermTypedNode
));
if
(
parseContext
.
currentFunctionType
->
getBasicType
()
==
EbtVoid
)
{
parseContext
.
error
((
yyvsp
[
-
2
].
lex
).
loc
,
"void function cannot return a value"
,
"return"
,
""
);
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
intermediate
.
addBranch
(
EOpReturn
,
(
yyvsp
[
-
2
].
lex
).
loc
);
}
else
if
(
*
(
parseContext
.
currentFunctionType
)
!=
(
yyvsp
[
-
1
].
interm
.
intermTypedNode
)
->
getType
())
{
TIntermTyped
*
converted
=
parseContext
.
intermediate
.
addConversion
(
EOpReturn
,
*
parseContext
.
currentFunctionType
,
(
yyvsp
[
-
1
].
interm
.
intermTypedNode
));
if
(
converted
)
{
if
(
parseContext
.
version
<
420
)
parseContext
.
warn
((
yyvsp
[
-
2
].
lex
).
loc
,
"type conversion on return values was not explicitly allowed until version 420"
,
"return"
,
""
);
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
intermediate
.
addBranch
(
EOpReturn
,
converted
,
(
yyvsp
[
-
2
].
lex
).
loc
);
}
else
{
parseContext
.
error
((
yyvsp
[
-
2
].
lex
).
loc
,
"type does not match, or is not convertible to, the function's return type"
,
"return"
,
""
);
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
intermediate
.
addBranch
(
EOpReturn
,
(
yyvsp
[
-
1
].
interm
.
intermTypedNode
),
(
yyvsp
[
-
2
].
lex
).
loc
);
}
}
else
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
intermediate
.
addBranch
(
EOpReturn
,
(
yyvsp
[
-
1
].
interm
.
intermTypedNode
),
(
yyvsp
[
-
2
].
lex
).
loc
);
}
}
#line 73
81
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 73
66
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
break
;
break
;
case
415
:
case
415
:
#line 26
53
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
#line 26
38
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
{
{
parseContext
.
requireStage
((
yyvsp
[
-
1
].
lex
).
loc
,
EShLangFragment
,
"discard"
);
parseContext
.
requireStage
((
yyvsp
[
-
1
].
lex
).
loc
,
EShLangFragment
,
"discard"
);
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
intermediate
.
addBranch
(
EOpKill
,
(
yyvsp
[
-
1
].
lex
).
loc
);
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
intermediate
.
addBranch
(
EOpKill
,
(
yyvsp
[
-
1
].
lex
).
loc
);
}
}
#line 73
90
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 73
75
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
break
;
break
;
case
416
:
case
416
:
#line 26
62
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
#line 26
47
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
{
{
(
yyval
.
interm
.
intermNode
)
=
(
yyvsp
[
0
].
interm
.
intermNode
);
(
yyval
.
interm
.
intermNode
)
=
(
yyvsp
[
0
].
interm
.
intermNode
);
parseContext
.
intermediate
.
setTreeRoot
((
yyval
.
interm
.
intermNode
));
parseContext
.
intermediate
.
setTreeRoot
((
yyval
.
interm
.
intermNode
));
}
}
#line 73
99
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 73
84
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
break
;
break
;
case
417
:
case
417
:
#line 26
66
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
#line 26
51
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
{
{
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
intermediate
.
growAggregate
((
yyvsp
[
-
1
].
interm
.
intermNode
),
(
yyvsp
[
0
].
interm
.
intermNode
));
(
yyval
.
interm
.
intermNode
)
=
parseContext
.
intermediate
.
growAggregate
((
yyvsp
[
-
1
].
interm
.
intermNode
),
(
yyvsp
[
0
].
interm
.
intermNode
));
parseContext
.
intermediate
.
setTreeRoot
((
yyval
.
interm
.
intermNode
));
parseContext
.
intermediate
.
setTreeRoot
((
yyval
.
interm
.
intermNode
));
}
}
#line 7
408
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 7
393
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
break
;
break
;
case
418
:
case
418
:
#line 26
73
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
#line 26
58
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
{
{
(
yyval
.
interm
.
intermNode
)
=
(
yyvsp
[
0
].
interm
.
intermNode
);
(
yyval
.
interm
.
intermNode
)
=
(
yyvsp
[
0
].
interm
.
intermNode
);
}
}
#line 74
16
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 74
01
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
break
;
break
;
case
419
:
case
419
:
#line 26
76
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
#line 26
61
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
{
{
(
yyval
.
interm
.
intermNode
)
=
(
yyvsp
[
0
].
interm
.
intermNode
);
(
yyval
.
interm
.
intermNode
)
=
(
yyvsp
[
0
].
interm
.
intermNode
);
}
}
#line 74
24
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 74
09
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
break
;
break
;
case
420
:
case
420
:
#line 26
82
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
#line 26
67
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
{
{
(
yyvsp
[
0
].
interm
).
function
=
parseContext
.
handleFunctionDeclarator
((
yyvsp
[
0
].
interm
).
loc
,
*
(
yyvsp
[
0
].
interm
).
function
,
false
/* not prototype */
);
(
yyvsp
[
0
].
interm
).
function
=
parseContext
.
handleFunctionDeclarator
((
yyvsp
[
0
].
interm
).
loc
,
*
(
yyvsp
[
0
].
interm
).
function
,
false
/* not prototype */
);
(
yyvsp
[
0
].
interm
).
intermNode
=
parseContext
.
handleFunctionDefinition
((
yyvsp
[
0
].
interm
).
loc
,
*
(
yyvsp
[
0
].
interm
).
function
);
(
yyvsp
[
0
].
interm
).
intermNode
=
parseContext
.
handleFunctionDefinition
((
yyvsp
[
0
].
interm
).
loc
,
*
(
yyvsp
[
0
].
interm
).
function
);
}
}
#line 74
33
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 74
18
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
break
;
break
;
case
421
:
case
421
:
#line 26
86
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
#line 26
71
"MachineIndependent/glslang.y"
/* yacc.c:1646 */
{
{
// May be best done as post process phase on intermediate code
// May be best done as post process phase on intermediate code
if
(
parseContext
.
currentFunctionType
->
getBasicType
()
!=
EbtVoid
&&
!
parseContext
.
functionReturnsValue
)
if
(
parseContext
.
currentFunctionType
->
getBasicType
()
!=
EbtVoid
&&
!
parseContext
.
functionReturnsValue
)
...
@@ -7449,11 +7434,11 @@ yyreduce:
...
@@ -7449,11 +7434,11 @@ yyreduce:
(
yyval
.
interm
.
intermNode
)
->
getAsAggregate
()
->
setDebug
(
parseContext
.
contextPragma
.
debug
);
(
yyval
.
interm
.
intermNode
)
->
getAsAggregate
()
->
setDebug
(
parseContext
.
contextPragma
.
debug
);
(
yyval
.
interm
.
intermNode
)
->
getAsAggregate
()
->
addToPragmaTable
(
parseContext
.
contextPragma
.
pragmaTable
);
(
yyval
.
interm
.
intermNode
)
->
getAsAggregate
()
->
addToPragmaTable
(
parseContext
.
contextPragma
.
pragmaTable
);
}
}
#line 74
53
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 74
38
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
break
;
break
;
#line 74
57
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
#line 74
42
"MachineIndependent/glslang_tab.cpp"
/* yacc.c:1646 */
default:
break
;
default:
break
;
}
}
/* User semantic actions sometimes alter yychar, and that requires
/* User semantic actions sometimes alter yychar, and that requires
...
@@ -7681,5 +7666,5 @@ yyreturn:
...
@@ -7681,5 +7666,5 @@ yyreturn:
#endif
#endif
return
yyresult
;
return
yyresult
;
}
}
#line 2
703
"MachineIndependent/glslang.y"
/* yacc.c:1906 */
#line 2
688
"MachineIndependent/glslang.y"
/* yacc.c:1906 */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment