r179819 - [libclang] Introduce clang_Cursor_isVariadic, which returns non-zero if the given cursor is a variadic function or method.

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Apr 18 16:53:05 PDT 2013


Author: akirtzidis
Date: Thu Apr 18 18:53:05 2013
New Revision: 179819

URL: http://llvm.org/viewvc/llvm-project?rev=179819&view=rev
Log:
[libclang] Introduce clang_Cursor_isVariadic, which returns non-zero if the given cursor is a variadic function or method.

rdar://13667150

Modified:
    cfe/trunk/include/clang-c/Index.h
    cfe/trunk/test/Index/print-type.m
    cfe/trunk/tools/c-index-test/c-index-test.c
    cfe/trunk/tools/libclang/CIndex.cpp
    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=179819&r1=179818&r2=179819&view=diff
==============================================================================
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Apr 18 18:53:05 2013
@@ -3410,6 +3410,11 @@ typedef enum {
 CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
 
 /**
+ * \brief Returns non-zero if the given cursor is a variadic function or method.
+ */
+CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
+
+/**
  * \brief Given a cursor that represents a declaration, return the associated
  * comment's source range.  The range may include multiple consecutive comments
  * with whitespace in between.

Modified: cfe/trunk/test/Index/print-type.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/print-type.m?rev=179819&r1=179818&r2=179819&view=diff
==============================================================================
--- cfe/trunk/test/Index/print-type.m (original)
+++ cfe/trunk/test/Index/print-type.m Thu Apr 18 18:53:05 2013
@@ -2,7 +2,7 @@
 @property (readonly) id x;
 -(int) mymethod;
 -(const id) mymethod2:(id)x blah:(Class)y boo:(SEL)z;
--(bycopy)methodIn:(in int)i andOut:(out short *)j;
+-(bycopy)methodIn:(in int)i andOut:(out short *)j , ...;
 @end
 
 // RUN: c-index-test -test-print-type %s | FileCheck %s
@@ -10,6 +10,6 @@
 // CHECK: ObjCInstanceMethodDecl=mymethod:3:8 [type=] [typekind=Invalid] [resulttype=int] [resulttypekind=Int] [isPOD=0]
 // CHECK: ObjCInstanceMethodDecl=mymethod2:blah:boo::4:13 [type=] [typekind=Invalid] [resulttype=const id] [resulttypekind=ObjCId] [args= [id] [ObjCId] [Class] [ObjCClass] [SEL] [ObjCSel]] [isPOD=0]
 // CHECK: ParmDecl=z:4:52 (Definition) [type=SEL] [typekind=ObjCSel] [canonicaltype=SEL *] [canonicaltypekind=Pointer] [isPOD=1]
-// CHECK: ObjCInstanceMethodDecl=methodIn:andOut::5:10 [Bycopy,] [type=] [typekind=Invalid] [resulttype=id] [resulttypekind=ObjCId] [args= [int] [Int] [short *] [Pointer]] [isPOD=0]
+// CHECK: ObjCInstanceMethodDecl=methodIn:andOut::5:10 (variadic) [Bycopy,] [type=] [typekind=Invalid] [resulttype=id] [resulttypekind=ObjCId] [args= [int] [Int] [short *] [Pointer]] [isPOD=0]
 // CHECK: ParmDecl=i:5:27 (Definition) [In,] [type=int] [typekind=Int] [isPOD=1]
 // CHECK: ParmDecl=j:5:49 (Definition) [Out,] [type=short *] [typekind=Pointer] [isPOD=1]

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=179819&r1=179818&r2=179819&view=diff
==============================================================================
--- cfe/trunk/tools/c-index-test/c-index-test.c (original)
+++ cfe/trunk/tools/c-index-test/c-index-test.c Thu Apr 18 18:53:05 2013
@@ -694,6 +694,9 @@ static void PrintCursor(CXCursor Cursor,
       printf(" (static)");
     if (clang_CXXMethod_isVirtual(Cursor))
       printf(" (virtual)");
+
+    if (clang_Cursor_isVariadic(Cursor))
+      printf(" (variadic)");
     
     if (Cursor.kind == CXCursor_IBOutletCollectionAttr) {
       CXType T =

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=179819&r1=179818&r2=179819&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Apr 18 18:53:05 2013
@@ -5972,6 +5972,19 @@ unsigned clang_Cursor_getObjCDeclQualifi
   return Result;
 }
 
+unsigned clang_Cursor_isVariadic(CXCursor C) {
+  if (!clang_isDeclaration(C.kind))
+    return 0;
+
+  const Decl *D = getCursorDecl(C);
+  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
+    return FD->isVariadic();
+  if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
+    return MD->isVariadic();
+
+  return 0;
+}
+
 CXSourceRange clang_Cursor_getCommentRange(CXCursor C) {
   if (!clang_isDeclaration(C.kind))
     return clang_getNullRange();

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=179819&r1=179818&r2=179819&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Thu Apr 18 18:53:05 2013
@@ -19,6 +19,7 @@ clang_Cursor_getReceiverType
 clang_Cursor_isBitField
 clang_Cursor_isDynamicCall
 clang_Cursor_isNull
+clang_Cursor_isVariadic
 clang_Cursor_getModule
 clang_Module_getParent
 clang_Module_getName





More information about the cfe-commits mailing list