]> granicus.if.org Git - clang/commitdiff
[libclang] Invoke a ppIncludedFile callback when indexing implicit module imports.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 18 Oct 2012 00:17:05 +0000 (00:17 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 18 Oct 2012 00:17:05 +0000 (00:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166161 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang-c/Index.h
test/Index/index-module.m
tools/c-index-test/c-index-test.c
tools/libclang/Indexing.cpp
tools/libclang/IndexingContext.cpp
tools/libclang/IndexingContext.h

index b122faa4431bde015fe1148cb8c3168a462e07f3..650e63394027093b9dddddca620736ee6515fb87 100644 (file)
@@ -4985,6 +4985,11 @@ typedef struct {
   CXFile file;
   int isImport;
   int isAngled;
+  /**
+   * \brief Non-zero if the directive was automatically turned into a module
+   * import.
+   */
+  int isModuleImport;
 } CXIdxIncludedFileInfo;
 
 /**
index 04eb99ac194ba841bc38fabfd7ba549aa4f874ce..0af4e37f3c3d18609ef0ae75386b45b2f99f57ef 100644 (file)
@@ -9,6 +9,7 @@ int glob;
 
 // CHECK-NOT: [indexDeclaration]
 // CHECK: [importedASTFile]: [[PCM:.*[/\\]DependsOnModule\.pcm]] | loc: 2:2 | name: "DependsOnModule" | isImplicit: 1
+// CHECK-NEXT: [ppIncludedFile]: {{.*}}/Modules/Inputs/DependsOnModule.framework{{[/\\]}}Headers{{[/\\]}}DependsOnModule.h | name: "DependsOnModule/DependsOnModule.h" | hash loc: 2:1 | isImport: 0 | isAngled: 1 | isModule: 1
 // CHECK-NOT: [indexDeclaration]
 // CHECK: [importedASTFile]: [[PCM]] | loc: 3:1 | name: "DependsOnModule" | isImplicit: 0
 // CHECK-NEXT: [indexDeclaration]: kind: variable | name: glob | {{.*}} | loc: 4:5 
@@ -18,6 +19,7 @@ int glob;
 
 // CHECK-DMOD:      [startedTranslationUnit]
 // CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_MODULE_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Headers[/\\]DependsOnModule\.h]] | {{.*}} | hash loc: <invalid>
+// CHECK-DMOD-NEXT: [ppIncludedFile]: {{.*}}/Modules/Inputs/Module.framework{{[/\\]}}Headers{{[/\\]}}Module.h | name: "Module/Module.h" | hash loc: {{.*}}/Modules/Inputs/DependsOnModule.framework{{[/\\]}}Headers{{[/\\]}}DependsOnModule.h:1:1 | isImport: 0 | isAngled: 1 | isModule: 1
 // CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_OTHER_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Headers[/\\]other\.h]] | {{.*}} | hash loc: <invalid>
 // CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_SUB_H:.*/Modules/Inputs/DependsOnModule\.framework[/\\]Frameworks[/\\]SubFramework\.framework[/\\]Headers[/\\]SubFramework\.h]] | {{.*}} | hash loc: <invalid>
 // CHECK-DMOD-NEXT: [ppIncludedFile]: [[DMOD_SUB_OTHER_H:.*/Modules/Inputs/DependsOnModule.framework[/\\]Frameworks/SubFramework\.framework/Headers/Other\.h]] | name: "SubFramework/Other.h" | hash loc: [[DMOD_SUB_H]]:1:1 | isImport: 0 | isAngled: 0
index c46ba74ce41f032e083f83cc776d8cab64823462..eda82d1872188b7b7391b295a0f30ac96ddd36ea 100644 (file)
@@ -2363,7 +2363,8 @@ static CXIdxClientFile index_ppIncludedFile(CXClientData client_data,
   printf(" | name: \"%s\"", info->filename);
   printf(" | hash loc: ");
   printCXIndexLoc(info->hashLoc, client_data);
-  printf(" | isImport: %d | isAngled: %d\n", info->isImport, info->isAngled);
+  printf(" | isImport: %d | isAngled: %d | isModule: %d\n",
+         info->isImport, info->isAngled, info->isModuleImport);
 
   return (CXIdxClientFile)info->file;
 }
index 887b5fc1ee3b1076f7eabc77ed052e5d31a6c839..36442fa232454d97c9a686828d5862015d0624bc 100644 (file)
@@ -73,14 +73,10 @@ public:
                                   StringRef SearchPath,
                                   StringRef RelativePath,
                                   const Module *Imported) {
-    if (Imported) {
-      // We handle implicit imports via ImportDecls.
-      return;
-    }
-
     bool isImport = (IncludeTok.is(tok::identifier) &&
             IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import);
-    IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled);
+    IndexCtx.ppIncludedFile(HashLoc, FileName, File, isImport, IsAngled,
+                            Imported);
   }
 
   /// MacroDefined - This hook is called whenever a macro definition is seen.
@@ -458,16 +454,15 @@ static void indexPreprocessingRecord(ASTUnit &Unit, IndexingContext &IdxCtx) {
     PreprocessedEntity *PPE = *I;
 
     if (InclusionDirective *ID = dyn_cast<InclusionDirective>(PPE)) {
-      if (!ID->importedModule()) {
-        SourceLocation Loc = ID->getSourceRange().getBegin();
-        // Modules have synthetic main files as input, give an invalid location
-        // if the location points to such a file.
-        if (isModuleFile && Unit.isInMainFileID(Loc))
-          Loc = SourceLocation();
-        IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
-                     ID->getFile(), ID->getKind() == InclusionDirective::Import,
-                     !ID->wasInQuotes());
-      }
+      SourceLocation Loc = ID->getSourceRange().getBegin();
+      // Modules have synthetic main files as input, give an invalid location
+      // if the location points to such a file.
+      if (isModuleFile && Unit.isInMainFileID(Loc))
+        Loc = SourceLocation();
+      IdxCtx.ppIncludedFile(Loc, ID->getFileName(),
+                            ID->getFile(),
+                            ID->getKind() == InclusionDirective::Import,
+                            !ID->wasInQuotes(), ID->importedModule());
     }
   }
 }
index 74b3cf362b133fd0f6992d16bdded7976baea032..09efebb62faa5e6d5e830463c55b5973c044071e 100644 (file)
@@ -240,7 +240,8 @@ void IndexingContext::enteredMainFile(const FileEntry *File) {
 void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
                                      StringRef filename,
                                      const FileEntry *File,
-                                     bool isImport, bool isAngled) {
+                                     bool isImport, bool isAngled,
+                                     bool isModuleImport) {
   if (!CB.ppIncludedFile)
     return;
 
@@ -248,7 +249,7 @@ void IndexingContext::ppIncludedFile(SourceLocation hashLoc,
   CXIdxIncludedFileInfo Info = { getIndexLoc(hashLoc),
                                  SA.toCStr(filename),
                                  (CXFile)File,
-                                 isImport, isAngled };
+                                 isImport, isAngled, isModuleImport };
   CXIdxClientFile idxFile = CB.ppIncludedFile(ClientData, &Info);
   FileMap[File] = idxFile;
 }
index 7671e6c2f1960980117ddd94a24cba0730ab174e..78a8abc2705876d1ed3353dcedb32e8d36b6ff1b 100644 (file)
@@ -369,7 +369,7 @@ public:
 
   void ppIncludedFile(SourceLocation hashLoc,
                       StringRef filename, const FileEntry *File,
-                      bool isImport, bool isAngled);
+                      bool isImport, bool isAngled, bool isModuleImport);
 
   void importedModule(const ImportDecl *ImportD);
   void importedPCH(const FileEntry *File);