@@ -60,7 +60,7 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
60
60
if (!llvm::sys::fs::exists (infoFile))
61
61
return false ;
62
62
63
- std::vector<std::pair<FileEntryRef, const FileEntry *> > pairs;
63
+ std::vector<std::pair<FileEntryRef, FileEntryRef> > pairs;
64
64
65
65
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBuf =
66
66
llvm::MemoryBuffer::getFile (infoFile, /* IsText=*/ true );
@@ -84,7 +84,7 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
84
84
continue ;
85
85
return report (" File does not exist: " + fromFilename, Diag);
86
86
}
87
- llvm::ErrorOr< const FileEntry *> newFE = FileMgr->getFile (toFilename);
87
+ auto newFE = FileMgr->getOptionalFileRef (toFilename);
88
88
if (!newFE) {
89
89
if (ignoreIfFilesChanged)
90
90
continue ;
@@ -134,8 +134,9 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
134
134
infoOut << origPath << ' \n ' ;
135
135
infoOut << (uint64_t )origFE.getModificationTime () << ' \n ' ;
136
136
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 ());
139
140
fs::make_absolute (newPath);
140
141
infoOut << newPath << ' \n ' ;
141
142
} else {
@@ -153,10 +154,10 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
153
154
newOut.write (mem->getBufferStart (), mem->getBufferSize ());
154
155
newOut.close ();
155
156
156
- auto newE = FileMgr->getFile (tempPath);
157
+ auto newE = FileMgr->getOptionalFileRef (tempPath);
157
158
if (newE) {
158
159
remap (origFE, *newE);
159
- infoOut << (* newE) ->getName () << ' \n ' ;
160
+ infoOut << newE->getName () << ' \n ' ;
160
161
}
161
162
}
162
163
}
@@ -196,8 +197,9 @@ void FileRemapper::forEachMapping(
196
197
llvm::function_ref<void(StringRef, const llvm::MemoryBufferRef &)>
197
198
CaptureBuffer) const {
198
199
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 ());
201
203
continue ;
202
204
}
203
205
CaptureBuffer (
@@ -209,8 +211,9 @@ void FileRemapper::forEachMapping(
209
211
void FileRemapper::applyMappings (PreprocessorOptions &PPOpts) const {
210
212
for (MappingsTy::const_iterator
211
213
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 ());
214
217
} else {
215
218
llvm::MemoryBuffer *mem = I->second .get <llvm::MemoryBuffer *>();
216
219
PPOpts.addRemappedFile (I->first .getName (), mem);
@@ -234,8 +237,7 @@ void FileRemapper::remap(FileEntryRef file,
234
237
targ = memBuf.release ();
235
238
}
236
239
237
- void FileRemapper::remap (FileEntryRef file, const FileEntry *newfile) {
238
- assert (newfile);
240
+ void FileRemapper::remap (FileEntryRef file, FileEntryRef newfile) {
239
241
Target &targ = FromToMappings[file];
240
242
resetTarget (targ);
241
243
targ = newfile;
@@ -263,7 +265,7 @@ void FileRemapper::resetTarget(Target &targ) {
263
265
if (llvm::MemoryBuffer *oldmem = targ.dyn_cast <llvm::MemoryBuffer *>()) {
264
266
delete oldmem;
265
267
} else {
266
- const FileEntry * toFE = targ.get <const FileEntry * >();
268
+ FileEntryRef toFE = targ.get <FileEntryRef >();
267
269
ToFromMappings.erase (toFE);
268
270
}
269
271
}
0 commit comments