aboutsummaryrefslogtreecommitdiff
path: root/bindings/python/clang/cindex.py
diff options
context:
space:
mode:
authorGregory Szorc <gregory.szorc@gmail.com>2012-06-11 11:11:48 +0000
committerGregory Szorc <gregory.szorc@gmail.com>2012-06-11 11:11:48 +0000
commit74bb710e73229ce0ad3bb27c8689c0276e8ec131 (patch)
tree63089e477ac76cfe5a06ce12f815e6b2113d516c /bindings/python/clang/cindex.py
parentecbc00929cde5db985b38682b1f62fcc62b3a2fe (diff)
[clang.py] Implement SourceLocation.from_offset
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158307 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/clang/cindex.py')
-rw-r--r--bindings/python/clang/cindex.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 7a637112a2..02cec2d796 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -169,6 +169,16 @@ class SourceLocation(Structure):
"""
return SourceLocation_getLocation(tu, file, line, column)
+ @staticmethod
+ def from_offset(tu, file, offset):
+ """Retrieve a SourceLocation from a given character offset.
+
+ tu -- TranslationUnit file belongs to
+ file -- File instance to obtain offset from
+ offset -- Integer character offset within file
+ """
+ return SourceLocation_getLocationForOffset(tu, file, offset)
+
@property
def file(self):
"""Get the file represented by this source location."""
@@ -2110,6 +2120,10 @@ SourceLocation_equalLocations = lib.clang_equalLocations
SourceLocation_equalLocations.argtypes = [SourceLocation, SourceLocation]
SourceLocation_equalLocations.restype = bool
+SourceLocation_getLocationForOffset = lib.clang_getLocationForOffset
+SourceLocation_getLocationForOffset.argtypes = [TranslationUnit, File, c_uint]
+SourceLocation_getLocationForOffset.restype = SourceLocation
+
# Source Range Functions
SourceRange_getRange = lib.clang_getRange
SourceRange_getRange.argtypes = [SourceLocation, SourceLocation]