SourceLocation Loc);
/// \returns true to continue indexing, or false to abort.
+ ///
+ /// This will be called for each module reference in an import decl.
+ /// For "@import MyMod.SubMod", there will be a call for 'MyMod' with the
+ /// 'reference' role, and a call for 'SubMod' with the 'declaration' role.
virtual bool handleModuleOccurence(const ImportDecl *ImportD,
+ const Module *Mod,
SymbolRoleSet Roles, SourceLocation Loc);
virtual void finish() {}
namespace clang {
class Decl;
class MacroDefinitionRecord;
+class Module;
class SourceLocation;
class SourceManager;
bool generateUSRForMacro(StringRef MacroName, SourceLocation Loc,
const SourceManager &SM, SmallVectorImpl<char> &Buf);
+/// Generate a USR for a module, including the USR prefix.
+/// \returns true on error, false on success.
+bool generateFullUSRForModule(const Module *Mod, raw_ostream &OS);
+
+/// Generate a USR for a top-level module name, including the USR prefix.
+/// \returns true on error, false on success.
+bool generateFullUSRForTopLevelModuleName(StringRef ModName, raw_ostream &OS);
+
+/// Generate a USR fragment for a module.
+/// \returns true on error, false on success.
+bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS);
+
+/// Generate a USR fragment for a module name.
+/// \returns true on error, false on success.
+bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS);
+
} // namespace index
} // namespace clang
}
bool IndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
+ const Module *Mod,
SymbolRoleSet Roles,
SourceLocation Loc) {
return true;
RefE, RefD, DC);
}
+static void reportModuleReferences(const Module *Mod,
+ ArrayRef<SourceLocation> IdLocs,
+ const ImportDecl *ImportD,
+ IndexDataConsumer &DataConsumer) {
+ if (!Mod)
+ return;
+ reportModuleReferences(Mod->Parent, IdLocs.drop_back(), ImportD,
+ DataConsumer);
+ DataConsumer.handleModuleOccurence(ImportD, Mod,
+ (SymbolRoleSet)SymbolRole::Reference,
+ IdLocs.back());
+}
+
bool IndexingContext::importedModule(const ImportDecl *ImportD) {
+ if (ImportD->isInvalidDecl())
+ return true;
+
SourceLocation Loc;
auto IdLocs = ImportD->getIdentifierLocs();
if (!IdLocs.empty())
- Loc = IdLocs.front();
+ Loc = IdLocs.back();
else
Loc = ImportD->getLocation();
}
}
+ const Module *Mod = ImportD->getImportedModule();
+ if (!ImportD->isImplicit() && Mod->Parent && !IdLocs.empty()) {
+ reportModuleReferences(Mod->Parent, IdLocs.drop_back(), ImportD,
+ DataConsumer);
+ }
+
SymbolRoleSet Roles = (unsigned)SymbolRole::Declaration;
if (ImportD->isImplicit())
Roles |= (unsigned)SymbolRole::Implicit;
- return DataConsumer.handleModuleOccurence(ImportD, Roles, Loc);
+ return DataConsumer.handleModuleOccurence(ImportD, Mod, Roles, Loc);
}
bool IndexingContext::isTemplateImplicitInstantiation(const Decl *D) {
Out << MacroName;
return false;
}
+
+bool clang::index::generateFullUSRForModule(const Module *Mod,
+ raw_ostream &OS) {
+ if (!Mod->Parent)
+ return generateFullUSRForTopLevelModuleName(Mod->Name, OS);
+ if (generateFullUSRForModule(Mod->Parent, OS))
+ return true;
+ return generateUSRFragmentForModule(Mod, OS);
+}
+
+bool clang::index::generateFullUSRForTopLevelModuleName(StringRef ModName,
+ raw_ostream &OS) {
+ OS << getUSRSpacePrefix();
+ return generateUSRFragmentForModuleName(ModName, OS);
+}
+
+bool clang::index::generateUSRFragmentForModule(const Module *Mod,
+ raw_ostream &OS) {
+ return generateUSRFragmentForModuleName(Mod->Name, OS);
+}
+
+bool clang::index::generateUSRFragmentForModuleName(StringRef ModName,
+ raw_ostream &OS) {
+ OS << "@M@" << ModName;
+ return false;
+}
--- /dev/null
+
+void SubModA_func(void);
--- /dev/null
+
+void SubSubModA_func(void);
-module ModA { header "ModA.h" export * }
+module ModA {
+ header "ModA.h" export *
+
+ module SubModA {
+ header "SubModA.h"
+
+ module SubSubModA {
+ header "SubSubModA.h"
+ }
+ }
+}
// RUN: rm -rf %t.mcp
// RUN: c-index-test core -print-source-symbols -dump-imported-module-files -- %s -I %S/Inputs/module -fmodules -fmodules-cache-path=%t.mcp | FileCheck %s
-// CHECK: [[@LINE+1]]:9 | module/C | ModA | Decl |
+// CHECK: [[@LINE+1]]:9 | module/C | ModA | [[ModA_USR:c:@M@ModA]] | Decl |
@import ModA;
-// CHECK: [[@LINE+1]]:1 | module/C | ModA | Decl,Impl |
+// CHECK: [[@LINE+1]]:1 | module/C | ModA | [[ModA_USR]] | Decl,Impl |
#include "ModA.h"
+@import ModA.SubModA.SubSubModA;
+// CHECK: [[@LINE-1]]:9 | module/C | ModA | [[ModA_USR]] | Ref |
+// CHECK: [[@LINE-2]]:14 | module/C | ModA.SubModA | c:@M@ModA@M@SubModA | Ref |
+// CHECK: [[@LINE-3]]:22 | module/C | ModA.SubModA.SubSubModA | [[SubSubModA_USR:c:@M@ModA@M@SubModA@M@SubSubModA]] | Decl |
+#include "SubSubModA.h" // CHECK: [[@LINE]]:1 | module/C | ModA.SubModA.SubSubModA | [[SubSubModA_USR]] | Decl,Impl |
+
void foo() {
// CHECK: [[@LINE+1]]:3 | function/C | ModA_func | c:@F@ModA_func | {{.*}} | Ref,Call,RelCall,RelCont | rel: 1
ModA_func();
static void printSymbolInfo(SymbolInfo SymInfo, raw_ostream &OS);
static void printSymbolNameAndUSR(const Decl *D, ASTContext &Ctx,
raw_ostream &OS);
+static void printSymbolNameAndUSR(const clang::Module *Mod, raw_ostream &OS);
namespace {
return true;
}
- bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles,
- SourceLocation Loc) override {
+ bool handleModuleOccurence(const ImportDecl *ImportD,
+ const clang::Module *Mod,
+ SymbolRoleSet Roles, SourceLocation Loc) override {
ASTContext &Ctx = ImportD->getASTContext();
SourceManager &SM = Ctx.getSourceManager();
printSymbolInfo(getSymbolInfo(ImportD), OS);
OS << " | ";
- OS << ImportD->getImportedModule()->getFullModuleName() << " | ";
+ printSymbolNameAndUSR(Mod, OS);
+ OS << " | ";
printSymbolRoles(Roles, OS);
OS << " |\n";
}
}
+static void printSymbolNameAndUSR(const clang::Module *Mod, raw_ostream &OS) {
+ assert(Mod);
+ OS << Mod->getFullModuleName() << " | ";
+ generateFullUSRForModule(Mod, OS);
+}
+
//===----------------------------------------------------------------------===//
// Command line processing.
//===----------------------------------------------------------------------===//
}
bool CXIndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD,
+ const Module *Mod,
SymbolRoleSet Roles,
SourceLocation Loc) {
- IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
+ if (Roles & (SymbolRoleSet)SymbolRole::Declaration)
+ IndexingDeclVisitor(*this, SourceLocation(), nullptr).Visit(ImportD);
return !shouldAbort();
}
ArrayRef<index::SymbolRelation> Relations,
SourceLocation Loc, ASTNodeInfo ASTNode) override;
- bool handleModuleOccurence(const ImportDecl *ImportD,
+ bool handleModuleOccurence(const ImportDecl *ImportD, const Module *Mod,
index::SymbolRoleSet Roles,
SourceLocation Loc) override;