Skip to content

Commit d84d287

Browse files
committed
nfc: add StringLiteral as a member of RootSignatureParser
1 parent 34d3879 commit d84d287

File tree

4 files changed

+38
-36
lines changed

4 files changed

+38
-36
lines changed

clang/include/clang/Parse/ParseHLSLRootSignature.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#ifndef LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H
1414
#define LLVM_CLANG_PARSE_PARSEHLSLROOTSIGNATURE_H
1515

16+
#include "clang/AST/Expr.h"
1617
#include "clang/Basic/DiagnosticParse.h"
1718
#include "clang/Lex/LexHLSLRootSignature.h"
1819
#include "clang/Lex/Preprocessor.h"
@@ -29,7 +30,8 @@ class RootSignatureParser {
2930
public:
3031
RootSignatureParser(llvm::dxbc::RootSignatureVersion Version,
3132
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements,
32-
RootSignatureLexer &Lexer, clang::Preprocessor &PP);
33+
RootSignatureLexer &Lexer, StringLiteral *Signature,
34+
Preprocessor &PP);
3335

3436
/// Consumes tokens from the Lexer and constructs the in-memory
3537
/// representations of the RootElements. Tokens are consumed until an
@@ -192,6 +194,7 @@ class RootSignatureParser {
192194
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements;
193195
RootSignatureLexer &Lexer;
194196

197+
clang::StringLiteral *Signature;
195198
clang::Preprocessor &PP;
196199

197200
RootSignatureToken CurToken;

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,20 +4944,19 @@ void Parser::ParseHLSLRootSignatureAttributeArgs(ParsedAttributes &Attrs) {
49444944
}
49454945

49464946
// Construct our identifier
4947-
StringRef Signature = StrLiteral.value()->getString();
4947+
StringLiteral *Signature = StrLiteral.value();
49484948
auto [DeclIdent, Found] =
4949-
Actions.HLSL().ActOnStartRootSignatureDecl(Signature);
4949+
Actions.HLSL().ActOnStartRootSignatureDecl(Signature->getString());
49504950
// If we haven't found an already defined DeclIdent then parse the root
49514951
// signature string and construct the in-memory elements
49524952
if (!Found) {
49534953
// Offset location 1 to account for '"'
4954-
SourceLocation SignatureLoc =
4955-
StrLiteral.value()->getExprLoc().getLocWithOffset(1);
4954+
SourceLocation SignatureLoc = Signature->getExprLoc().getLocWithOffset(1);
49564955
// Invoke the root signature parser to construct the in-memory constructs
4957-
hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc);
4956+
hlsl::RootSignatureLexer Lexer(Signature->getString(), SignatureLoc);
49584957
SmallVector<llvm::hlsl::rootsig::RootElement> RootElements;
49594958
hlsl::RootSignatureParser Parser(getLangOpts().HLSLRootSigVer, RootElements,
4960-
Lexer, PP);
4959+
Lexer, Signature, PP);
49614960
if (Parser.parse()) {
49624961
T.consumeClose();
49634962
return;

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ using TokenKind = RootSignatureToken::Kind;
2020
RootSignatureParser::RootSignatureParser(
2121
llvm::dxbc::RootSignatureVersion Version,
2222
SmallVector<RootElement> &Elements, RootSignatureLexer &Lexer,
23-
Preprocessor &PP)
24-
: Version(Version), Elements(Elements), Lexer(Lexer), PP(PP),
25-
CurToken(SourceLocation()) {}
23+
StringLiteral *Signature, Preprocessor &PP)
24+
: Version(Version), Elements(Elements), Signature(Signature), Lexer(Lexer),
25+
PP(PP), CurToken(SourceLocation()) {}
2626

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

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
139139
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
140140
SmallVector<RootElement> Elements;
141141
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
142-
*PP);
142+
Signature, *PP);
143143

144144
// Test no diagnostics produced
145145
Consumer->setNoDiag();
@@ -177,7 +177,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
177177
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
178178
SmallVector<RootElement> Elements;
179179
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
180-
*PP);
180+
Signature, *PP);
181181

182182
// Test no diagnostics produced
183183
Consumer->setNoDiag();
@@ -284,7 +284,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
284284
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
285285
SmallVector<RootElement> Elements;
286286
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
287-
*PP);
287+
Signature, *PP);
288288

289289
// Test no diagnostics produced
290290
Consumer->setNoDiag();
@@ -373,7 +373,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
373373
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
374374
SmallVector<RootElement> Elements;
375375
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
376-
*PP);
376+
Signature, *PP);
377377

378378
// Test no diagnostics produced
379379
Consumer->setNoDiag();
@@ -452,7 +452,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
452452
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
453453
SmallVector<RootElement> Elements;
454454
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
455-
*PP);
455+
Signature, *PP);
456456

457457
// Test no diagnostics produced
458458
Consumer->setNoDiag();
@@ -487,7 +487,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
487487
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
488488
SmallVector<RootElement> Elements;
489489
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
490-
*PP);
490+
Signature, *PP);
491491

492492
// Test no diagnostics produced
493493
Consumer->setNoDiag();
@@ -548,7 +548,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
548548
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
549549
SmallVector<RootElement> Elements;
550550
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
551-
*PP);
551+
Signature, *PP);
552552

553553
// Test no diagnostics produced
554554
Consumer->setNoDiag();
@@ -605,7 +605,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
605605
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
606606
SmallVector<RootElement> Elements;
607607
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
608-
*PP);
608+
Signature, *PP);
609609

610610
// Test no diagnostics produced
611611
Consumer->setNoDiag();
@@ -683,7 +683,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
683683
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
684684
SmallVector<RootElement> Elements;
685685
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
686-
*PP);
686+
Signature, *PP);
687687

688688
// Test no diagnostics produced
689689
Consumer->setNoDiag();
@@ -857,7 +857,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
857857
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
858858
SmallVector<RootElement> Elements;
859859
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
860-
*PP);
860+
Signature, *PP);
861861

862862
// Test correct diagnostic produced
863863
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
@@ -881,7 +881,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
881881
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
882882
SmallVector<RootElement> Elements;
883883
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
884-
*PP);
884+
Signature, *PP);
885885

886886
// Test correct diagnostic produced - invalid token
887887
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
@@ -905,7 +905,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
905905
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
906906
SmallVector<RootElement> Elements;
907907
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
908-
*PP);
908+
Signature, *PP);
909909

910910
// Test correct diagnostic produced - end of stream
911911
Consumer->setExpected(diag::err_expected_after);
@@ -934,7 +934,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
934934
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
935935
SmallVector<RootElement> Elements;
936936
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
937-
*PP);
937+
Signature, *PP);
938938

939939
// Test correct diagnostic produced
940940
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -960,7 +960,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
960960
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
961961
SmallVector<RootElement> Elements;
962962
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
963-
*PP);
963+
Signature, *PP);
964964

965965
// Test correct diagnostic produced
966966
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -986,7 +986,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
986986
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
987987
SmallVector<RootElement> Elements;
988988
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
989-
*PP);
989+
Signature, *PP);
990990

991991
// Test correct diagnostic produced
992992
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -1014,7 +1014,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
10141014
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
10151015
SmallVector<RootElement> Elements;
10161016
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1017-
*PP);
1017+
Signature, *PP);
10181018

10191019
// Test correct diagnostic produced
10201020
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -1040,7 +1040,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
10401040
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
10411041
SmallVector<RootElement> Elements;
10421042
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1043-
*PP);
1043+
Signature, *PP);
10441044

10451045
// Test correct diagnostic produced
10461046
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -1068,7 +1068,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
10681068
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
10691069
SmallVector<RootElement> Elements;
10701070
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1071-
*PP);
1071+
Signature, *PP);
10721072

10731073
// Test correct diagnostic produced
10741074
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -1098,7 +1098,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
10981098
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
10991099
SmallVector<RootElement> Elements;
11001100
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1101-
*PP);
1101+
Signature, *PP);
11021102

11031103
// Test correct diagnostic produced
11041104
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -1125,7 +1125,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
11251125
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
11261126
SmallVector<RootElement> Elements;
11271127
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1128-
*PP);
1128+
Signature, *PP);
11291129

11301130
// Test correct diagnostic produced
11311131
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1151,7 +1151,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
11511151
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
11521152
SmallVector<RootElement> Elements;
11531153
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1154-
*PP);
1154+
Signature, *PP);
11551155

11561156
// Test correct diagnostic produced
11571157
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1176,7 +1176,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
11761176
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
11771177
SmallVector<RootElement> Elements;
11781178
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1179-
*PP);
1179+
Signature, *PP);
11801180

11811181
// Test correct diagnostic produced
11821182
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1201,7 +1201,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
12011201
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
12021202
SmallVector<RootElement> Elements;
12031203
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1204-
*PP);
1204+
Signature, *PP);
12051205

12061206
// Test correct diagnostic produced
12071207
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1226,7 +1226,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
12261226
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
12271227
SmallVector<RootElement> Elements;
12281228
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1229-
*PP);
1229+
Signature, *PP);
12301230

12311231
// Test correct diagnostic produced
12321232
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1251,7 +1251,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
12511251
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
12521252
SmallVector<RootElement> Elements;
12531253
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1254-
*PP);
1254+
Signature, *PP);
12551255

12561256
// Test correct diagnostic produced
12571257
Consumer->setExpected(diag::err_hlsl_number_literal_underflow);
@@ -1279,7 +1279,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
12791279
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
12801280
SmallVector<RootElement> Elements;
12811281
hlsl::RootSignatureParser Parser(RootSignatureVersion::V1_1, Elements, Lexer,
1282-
*PP);
1282+
Signature, *PP);
12831283

12841284
// Test correct diagnostic produced
12851285
Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag);

0 commit comments

Comments
 (0)