Skip to content

Commit 2a3ffdc

Browse files
committed
nfc: add phony ASTContext and StringLiteral to ParseHLSL
1 parent 0ceb0c3 commit 2a3ffdc

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed

clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "clang/AST/ASTContext.h"
10+
#include "clang/AST/Expr.h"
911
#include "clang/Basic/Diagnostic.h"
1012
#include "clang/Basic/DiagnosticOptions.h"
1113
#include "clang/Basic/FileManager.h"
@@ -91,6 +93,22 @@ class ParseHLSLRootSignatureTest : public ::testing::Test {
9193
return PP;
9294
}
9395

96+
std::unique_ptr<ASTContext> createMinimalASTContext() {
97+
IdentifierTable Idents(LangOpts);
98+
SelectorTable Selectors;
99+
Builtin::Context Builtins;
100+
101+
return std::make_unique<ASTContext>(LangOpts, SourceMgr, Idents, Selectors,
102+
Builtins, TU_Complete);
103+
}
104+
105+
StringLiteral *wrapSource(std::unique_ptr<ASTContext> &Ctx,
106+
StringRef Source) {
107+
SourceLocation Locs[1] = {SourceLocation()};
108+
return StringLiteral::Create(*Ctx, Source, StringLiteralKind::Unevaluated,
109+
false, Ctx->VoidTy, Locs);
110+
}
111+
94112
FileSystemOptions FileMgrOpts;
95113
FileManager FileMgr;
96114
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
@@ -109,6 +127,9 @@ class ParseHLSLRootSignatureTest : public ::testing::Test {
109127
TEST_F(ParseHLSLRootSignatureTest, ValidParseEmptyTest) {
110128
const llvm::StringLiteral Source = R"cc()cc";
111129

130+
auto Ctx = createMinimalASTContext();
131+
StringLiteral *Signature = wrapSource(Ctx, Source);
132+
112133
TrivialModuleLoader ModLoader;
113134
auto PP = createPP(Source, ModLoader);
114135
auto TokLoc = SourceLocation();
@@ -143,6 +164,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseDTClausesTest) {
143164
DescriptorTable()
144165
)cc";
145166

167+
auto Ctx = createMinimalASTContext();
168+
StringLiteral *Signature = wrapSource(Ctx, Source);
169+
146170
TrivialModuleLoader ModLoader;
147171
auto PP = createPP(Source, ModLoader);
148172
auto TokLoc = SourceLocation();
@@ -246,6 +270,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseStaticSamplerTest) {
246270
)
247271
)cc";
248272

273+
auto Ctx = createMinimalASTContext();
274+
StringLiteral *Signature = wrapSource(Ctx, Source);
275+
249276
TrivialModuleLoader ModLoader;
250277
auto PP = createPP(Source, ModLoader);
251278
auto TokLoc = SourceLocation();
@@ -331,6 +358,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseFloatsTest) {
331358
StaticSampler(s0, mipLODBias = 2147483648),
332359
)cc";
333360

361+
auto Ctx = createMinimalASTContext();
362+
StringLiteral *Signature = wrapSource(Ctx, Source);
363+
334364
TrivialModuleLoader ModLoader;
335365
auto PP = createPP(Source, ModLoader);
336366
auto TokLoc = SourceLocation();
@@ -406,6 +436,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidSamplerFlagsTest) {
406436
DescriptorTable(Sampler(s0, flags = DESCRIPTORS_VOLATILE))
407437
)cc";
408438

439+
auto Ctx = createMinimalASTContext();
440+
StringLiteral *Signature = wrapSource(Ctx, Source);
441+
409442
TrivialModuleLoader ModLoader;
410443
auto PP = createPP(Source, ModLoader);
411444
auto TokLoc = SourceLocation();
@@ -437,6 +470,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootConsantsTest) {
437470
)
438471
)cc";
439472

473+
auto Ctx = createMinimalASTContext();
474+
StringLiteral *Signature = wrapSource(Ctx, Source);
475+
440476
TrivialModuleLoader ModLoader;
441477
auto PP = createPP(Source, ModLoader);
442478
auto TokLoc = SourceLocation();
@@ -494,6 +530,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootFlagsTest) {
494530
)
495531
)cc";
496532

533+
auto Ctx = createMinimalASTContext();
534+
StringLiteral *Signature = wrapSource(Ctx, Source);
535+
497536
TrivialModuleLoader ModLoader;
498537
auto PP = createPP(Source, ModLoader);
499538
auto TokLoc = SourceLocation();
@@ -547,6 +586,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidParseRootDescriptorsTest) {
547586
CBV(b0, flags = 0),
548587
)cc";
549588

589+
auto Ctx = createMinimalASTContext();
590+
StringLiteral *Signature = wrapSource(Ctx, Source);
591+
550592
TrivialModuleLoader ModLoader;
551593
auto PP = createPP(Source, ModLoader);
552594
auto TokLoc = SourceLocation();
@@ -621,6 +663,9 @@ TEST_F(ParseHLSLRootSignatureTest, ValidTrailingCommaTest) {
621663
)
622664
)cc";
623665

666+
auto Ctx = createMinimalASTContext();
667+
StringLiteral *Signature = wrapSource(Ctx, Source);
668+
624669
TrivialModuleLoader ModLoader;
625670
auto PP = createPP(Source, ModLoader);
626671
auto TokLoc = SourceLocation();
@@ -645,6 +690,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedTokenTest) {
645690
space
646691
)cc";
647692

693+
auto Ctx = createMinimalASTContext();
694+
StringLiteral *Signature = wrapSource(Ctx, Source);
695+
648696
TrivialModuleLoader ModLoader;
649697
auto PP = createPP(Source, ModLoader);
650698
auto TokLoc = SourceLocation();
@@ -665,6 +713,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseInvalidTokenTest) {
665713
notAnIdentifier
666714
)cc";
667715

716+
auto Ctx = createMinimalASTContext();
717+
StringLiteral *Signature = wrapSource(Ctx, Source);
718+
668719
TrivialModuleLoader ModLoader;
669720
auto PP = createPP(Source, ModLoader);
670721
auto TokLoc = SourceLocation();
@@ -685,6 +736,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseUnexpectedEndOfStreamTest) {
685736
DescriptorTable
686737
)cc";
687738

739+
auto Ctx = createMinimalASTContext();
740+
StringLiteral *Signature = wrapSource(Ctx, Source);
741+
688742
TrivialModuleLoader ModLoader;
689743
auto PP = createPP(Source, ModLoader);
690744
auto TokLoc = SourceLocation();
@@ -710,6 +764,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingDTParameterTest) {
710764
)
711765
)cc";
712766

767+
auto Ctx = createMinimalASTContext();
768+
StringLiteral *Signature = wrapSource(Ctx, Source);
769+
713770
TrivialModuleLoader ModLoader;
714771
auto PP = createPP(Source, ModLoader);
715772
auto TokLoc = SourceLocation();
@@ -732,6 +789,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRDParameterTest) {
732789
SRV()
733790
)cc";
734791

792+
auto Ctx = createMinimalASTContext();
793+
StringLiteral *Signature = wrapSource(Ctx, Source);
794+
735795
TrivialModuleLoader ModLoader;
736796
auto PP = createPP(Source, ModLoader);
737797
auto TokLoc = SourceLocation();
@@ -754,6 +814,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidMissingRCParameterTest) {
754814
RootConstants(b0)
755815
)cc";
756816

817+
auto Ctx = createMinimalASTContext();
818+
StringLiteral *Signature = wrapSource(Ctx, Source);
819+
757820
TrivialModuleLoader ModLoader;
758821
auto PP = createPP(Source, ModLoader);
759822
auto TokLoc = SourceLocation();
@@ -778,6 +841,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryDTParameterTest) {
778841
)
779842
)cc";
780843

844+
auto Ctx = createMinimalASTContext();
845+
StringLiteral *Signature = wrapSource(Ctx, Source);
846+
781847
TrivialModuleLoader ModLoader;
782848
auto PP = createPP(Source, ModLoader);
783849
auto TokLoc = SourceLocation();
@@ -800,6 +866,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedMandatoryRCParameterTest) {
800866
RootConstants(num32BitConstants = 32, num32BitConstants = 24)
801867
)cc";
802868

869+
auto Ctx = createMinimalASTContext();
870+
StringLiteral *Signature = wrapSource(Ctx, Source);
871+
803872
TrivialModuleLoader ModLoader;
804873
auto PP = createPP(Source, ModLoader);
805874
auto TokLoc = SourceLocation();
@@ -824,6 +893,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalDTParameterTest) {
824893
)
825894
)cc";
826895

896+
auto Ctx = createMinimalASTContext();
897+
StringLiteral *Signature = wrapSource(Ctx, Source);
898+
827899
TrivialModuleLoader ModLoader;
828900
auto PP = createPP(Source, ModLoader);
829901
auto TokLoc = SourceLocation();
@@ -850,6 +922,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidRepeatedOptionalRCParameterTest) {
850922
)
851923
)cc";
852924

925+
auto Ctx = createMinimalASTContext();
926+
StringLiteral *Signature = wrapSource(Ctx, Source);
927+
853928
TrivialModuleLoader ModLoader;
854929
auto PP = createPP(Source, ModLoader);
855930
auto TokLoc = SourceLocation();
@@ -873,6 +948,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedNumberTest) {
873948
)
874949
)cc";
875950

951+
auto Ctx = createMinimalASTContext();
952+
StringLiteral *Signature = wrapSource(Ctx, Source);
953+
876954
TrivialModuleLoader ModLoader;
877955
auto PP = createPP(Source, ModLoader);
878956
auto TokLoc = SourceLocation();
@@ -895,6 +973,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidParseOverflowedNegativeNumberTest) {
895973
StaticSampler(s0, mipLODBias = -4294967295)
896974
)cc";
897975

976+
auto Ctx = createMinimalASTContext();
977+
StringLiteral *Signature = wrapSource(Ctx, Source);
978+
898979
TrivialModuleLoader ModLoader;
899980
auto PP = createPP(Source, ModLoader);
900981
auto TokLoc = SourceLocation();
@@ -916,6 +997,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedFloatTest) {
916997
StaticSampler(s0, mipLODBias = 3.402823467e+38F)
917998
)cc";
918999

1000+
auto Ctx = createMinimalASTContext();
1001+
StringLiteral *Signature = wrapSource(Ctx, Source);
1002+
9191003
TrivialModuleLoader ModLoader;
9201004
auto PP = createPP(Source, ModLoader);
9211005
auto TokLoc = SourceLocation();
@@ -937,6 +1021,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexNegOverflowedFloatTest) {
9371021
StaticSampler(s0, mipLODBias = -3.402823467e+38F)
9381022
)cc";
9391023

1024+
auto Ctx = createMinimalASTContext();
1025+
StringLiteral *Signature = wrapSource(Ctx, Source);
1026+
9401027
TrivialModuleLoader ModLoader;
9411028
auto PP = createPP(Source, ModLoader);
9421029
auto TokLoc = SourceLocation();
@@ -958,6 +1045,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexOverflowedDoubleTest) {
9581045
StaticSampler(s0, mipLODBias = 1.e+500)
9591046
)cc";
9601047

1048+
auto Ctx = createMinimalASTContext();
1049+
StringLiteral *Signature = wrapSource(Ctx, Source);
1050+
9611051
TrivialModuleLoader ModLoader;
9621052
auto PP = createPP(Source, ModLoader);
9631053
auto TokLoc = SourceLocation();
@@ -979,6 +1069,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidLexUnderflowFloatTest) {
9791069
StaticSampler(s0, mipLODBias = 10e-309)
9801070
)cc";
9811071

1072+
auto Ctx = createMinimalASTContext();
1073+
StringLiteral *Signature = wrapSource(Ctx, Source);
1074+
9821075
TrivialModuleLoader ModLoader;
9831076
auto PP = createPP(Source, ModLoader);
9841077
auto TokLoc = SourceLocation();
@@ -1003,6 +1096,9 @@ TEST_F(ParseHLSLRootSignatureTest, InvalidNonZeroFlagsTest) {
10031096
)
10041097
)cc";
10051098

1099+
auto Ctx = createMinimalASTContext();
1100+
StringLiteral *Signature = wrapSource(Ctx, Source);
1101+
10061102
TrivialModuleLoader ModLoader;
10071103
auto PP = createPP(Source, ModLoader);
10081104
auto TokLoc = SourceLocation();

0 commit comments

Comments
 (0)