[cfe-commits] r106459 - in /cfe/trunk: include/clang-c/Index.h test/Index/print-typekind.c 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:15:39 PDT 2010
Author: kremenek
Date: Mon Jun 21 15:15:39 2010
New Revision: 106459
URL: http://llvm.org/viewvc/llvm-project?rev=106459&view=rev
Log:
Add CXType support for FunctionNoProto and FunctionProto types. This includes adding a new
function, clang_getResultType(), which returns the result type of the function type.
Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/test/Index/print-typekind.c
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=106459&r1=106458&r2=106459&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Mon Jun 21 15:15:39 2010
@@ -1086,7 +1086,9 @@
CXType_Enum = 106,
CXType_Typedef = 107,
CXType_ObjCInterface = 108,
- CXType_ObjCObjectPointer = 109
+ CXType_ObjCObjectPointer = 109,
+ CXType_FunctionNoProto = 110,
+ CXType_FunctionProto = 111
};
/**
@@ -1139,6 +1141,11 @@
CINDEX_LINKAGE CXString clang_getTypeKindSpelling(enum CXTypeKind K);
/**
+ * \brief Retrieve the result type associated with a function or method type.
+ */
+CINDEX_LINKAGE CXType clang_getResultType(CXType T);
+
+/**
* @}
*/
Modified: cfe/trunk/test/Index/print-typekind.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-typekind.c?rev=106459&r1=106458&r2=106459&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-typekind.c (original)
+++ cfe/trunk/test/Index/print-typekind.c Mon Jun 21 15:15:39 2010
@@ -8,7 +8,7 @@
// RUN: c-index-test -test-print-typekind %s | FileCheck %s
// CHECK: TypedefDecl=FooType:1:13 (Definition) typekind=Typedef [canonical=Int]
// CHECK: VarDecl=p:2:6 typekind=Pointer
-// CHECK: FunctionDecl=f:3:6 (Definition) typekind=Unexposed [canonical=Unexposed]
+// CHECK: FunctionDecl=f:3:6 (Definition) typekind=FunctionProto [canonical=FunctionProto] [result=Pointer]
// CHECK: ParmDecl=p:3:13 (Definition) typekind=Pointer
// CHECK: ParmDecl=x:3:22 (Definition) typekind=Pointer
// CHECK: ParmDecl=z:3:33 (Definition) typekind=Typedef [canonical=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=106459&r1=106458&r2=106459&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:15:39 2010
@@ -455,16 +455,29 @@
if (!clang_isInvalid(clang_getCursorKind(cursor))) {
CXType T = clang_getCursorType(cursor);
- CXType CT = clang_getCanonicalType(T);
CXString S = clang_getTypeKindSpelling(T.kind);
PrintCursor(cursor);
printf(" typekind=%s", clang_getCString(S));
- if (!clang_equalTypes(T, CT)) {
- CXString CS = clang_getTypeKindSpelling(CT.kind);
- printf(" [canonical=%s]", clang_getCString(CS));
- clang_disposeString(CS);
- }
clang_disposeString(S);
+ // Print the canonical type if it is different.
+ {
+ CXType CT = clang_getCanonicalType(T);
+ if (!clang_equalTypes(T, CT)) {
+ CXString CS = clang_getTypeKindSpelling(CT.kind);
+ printf(" [canonical=%s]", clang_getCString(CS));
+ clang_disposeString(CS);
+ }
+ }
+ // Print the return type if it exists.
+ {
+ CXType RT = clang_getResultType(T);
+ if (RT.kind != CXType_Invalid) {
+ CXString RS = clang_getTypeKindSpelling(RT.kind);
+ printf(" [result=%s]", clang_getCString(RS));
+ clang_disposeString(RS);
+ }
+ }
+
printf("\n");
}
return CXChildVisit_Recurse;
Modified: cfe/trunk/tools/libclang/CXTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXTypes.cpp?rev=106459&r1=106458&r2=106459&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXTypes.cpp (original)
+++ cfe/trunk/tools/libclang/CXTypes.cpp Mon Jun 21 15:15:39 2010
@@ -77,6 +77,8 @@
TKCASE(Typedef);
TKCASE(ObjCInterface);
TKCASE(ObjCObjectPointer);
+ TKCASE(FunctionNoProto);
+ TKCASE(FunctionProto);
default:
return CXType_Unexposed;
}
@@ -118,7 +120,8 @@
return MakeCXType(VD->getType(), AU);
if (ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
return MakeCXType(PD->getType(), AU);
-
+ if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+ return MakeCXType(FD->getType(), AU);
return MakeCXType(QualType(), AU);
}
@@ -246,6 +249,8 @@
TKIND(Typedef);
TKIND(ObjCInterface);
TKIND(ObjCObjectPointer);
+ TKIND(FunctionNoProto);
+ TKIND(FunctionProto);
}
#undef TKIND
return cxstring::createCXString(s);
@@ -255,4 +260,15 @@
return A.data[0] == B.data[0] && A.data[1] == B.data[1];;
}
+CXType clang_getResultType(CXType X) {
+ QualType T = GetQualType(X);
+ if (!T.getTypePtr())
+ return MakeCXType(QualType(), GetASTU(X));
+
+ if (const FunctionType *FD = T->getAs<FunctionType>())
+ return MakeCXType(FD->getResultType(), GetASTU(X));
+
+ return MakeCXType(QualType(), GetASTU(X));
+}
+
} // 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=106459&r1=106458&r2=106459&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.darwin.exports (original)
+++ cfe/trunk/tools/libclang/libclang.darwin.exports Mon Jun 21 15:15:39 2010
@@ -67,6 +67,7 @@
_clang_getRange
_clang_getRangeEnd
_clang_getRangeStart
+_clang_getResultType
_clang_getTokenExtent
_clang_getTokenKind
_clang_getTokenLocation
Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=106459&r1=106458&r2=106459&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Mon Jun 21 15:15:39 2010
@@ -67,6 +67,7 @@
clang_getRange
clang_getRangeEnd
clang_getRangeStart
+clang_getResultType
clang_getTokenExtent
clang_getTokenKind
clang_getTokenLocation
More information about the cfe-commits
mailing list