]> granicus.if.org Git - clang/commitdiff
[libclang] Make clang_Cursor_getArgument work with call-exprs.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 1 Apr 2013 17:38:59 +0000 (17:38 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Mon, 1 Apr 2013 17:38:59 +0000 (17:38 +0000)
Patch by Matthias Kleine!

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

include/clang-c/Index.h
test/Index/print-type.c
tools/libclang/CXCursor.cpp

index 71d3443ae6fe8c02005e96fc33ab24bf2888969d..787c44a2e4fa25ab5ad94c665990638b3f8bdefb 100644 (file)
@@ -2749,15 +2749,17 @@ CINDEX_LINKAGE int clang_getFieldDeclBitWidth(CXCursor C);
  * \brief Retrieve the number of non-variadic arguments associated with a given
  * cursor.
  *
- * If a cursor that is not a function or method is passed in, -1 is returned.
+ * The number of arguments can be determined for calls as well as for
+ * declarations of functions or methods. For other cursors -1 is returned.
  */
 CINDEX_LINKAGE int clang_Cursor_getNumArguments(CXCursor C);
 
 /**
  * \brief Retrieve the argument cursor of a function or method.
  *
- * If a cursor that is not a function or method is passed in or the index
- * exceeds the number of arguments, an invalid cursor is returned.
+ * The argument cursor can be determined for calls as well as for declarations
+ * of functions or methods. For other cursors and for invalid indices, an
+ * invalid cursor is returned.
  */
 CINDEX_LINKAGE CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i);
 
index 9358772dbf89ae502fb038c98b92ae037d485f8c..8594994e77ed95fd5da8c1ff0561f9922ff06e18 100644 (file)
@@ -21,7 +21,7 @@ typedef int __attribute__((vector_size(16))) int4_t;
 // CHECK: ParmDecl=fn:3:55 (Definition) [type=void (*)(int)] [typekind=Pointer] [canonicaltype=void (*)(int)] [canonicaltypekind=Pointer] [isPOD=1]
 // CHECK: ParmDecl=:3:62 (Definition) [type=int] [typekind=Int] [isPOD=1]
 // CHECK: CompoundStmt= [type=] [typekind=Invalid] [isPOD=0]
-// CHECK: CallExpr=fn:3:55 [type=void] [typekind=Void] [isPOD=0]
+// CHECK: CallExpr=fn:3:55 [type=void] [typekind=Void] [args= [int] [Int]] [isPOD=0]
 // CHECK: DeclRefExpr=fn:3:55 [type=void (*)(int)] [typekind=Pointer] [canonicaltype=void (*)(int)] [canonicaltypekind=Pointer] [isPOD=1]
 // CHECK: UnaryOperator= [type=int] [typekind=Int] [isPOD=1]
 // CHECK: DeclRefExpr=p:3:13 [type=int *] [typekind=Pointer] [isPOD=1]
index 73d11f943a7b54c16c1f632861deb1df20d0947f..7b01ec2de0cada7372e977f1affaf22ecb65a228 100644 (file)
@@ -939,6 +939,13 @@ int clang_Cursor_getNumArguments(CXCursor C) {
       return FD->param_size();
   }
 
+  if (clang_isExpression(C.kind)) {
+    const Expr *E = cxcursor::getCursorExpr(C);
+    if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
+      return CE->getNumArgs();
+    }
+  }
+
   return -1;
 }
 
@@ -956,6 +963,17 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) {
     }
   }
 
+  if (clang_isExpression(C.kind)) {
+    const Expr *E = cxcursor::getCursorExpr(C);
+    if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
+      if (i < CE->getNumArgs()) {
+        return cxcursor::MakeCXCursor(CE->getArg(i),
+                                      getCursorDecl(C),
+                                      cxcursor::getCursorTU(C));
+      }
+    }
+  }
+
   return clang_getNullCursor();
 }