]> granicus.if.org Git - clang/commitdiff
[libclang] Simplify indexing of module imports by handling implicit
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 3 Oct 2012 21:05:44 +0000 (21:05 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 3 Oct 2012 21:05:44 +0000 (21:05 +0000)
imports via ImportDecls.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165160 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 6ef028a0777c51b19e872ab27863083f15c4b6de..fba2ba833701b94cd330178e5e1fb4647293700d 100644 (file)
@@ -4937,12 +4937,7 @@ typedef struct {
    * \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"
index 5b71e5ce25e548bda039546ac6f221e3d88b4170..f4efa900cb6d3b5570e94581f7cfabd52cbb4732 100644 (file)
@@ -2359,10 +2359,9 @@ static CXIdxClientFile index_importedASTFile(CXClientData client_data,
   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;
 }
index 65b0b16a37295012f4776ce553e891e2dbf163f0..513038119d242407e998250a7e01d13f43954890 100644 (file)
@@ -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 @@ public:
   }
 
   bool VisitImportDecl(ImportDecl *D) {
-    Module *Imported = D->getImportedModule();
-    if (Imported)
-      IndexCtx.importedModule(D->getLocation(), Imported->getFullModuleName(),
-                              /*isIncludeDirective=*/false, Imported);
+    IndexCtx.importedModule(D);
     return true;
   }
 };
index 6b9abbcf03ba5f78d189fe9a1df24e3dd94df8fb..6cf3a637acfdafe9514d9ed7fb7db9a6d6f92008 100644 (file)
@@ -74,8 +74,7 @@ public:
                                   StringRef RelativePath,
                                   const Module *Imported) {
     if (Imported) {
-      IndexCtx.importedModule(HashLoc, FileName, /*isIncludeDirective=*/true,
-                              Imported);
+      // We handle implicit imports via ImportDecls.
       return;
     }
 
index 3a3c010370bf99edea4a2f076dd543e786a386ab..c964e963c73ea2c69baa44f00f84ecf88384b937 100644 (file)
@@ -253,21 +253,20 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
   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 @@ bool IndexingContext::shouldIgnoreIfImplicit(const Decl *D) {
     return false;
   if (isa<ObjCMethodDecl>(D))
     return false;
+  if (isa<ImportDecl>(D))
+    return false;
   return true;
 }
 
index f74dd1ad0aea21e1c84d718a17df6bd046dd935d..e556d4dd5f755af05b8b82c37785374869901dc3 100644 (file)
@@ -382,9 +382,7 @@ public:
                       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();