Skip to content

Commit 0c372bf

Browse files
committed
review: remove unique end_of_stream lexing error
- instead of reporting the unique end_of_stream error, we can instead pass up an end_of_stream token and let the unexpected diag reporting handles this in the parser with more context
1 parent 8ac979c commit 0c372bf

File tree

3 files changed

+10
-28
lines changed

3 files changed

+10
-28
lines changed

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,6 @@ let CategoryName = "Root Signature Lexical Issue" in {
10251025
Error<"integer literal '%0' is too large to be represented in a 32-bit integer type">;
10261026
def err_hlsl_invalid_token: Error<"unable to lex a valid Root Signature token">;
10271027
def err_hlsl_invalid_register_literal: Error<"expected unsigned integer literal as part of register">;
1028-
def err_hlsl_rootsig_unexpected_eos : Error<"unexpected end to token stream">;
10291028
}
10301029

10311030
}

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,8 @@ bool RootSignatureLexer::ConsumeToken() {
164164

165165
// This will be implicity be true if NextToken->Kind == end_of_stream
166166
if (EndOfBuffer()) {
167-
// Report unexpected end of tokens error
168-
PP.getDiagnostics().Report(SourceLoc,
169-
diag::err_hlsl_rootsig_unexpected_eos);
170-
return true;
167+
CurToken = RootSignatureToken(TokenKind::end_of_stream, SourceLoc);
168+
return false;
171169
}
172170

173171
return LexToken(CurToken);
@@ -178,14 +176,11 @@ std::optional<RootSignatureToken> RootSignatureLexer::PeekNextToken() {
178176
if (NextToken.has_value())
179177
return NextToken;
180178

181-
if (EndOfBuffer()) {
182-
// We have reached the end of the stream, but only error on consume
183-
return RootSignatureToken(TokenKind::end_of_stream, SourceLoc);
184-
}
185-
186179
RootSignatureToken Result;
187-
if (LexToken(Result))
188-
return std::nullopt;
180+
if (EndOfBuffer()) {
181+
Result = RootSignatureToken(TokenKind::end_of_stream, SourceLoc);
182+
} else if (LexToken(Result))
183+
return std::nullopt; // propogate lex error up
189184
NextToken = Result;
190185
return Result;
191186
}

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -258,27 +258,15 @@ TEST_F(ParseHLSLRootSignatureTest, ValidLexPeekTest) {
258258
ASSERT_TRUE(Res.has_value());
259259
ASSERT_EQ(Res->Kind, hlsl::TokenKind::end_of_stream);
260260

261+
// Ensure no error raised when consuming past end of stream
262+
ASSERT_FALSE(Lexer.ConsumeToken());
263+
ASSERT_EQ(Lexer.GetCurToken().Kind, hlsl::TokenKind::end_of_stream);
264+
261265
ASSERT_TRUE(Consumer->IsSatisfied());
262266
}
263267

264268
// Invalid Lexing Tests
265269

266-
TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEOSTest) {
267-
const llvm::StringLiteral Source = R"cc()cc";
268-
269-
TrivialModuleLoader ModLoader;
270-
auto PP = CreatePP(Source, ModLoader);
271-
auto TokLoc = SourceLocation();
272-
273-
hlsl::RootSignatureLexer Lexer(Source, TokLoc, *PP);
274-
275-
// Test correct diagnostic produced
276-
Consumer->SetExpected(diag::err_hlsl_rootsig_unexpected_eos);
277-
ASSERT_TRUE(Lexer.ConsumeToken());
278-
279-
ASSERT_TRUE(Consumer->IsSatisfied());
280-
}
281-
282270
TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
283271
// This test will check that the lexing fails due to an integer overflow
284272
const llvm::StringLiteral Source = R"cc(

0 commit comments

Comments
 (0)