[index] Add 'contained-by' relation between references and their lexical container.
llvm-svn: 291700
diff --git a/clang/lib/Index/IndexSymbol.cpp b/clang/lib/Index/IndexSymbol.cpp
index be847e7..d7df097 100644
--- a/clang/lib/Index/IndexSymbol.cpp
+++ b/clang/lib/Index/IndexSymbol.cpp
@@ -289,6 +289,7 @@
APPLY_FOR_ROLE(RelationCalledBy);
APPLY_FOR_ROLE(RelationExtendedBy);
APPLY_FOR_ROLE(RelationAccessorOf);
+ APPLY_FOR_ROLE(RelationContainedBy);
#undef APPLY_FOR_ROLE
}
@@ -317,6 +318,7 @@
case SymbolRole::RelationCalledBy: OS << "RelCall"; break;
case SymbolRole::RelationExtendedBy: OS << "RelExt"; break;
case SymbolRole::RelationAccessorOf: OS << "RelAcc"; break;
+ case SymbolRole::RelationContainedBy: OS << "RelCont"; break;
}
});
}
diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp
index e623a49..2d5fc0d 100644
--- a/clang/lib/Index/IndexingContext.cpp
+++ b/clang/lib/Index/IndexingContext.cpp
@@ -312,9 +312,14 @@
Roles |= Rel.Roles;
};
- if (!IsRef && Parent && !cast<DeclContext>(Parent)->isFunctionOrMethod()) {
- addRelation(SymbolRelation{(unsigned)SymbolRole::RelationChildOf, Parent});
+ if (Parent) {
+ if (IsRef) {
+ addRelation(SymbolRelation{(unsigned)SymbolRole::RelationContainedBy, Parent});
+ } else if (!cast<DeclContext>(Parent)->isFunctionOrMethod()) {
+ addRelation(SymbolRelation{(unsigned)SymbolRole::RelationChildOf, Parent});
+ }
}
+
for (auto &Rel : Relations) {
addRelation(SymbolRelation(Rel.Roles,
Rel.RelatedSymbol->getCanonicalDecl()));