Skip to content

Commit 428fc2c

Browse files
inbelicFinn Plummer
and
Finn Plummer
authored
[NFC][HLSL][RootSignature] Make the Lexer adhere to naming conventions (#134136)
- when developing the RootSignatureLexer library, we are creating new files so we should set the standard to adhere to the coding conventions for function naming - this was missed in the initial review but caught in the review of the parser pr [here](#133302 (comment)) Co-authored-by: Finn Plummer <[email protected]>
1 parent bbaf087 commit 428fc2c

File tree

5 files changed

+36
-36
lines changed

5 files changed

+36
-36
lines changed

clang/include/clang/Lex/LexHLSLRootSignature.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ class RootSignatureLexer {
6161
: Buffer(Signature), SourceLoc(SourceLoc) {}
6262

6363
/// Consumes and returns the next token.
64-
RootSignatureToken ConsumeToken();
64+
RootSignatureToken consumeToken();
6565

6666
/// Returns the token that proceeds CurToken
67-
RootSignatureToken PeekNextToken();
67+
RootSignatureToken peekNextToken();
6868

69-
bool EndOfBuffer() {
70-
AdvanceBuffer(Buffer.take_while(isspace).size());
69+
bool isEndOfBuffer() {
70+
advanceBuffer(Buffer.take_while(isspace).size());
7171
return Buffer.empty();
7272
}
7373

@@ -82,11 +82,11 @@ class RootSignatureLexer {
8282
clang::SourceLocation SourceLoc;
8383

8484
/// Consumes the buffer and returns the lexed token.
85-
RootSignatureToken LexToken();
85+
RootSignatureToken lexToken();
8686

8787
/// Advance the buffer by the specified number of characters.
8888
/// Updates the SourceLocation appropriately.
89-
void AdvanceBuffer(unsigned NumCharacters = 1) {
89+
void advanceBuffer(unsigned NumCharacters = 1) {
9090
Buffer = Buffer.drop_front(NumCharacters);
9191
SourceLoc = SourceLoc.getLocWithOffset(NumCharacters);
9292
}

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class RootSignatureParser {
7070
bool parseDescriptorTableClause();
7171

7272
/// Invoke the Lexer to consume a token and update CurToken with the result
73-
void consumeNextToken() { CurToken = Lexer.ConsumeToken(); }
73+
void consumeNextToken() { CurToken = Lexer.consumeToken(); }
7474

7575
/// Return true if the next token one of the expected kinds
7676
bool peekExpectedToken(RootSignatureToken::Kind Expected);

clang/lib/Lex/LexHLSLRootSignature.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ using TokenKind = RootSignatureToken::Kind;
1515

1616
// Lexer Definitions
1717

18-
static bool IsNumberChar(char C) {
18+
static bool isNumberChar(char C) {
1919
// TODO(#126565): extend for float support exponents
2020
return isdigit(C); // integer support
2121
}
2222

23-
RootSignatureToken RootSignatureLexer::LexToken() {
23+
RootSignatureToken RootSignatureLexer::lexToken() {
2424
// Discard any leading whitespace
25-
AdvanceBuffer(Buffer.take_while(isspace).size());
25+
advanceBuffer(Buffer.take_while(isspace).size());
2626

27-
if (EndOfBuffer())
27+
if (isEndOfBuffer())
2828
return RootSignatureToken(TokenKind::end_of_stream, SourceLoc);
2929

3030
// Record where this token is in the text for usage in parser diagnostics
@@ -37,7 +37,7 @@ RootSignatureToken RootSignatureLexer::LexToken() {
3737
#define PUNCTUATOR(X, Y) \
3838
case Y: { \
3939
Result.TokKind = TokenKind::pu_##X; \
40-
AdvanceBuffer(); \
40+
advanceBuffer(); \
4141
return Result; \
4242
}
4343
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
@@ -48,8 +48,8 @@ RootSignatureToken RootSignatureLexer::LexToken() {
4848
// Integer literal
4949
if (isdigit(C)) {
5050
Result.TokKind = TokenKind::int_literal;
51-
Result.NumSpelling = Buffer.take_while(IsNumberChar);
52-
AdvanceBuffer(Result.NumSpelling.size());
51+
Result.NumSpelling = Buffer.take_while(isNumberChar);
52+
advanceBuffer(Result.NumSpelling.size());
5353
return Result;
5454
}
5555

@@ -82,11 +82,11 @@ RootSignatureToken RootSignatureLexer::LexToken() {
8282
llvm_unreachable("Switch for an expected token was not provided");
8383
}
8484

85-
AdvanceBuffer();
85+
advanceBuffer();
8686

8787
// Lex the integer literal
88-
Result.NumSpelling = Buffer.take_while(IsNumberChar);
89-
AdvanceBuffer(Result.NumSpelling.size());
88+
Result.NumSpelling = Buffer.take_while(isNumberChar);
89+
advanceBuffer(Result.NumSpelling.size());
9090

9191
return Result;
9292
}
@@ -103,26 +103,26 @@ RootSignatureToken RootSignatureLexer::LexToken() {
103103

104104
// Then attempt to retreive a string from it
105105
Result.TokKind = Switch.Default(TokenKind::invalid);
106-
AdvanceBuffer(TokSpelling.size());
106+
advanceBuffer(TokSpelling.size());
107107
return Result;
108108
}
109109

110-
RootSignatureToken RootSignatureLexer::ConsumeToken() {
110+
RootSignatureToken RootSignatureLexer::consumeToken() {
111111
// If we previously peeked then just return the previous value over
112112
if (NextToken && NextToken->TokKind != TokenKind::end_of_stream) {
113113
RootSignatureToken Result = *NextToken;
114114
NextToken = std::nullopt;
115115
return Result;
116116
}
117-
return LexToken();
117+
return lexToken();
118118
}
119119

120-
RootSignatureToken RootSignatureLexer::PeekNextToken() {
120+
RootSignatureToken RootSignatureLexer::peekNextToken() {
121121
// Already peeked from the current token
122122
if (NextToken)
123123
return *NextToken;
124124

125-
NextToken = LexToken();
125+
NextToken = lexToken();
126126
return *NextToken;
127127
}
128128

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ bool RootSignatureParser::peekExpectedToken(TokenKind Expected) {
125125
}
126126

127127
bool RootSignatureParser::peekExpectedToken(ArrayRef<TokenKind> AnyExpected) {
128-
RootSignatureToken Result = Lexer.PeekNextToken();
128+
RootSignatureToken Result = Lexer.peekNextToken();
129129
return llvm::is_contained(AnyExpected, Result.TokKind);
130130
}
131131

clang/unittests/Lex/LexHLSLRootSignatureTest.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ class LexHLSLRootSignatureTest : public ::testing::Test {
1919
protected:
2020
LexHLSLRootSignatureTest() {}
2121

22-
void CheckTokens(hlsl::RootSignatureLexer &Lexer,
22+
void checkTokens(hlsl::RootSignatureLexer &Lexer,
2323
SmallVector<hlsl::RootSignatureToken> &Computed,
2424
SmallVector<TokenKind> &Expected) {
2525
for (unsigned I = 0, E = Expected.size(); I != E; ++I) {
2626
// Skip these to help with the macro generated test
2727
if (Expected[I] == TokenKind::invalid ||
2828
Expected[I] == TokenKind::end_of_stream)
2929
continue;
30-
hlsl::RootSignatureToken Result = Lexer.ConsumeToken();
30+
hlsl::RootSignatureToken Result = Lexer.consumeToken();
3131
ASSERT_EQ(Result.TokKind, Expected[I]);
3232
Computed.push_back(Result);
3333
}
34-
hlsl::RootSignatureToken EndOfStream = Lexer.ConsumeToken();
34+
hlsl::RootSignatureToken EndOfStream = Lexer.consumeToken();
3535
ASSERT_EQ(EndOfStream.TokKind, TokenKind::end_of_stream);
36-
ASSERT_TRUE(Lexer.EndOfBuffer());
36+
ASSERT_TRUE(Lexer.isEndOfBuffer());
3737
}
3838
};
3939

@@ -55,7 +55,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexNumbersTest) {
5555
TokenKind::pu_plus, TokenKind::int_literal, TokenKind::pu_plus,
5656
TokenKind::int_literal,
5757
};
58-
CheckTokens(Lexer, Tokens, Expected);
58+
checkTokens(Lexer, Tokens, Expected);
5959

6060
// Sample negative: int component
6161
hlsl::RootSignatureToken IntToken = Tokens[1];
@@ -119,7 +119,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
119119
#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
120120
};
121121

122-
CheckTokens(Lexer, Tokens, Expected);
122+
checkTokens(Lexer, Tokens, Expected);
123123
}
124124

125125
TEST_F(LexHLSLRootSignatureTest, ValidCaseInsensitiveKeywordsTest) {
@@ -149,7 +149,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidCaseInsensitiveKeywordsTest) {
149149
TokenKind::kw_offset,
150150
};
151151

152-
CheckTokens(Lexer, Tokens, Expected);
152+
checkTokens(Lexer, Tokens, Expected);
153153
}
154154

155155
TEST_F(LexHLSLRootSignatureTest, ValidLexPeekTest) {
@@ -161,26 +161,26 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexPeekTest) {
161161
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
162162

163163
// Test basic peek
164-
hlsl::RootSignatureToken Res = Lexer.PeekNextToken();
164+
hlsl::RootSignatureToken Res = Lexer.peekNextToken();
165165
ASSERT_EQ(Res.TokKind, TokenKind::pu_r_paren);
166166

167167
// Ensure it doesn't peek past one element
168-
Res = Lexer.PeekNextToken();
168+
Res = Lexer.peekNextToken();
169169
ASSERT_EQ(Res.TokKind, TokenKind::pu_r_paren);
170170

171-
Res = Lexer.ConsumeToken();
171+
Res = Lexer.consumeToken();
172172
ASSERT_EQ(Res.TokKind, TokenKind::pu_r_paren);
173173

174174
// Invoke after reseting the NextToken
175-
Res = Lexer.PeekNextToken();
175+
Res = Lexer.peekNextToken();
176176
ASSERT_EQ(Res.TokKind, TokenKind::int_literal);
177177

178178
// Ensure we can still consume the second token
179-
Res = Lexer.ConsumeToken();
179+
Res = Lexer.consumeToken();
180180
ASSERT_EQ(Res.TokKind, TokenKind::int_literal);
181181

182182
// Ensure end of stream token
183-
Res = Lexer.PeekNextToken();
183+
Res = Lexer.peekNextToken();
184184
ASSERT_EQ(Res.TokKind, TokenKind::end_of_stream);
185185
}
186186

0 commit comments

Comments
 (0)