cindex.py: Allow to create a cursor from file/row/column
We add a constructor to create a SourceLocation from a position in
a file and we use this SourceLocation to retrieve a cursor.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143322 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index c66e356..9ab9ae8 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -115,6 +115,14 @@
self._data = (f, int(l.value), int(c.value), int(o.value))
return self._data
+ @staticmethod
+ def from_position(tu, file, line, column):
+ """
+ Retrieve the source location associated with a given file/line/column in
+ a particular translation unit.
+ """
+ return SourceLocation_getLocation(tu, file, line, column)
+
@property
def file(self):
"""Get the file represented by this source location."""
@@ -817,6 +825,10 @@
"""
_fields_ = [("_kind_id", c_int), ("xdata", c_int), ("data", c_void_p * 3)]
+ @staticmethod
+ def from_location(tu, location):
+ return Cursor_get(tu, location)
+
def __eq__(self, other):
return Cursor_eq(self, other)
@@ -1580,6 +1592,10 @@
POINTER(c_uint), POINTER(c_uint),
POINTER(c_uint)]
+SourceLocation_getLocation = lib.clang_getLocation
+SourceLocation_getLocation.argtypes = [TranslationUnit, File, c_uint, c_uint]
+SourceLocation_getLocation.restype = SourceLocation
+
# Source Range Functions
SourceRange_getRange = lib.clang_getRange
SourceRange_getRange.argtypes = [SourceLocation, SourceLocation]