---
 bindings/python/clang/cindex.py             |   18 ++++++++++++++++++
 bindings/python/tests/cindex/test_cursor.py |   15 +++++++++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 37ff5ff..ecbf42e 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -977,16 +977,29 @@ class Cursor(Structure):
         Retrieve the type (if any) of of the entity pointed at by the
         cursor.
         """
         if not hasattr(self, '_type'):
             self._type = Cursor_type(self)
         return self._type
 
     @property
+    def underlying_typedef_type(self):
+        """Return the underlying type of a typedef declaration.
+
+        Returns a Type for the typedef this cursor is a declaration for. If
+        the current cursor is not a typedef, this raises.
+        """
+        if not hasattr(self, '_underlying_type'):
+            assert self.kind.is_declaration()
+            self._underlying_type = Cursor_underlying_type(self)
+
+        return self._underlying_type
+
+    @property
     def hash(self):
         """Returns a hash of the cursor as an int."""
         if not hasattr(self, '_hash'):
             self._hash = Cursor_hash(self)
 
         return self._hash
 
     def get_children(self):
@@ -1795,16 +1808,21 @@ Cursor_ref.argtypes = [Cursor]
 Cursor_ref.restype = Cursor
 Cursor_ref.errcheck = Cursor.from_result
 
 Cursor_type = lib.clang_getCursorType
 Cursor_type.argtypes = [Cursor]
 Cursor_type.restype = Type
 Cursor_type.errcheck = Type.from_result
 
+Cursor_underlying_type = lib.clang_getTypedefDeclUnderlyingType
+Cursor_underlying_type.argtypes = [Cursor]
+Cursor_underlying_type.restype = Type
+Cursor_underlying_type.errcheck = Type.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]
 Cursor_visit.restype = c_uint
 
 # Type Functions
 Type_get_canonical = lib.clang_getCanonicalType
 Type_get_canonical.argtypes = [Type]
diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py
index efcede9..d868303 100644
--- a/bindings/python/tests/cindex/test_cursor.py
+++ b/bindings/python/tests/cindex/test_cursor.py
@@ -57,8 +57,23 @@ def test_get_children():
     assert tu_nodes[1].spelling == 's1'
     assert tu_nodes[1].displayname == 's1'
     assert tu_nodes[1].is_definition() == False
 
     assert tu_nodes[2].kind == CursorKind.FUNCTION_DECL
     assert tu_nodes[2].spelling == 'f0'
     assert tu_nodes[2].displayname == 'f0(int, int)'
     assert tu_nodes[2].is_definition() == True
+
+def test_underlying_type():
+    source = 'typedef int foo;'
+    index = Index.create()
+    tu = index.parse('test.c', unsaved_files=[('test.c', source)])
+    assert tu is not None
+
+    for cursor in tu.cursor.get_children():
+        if cursor.spelling == 'foo':
+            typedef = cursor
+            break
+
+    assert typedef.kind.is_declaration()
+    underlying = typedef.underlying_typedef_type
+    assert underlying.kind == TypeKind.INT
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to