summaryrefslogtreecommitdiff
path: root/bindings
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2010-01-24 21:20:21 +0000
committerDaniel Dunbar <daniel@zuster.org>2010-01-24 21:20:21 +0000
commitf869083cbfea538d6b7baf4ece30066b11984e12 (patch)
tree7a397d9ede9ac7ff158841228d263d12ea9b25bf /bindings
parent3d855f8d48b235eb2beb45216cced24efd3c08fa (diff)
downloadclang-f869083cbfea538d6b7baf4ece30066b11984e12.tar.gz
cindex/Python: Fetch SourceLocation instantiation location information on lazily, it isn't free.
Also, add repr() support to SourceRange. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94387 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings')
-rw-r--r--bindings/python/clang/cindex.py41
1 files changed, 29 insertions, 12 deletions
diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py
index 39239e5020..dccc42974e 100644
--- a/bindings/python/clang/cindex.py
+++ b/bindings/python/clang/cindex.py
@@ -79,16 +79,30 @@ class SourceLocation(Structure):
A SourceLocation represents a particular location within a source file.
"""
_fields_ = [("ptr_data", c_void_p), ("int_data", c_uint)]
+ _data = None
- def init(self):
- """
- Initialize the source location, setting its file, line and column.
- """
- f, l, c = c_object_p(), c_uint(), c_uint()
- SourceLocation_loc(self, byref(f), byref(l), byref(c))
- f = File(f) if f else None
- self.file, self.line, self.column = f, int(l.value), int(c.value)
- return self
+ def _get_instantiation(self):
+ if self._data is None:
+ f, l, c = c_object_p(), c_uint(), c_uint()
+ SourceLocation_loc(self, byref(f), byref(l), byref(c))
+ f = File(f) if f else None
+ self._data = (f, int(l.value), int(c.value))
+ return self._data
+
+ @property
+ def file(self):
+ """Get the file represented by this source location."""
+ return self._get_instantiation()[0]
+
+ @property
+ def line(self):
+ """Get the line represented by this source location."""
+ return self._get_instantiation()[1]
+
+ @property
+ def column(self):
+ """Get the column represented by this source location."""
+ return self._get_instantiation()[2]
def __repr__(self):
return "<SourceLocation file %r, line %r, column %r>" % (
@@ -110,7 +124,7 @@ class SourceRange(Structure):
Return a SourceLocation representing the first character within a
source range.
"""
- return SourceRange_start(self).init()
+ return SourceRange_start(self)
@property
def end(self):
@@ -118,7 +132,10 @@ class SourceRange(Structure):
Return a SourceLocation representing the last character within a
source range.
"""
- return SourceRange_end(self).init()
+ return SourceRange_end(self)
+
+ def __repr__(self):
+ return "<SourceRange start %r, end %r>" % (self.start, self.end)
class Cursor(Structure):
"""
@@ -200,7 +217,7 @@ class Cursor(Structure):
Return the source location (the starting character) of the entity
pointed at by the cursor.
"""
- return Cursor_loc(self).init()
+ return Cursor_loc(self)
@property
def extent(self):