From a8b30c5b61069cc576ca87c719cb5817d79f946a Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Sat, 10 Mar 2012 22:23:27 +0000 Subject: [PATCH] [clang.py] Implement Cursor.objc_type_encoding llvm-svn: 152513 --- clang/bindings/python/clang/cindex.py | 13 +++++++++++++ clang/bindings/python/tests/cindex/test_cursor.py | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 3b1e751ec0d0..b4563eb0c624 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -1007,6 +1007,14 @@ class Cursor(Structure): return self._enum_type + @property + def objc_type_encoding(self): + """Return the Objective-C type encoding as a str.""" + if not hasattr(self, '_objc_type_encoding'): + self._objc_type_encoding = Cursor_objc_type_encoding(self) + + return self._objc_type_encoding + @property def hash(self): """Returns a hash of the cursor as an int.""" @@ -1920,6 +1928,11 @@ Cursor_enum_type.argtypes = [Cursor] Cursor_enum_type.restype = Type Cursor_enum_type.errcheck = Type.from_result +Cursor_objc_type_encoding = lib.clang_getDeclObjCTypeEncoding +Cursor_objc_type_encoding.argtypes = [Cursor] +Cursor_objc_type_encoding.restype = _CXString +Cursor_objc_type_encoding.errcheck = _CXString.from_result + Cursor_visit_callback = CFUNCTYPE(c_int, Cursor, Cursor, py_object) Cursor_visit = lib.clang_visitChildren Cursor_visit.argtypes = [Cursor, Cursor_visit_callback, py_object] diff --git a/clang/bindings/python/tests/cindex/test_cursor.py b/clang/bindings/python/tests/cindex/test_cursor.py index bbe2c1d7e5e6..9f02bb2a7686 100644 --- a/clang/bindings/python/tests/cindex/test_cursor.py +++ b/clang/bindings/python/tests/cindex/test_cursor.py @@ -83,3 +83,10 @@ def test_enum_type(): assert enum.kind == CursorKind.ENUM_DECL enum_type = enum.enum_type assert enum_type.kind == TypeKind.UINT + +def test_objc_type_encoding(): + tu = get_tu('int i;', lang='objc') + i = get_cursor(tu, 'i') + + assert i is not None + assert i.objc_type_encoding == 'i'