@@ -230,7 +230,7 @@ namespace {
230
230
231
231
typedef uint64_t BufferStamp;
232
232
233
- struct FileContent : llvm::RefCountedBase<FileContent> {
233
+ struct FileContent {
234
234
ImmutableTextSnapshotRef Snapshot;
235
235
std::string Filename;
236
236
std::unique_ptr<llvm::MemoryBuffer> Buffer;
@@ -248,8 +248,6 @@ struct FileContent : llvm::RefCountedBase<FileContent> {
248
248
}
249
249
};
250
250
251
- using FileContentRef = llvm::IntrusiveRefCntPtr<FileContent>;
252
-
253
251
// / An \c ASTBuildOperations builds an AST. Once the AST is built, it informs
254
252
// / a list of \c SwiftASTConsumers about the built AST.
255
253
// / It also supports cancellation with the following paradigm: If an \c
@@ -304,7 +302,7 @@ class ASTBuildOperation
304
302
305
303
// / The contents of all explicit input files of the compiler invoation, which
306
304
// / can be determined at construction time of the \c ASTBuildOperation.
307
- const std::vector<FileContentRef > FileContents;
305
+ const std::vector<FileContent > FileContents;
308
306
309
307
// / \c DependencyStamps contains the stamps of all module depenecies needed
310
308
// / for the AST build. These stamps are only known after the AST is built.
@@ -366,7 +364,7 @@ class ASTBuildOperation
366
364
367
365
// / Create a vector of \c FileContents containing all files explicitly
368
366
// / referenced by the compiler invocation.
369
- std::vector<FileContentRef > fileContentsForFilesInCompilerInvocation ();
367
+ std::vector<FileContent > fileContentsForFilesInCompilerInvocation ();
370
368
371
369
public:
372
370
ASTBuildOperation (IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
@@ -376,7 +374,7 @@ class ASTBuildOperation
376
374
DidFinishCallback (DidFinishCallback) {
377
375
// const_cast is fine here. We just want to guard against modifying these
378
376
// fields later on. It's fine to set them in the constructor.
379
- const_cast <std::vector<FileContentRef > &>(this ->FileContents ) =
377
+ const_cast <std::vector<FileContent > &>(this ->FileContents ) =
380
378
fileContentsForFilesInCompilerInvocation ();
381
379
}
382
380
@@ -387,7 +385,7 @@ class ASTBuildOperation
387
385
" not receive their callback." );
388
386
}
389
387
390
- ArrayRef<FileContentRef > getFileContents () const { return FileContents; }
388
+ ArrayRef<FileContent > getFileContents () const { return FileContents; }
391
389
392
390
// / Returns true if the build operation has finished.
393
391
bool isFinished () {
@@ -598,7 +596,7 @@ struct SwiftASTManager::Implementation {
598
596
599
597
ASTProducerRef getASTProducer (SwiftInvocationRef InvokRef);
600
598
601
- FileContentRef
599
+ FileContent
602
600
getFileContent (StringRef FilePath, bool IsPrimary,
603
601
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
604
602
std::string &Error) const ;
@@ -634,10 +632,10 @@ SwiftASTManager::getMemoryBuffer(StringRef Filename, std::string &Error) {
634
632
}
635
633
636
634
static FrontendInputsAndOutputs
637
- convertFileContentsToInputs (ArrayRef<FileContentRef > contents) {
635
+ convertFileContentsToInputs (ArrayRef<FileContent > contents) {
638
636
FrontendInputsAndOutputs inputsAndOutputs;
639
- for (FileContentRef content : contents)
640
- inputsAndOutputs.addInput (InputFile (* content));
637
+ for (const FileContent & content : contents)
638
+ inputsAndOutputs.addInput (InputFile (content));
641
639
return inputsAndOutputs;
642
640
}
643
641
@@ -780,16 +778,15 @@ SwiftASTManager::Implementation::getASTProducer(SwiftInvocationRef InvokRef) {
780
778
return Producer;
781
779
}
782
780
783
- static FileContentRef getFileContentFromSnap (ImmutableTextSnapshotRef Snap,
784
- bool IsPrimary,
785
- StringRef FilePath) {
781
+ static FileContent getFileContentFromSnap (ImmutableTextSnapshotRef Snap,
782
+ bool IsPrimary, StringRef FilePath) {
786
783
auto Buf = llvm::MemoryBuffer::getMemBufferCopy (
787
784
Snap->getBuffer ()->getText (), FilePath);
788
- return new FileContent (Snap, FilePath.str (), std::move (Buf), IsPrimary,
789
- Snap->getStamp ());
785
+ return FileContent (Snap, FilePath.str (), std::move (Buf), IsPrimary,
786
+ Snap->getStamp ());
790
787
}
791
788
792
- FileContentRef SwiftASTManager::Implementation::getFileContent (
789
+ FileContent SwiftASTManager::Implementation::getFileContent (
793
790
StringRef UnresolvedPath, bool IsPrimary,
794
791
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FileSystem,
795
792
std::string &Error) const {
@@ -802,8 +799,8 @@ FileContentRef SwiftASTManager::Implementation::getFileContent(
802
799
// No need to check EditorDocs again. We did so above.
803
800
auto Stamp = getBufferStamp (FilePath, FileSystem, /* CheckEditorDocs=*/ false );
804
801
auto Buffer = getMemoryBuffer (FilePath, FileSystem, Error);
805
- return new FileContent (nullptr , UnresolvedPath.str (), std::move (Buffer),
806
- IsPrimary, Stamp);
802
+ return FileContent (nullptr , UnresolvedPath.str (), std::move (Buffer),
803
+ IsPrimary, Stamp);
807
804
}
808
805
809
806
BufferStamp SwiftASTManager::Implementation::getBufferStamp (
@@ -845,12 +842,12 @@ SwiftASTManager::Implementation::getMemoryBuffer(
845
842
return nullptr ;
846
843
}
847
844
848
- std::vector<FileContentRef >
845
+ std::vector<FileContent >
849
846
ASTBuildOperation::fileContentsForFilesInCompilerInvocation () {
850
847
const InvocationOptions &Opts = InvokRef->Impl .Opts ;
851
848
std::string Error; // is ignored
852
849
853
- std::vector<FileContentRef > FileContents;
850
+ std::vector<FileContent > FileContents;
854
851
FileContents.reserve (
855
852
Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
856
853
@@ -862,14 +859,13 @@ ASTBuildOperation::fileContentsForFilesInCompilerInvocation() {
862
859
bool IsPrimary = input.isPrimary ();
863
860
auto Content =
864
861
ASTManager->Impl .getFileContent (Filename, IsPrimary, FileSystem, Error);
865
- if (!Content-> Buffer ) {
862
+ if (!Content. Buffer ) {
866
863
LOG_WARN_FUNC (" failed getting file contents for " << Filename << " : "
867
864
<< Error);
868
865
// File may not exist, continue and recover as if it was empty.
869
- Content->Buffer =
870
- llvm::WritableMemoryBuffer::getNewMemBuffer (0 , Filename);
866
+ Content.Buffer = llvm::WritableMemoryBuffer::getNewMemBuffer (0 , Filename);
871
867
}
872
- FileContents.push_back (Content);
868
+ FileContents.push_back (std::move ( Content) );
873
869
}
874
870
assert (FileContents.size () ==
875
871
Opts.Invok .getFrontendOptions ().InputsAndOutputs .inputCount ());
@@ -882,7 +878,7 @@ bool ASTBuildOperation::matchesSourceState(
882
878
883
879
auto Inputs = Opts.Invok .getFrontendOptions ().InputsAndOutputs .getAllInputs ();
884
880
for (size_t I = 0 ; I < Inputs.size (); I++) {
885
- if (getFileContents ()[I]-> Stamp !=
881
+ if (getFileContents ()[I]. Stamp !=
886
882
ASTManager->Impl .getBufferStamp (Inputs[I].getFileName (),
887
883
OtherFileSystem)) {
888
884
return false ;
@@ -1011,8 +1007,8 @@ ASTUnitRef ASTBuildOperation::buildASTUnit(std::string &Error) {
1011
1007
1012
1008
ASTUnitRef ASTRef = new ASTUnit (++ASTUnitGeneration, ASTManager->Impl .Stats );
1013
1009
for (auto &Content : getFileContents ()) {
1014
- if (Content-> Snapshot )
1015
- ASTRef->Impl .Snapshots .push_back (Content-> Snapshot );
1010
+ if (Content. Snapshot )
1011
+ ASTRef->Impl .Snapshots .push_back (Content. Snapshot );
1016
1012
}
1017
1013
auto &CompIns = ASTRef->Impl .CompInst ;
1018
1014
auto &Consumer = ASTRef->Impl .CollectDiagConsumer ;
@@ -1180,7 +1176,7 @@ ASTBuildOperationRef ASTProducer::getBuildOperationForConsumer(
1180
1176
std::vector<ImmutableTextSnapshotRef> Snapshots;
1181
1177
Snapshots.reserve (BuildOp->getFileContents ().size ());
1182
1178
for (auto &FileContent : BuildOp->getFileContents ()) {
1183
- Snapshots.push_back (FileContent-> Snapshot );
1179
+ Snapshots.push_back (FileContent. Snapshot );
1184
1180
}
1185
1181
if (BuildOp->matchesSourceState (FileSystem)) {
1186
1182
++Mgr->Impl .Stats ->numASTCacheHits ;
0 commit comments