]> granicus.if.org Git - clang/commitdiff
Add CXType support for FunctionNoProto and FunctionProto types. This includes adding...
authorTed Kremenek <kremenek@apple.com>
Mon, 21 Jun 2010 20:15:39 +0000 (20:15 +0000)
committerTed Kremenek <kremenek@apple.com>
Mon, 21 Jun 2010 20:15:39 +0000 (20:15 +0000)
function, clang_getResultType(), which returns the result type of the function type.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@106459 91177308-0d34-0410-b5e6-96231b3b80d8

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

index ef779d622a8a1a52041f44858ddb5923d75555e9..9a56f332a0f51c04ed4f88f51028dd96446d143a 100644 (file)
@@ -1086,7 +1086,9 @@ enum CXTypeKind {
   CXType_Enum = 106,
   CXType_Typedef = 107,
   CXType_ObjCInterface = 108,
-  CXType_ObjCObjectPointer = 109
+  CXType_ObjCObjectPointer = 109,
+  CXType_FunctionNoProto = 110,
+  CXType_FunctionProto = 111
 };
 
 /**
@@ -1138,6 +1140,11 @@ 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.
+ */
+CINDEX_LINKAGE CXType clang_getResultType(CXType T);
+
 /**
  * @}
  */
index 79a9965d4d85c1d4bf705ac08c63e46dc3d28105..13b41198f127818f6f0f88bd4a3fffee0346da82 100644 (file)
@@ -8,7 +8,7 @@ int *f(int *p, char *x, FooType z) {
 // 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]
index 4268cec1b231fe1e27d8b10fca5c4651f0f6cbe1..27c51a0c596a3a51c9dc55e108ff2eb6f285fed0 100644 (file)
@@ -455,16 +455,29 @@ static enum CXChildVisitResult PrintTypeKind(CXCursor cursor, CXCursor p,
 
   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;
index ae756c7a1eea2bf68a4ab30b2f2c8d551bd0e808..64e49fba2b54375419866ff714c637fd24354f5e 100644 (file)
@@ -77,6 +77,8 @@ static CXTypeKind GetTypeKind(QualType T) {
     TKCASE(Typedef);
     TKCASE(ObjCInterface);
     TKCASE(ObjCObjectPointer);
+    TKCASE(FunctionNoProto);
+    TKCASE(FunctionProto);
     default:
       return CXType_Unexposed;
   }
@@ -118,7 +120,8 @@ CXType clang_getCursorType(CXCursor C) {
       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 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
     TKIND(Typedef);
     TKIND(ObjCInterface);
     TKIND(ObjCObjectPointer);
+    TKIND(FunctionNoProto);
+    TKIND(FunctionProto);
   }
 #undef TKIND
   return cxstring::createCXString(s);
@@ -255,4 +260,15 @@ unsigned clang_equalTypes(CXType A, CXType B) {
   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"
index 3ef3b748547b9011808212c32f23f6929cfbdcc2..6c7eddfec62dc1f6eeb476252bc5dfe91744069f 100644 (file)
@@ -67,6 +67,7 @@ _clang_getPointeeType
 _clang_getRange
 _clang_getRangeEnd
 _clang_getRangeStart
+_clang_getResultType
 _clang_getTokenExtent
 _clang_getTokenKind
 _clang_getTokenLocation
index c7831f777e9758516c05c67d751d5d505c7ef3b2..138b9767b19f8d870feda3171a0a80868c82365f 100644 (file)
@@ -67,6 +67,7 @@ clang_getPointeeType
 clang_getRange
 clang_getRangeEnd
 clang_getRangeStart
+clang_getResultType
 clang_getTokenExtent
 clang_getTokenKind
 clang_getTokenLocation