diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-09-22 18:35:09 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-09-22 18:35:09 +0000 |
commit | da4e89c8477c389ad03d1ba659bbfa23df1584cd (patch) | |
tree | 0661855352ca0739cbdd0a5c38f4f73bea4c4787 /bindings | |
parent | 74d4b6706e86e2b92c38cc801053cb174636d53a (diff) |
bindings: expose Linkage to the python bindings
Add Python bindings for the 'clang_getCursorLinkage', and tests to
validate the functionality.
Patch by Masud Rahman!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@314009 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r-- | bindings/python/clang/cindex.py | 28 | ||||
-rw-r--r-- | bindings/python/tests/cindex/test_linkage.py | 30 |
2 files changed, 58 insertions, 0 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index 6a53bc0c47..c236a47651 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -1549,6 +1549,14 @@ class Cursor(Structure): return self._loc @property + def linkage(self): + """Return the linkage of this cursor.""" + if not hasattr(self, '_linkage'): + self._linkage = conf.lib.clang_getCursorLinkage(self) + + return LinkageKind.from_id(self._linkage) + + @property def tls_kind(self): """Return the thread-local storage (TLS) kind of this cursor.""" if not hasattr(self, '_tls_kind'): @@ -2069,6 +2077,25 @@ RefQualifierKind.NONE = RefQualifierKind(0) RefQualifierKind.LVALUE = RefQualifierKind(1) RefQualifierKind.RVALUE = RefQualifierKind(2) +class LinkageKind(BaseEnumeration): + """Describes the kind of linkage of a cursor.""" + + # 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 TLSKind(BaseEnumeration): """Describes the kind of thread-local storage (TLS) of a cursor.""" @@ -4090,6 +4117,7 @@ __all__ = [ 'File', 'FixIt', 'Index', + 'LinkageKind', 'SourceLocation', 'SourceRange', 'TLSKind', diff --git a/bindings/python/tests/cindex/test_linkage.py b/bindings/python/tests/cindex/test_linkage.py new file mode 100644 index 0000000000..2f056d5140 --- /dev/null +++ b/bindings/python/tests/cindex/test_linkage.py @@ -0,0 +1,30 @@ + +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 + |