diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-06-21 20:48:56 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-06-21 20:48:56 +0000 |
commit | 9a140845438c2fc31e7d48a6dedbc695f4c83c68 (patch) | |
tree | 3f7c3667670d3b43976cedad6ae8116a3f18de87 | |
parent | dbc4c465a0eabd42b3cb16edc610aceb48ac7823 (diff) |
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
-rw-r--r-- | include/clang-c/Index.h | 8 | ||||
-rw-r--r-- | test/Index/print-typekind.m | 3 | ||||
-rw-r--r-- | tools/c-index-test/c-index-test.c | 2 | ||||
-rw-r--r-- | tools/libclang/CXTypes.cpp | 12 | ||||
-rw-r--r-- | tools/libclang/libclang.darwin.exports | 1 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 1 |
6 files changed, 25 insertions, 2 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 9a56f332a0..b377b6d5fe 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -1141,11 +1141,17 @@ 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); + +/** * @} */ diff --git a/test/Index/print-typekind.m b/test/Index/print-typekind.m index 62cbb70c8e..68827fb7ca 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 27c51a0c59..05e2d9e16b 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -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)); diff --git a/tools/libclang/CXTypes.cpp b/tools/libclang/CXTypes.cpp index 64e49fba2b..d5c9f45210 100644 --- a/tools/libclang/CXTypes.cpp +++ b/tools/libclang/CXTypes.cpp @@ -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" diff --git a/tools/libclang/libclang.darwin.exports b/tools/libclang/libclang.darwin.exports index 6c7eddfec6..f21fec63f4 100644 --- a/tools/libclang/libclang.darwin.exports +++ b/tools/libclang/libclang.darwin.exports @@ -41,6 +41,7 @@ _clang_getCursorLinkage _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 138b9767b1..dcb40d413c 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -41,6 +41,7 @@ clang_getCursorLinkage clang_getCursorLocation clang_getCursorReferenced clang_getCursorSpelling +clang_getCursorResultType clang_getCursorType clang_getCursorUSR clang_getDefinitionSpellingAndExtent |