summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/clang-c/Index.h14
-rw-r--r--test/Index/get-cursor.m4
-rw-r--r--tools/c-index-test/c-index-test.c2
-rw-r--r--tools/libclang/CIndex.cpp4
-rw-r--r--tools/libclang/libclang.exports1
5 files changed, 23 insertions, 2 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index a65bb635b2..4568a764e0 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -3001,6 +3001,20 @@ CINDEX_LINKAGE unsigned clang_isCursorDefinition(CXCursor);
*/
CINDEX_LINKAGE CXCursor clang_getCanonicalCursor(CXCursor);
+
+/**
+ * \brief If the cursor points to a selector identifier in a objc method or
+ * message expression, this returns the selector index.
+ *
+ * After getting a cursor with \see clang_getCursor, this can be called to
+ * determine if the location points to a selector identifier.
+ *
+ * \returns The selector index if the cursor is an objc method or message
+ * expression and the cursor is pointing to a selector identifier, or -1
+ * otherwise.
+ */
+CINDEX_LINKAGE int clang_Cursor_getObjCSelectorIndex(CXCursor);
+
/**
* @}
*/
diff --git a/test/Index/get-cursor.m b/test/Index/get-cursor.m
index d73b23a18f..60e35eedd4 100644
--- a/test/Index/get-cursor.m
+++ b/test/Index/get-cursor.m
@@ -83,5 +83,5 @@ void foo3(Test3 *test3) {
// RUN: c-index-test -cursor-at=%s:56:24 -cursor-at=%s:60:14 \
// RUN: %s | FileCheck -check-prefix=CHECK-SPELLRANGE %s
-// CHECK-SPELLRANGE: 56:8 ObjCInstanceMethodDecl=setFoo:withBar::56:8 Extent=[56:1 - 56:37] Spelling=setFoo:withBar: ([56:8 - 56:14][56:22 - 56:29])
-// CHECK-SPELLRANGE: 60:3 ObjCMessageExpr=setFoo:withBar::56:8 Extent=[60:3 - 60:29] Spelling=setFoo:withBar: ([60:10 - 60:16][60:19 - 60:26])
+// CHECK-SPELLRANGE: 56:8 ObjCInstanceMethodDecl=setFoo:withBar::56:8 Extent=[56:1 - 56:37] Spelling=setFoo:withBar: ([56:8 - 56:14][56:22 - 56:29]) Selector index=1
+// CHECK-SPELLRANGE: 60:3 ObjCMessageExpr=setFoo:withBar::56:8 Extent=[60:3 - 60:29] Spelling=setFoo:withBar: ([60:10 - 60:16][60:19 - 60:26]) Selector index=0
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index e774e78086..873233575c 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -1464,6 +1464,8 @@ static int inspect_cursor_at(int argc, const char **argv) {
printf(")");
}
clang_disposeString(Spelling);
+ if (clang_Cursor_getObjCSelectorIndex(Cursor) != -1)
+ printf(" Selector index=%d",clang_Cursor_getObjCSelectorIndex(Cursor));
if (completionString != NULL) {
printf("\nCompletion string: ");
print_completion_string(completionString, stdout);
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index c63a969fe4..1896132fa0 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -4425,6 +4425,10 @@ CXCursor clang_getCanonicalCursor(CXCursor C) {
return C;
}
+
+int clang_Cursor_getObjCSelectorIndex(CXCursor cursor) {
+ return cxcursor::getSelectorIdentifierIndexAndLoc(cursor).first;
+}
unsigned clang_getNumOverloadedDecls(CXCursor C) {
if (C.kind != CXCursor_OverloadedDeclRef)
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 2fe3f1d53c..95cfb025cb 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -6,6 +6,7 @@ clang_CXXMethod_isStatic
clang_CXXMethod_isVirtual
clang_Cursor_getSpellingNameRange
clang_Cursor_getTranslationUnit
+clang_Cursor_getObjCSelectorIndex
clang_Cursor_isNull
clang_IndexAction_create
clang_IndexAction_dispose