Skip to content

Commit dece8af

Browse files
committed
nfc: instantiate Lexer in Parser constructor
- the StringLiteral between the Lexer and Parser is now inherently coupled together and this constructor will enforce such
1 parent 9351946 commit dece8af

File tree

4 files changed

+33
-62
lines changed

4 files changed

+33
-62
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ class RootSignatureParser {
3030
public:
3131
RootSignatureParser(llvm::dxbc::RootSignatureVersion Version,
3232
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements,
33-
RootSignatureLexer &Lexer, StringLiteral *Signature,
34-
Preprocessor &PP);
33+
StringLiteral *Signature, Preprocessor &PP);
3534

3635
/// Consumes tokens from the Lexer and constructs the in-memory
3736
/// representations of the RootElements. Tokens are consumed until an
@@ -198,9 +197,8 @@ class RootSignatureParser {
198197
private:
199198
llvm::dxbc::RootSignatureVersion Version;
200199
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements;
201-
RootSignatureLexer &Lexer;
202-
203200
clang::StringLiteral *Signature;
201+
RootSignatureLexer Lexer;
204202
clang::Preprocessor &PP;
205203

206204
RootSignatureToken CurToken;

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,10 +4951,9 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49514951
// signature string and construct the in-memory elements
49524952
if (!Found) {
49534953
// Invoke the root signature parser to construct the in-memory constructs
4954-
hlsl::RootSignatureLexer Lexer(Signature->getString());
49554954
SmallVector<llvm::hlsl::rootsig::RootElement> RootElements;
49564955
hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements,
4957-
Lexer, Signature, PP);
4956+
Signature, PP);
49584957
if (Parser.parse()) {
49594958
T.consumeClose();
49604959
return;

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ using TokenKind = RootSignatureToken::Kind;
1919

2020
RootSignatureParser::RootSignatureParser(
2121
llvm::dxbc::RootSignatureVersion Version,
22-
SmallVector<RootElement> &Elements, RootSignatureLexer &Lexer,
23-
StringLiteral *Signature, Preprocessor &PP)
24-
: Version(Version), Elements(Elements), Signature(Signature), Lexer(Lexer),
25-
PP(PP), CurToken(0) {}
22+
SmallVector<RootElement> &Elements, StringLiteral *Signature,
23+
Preprocessor &PP)
24+
: Version(Version), Elements(Elements), Signature(Signature),
25+
Lexer(Signature->getString()), PP(PP), CurToken(0) {}
2626

2727
bool RootSignatureParser::parse() {
2828
// Iterate as many RootElements as possible

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 26 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
135135
TrivialModuleLoader ModLoader;
136136
auto PP = createPP(Source, ModLoader);
137137

138-
hlsl::RootSignatureLexer Lexer(Source);
139138
SmallVector<RootElement> Elements;
140-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
139+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
141140
Signature, *PP);
142141

143142
// Test no diagnostics produced
@@ -172,9 +171,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
172171
TrivialModuleLoader ModLoader;
173172
auto PP = createPP(Source, ModLoader);
174173

175-
hlsl::RootSignatureLexer Lexer(Source);
176174
SmallVector<RootElement> Elements;
177-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
175+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
178176
Signature, *PP);
179177

180178
// Test no diagnostics produced
@@ -278,9 +276,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
278276
TrivialModuleLoader ModLoader;
279277
auto PP = createPP(Source, ModLoader);
280278

281-
hlsl::RootSignatureLexer Lexer(Source);
282279
SmallVector<RootElement> Elements;
283-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
280+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
284281
Signature, *PP);
285282

286283
// Test no diagnostics produced
@@ -366,9 +363,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
366363
TrivialModuleLoader ModLoader;
367364
auto PP = createPP(Source, ModLoader);
368365

369-
hlsl::RootSignatureLexer Lexer(Source);
370366
SmallVector<RootElement> Elements;
371-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
367+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
372368
Signature, *PP);
373369

374370
// Test no diagnostics produced
@@ -444,9 +440,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
444440
TrivialModuleLoader ModLoader;
445441
auto PP = createPP(Source, ModLoader);
446442

447-
hlsl::RootSignatureLexer Lexer(Source);
448443
SmallVector<RootElement> Elements;
449-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
444+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
450445
Signature, *PP);
451446

452447
// Test no diagnostics produced
@@ -478,9 +473,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
478473
TrivialModuleLoader ModLoader;
479474
auto PP = createPP(Source, ModLoader);
480475

481-
hlsl::RootSignatureLexer Lexer(Source);
482476
SmallVector<RootElement> Elements;
483-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
477+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
484478
Signature, *PP);
485479

486480
// Test no diagnostics produced
@@ -538,9 +532,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
538532
TrivialModuleLoader ModLoader;
539533
auto PP = createPP(Source, ModLoader);
540534

541-
hlsl::RootSignatureLexer Lexer(Source);
542535
SmallVector<RootElement> Elements;
543-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
536+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
544537
Signature, *PP);
545538

546539
// Test no diagnostics produced
@@ -594,9 +587,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
594587
TrivialModuleLoader ModLoader;
595588
auto PP = createPP(Source, ModLoader);
596589

597-
hlsl::RootSignatureLexer Lexer(Source);
598590
SmallVector<RootElement> Elements;
599-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
591+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
600592
Signature, *PP);
601593

602594
// Test no diagnostics produced
@@ -671,9 +663,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
671663
TrivialModuleLoader ModLoader;
672664
auto PP = createPP(Source, ModLoader);
673665

674-
hlsl::RootSignatureLexer Lexer(Source);
675666
SmallVector<RootElement> Elements;
676-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
667+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
677668
Signature, *PP);
678669

679670
// Test no diagnostics produced
@@ -844,9 +835,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
844835
TrivialModuleLoader ModLoader;
845836
auto PP = createPP(Source, ModLoader);
846837

847-
hlsl::RootSignatureLexer Lexer(Source);
848838
SmallVector<RootElement> Elements;
849-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
839+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
850840
Signature, *PP);
851841

852842
// Test correct diagnostic produced
@@ -867,9 +857,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
867857
TrivialModuleLoader ModLoader;
868858
auto PP = createPP(Source, ModLoader);
869859

870-
hlsl::RootSignatureLexer Lexer(Source);
871860
SmallVector<RootElement> Elements;
872-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
861+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
873862
Signature, *PP);
874863

875864
// Test correct diagnostic produced - invalid token
@@ -890,9 +879,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
890879
TrivialModuleLoader ModLoader;
891880
auto PP = createPP(Source, ModLoader);
892881

893-
hlsl::RootSignatureLexer Lexer(Source);
894882
SmallVector<RootElement> Elements;
895-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
883+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
896884
Signature, *PP);
897885

898886
// Test correct diagnostic produced - end of stream
@@ -918,9 +906,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
918906
TrivialModuleLoader ModLoader;
919907
auto PP = createPP(Source, ModLoader);
920908

921-
hlsl::RootSignatureLexer Lexer(Source);
922909
SmallVector<RootElement> Elements;
923-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
910+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
924911
Signature, *PP);
925912

926913
// Test correct diagnostic produced
@@ -943,9 +930,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
943930
TrivialModuleLoader ModLoader;
944931
auto PP = createPP(Source, ModLoader);
945932

946-
hlsl::RootSignatureLexer Lexer(Source);
947933
SmallVector<RootElement> Elements;
948-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
934+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
949935
Signature, *PP);
950936

951937
// Test correct diagnostic produced
@@ -968,9 +954,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
968954
TrivialModuleLoader ModLoader;
969955
auto PP = createPP(Source, ModLoader);
970956

971-
hlsl::RootSignatureLexer Lexer(Source);
972957
SmallVector<RootElement> Elements;
973-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
958+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
974959
Signature, *PP);
975960

976961
// Test correct diagnostic produced
@@ -995,9 +980,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
995980
TrivialModuleLoader ModLoader;
996981
auto PP = createPP(Source, ModLoader);
997982

998-
hlsl::RootSignatureLexer Lexer(Source);
999983
SmallVector<RootElement> Elements;
1000-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
984+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
1001985
Signature, *PP);
1002986

1003987
// Test correct diagnostic produced
@@ -1020,9 +1004,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
10201004
TrivialModuleLoader ModLoader;
10211005
auto PP = createPP(Source, ModLoader);
10221006

1023-
hlsl::RootSignatureLexer Lexer(Source);
10241007
SmallVector<RootElement> Elements;
1025-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1008+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
10261009
Signature, *PP);
10271010

10281011
// Test correct diagnostic produced
@@ -1047,9 +1030,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
10471030
TrivialModuleLoader ModLoader;
10481031
auto PP = createPP(Source, ModLoader);
10491032

1050-
hlsl::RootSignatureLexer Lexer(Source);
10511033
SmallVector<RootElement> Elements;
1052-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1034+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
10531035
Signature, *PP);
10541036

10551037
// Test correct diagnostic produced
@@ -1076,9 +1058,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
10761058
TrivialModuleLoader ModLoader;
10771059
auto PP = createPP(Source, ModLoader);
10781060

1079-
hlsl::RootSignatureLexer Lexer(Source);
10801061
SmallVector<RootElement> Elements;
1081-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1062+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
10821063
Signature, *PP);
10831064

10841065
// Test correct diagnostic produced
@@ -1102,9 +1083,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
11021083
TrivialModuleLoader ModLoader;
11031084
auto PP = createPP(Source, ModLoader);
11041085

1105-
hlsl::RootSignatureLexer Lexer(Source);
11061086
SmallVector<RootElement> Elements;
1107-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1087+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
11081088
Signature, *PP);
11091089

11101090
// Test correct diagnostic produced
@@ -1127,9 +1107,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
11271107
TrivialModuleLoader ModLoader;
11281108
auto PP = createPP(Source, ModLoader);
11291109

1130-
hlsl::RootSignatureLexer Lexer(Source);
11311110
SmallVector<RootElement> Elements;
1132-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1111+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
11331112
Signature, *PP);
11341113

11351114
// Test correct diagnostic produced
@@ -1151,9 +1130,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
11511130
TrivialModuleLoader ModLoader;
11521131
auto PP = createPP(Source, ModLoader);
11531132

1154-
hlsl::RootSignatureLexer Lexer(Source);
11551133
SmallVector<RootElement> Elements;
1156-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1134+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
11571135
Signature, *PP);
11581136

11591137
// Test correct diagnostic produced
@@ -1175,9 +1153,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
11751153
TrivialModuleLoader ModLoader;
11761154
auto PP = createPP(Source, ModLoader);
11771155

1178-
hlsl::RootSignatureLexer Lexer(Source);
11791156
SmallVector<RootElement> Elements;
1180-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1157+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
11811158
Signature, *PP);
11821159

11831160
// Test correct diagnostic produced
@@ -1199,9 +1176,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
11991176
TrivialModuleLoader ModLoader;
12001177
auto PP = createPP(Source, ModLoader);
12011178

1202-
hlsl::RootSignatureLexer Lexer(Source);
12031179
SmallVector<RootElement> Elements;
1204-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1180+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
12051181
Signature, *PP);
12061182

12071183
// Test correct diagnostic produced
@@ -1223,9 +1199,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
12231199
TrivialModuleLoader ModLoader;
12241200
auto PP = createPP(Source, ModLoader);
12251201

1226-
hlsl::RootSignatureLexer Lexer(Source);
12271202
SmallVector<RootElement> Elements;
1228-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1203+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
12291204
Signature, *PP);
12301205

12311206
// Test correct diagnostic produced
@@ -1250,9 +1225,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
12501225
TrivialModuleLoader ModLoader;
12511226
auto PP = createPP(Source, ModLoader);
12521227

1253-
hlsl::RootSignatureLexer Lexer(Source);
12541228
SmallVector<RootElement> Elements;
1255-
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1229+
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements,
12561230
Signature, *PP);
12571231

12581232
// Test correct diagnostic produced

0 commit comments

Comments
 (0)