[libclang] Indexing API: provide both the semantic and the lexical container.
They are generally the same except in C++ cases like out-of-line member functions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146069 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 5d1e19e..dac8b54 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -4199,7 +4199,12 @@
const CXIdxEntityInfo *entityInfo;
CXCursor cursor;
CXIdxLoc loc;
- const CXIdxContainerInfo *container;
+ const CXIdxContainerInfo *semanticContainer;
+ /**
+ * \brief Generally same as \see semanticContainer but can be different in
+ * cases like out-of-line C++ member functions.
+ */
+ const CXIdxContainerInfo *lexicalContainer;
int isRedeclaration;
int isDefinition;
int isContainer;
@@ -4279,6 +4284,7 @@
* \brief Data for \see indexEntityReference callback.
*/
typedef struct {
+ CXIdxEntityRefKind kind;
/**
* \brief Reference cursor.
*/
@@ -4303,7 +4309,6 @@
* \brief Container context of the reference.
*/
const CXIdxContainerInfo *container;
- CXIdxEntityRefKind kind;
} CXIdxEntityRefInfo;
typedef struct {
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 18a0a6b..1370e21 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -1801,8 +1801,10 @@
PrintCursor(info->cursor);
printf(" | loc: ");
printCXIndexLoc(info->loc);
- printf(" | container: ");
- printCXIndexContainer(info->container);
+ printf(" | semantic-container: ");
+ printCXIndexContainer(info->semanticContainer);
+ printf(" | lexical-container: ");
+ printCXIndexContainer(info->lexicalContainer);
printf(" | isRedecl: %d", info->isRedeclaration);
printf(" | isDef: %d", info->isDefinition);
printf(" | isContainer: %d", info->isContainer);
diff --git a/tools/libclang/IndexingContext.cpp b/tools/libclang/IndexingContext.cpp
index 0ec8619..657aed8 100644
--- a/tools/libclang/IndexingContext.cpp
+++ b/tools/libclang/IndexingContext.cpp
@@ -239,8 +239,10 @@
DInfo.attributes = AttrList.getAttrs();
DInfo.numAttributes = AttrList.getNumAttrs();
- getContainerInfo(D->getDeclContext(), DInfo.Container);
- DInfo.container = &DInfo.Container;
+ getContainerInfo(D->getDeclContext(), DInfo.SemanticContainer);
+ getContainerInfo(D->getLexicalDeclContext(), DInfo.LexicalContainer);
+ DInfo.semanticContainer = &DInfo.SemanticContainer;
+ DInfo.lexicalContainer = &DInfo.LexicalContainer;
if (DInfo.isContainer) {
getContainerInfo(getEntityContainer(D), DInfo.DeclAsContainer);
DInfo.declAsContainer = &DInfo.DeclAsContainer;
@@ -506,12 +508,12 @@
ContainerInfo Container;
getContainerInfo(DC, Container);
- CXIdxEntityRefInfo Info = { Cursor,
+ CXIdxEntityRefInfo Info = { Kind,
+ Cursor,
getIndexLoc(Loc),
&RefEntity,
Parent ? &ParentEntity : 0,
- &Container,
- Kind };
+ &Container };
CB.indexEntityReference(ClientData, &Info);
return true;
}
diff --git a/tools/libclang/IndexingContext.h b/tools/libclang/IndexingContext.h
index ff5ca1b..bce3ab3 100644
--- a/tools/libclang/IndexingContext.h
+++ b/tools/libclang/IndexingContext.h
@@ -54,7 +54,8 @@
DInfoKind Kind;
EntityInfo EntInfo;
- ContainerInfo Container;
+ ContainerInfo SemanticContainer;
+ ContainerInfo LexicalContainer;
ContainerInfo DeclAsContainer;
DeclInfo(bool isRedeclaration, bool isDefinition, bool isContainer)
@@ -64,7 +65,7 @@
this->isContainer = isContainer;
attributes = 0;
numAttributes = 0;
- declAsContainer = container = 0;
+ declAsContainer = semanticContainer = lexicalContainer = 0;
}
DeclInfo(DInfoKind K,
bool isRedeclaration, bool isDefinition, bool isContainer)
@@ -74,7 +75,7 @@
this->isContainer = isContainer;
attributes = 0;
numAttributes = 0;
- declAsContainer = container = 0;
+ declAsContainer = semanticContainer = lexicalContainer = 0;
}
static bool classof(const DeclInfo *) { return true; }