Skip to content

Commit e58c89a

Browse files
committed
review: remove unique invalid_token lexing error
- similarily, we can let the unexpected_token diagnostics reporting handle this error by passing up an invalid token and provide more context
1 parent 0c372bf commit e58c89a

File tree

3 files changed

+3
-29
lines changed

3 files changed

+3
-29
lines changed

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,6 @@ let CategoryName = "Root Signature Lexical Issue" in {
10231023
def err_hlsl_expected_number_literal: Error<"expected numberic literal">;
10241024
def err_hlsl_number_literal_overflow :
10251025
Error<"integer literal '%0' is too large to be represented in a 32-bit integer type">;
1026-
def err_hlsl_invalid_token: Error<"unable to lex a valid Root Signature token">;
10271026
def err_hlsl_invalid_register_literal: Error<"expected unsigned integer literal as part of register">;
10281027
}
10291028

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
8888

8989
// All following tokens require at least one additional character
9090
if (Buffer.size() <= 1) {
91-
PP.getDiagnostics().Report(Result.TokLoc, diag::err_hlsl_invalid_token);
92-
return true;
91+
Result = RootSignatureToken(SourceLoc);
92+
return false;
9393
}
9494

9595
// Peek at the next character to deteremine token type
@@ -143,13 +143,7 @@ bool RootSignatureLexer::LexToken(RootSignatureToken &Result) {
143143
#include "clang/Parse/HLSLRootSignatureTokenKinds.def"
144144

145145
// Then attempt to retreive a string from it
146-
auto Kind = Switch.Default(TokenKind::invalid);
147-
if (Kind == TokenKind::invalid) {
148-
PP.getDiagnostics().Report(Result.TokLoc, diag::err_hlsl_invalid_token);
149-
return true;
150-
}
151-
152-
Result.Kind = Kind;
146+
Result.Kind = Switch.Default(TokenKind::invalid);
153147
AdvanceBuffer(TokSpelling.size());
154148
return false;
155149
}

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,4 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexRegNumberTest) {
325325
ASSERT_FALSE(Consumer->IsSatisfied());
326326
}
327327

328-
TEST_F(ParseHLSLRootSignatureTest, InvalidLexIdentifierTest) {
329-
// This test will check that the lexing fails due to no valid token
330-
const llvm::StringLiteral Source = R"cc(
331-
notAToken
332-
)cc";
333-
334-
TrivialModuleLoader ModLoader;
335-
auto PP = CreatePP(Source, ModLoader);
336-
auto TokLoc = SourceLocation();
337-
338-
// Test correct diagnostic produced
339-
Consumer->SetExpected(diag::err_hlsl_invalid_token);
340-
341-
hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
342-
343-
ASSERT_TRUE(Lexer.ConsumeToken());
344-
ASSERT_TRUE(Consumer->IsSatisfied());
345-
}
346-
347328
} // anonymous namespace

0 commit comments

Comments
 (0)