[cfe-commits] r149829 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_cursor.py
Tobias Grosser
grosser at fim.uni-passau.de
Sun Feb 5 03:42:20 PST 2012
Author: grosser
Date: Sun Feb 5 05:42:20 2012
New Revision: 149829
URL: http://llvm.org/viewvc/llvm-project?rev=149829&view=rev
Log:
[clang.py] Implement Cursor.underlying_typedef_type
Contributed by: Gregory Szorc <gregory.szorc at gmail.com>
Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/bindings/python/tests/cindex/test_cursor.py
Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=149829&r1=149828&r2=149829&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sun Feb 5 05:42:20 2012
@@ -982,6 +982,19 @@
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'):
@@ -1800,6 +1813,11 @@
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]
Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor.py?rev=149829&r1=149828&r2=149829&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cursor.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py Sun Feb 5 05:42:20 2012
@@ -62,3 +62,18 @@
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
More information about the cfe-commits
mailing list