summaryrefslogtreecommitdiffstats
path: root/clang/bindings
diff options
context:
space:
mode:
authorTobias Grosser <grosser@fim.uni-passau.de>2012-02-05 11:42:25 +0000
committerTobias Grosser <grosser@fim.uni-passau.de>2012-02-05 11:42:25 +0000
commita0022e911ec13976ea91e31ea7f713ab89cfe439 (patch)
tree94a3f663f4c35e7621b35378704f0c5dbe697bba /clang/bindings
parent062d2a3c89d801ac3075f926c5d04a2556aaa9dc (diff)
downloadbcm5719-llvm-a0022e911ec13976ea91e31ea7f713ab89cfe439.tar.gz
bcm5719-llvm-a0022e911ec13976ea91e31ea7f713ab89cfe439.zip
[clang.py] Implement Cursor.enum_type
Contributed by: Gregory Szorc <gregory.szorc@gmail.com> llvm-svn: 149830
Diffstat (limited to 'clang/bindings')
-rw-r--r--clang/bindings/python/clang/cindex.py18
-rw-r--r--clang/bindings/python/tests/cindex/test_cursor.py15
2 files changed, 33 insertions, 0 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 4c819c26fec..86292132074 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -995,6 +995,19 @@ class Cursor(Structure):
return self._underlying_type
@property
+ def enum_type(self):
+ """Return the integer type of an enum declaration.
+
+ Returns a type corresponding to an integer. If the cursor is not for an
+ enum, this raises.
+ """
+ if not hasattr(self, '_enum_type'):
+ assert self.kind == CursorKind.ENUM_DECL
+ self._enum_type = Cursor_enum_type(self)
+
+ return self._enum_type
+
+ @property
def hash(self):
"""Returns a hash of the cursor as an int."""
if not hasattr(self, '_hash'):
@@ -1818,6 +1831,11 @@ Cursor_underlying_type.argtypes = [Cursor]
Cursor_underlying_type.restype = Type
Cursor_underlying_type.errcheck = Type.from_result
+Cursor_enum_type = lib.clang_getEnumDeclIntegerType
+Cursor_enum_type.argtypes = [Cursor]
+Cursor_enum_type.restype = Type
+Cursor_enum_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]
diff --git a/clang/bindings/python/tests/cindex/test_cursor.py b/clang/bindings/python/tests/cindex/test_cursor.py
index d86830334dd..71ee0c5763e 100644
--- a/clang/bindings/python/tests/cindex/test_cursor.py
+++ b/clang/bindings/python/tests/cindex/test_cursor.py
@@ -77,3 +77,18 @@ def test_underlying_type():
assert typedef.kind.is_declaration()
underlying = typedef.underlying_typedef_type
assert underlying.kind == TypeKind.INT
+
+def test_enum_type():
+ source = 'enum TEST { FOO=1, BAR=2 };'
+ 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 == 'TEST':
+ enum = cursor
+ break
+
+ assert enum.kind == CursorKind.ENUM_DECL
+ enum_type = enum.enum_type
+ assert enum_type.kind == TypeKind.UINT
OpenPOWER on IntegriCloud