HLSL: Finish skeletan of the "statement" grammar.
This commit is contained in:
parent
1cc1a2813e
commit
21472aee75
@ -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
|
||||||
TIntermAggregate* functionBody = nullptr;
|
TIntermNode* 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)
|
|||||||
// 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)
|
|||||||
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)
|
|||||||
// compound_statement
|
// compound_statement
|
||||||
// : LEFT_CURLY statement statement ... RIGHT_CURLY
|
// : LEFT_CURLY statement statement ... RIGHT_CURLY
|
||||||
//
|
//
|
||||||
bool HlslGrammar::acceptCompoundStatement(TIntermAggregate*& compoundStatement)
|
bool HlslGrammar::acceptCompoundStatement(TIntermNode*& retStatement)
|
||||||
{
|
{
|
||||||
|
TIntermAggregate* compoundStatement = nullptr;
|
||||||
|
|
||||||
// LEFT_CURLY
|
// LEFT_CURLY
|
||||||
if (! acceptTokenClass(EHTokLeftBrace))
|
if (! acceptTokenClass(EHTokLeftBrace))
|
||||||
return false;
|
return false;
|
||||||
@ -882,54 +890,170 @@ 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)) {
|
|
||||||
statement = compoundStatement;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// RETURN
|
// attributes
|
||||||
if (acceptTokenClass(EHTokReturn)) {
|
acceptAttributes();
|
||||||
// expression
|
|
||||||
TIntermTyped* node;
|
|
||||||
if (acceptExpression(node)) {
|
|
||||||
// hook it up
|
|
||||||
statement = intermediate.addBranch(EOpReturn, node, token.loc);
|
|
||||||
} else
|
|
||||||
statement = intermediate.addBranch(EOpReturn, token.loc);
|
|
||||||
|
|
||||||
// SEMICOLON
|
// attributed_statement
|
||||||
if (! acceptTokenClass(EHTokSemicolon))
|
switch (peek()) {
|
||||||
return false;
|
case EHTokLeftBrace:
|
||||||
|
return acceptCompoundStatement(statement);
|
||||||
|
|
||||||
return true;
|
case EHTokIf:
|
||||||
}
|
return acceptSelectionStatement(statement);
|
||||||
|
|
||||||
// expression
|
case EHTokSwitch:
|
||||||
TIntermTyped* node;
|
return acceptSwitchStatement(statement);
|
||||||
if (acceptExpression(node))
|
|
||||||
statement = node;
|
|
||||||
|
|
||||||
// SEMICOLON
|
case EHTokFor:
|
||||||
if (! acceptTokenClass(EHTokSemicolon))
|
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;
|
return false;
|
||||||
|
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// declaration
|
||||||
|
if (acceptDeclaration(statement))
|
||||||
|
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 true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)) {
|
||||||
|
// expression
|
||||||
|
TIntermTyped* node;
|
||||||
|
if (acceptExpression(node)) {
|
||||||
|
// hook it up
|
||||||
|
statement = intermediate.addBranch(EOpReturn, node, token.loc);
|
||||||
|
} else
|
||||||
|
statement = intermediate.addBranch(EOpReturn, token.loc);
|
||||||
|
|
||||||
|
// SEMICOLON
|
||||||
|
if (! acceptTokenClass(EHTokSemicolon)) {
|
||||||
|
expected("semicolon");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool HlslGrammar::acceptCaseLabel(TIntermNode*& statement)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// COLON semantic
|
// COLON semantic
|
||||||
bool HlslGrammar::acceptSemantic()
|
bool HlslGrammar::acceptSemantic()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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(TIntermAggregate*&);
|
bool acceptCompoundStatement(TIntermNode*&);
|
||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user