@@ -26,22 +26,14 @@ RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
26
26
27
27
bool RootSignatureParser::parse () {
28
28
// 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 ())
36
33
return true ;
37
- break ;
38
- default :
39
- llvm_unreachable (" Switch for consumed token was not provided" );
34
+ Elements.push_back (*Table);
40
35
}
41
-
42
- if (!tryConsumeExpectedToken (TokenKind::pu_comma))
43
- break ;
44
- }
36
+ } while (tryConsumeExpectedToken (TokenKind::pu_comma));
45
37
46
38
if (consumeExpectedToken (TokenKind::end_of_stream,
47
39
diag::err_hlsl_unexpected_end_of_params,
@@ -51,38 +43,38 @@ bool RootSignatureParser::parse() {
51
43
return false ;
52
44
}
53
45
54
- bool RootSignatureParser::parseDescriptorTable () {
46
+ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable () {
55
47
assert (CurToken.TokKind == TokenKind::kw_DescriptorTable &&
56
48
" Expects to only be invoked starting at given keyword" );
57
49
58
- DescriptorTable Table;
59
-
60
50
if (consumeExpectedToken (TokenKind::pu_l_paren, diag::err_expected_after,
61
51
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;
69
53
70
- Table. NumClauses ++ ;
54
+ DescriptorTable Table;
71
55
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));
75
67
76
68
if (consumeExpectedToken (TokenKind::pu_r_paren,
77
69
diag::err_hlsl_unexpected_end_of_params,
78
70
/* param of=*/ TokenKind::kw_DescriptorTable))
79
- return true ;
71
+ return std::nullopt ;
80
72
81
- Elements.push_back (Table);
82
- return false ;
73
+ return Table;
83
74
}
84
75
85
- bool RootSignatureParser::parseDescriptorTableClause () {
76
+ std::optional<DescriptorTableClause>
77
+ RootSignatureParser::parseDescriptorTableClause () {
86
78
assert ((CurToken.TokKind == TokenKind::kw_CBV ||
87
79
CurToken.TokKind == TokenKind::kw_SRV ||
88
80
CurToken.TokKind == TokenKind::kw_UAV ||
@@ -93,7 +85,7 @@ bool RootSignatureParser::parseDescriptorTableClause() {
93
85
94
86
if (consumeExpectedToken (TokenKind::pu_l_paren, diag::err_expected_after,
95
87
CurToken.TokKind ))
96
- return true ;
88
+ return std::nullopt ;
97
89
98
90
DescriptorTableClause Clause;
99
91
TokenKind ExpectedReg;
@@ -120,13 +112,13 @@ bool RootSignatureParser::parseDescriptorTableClause() {
120
112
121
113
auto Params = parseDescriptorTableClauseParams (ExpectedReg);
122
114
if (!Params.has_value ())
123
- return true ;
115
+ return std::nullopt ;
124
116
125
117
// Check mandatory parameters were provided
126
118
if (!Params->Reg .has_value ()) {
127
119
getDiags ().Report (CurToken.TokLoc , diag::err_hlsl_rootsig_missing_param)
128
120
<< ExpectedReg;
129
- return true ;
121
+ return std::nullopt ;
130
122
}
131
123
132
124
Clause.Reg = Params->Reg .value ();
@@ -138,10 +130,9 @@ bool RootSignatureParser::parseDescriptorTableClause() {
138
130
if (consumeExpectedToken (TokenKind::pu_r_paren,
139
131
diag::err_hlsl_unexpected_end_of_params,
140
132
/* param of=*/ ParamKind))
141
- return true ;
133
+ return std::nullopt ;
142
134
143
- Elements.push_back (Clause);
144
- return false ;
135
+ return Clause;
145
136
}
146
137
147
138
std::optional<RootSignatureParser::ParsedClauseParams>
0 commit comments