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
21472aee
Commit
21472aee
authored
Jun 04, 2016
by
John Kessenich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HLSL: Finish skeletan of the "statement" grammar.
parent
1cc1a281
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
151 additions
and
20 deletions
+151
-20
hlslGrammar.cpp
hlsl/hlslGrammar.cpp
+143
-19
hlslGrammar.h
hlsl/hlslGrammar.h
+8
-1
No files found.
hlsl/hlslGrammar.cpp
View file @
21472aee
...
@@ -472,7 +472,7 @@ bool HlslGrammar::acceptFunctionDefinition(TFunction& function, TIntermNode*& no
...
@@ -472,7 +472,7 @@ bool HlslGrammar::acceptFunctionDefinition(TFunction& function, TIntermNode*& no
node
=
parseContext
.
handleFunctionDefinition
(
token
.
loc
,
*
functionDeclarator
);
node
=
parseContext
.
handleFunctionDefinition
(
token
.
loc
,
*
functionDeclarator
);
// compound_statement
// compound_statement
TInterm
Aggregat
e
*
functionBody
=
nullptr
;
TInterm
Nod
e
*
functionBody
=
nullptr
;
if
(
acceptCompoundStatement
(
functionBody
))
{
if
(
acceptCompoundStatement
(
functionBody
))
{
node
=
intermediate
.
growAggregate
(
node
,
functionBody
);
node
=
intermediate
.
growAggregate
(
node
,
functionBody
);
intermediate
.
setAggregateOperator
(
node
,
EOpFunction
,
functionDeclarator
->
getType
(),
token
.
loc
);
intermediate
.
setAggregateOperator
(
node
,
EOpFunction
,
functionDeclarator
->
getType
(),
token
.
loc
);
...
@@ -690,8 +690,10 @@ bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node)
...
@@ -690,8 +690,10 @@ bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node)
// idToken will pick up either a variable or a function name in a function call
// idToken will pick up either a variable or a function name in a function call
HlslToken
idToken
;
HlslToken
idToken
;
// LEFT_PAREN expression RIGHT_PAREN
// Find something before the postfix operations, as they can't operate
// on nothing. So, no "return true", they fall through, only "return false".
if
(
acceptTokenClass
(
EHTokLeftParen
))
{
if
(
acceptTokenClass
(
EHTokLeftParen
))
{
// LEFT_PAREN expression RIGHT_PAREN
if
(
!
acceptExpression
(
node
))
{
if
(
!
acceptExpression
(
node
))
{
expected
(
"expression"
);
expected
(
"expression"
);
return
false
;
return
false
;
...
@@ -714,8 +716,12 @@ bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node)
...
@@ -714,8 +716,12 @@ bool HlslGrammar::acceptPostfixExpression(TIntermTyped*& node)
expected
(
"function call arguments"
);
expected
(
"function call arguments"
);
return
false
;
return
false
;
}
}
}
else
{
// nothing found, can't post operate
return
false
;
}
}
// Something was found, chain as many postfix operations as exist.
do
{
do
{
TSourceLoc
loc
=
token
.
loc
;
TSourceLoc
loc
=
token
.
loc
;
TOperator
postOp
=
HlslOpMap
::
postUnary
(
peek
());
TOperator
postOp
=
HlslOpMap
::
postUnary
(
peek
());
...
@@ -867,8 +873,10 @@ bool HlslGrammar::acceptLiteral(TIntermTyped*& node)
...
@@ -867,8 +873,10 @@ bool HlslGrammar::acceptLiteral(TIntermTyped*& node)
// compound_statement
// compound_statement
// : LEFT_CURLY statement statement ... RIGHT_CURLY
// : LEFT_CURLY statement statement ... RIGHT_CURLY
//
//
bool
HlslGrammar
::
acceptCompoundStatement
(
TInterm
Aggregate
*&
compound
Statement
)
bool
HlslGrammar
::
acceptCompoundStatement
(
TInterm
Node
*&
ret
Statement
)
{
{
TIntermAggregate
*
compoundStatement
=
nullptr
;
// LEFT_CURLY
// LEFT_CURLY
if
(
!
acceptTokenClass
(
EHTokLeftBrace
))
if
(
!
acceptTokenClass
(
EHTokLeftBrace
))
return
false
;
return
false
;
...
@@ -882,26 +890,141 @@ bool HlslGrammar::acceptCompoundStatement(TIntermAggregate*& compoundStatement)
...
@@ -882,26 +890,141 @@ bool HlslGrammar::acceptCompoundStatement(TIntermAggregate*& compoundStatement)
if
(
compoundStatement
)
if
(
compoundStatement
)
compoundStatement
->
setOperator
(
EOpSequence
);
compoundStatement
->
setOperator
(
EOpSequence
);
retStatement
=
compoundStatement
;
// RIGHT_CURLY
// RIGHT_CURLY
return
acceptTokenClass
(
EHTokRightBrace
);
return
acceptTokenClass
(
EHTokRightBrace
);
}
}
// statement
// statement
// : attributes attributed_statement
//
// attributed_statement
// : compound_statement
// : compound_statement
// | return SEMICOLON
// | SEMICOLON
// | return expression SEMICOLON
// | expression SEMICOLON
// | expression SEMICOLON
// | declaration_statement
// | selection_statement
// | switch_statement
// | case_label
// | iteration_statement
// | jump_statement
//
//
bool
HlslGrammar
::
acceptStatement
(
TIntermNode
*&
statement
)
bool
HlslGrammar
::
acceptStatement
(
TIntermNode
*&
statement
)
{
{
// compound_statement
statement
=
nullptr
;
TIntermAggregate
*
compoundStatement
=
nullptr
;
if
(
acceptCompoundStatement
(
compoundStatement
))
{
// attributes
statement
=
compoundStatement
;
acceptAttributes
();
// attributed_statement
switch
(
peek
())
{
case
EHTokLeftBrace
:
return
acceptCompoundStatement
(
statement
);
case
EHTokIf
:
return
acceptSelectionStatement
(
statement
);
case
EHTokSwitch
:
return
acceptSwitchStatement
(
statement
);
case
EHTokFor
:
case
EHTokDo
:
case
EHTokWhile
:
return
acceptIterationStatement
(
statement
);
case
EHTokContinue
:
case
EHTokBreak
:
case
EHTokDiscard
:
case
EHTokReturn
:
return
acceptJumpStatement
(
statement
);
case
EHTokCase
:
return
acceptCaseLabel
(
statement
);
case
EHTokSemicolon
:
return
acceptTokenClass
(
EHTokSemicolon
);
case
EHTokRightBrace
:
// Performance: not strictly necessary, but stops a bunch of hunting early,
// and is how sequences of statements end.
return
false
;
default
:
{
// declaration
if
(
acceptDeclaration
(
statement
))
return
true
;
return
true
;
// expression
TIntermTyped
*
node
;
if
(
acceptExpression
(
node
))
statement
=
node
;
else
return
false
;
// SEMICOLON (following an expression)
if
(
!
acceptTokenClass
(
EHTokSemicolon
))
{
expected
(
"semicolon"
);
return
false
;
}
}
}
}
return
true
;
}
// RETURN
// attributes
// : list of zero or more of: LEFT_BRACKET attribute RIGHT_BRACKET
//
// attribute:
// : UNROLL
// | UNROLL LEFT_PAREN literal RIGHT_PAREN
// | FASTOPT
// | ALLOW_UAV_CONDITION
// | BRANCH
// | FLATTEN
// | FORCECASE
// | CALL
//
void
HlslGrammar
::
acceptAttributes
()
{
// TODO
}
bool
HlslGrammar
::
acceptSelectionStatement
(
TIntermNode
*&
statement
)
{
return
false
;
}
bool
HlslGrammar
::
acceptSwitchStatement
(
TIntermNode
*&
statement
)
{
return
false
;
}
bool
HlslGrammar
::
acceptIterationStatement
(
TIntermNode
*&
statement
)
{
return
false
;
}
// jump_statement
// : CONTINUE SEMICOLON
// | BREAK SEMICOLON
// | DISCARD SEMICOLON
// | RETURN SEMICOLON
// | RETURN expression SEMICOLON
//
bool
HlslGrammar
::
acceptJumpStatement
(
TIntermNode
*&
statement
)
{
switch
(
peek
())
{
case
EHTokContinue
:
case
EHTokBreak
:
case
EHTokDiscard
:
// TODO
return
false
;
case
EHTokReturn
:
// return
if
(
acceptTokenClass
(
EHTokReturn
))
{
if
(
acceptTokenClass
(
EHTokReturn
))
{
// expression
// expression
TIntermTyped
*
node
;
TIntermTyped
*
node
;
...
@@ -912,22 +1035,23 @@ bool HlslGrammar::acceptStatement(TIntermNode*& statement)
...
@@ -912,22 +1035,23 @@ bool HlslGrammar::acceptStatement(TIntermNode*& statement)
statement
=
intermediate
.
addBranch
(
EOpReturn
,
token
.
loc
);
statement
=
intermediate
.
addBranch
(
EOpReturn
,
token
.
loc
);
// SEMICOLON
// SEMICOLON
if
(
!
acceptTokenClass
(
EHTokSemicolon
))
if
(
!
acceptTokenClass
(
EHTokSemicolon
))
{
expected
(
"semicolon"
);
return
false
;
return
false
;
}
return
true
;
return
true
;
}
}
// expression
default
:
TIntermTyped
*
node
;
if
(
acceptExpression
(
node
))
statement
=
node
;
// SEMICOLON
if
(
!
acceptTokenClass
(
EHTokSemicolon
))
return
false
;
return
false
;
}
}
return
true
;
bool
HlslGrammar
::
acceptCaseLabel
(
TIntermNode
*&
statement
)
{
return
false
;
}
}
// COLON semantic
// COLON semantic
...
...
hlsl/hlslGrammar.h
View file @
21472aee
...
@@ -73,8 +73,15 @@ namespace glslang {
...
@@ -73,8 +73,15 @@ namespace glslang {
bool
acceptFunctionCall
(
HlslToken
,
TIntermTyped
*&
);
bool
acceptFunctionCall
(
HlslToken
,
TIntermTyped
*&
);
bool
acceptArguments
(
TFunction
*
,
TIntermTyped
*&
);
bool
acceptArguments
(
TFunction
*
,
TIntermTyped
*&
);
bool
acceptLiteral
(
TIntermTyped
*&
);
bool
acceptLiteral
(
TIntermTyped
*&
);
bool
acceptCompoundStatement
(
TInterm
Aggregat
e
*&
);
bool
acceptCompoundStatement
(
TInterm
Nod
e
*&
);
bool
acceptStatement
(
TIntermNode
*&
);
bool
acceptStatement
(
TIntermNode
*&
);
void
acceptAttributes
();
bool
acceptSelectionStatement
(
TIntermNode
*&
);
bool
acceptSwitchStatement
(
TIntermNode
*&
);
bool
acceptIterationStatement
(
TIntermNode
*&
);
bool
acceptJumpStatement
(
TIntermNode
*&
);
bool
acceptCaseLabel
(
TIntermNode
*&
);
bool
acceptSemantic
();
bool
acceptSemantic
();
HlslParseContext
&
parseContext
;
// state of parsing and helper functions for building the intermediate
HlslParseContext
&
parseContext
;
// state of parsing and helper functions for building the intermediate
...
...
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