[cfe-commits] r165160 - in /cfe/trunk: include/clang-c/Index.h tools/c-index-test/c-index-test.c tools/libclang/IndexDecl.cpp tools/libclang/Indexing.cpp tools/libclang/IndexingContext.cpp tools/libclang/IndexingContext.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Oct 3 14:05:45 PDT 2012


Author: akirtzidis
Date: Wed Oct  3 16:05:44 2012
New Revision: 165160

URL: http://llvm.org/viewvc/llvm-project?rev=165160&view=rev
Log:
[libclang] Simplify indexing of module imports by handling implicit
imports via ImportDecls.

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/IndexDecl.cpp
    cfe/trunk/tools/libclang/Indexing.cpp
    cfe/trunk/tools/libclang/IndexingContext.cpp
    cfe/trunk/tools/libclang/IndexingContext.h

Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=165160&r1=165159&r2=165160&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Wed Oct  3 16:05:44 2012
@@ -4937,12 +4937,7 @@
    * \brief Non-zero if an inclusion directive was automatically turned into
    * a module import.
    */
-  int isIncludeDirective;
-  /**
-   * \brief The name of the file being included or the module being imported,
-   * as written in the source code.
-   */
-  const char *sourceName;
+  int isImplicit;
   /**
    * \brief The actual name of the module or submodule being imported.
    * The syntax is a sequence of identifiers separated by dots, e.g "std.vector"

Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=165160&r1=165159&r2=165160&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Wed Oct  3 16:05:44 2012
@@ -2359,10 +2359,9 @@
   printCXIndexFile((CXIdxClientFile)info->file);
   printf(" | loc: ");
   printCXIndexLoc(info->loc, client_data);
-  printf(" | module name: \"%s\"", info->moduleName);
-  printf(" | source name: \"%s\"", info->sourceName);
-  printf(" | isModule: %d | isIncludeDirective: %d\n",
-         info->isModule, info->isIncludeDirective);
+  printf(" | name: \"%s\"", info->moduleName);
+  printf(" | isModule: %d | isImplicit: %d\n",
+         info->isModule, info->isImplicit);
 
   return (CXIdxClientFile)info->file;
 }

Modified: cfe/trunk/tools/libclang/IndexDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexDecl.cpp?rev=165160&r1=165159&r2=165160&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexDecl.cpp (original)
+++ cfe/trunk/tools/libclang/IndexDecl.cpp Wed Oct  3 16:05:44 2012
@@ -10,7 +10,6 @@
 #include "IndexingContext.h"
 
 #include "clang/AST/DeclVisitor.h"
-#include "clang/Basic/Module.h"
 
 using namespace clang;
 using namespace cxindex;
@@ -308,10 +307,7 @@
   }
 
   bool VisitImportDecl(ImportDecl *D) {
-    Module *Imported = D->getImportedModule();
-    if (Imported)
-      IndexCtx.importedModule(D->getLocation(), Imported->getFullModuleName(),
-                              /*isIncludeDirective=*/false, Imported);
+    IndexCtx.importedModule(D);
     return true;
   }
 };

Modified: cfe/trunk/tools/libclang/Indexing.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/Indexing.cpp?rev=165160&r1=165159&r2=165160&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/Indexing.cpp (original)
+++ cfe/trunk/tools/libclang/Indexing.cpp Wed Oct  3 16:05:44 2012
@@ -74,8 +74,7 @@
                                   StringRef RelativePath,
                                   const Module *Imported) {
     if (Imported) {
-      IndexCtx.importedModule(HashLoc, FileName, /*isIncludeDirective=*/true,
-                              Imported);
+      // We handle implicit imports via ImportDecls.
       return;
     }
 

Modified: cfe/trunk/tools/libclang/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.cpp?rev=165160&r1=165159&r2=165160&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.cpp (original)
+++ cfe/trunk/tools/libclang/IndexingContext.cpp Wed Oct  3 16:05:44 2012
@@ -253,21 +253,20 @@
   FileMap[File] = idxFile;
 }
 
-void IndexingContext::importedModule(SourceLocation Loc,
-                                     StringRef name, bool isIncludeDirective,
-                                     const Module *module) {
+void IndexingContext::importedModule(const ImportDecl *ImportD) {
   if (!CB.importedASTFile)
     return;
 
-  std::string ModuleName = module->getFullModuleName();
+  Module *Mod = ImportD->getImportedModule();
+  if (!Mod)
+    return;
+  std::string ModuleName = Mod->getFullModuleName();
 
-  ScratchAlloc SA(*this);
   CXIdxImportedASTFileInfo Info = {
-                                    (CXFile)module->getASTFile(),
-                                    getIndexLoc(Loc),
+                                    (CXFile)Mod->getASTFile(),
+                                    getIndexLoc(ImportD->getLocation()),
                                     /*isModule=*/true,
-                                    isIncludeDirective,
-                                    SA.toCStr(name),
+                                    ImportD->isImplicit(),
                                     ModuleName.c_str(),
                                   };
   CXIdxClientASTFile astFile = CB.importedASTFile(ClientData, &Info);
@@ -1110,6 +1109,8 @@
     return false;
   if (isa<ObjCMethodDecl>(D))
     return false;
+  if (isa<ImportDecl>(D))
+    return false;
   return true;
 }
 

Modified: cfe/trunk/tools/libclang/IndexingContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/IndexingContext.h?rev=165160&r1=165159&r2=165160&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/IndexingContext.h (original)
+++ cfe/trunk/tools/libclang/IndexingContext.h Wed Oct  3 16:05:44 2012
@@ -382,9 +382,7 @@
                       StringRef filename, const FileEntry *File,
                       bool isImport, bool isAngled);
 
-  void importedModule(SourceLocation Loc,
-                      StringRef name, bool isIncludeDirective,
-                      const Module *module);
+  void importedModule(const ImportDecl *ImportD);
 
   void startedTranslationUnit();
 





More information about the cfe-commits mailing list