Skip to content

Commit ddaded2

Browse files
committed
nfc: instaniate the Lexer for the Parser
- the StringLiteral between the Lexer and Parser is now inherently coupled together and this constructor will enforce such
1 parent 1678a07 commit ddaded2

File tree

4 files changed

+31
-60
lines changed

4 files changed

+31
-60
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ namespace hlsl {
2929
class RootSignatureParser {
3030
public:
3131
RootSignatureParser(SmallVector<llvm::hlsl::rootsig::RootElement> &Elements,
32-
RootSignatureLexer &Lexer, StringLiteral *Signature,
33-
Preprocessor &PP);
32+
StringLiteral *Signature, Preprocessor &PP);
3433

3534
/// Consumes tokens from the Lexer and constructs the in-memory
3635
/// representations of the RootElements. Tokens are consumed until an
@@ -196,7 +195,7 @@ class RootSignatureParser {
196195

197196
private:
198197
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements;
199-
RootSignatureLexer &Lexer;
198+
RootSignatureLexer Lexer;
200199

201200
clang::StringLiteral *Signature;
202201
clang::Preprocessor &PP;

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4951,9 +4951,8 @@ 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;
4956-
hlsl::RootSignatureParser Parser(RootElements, Lexer, Signature, PP);
4955+
hlsl::RootSignatureParser Parser(RootElements, Signature, PP);
49574956
if (Parser.parse()) {
49584957
T.consumeClose();
49594958
return;

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ namespace hlsl {
1818
using TokenKind = RootSignatureToken::Kind;
1919

2020
RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
21-
RootSignatureLexer &Lexer,
2221
StringLiteral *Signature,
2322
Preprocessor &PP)
24-
: Elements(Elements), Lexer(Lexer), Signature(Signature), PP(PP),
25-
CurToken(0) {}
23+
: Elements(Elements), Lexer(Signature->getString()), Signature(Signature),
24+
PP(PP), CurToken(0) {}
2625

2726
bool RootSignatureParser::parse() {
2827
// 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
@@ -133,9 +133,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
133133
TrivialModuleLoader ModLoader;
134134
auto PP = createPP(Source, ModLoader);
135135

136-
hlsl::RootSignatureLexer Lexer(Source);
137136
SmallVector<RootElement> Elements;
138-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
137+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
139138

140139
// Test no diagnostics produced
141140
Consumer->setNoDiag();
@@ -169,9 +168,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
169168
TrivialModuleLoader ModLoader;
170169
auto PP = createPP(Source, ModLoader);
171170

172-
hlsl::RootSignatureLexer Lexer(Source);
173171
SmallVector<RootElement> Elements;
174-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
172+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
175173

176174
// Test no diagnostics produced
177175
Consumer->setNoDiag();
@@ -274,9 +272,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
274272
TrivialModuleLoader ModLoader;
275273
auto PP = createPP(Source, ModLoader);
276274

277-
hlsl::RootSignatureLexer Lexer(Source);
278275
SmallVector<RootElement> Elements;
279-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
276+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
280277

281278
// Test no diagnostics produced
282279
Consumer->setNoDiag();
@@ -361,9 +358,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
361358
TrivialModuleLoader ModLoader;
362359
auto PP = createPP(Source, ModLoader);
363360

364-
hlsl::RootSignatureLexer Lexer(Source);
365361
SmallVector<RootElement> Elements;
366-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
362+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
367363

368364
// Test no diagnostics produced
369365
Consumer->setNoDiag();
@@ -438,9 +434,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
438434
TrivialModuleLoader ModLoader;
439435
auto PP = createPP(Source, ModLoader);
440436

441-
hlsl::RootSignatureLexer Lexer(Source);
442437
SmallVector<RootElement> Elements;
443-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
438+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
444439

445440
// Test no diagnostics produced
446441
Consumer->setNoDiag();
@@ -471,9 +466,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
471466
TrivialModuleLoader ModLoader;
472467
auto PP = createPP(Source, ModLoader);
473468

474-
hlsl::RootSignatureLexer Lexer(Source);
475469
SmallVector<RootElement> Elements;
476-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
470+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
477471

478472
// Test no diagnostics produced
479473
Consumer->setNoDiag();
@@ -530,9 +524,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
530524
TrivialModuleLoader ModLoader;
531525
auto PP = createPP(Source, ModLoader);
532526

533-
hlsl::RootSignatureLexer Lexer(Source);
534527
SmallVector<RootElement> Elements;
535-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
528+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
536529

537530
// Test no diagnostics produced
538531
Consumer->setNoDiag();
@@ -585,9 +578,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
585578
TrivialModuleLoader ModLoader;
586579
auto PP = createPP(Source, ModLoader);
587580

588-
hlsl::RootSignatureLexer Lexer(Source);
589581
SmallVector<RootElement> Elements;
590-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
582+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
591583

592584
// Test no diagnostics produced
593585
Consumer->setNoDiag();
@@ -661,9 +653,8 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
661653
TrivialModuleLoader ModLoader;
662654
auto PP = createPP(Source, ModLoader);
663655

664-
hlsl::RootSignatureLexer Lexer(Source);
665656
SmallVector<RootElement> Elements;
666-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
657+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
667658

668659
// Test no diagnostics produced
669660
Consumer->setNoDiag();
@@ -687,9 +678,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
687678
TrivialModuleLoader ModLoader;
688679
auto PP = createPP(Source, ModLoader);
689680

690-
hlsl::RootSignatureLexer Lexer(Source);
691681
SmallVector<RootElement> Elements;
692-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
682+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
693683

694684
// Test correct diagnostic produced
695685
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
@@ -709,9 +699,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
709699
TrivialModuleLoader ModLoader;
710700
auto PP = createPP(Source, ModLoader);
711701

712-
hlsl::RootSignatureLexer Lexer(Source);
713702
SmallVector<RootElement> Elements;
714-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
703+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
715704

716705
// Test correct diagnostic produced - invalid token
717706
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
@@ -731,9 +720,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
731720
TrivialModuleLoader ModLoader;
732721
auto PP = createPP(Source, ModLoader);
733722

734-
hlsl::RootSignatureLexer Lexer(Source);
735723
SmallVector<RootElement> Elements;
736-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
724+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
737725

738726
// Test correct diagnostic produced - end of stream
739727
Consumer->setExpected(diag::err_expected_after);
@@ -758,9 +746,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
758746
TrivialModuleLoader ModLoader;
759747
auto PP = createPP(Source, ModLoader);
760748

761-
hlsl::RootSignatureLexer Lexer(Source);
762749
SmallVector<RootElement> Elements;
763-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
750+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
764751

765752
// Test correct diagnostic produced
766753
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -782,9 +769,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
782769
TrivialModuleLoader ModLoader;
783770
auto PP = createPP(Source, ModLoader);
784771

785-
hlsl::RootSignatureLexer Lexer(Source);
786772
SmallVector<RootElement> Elements;
787-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
773+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
788774

789775
// Test correct diagnostic produced
790776
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -806,9 +792,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
806792
TrivialModuleLoader ModLoader;
807793
auto PP = createPP(Source, ModLoader);
808794

809-
hlsl::RootSignatureLexer Lexer(Source);
810795
SmallVector<RootElement> Elements;
811-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
796+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
812797

813798
// Test correct diagnostic produced
814799
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -832,9 +817,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
832817
TrivialModuleLoader ModLoader;
833818
auto PP = createPP(Source, ModLoader);
834819

835-
hlsl::RootSignatureLexer Lexer(Source);
836820
SmallVector<RootElement> Elements;
837-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
821+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
838822

839823
// Test correct diagnostic produced
840824
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -856,9 +840,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
856840
TrivialModuleLoader ModLoader;
857841
auto PP = createPP(Source, ModLoader);
858842

859-
hlsl::RootSignatureLexer Lexer(Source);
860843
SmallVector<RootElement> Elements;
861-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
844+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
862845

863846
// Test correct diagnostic produced
864847
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -882,9 +865,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
882865
TrivialModuleLoader ModLoader;
883866
auto PP = createPP(Source, ModLoader);
884867

885-
hlsl::RootSignatureLexer Lexer(Source);
886868
SmallVector<RootElement> Elements;
887-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
869+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
888870

889871
// Test correct diagnostic produced
890872
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -910,9 +892,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
910892
TrivialModuleLoader ModLoader;
911893
auto PP = createPP(Source, ModLoader);
912894

913-
hlsl::RootSignatureLexer Lexer(Source);
914895
SmallVector<RootElement> Elements;
915-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
896+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
916897

917898
// Test correct diagnostic produced
918899
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -935,9 +916,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
935916
TrivialModuleLoader ModLoader;
936917
auto PP = createPP(Source, ModLoader);
937918

938-
hlsl::RootSignatureLexer Lexer(Source);
939919
SmallVector<RootElement> Elements;
940-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
920+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
941921

942922
// Test correct diagnostic produced
943923
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -959,9 +939,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
959939
TrivialModuleLoader ModLoader;
960940
auto PP = createPP(Source, ModLoader);
961941

962-
hlsl::RootSignatureLexer Lexer(Source);
963942
SmallVector<RootElement> Elements;
964-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
943+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
965944

966945
// Test correct diagnostic produced
967946
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -982,9 +961,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
982961
TrivialModuleLoader ModLoader;
983962
auto PP = createPP(Source, ModLoader);
984963

985-
hlsl::RootSignatureLexer Lexer(Source);
986964
SmallVector<RootElement> Elements;
987-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
965+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
988966

989967
// Test correct diagnostic produced
990968
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1005,9 +983,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
1005983
TrivialModuleLoader ModLoader;
1006984
auto PP = createPP(Source, ModLoader);
1007985

1008-
hlsl::RootSignatureLexer Lexer(Source);
1009986
SmallVector<RootElement> Elements;
1010-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
987+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
1011988

1012989
// Test correct diagnostic produced
1013990
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1028,9 +1005,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
10281005
TrivialModuleLoader ModLoader;
10291006
auto PP = createPP(Source, ModLoader);
10301007

1031-
hlsl::RootSignatureLexer Lexer(Source);
10321008
SmallVector<RootElement> Elements;
1033-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
1009+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
10341010

10351011
// Test correct diagnostic produced
10361012
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1051,9 +1027,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
10511027
TrivialModuleLoader ModLoader;
10521028
auto PP = createPP(Source, ModLoader);
10531029

1054-
hlsl::RootSignatureLexer Lexer(Source);
10551030
SmallVector<RootElement> Elements;
1056-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
1031+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
10571032

10581033
// Test correct diagnostic produced
10591034
Consumer->setExpected(diag::err_hlsl_number_literal_underflow);
@@ -1077,9 +1052,8 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
10771052
TrivialModuleLoader ModLoader;
10781053
auto PP = createPP(Source, ModLoader);
10791054

1080-
hlsl::RootSignatureLexer Lexer(Source);
10811055
SmallVector<RootElement> Elements;
1082-
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
1056+
hlsl::RootSignatureParser Parser(Elements, Signature, *PP);
10831057

10841058
// Test correct diagnostic produced
10851059
Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag);

0 commit comments

Comments
 (0)