aboutsummaryrefslogtreecommitdiff
path: root/tools/libclang/CXCursor.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-04-11 19:32:19 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-04-11 19:32:19 +0000
commitd98ef9ae48ab4090d4d5d703ce65cfac62807fda (patch)
tree10f93d77fa3dec4dc2bef3c008d440205485da6b /tools/libclang/CXCursor.cpp
parenteba8cd5967e47592285590360bde73063c9c226f (diff)
[libclang] Introduce a couple of functions to make it convenient
to get at the parameters (and their types) of a function or objc method cursor. int clang_Cursor_getNumArguments(CXCursor C); CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i); rdar://11201527 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154523 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang/CXCursor.cpp')
-rw-r--r--tools/libclang/CXCursor.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp
index 8371a4f273..d84cf29098 100644
--- a/tools/libclang/CXCursor.cpp
+++ b/tools/libclang/CXCursor.cpp
@@ -1024,6 +1024,35 @@ CXTranslationUnit clang_Cursor_getTranslationUnit(CXCursor cursor) {
return getCursorTU(cursor);
}
+int clang_Cursor_getNumArguments(CXCursor C) {
+ if (clang_isDeclaration(C.kind)) {
+ Decl *D = cxcursor::getCursorDecl(C);
+ if (const ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D))
+ return MD->param_size();
+ if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
+ return FD->param_size();
+ }
+
+ return -1;
+}
+
+CXCursor clang_Cursor_getArgument(CXCursor C, unsigned i) {
+ if (clang_isDeclaration(C.kind)) {
+ Decl *D = cxcursor::getCursorDecl(C);
+ if (ObjCMethodDecl *MD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
+ if (i < MD->param_size())
+ return cxcursor::MakeCXCursor(MD->param_begin()[i],
+ cxcursor::getCursorTU(C));
+ } else if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
+ if (i < FD->param_size())
+ return cxcursor::MakeCXCursor(FD->param_begin()[i],
+ cxcursor::getCursorTU(C));
+ }
+ }
+
+ return clang_getNullCursor();
+}
+
} // end: extern "C"
//===----------------------------------------------------------------------===//