[libclang] Make clang_Cursor_getArgument work with call-exprs.
Patch by Matthias Kleine! llvm-svn: 178475
This commit is contained in:
parent
6e42b1eb8b
commit
b2792972a2
|
@ -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);
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue