forked from OSchip/llvm-project
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()). llvm-svn: 106473
This commit is contained in:
parent
b5c9a04a2c
commit
c62ab8d064
|
@ -1141,10 +1141,16 @@ CINDEX_LINKAGE CXCursor clang_getTypeDeclaration(CXType T);
|
||||||
CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
|
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);
|
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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
@interface Foo
|
@interface Foo
|
||||||
@property (readonly) id x;
|
@property (readonly) id x;
|
||||||
|
-(int) mymethod;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
// RUN: c-index-test -test-print-typekind %s | FileCheck %s
|
// RUN: c-index-test -test-print-typekind %s | FileCheck %s
|
||||||
// CHECK: ObjCPropertyDecl=x:2:25 typekind=Typedef [canonical=ObjCObjectPointer]
|
// CHECK: ObjCPropertyDecl=x:2:25 typekind=Typedef [canonical=ObjCObjectPointer]
|
||||||
|
// CHECK: ObjCInstanceMethodDecl=mymethod:3:1 typekind=Invalid [result=Int]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -470,7 +470,7 @@ static enum CXChildVisitResult PrintTypeKind(CXCursor cursor, CXCursor p,
|
||||||
}
|
}
|
||||||
// Print the return type if it exists.
|
// Print the return type if it exists.
|
||||||
{
|
{
|
||||||
CXType RT = clang_getResultType(T);
|
CXType RT = clang_getCursorResultType(cursor);
|
||||||
if (RT.kind != CXType_Invalid) {
|
if (RT.kind != CXType_Invalid) {
|
||||||
CXString RS = clang_getTypeKindSpelling(RT.kind);
|
CXString RS = clang_getTypeKindSpelling(RT.kind);
|
||||||
printf(" [result=%s]", clang_getCString(RS));
|
printf(" [result=%s]", clang_getCString(RS));
|
||||||
|
|
|
@ -271,4 +271,16 @@ CXType clang_getResultType(CXType X) {
|
||||||
return MakeCXType(QualType(), GetASTU(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"
|
} // end: extern "C"
|
||||||
|
|
|
@ -41,6 +41,7 @@ _clang_getCursorLinkage
|
||||||
_clang_getCursorLocation
|
_clang_getCursorLocation
|
||||||
_clang_getCursorReferenced
|
_clang_getCursorReferenced
|
||||||
_clang_getCursorSpelling
|
_clang_getCursorSpelling
|
||||||
|
_clang_getCursorResultType
|
||||||
_clang_getCursorType
|
_clang_getCursorType
|
||||||
_clang_getCursorUSR
|
_clang_getCursorUSR
|
||||||
_clang_getDefinitionSpellingAndExtent
|
_clang_getDefinitionSpellingAndExtent
|
||||||
|
|
|
@ -41,6 +41,7 @@ clang_getCursorLinkage
|
||||||
clang_getCursorLocation
|
clang_getCursorLocation
|
||||||
clang_getCursorReferenced
|
clang_getCursorReferenced
|
||||||
clang_getCursorSpelling
|
clang_getCursorSpelling
|
||||||
|
clang_getCursorResultType
|
||||||
clang_getCursorType
|
clang_getCursorType
|
||||||
clang_getCursorUSR
|
clang_getCursorUSR
|
||||||
clang_getDefinitionSpellingAndExtent
|
clang_getDefinitionSpellingAndExtent
|
||||||
|
|
Loading…
Reference in New Issue