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);
+
/**
* @}
*/
@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]
+
}
// 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));
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"
_clang_getCursorLocation
_clang_getCursorReferenced
_clang_getCursorSpelling
+_clang_getCursorResultType
_clang_getCursorType
_clang_getCursorUSR
_clang_getDefinitionSpellingAndExtent
clang_getCursorLocation
clang_getCursorReferenced
clang_getCursorSpelling
+clang_getCursorResultType
clang_getCursorType
clang_getCursorUSR
clang_getDefinitionSpellingAndExtent