[cfe-commits] r106473 - in /cfe/trunk: 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
Ted Kremenek
kremenek at apple.com
Mon Jun 21 13:48:56 PDT 2010
Author: kremenek
Date: Mon Jun 21 15:48:56 2010
New Revision: 106473
URL: http://llvm.org/viewvc/llvm-project?rev=106473&view=rev
Log:
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()).
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/test/Index/print-typekind.m
cfe/trunk/tools/c-index-test/c-index-test.c
cfe/trunk/tools/libclang/CXTypes.cpp
cfe/trunk/tools/libclang/libclang.darwin.exports
cfe/trunk/tools/libclang/libclang.exports
Modified: cfe/trunk/include/clang-c/Index.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=106473&r1=106472&r2=106473&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Mon Jun 21 15:48:56 2010
@@ -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);
+
+/**
* @}
*/
Modified: cfe/trunk/test/Index/print-typekind.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-typekind.m?rev=106473&r1=106472&r2=106473&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-typekind.m (original)
+++ cfe/trunk/test/Index/print-typekind.m Mon Jun 21 15:48:56 2010
@@ -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]
+
Modified: cfe/trunk/tools/c-index-test/c-index-test.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/c-index-test/c-index-test.c?rev=106473&r1=106472&r2=106473&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Mon Jun 21 15:48:56 2010
@@ -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));
Modified: cfe/trunk/tools/libclang/CXTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXTypes.cpp?rev=106473&r1=106472&r2=106473&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXTypes.cpp (original)
+++ cfe/trunk/tools/libclang/CXTypes.cpp Mon Jun 21 15:48:56 2010
@@ -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"
Modified: cfe/trunk/tools/libclang/libclang.darwin.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.darwin.exports?rev=106473&r1=106472&r2=106473&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.darwin.exports (original)
+++ cfe/trunk/tools/libclang/libclang.darwin.exports Mon Jun 21 15:48:56 2010
@@ -41,6 +41,7 @@
_clang_getCursorLocation
_clang_getCursorReferenced
_clang_getCursorSpelling
+_clang_getCursorResultType
_clang_getCursorType
_clang_getCursorUSR
_clang_getDefinitionSpellingAndExtent
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=106473&r1=106472&r2=106473&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Mon Jun 21 15:48:56 2010
@@ -41,6 +41,7 @@
clang_getCursorLocation
clang_getCursorReferenced
clang_getCursorSpelling
+clang_getCursorResultType
clang_getCursorType
clang_getCursorUSR
clang_getDefinitionSpellingAndExtent
More information about the cfe-commits
mailing list