[cfe-commits] r94387 - /cfe/trunk/bindings/python/clang/cindex.py
Daniel Dunbar
daniel at zuster.org
Sun Jan 24 13:20:21 PST 2010
Author: ddunbar
Date: Sun Jan 24 15:20:21 2010
New Revision: 94387
URL: http://llvm.org/viewvc/llvm-project?rev=94387&view=rev
Log:
cindex/Python: Fetch SourceLocation instantiation location information on lazily, it isn't free.
Also, add repr() support to SourceRange.
Modified:
cfe/trunk/bindings/python/clang/cindex.py
Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=94387&r1=94386&r2=94387&view=diff
==============================================================================
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Sun Jan 24 15:20:21 2010
@@ -79,16 +79,30 @@
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 @@
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 @@
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 @@
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):
More information about the cfe-commits
mailing list