@@ -234,7 +234,7 @@ TEST_F(RecordPPTest, CapturesMacroRefs) {
234
234
const auto &SM = AST.sourceManager ();
235
235
236
236
SourceLocation Def = SM.getComposedLoc (
237
- SM.translateFile (AST.fileManager ().getFile (" header.h" ). get ( )),
237
+ SM.translateFile (* AST.fileManager ().getOptionalFileRef (" header.h" )),
238
238
Header.point (" def" ));
239
239
ASSERT_THAT (Recorded.MacroReferences , Not (IsEmpty ()));
240
240
Symbol OrigX = Recorded.MacroReferences .front ().Target ;
@@ -368,29 +368,29 @@ TEST_F(PragmaIncludeTest, IWYUKeep) {
368
368
TestAST Processed = build ();
369
369
auto &FM = Processed.fileManager ();
370
370
371
- EXPECT_FALSE (PI.shouldKeep (FM.getFile (" normal.h" ). get ( )));
372
- EXPECT_FALSE (PI.shouldKeep (FM.getFile (" std/vector" ). get ( )));
371
+ EXPECT_FALSE (PI.shouldKeep (* FM.getOptionalFileRef (" normal.h" )));
372
+ EXPECT_FALSE (PI.shouldKeep (* FM.getOptionalFileRef (" std/vector" )));
373
373
374
374
// Keep
375
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" keep1.h" ). get ( )));
376
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" keep2.h" ). get ( )));
377
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" keep3.h" ). get ( )));
378
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" keep4.h" ). get ( )));
379
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" keep5.h" ). get ( )));
380
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" keep6.h" ). get ( )));
381
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" std/map" ). get ( )));
375
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" keep1.h" )));
376
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" keep2.h" )));
377
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" keep3.h" )));
378
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" keep4.h" )));
379
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" keep5.h" )));
380
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" keep6.h" )));
381
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" std/map" )));
382
382
383
383
// Exports
384
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" export1.h" ). get ( )));
385
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" export2.h" ). get ( )));
386
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" export3.h" ). get ( )));
387
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" std/set" ). get ( )));
384
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" export1.h" )));
385
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" export2.h" )));
386
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" export3.h" )));
387
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" std/set" )));
388
388
}
389
389
390
390
TEST_F (PragmaIncludeTest, AssociatedHeader) {
391
391
createEmptyFiles ({" foo/main.h" , " bar/main.h" , " bar/other.h" , " std/vector" });
392
392
auto IsKeep = [&](llvm::StringRef Name, TestAST &AST) {
393
- return PI.shouldKeep (AST.fileManager ().getFile (Name). get ( ));
393
+ return PI.shouldKeep (* AST.fileManager ().getOptionalFileRef (Name));
394
394
};
395
395
396
396
Inputs.FileName = " main.cc" ;
@@ -452,19 +452,19 @@ TEST_F(PragmaIncludeTest, IWYUPrivate) {
452
452
// IWYU pragma: private
453
453
)cpp" ;
454
454
TestAST Processed = build ();
455
- auto PrivateFE = Processed.fileManager ().getFile (" private.h" );
455
+ auto PrivateFE = Processed.fileManager ().getOptionalFileRef (" private.h" );
456
456
assert (PrivateFE);
457
- EXPECT_TRUE (PI.isPrivate (PrivateFE. get () ));
458
- EXPECT_EQ (PI.getPublic (PrivateFE. get () ), " \" public2.h\" " );
457
+ EXPECT_TRUE (PI.isPrivate (* PrivateFE));
458
+ EXPECT_EQ (PI.getPublic (* PrivateFE), " \" public2.h\" " );
459
459
460
- auto PublicFE = Processed.fileManager ().getFile (" public.h" );
460
+ auto PublicFE = Processed.fileManager ().getOptionalFileRef (" public.h" );
461
461
assert (PublicFE);
462
- EXPECT_EQ (PI.getPublic (PublicFE. get () ), " " ); // no mapping.
463
- EXPECT_FALSE (PI.isPrivate (PublicFE. get () ));
462
+ EXPECT_EQ (PI.getPublic (* PublicFE), " " ); // no mapping.
463
+ EXPECT_FALSE (PI.isPrivate (* PublicFE));
464
464
465
- auto Private2FE = Processed.fileManager ().getFile (" private2.h" );
465
+ auto Private2FE = Processed.fileManager ().getOptionalFileRef (" private2.h" );
466
466
assert (Private2FE);
467
- EXPECT_TRUE (PI.isPrivate (Private2FE. get () ));
467
+ EXPECT_TRUE (PI.isPrivate (* Private2FE));
468
468
}
469
469
470
470
TEST_F (PragmaIncludeTest, IWYUExport) {
@@ -486,13 +486,13 @@ TEST_F(PragmaIncludeTest, IWYUExport) {
486
486
const auto &SM = Processed.sourceManager ();
487
487
auto &FM = Processed.fileManager ();
488
488
489
- EXPECT_THAT (PI.getExporters (FM.getFile (" private.h" ). get ( ), FM),
489
+ EXPECT_THAT (PI.getExporters (* FM.getOptionalFileRef (" private.h" ), FM),
490
490
testing::UnorderedElementsAre (FileNamed (" export1.h" ),
491
491
FileNamed (" export3.h" )));
492
492
493
- EXPECT_TRUE (PI.getExporters (FM.getFile (" export1.h" ). get ( ), FM).empty ());
494
- EXPECT_TRUE (PI.getExporters (FM.getFile (" export2.h" ). get ( ), FM).empty ());
495
- EXPECT_TRUE (PI.getExporters (FM.getFile (" export3.h" ). get ( ), FM).empty ());
493
+ EXPECT_TRUE (PI.getExporters (* FM.getOptionalFileRef (" export1.h" ), FM).empty ());
494
+ EXPECT_TRUE (PI.getExporters (* FM.getOptionalFileRef (" export2.h" ), FM).empty ());
495
+ EXPECT_TRUE (PI.getExporters (* FM.getOptionalFileRef (" export3.h" ), FM).empty ());
496
496
EXPECT_TRUE (
497
497
PI.getExporters (SM.getFileEntryForID (SM.getMainFileID ()), FM).empty ());
498
498
}
@@ -548,23 +548,23 @@ TEST_F(PragmaIncludeTest, IWYUExportBlock) {
548
548
}
549
549
return Result;
550
550
};
551
- auto Exporters = PI.getExporters (FM.getFile (" private1.h" ). get ( ), FM);
551
+ auto Exporters = PI.getExporters (* FM.getOptionalFileRef (" private1.h" ), FM);
552
552
EXPECT_THAT (Exporters, testing::UnorderedElementsAre (FileNamed (" export1.h" ),
553
553
FileNamed (" normal.h" )))
554
554
<< GetNames (Exporters);
555
555
556
- Exporters = PI.getExporters (FM.getFile (" private2.h" ). get ( ), FM);
556
+ Exporters = PI.getExporters (* FM.getOptionalFileRef (" private2.h" ), FM);
557
557
EXPECT_THAT (Exporters, testing::UnorderedElementsAre (FileNamed (" export1.h" )))
558
558
<< GetNames (Exporters);
559
559
560
- Exporters = PI.getExporters (FM.getFile (" private3.h" ). get ( ), FM);
560
+ Exporters = PI.getExporters (* FM.getOptionalFileRef (" private3.h" ), FM);
561
561
EXPECT_THAT (Exporters, testing::UnorderedElementsAre (FileNamed (" export1.h" )))
562
562
<< GetNames (Exporters);
563
563
564
- Exporters = PI.getExporters (FM.getFile (" foo.h" ). get ( ), FM);
564
+ Exporters = PI.getExporters (* FM.getOptionalFileRef (" foo.h" ), FM);
565
565
EXPECT_TRUE (Exporters.empty ()) << GetNames (Exporters);
566
566
567
- Exporters = PI.getExporters (FM.getFile (" bar.h" ). get ( ), FM);
567
+ Exporters = PI.getExporters (* FM.getOptionalFileRef (" bar.h" ), FM);
568
568
EXPECT_TRUE (Exporters.empty ()) << GetNames (Exporters);
569
569
}
570
570
@@ -580,8 +580,8 @@ TEST_F(PragmaIncludeTest, SelfContained) {
580
580
Inputs.ExtraFiles [" unguarded.h" ] = " " ;
581
581
TestAST Processed = build ();
582
582
auto &FM = Processed.fileManager ();
583
- EXPECT_TRUE (PI.isSelfContained (FM.getFile (" guarded.h" ). get ( )));
584
- EXPECT_FALSE (PI.isSelfContained (FM.getFile (" unguarded.h" ). get ( )));
583
+ EXPECT_TRUE (PI.isSelfContained (* FM.getOptionalFileRef (" guarded.h" )));
584
+ EXPECT_FALSE (PI.isSelfContained (* FM.getOptionalFileRef (" unguarded.h" )));
585
585
}
586
586
587
587
TEST_F (PragmaIncludeTest, AlwaysKeep) {
@@ -596,8 +596,8 @@ TEST_F(PragmaIncludeTest, AlwaysKeep) {
596
596
Inputs.ExtraFiles [" usual.h" ] = " #pragma once" ;
597
597
TestAST Processed = build ();
598
598
auto &FM = Processed.fileManager ();
599
- EXPECT_TRUE (PI.shouldKeep (FM.getFile (" always_keep.h" ). get ( )));
600
- EXPECT_FALSE (PI.shouldKeep (FM.getFile (" usual.h" ). get ( )));
599
+ EXPECT_TRUE (PI.shouldKeep (* FM.getOptionalFileRef (" always_keep.h" )));
600
+ EXPECT_FALSE (PI.shouldKeep (* FM.getOptionalFileRef (" usual.h" )));
601
601
}
602
602
603
603
TEST_F (PragmaIncludeTest, ExportInUnnamedBuffer) {
@@ -653,13 +653,13 @@ TEST_F(PragmaIncludeTest, OutlivesFMAndSM) {
653
653
// Now this build gives us a new File&Source Manager.
654
654
TestAST Processed = build (/* ResetPragmaIncludes=*/ false );
655
655
auto &FM = Processed.fileManager ();
656
- auto PrivateFE = FM.getFile (" private.h" );
656
+ auto PrivateFE = FM.getOptionalFileRef (" private.h" );
657
657
assert (PrivateFE);
658
- EXPECT_EQ (PI.getPublic (PrivateFE. get () ), " \" public.h\" " );
658
+ EXPECT_EQ (PI.getPublic (* PrivateFE), " \" public.h\" " );
659
659
660
- auto Private2FE = FM.getFile (" private2.h" );
660
+ auto Private2FE = FM.getOptionalFileRef (" private2.h" );
661
661
assert (Private2FE);
662
- EXPECT_THAT (PI.getExporters (Private2FE. get () , FM),
662
+ EXPECT_THAT (PI.getExporters (* Private2FE, FM),
663
663
testing::ElementsAre (llvm::cantFail (FM.getFileRef (" public.h" ))));
664
664
}
665
665
@@ -676,8 +676,8 @@ TEST_F(PragmaIncludeTest, CanRecordManyTimes) {
676
676
677
677
TestAST Processed = build ();
678
678
auto &FM = Processed.fileManager ();
679
- auto PrivateFE = FM.getFile (" private.h" );
680
- llvm::StringRef Public = PI.getPublic (PrivateFE. get () );
679
+ auto PrivateFE = FM.getOptionalFileRef (" private.h" );
680
+ llvm::StringRef Public = PI.getPublic (* PrivateFE);
681
681
EXPECT_EQ (Public, " \" public.h\" " );
682
682
683
683
// This build populates same PI during build, but this time we don't have
0 commit comments