@@ -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<const FileEntry * , const FileEntry *> > pairs;
63
+ std::vector<std::pair<FileEntryRef , const FileEntry *> > pairs;
64
64
65
65
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBuf =
66
66
llvm::MemoryBuffer::getFile (infoFile, /* IsText=*/ true );
@@ -78,7 +78,7 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
78
78
Diag);
79
79
StringRef toFilename = lines[idx+2 ];
80
80
81
- llvm::ErrorOr< const FileEntry *> origFE = FileMgr->getFile (fromFilename);
81
+ auto origFE = FileMgr->getOptionalFileRef (fromFilename);
82
82
if (!origFE) {
83
83
if (ignoreIfFilesChanged)
84
84
continue ;
@@ -91,7 +91,7 @@ bool FileRemapper::initFromFile(StringRef filePath, DiagnosticsEngine &Diag,
91
91
return report (" File does not exist: " + toFilename, Diag);
92
92
}
93
93
94
- if ((uint64_t )(* origFE) ->getModificationTime () != timeModified) {
94
+ if ((uint64_t )origFE->getModificationTime () != timeModified) {
95
95
if (ignoreIfFilesChanged)
96
96
continue ;
97
97
return report (" File was modified: " + fromFilename, Diag);
@@ -128,11 +128,11 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
128
128
for (MappingsTy::iterator
129
129
I = FromToMappings.begin (), E = FromToMappings.end (); I != E; ++I) {
130
130
131
- const FileEntry * origFE = I->first ;
132
- SmallString<200 > origPath = StringRef (origFE-> getName ());
131
+ FileEntryRef origFE = I->first ;
132
+ SmallString<200 > origPath = StringRef (origFE. getName ());
133
133
fs::make_absolute (origPath);
134
134
infoOut << origPath << ' \n ' ;
135
- infoOut << (uint64_t )origFE-> getModificationTime () << ' \n ' ;
135
+ infoOut << (uint64_t )origFE. getModificationTime () << ' \n ' ;
136
136
137
137
if (const FileEntry *FE = I->second .dyn_cast <const FileEntry *>()) {
138
138
SmallString<200 > newPath = StringRef (FE->getName ());
@@ -143,8 +143,8 @@ bool FileRemapper::flushToFile(StringRef outputPath, DiagnosticsEngine &Diag) {
143
143
SmallString<64 > tempPath;
144
144
int fd;
145
145
if (fs::createTemporaryFile (
146
- path::filename (origFE-> getName ()),
147
- path::extension (origFE-> getName ()).drop_front (), fd, tempPath,
146
+ path::filename (origFE. getName ()),
147
+ path::extension (origFE. getName ()).drop_front (), fd, tempPath,
148
148
llvm::sys::fs::OF_Text))
149
149
return report (" Could not create file: " + tempPath.str (), Diag);
150
150
@@ -171,14 +171,14 @@ bool FileRemapper::overwriteOriginal(DiagnosticsEngine &Diag,
171
171
172
172
for (MappingsTy::iterator
173
173
I = FromToMappings.begin (), E = FromToMappings.end (); I != E; ++I) {
174
- const FileEntry * origFE = I->first ;
174
+ FileEntryRef origFE = I->first ;
175
175
assert (I->second .is <llvm::MemoryBuffer *>());
176
- if (!fs::exists (origFE-> getName ()))
177
- return report (StringRef (" File does not exist: " ) + origFE-> getName (),
176
+ if (!fs::exists (origFE. getName ()))
177
+ return report (StringRef (" File does not exist: " ) + origFE. getName (),
178
178
Diag);
179
179
180
180
std::error_code EC;
181
- llvm::raw_fd_ostream Out (origFE-> getName (), EC, llvm::sys::fs::OF_None);
181
+ llvm::raw_fd_ostream Out (origFE. getName (), EC, llvm::sys::fs::OF_None);
182
182
if (EC)
183
183
return report (EC.message (), Diag);
184
184
@@ -197,11 +197,11 @@ void FileRemapper::forEachMapping(
197
197
CaptureBuffer) const {
198
198
for (auto &Mapping : FromToMappings) {
199
199
if (const FileEntry *FE = Mapping.second .dyn_cast <const FileEntry *>()) {
200
- CaptureFile (Mapping.first -> getName (), FE->getName ());
200
+ CaptureFile (Mapping.first . getName (), FE->getName ());
201
201
continue ;
202
202
}
203
203
CaptureBuffer (
204
- Mapping.first -> getName (),
204
+ Mapping.first . getName (),
205
205
Mapping.second .get <llvm::MemoryBuffer *>()->getMemBufferRef ());
206
206
}
207
207
}
@@ -210,10 +210,10 @@ void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const {
210
210
for (MappingsTy::const_iterator
211
211
I = FromToMappings.begin (), E = FromToMappings.end (); I != E; ++I) {
212
212
if (const FileEntry *FE = I->second .dyn_cast <const FileEntry *>()) {
213
- PPOpts.addRemappedFile (I->first -> getName (), FE->getName ());
213
+ PPOpts.addRemappedFile (I->first . getName (), FE->getName ());
214
214
} else {
215
215
llvm::MemoryBuffer *mem = I->second .get <llvm::MemoryBuffer *>();
216
- PPOpts.addRemappedFile (I->first -> getName (), mem);
216
+ PPOpts.addRemappedFile (I->first . getName (), mem);
217
217
}
218
218
}
219
219
@@ -222,38 +222,38 @@ void FileRemapper::applyMappings(PreprocessorOptions &PPOpts) const {
222
222
223
223
void FileRemapper::remap (StringRef filePath,
224
224
std::unique_ptr<llvm::MemoryBuffer> memBuf) {
225
- remap (getOriginalFile (filePath), std::move (memBuf));
225
+ OptionalFileEntryRef File = getOriginalFile (filePath);
226
+ assert (File);
227
+ remap (*File, std::move (memBuf));
226
228
}
227
229
228
- void FileRemapper::remap (const FileEntry * file,
230
+ void FileRemapper::remap (FileEntryRef file,
229
231
std::unique_ptr<llvm::MemoryBuffer> memBuf) {
230
- assert (file);
231
232
Target &targ = FromToMappings[file];
232
233
resetTarget (targ);
233
234
targ = memBuf.release ();
234
235
}
235
236
236
- void FileRemapper::remap (const FileEntry * file, const FileEntry *newfile) {
237
- assert (file && newfile);
237
+ void FileRemapper::remap (FileEntryRef file, const FileEntry *newfile) {
238
+ assert (newfile);
238
239
Target &targ = FromToMappings[file];
239
240
resetTarget (targ);
240
241
targ = newfile;
241
- ToFromMappings[ newfile] = file;
242
+ ToFromMappings. insert ({ newfile, file}) ;
242
243
}
243
244
244
- const FileEntry * FileRemapper::getOriginalFile (StringRef filePath) {
245
- const FileEntry *file = nullptr ;
246
- if (auto fileOrErr = FileMgr-> getFile (filePath) )
247
- file = *fileOrErr ;
245
+ OptionalFileEntryRef FileRemapper::getOriginalFile (StringRef filePath) {
246
+ OptionalFileEntryRef File = FileMgr-> getOptionalFileRef (filePath) ;
247
+ if (!File )
248
+ return std::nullopt ;
248
249
// If we are updating a file that overridden an original file,
249
250
// actually update the original file.
250
- llvm::DenseMap<const FileEntry *, const FileEntry *>::iterator
251
- I = ToFromMappings.find (file);
251
+ auto I = ToFromMappings.find (*File);
252
252
if (I != ToFromMappings.end ()) {
253
- file = I->second ;
254
- assert (FromToMappings.contains (file ) && " Original file not in mappings!" );
253
+ *File = I->second ;
254
+ assert (FromToMappings.contains (*File ) && " Original file not in mappings!" );
255
255
}
256
- return file ;
256
+ return File ;
257
257
}
258
258
259
259
void FileRemapper::resetTarget (Target &targ) {
0 commit comments