Skip to content

Commit 2eeda54

Browse files
author
Finn Plummer
committed
self-review: improve error messaging for expected end of parameters
1 parent 262eeed commit 2eeda54

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,4 +1830,8 @@ def err_hlsl_virtual_function
18301830
def err_hlsl_virtual_inheritance
18311831
: Error<"virtual inheritance is unsupported in HLSL">;
18321832

1833+
// HLSL Root Siganture diagnostic messages
1834+
def err_hlsl_unexpected_end_of_params
1835+
: Error<"expected %0 to denote end of parameters, or, another valid parameter of %1">;
1836+
18331837
} // end of Parser diagnostics

clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ PUNCTUATOR(plus, '+')
6969
PUNCTUATOR(minus, '-')
7070

7171
// RootElement Keywords:
72+
KEYWORD(RootSignature) // used only for diagnostic messaging
7273
KEYWORD(DescriptorTable)
7374

7475
// DescriptorTable Keywords:

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ bool RootSignatureParser::parse() {
3939
break;
4040
}
4141

42-
return consumeExpectedToken(TokenKind::end_of_stream, diag::err_expected);
42+
if (!tryConsumeExpectedToken(TokenKind::end_of_stream)) {
43+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_unexpected_end_of_params)
44+
<< /*expected=*/TokenKind::end_of_stream
45+
<< /*param of=*/TokenKind::kw_RootSignature;
46+
return true;
47+
}
48+
return false;
4349
}
4450

4551
bool RootSignatureParser::parseDescriptorTable() {
@@ -64,9 +70,12 @@ bool RootSignatureParser::parseDescriptorTable() {
6470
break;
6571
}
6672

67-
if (consumeExpectedToken(TokenKind::pu_r_paren, diag::err_expected_after,
68-
CurToken.Kind))
73+
if (!tryConsumeExpectedToken(TokenKind::pu_r_paren)) {
74+
getDiags().Report(CurToken.TokLoc, diag::err_hlsl_unexpected_end_of_params)
75+
<< /*expected=*/TokenKind::pu_r_paren
76+
<< /*param of=*/TokenKind::kw_DescriptorTable;
6977
return true;
78+
}
7079

7180
Elements.push_back(Table);
7281
return false;

clang/unittests/Lex/LexHLSLRootSignatureTest.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
8585
8686
(),|=+-
8787
88+
RootSignature
89+
8890
DescriptorTable
8991
9092
CBV SRV UAV Sampler

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
196196
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
197197

198198
// Test correct diagnostic produced
199-
Consumer->setExpected(diag::err_expected);
199+
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
200200
ASSERT_TRUE(Parser.parse());
201201

202202
ASSERT_TRUE(Consumer->isSatisfied());
@@ -216,7 +216,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
216216
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
217217

218218
// Test correct diagnostic produced - invalid token
219-
Consumer->setExpected(diag::err_expected);
219+
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
220220
ASSERT_TRUE(Parser.parse());
221221

222222
ASSERT_TRUE(Consumer->isSatisfied());

0 commit comments

Comments
 (0)