]> granicus.if.org Git - clang/commitdiff
Expose the name mangling C API to Python bindings.
authorEli Bendersky <eliben@google.com>
Tue, 5 Aug 2014 22:27:50 +0000 (22:27 +0000)
committerEli Bendersky <eliben@google.com>
Tue, 5 Aug 2014 22:27:50 +0000 (22:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214930 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/clang/cindex.py
bindings/python/tests/cindex/test_cursor.py

index 34e08602b834718dd024f43d8abd8d6e4fe9637c..ebe28fb08a44f7d12965fb6d9b9f979d337c8ae5 100644 (file)
@@ -1185,6 +1185,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):
         """
@@ -2973,6 +2981,11 @@ functionList = [
    _CXString,
    _CXString.from_result),
 
+  ("clang_Cursor_getMangling",
+   [Cursor],
+   _CXString,
+   _CXString.from_result),
+
 # ("clang_getCXTUResourceUsage",
 #  [TranslationUnit],
 #  CXTUResourceUsage),
index 43150450224551f8c5e29027ecf81e01bc60d27c..d4ee9daa9614d5f9a1a1fc69390cd9f29676ed05 100644 (file)
@@ -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')