Skip to content

Commit 7560356

Browse files
committed
[clang] NFCI: Use FileEntryRef in FileRemapper (2/2)
1 parent 3817c8a commit 7560356

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

clang/include/clang/ARCMigrate/FileRemapper.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FileRemapper {
3333
// FIXME: Reuse the same FileManager for multiple ASTContexts.
3434
std::unique_ptr<FileManager> FileMgr;
3535

36-
typedef llvm::PointerUnion<const FileEntry *, llvm::MemoryBuffer *> Target;
36+
typedef llvm::PointerUnion<FileEntryRef, llvm::MemoryBuffer *> Target;
3737
using MappingsTy = llvm::DenseMap<FileEntryRef, Target>;
3838
MappingsTy FromToMappings;
3939

@@ -67,7 +67,7 @@ class FileRemapper {
6767

6868
private:
6969
void remap(FileEntryRef file, std::unique_ptr<llvm::MemoryBuffer> memBuf);
70-
void remap(FileEntryRef file, const FileEntry *newfile);
70+
void remap(FileEntryRef file, FileEntryRef newfile);
7171

7272
OptionalFileEntryRef getOriginalFile(StringRef filePath);
7373
void resetTarget(Target &targ);

clang/lib/ARCMigrate/FileRemapper.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
6060
if (!llvm::sys::fs::exists(infoFile))
6161
return false;
6262

63-
std::vector<std::pair<FileEntryRef, const FileEntry *> > pairs;
63+
std::vector<std::pair<FileEntryRef, FileEntryRef>> pairs;
6464

6565
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBuf =
6666
llvm::MemoryBuffer::getFile(infoFile, /*IsText=*/true);
@@ -84,7 +84,7 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
8484
continue;
8585
return report("File does not exist: " + fromFilename, Diag);
8686
}
87-
llvm::ErrorOr<const FileEntry *> newFE = FileMgr->getFile(toFilename);
87+
auto newFE = FileMgr->getOptionalFileRef(toFilename);
8888
if (!newFE) {
8989
if (ignoreIfFilesChanged)
9090
continue;
@@ -134,8 +134,9 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
134134
infoOut << origPath << '\n';
135135
infoOut << (uint64_t)origFE.getModificationTime() << '\n';
136136

137-
if (const FileEntry *FE = I->second.dyn_cast<const FileEntry *>()) {
138-
SmallString<200> newPath = StringRef(FE->getName());
137+
if (I->second.is<FileEntryRef>()) {
138+
auto FE = I->second.get<FileEntryRef>();
139+
SmallString<200> newPath = StringRef(FE.getName());
139140
fs::make_absolute(newPath);
140141
infoOut << newPath << '\n';
141142
} else {
@@ -153,10 +154,10 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
153154
newOut.write(mem->getBufferStart(), mem->getBufferSize());
154155
newOut.close();
155156

156-
auto newE = FileMgr->getFile(tempPath);
157+
auto newE = FileMgr->getOptionalFileRef(tempPath);
157158
if (newE) {
158159
remap(origFE, *newE);
159-
infoOut << (*newE)->getName() << '\n';
160+
infoOut << newE->getName() << '\n';
160161
}
161162
}
162163
}
@@ -196,8 +197,9 @@ void FileRemapper::forEachMapping(
196197
llvm::function_ref<void(StringRef, const llvm::MemoryBufferRef &)>
197198
CaptureBuffer) const {
198199
for (auto &Mapping : FromToMappings) {
199-
if (const FileEntry *FE = Mapping.second.dyn_cast<const FileEntry *>()) {
200-
CaptureFile(Mapping.first.getName(), FE->getName());
200+
if (Mapping.second.is<FileEntryRef>()) {
201+
auto FE = Mapping.second.get<FileEntryRef>();
202+
CaptureFile(Mapping.first.getName(), FE.getName());
201203
continue;
202204
}
203205
CaptureBuffer(
@@ -209,8 +211,9 @@ void FileRemapper::forEachMapping(
209211
void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const {
210212
for (MappingsTy::const_iterator
211213
I = FromToMappings.begin(), E = FromToMappings.end(); I != E; ++I) {
212-
if (const FileEntry *FE = I->second.dyn_cast<const FileEntry *>()) {
213-
PPOpts.addRemappedFile(I->first.getName(), FE->getName());
214+
if (I->second.is<FileEntryRef>()) {
215+
auto FE = I->second.get<FileEntryRef>();
216+
PPOpts.addRemappedFile(I->first.getName(), FE.getName());
214217
} else {
215218
llvm::MemoryBuffer *mem = I->second.get<llvm::MemoryBuffer *>();
216219
PPOpts.addRemappedFile(I->first.getName(), mem);
@@ -234,8 +237,7 @@ void FileRemapper::remap(FileEntryRef file,
234237
targ = memBuf.release();
235238
}
236239

237-
void FileRemapper::remap(FileEntryRef file, const FileEntry *newfile) {
238-
assert(newfile);
240+
void FileRemapper::remap(FileEntryRef file, FileEntryRef newfile) {
239241
Target &targ = FromToMappings[file];
240242
resetTarget(targ);
241243
targ = newfile;
@@ -263,7 +265,7 @@ void FileRemapper::resetTarget(Target &targ) {
263265
if (llvm::MemoryBuffer *oldmem = targ.dyn_cast<llvm::MemoryBuffer *>()) {
264266
delete oldmem;
265267
} else {
266-
const FileEntry *toFE = targ.get<const FileEntry *>();
268+
FileEntryRef toFE = targ.get<FileEntryRef>();
267269
ToFromMappings.erase(toFE);
268270
}
269271
}

0 commit comments

Comments
 (0)