[PATCH] D147414: [python] Expose clang_Location_isInSystemHeader
Artur Ryt via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 3 10:00:49 PDT 2023
R2RT updated this revision to Diff 510542.
R2RT added a comment.
Bring back Python section in release notes and document new `is_in_system_header` property.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147414/new/
https://reviews.llvm.org/D147414
Files:
clang/bindings/python/clang/cindex.py
clang/bindings/python/tests/cindex/test_location.py
clang/docs/ReleaseNotes.rst
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -436,6 +436,13 @@
Sanitizers
----------
+Python Binding Changes
+----------------------
+
+The following methods have been added:
+
+- `clang_Location_isInSystemHeader` exposed via `is_in_system_header` property
+ of `Location` class.
Additional Information
======================
Index: clang/bindings/python/tests/cindex/test_location.py
===================================================================
--- clang/bindings/python/tests/cindex/test_location.py
+++ clang/bindings/python/tests/cindex/test_location.py
@@ -7,6 +7,7 @@
from clang.cindex import File
from clang.cindex import SourceLocation
from clang.cindex import SourceRange
+from clang.cindex import TranslationUnit
from .util import get_cursor
from .util import get_tu
@@ -103,3 +104,17 @@
location3 = SourceLocation.from_position(tu, file, 1, 6)
range3 = SourceRange.from_locations(location1, location3)
self.assertNotEqual(range1, range3)
+
+ def test_is_system_location(self):
+ header = os.path.normpath('./fake/fake.h')
+ tu = TranslationUnit.from_source('fake.c', [f'-isystem{os.path.dirname(header)}'], unsaved_files = [
+ ('fake.c', """
+#include <fake.h>
+int one;
+"""),
+ (header, "int two();")
+ ])
+ one = get_cursor(tu, 'one')
+ two = get_cursor(tu, 'two')
+ self.assertFalse(one.location.is_in_system_header)
+ self.assertTrue(two.location.is_in_system_header)
Index: clang/bindings/python/clang/cindex.py
===================================================================
--- clang/bindings/python/clang/cindex.py
+++ clang/bindings/python/clang/cindex.py
@@ -286,6 +286,11 @@
"""Get the file offset represented by this source location."""
return self._get_instantiation()[3]
+ @property
+ def is_in_system_header(self):
+ """Returns true if the given source location is in a system header."""
+ return conf.lib.clang_Location_isInSystemHeader(self)
+
def __eq__(self, other):
return conf.lib.clang_equalLocations(self, other)
@@ -4131,6 +4136,10 @@
[Cursor],
c_longlong),
+ ("clang_Location_isInSystemHeader",
+ [SourceLocation],
+ bool),
+
("clang_Type_getAlignOf",
[Type],
c_longlong),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147414.510542.patch
Type: text/x-patch
Size: 2461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230403/34d9937b/attachment.bin>
More information about the cfe-commits
mailing list