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
07354241
Commit
07354241
authored
Jul 01, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLSL: Grammar: Recognize { } style initializers for composites.
parent
b0a63f57
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
3 deletions
+65
-3
hlsl.init.frag.out
Test/baseResults/hlsl.init.frag.out
+0
-0
hlsl.init.frag
Test/hlsl.init.frag
+12
-0
hlslGrammar.cpp
hlsl/hlslGrammar.cpp
+52
-3
hlslGrammar.h
hlsl/hlslGrammar.h
+1
-0
No files found.
Test/baseResults/hlsl.init.frag.out
View file @
07354241
This diff is collapsed.
Click to expand it.
Test/hlsl.init.frag
View file @
07354241
float4
a1
=
float4
(
1
,
0
.
5
,
0
,
1
),
b1
=
float4
(
2
.
0
,
2
.
5
,
2
.
1
,
2
.
2
);
float4
a1
=
float4
(
1
,
0
.
5
,
0
,
1
),
b1
=
float4
(
2
.
0
,
2
.
5
,
2
.
1
,
2
.
2
);
float4
a1i
=
{
1
,
0
.
5
,
0
,
1
},
b1i
=
{
2
.
0
,
2
.
5
,
2
.
1
,
2
.
2
};
float
a2
=
0
.
2
,
b2
;
float
a2
=
0
.
2
,
b2
;
float
a3
,
b3
=
0
.
3
;
float
a3
,
b3
=
0
.
3
;
float
a4
,
b4
=
0
.
4
,
c4
;
float
a4
,
b4
=
0
.
4
,
c4
;
...
@@ -7,6 +8,17 @@ float a5 = 0.5, b5, c5 = 1.5;
...
@@ -7,6 +8,17 @@ float a5 = 0.5, b5, c5 = 1.5;
float4
ShaderFunction
(
float4
input
)
:
COLOR0
float4
ShaderFunction
(
float4
input
)
:
COLOR0
{
{
float4
a2
=
float4
(
0
.
2
,
0
.
3
,
0
.
4
,
0
.
5
);
float4
a2
=
float4
(
0
.
2
,
0
.
3
,
0
.
4
,
0
.
5
);
struct
S1
{
float
f
;
int
i
;
};
struct
S2
{
int
j
;
float
g
;
S1
s1
;
};
S2
s2i
=
{
9
,
a5
,
{
(
a3
,
a4
),
12
}
},
s2
=
S2
(
9
,
a5
,
S1
((
a3
,
a4
),
12
));
float
a8
=
(
a2
,
b2
),
a9
=
a5
;
return
input
*
a1
;
return
input
*
a1
;
}
}
hlsl/hlslGrammar.cpp
View file @
07354241
...
@@ -1173,28 +1173,77 @@ bool HlslGrammar::acceptExpression(TIntermTyped*& node)
...
@@ -1173,28 +1173,77 @@ bool HlslGrammar::acceptExpression(TIntermTyped*& node)
}
while
(
true
);
}
while
(
true
);
}
}
// initializer
// : LEFT_BRACE initializer_list RIGHT_BRACE
//
// initializer_list
// : assignment_expression COMMA assignment_expression COMMA ...
//
bool
HlslGrammar
::
acceptInitializer
(
TIntermTyped
*&
node
)
{
// LEFT_BRACE
if
(
!
acceptTokenClass
(
EHTokLeftBrace
))
return
false
;
// initializer_list
TSourceLoc
loc
=
token
.
loc
;
node
=
nullptr
;
do
{
// assignment_expression
TIntermTyped
*
expr
;
if
(
!
acceptAssignmentExpression
(
expr
))
{
expected
(
"assignment expression in initializer list"
);
return
false
;
}
node
=
intermediate
.
growAggregate
(
node
,
expr
,
loc
);
// COMMA
if
(
acceptTokenClass
(
EHTokComma
))
continue
;
// RIGHT_BRACE
if
(
acceptTokenClass
(
EHTokRightBrace
))
return
true
;
expected
(
", or }"
);
return
false
;
}
while
(
true
);
}
// Accept an assignment expression, where assignment operations
// Accept an assignment expression, where assignment operations
// associate right-to-left. Th
is
is, it is implicit, for example
// associate right-to-left. Th
at
is, it is implicit, for example
//
//
// a op (b op (c op d))
// a op (b op (c op d))
//
//
// assigment_expression
// assigment_expression
// : binary_expression op binary_expression op binary_expression ...
// : binary_expression op binary_expression op binary_expression ...
// | initializer
//
//
bool
HlslGrammar
::
acceptAssignmentExpression
(
TIntermTyped
*&
node
)
bool
HlslGrammar
::
acceptAssignmentExpression
(
TIntermTyped
*&
node
)
{
{
// initializer
if
(
peekTokenClass
(
EHTokLeftBrace
))
{
if
(
acceptInitializer
(
node
))
return
true
;
expected
(
"initializer"
);
return
false
;
}
// binary_expression
if
(
!
acceptBinaryExpression
(
node
,
PlLogicalOr
))
if
(
!
acceptBinaryExpression
(
node
,
PlLogicalOr
))
return
false
;
return
false
;
// assignment operation?
TOperator
assignOp
=
HlslOpMap
::
assignment
(
peek
());
TOperator
assignOp
=
HlslOpMap
::
assignment
(
peek
());
if
(
assignOp
==
EOpNull
)
if
(
assignOp
==
EOpNull
)
return
true
;
return
true
;
//
...
op
//
assignment
op
TSourceLoc
loc
=
token
.
loc
;
TSourceLoc
loc
=
token
.
loc
;
advanceToken
();
advanceToken
();
//
...
binary_expression
// binary_expression
// But, done by recursing this function, which automatically
// But, done by recursing this function, which automatically
// gets the right-to-left associativity.
// gets the right-to-left associativity.
TIntermTyped
*
rightNode
=
nullptr
;
TIntermTyped
*
rightNode
=
nullptr
;
...
...
hlsl/hlslGrammar.h
View file @
07354241
...
@@ -73,6 +73,7 @@ namespace glslang {
...
@@ -73,6 +73,7 @@ namespace glslang {
bool
acceptFunctionDefinition
(
TFunction
&
,
TIntermNode
*&
);
bool
acceptFunctionDefinition
(
TFunction
&
,
TIntermNode
*&
);
bool
acceptParenExpression
(
TIntermTyped
*&
);
bool
acceptParenExpression
(
TIntermTyped
*&
);
bool
acceptExpression
(
TIntermTyped
*&
);
bool
acceptExpression
(
TIntermTyped
*&
);
bool
acceptInitializer
(
TIntermTyped
*&
);
bool
acceptAssignmentExpression
(
TIntermTyped
*&
);
bool
acceptAssignmentExpression
(
TIntermTyped
*&
);
bool
acceptBinaryExpression
(
TIntermTyped
*&
,
PrecedenceLevel
);
bool
acceptBinaryExpression
(
TIntermTyped
*&
,
PrecedenceLevel
);
bool
acceptUnaryExpression
(
TIntermTyped
*&
);
bool
acceptUnaryExpression
(
TIntermTyped
*&
);
...
...
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