]> granicus.if.org Git - clang/commitdiff
[libclang] When indexing, invoke the importedASTFile for PCH files as well.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 3 Oct 2012 21:05:51 +0000 (21:05 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 3 Oct 2012 21:05:51 +0000 (21:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165161 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Frontend/ASTUnit.h
lib/Frontend/ASTUnit.cpp
tools/libclang/Indexing.cpp
tools/libclang/IndexingContext.cpp
tools/libclang/IndexingContext.h

index e6ef410be45256de2725b6be3769918fc5c60a69..cadf2810b97e1652e8802799ce1ec0e08b3bf3cc 100644 (file)
@@ -623,6 +623,9 @@ public:
   /// \returns true if the iteration was complete or false if it was aborted.
   bool visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn);
 
+  /// \brief Get the PCH file if one was included.
+  const FileEntry *getPCHFile();
+
   llvm::MemoryBuffer *getBufferForFile(StringRef Filename,
                                        std::string *ErrorStr = 0);
 
index 79559a3dcdbd73c775d1c546c6b834f4462b494e..136e72a6c6c46b3d85f5699f789f9e2a40f5835a 100644 (file)
@@ -2816,6 +2816,42 @@ bool ASTUnit::visitLocalTopLevelDecls(void *context, DeclVisitorFn Fn) {
   return true;
 }
 
+namespace {
+struct PCHLocatorInfo {
+  serialization::ModuleFile *Mod;
+  PCHLocatorInfo() : Mod(0) {}
+};
+}
+
+static bool PCHLocator(serialization::ModuleFile &M, void *UserData) {
+  PCHLocatorInfo &Info = *static_cast<PCHLocatorInfo*>(UserData);
+  switch (M.Kind) {
+  case serialization::MK_Module:
+    return true; // skip dependencies.
+  case serialization::MK_PCH:
+    Info.Mod = &M;
+    return true; // found it.
+  case serialization::MK_Preamble:
+    return false; // look in dependencies.
+  case serialization::MK_MainFile:
+    return false; // look in dependencies.
+  }
+
+  return true;
+}
+
+const FileEntry *ASTUnit::getPCHFile() {
+  if (!Reader)
+    return 0;
+
+  PCHLocatorInfo Info;
+  Reader->getModuleManager().visit(PCHLocator, &Info);
+  if (Info.Mod)
+    return Info.Mod->File;
+
+  return 0;
+}
+
 void ASTUnit::PreambleData::countLines() const {
   NumLines = 0;
   if (empty())
index 6cf3a637acfdafe9514d9ed7fb7db9a6d6f92008..0b12d82d30a48c0e6a1937341445772d30137cac 100644 (file)
@@ -197,13 +197,20 @@ public:
 
   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
                                          StringRef InFile) {
+    PreprocessorOptions &PPOpts = CI.getPreprocessorOpts();
+
     // We usually disable the preprocessing record for indexing even if the
     // original preprocessing options had it enabled. Now that the indexing
     // Preprocessor has been created (without a preprocessing record), re-enable
     // the option in case modules are enabled, so that the detailed record
     // option can be propagated when the module file is generated.
     if (CI.getLangOpts().Modules && EnablePPDetailedRecordForModules)
-      CI.getPreprocessorOpts().DetailedRecord = true;
+      PPOpts.DetailedRecord = true;
+
+    if (!PPOpts.ImplicitPCHInclude.empty()) {
+      IndexCtx.importedPCH(
+                        CI.getFileManager().getFile(PPOpts.ImplicitPCHInclude));
+    }
 
     IndexCtx.setASTContext(CI.getASTContext());
     Preprocessor &PP = CI.getPreprocessor();
@@ -536,6 +543,9 @@ static void clang_indexTranslationUnit_Impl(void *UserData) {
 
   ASTUnit::ConcurrencyCheck Check(*Unit);
 
+  if (const FileEntry *PCHFile = Unit->getPCHFile())
+    IndexCtx->importedPCH(PCHFile);
+
   FileManager &FileMgr = Unit->getFileManager();
 
   if (Unit->getOriginalSourceFileName().empty())
index c964e963c73ea2c69baa44f00f84ecf88384b937..1186191cc3701da1dd0eaa88bb4d961762d75a4a 100644 (file)
@@ -273,6 +273,21 @@ void IndexingContext::importedModule(const ImportDecl *ImportD) {
   (void)astFile;
 }
 
+void IndexingContext::importedPCH(const FileEntry *File) {
+  if (!CB.importedASTFile)
+    return;
+
+  CXIdxImportedASTFileInfo Info = {
+                                    (CXFile)File,
+                                    getIndexLoc(SourceLocation()),
+                                    /*isModule=*/false,
+                                    /*isImplicit=*/false,
+                                    /*moduleName=*/NULL
+                                  };
+  CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info);
+  (void)astFile;
+}
+
 void IndexingContext::startedTranslationUnit() {
   CXIdxClientContainer idxCont = 0;
   if (CB.startedTranslationUnit)
index e556d4dd5f755af05b8b82c37785374869901dc3..e92894ae6606f2da888a551ad2f52b2b897fd73e 100644 (file)
@@ -383,6 +383,7 @@ public:
                       bool isImport, bool isAngled);
 
   void importedModule(const ImportDecl *ImportD);
+  void importedPCH(const FileEntry *File);
 
   void startedTranslationUnit();