diff options
author | Eli Bendersky <eliben@google.com> | 2014-08-05 22:27:50 +0000 |
---|---|---|
committer | Eli Bendersky <eliben@google.com> | 2014-08-05 22:27:50 +0000 |
commit | ac630d930b77643416e3776b11801217bb40c1b3 (patch) | |
tree | 01a7908f8b8bf81aa6b2573d891971104a359355 /bindings | |
parent | 31cad06755bc57a8d4e8cece2169e3bf49721638 (diff) |
Expose the name mangling C API to Python bindings.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214930 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/python/clang/cindex.py | 13 | ||||
-rw-r--r-- | bindings/python/tests/cindex/test_cursor.py | 14 |
2 files changed, 27 insertions, 0 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index 34e08602b8..ebe28fb08a 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -1186,6 +1186,14 @@ class Cursor(Structure): 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 def location(self): """ Return the source location (the starting character) of the entity @@ -2973,6 +2981,11 @@ functionList = [ _CXString, _CXString.from_result), + ("clang_Cursor_getMangling", + [Cursor], + _CXString, + _CXString.from_result), + # ("clang_getCXTUResourceUsage", # [TranslationUnit], # CXTUResourceUsage), diff --git a/bindings/python/tests/cindex/test_cursor.py b/bindings/python/tests/cindex/test_cursor.py index 4315045022..d4ee9daa96 100644 --- a/bindings/python/tests/cindex/test_cursor.py +++ b/bindings/python/tests/cindex/test_cursor.py @@ -252,3 +252,17 @@ def test_referenced(): if c.kind == CursorKind.CALL_EXPR: assert c.referenced.spelling == foo.spelling 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') |