dexonsmith updated this revision to Diff 301146.
dexonsmith retitled this revision from "Change Module::ASTFile and
ModuleFile::File => MaybeFileEntryRef, NFC" to "Change Module::ASTFile and
ModuleFile::File => Optional<FileEntryRef>, NFC".
dexonsmith edited the summary of this revision.
dexonsmith added a comment.
Rebase.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D89836/new/
https://reviews.llvm.org/D89836
Files:
clang/include/clang/Basic/FileEntry.h
clang/include/clang/Basic/Module.h
clang/include/clang/Serialization/ModuleFile.h
clang/include/clang/Serialization/ModuleManager.h
clang/lib/Basic/Module.cpp
clang/lib/Sema/SemaModule.cpp
clang/lib/Serialization/ModuleManager.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXIndexDataConsumer.cpp
Index: clang/tools/libclang/CXIndexDataConsumer.cpp
===================================================================
--- clang/tools/libclang/CXIndexDataConsumer.cpp
+++ clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -491,13 +491,12 @@
if (SrcMod->getTopLevelModule() == Mod->getTopLevelModule())
return;
- CXIdxImportedASTFileInfo Info = {
- static_cast<CXFile>(
- const_cast<FileEntry *>(Mod->getASTFile())),
- Mod,
- getIndexLoc(ImportD->getLocation()),
- ImportD->isImplicit()
- };
+ FileEntry *FE = nullptr;
+ if (auto File = Mod->getASTFile())
+ FE = const_cast<FileEntry *>(&File->getFileEntry());
+ CXIdxImportedASTFileInfo Info = {static_cast<CXFile>(FE), Mod,
+ getIndexLoc(ImportD->getLocation()),
+ ImportD->isImplicit()};
CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info);
(void)astFile;
}
Index: clang/tools/libclang/CIndex.cpp
===================================================================
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -8398,7 +8398,9 @@
if (!CXMod)
return nullptr;
Module *Mod = static_cast<Module *>(CXMod);
- return const_cast<FileEntry *>(Mod->getASTFile());
+ if (auto File = Mod->getASTFile())
+ return const_cast<FileEntry *>(&File->getFileEntry());
+ return nullptr;
}
CXModule clang_Module_getParent(CXModule CXMod) {
Index: clang/lib/Serialization/ModuleManager.cpp
===================================================================
--- clang/lib/Serialization/ModuleManager.cpp
+++ clang/lib/Serialization/ModuleManager.cpp
@@ -112,7 +112,7 @@
// Look for the file entry. This only fails if the expected size or
// modification time differ.
- const FileEntry *Entry;
+ Optional<FileEntryRef> Entry;
if (Type == MK_ExplicitModule || Type == MK_PrebuiltModule) {
// If we're not expecting to pull this file out of the module cache, it
// might have a different mtime due to being moved across filesystems in
@@ -288,7 +288,7 @@
if (modMap) {
StringRef ModuleName = victim->ModuleName;
if (Module *mod = modMap->findModule(ModuleName)) {
- mod->setASTFile(nullptr);
+ mod->setASTFile(None);
}
}
}
@@ -458,18 +458,18 @@
returnVisitState(State);
}
-bool ModuleManager::lookupModuleFile(StringRef FileName,
- off_t ExpectedSize,
+bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,
time_t ExpectedModTime,
- const FileEntry *&File) {
- File = nullptr;
+ Optional<FileEntryRef> &File) {
+ File = None;
if (FileName == "-")
return false;
// Open the file immediately to ensure there is no race between stat'ing and
// opening the file.
- auto FileOrErr = FileMgr.getFile(FileName, /*OpenFile=*/true,
- /*CacheFailure=*/false);
+ Optional<FileEntryRef> FileOrErr =
+ expectedToOptional(FileMgr.getFileRef(FileName, /*OpenFile=*/true,
+ /*CacheFailure=*/false));
if (!FileOrErr)
return false;
Index: clang/lib/Sema/SemaModule.cpp
===================================================================
--- clang/lib/Sema/SemaModule.cpp
+++ clang/lib/Sema/SemaModule.cpp
@@ -187,7 +187,7 @@
Diag(Path[0].second, diag::err_module_redefinition) << ModuleName;
if (M->DefinitionLoc.isValid())
Diag(M->DefinitionLoc, diag::note_prev_module_definition);
- else if (const auto *FE = M->getASTFile())
+ else if (Optional<FileEntryRef> FE = M->getASTFile())
Diag(M->DefinitionLoc, diag::note_prev_module_definition_from_ast_file)
<< FE->getName();
Mod = M;
Index: clang/lib/Basic/Module.cpp
===================================================================
--- clang/lib/Basic/Module.cpp
+++ clang/lib/Basic/Module.cpp
@@ -671,7 +671,7 @@
: Signature(M.Signature), ClangModule(&M) {
if (M.Directory)
Path = M.Directory->getName();
- if (auto *File = M.getASTFile())
+ if (auto File = M.getASTFile())
ASTFile = File->getName();
}
Index: clang/include/clang/Serialization/ModuleManager.h
===================================================================
--- clang/include/clang/Serialization/ModuleManager.h
+++ clang/include/clang/Serialization/ModuleManager.h
@@ -307,10 +307,8 @@
/// \returns True if a file exists but does not meet the size/
/// modification time criteria, false if the file is either available and
/// suitable, or is missing.
- bool lookupModuleFile(StringRef FileName,
- off_t ExpectedSize,
- time_t ExpectedModTime,
- const FileEntry *&File);
+ bool lookupModuleFile(StringRef FileName, off_t ExpectedSize,
+ time_t ExpectedModTime, Optional<FileEntryRef> &File);
/// View the graphviz representation of the module graph.
void viewGraph();
Index: clang/include/clang/Serialization/ModuleFile.h
===================================================================
--- clang/include/clang/Serialization/ModuleFile.h
+++ clang/include/clang/Serialization/ModuleFile.h
@@ -159,7 +159,7 @@
bool DidReadTopLevelSubmodule = false;
/// The file entry for the module file.
- const FileEntry *File = nullptr;
+ Optional<FileEntryRef> File;
/// The signature of the module file, which may be used instead of the size
/// and modification time to identify this particular file.
Index: clang/include/clang/Basic/Module.h
===================================================================
--- clang/include/clang/Basic/Module.h
+++ clang/include/clang/Basic/Module.h
@@ -15,6 +15,7 @@
#ifndef LLVM_CLANG_BASIC_MODULE_H
#define LLVM_CLANG_BASIC_MODULE_H
+#include "clang/Basic/FileEntry.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
@@ -160,7 +161,7 @@
/// The AST file if this is a top-level module which has a
/// corresponding serialized AST file, or null otherwise.
- const FileEntry *ASTFile = nullptr;
+ Optional<FileEntryRef> ASTFile;
/// The top-level headers associated with this module.
llvm::SmallSetVector<const FileEntry *, 2> TopHeaders;
@@ -529,14 +530,14 @@
}
/// The serialized AST file for this module, if one was created.
- const FileEntry *getASTFile() const {
+ Optional<FileEntryRef> getASTFile() const {
return getTopLevelModule()->ASTFile;
}
/// Set the serialized AST file for the top-level module of this module.
- void setASTFile(const FileEntry *File) {
- assert((File == nullptr || getASTFile() == nullptr ||
- getASTFile() == File) && "file path changed");
+ void setASTFile(Optional<FileEntryRef> File) {
+ assert((!File || !getASTFile() || getASTFile() == File) &&
+ "file path changed");
getTopLevelModule()->ASTFile = File;
}
Index: clang/include/clang/Basic/FileEntry.h
===================================================================
--- clang/include/clang/Basic/FileEntry.h
+++ clang/include/clang/Basic/FileEntry.h
@@ -48,6 +48,7 @@
inline unsigned getUID() const;
inline const llvm::sys::fs::UniqueID &getUniqueID() const;
inline time_t getModificationTime() const;
+ inline void closeFile() const;
/// Check if the underlying FileEntry is the same, intentially ignoring
/// whether the file was referenced with the same spelling of the filename.
@@ -291,6 +292,8 @@
return getFileEntry().getModificationTime();
}
+void FileEntryRef::closeFile() const { getFileEntry().closeFile(); }
+
} // end namespace clang
#endif // LLVM_CLANG_BASIC_FILEENTRY_H
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits