Skip to content

Commit 25152be

Browse files
committed
nfc: provide reportDiag helper and simplify diagnostics
1 parent b49cfb8 commit 25152be

File tree

5 files changed

+70
-162
lines changed

5 files changed

+70
-162
lines changed

clang/include/clang/Basic/DiagnosticParseKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,8 +1857,6 @@ def err_hlsl_virtual_inheritance
18571857
: Error<"virtual inheritance is unsupported in HLSL">;
18581858

18591859
// HLSL Root Signature Parser Diagnostics
1860-
def err_hlsl_unexpected_end_of_params
1861-
: Error<"expected %0 to denote end of parameters, or, another valid parameter of %1">;
18621860
def err_hlsl_rootsig_repeat_param : Error<"specified the same parameter '%0' multiple times">;
18631861
def err_hlsl_rootsig_missing_param : Error<"did not specify mandatory parameter '%0'">;
18641862
def err_hlsl_number_literal_overflow : Error<

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ class RootSignatureParser {
178178
///
179179
/// Returns true if there was an error reported.
180180
bool consumeExpectedToken(
181-
RootSignatureToken::Kind Expected, unsigned DiagID = diag::err_expected,
182-
RootSignatureToken::Kind Context = RootSignatureToken::Kind::invalid);
181+
RootSignatureToken::Kind Expected,
182+
std::optional<RootSignatureToken::Kind> Context = std::nullopt);
183183

184184
/// Peek if the next token is of the expected kind and if it is then consume
185185
/// it.
@@ -195,6 +195,13 @@ class RootSignatureParser {
195195
/// StringLiterals
196196
SourceLocation getTokenLocation(RootSignatureToken Tok);
197197

198+
DiagnosticBuilder
199+
reportDiag(unsigned DiagID,
200+
std::optional<RootSignatureToken> Context = std::nullopt) {
201+
RootSignatureToken Tok = Context.has_value() ? *Context : CurToken;
202+
return getDiags().Report(getTokenLocation(Tok), DiagID);
203+
}
204+
198205
private:
199206
llvm::dxbc::RootSignatureVersion Version;
200207
SmallVector<RootSignatureElement> &Elements;

0 commit comments

Comments
 (0)