@@ -38,59 +38,67 @@ bool RootSignatureParser::parse() {
38
38
// end of the stream
39
39
bool HadError = false ;
40
40
while (!peekExpectedToken (TokenKind::end_of_stream)) {
41
- bool HadLocalError = false ;
42
41
if (tryConsumeExpectedToken (TokenKind::kw_RootFlags)) {
43
42
SourceLocation ElementLoc = getTokenLocation (CurToken);
44
43
auto Flags = parseRootFlags ();
45
- if (Flags.has_value ())
46
- Elements.emplace_back (ElementLoc, *Flags);
47
- else
48
- HadLocalError = true ;
44
+ if (!Flags.has_value ()) {
45
+ HadError = true ;
46
+ skipUntilExpectedToken (RootElementKeywords);
47
+ continue ;
48
+ }
49
+
50
+ Elements.emplace_back (ElementLoc, *Flags);
49
51
} else if (tryConsumeExpectedToken (TokenKind::kw_RootConstants)) {
50
52
SourceLocation ElementLoc = getTokenLocation (CurToken);
51
53
auto Constants = parseRootConstants ();
52
- if (Constants.has_value ())
53
- Elements.emplace_back (ElementLoc, *Constants);
54
- else
55
- HadLocalError = true ;
54
+ if (!Constants.has_value ()) {
55
+ HadError = true ;
56
+ skipUntilExpectedToken (RootElementKeywords);
57
+ continue ;
58
+ }
59
+ Elements.emplace_back (ElementLoc, *Constants);
56
60
} else if (tryConsumeExpectedToken (TokenKind::kw_DescriptorTable)) {
57
61
SourceLocation ElementLoc = getTokenLocation (CurToken);
58
62
auto Table = parseDescriptorTable ();
59
- if (Table.has_value ())
60
- Elements.emplace_back (ElementLoc, *Table);
61
- else {
62
- HadLocalError = true ;
63
+ if (!Table.has_value ()) {
64
+ HadError = true ;
63
65
// We are within a DescriptorTable, we will do our best to recover
64
66
// by skipping until we encounter the expected closing ')'.
65
67
skipUntilClosedParens ();
66
68
consumeNextToken ();
69
+ skipUntilExpectedToken (RootElementKeywords);
70
+ continue ;
67
71
}
72
+ Elements.emplace_back (ElementLoc, *Table);
68
73
} else if (tryConsumeExpectedToken (
69
74
{TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
70
75
SourceLocation ElementLoc = getTokenLocation (CurToken);
71
76
auto Descriptor = parseRootDescriptor ();
72
- if (Descriptor.has_value ())
73
- Elements.emplace_back (ElementLoc, *Descriptor);
74
- else
75
- HadLocalError = true ;
77
+ if (!Descriptor.has_value ()) {
78
+ HadError = true ;
79
+ skipUntilExpectedToken (RootElementKeywords);
80
+ continue ;
81
+ }
82
+ Elements.emplace_back (ElementLoc, *Descriptor);
76
83
} else if (tryConsumeExpectedToken (TokenKind::kw_StaticSampler)) {
77
84
SourceLocation ElementLoc = getTokenLocation (CurToken);
78
85
auto Sampler = parseStaticSampler ();
79
- if (Sampler.has_value ())
80
- Elements.emplace_back (ElementLoc, *Sampler);
81
- else
82
- HadLocalError = true ;
86
+ if (!Sampler.has_value ()) {
87
+ HadError = true ;
88
+ skipUntilExpectedToken (RootElementKeywords);
89
+ continue ;
90
+ }
91
+ Elements.emplace_back (ElementLoc, *Sampler);
83
92
} else {
84
- HadLocalError = true ;
93
+ HadError = true ;
85
94
consumeNextToken (); // let diagnostic be at the start of invalid token
86
95
reportDiag (diag::err_hlsl_invalid_token)
87
96
<< /* parameter=*/ 0 << /* param of*/ TokenKind::kw_RootSignature;
97
+ skipUntilExpectedToken (RootElementKeywords);
98
+ continue ;
88
99
}
89
100
90
- if (HadLocalError) {
91
- HadError = true ;
92
- skipUntilExpectedToken (RootElementKeywords);
93
- } else if (!tryConsumeExpectedToken (TokenKind::pu_comma)) {
101
+ if (!tryConsumeExpectedToken (TokenKind::pu_comma)) {
94
102
// ',' denotes another element, otherwise, expected to be at end of stream
95
103
break ;
96
104
}
0 commit comments