diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2010-01-24 21:20:21 +0000 | 
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2010-01-24 21:20:21 +0000 | 
| commit | 55d6964e28e2653561dff2beb64442654f4666bf (patch) | |
| tree | 5037feeeb45eebdaf0404d621cbf559064f67233 /clang | |
| parent | aca5acfd014188e5d0bcceb2b4322ecc6156540b (diff) | |
| download | bcm5719-llvm-55d6964e28e2653561dff2beb64442654f4666bf.tar.gz bcm5719-llvm-55d6964e28e2653561dff2beb64442654f4666bf.zip  | |
cindex/Python: Fetch SourceLocation instantiation location information on lazily, it isn't free.
Also, add repr() support to SourceRange.
llvm-svn: 94387
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/bindings/python/clang/cindex.py | 41 | 
1 files changed, 29 insertions, 12 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 39239e5020c..dccc42974e1 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/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):  | 

