r241083 - Add a function to ExternalASTSource that returns a descriptor that
Adrian Prantl
aprantl at apple.com
Tue Jun 30 10:39:44 PDT 2015
Author: adrian
Date: Tue Jun 30 12:39:43 2015
New Revision: 241083
URL: http://llvm.org/viewvc/llvm-project?rev=241083&view=rev
Log:
Add a function to ExternalASTSource that returns a descriptor that
abstracts the commonalities between modules and PCH files that are
needed to emit debug info for a module or precompiled header.
Modified:
cfe/trunk/include/clang/AST/ExternalASTSource.h
cfe/trunk/include/clang/Basic/Module.h
cfe/trunk/include/clang/Serialization/ASTReader.h
cfe/trunk/lib/AST/ExternalASTSource.cpp
cfe/trunk/lib/Basic/Module.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
Modified: cfe/trunk/include/clang/AST/ExternalASTSource.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExternalASTSource.h?rev=241083&r1=241082&r2=241083&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExternalASTSource.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTSource.h Tue Jun 30 12:39:43 2015
@@ -156,6 +156,20 @@ public:
/// \brief Retrieve the module that corresponds to the given module ID.
virtual Module *getModule(unsigned ID) { return nullptr; }
+ /// \brief Holds everything needed to generate debug info for an
+ /// imported module or precompiled header file.
+ struct ASTSourceDescriptor {
+ std::string ModuleName;
+ std::string Path;
+ std::string ASTFile;
+ uint64_t Signature;
+ };
+
+ /// \brief Return a descriptor for the corresponding module, if one exists.
+ virtual llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID);
+ /// \brief Return a descriptor for the module.
+ virtual ASTSourceDescriptor getSourceDescriptor(const Module &M);
+
/// \brief Finds all declarations lexically contained within the given
/// DeclContext, after applying an optional filter predicate.
///
Modified: cfe/trunk/include/clang/Basic/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=241083&r1=241082&r2=241083&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Tue Jun 30 12:39:43 2015
@@ -66,6 +66,9 @@ public:
/// \brief The umbrella header or directory.
llvm::PointerUnion<const DirectoryEntry *, const FileEntry *> Umbrella;
+ /// \brief The module signature.
+ uint64_t Signature;
+
/// \brief The name of the umbrella entry, as written in the module map.
std::string UmbrellaAsWritten;
Modified: cfe/trunk/include/clang/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=241083&r1=241082&r2=241083&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Tue Jun 30 12:39:43 2015
@@ -1846,6 +1846,11 @@ public:
/// Note: overrides method in ExternalASTSource
Module *getModule(unsigned ID) override;
+ /// \brief Return a descriptor for the corresponding module.
+ llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
+ /// \brief Return a descriptor for the module.
+ ASTSourceDescriptor getSourceDescriptor(const Module &M) override;
+
/// \brief Retrieve a selector from the given module with its local ID
/// number.
Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
Modified: cfe/trunk/lib/AST/ExternalASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTSource.cpp?rev=241083&r1=241082&r2=241083&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExternalASTSource.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTSource.cpp Tue Jun 30 12:39:43 2015
@@ -22,6 +22,16 @@ using namespace clang;
ExternalASTSource::~ExternalASTSource() { }
+llvm::Optional<ExternalASTSource::ASTSourceDescriptor>
+ExternalASTSource::getSourceDescriptor(unsigned ID) {
+ return None;
+}
+
+ExternalASTSource::ASTSourceDescriptor
+ExternalASTSource::getSourceDescriptor(const Module &M) {
+ return ASTSourceDescriptor();
+}
+
void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,
unsigned Length,
SmallVectorImpl<Decl *> &Decls) {}
Modified: cfe/trunk/lib/Basic/Module.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Module.cpp?rev=241083&r1=241082&r2=241083&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Module.cpp (original)
+++ cfe/trunk/lib/Basic/Module.cpp Tue Jun 30 12:39:43 2015
@@ -27,7 +27,7 @@ using namespace clang;
Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
bool IsFramework, bool IsExplicit, unsigned VisibilityID)
: Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), Directory(),
- Umbrella(), ASTFile(nullptr), VisibilityID(VisibilityID),
+ Umbrella(), Signature(0), ASTFile(nullptr), VisibilityID(VisibilityID),
IsMissingRequirement(false), IsAvailable(true), IsFromModuleFile(false),
IsFramework(IsFramework), IsExplicit(IsExplicit), IsSystem(false),
IsExternC(false), IsInferred(false), InferSubmodules(false),
Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=241083&r1=241082&r2=241083&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Tue Jun 30 12:39:43 2015
@@ -4269,6 +4269,7 @@ ASTReader::ReadSubmoduleBlock(ModuleFile
CurrentModule->setASTFile(F.File);
}
+ CurrentModule->Signature = F.Signature;
CurrentModule->IsFromModuleFile = true;
CurrentModule->IsSystem = IsSystem || CurrentModule->IsSystem;
CurrentModule->IsExternC = IsExternC;
@@ -7366,6 +7367,37 @@ Module *ASTReader::getModule(unsigned ID
return getSubmodule(ID);
}
+ExternalASTSource::ASTSourceDescriptor
+ASTReader::getSourceDescriptor(const Module &M) {
+ StringRef Dir, Filename;
+ if (M.Directory)
+ Dir = M.Directory->getName();
+ if (auto *File = M.getASTFile())
+ Filename = File->getName();
+ return ASTReader::ASTSourceDescriptor{
+ M.getFullModuleName(), Dir, Filename,
+ M.Signature
+ };
+}
+
+llvm::Optional<ExternalASTSource::ASTSourceDescriptor>
+ASTReader::getSourceDescriptor(unsigned ID) {
+ if (const Module *M = getSubmodule(ID))
+ return getSourceDescriptor(*M);
+
+ // If there is only a single PCH, return it instead.
+ // Chained PCH are not suported.
+ if (ModuleMgr.size() == 1) {
+ ModuleFile &MF = ModuleMgr.getPrimaryModule();
+ return ASTReader::ASTSourceDescriptor{
+ MF.OriginalSourceFileName, MF.OriginalDir,
+ MF.FileName,
+ MF.Signature
+ };
+ }
+ return None;
+}
+
Selector ASTReader::getLocalSelector(ModuleFile &M, unsigned LocalID) {
return DecodeSelector(getGlobalSelectorID(M, LocalID));
}
More information about the cfe-commits
mailing list