Implement libclang API functions for retrieving the lexical and
semantic parents of the given cursor.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114587 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index c0cecff..6d6938a 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -4018,6 +4018,36 @@
return CXLanguage_Invalid;
}
+
+CXCursor clang_getCursorSemanticParent(CXCursor cursor) {
+ if (clang_isDeclaration(cursor.kind)) {
+ if (Decl *D = getCursorDecl(cursor)) {
+ DeclContext *DC = D->getDeclContext();
+ return MakeCXCursor(cast<Decl>(DC), getCursorASTUnit(cursor));
+ }
+ }
+
+ if (clang_isStatement(cursor.kind) || clang_isExpression(cursor.kind)) {
+ if (Decl *D = getCursorDecl(cursor))
+ return MakeCXCursor(D, getCursorASTUnit(cursor));
+ }
+
+ return clang_getNullCursor();
+}
+
+CXCursor clang_getCursorLexicalParent(CXCursor cursor) {
+ if (clang_isDeclaration(cursor.kind)) {
+ if (Decl *D = getCursorDecl(cursor)) {
+ DeclContext *DC = D->getLexicalDeclContext();
+ return MakeCXCursor(cast<Decl>(DC), getCursorASTUnit(cursor));
+ }
+ }
+
+ // FIXME: Note that we can't easily compute the lexical context of a
+ // statement or expression, so we return nothing.
+ return clang_getNullCursor();
+}
+
} // end: extern "C"
diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports
index 6b30da4..da1a6ee 100644
--- a/tools/libclang/libclang.darwin.exports
+++ b/tools/libclang/libclang.darwin.exports
@@ -45,10 +45,12 @@
_clang_getCursorKind
_clang_getCursorKindSpelling
_clang_getCursorLanguage
+_clang_getCursorLexicalParent
_clang_getCursorLinkage
_clang_getCursorLocation
_clang_getCursorReferenced
_clang_getCursorResultType
+_clang_getCursorSemanticParent
_clang_getCursorSpelling
_clang_getCursorType
_clang_getCursorUSR
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 798ec32..511c85d 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -45,10 +45,12 @@
clang_getCursorKind
clang_getCursorKindSpelling
clang_getCursorLanguage
+clang_getCursorLexicalParent
clang_getCursorLinkage
clang_getCursorLocation
clang_getCursorReferenced
clang_getCursorResultType
+clang_getCursorSemanticParent
clang_getCursorSpelling
clang_getCursorType
clang_getCursorUSR