From 0c27e4b36bd031fda61a8a457e33221fc2177370 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Wed, 11 Apr 2012 19:32:19 +0000 Subject: [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 --- clang/tools/libclang/CXCursor.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'clang/tools/libclang/CXCursor.cpp') 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(D)) + return MD->param_size(); + if (const FunctionDecl *FD = dyn_cast_or_null(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(D)) { + if (i < MD->param_size()) + return cxcursor::MakeCXCursor(MD->param_begin()[i], + cxcursor::getCursorTU(C)); + } else if (FunctionDecl *FD = dyn_cast_or_null(D)) { + if (i < FD->param_size()) + return cxcursor::MakeCXCursor(FD->param_begin()[i], + cxcursor::getCursorTU(C)); + } + } + + return clang_getNullCursor(); +} + } // end: extern "C" //===----------------------------------------------------------------------===// -- cgit v1.2.3