Skip to content

Commit 257dbcd

Browse files
committed
Update Swift for the FileManager API change
Change Swift to work with the new FileManager API. It now returns and ErrorOr<FileEntry*> instead of just the raw pointer.
1 parent 862b18d commit 257dbcd

File tree

2 files changed

+31
-30
lines changed

2 files changed

+31
-30
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ ClangImporter::create(ASTContext &ctx,
11801180
bool ClangImporter::addSearchPath(StringRef newSearchPath, bool isFramework,
11811181
bool isSystem) {
11821182
clang::FileManager &fileMgr = Impl.Instance->getFileManager();
1183-
const clang::DirectoryEntry *entry = fileMgr.getDirectory(newSearchPath);
1183+
auto entry = fileMgr.getDirectory(newSearchPath);
11841184
if (!entry)
11851185
return true;
11861186

@@ -1189,8 +1189,8 @@ bool ClangImporter::addSearchPath(StringRef newSearchPath, bool isFramework,
11891189
headerSearchInfo.search_dir_end(),
11901190
[&](const clang::DirectoryLookup &lookup) -> bool {
11911191
if (isFramework)
1192-
return lookup.getFrameworkDir() == entry;
1193-
return lookup.getDir() == entry;
1192+
return lookup.getFrameworkDir() == *entry;
1193+
return lookup.getDir() == *entry;
11941194
});
11951195
if (exists) {
11961196
// Don't bother adding a search path that's already there. Clang would have
@@ -1199,7 +1199,7 @@ bool ClangImporter::addSearchPath(StringRef newSearchPath, bool isFramework,
11991199
}
12001200

12011201
auto kind = isSystem ? clang::SrcMgr::C_System : clang::SrcMgr::C_User;
1202-
headerSearchInfo.AddSearchPath({entry, kind, isFramework},
1202+
headerSearchInfo.AddSearchPath({*entry, kind, isFramework},
12031203
/*isAngled=*/true);
12041204

12051205
// In addition to changing the current preprocessor directly, we still need
@@ -1361,10 +1361,9 @@ bool ClangImporter::importHeader(StringRef header, ModuleDecl *adapter,
13611361
off_t expectedSize, time_t expectedModTime,
13621362
StringRef cachedContents, SourceLoc diagLoc) {
13631363
clang::FileManager &fileManager = Impl.Instance->getFileManager();
1364-
const clang::FileEntry *headerFile = fileManager.getFile(header,
1365-
/*OpenFile=*/true);
1366-
if (headerFile && headerFile->getSize() == expectedSize &&
1367-
headerFile->getModificationTime() == expectedModTime) {
1364+
auto headerFile = fileManager.getFile(header, /*OpenFile=*/true);
1365+
if (headerFile && (*headerFile)->getSize() == expectedSize &&
1366+
(*headerFile)->getModificationTime() == expectedModTime) {
13681367
return importBridgingHeader(header, adapter, diagLoc, false, true);
13691368
}
13701369

@@ -1397,8 +1396,7 @@ bool ClangImporter::importBridgingHeader(StringRef header, ModuleDecl *adapter,
13971396
}
13981397

13991398
clang::FileManager &fileManager = Impl.Instance->getFileManager();
1400-
const clang::FileEntry *headerFile = fileManager.getFile(header,
1401-
/*OpenFile=*/true);
1399+
auto headerFile = fileManager.getFile(header, /*OpenFile=*/true);
14021400
if (!headerFile) {
14031401
Impl.SwiftContext.Diags.diagnose(diagLoc, diag::bridging_header_missing,
14041402
header);
@@ -1474,9 +1472,10 @@ std::string ClangImporter::getBridgingHeaderContents(StringRef headerPath,
14741472
return "";
14751473
}
14761474

1477-
const clang::FileEntry *fileInfo = fileManager.getFile(headerPath);
1478-
fileSize = fileInfo->getSize();
1479-
fileModTime = fileInfo->getModificationTime();
1475+
if (auto fileInfo = fileManager.getFile(headerPath)) {
1476+
fileSize = (*fileInfo)->getSize();
1477+
fileModTime = (*fileInfo)->getModificationTime();
1478+
}
14801479
return result;
14811480
}
14821481

@@ -2410,8 +2409,7 @@ void ClangImporter::lookupBridgingHeaderDecls(
24102409
bool ClangImporter::lookupDeclsFromHeader(StringRef Filename,
24112410
llvm::function_ref<bool(ClangNode)> filter,
24122411
llvm::function_ref<void(Decl*)> receiver) const {
2413-
const clang::FileEntry *File =
2414-
getClangPreprocessor().getFileManager().getFile(Filename);
2412+
auto File = getClangPreprocessor().getFileManager().getFile(Filename);
24152413
if (!File)
24162414
return true;
24172415

@@ -2420,7 +2418,7 @@ bool ClangImporter::lookupDeclsFromHeader(StringRef Filename,
24202418
auto &ClangPP = getClangPreprocessor();
24212419

24222420
// Look up the header in the includes of the bridging header.
2423-
if (Impl.BridgeHeaderFiles.count(File)) {
2421+
if (Impl.BridgeHeaderFiles.count(*File)) {
24242422
auto headerFilter = [&](ClangNode ClangN) -> bool {
24252423
if (ClangN.isNull())
24262424
return false;
@@ -2429,7 +2427,7 @@ bool ClangImporter::lookupDeclsFromHeader(StringRef Filename,
24292427
if (ClangLoc.isInvalid())
24302428
return false;
24312429

2432-
if (ClangSM.getFileEntryForID(ClangSM.getFileID(ClangLoc)) != File)
2430+
if (ClangSM.getFileEntryForID(ClangSM.getFileID(ClangLoc)) != *File)
24332431
return false;
24342432

24352433
return filter(ClangN);
@@ -2439,7 +2437,7 @@ bool ClangImporter::lookupDeclsFromHeader(StringRef Filename,
24392437
return false;
24402438
}
24412439

2442-
clang::FileID FID = ClangSM.translateFile(File);
2440+
clang::FileID FID = ClangSM.translateFile(*File);
24432441
if (FID.isInvalid())
24442442
return false;
24452443

lib/Index/IndexRecord.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ static void addModuleDependencies(ArrayRef<ModuleDecl::ImportedModule> imports,
405405
case FileUnitKind::DWARFModule:
406406
case FileUnitKind::ClangModule: {
407407
auto *LFU = cast<LoadedFile>(FU);
408-
if (auto *F = fileMgr.getFile(LFU->getFilename())) {
408+
if (auto F = fileMgr.getFile(LFU->getFilename())) {
409409
std::string moduleName = mod->getNameStr();
410410
bool withoutUnitName = true;
411411
if (FU->getKind() == FileUnitKind::ClangModule) {
@@ -434,7 +434,7 @@ static void addModuleDependencies(ArrayRef<ModuleDecl::ImportedModule> imports,
434434
}
435435
clang::index::writer::OpaqueModule opaqMod =
436436
moduleNameScratch.createString(moduleName);
437-
unitWriter.addASTFileDependency(F, mod->isSystemModule(), opaqMod,
437+
unitWriter.addASTFileDependency(*F, mod->isSystemModule(), opaqMod,
438438
withoutUnitName);
439439
}
440440
break;
@@ -547,15 +547,15 @@ emitDataForSwiftSerializedModule(ModuleDecl *module,
547547
/*MainFile=*/nullptr, isSystem, /*IsModuleUnit=*/true,
548548
isDebugCompilation, targetTriple, sysrootPath, getModuleInfoFromOpaqueModule);
549549

550-
const clang::FileEntry *FE = fileMgr.getFile(filename);
550+
auto FE = fileMgr.getFile(filename);
551551
bool isSystemModule = module->isSystemModule();
552552
for (auto &pair : records) {
553553
std::string &recordFile = pair.first;
554554
std::string &groupName = pair.second;
555555
if (recordFile.empty())
556556
continue;
557557
clang::index::writer::OpaqueModule mod = &groupName;
558-
unitWriter.addRecordFile(recordFile, FE, isSystemModule, mod);
558+
unitWriter.addRecordFile(recordFile, *FE, isSystemModule, mod);
559559
}
560560

561561
ModuleDecl::ImportFilter importFilter;
@@ -585,15 +585,16 @@ recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
585585
auto &fileMgr = clangCI.getFileManager();
586586
auto *module = primarySourceFile->getParentModule();
587587
bool isSystem = module->isSystemModule();
588-
auto *mainFile = fileMgr.getFile(primarySourceFile->getFilename());
588+
auto mainFile = fileMgr.getFile(primarySourceFile->getFilename());
589589
// FIXME: Get real values for the following.
590590
StringRef swiftVersion;
591591
StringRef sysrootPath = clangCI.getHeaderSearchOpts().Sysroot;
592592

593-
IndexUnitWriter unitWriter(fileMgr, indexStorePath,
594-
"swift", swiftVersion, indexUnitToken, module->getNameStr(),
595-
mainFile, isSystem, /*isModuleUnit=*/false, isDebugCompilation,
596-
targetTriple, sysrootPath, getModuleInfoFromOpaqueModule);
593+
IndexUnitWriter unitWriter(
594+
fileMgr, indexStorePath, "swift", swiftVersion, indexUnitToken,
595+
module->getNameStr(), mainFile ? *mainFile : nullptr, isSystem,
596+
/*isModuleUnit=*/false, isDebugCompilation, targetTriple, sysrootPath,
597+
getModuleInfoFromOpaqueModule);
597598

598599
// Module dependencies.
599600
ModuleDecl::ImportFilter importFilter;
@@ -612,9 +613,11 @@ recordSourceFileUnit(SourceFile *primarySourceFile, StringRef indexUnitToken,
612613

613614
recordSourceFile(primarySourceFile, indexStorePath, diags,
614615
[&](StringRef recordFile, StringRef filename) {
615-
unitWriter.addRecordFile(recordFile, fileMgr.getFile(filename),
616-
module->isSystemModule(), /*Module=*/nullptr);
617-
});
616+
auto file = fileMgr.getFile(filename);
617+
unitWriter.addRecordFile(
618+
recordFile, file ? *file : nullptr,
619+
module->isSystemModule(), /*Module=*/nullptr);
620+
});
618621

619622
std::string error;
620623
if (unitWriter.write(error)) {

0 commit comments

Comments
 (0)