summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Wu <mwu.code@gmail.com>2018-08-03 05:38:29 +0000
committerMichael Wu <mwu.code@gmail.com>2018-08-03 05:38:29 +0000
commit6e88f5334ca731e3a2da51286602bae450404216 (patch)
treef63e237f60a0370e733953acb31910a9825646ee
parent40ff105663d9f55185d44844eddcbadf0b45360a (diff)
downloadbcm5719-llvm-6e88f5334ca731e3a2da51286602bae450404216.tar.gz
bcm5719-llvm-6e88f5334ca731e3a2da51286602bae450404216.zip
[libclang 7/8] Add support for getting property setter and getter names
Summary: This allows libclang to access the actual names of property setters and getters without needing to go through the indexer API. Usually default names are used, but the property can specify a different name. Reviewers: yvvan, jbcoe Reviewed By: yvvan Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D49634 llvm-svn: 338816
-rw-r--r--clang/include/clang-c/Index.h12
-rw-r--r--clang/test/Index/property-getter-setter.m10
-rw-r--r--clang/tools/c-index-test/c-index-test.c28
-rw-r--r--clang/tools/libclang/CIndex.cpp24
-rw-r--r--clang/tools/libclang/libclang.exports2
5 files changed, 76 insertions, 0 deletions
diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 481f65ac433..93f6a7770f0 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -4449,6 +4449,18 @@ CINDEX_LINKAGE unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C,
unsigned reserved);
/**
+ * Given a cursor that represents a property declaration, return the
+ * name of the method that implements the getter.
+ */
+CINDEX_LINKAGE CXString clang_Cursor_getObjCPropertyGetterName(CXCursor C);
+
+/**
+ * Given a cursor that represents a property declaration, return the
+ * name of the method that implements the setter, if any.
+ */
+CINDEX_LINKAGE CXString clang_Cursor_getObjCPropertySetterName(CXCursor C);
+
+/**
* 'Qualifiers' written next to the return and parameter types in
* Objective-C method declarations.
*/
diff --git a/clang/test/Index/property-getter-setter.m b/clang/test/Index/property-getter-setter.m
new file mode 100644
index 00000000000..d77775ac149
--- /dev/null
+++ b/clang/test/Index/property-getter-setter.m
@@ -0,0 +1,10 @@
+@interface Foo
+@property (assign,readwrite,getter=b,setter=c:) id a;
+@property (assign,readonly,getter=e) id d;
+@property (assign,readwrite) id f;
+@end
+
+// RUN: c-index-test -test-print-type-declaration %s | FileCheck %s
+// CHECK: ObjCPropertyDecl=a:2:52 [getter,assign,readwrite,setter,] (getter=b) (setter=c:) [typedeclaration=id] [typekind=ObjCId]
+// CHECK: ObjCPropertyDecl=d:3:41 [readonly,getter,assign,] (getter=e) [typedeclaration=id] [typekind=ObjCId]
+// CHECK: ObjCPropertyDecl=f:4:33 [assign,readwrite,] [typedeclaration=id] [typekind=ObjCId]
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 41dbbe73a45..7c88811a74c 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -1103,6 +1103,34 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) {
}
}
+ if (Cursor.kind == CXCursor_ObjCPropertyDecl) {
+ CXString Name = clang_Cursor_getObjCPropertyGetterName(Cursor);
+ CXString Spelling = clang_getCursorSpelling(Cursor);
+ const char *CName = clang_getCString(Name);
+ const char *CSpelling = clang_getCString(Spelling);
+ if (CName && strcmp(CName, CSpelling)) {
+ printf(" (getter=%s)", CName);
+ }
+ clang_disposeString(Spelling);
+ clang_disposeString(Name);
+ }
+
+ if (Cursor.kind == CXCursor_ObjCPropertyDecl) {
+ CXString Name = clang_Cursor_getObjCPropertySetterName(Cursor);
+ CXString Spelling = clang_getCursorSpelling(Cursor);
+ const char *CName = clang_getCString(Name);
+ const char *CSpelling = clang_getCString(Spelling);
+ char *DefaultSetter = malloc(strlen(CSpelling) + 5);
+ sprintf(DefaultSetter, "set%s:", CSpelling);
+ DefaultSetter[3] &= ~(1 << 5); /* Make uppercase */
+ if (CName && strcmp(CName, DefaultSetter)) {
+ printf(" (setter=%s)", CName);
+ }
+ free(DefaultSetter);
+ clang_disposeString(Spelling);
+ clang_disposeString(Name);
+ }
+
{
unsigned QT = clang_Cursor_getObjCDeclQualifiers(Cursor);
if (QT != CXObjCDeclQualifier_None) {
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 9ab0009b3fb..41fa868b06e 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -7913,6 +7913,30 @@ unsigned clang_Cursor_getObjCPropertyAttributes(CXCursor C, unsigned reserved) {
return Result;
}
+CXString clang_Cursor_getObjCPropertyGetterName(CXCursor C) {
+ if (C.kind != CXCursor_ObjCPropertyDecl)
+ return cxstring::createNull();
+
+ const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(getCursorDecl(C));
+ Selector sel = PD->getGetterName();
+ if (sel.isNull())
+ return cxstring::createNull();
+
+ return cxstring::createDup(sel.getAsString());
+}
+
+CXString clang_Cursor_getObjCPropertySetterName(CXCursor C) {
+ if (C.kind != CXCursor_ObjCPropertyDecl)
+ return cxstring::createNull();
+
+ const ObjCPropertyDecl *PD = dyn_cast<ObjCPropertyDecl>(getCursorDecl(C));
+ Selector sel = PD->getSetterName();
+ if (sel.isNull())
+ return cxstring::createNull();
+
+ return cxstring::createDup(sel.getAsString());
+}
+
unsigned clang_Cursor_getObjCDeclQualifiers(CXCursor C) {
if (!clang_isDeclaration(C.kind))
return CXObjCDeclQualifier_None;
diff --git a/clang/tools/libclang/libclang.exports b/clang/tools/libclang/libclang.exports
index 10a7143f94c..2c4b083a594 100644
--- a/clang/tools/libclang/libclang.exports
+++ b/clang/tools/libclang/libclang.exports
@@ -31,6 +31,8 @@ clang_Cursor_getRawCommentText
clang_Cursor_getNumArguments
clang_Cursor_getObjCDeclQualifiers
clang_Cursor_getObjCPropertyAttributes
+clang_Cursor_getObjCPropertyGetterName
+clang_Cursor_getObjCPropertySetterName
clang_Cursor_getObjCSelectorIndex
clang_Cursor_getOffsetOfField
clang_Cursor_getSpellingNameRange
OpenPOWER on IntegriCloud