r214930 - Expose the name mangling C API to Python bindings.

Eli Bendersky eliben at google.com
Tue Aug 5 15:27:50 PDT 2014


Author: eliben
Date: Tue Aug  5 17:27:50 2014
New Revision: 214930

URL: http://llvm.org/viewvc/llvm-project?rev=214930&view=rev
Log:
Expose the name mangling C API to Python bindings.

Modified:
    cfe/trunk/bindings/python/clang/cindex.py
    cfe/trunk/bindings/python/tests/cindex/test_cursor.py

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=214930&r1=214929&r2=214930&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Tue Aug  5 17:27:50 2014
@@ -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
@@ -2972,6 +2980,11 @@ functionList = [
    [Cursor],
    _CXString,
    _CXString.from_result),
+
+  ("clang_Cursor_getMangling",
+   [Cursor],
+   _CXString,
+   _CXString.from_result),
 
 # ("clang_getCXTUResourceUsage",
 #  [TranslationUnit],

Modified: cfe/trunk/bindings/python/tests/cindex/test_cursor.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/tests/cindex/test_cursor.py?rev=214930&r1=214929&r2=214930&view=diff
==============================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_cursor.py (original)
+++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py Tue Aug  5 17:27:50 2014
@@ -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')





More information about the cfe-commits mailing list