]> granicus.if.org Git - clang/commitdiff
Add CXType support for querying the return type of Objective-C methods. This is...
authorTed Kremenek <kremenek@apple.com>
Mon, 21 Jun 2010 20:48:56 +0000 (20:48 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 21 Jun 2010 20:48:56 +0000 (20:48 +0000)
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

include/clang-c/Index.h
test/Index/print-typekind.m
tools/c-index-test/c-index-test.c
tools/libclang/CXTypes.cpp
tools/libclang/libclang.darwin.exports
tools/libclang/libclang.exports

index 9a56f332a0f51c04ed4f88f51028dd96446d143a..b377b6d5fe2c28febb939b15b5c0d0ce0bd91717 100644 (file)
@@ -1141,10 +1141,16 @@ CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
 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);
+
 /**
  * @}
  */
index 62cbb70c8ee50f3d5d37654b3c4e8fbdb8bc7b0a..68827fb7ca6e9aef9a3f994490f966d3d5c7e6db 100644 (file)
@@ -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]
+
 
index 27c51a0c596a3a51c9dc55e108ff2eb6f285fed0..05e2d9e16b1a80367518ed1f8990e96226abafd8 100644 (file)
@@ -470,7 +470,7 @@ static enum CXChildVisitResult PrintTypeKind(CXCursor cursor, CXCursor p,
     }
     // 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));
index 64e49fba2b54375419866ff714c637fd24354f5e..d5c9f452100b02bd3143c7fe1c78cf31e1524975 100644 (file)
@@ -271,4 +271,16 @@ CXType clang_getResultType(CXType X) {
   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"
index 6c7eddfec62dc1f6eeb476252bc5dfe91744069f..f21fec63f48aac69840615a176564111739dbfc7 100644 (file)
@@ -41,6 +41,7 @@ _clang_getCursorLinkage
 _clang_getCursorLocation
 _clang_getCursorReferenced
 _clang_getCursorSpelling
+_clang_getCursorResultType
 _clang_getCursorType
 _clang_getCursorUSR
 _clang_getDefinitionSpellingAndExtent
index 138b9767b19f8d870feda3171a0a80868c82365f..dcb40d413ca9549c15b7b6da0ca1d2e8c8e405b9 100644 (file)
@@ -41,6 +41,7 @@ clang_getCursorLinkage
 clang_getCursorLocation
 clang_getCursorReferenced
 clang_getCursorSpelling
+clang_getCursorResultType
 clang_getCursorType
 clang_getCursorUSR
 clang_getDefinitionSpellingAndExtent