@@ -26,22 +26,14 @@ RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
2626
2727bool RootSignatureParser::parse () {
2828 // Iterate as many RootElements as possible
29- while (tryConsumeExpectedToken (TokenKind::kw_DescriptorTable)) {
30- // Dispatch onto parser method.
31- // We guard against the unreachable here as we just ensured that CurToken
32- // will be one of the kinds in the while condition
33- switch (CurToken.TokKind ) {
34- case TokenKind::kw_DescriptorTable:
35- if (parseDescriptorTable ())
29+ do {
30+ if (tryConsumeExpectedToken (TokenKind::kw_DescriptorTable)) {
31+ auto Table = parseDescriptorTable ();
32+ if (!Table.has_value ())
3633 return true ;
37- break ;
38- default :
39- llvm_unreachable (" Switch for consumed token was not provided" );
34+ Elements.push_back (*Table);
4035 }
41-
42- if (!tryConsumeExpectedToken (TokenKind::pu_comma))
43- break ;
44- }
36+ } while (tryConsumeExpectedToken (TokenKind::pu_comma));
4537
4638 if (consumeExpectedToken (TokenKind::end_of_stream,
4739 diag::err_hlsl_unexpected_end_of_params,
@@ -51,38 +43,38 @@ bool RootSignatureParser::parse() {
5143 return false ;
5244}
5345
54- bool RootSignatureParser::parseDescriptorTable () {
46+ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable () {
5547 assert (CurToken.TokKind == TokenKind::kw_DescriptorTable &&
5648 " Expects to only be invoked starting at given keyword" );
5749
58- DescriptorTable Table;
59-
6050 if (consumeExpectedToken (TokenKind::pu_l_paren, diag::err_expected_after,
6151 CurToken.TokKind ))
62- return true ;
63-
64- // Iterate as many Clauses as possible
65- while (tryConsumeExpectedToken ({TokenKind::kw_CBV, TokenKind::kw_SRV,
66- TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
67- if (parseDescriptorTableClause ())
68- return true ;
52+ return std::nullopt ;
6953
70- Table. NumClauses ++ ;
54+ DescriptorTable Table;
7155
72- if (!tryConsumeExpectedToken (TokenKind::pu_comma))
73- break ;
74- }
56+ // Iterate as many Clauses as possible
57+ do {
58+ if (tryConsumeExpectedToken ({TokenKind::kw_CBV, TokenKind::kw_SRV,
59+ TokenKind::kw_UAV, TokenKind::kw_Sampler})) {
60+ auto Clause = parseDescriptorTableClause ();
61+ if (!Clause.has_value ())
62+ return std::nullopt ;
63+ Elements.push_back (*Clause);
64+ Table.NumClauses ++;
65+ }
66+ } while (tryConsumeExpectedToken (TokenKind::pu_comma));
7567
7668 if (consumeExpectedToken (TokenKind::pu_r_paren,
7769 diag::err_hlsl_unexpected_end_of_params,
7870 /* param of=*/ TokenKind::kw_DescriptorTable))
79- return true ;
71+ return std:: nullopt ;
8072
81- Elements.push_back (Table);
82- return false ;
73+ return Table;
8374}
8475
85- bool RootSignatureParser::parseDescriptorTableClause () {
76+ std::optional<DescriptorTableClause>
77+ RootSignatureParser::parseDescriptorTableClause () {
8678 assert ((CurToken.TokKind == TokenKind::kw_CBV ||
8779 CurToken.TokKind == TokenKind::kw_SRV ||
8880 CurToken.TokKind == TokenKind::kw_UAV ||
@@ -93,7 +85,7 @@ bool RootSignatureParser::parseDescriptorTableClause() {
9385
9486 if (consumeExpectedToken (TokenKind::pu_l_paren, diag::err_expected_after,
9587 CurToken.TokKind ))
96- return true ;
88+ return std:: nullopt ;
9789
9890 DescriptorTableClause Clause;
9991 TokenKind ExpectedReg;
@@ -120,13 +112,13 @@ bool RootSignatureParser::parseDescriptorTableClause() {
120112
121113 auto Params = parseDescriptorTableClauseParams (ExpectedReg);
122114 if (!Params.has_value ())
123- return true ;
115+ return std:: nullopt ;
124116
125117 // Check mandatory parameters were provided
126118 if (!Params->Reg .has_value ()) {
127119 getDiags ().Report (CurToken.TokLoc , diag::err_hlsl_rootsig_missing_param)
128120 << ExpectedReg;
129- return true ;
121+ return std:: nullopt ;
130122 }
131123
132124 Clause.Reg = Params->Reg .value ();
@@ -138,10 +130,9 @@ bool RootSignatureParser::parseDescriptorTableClause() {
138130 if (consumeExpectedToken (TokenKind::pu_r_paren,
139131 diag::err_hlsl_unexpected_end_of_params,
140132 /* param of=*/ ParamKind))
141- return true ;
133+ return std:: nullopt ;
142134
143- Elements.push_back (Clause);
144- return false ;
135+ return Clause;
145136}
146137
147138std::optional<RootSignatureParser::ParsedClauseParams>
0 commit comments