зеркало из https://github.com/microsoft/clang-1.git
[clang.py] Implement TypeKind.spelling
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154769 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
2d7cb069fe
Коммит
6e67eed327
|
@ -1079,6 +1079,11 @@ class TypeKind(object):
|
|||
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 @@ class TypeKind(object):
|
|||
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)
|
||||
|
|
|
@ -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 @@ def test_equal():
|
|||
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);')
|
||||
|
|
Загрузка…
Ссылка в новой задаче