Skip to content

Commit 39e450b

Browse files
committed
nfc, review: update loop logic to remove use of local bool
1 parent f589f36 commit 39e450b

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,59 +38,67 @@ bool RootSignatureParser::parse() {
3838
// end of the stream
3939
bool HadError = false;
4040
while (!peekExpectedToken(TokenKind::end_of_stream)) {
41-
bool HadLocalError = false;
4241
if (tryConsumeExpectedToken(TokenKind::kw_RootFlags)) {
4342
SourceLocation ElementLoc = getTokenLocation(CurToken);
4443
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);
4951
} else if (tryConsumeExpectedToken(TokenKind::kw_RootConstants)) {
5052
SourceLocation ElementLoc = getTokenLocation(CurToken);
5153
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);
5660
} else if (tryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
5761
SourceLocation ElementLoc = getTokenLocation(CurToken);
5862
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;
6365
// We are within a DescriptorTable, we will do our best to recover
6466
// by skipping until we encounter the expected closing ')'.
6567
skipUntilClosedParens();
6668
consumeNextToken();
69+
skipUntilExpectedToken(RootElementKeywords);
70+
continue;
6771
}
72+
Elements.emplace_back(ElementLoc, *Table);
6873
} else if (tryConsumeExpectedToken(
6974
{TokenKind::kw_CBV, TokenKind::kw_SRV, TokenKind::kw_UAV})) {
7075
SourceLocation ElementLoc = getTokenLocation(CurToken);
7176
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);
7683
} else if (tryConsumeExpectedToken(TokenKind::kw_StaticSampler)) {
7784
SourceLocation ElementLoc = getTokenLocation(CurToken);
7885
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);
8392
} else {
84-
HadLocalError = true;
93+
HadError = true;
8594
consumeNextToken(); // let diagnostic be at the start of invalid token
8695
reportDiag(diag::err_hlsl_invalid_token)
8796
<< /*parameter=*/0 << /*param of*/ TokenKind::kw_RootSignature;
97+
skipUntilExpectedToken(RootElementKeywords);
98+
continue;
8899
}
89100

90-
if (HadLocalError) {
91-
HadError = true;
92-
skipUntilExpectedToken(RootElementKeywords);
93-
} else if (!tryConsumeExpectedToken(TokenKind::pu_comma)) {
101+
if (!tryConsumeExpectedToken(TokenKind::pu_comma)) {
94102
// ',' denotes another element, otherwise, expected to be at end of stream
95103
break;
96104
}

0 commit comments

Comments
 (0)