summaryrefslogtreecommitdiffstats
path: root/tools/libclang
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
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')
-rw-r--r--tools/libclang/CXCursor.cpp29
-rw-r--r--tools/libclang/CXType.cpp6
-rw-r--r--tools/libclang/libclang.exports2
3 files changed, 34 insertions, 3 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"
//===----------------------------------------------------------------------===//
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 0d4a5195ab..850fac129e 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -455,10 +455,10 @@ CXCallingConv clang_getFunctionTypeCallingConv(CXType X) {
return CXCallingConv_Invalid;
}
-unsigned clang_getNumArgTypes(CXType X) {
+int clang_getNumArgTypes(CXType X) {
QualType T = GetQualType(X);
if (T.isNull())
- return UINT_MAX;
+ return -1;
if (const FunctionProtoType *FD = T->getAs<FunctionProtoType>()) {
return FD->getNumArgs();
@@ -468,7 +468,7 @@ unsigned clang_getNumArgTypes(CXType X) {
return 0;
}
- return UINT_MAX;
+ return -1;
}
CXType clang_getArgType(CXType X, unsigned i) {
diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports
index 95cfb025cb..07bdece8eb 100644
--- a/tools/libclang/libclang.exports
+++ b/tools/libclang/libclang.exports
@@ -4,6 +4,8 @@ clang_CXIndex_getGlobalOptions
clang_CXIndex_setGlobalOptions
clang_CXXMethod_isStatic
clang_CXXMethod_isVirtual
+clang_Cursor_getArgument
+clang_Cursor_getNumArguments
clang_Cursor_getSpellingNameRange
clang_Cursor_getTranslationUnit
clang_Cursor_getObjCSelectorIndex