aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang-c/Index.h8
-rw-r--r--test/Index/print-type.c2
-rw-r--r--tools/libclang/CXCursor.cpp18
3 files changed, 24 insertions, 4 deletions
diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h
index 71d3443ae6..787c44a2e4 100644
--- a/include/clang-c/Index.h
+++ b/include/clang-c/Index.h
@@ -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);
diff --git a/test/Index/print-type.c b/test/Index/print-type.c
index 9358772dbf..8594994e77 100644
--- a/test/Index/print-type.c
+++ b/test/Index/print-type.c
@@ -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]
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index 73d11f943a..7b01ec2de0 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -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();
}