[PATCH] D36973: [libclang] Add support for querying cursor availability
jklaehn updated this revision to Diff 116456. jklaehn marked an inline comment as done. jklaehn added a comment. Added test for `AvailabilityKind.DEPRECATED`. `NOT_ACCESSIBLE` is never returned by `clang_getCursorAvailability` but only only used in `CodeCompletionResult`. https://reviews.llvm.org/D36973 Files: bindings/python/clang/cindex.py bindings/python/tests/cindex/test_cursor.py Index: bindings/python/tests/cindex/test_cursor.py === --- bindings/python/tests/cindex/test_cursor.py +++ bindings/python/tests/cindex/test_cursor.py @@ -1,6 +1,7 @@ import ctypes import gc +from clang.cindex import AvailabilityKind from clang.cindex import CursorKind from clang.cindex import TemplateArgumentKind from clang.cindex import TranslationUnit @@ -385,6 +386,30 @@ t = foo.result_type assert t.kind == TypeKind.INT +def test_availability(): +tu = get_tu('class A { A(A const&) = delete; };', lang='cpp') + +# AvailabilityKind.AVAILABLE +cursor = get_cursor(tu, 'A') +assert cursor.kind == CursorKind.CLASS_DECL +assert cursor.availability == AvailabilityKind.AVAILABLE + +# AvailabilityKind.NOT_AVAILABLE +cursors = get_cursors(tu, 'A') +for c in cursors: +if c.kind == CursorKind.CONSTRUCTOR: +assert c.availability == AvailabilityKind.NOT_AVAILABLE +break +else: +assert False, "Could not find cursor for deleted constructor" + +# AvailabilityKind.DEPRECATED +tu = get_tu('#include \n void test(char* s) { std::gets(s); }', lang='cpp') +cursor = get_cursor(tu, 'gets') +assert cursor.availability == AvailabilityKind.DEPRECATED + +# AvailabilityKind.NOT_ACCESSIBLE is only used in the code completion results + def test_get_tokens(): """Ensure we can map cursors back to tokens.""" tu = get_tu('int foo(int i);') Index: bindings/python/clang/cindex.py === --- bindings/python/clang/cindex.py +++ bindings/python/clang/cindex.py @@ -1572,6 +1572,16 @@ return StorageClass.from_id(self._storage_class) +@property +def availability(self): +""" +Retrieves the availability of the entity pointed at by the cursor. +""" +if not hasattr(self, '_availability'): +self._availability = conf.lib.clang_getCursorAvailability(self) + +return AvailabilityKind.from_id(self._availability) + @property def access_specifier(self): """ @@ -1909,6 +1919,24 @@ StorageClass.AUTO = StorageClass(6) StorageClass.REGISTER = StorageClass(7) +### Availability Kinds ### + +class AvailabilityKind(BaseEnumeration): +""" +Describes the availability of an entity. +""" + +# The unique kind objects, indexed by id. +_kinds = [] +_name_map = None + +def __repr__(self): +return 'AvailabilityKind.%s' % (self.name,) + +AvailabilityKind.AVAILABLE = AvailabilityKind(0) +AvailabilityKind.DEPRECATED = AvailabilityKind(1) +AvailabilityKind.NOT_AVAILABLE = AvailabilityKind(2) +AvailabilityKind.NOT_ACCESSIBLE = AvailabilityKind(3) ### C++ access specifiers ### @@ -3440,6 +3468,10 @@ [TranslationUnit, SourceLocation], Cursor), + ("clang_getCursorAvailability", + [Cursor], + c_int), + ("clang_getCursorDefinition", [Cursor], Cursor, @@ -4055,6 +4087,7 @@ register_enumerations() __all__ = [ +'AvailabilityKind', 'Config', 'CodeCompletionResults', 'CompilationDatabase', ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36973: [libclang] Add support for querying cursor availability
jbcoe added inline comments. Comment at: bindings/python/tests/cindex/test_cursor.py:407 +# AvailabilityKind.DEPRECATED +tu = get_tu('#include \n void test(char* s) { std::gets(s); }', lang='cpp') +cursor = get_cursor(tu, 'gets') It might be better to use a user-defined function that is explicitly deprecated rather than relying on 3rd party standard includes deprecating things for you. https://reviews.llvm.org/D36973 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36973: [libclang] Add support for querying cursor availability
jklaehn updated this revision to Diff 118333. jklaehn added a comment. Use user-defined function for test of `AvailabilityKind.DEPRECATED`. https://reviews.llvm.org/D36973 Files: bindings/python/clang/cindex.py bindings/python/tests/cindex/test_cursor.py Index: bindings/python/tests/cindex/test_cursor.py === --- bindings/python/tests/cindex/test_cursor.py +++ bindings/python/tests/cindex/test_cursor.py @@ -1,6 +1,7 @@ import ctypes import gc +from clang.cindex import AvailabilityKind from clang.cindex import CursorKind from clang.cindex import TemplateArgumentKind from clang.cindex import TranslationUnit @@ -385,6 +386,30 @@ t = foo.result_type assert t.kind == TypeKind.INT +def test_availability(): +tu = get_tu('class A { A(A const&) = delete; };', lang='cpp') + +# AvailabilityKind.AVAILABLE +cursor = get_cursor(tu, 'A') +assert cursor.kind == CursorKind.CLASS_DECL +assert cursor.availability == AvailabilityKind.AVAILABLE + +# AvailabilityKind.NOT_AVAILABLE +cursors = get_cursors(tu, 'A') +for c in cursors: +if c.kind == CursorKind.CONSTRUCTOR: +assert c.availability == AvailabilityKind.NOT_AVAILABLE +break +else: +assert False, "Could not find cursor for deleted constructor" + +# AvailabilityKind.DEPRECATED +tu = get_tu('void test() __attribute__((deprecated));', lang='cpp') +cursor = get_cursor(tu, 'test') +assert cursor.availability == AvailabilityKind.DEPRECATED + +# AvailabilityKind.NOT_ACCESSIBLE is only used in the code completion results + def test_get_tokens(): """Ensure we can map cursors back to tokens.""" tu = get_tu('int foo(int i);') Index: bindings/python/clang/cindex.py === --- bindings/python/clang/cindex.py +++ bindings/python/clang/cindex.py @@ -1572,6 +1572,16 @@ return StorageClass.from_id(self._storage_class) +@property +def availability(self): +""" +Retrieves the availability of the entity pointed at by the cursor. +""" +if not hasattr(self, '_availability'): +self._availability = conf.lib.clang_getCursorAvailability(self) + +return AvailabilityKind.from_id(self._availability) + @property def access_specifier(self): """ @@ -1909,6 +1919,24 @@ StorageClass.AUTO = StorageClass(6) StorageClass.REGISTER = StorageClass(7) +### Availability Kinds ### + +class AvailabilityKind(BaseEnumeration): +""" +Describes the availability of an entity. +""" + +# The unique kind objects, indexed by id. +_kinds = [] +_name_map = None + +def __repr__(self): +return 'AvailabilityKind.%s' % (self.name,) + +AvailabilityKind.AVAILABLE = AvailabilityKind(0) +AvailabilityKind.DEPRECATED = AvailabilityKind(1) +AvailabilityKind.NOT_AVAILABLE = AvailabilityKind(2) +AvailabilityKind.NOT_ACCESSIBLE = AvailabilityKind(3) ### C++ access specifiers ### @@ -3440,6 +3468,10 @@ [TranslationUnit, SourceLocation], Cursor), + ("clang_getCursorAvailability", + [Cursor], + c_int), + ("clang_getCursorDefinition", [Cursor], Cursor, @@ -4055,6 +4087,7 @@ register_enumerations() __all__ = [ +'AvailabilityKind', 'Config', 'CodeCompletionResults', 'CompilationDatabase', ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36973: [libclang] Add support for querying cursor availability
jbcoe accepted this revision. jbcoe added a comment. This revision is now accepted and ready to land. LGTM Would you like me to commit this for you? https://reviews.llvm.org/D36973 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36973: [libclang] Add support for querying cursor availability
jklaehn marked an inline comment as done. jklaehn added a comment. In https://reviews.llvm.org/D36973#893851, @jbcoe wrote: > LGTM > > Would you like me to commit this for you? Yes, that would be great! https://reviews.llvm.org/D36973 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36973: [libclang] Add support for querying cursor availability
This revision was automatically updated to reflect the committed changes. Closed by commit rL315959: [libclang] Add support for querying cursor availability (authored by jbcoe). Changed prior to commit: https://reviews.llvm.org/D36973?vs=118333&id=119234#toc Repository: rL LLVM https://reviews.llvm.org/D36973 Files: cfe/trunk/bindings/python/clang/cindex.py cfe/trunk/bindings/python/tests/cindex/test_cursor.py Index: cfe/trunk/bindings/python/clang/cindex.py === --- cfe/trunk/bindings/python/clang/cindex.py +++ cfe/trunk/bindings/python/clang/cindex.py @@ -1587,6 +1587,16 @@ return StorageClass.from_id(self._storage_class) @property +def availability(self): +""" +Retrieves the availability of the entity pointed at by the cursor. +""" +if not hasattr(self, '_availability'): +self._availability = conf.lib.clang_getCursorAvailability(self) + +return AvailabilityKind.from_id(self._availability) + +@property def access_specifier(self): """ Retrieves the access specifier (if any) of the entity pointed at by the @@ -1923,6 +1933,24 @@ StorageClass.AUTO = StorageClass(6) StorageClass.REGISTER = StorageClass(7) +### Availability Kinds ### + +class AvailabilityKind(BaseEnumeration): +""" +Describes the availability of an entity. +""" + +# The unique kind objects, indexed by id. +_kinds = [] +_name_map = None + +def __repr__(self): +return 'AvailabilityKind.%s' % (self.name,) + +AvailabilityKind.AVAILABLE = AvailabilityKind(0) +AvailabilityKind.DEPRECATED = AvailabilityKind(1) +AvailabilityKind.NOT_AVAILABLE = AvailabilityKind(2) +AvailabilityKind.NOT_ACCESSIBLE = AvailabilityKind(3) ### C++ access specifiers ### @@ -3491,6 +3519,10 @@ [TranslationUnit, SourceLocation], Cursor), + ("clang_getCursorAvailability", + [Cursor], + c_int), + ("clang_getCursorDefinition", [Cursor], Cursor, @@ -4106,6 +4138,7 @@ register_enumerations() __all__ = [ +'AvailabilityKind', 'Config', 'CodeCompletionResults', 'CompilationDatabase', Index: cfe/trunk/bindings/python/tests/cindex/test_cursor.py === --- cfe/trunk/bindings/python/tests/cindex/test_cursor.py +++ cfe/trunk/bindings/python/tests/cindex/test_cursor.py @@ -1,6 +1,7 @@ import ctypes import gc +from clang.cindex import AvailabilityKind from clang.cindex import CursorKind from clang.cindex import TemplateArgumentKind from clang.cindex import TranslationUnit @@ -405,6 +406,30 @@ t = foo.result_type assert t.kind == TypeKind.INT +def test_availability(): +tu = get_tu('class A { A(A const&) = delete; };', lang='cpp') + +# AvailabilityKind.AVAILABLE +cursor = get_cursor(tu, 'A') +assert cursor.kind == CursorKind.CLASS_DECL +assert cursor.availability == AvailabilityKind.AVAILABLE + +# AvailabilityKind.NOT_AVAILABLE +cursors = get_cursors(tu, 'A') +for c in cursors: +if c.kind == CursorKind.CONSTRUCTOR: +assert c.availability == AvailabilityKind.NOT_AVAILABLE +break +else: +assert False, "Could not find cursor for deleted constructor" + +# AvailabilityKind.DEPRECATED +tu = get_tu('void test() __attribute__((deprecated));', lang='cpp') +cursor = get_cursor(tu, 'test') +assert cursor.availability == AvailabilityKind.DEPRECATED + +# AvailabilityKind.NOT_ACCESSIBLE is only used in the code completion results + def test_get_tokens(): """Ensure we can map cursors back to tokens.""" tu = get_tu('int foo(int i);') ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D36973: [libclang] Add support for querying cursor availability
jklaehn created this revision. jklaehn added a project: clang. This patch allows checking the availability of cursors through libclang and clang.cindex (Python). This e.g. allows to check whether a C++ member function has been marked as deleted. https://reviews.llvm.org/D36973 Files: bindings/python/clang/cindex.py bindings/python/tests/cindex/test_cursor.py Index: bindings/python/tests/cindex/test_cursor.py === --- bindings/python/tests/cindex/test_cursor.py +++ bindings/python/tests/cindex/test_cursor.py @@ -1,6 +1,7 @@ import ctypes import gc +from clang.cindex import AvailabilityKind from clang.cindex import CursorKind from clang.cindex import TemplateArgumentKind from clang.cindex import TranslationUnit @@ -385,6 +386,18 @@ t = foo.result_type assert t.kind == TypeKind.INT +def test_availability(): +tu = get_tu('class A { A(A const&) = delete; };', lang='cpp') +cursors = get_cursors(tu, "A") +for c in cursors: +if c.kind == CursorKind.CLASS_DECL: +assert c.availability == AvailabilityKind.AVAILABLE +if c.kind == CursorKind.CONSTRUCTOR: +assert c.availability == AvailabilityKind.NOT_AVAILABLE +break +else: +assert False, "Could not find cursor for deleted constructor" + def test_get_tokens(): """Ensure we can map cursors back to tokens.""" tu = get_tu('int foo(int i);') Index: bindings/python/clang/cindex.py === --- bindings/python/clang/cindex.py +++ bindings/python/clang/cindex.py @@ -1572,6 +1572,16 @@ return StorageClass.from_id(self._storage_class) +@property +def availability(self): +""" +Retrieves the availability of the entity pointed at by the cursor. +""" +if not hasattr(self, '_availability'): +self._availability = conf.lib.clang_getCursorAvailability(self) + +return AvailabilityKind.from_id(self._availability) + @property def access_specifier(self): """ @@ -1909,6 +1919,25 @@ StorageClass.AUTO = StorageClass(6) StorageClass.REGISTER = StorageClass(7) +### Availability Kinds ### + +class AvailabilityKind(BaseEnumeration): +""" +Describes the availability of an entity. +""" + +# The unique kind objects, indexed by id. +_kinds = [] +_name_map = None + +def __repr__(self): +return 'AvailabilityKind.%s' % (self.name,) + +AvailabilityKind.AVAILABLE = AvailabilityKind(0) +AvailabilityKind.DEPRECATED = AvailabilityKind(1) +AvailabilityKind.NOT_AVAILABLE = AvailabilityKind(2) +AvailabilityKind.NOT_ACCESSIBLE = AvailabilityKind(3) + ### C++ access specifiers ### @@ -3440,6 +3469,10 @@ [TranslationUnit, SourceLocation], Cursor), + ("clang_getCursorAvailability", + [Cursor], + c_int), + ("clang_getCursorDefinition", [Cursor], Cursor, Index: bindings/python/tests/cindex/test_cursor.py === --- bindings/python/tests/cindex/test_cursor.py +++ bindings/python/tests/cindex/test_cursor.py @@ -1,6 +1,7 @@ import ctypes import gc +from clang.cindex import AvailabilityKind from clang.cindex import CursorKind from clang.cindex import TemplateArgumentKind from clang.cindex import TranslationUnit @@ -385,6 +386,18 @@ t = foo.result_type assert t.kind == TypeKind.INT +def test_availability(): +tu = get_tu('class A { A(A const&) = delete; };', lang='cpp') +cursors = get_cursors(tu, "A") +for c in cursors: +if c.kind == CursorKind.CLASS_DECL: +assert c.availability == AvailabilityKind.AVAILABLE +if c.kind == CursorKind.CONSTRUCTOR: +assert c.availability == AvailabilityKind.NOT_AVAILABLE +break +else: +assert False, "Could not find cursor for deleted constructor" + def test_get_tokens(): """Ensure we can map cursors back to tokens.""" tu = get_tu('int foo(int i);') Index: bindings/python/clang/cindex.py === --- bindings/python/clang/cindex.py +++ bindings/python/clang/cindex.py @@ -1572,6 +1572,16 @@ return StorageClass.from_id(self._storage_class) +@property +def availability(self): +""" +Retrieves the availability of the entity pointed at by the cursor. +""" +if not hasattr(self, '_availability'): +self._availability = conf.lib.clang_getCursorAvailability(self) + +return AvailabilityKind.from_id(self._availability) + @property def access_specifier(self): """ @@ -1909,6 +1919,25 @@ StorageClass.AUTO = StorageClass(6) StorageClass.REGISTER = StorageClass(7) +### Availability Kinds ### + +class AvailabilityKind(BaseEnumeration): +""" +Describes the availability of an entity. +"""
[PATCH] D36973: [libclang] Add support for querying cursor availability
jbcoe requested changes to this revision. jbcoe added inline comments. This revision now requires changes to proceed. Comment at: bindings/python/tests/cindex/test_cursor.py:399 +else: +assert False, "Could not find cursor for deleted constructor" + Can you add tests for the other `AvailabilityKind`s? https://reviews.llvm.org/D36973 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits