Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion clang/lib/Lex/LexHLSLRootSignature.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//=== LexHLSLRootSignature.cpp - Lex Root Signature -----------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "clang/Lex/LexHLSLRootSignature.h"

namespace clang {
Expand Down Expand Up @@ -87,7 +95,7 @@ RootSignatureToken RootSignatureLexer::LexToken() {

// Define a large string switch statement for all the keywords and enums
auto Switch = llvm::StringSwitch<TokenKind>(TokSpelling);
#define KEYWORD(NAME) Switch.Case(#NAME, TokenKind::kw_##NAME);
#define KEYWORD(NAME) Switch.CaseLower(#NAME, TokenKind::kw_##NAME);
#define ENUM(NAME, LIT) Switch.CaseLower(LIT, TokenKind::en_##NAME);
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"

Expand Down
30 changes: 30 additions & 0 deletions clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,36 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
CheckTokens(Lexer, Tokens, Expected);
}

TEST_F(LexHLSLRootSignatureTest, ValidCaseInsensitiveKeywordsTest) {
// This test will check that we can lex keywords in an case-insensitive
// manner
const llvm::StringLiteral Source = R"cc(
DeScRiPtOrTaBlE

CBV srv UAV sampler
SPACE visibility FLAGS
numDescriptors OFFSET
)cc";
auto TokLoc = SourceLocation();
hlsl::RootSignatureLexer Lexer(Source, TokLoc);

SmallVector<hlsl::RootSignatureToken> Tokens;
SmallVector<hlsl::TokenKind> Expected = {
hlsl::TokenKind::kw_DescriptorTable,
hlsl::TokenKind::kw_CBV,
hlsl::TokenKind::kw_SRV,
hlsl::TokenKind::kw_UAV,
hlsl::TokenKind::kw_Sampler,
hlsl::TokenKind::kw_space,
hlsl::TokenKind::kw_visibility,
hlsl::TokenKind::kw_flags,
hlsl::TokenKind::kw_numDescriptors,
hlsl::TokenKind::kw_offset,
};

CheckTokens(Lexer, Tokens, Expected);
}

TEST_F(LexHLSLRootSignatureTest, ValidLexPeekTest) {
// This test will check that we the peek api is correctly used
const llvm::StringLiteral Source = R"cc(
Expand Down