@@ -25,54 +25,60 @@ RootSignatureParser::RootSignatureParser(
25
25
Lexer (Signature->getString ()), PP(PP), CurToken(0 ) {}
26
26
27
27
bool RootSignatureParser::parse () {
28
- // Iterate as many RootSignatureElements 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
std::optional<RootSignatureElement> Element = std::nullopt;
31
32
if (tryConsumeExpectedToken (TokenKind::kw_RootFlags)) {
33
+ // RootFlags
32
34
SourceLocation ElementLoc = getTokenLocation (CurToken);
33
35
auto Flags = parseRootFlags ();
34
36
if (!Flags.has_value ())
35
37
return true ;
36
38
Element = RootSignatureElement (ElementLoc, *Flags);
37
- }
38
-
39
- if (tryConsumeExpectedToken (TokenKind::kw_RootConstants)) {
39
+ } else if (tryConsumeExpectedToken (TokenKind::kw_RootConstants)) {
40
+ // RootConstants
40
41
SourceLocation ElementLoc = getTokenLocation (CurToken);
41
42
auto Constants = parseRootConstants ();
42
43
if (!Constants.has_value ())
43
44
return true ;
44
45
Element = RootSignatureElement (ElementLoc, *Constants);
45
- }
46
-
47
- if (tryConsumeExpectedToken (TokenKind::kw_DescriptorTable)) {
46
+ } else if (tryConsumeExpectedToken (TokenKind::kw_DescriptorTable)) {
47
+ // DescriptorTable
48
48
SourceLocation ElementLoc = getTokenLocation (CurToken);
49
49
auto Table = parseDescriptorTable ();
50
50
if (!Table.has_value ())
51
51
return true ;
52
52
Element = RootSignatureElement (ElementLoc, *Table);
53
- }
54
-
55
- if (tryConsumeExpectedToken (
56
- {TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
53
+ } else if (tryConsumeExpectedToken (
54
+ {TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
55
+ // RootDescriptor - CBV, SRV, UAV
57
56
SourceLocation ElementLoc = getTokenLocation (CurToken);
58
57
auto Descriptor = parseRootDescriptor ();
59
58
if (!Descriptor.has_value ())
60
59
return true ;
61
60
Element = RootSignatureElement (ElementLoc, *Descriptor);
62
- }
63
-
64
- if (tryConsumeExpectedToken (TokenKind::kw_StaticSampler)) {
61
+ } else if (tryConsumeExpectedToken (TokenKind::kw_StaticSampler)) {
62
+ // StaticSampler
65
63
SourceLocation ElementLoc = getTokenLocation (CurToken);
66
64
auto Sampler = parseStaticSampler ();
67
65
if (!Sampler.has_value ())
68
66
return true ;
69
67
Element = RootSignatureElement (ElementLoc, *Sampler);
68
+ } else {
69
+ consumeNextToken (); // position to start of invalid token
70
+ reportDiag (diag::err_hlsl_rootsig_invalid_param)
71
+ << /* param of=*/ TokenKind::kw_RootSignature;
72
+ return true ;
70
73
}
71
74
72
75
if (Element.has_value ())
73
76
Elements.push_back (*Element);
74
77
75
- } while (tryConsumeExpectedToken (TokenKind::pu_comma));
78
+ // ',' denotes another element, otherwise, expected to be at end of stream
79
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma))
80
+ break ;
81
+ }
76
82
77
83
return consumeExpectedToken (TokenKind::end_of_stream);
78
84
}
@@ -251,9 +257,7 @@ std::optional<DescriptorTable> RootSignatureParser::parseDescriptorTable() {
251
257
return std::nullopt;
252
258
Elements.push_back (RootSignatureElement (ElementLoc, *Clause));
253
259
Table.NumClauses ++;
254
- }
255
-
256
- if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
260
+ } else if (tryConsumeExpectedToken (TokenKind::kw_visibility)) {
257
261
if (Visibility.has_value ()) {
258
262
reportDiag (diag::err_hlsl_rootsig_repeat_param) << CurToken.TokKind ;
259
263
return std::nullopt;
0 commit comments