Expose the name mangling C API to Python bindings.

llvm-svn: 214930
This commit is contained in:
Eli Bendersky 2014-08-05 22:27:50 +00:00
parent b8141d55b9
commit d28bc5e2f2
2 changed files with 27 additions and 0 deletions

View File

@ -1185,6 +1185,14 @@ class Cursor(Structure):
return self._displayname return self._displayname
@property
def mangled_name(self):
"""Return the mangled name for the entity referenced by this cursor."""
if not hasattr(self, '_mangled_name'):
self._mangled_name = conf.lib.clang_Cursor_getMangling(self)
return self._mangled_name
@property @property
def location(self): def location(self):
""" """
@ -2973,6 +2981,11 @@ functionList = [
_CXString, _CXString,
_CXString.from_result), _CXString.from_result),
("clang_Cursor_getMangling",
[Cursor],
_CXString,
_CXString.from_result),
# ("clang_getCXTUResourceUsage", # ("clang_getCXTUResourceUsage",
# [TranslationUnit], # [TranslationUnit],
# CXTUResourceUsage), # CXTUResourceUsage),

View File

@ -252,3 +252,17 @@ def test_referenced():
if c.kind == CursorKind.CALL_EXPR: if c.kind == CursorKind.CALL_EXPR:
assert c.referenced.spelling == foo.spelling assert c.referenced.spelling == foo.spelling
break break
def test_mangled_name():
kInputForMangling = """\
int foo(int, int);
"""
tu = get_tu(kInputForMangling, lang='cpp')
foo = get_cursor(tu, 'foo')
# Since libclang does not link in targets, we cannot pass a triple to it
# and force the target. To enable this test to pass on all platforms, accept
# all valid manglings.
# [c-index-test handles this by running the source through clang, emitting
# an AST file and running libclang on that AST file]
assert foo.mangled_name in ('_Z3fooii', '__Z3fooii', '?foo@@YAHHH')