Skip to content

Commit 4c616ff

Browse files
committed
nfc: add StringLiteral as a member of RootSignatureParser
1 parent abef313 commit 4c616ff

File tree

4 files changed

+37
-33
lines changed

4 files changed

+37
-33
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"
@@ -28,7 +29,8 @@ namespace hlsl {
2829
class RootSignatureParser {
2930
public:
3031
RootSignatureParser(SmallVector<llvm::hlsl::rootsig::RootElement> &Elements,
31-
RootSignatureLexer &Lexer, clang::Preprocessor &PP);
32+
RootSignatureLexer &Lexer, StringLiteral *Signature,
33+
Preprocessor &PP);
3234

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

195+
clang::StringLiteral *Signature;
193196
clang::Preprocessor &PP;
194197

195198
RootSignatureToken CurToken;

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4944,19 +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 '"'
49544954
SourceLocation SignatureLoc =
4955-
StrLiteral.value()->getExprLoc().getLocWithOffset(1);
4955+
Signature->getExprLoc().getLocWithOffset(1);
49564956
// Invoke the root signature parser to construct the in-memory constructs
4957-
hlsl::RootSignatureLexer Lexer(Signature, SignatureLoc);
4957+
hlsl::RootSignatureLexer Lexer(Signature->getString(), SignatureLoc);
49584958
SmallVector<llvm::hlsl::rootsig::RootElement> RootElements;
4959-
hlsl::RootSignatureParser Parser(RootElements, Lexer, PP);
4959+
hlsl::RootSignatureParser Parser(RootElements, Lexer, Signature, PP);
49604960
if (Parser.parse()) {
49614961
T.consumeClose();
49624962
return;

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ using TokenKind = RootSignatureToken::Kind;
1919

2020
RootSignatureParser::RootSignatureParser(SmallVector<RootElement> &Elements,
2121
RootSignatureLexer &Lexer,
22+
StringLiteral *Signature,
2223
Preprocessor &PP)
23-
: Elements(Elements), Lexer(Lexer), PP(PP), CurToken(SourceLocation()) {}
24+
: Elements(Elements), Lexer(Lexer), Signature(Signature), PP(PP), CurToken(SourceLocation()) {}
2425

2526
bool RootSignatureParser::parse() {
2627
// 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
@@ -136,7 +136,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
136136

137137
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
138138
SmallVector<RootElement> Elements;
139-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
139+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
140140

141141
// Test no diagnostics produced
142142
Consumer->setNoDiag();
@@ -173,7 +173,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
173173

174174
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
175175
SmallVector<RootElement> Elements;
176-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
176+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
177177

178178
// Test no diagnostics produced
179179
Consumer->setNoDiag();
@@ -279,7 +279,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
279279

280280
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
281281
SmallVector<RootElement> Elements;
282-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
282+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
283283

284284
// Test no diagnostics produced
285285
Consumer->setNoDiag();
@@ -367,7 +367,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
367367

368368
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
369369
SmallVector<RootElement> Elements;
370-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
370+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
371371

372372
// Test no diagnostics produced
373373
Consumer->setNoDiag();
@@ -445,7 +445,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
445445

446446
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
447447
SmallVector<RootElement> Elements;
448-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
448+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
449449

450450
// Test no diagnostics produced
451451
Consumer->setNoDiag();
@@ -479,7 +479,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
479479

480480
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
481481
SmallVector<RootElement> Elements;
482-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
482+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
483483

484484
// Test no diagnostics produced
485485
Consumer->setNoDiag();
@@ -539,7 +539,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
539539

540540
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
541541
SmallVector<RootElement> Elements;
542-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
542+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
543543

544544
// Test no diagnostics produced
545545
Consumer->setNoDiag();
@@ -595,7 +595,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
595595

596596
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
597597
SmallVector<RootElement> Elements;
598-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
598+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
599599

600600
// Test no diagnostics produced
601601
Consumer->setNoDiag();
@@ -672,7 +672,7 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
672672

673673
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
674674
SmallVector<RootElement> Elements;
675-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
675+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
676676

677677
// Test no diagnostics produced
678678
Consumer->setNoDiag();
@@ -699,7 +699,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
699699

700700
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
701701
SmallVector<RootElement> Elements;
702-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
702+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
703703

704704
// Test correct diagnostic produced
705705
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
@@ -722,7 +722,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
722722

723723
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
724724
SmallVector<RootElement> Elements;
725-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
725+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
726726

727727
// Test correct diagnostic produced - invalid token
728728
Consumer->setExpected(diag::err_hlsl_unexpected_end_of_params);
@@ -745,7 +745,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
745745

746746
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
747747
SmallVector<RootElement> Elements;
748-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
748+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
749749

750750
// Test correct diagnostic produced - end of stream
751751
Consumer->setExpected(diag::err_expected_after);
@@ -773,7 +773,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
773773

774774
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
775775
SmallVector<RootElement> Elements;
776-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
776+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
777777

778778
// Test correct diagnostic produced
779779
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -798,7 +798,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
798798

799799
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
800800
SmallVector<RootElement> Elements;
801-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
801+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
802802

803803
// Test correct diagnostic produced
804804
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -823,7 +823,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
823823

824824
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
825825
SmallVector<RootElement> Elements;
826-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
826+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
827827

828828
// Test correct diagnostic produced
829829
Consumer->setExpected(diag::err_hlsl_rootsig_missing_param);
@@ -850,7 +850,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
850850

851851
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
852852
SmallVector<RootElement> Elements;
853-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
853+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
854854

855855
// Test correct diagnostic produced
856856
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -875,7 +875,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
875875

876876
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
877877
SmallVector<RootElement> Elements;
878-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
878+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
879879

880880
// Test correct diagnostic produced
881881
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -902,7 +902,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
902902

903903
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
904904
SmallVector<RootElement> Elements;
905-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
905+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
906906

907907
// Test correct diagnostic produced
908908
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -931,7 +931,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
931931

932932
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
933933
SmallVector<RootElement> Elements;
934-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
934+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
935935

936936
// Test correct diagnostic produced
937937
Consumer->setExpected(diag::err_hlsl_rootsig_repeat_param);
@@ -957,7 +957,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
957957

958958
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
959959
SmallVector<RootElement> Elements;
960-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
960+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
961961

962962
// Test correct diagnostic produced
963963
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -982,7 +982,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
982982

983983
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
984984
SmallVector<RootElement> Elements;
985-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
985+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
986986

987987
// Test correct diagnostic produced
988988
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1006,7 +1006,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
10061006

10071007
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
10081008
SmallVector<RootElement> Elements;
1009-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1009+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
10101010

10111011
// Test correct diagnostic produced
10121012
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1030,7 +1030,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
10301030

10311031
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
10321032
SmallVector<RootElement> Elements;
1033-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1033+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
10341034

10351035
// Test correct diagnostic produced
10361036
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1054,7 +1054,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
10541054

10551055
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
10561056
SmallVector<RootElement> Elements;
1057-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1057+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
10581058

10591059
// Test correct diagnostic produced
10601060
Consumer->setExpected(diag::err_hlsl_number_literal_overflow);
@@ -1078,7 +1078,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
10781078

10791079
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
10801080
SmallVector<RootElement> Elements;
1081-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1081+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
10821082

10831083
// Test correct diagnostic produced
10841084
Consumer->setExpected(diag::err_hlsl_number_literal_underflow);
@@ -1105,7 +1105,7 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
11051105

11061106
hlsl::RootSignatureLexer Lexer(Source, TokLoc);
11071107
SmallVector<RootElement> Elements;
1108-
hlsl::RootSignatureParser Parser(Elements, Lexer, *PP);
1108+
hlsl::RootSignatureParser Parser(Elements, Lexer, Signature, *PP);
11091109

11101110
// Test correct diagnostic produced
11111111
Consumer->setExpected(diag::err_hlsl_rootsig_non_zero_flag);

0 commit comments

Comments
 (0)