Add CXType support for querying the return type of Objective-C methods.  This is done by
adding a clang_getCursorResultType() function (which complements clang_getResultType()).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106473 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 9a56f33..b377b6d 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -1141,11 +1141,17 @@
 CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
 
 /**
- * \brief Retrieve the result type associated with a function or method type.
+ * \brief Retrieve the result type associated with a function type.
  */
 CINDEX_LINKAGE CXType clang_getResultType(CXType T);
 
 /**
+ * \brief Retrieve the result type associated with a given cursor.  This only
+ *  returns a valid type of the cursor refers to a function or method.
+ */
+CINDEX_LINKAGE CXType clang_getCursorResultType(CXCursor C);
+
+/**
  * @}
  */
 
diff --git a/test/Index/print-typekind.m b/test/Index/print-typekind.m
index 62cbb70..68827fb 100644
--- a/test/Index/print-typekind.m
+++ b/test/Index/print-typekind.m
@@ -1,7 +1,10 @@
 @interface Foo
 @property (readonly) id x;
+-(int) mymethod;
 @end
 
 // RUN: c-index-test -test-print-typekind %s | FileCheck %s
 // CHECK: ObjCPropertyDecl=x:2:25 typekind=Typedef [canonical=ObjCObjectPointer]
+// CHECK: ObjCInstanceMethodDecl=mymethod:3:1 typekind=Invalid [result=Int]
+
 
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c
index 27c51a0..05e2d9e 100644
--- a/tools/c-index-test/c-index-test.c
+++ b/tools/c-index-test/c-index-test.c
@@ -470,7 +470,7 @@
     }
     // Print the return type if it exists.
     {
-      CXType RT = clang_getResultType(T);
+      CXType RT = clang_getCursorResultType(cursor);
       if (RT.kind != CXType_Invalid) {
         CXString RS = clang_getTypeKindSpelling(RT.kind);
         printf(" [result=%s]", clang_getCString(RS));
diff --git a/tools/libclang/CXTypes.cpp b/tools/libclang/CXTypes.cpp
index 64e49fb..d5c9f45 100644
--- a/tools/libclang/CXTypes.cpp
+++ b/tools/libclang/CXTypes.cpp
@@ -271,4 +271,16 @@
   return MakeCXType(QualType(), GetASTU(X));
 }
 
+CXType clang_getCursorResultType(CXCursor C) {
+  if (clang_isDeclaration(C.kind)) {
+    Decl *D = cxcursor::getCursorDecl(C);
+    if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
+      return MakeCXType(MD->getResultType(), cxcursor::getCursorASTUnit(C));
+
+    return clang_getResultType(clang_getCursorType(C));
+  }
+
+  return MakeCXType(QualType(), cxcursor::getCursorASTUnit(C));
+}
+
 } // end: extern "C"
diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports
index 6c7eddf..f21fec6 100644
--- a/tools/libclang/libclang.darwin.exports
+++ b/tools/libclang/libclang.darwin.exports
@@ -41,6 +41,7 @@
 _clang_getCursorLocation
 _clang_getCursorReferenced
 _clang_getCursorSpelling
+_clang_getCursorResultType
 _clang_getCursorType
 _clang_getCursorUSR
 _clang_getDefinitionSpellingAndExtent
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 138b976..dcb40d4 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -41,6 +41,7 @@
 clang_getCursorLocation
 clang_getCursorReferenced
 clang_getCursorSpelling
+clang_getCursorResultType
 clang_getCursorType
 clang_getCursorUSR
 clang_getDefinitionSpellingAndExtent