r248069 - Refactor ASTReader::getSourceDescriptor(const Module &) into a constructor

Adrian Prantl via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 18 17:10:33 PDT 2015


Author: adrian
Date: Fri Sep 18 19:10:32 2015
New Revision: 248069

URL: http://llvm.org/viewvc/llvm-project?rev=248069&view=rev
Log:
Refactor ASTReader::getSourceDescriptor(const Module &) into a constructor
of ASTSourceDescriptor. It was effectively a static function.

NFC.

Modified:
    cfe/trunk/include/clang/AST/ExternalASTSource.h
    cfe/trunk/include/clang/Serialization/ASTReader.h
    cfe/trunk/lib/AST/ExternalASTSource.cpp
    cfe/trunk/lib/CodeGen/CGDebugInfo.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=248069&r1=248068&r2=248069&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ExternalASTSource.h (original)
+++ cfe/trunk/include/clang/AST/ExternalASTSource.h Fri Sep 18 19:10:32 2015
@@ -142,19 +142,23 @@ 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.
+  /// Abstracts clang modules and precompiled header files and holds
+  /// everything needed to generate debug info for an imported module
+  /// or PCH.
   struct ASTSourceDescriptor {
+    ASTSourceDescriptor(std::string Name, std::string Path, std::string ASTFile,
+                        uint64_t Signature)
+        : ModuleName(Name), Path(Path), ASTFile(ASTFile),
+          Signature(Signature){};
+    ASTSourceDescriptor(const Module &M);
     std::string ModuleName;
     std::string Path;
     std::string ASTFile;
-    uint64_t Signature;
+    uint64_t Signature = 0;
   };
 
-  /// \brief Return a descriptor for the corresponding module, if one exists.
+  /// 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/Serialization/ASTReader.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTReader.h?rev=248069&r1=248068&r2=248069&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTReader.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTReader.h Fri Sep 18 19:10:32 2015
@@ -1889,8 +1889,6 @@ public:
 
   /// \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.

Modified: cfe/trunk/lib/AST/ExternalASTSource.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExternalASTSource.cpp?rev=248069&r1=248068&r2=248069&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExternalASTSource.cpp (original)
+++ cfe/trunk/lib/AST/ExternalASTSource.cpp Fri Sep 18 19:10:32 2015
@@ -16,6 +16,7 @@
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclarationName.h"
+#include "clang/Basic/Module.h"
 #include "llvm/Support/ErrorHandling.h"
 
 using namespace clang;
@@ -27,9 +28,12 @@ ExternalASTSource::getSourceDescriptor(u
   return None;
 }
 
-ExternalASTSource::ASTSourceDescriptor
-ExternalASTSource::getSourceDescriptor(const Module &M) {
-  return ASTSourceDescriptor();
+ExternalASTSource::ASTSourceDescriptor::ASTSourceDescriptor(const Module &M)
+    : ModuleName(M.getFullModuleName()), Signature(M.Signature) {
+  if (M.Directory)
+    Path = M.Directory->getName();
+  if (auto *File = M.getASTFile())
+    ASTFile = File->getName();
 }
 
 void ExternalASTSource::FindFileRegionDecls(FileID File, unsigned Offset,

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=248069&r1=248068&r2=248069&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Sep 18 19:10:32 2015
@@ -3391,8 +3391,7 @@ void CGDebugInfo::EmitUsingDecl(const Us
 }
 
 void CGDebugInfo::EmitImportDecl(const ImportDecl &ID) {
-  auto *Reader = CGM.getContext().getExternalSource();
-  auto Info = Reader->getSourceDescriptor(*ID.getImportedModule());
+  auto Info = ExternalASTSource::ASTSourceDescriptor(*ID.getImportedModule());
   DBuilder.createImportedDeclaration(
       getCurrentContextDescriptor(cast<Decl>(ID.getDeclContext())),
       getOrCreateModuleRef(Info, DebugTypeExtRefs),

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=248069&r1=248068&r2=248069&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Sep 18 19:10:32 2015
@@ -7403,33 +7403,17 @@ unsigned ASTReader::getModuleFileID(Modu
   return (I - PCHModules.end()) << 1;
 }
 
-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);
+    return ExternalASTSource::ASTSourceDescriptor(*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 ASTReader::ASTSourceDescriptor(
+        MF.OriginalSourceFileName, MF.OriginalDir, MF.FileName, MF.Signature);
   }
   return None;
 }




More information about the cfe-commits mailing list