@@ -25,44 +25,41 @@ RootSignatureParser::RootSignatureParser(
25
25
Lexer (Signature->getString ()), PP(PP), CurToken(0 ) {}
26
26
27
27
bool RootSignatureParser::parse () {
28
- // Iterate as many RootElements as possible
29
- do {
28
+ // Iterate as many RootSignatureElements as possible, until we hit the
29
+ // end of the stream
30
+ while (!peekExpectedToken (TokenKind::end_of_stream)) {
30
31
if (tryConsumeExpectedToken (TokenKind::kw_RootFlags)) {
31
32
auto Flags = parseRootFlags ();
32
33
if (!Flags.has_value ())
33
34
return true ;
34
35
Elements.push_back (*Flags);
35
- }
36
-
37
- if (tryConsumeExpectedToken (TokenKind::kw_RootConstants)) {
36
+ } else if (tryConsumeExpectedToken (TokenKind::kw_RootConstants)) {
38
37
auto Constants = parseRootConstants ();
39
38
if (!Constants.has_value ())
40
39
return true ;
41
40
Elements.push_back (*Constants);
42
- }
43
-
44
- if (tryConsumeExpectedToken (TokenKind::kw_DescriptorTable)) {
41
+ } else if (tryConsumeExpectedToken (TokenKind::kw_DescriptorTable)) {
45
42
auto Table = parseDescriptorTable ();
46
43
if (!Table.has_value ())
47
44
return true ;
48
45
Elements.push_back (*Table);
49
- }
50
-
51
- if (tryConsumeExpectedToken (
52
- {TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
46
+ } else if (tryConsumeExpectedToken (
47
+ {TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
53
48
auto Descriptor = parseRootDescriptor ();
54
49
if (!Descriptor.has_value ())
55
50
return true ;
56
51
Elements.push_back (*Descriptor);
57
- }
58
-
59
- if (tryConsumeExpectedToken (TokenKind::kw_StaticSampler)) {
52
+ } else if (tryConsumeExpectedToken (TokenKind::kw_StaticSampler)) {
60
53
auto Sampler = parseStaticSampler ();
61
54
if (!Sampler.has_value ())
62
55
return true ;
63
56
Elements.push_back (*Sampler);
64
57
}
65
- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
58
+
59
+ // ',' denotes another element, otherwise, expected to be at end of stream
60
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
61
+ break ;
62
+ }
66
63
67
64
return consumeExpectedToken (TokenKind::end_of_stream,
68
65
diag::err_hlsl_unexpected_end_of_params,
@@ -252,9 +249,7 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
252
249
return std::nullopt;
253
250
Elements.push_back (*Clause);
254
251
Table.NumClauses ++;
255
- }
256
-
257
- if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
252
+ } else if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
258
253
if (Visibility.has_value ()) {
259
254
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
260
255
return std::nullopt;
0 commit comments