[bindings] add Cursor.linkage
Masud Rahman via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 7 08:42:56 PDT 2017
commit cc52d367ede0f3f306014d0418e18772e0c49dec
Author: Masud Rahman <mrahman15 at bloomberg.net>
Date: Thu Sep 7 11:39:19 2017 -0400
[bindings] add Cursor.linkage
Add Python bindings for the 'clang_getCursorLinkage', and tests to
validate the functionality.
diff --git a/bindings/python/clang/cindex.py
b/bindings/python/clang/cindex.py
index 4069ab8650..5713ab7f29 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1548,6 +1548,13 @@ class Cursor(Structure):
return self._loc
+ @property
+ def linkage(self):
+ if not hasattr(self, '_linkage'):
+ self._linkage = conf.lib.clang_getCursorLinkage(self)
+
+ return LinkageKind.from_id(self._linkage)
+
@property
def extent(self):
"""
@@ -2061,6 +2068,26 @@ RefQualifierKind.NONE = RefQualifierKind(0)
RefQualifierKind.LVALUE = RefQualifierKind(1)
RefQualifierKind.RVALUE = RefQualifierKind(2)
+class LinkageKind(BaseEnumeration):
+ """
+ """
+
+ # The unique kind objects, indexed by id.
+ _kinds = []
+ _name_map = None
+
+ def from_param(self):
+ return self.value
+
+ def __repr__(self):
+ return 'LinkageKind.%s' % (self.name,)
+
+LinkageKind.INVALID = LinkageKind(0)
+LinkageKind.NO_LINKAGE = LinkageKind(1)
+LinkageKind.INTERNAL = LinkageKind(2)
+LinkageKind.UNIQUE_EXTERNAL = LinkageKind(3)
+LinkageKind.EXTERNAL = LinkageKind(4)
+
class Type(Structure):
"""
The type of an element in the abstract syntax tree.
diff --git a/bindings/python/tests/cindex/test_linkage.py
b/bindings/python/tests/cindex/test_linkage.py
new file mode 100644
index 0000000000..392a0f156c
--- /dev/null
+++ b/bindings/python/tests/cindex/test_linkage.py
@@ -0,0 +1,31 @@
+
+from clang.cindex import LinkageKind
+from clang.cindex import Cursor
+from clang.cindex import TranslationUnit
+
+from .util import get_cursor
+from .util import get_tu
+
+def test_linkage():
+ """Ensure that linkage specifers are available on cursors"""
+
+ tu = get_tu("""
+void foo() { int no_linkage; }
+static int internal;
+namespace { extern int unique_external; }
+extern int external;
+""", lang = 'cpp')
+
+ no_linkage = get_cursor(tu.cursor, "no_linkage")
+ assert no_linkage.linkage == LinkageKind.NO_LINKAGE;
+
+ internal = get_cursor(tu.cursor, "internal")
+ assert internal.linkage == LinkageKind.INTERNAL
+
+ unique_external = get_cursor(tu.cursor, "unique_external")
+ assert unique_external.linkage == LinkageKind.UNIQUE_EXTERNAL
+
+ external = get_cursor(tu.cursor, "external")
+ assert external.linkage == LinkageKind.EXTERNAL
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170907/acf714bc/attachment.html>
More information about the cfe-commits
mailing list