summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-07-05 20:44:37 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-07-05 20:44:37 +0000
commit7b50fc520f67f8c4bec0a2a0fb7054676cf839bc (patch)
tree2597bc6fc93345c9c3c2bf0960f06a60a4c9c14b
parenteecc09a99c34526ab5afb8e8d870bd8870425feb (diff)
downloadbcm5719-llvm-7b50fc520f67f8c4bec0a2a0fb7054676cf839bc.tar.gz
bcm5719-llvm-7b50fc520f67f8c4bec0a2a0fb7054676cf839bc.zip
[libclang] Introduce clang_Cursor_isObjCOptional, which returns whether the declaration was affected by "@optional"
rdar://14348525. llvm-svn: 185722
-rw-r--r--clang/include/clang-c/Index.h7
-rw-r--r--clang/test/Index/get-cursor.m24
-rw-r--r--clang/tools/c-index-test/c-index-test.c4
-rw-r--r--clang/tools/libclang/CIndex.cpp13
4 files changed, 47 insertions, 1 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 21b7dba0763..aa4b46f8df9 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3414,6 +3414,13 @@ typedef enum {
CINDEX_LINKAGE unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C);
/**
+ * \brief Given a cursor that represents an ObjC method or property declaration,
+ * return non-zero if the declaration was affected by "@optional".
+ * Returns zero if the cursor is not such a declaration or it is "@required".
+ */
+CINDEX_LINKAGE unsigned clang_Cursor_isObjCOptional(CXCursor C);
+
+/**
* \brief Returns non-zero if the given cursor is a variadic function or method.
*/
CINDEX_LINKAGE unsigned clang_Cursor_isVariadic(CXCursor C);
diff --git a/clang/test/Index/get-cursor.m b/clang/test/Index/get-cursor.m
index 7eaa3a0a3c1..f659fb1ff61 100644
--- a/clang/test/Index/get-cursor.m
+++ b/clang/test/Index/get-cursor.m
@@ -99,6 +99,20 @@ void foo3(Test3 *test3) {
@synthesize prop1 = _prop1;
@end
+@protocol TestProt
+-(void)protMeth1;
+@property (retain) id propProp1;
+
+@optional
+-(void)protMeth2;
+@property (retain) id propProp2;
+
+@required
+-(void)protMeth3;
+@property (retain) id propProp3;
+@end
+
+
// RUN: c-index-test -cursor-at=%s:4:28 -cursor-at=%s:5:28 %s | FileCheck -check-prefix=CHECK-PROP %s
// CHECK-PROP: ObjCPropertyDecl=foo1:4:26
// CHECK-PROP: ObjCPropertyDecl=foo2:5:27
@@ -146,3 +160,13 @@ void foo3(Test3 *test3) {
// RUN: c-index-test -cursor-at=%s:86:7 -cursor-at=%s:89:7 %s | FileCheck -check-prefix=CHECK-SELECTORLOC %s
// CHECK-SELECTORLOC: 86:6 ObjCInstanceMethodDecl=meth1:86:6 (Definition) Extent=[86:1 - 88:2] Spelling=meth1 ([86:6 - 86:11]) Selector index=0
// CHECK-SELECTORLOC: 89:6 ObjCInstanceMethodDecl=meth2:89:6 (Definition) Extent=[89:1 - 91:2] Spelling=meth2 ([89:6 - 89:11]) Selector index=0
+
+// RUN: c-index-test -cursor-at=%s:103:10 -cursor-at=%s:104:10 \
+// RUN: -cursor-at=%s:107:10 -cursor-at=%s:108:10 \
+// RUN: -cursor-at=%s:111:10 -cursor-at=%s:112:10 %s | FileCheck -check-prefix=CHECK-OBJCOPTIONAL %s
+// CHECK-OBJCOPTIONAL: 103:8 ObjCInstanceMethodDecl=protMeth1:103:8 Extent=[103:1 - 103:18]
+// CHECK-OBJCOPTIONAL: 104:23 ObjCPropertyDecl=propProp1:104:23 [retain,] Extent=[104:1 - 104:32]
+// CHECK-OBJCOPTIONAL: 107:8 ObjCInstanceMethodDecl=protMeth2:107:8 (@optional) Extent=[107:1 - 107:18]
+// CHECK-OBJCOPTIONAL: 108:23 ObjCPropertyDecl=propProp2:108:23 (@optional) [retain,] Extent=[108:1 - 108:32]
+// CHECK-OBJCOPTIONAL: 111:8 ObjCInstanceMethodDecl=protMeth3:111:8 Extent=[111:1 - 111:18]
+// CHECK-OBJCOPTIONAL: 112:23 ObjCPropertyDecl=propProp3:112:23 [retain,] Extent=[112:1 - 112:32]
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index a824a9f041a..2e8b58bff44 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -698,7 +698,9 @@ static void PrintCursor(CXCursor Cursor,
printf(" (pure)");
if (clang_Cursor_isVariadic(Cursor))
printf(" (variadic)");
-
+ if (clang_Cursor_isObjCOptional(Cursor))
+ printf(" (@optional)");
+
if (Cursor.kind == CXCursor_IBOutletCollectionAttr) {
CXType T =
clang_getCanonicalType(clang_getIBOutletCollectionType(Cursor));
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index eecb16a17ee..ae131af3335 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -5992,6 +5992,19 @@ unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C) {
return Result;
}
+unsigned clang_Cursor_isObjCOptional(CXCursor C) {
+ if (!clang_isDeclaration(C.kind))
+ return 0;
+
+ const Decl *D = getCursorDecl(C);
+ if (const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(D))
+ return PD->getPropertyImplementation() == ObjCPropertyDecl::Optional;
+ if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D))
+ return MD->getImplementationControl() == ObjCMethodDecl::Optional;
+
+ return 0;
+}
+
unsigned clang_Cursor_isVariadic(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return 0;
OpenPOWER on IntegriCloud