[cfe-commits] r154769 - in /cfe/trunk/bindings/python: clang/cindex.py tests/cindex/test_type.py
Gregory Szorc
gregory.szorc at gmail.com
Sun Apr 15 11:51:10 PDT 2012
Author: gps
Date: Sun Apr 15 13:51:10 2012
New Revision: 154769
URL: http://llvm.org/viewvc/llvm-project?rev=154769&view=rev
Log:
[clang.py] Implement TypeKind.spelling
Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/bindings/python/tests/cindex/test_type.py
Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=154769&r1=154768&r2=154769&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sun Apr 15 13:51:10 2012
@@ -1079,6 +1079,11 @@
self._name_map[value] = key
return self._name_map[self]
+ @property
+ def spelling(self):
+ """Retrieve the spelling of this TypeKind."""
+ return TypeKind_spelling(self.value)
+
@staticmethod
def from_id(id):
if id >= len(TypeKind._kinds) or TypeKind._kinds[id] is None:
@@ -1088,6 +1093,10 @@
def __repr__(self):
return 'TypeKind.%s' % (self.name,)
+TypeKind_spelling = lib.clang_getTypeKindSpelling
+TypeKind_spelling.argtypes = [c_uint]
+TypeKind_spelling.restype = _CXString
+TypeKind_spelling.errcheck = _CXString.from_result
TypeKind.INVALID = TypeKind(0)
Modified: cfe/trunk/bindings/python/tests/cindex/test_type.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_type.py?rev=154769&r1=154768&r2=154769&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_type.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_type.py Sun Apr 15 13:51:10 2012
@@ -1,5 +1,4 @@
from clang.cindex import CursorKind
-from clang.cindex import Index
from clang.cindex import TypeKind
from nose.tools import raises
from .util import get_cursor
@@ -109,6 +108,14 @@
assert a.type != None
assert a.type != 'foo'
+def test_typekind_spelling():
+ """Ensure TypeKind.spelling works."""
+ tu = get_tu('int a;')
+ a = get_cursor(tu, 'a')
+
+ assert a is not None
+ assert a.type.kind.spelling == 'Int'
+
def test_function_argument_types():
"""Ensure that Type.argument_types() works as expected."""
tu = get_tu('void f(int, int);')
More information about the cfe-commits
mailing list