[PATCH] D46383: implementing Cursor.get_included_file in python bindings
Jonathan B Coe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 10 14:43:21 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332045: implementing Cursor.get_included_file in python bindings (authored by jbcoe, committed by ).
Herald added a subscriber: llvm-commits.
Changed prior to commit:
https://reviews.llvm.org/D46383?vs=144992&id=146230#toc
Repository:
rL LLVM
https://reviews.llvm.org/D46383
Files:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py
Index: cfe/trunk/bindings/python/clang/cindex.py
===================================================================
--- cfe/trunk/bindings/python/clang/cindex.py
+++ cfe/trunk/bindings/python/clang/cindex.py
@@ -1511,6 +1511,12 @@
another translation unit."""
return conf.lib.clang_getCursorUSR(self)
+ def get_included_file(self):
+ """Returns the File that is included by the current inclusion cursor."""
+ assert self.kind == CursorKind.INCLUSION_DIRECTIVE
+
+ return conf.lib.clang_getIncludedFile(self)
+
@property
def kind(self):
"""Return the kind of this cursor."""
@@ -3085,8 +3091,9 @@
return "<File: %s>" % (self.name)
@staticmethod
- def from_cursor_result(res, fn, args):
- assert isinstance(res, File)
+ def from_result(res, fn, args):
+ assert isinstance(res, c_object_p)
+ res = File(res)
# Copy a reference to the TranslationUnit to prevent premature GC.
res._tu = args[0]._tu
@@ -3701,8 +3708,8 @@
("clang_getIncludedFile",
[Cursor],
- File,
- File.from_cursor_result),
+ c_object_p,
+ File.from_result),
("clang_getInclusions",
[TranslationUnit, callbacks['translation_unit_includes'], py_object]),
Index: cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py
===================================================================
--- cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py
+++ cfe/trunk/bindings/python/tests/cindex/test_translation_unit.py
@@ -108,6 +108,18 @@
for i in zip(inc, tu.get_includes()):
eq(i[0], i[1])
+ def test_inclusion_directive(self):
+ src = os.path.join(kInputsDir, 'include.cpp')
+ h1 = os.path.join(kInputsDir, "header1.h")
+ h2 = os.path.join(kInputsDir, "header2.h")
+ h3 = os.path.join(kInputsDir, "header3.h")
+ inc = [h1, h3, h2, h3, h1]
+
+ tu = TranslationUnit.from_source(src, options=TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD)
+ inclusion_directive_files = [c.get_included_file().name for c in tu.cursor.get_children() if c.kind == CursorKind.INCLUSION_DIRECTIVE]
+ for i in zip(inc, inclusion_directive_files):
+ self.assert_normpaths_equal(i[0], i[1])
+
def test_save(self):
"""Ensure TranslationUnit.save() works."""
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46383.146230.patch
Type: text/x-patch
Size: 2373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180510/cd210044/attachment-0001.bin>
More information about the cfe-commits
mailing list