summaryrefslogtreecommitdiffstats
path: root/clang/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
commit0c27e4b36bd031fda61a8a457e33221fc2177370 (patch)
tree7dda5feb7e95bf27c3b9ad9485ea1ae905e444ea /clang/tools/libclang/CXCursor.cpp
parentcc899f3b6dc88107e612bc33b1489e5594850ddf (diff)
downloadbcm5719-llvm-0c27e4b36bd031fda61a8a457e33221fc2177370.tar.gz
bcm5719-llvm-0c27e4b36bd031fda61a8a457e33221fc2177370.zip
[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 llvm-svn: 154523
Diffstat (limited to 'clang/tools/libclang/CXCursor.cpp')
-rw-r--r--clang/tools/libclang/CXCursor.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/clang/tools/libclang/CXCursor.cpp b/clang/tools/libclang/CXCursor.cpp
index 8371a4f273c..d84cf29098f 100644
--- a/clang/tools/libclang/CXCursor.cpp
+++ b/clang/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"
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud