summaryrefslogtreecommitdiffstats
path: root/bindings
diff options
context:
space:
mode:
authorJonathan Coe <jbcoe@me.com>2018-05-10 21:39:29 +0000
committerJonathan Coe <jbcoe@me.com>2018-05-10 21:39:29 +0000
commitf36fd3dfee9cf0d64fcf587cfbe4020a6ff8efad (patch)
treea6d365c4cc340bebf06519a4965b866e4a2b8eab /bindings
parent1cd49d08a42d28f602dd04624f8d9d04083dc551 (diff)
implementing Cursor.get_included_file in python bindings
Summary: adding function: `Cursor.get_included_file` , so the C API's `clang_getIncludedFile` function is available on the python binding interface also adding test to unittests related ticket: https://bugs.llvm.org/show_bug.cgi?id=15223 Reviewers: mgorny, arphaman, jbcoe Reviewed By: jbcoe Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D46383 Patch by jlaz (József Láz) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@332045 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py15
-rw-r--r--bindings/python/tests/cindex/test_translation_unit.py12
2 files changed, 23 insertions, 4 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 06fc79950e..56fcc78763 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -1511,6 +1511,12 @@ class Cursor(Structure):
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 @@ class File(ClangObject):
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 @@ functionList = [
("clang_getIncludedFile",
[Cursor],
- File,
- File.from_cursor_result),
+ c_object_p,
+ File.from_result),
("clang_getInclusions",
[TranslationUnit, callbacks['translation_unit_includes'], py_object]),
diff --git a/bindings/python/tests/cindex/test_translation_unit.py b/bindings/python/tests/cindex/test_translation_unit.py
index 1b3973d59f..09230d1da2 100644
--- a/bindings/python/tests/cindex/test_translation_unit.py
+++ b/bindings/python/tests/cindex/test_translation_unit.py
@@ -108,6 +108,18 @@ int SOME_DEFINE;
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."""