@@ -214,45 +214,25 @@ def from_result(res, fn=None, args=None):
214
214
assert isinstance (res , _CXString )
215
215
return conf .lib .clang_getCString (res )
216
216
217
- class Location (object ):
218
- """A Location is a specific kind of source location. A SourceLocation
219
- refers to several kinds of locations (e.g. spelling location vs. expansion
220
- location)."""
221
-
222
- def __init__ (self , file , line , column , offset ):
223
- self ._file = File (file ) if file else None
224
- self ._line = int (line .value )
225
- self ._column = int (column .value )
226
- self ._offset = int (offset .value )
227
-
228
-
229
- @property
230
- def file (self ):
231
- """Get the file represented by this source location."""
232
- return self ._file
233
-
234
- @property
235
- def line (self ):
236
- """Get the line represented by this source location."""
237
- return self ._line
238
-
239
- @property
240
- def column (self ):
241
- """Get the column represented by this source location."""
242
- return self ._column
243
-
244
- @property
245
- def offset (self ):
246
- """Get the file offset represented by this source location."""
247
- return self ._offset
248
217
249
218
class SourceLocation (Structure ):
250
219
"""
251
220
A SourceLocation represents a particular location within a source file.
252
221
"""
253
222
_fields_ = [("ptr_data" , c_void_p * 2 ), ("int_data" , c_uint )]
254
- _expansion = None
255
- _spelling = None
223
+ _data = None
224
+
225
+ def _get_instantiation (self ):
226
+ if self ._data is None :
227
+ f , l , c , o = c_object_p (), c_uint (), c_uint (), c_uint ()
228
+ conf .lib .clang_getInstantiationLocation (self , byref (f ), byref (l ),
229
+ byref (c ), byref (o ))
230
+ if f :
231
+ f = File (f )
232
+ else :
233
+ f = None
234
+ self ._data = (f , int (l .value ), int (c .value ), int (o .value ))
235
+ return self ._data
256
236
257
237
@staticmethod
258
238
def from_position (tu , file , line , column ):
@@ -272,73 +252,25 @@ def from_offset(tu, file, offset):
272
252
"""
273
253
return conf .lib .clang_getLocationForOffset (tu , file , offset )
274
254
275
- @property
276
- def expansion (self ):
277
- """
278
- The source location where then entity this object is referring to is
279
- expanded.
280
- """
281
- if not self ._expansion :
282
- file = c_object_p ()
283
- line = c_uint ()
284
- column = c_uint ()
285
- offset = c_uint ()
286
- conf .lib .clang_getExpansionLocation (self ,
287
- byref (file ),
288
- byref (line ),
289
- byref (column ),
290
- byref (offset ))
291
-
292
- self ._expansion = Location (file , line , column , offset )
293
- return self ._expansion
294
-
295
- @property
296
- def spelling (self ):
297
- """
298
- The source location where then entity this object is referring to is
299
- written.
300
- """
301
- if not self ._spelling :
302
- file = c_object_p ()
303
- line = c_uint ()
304
- column = c_uint ()
305
- offset = c_uint ()
306
- conf .lib .clang_getSpellingLocation (self ,
307
- byref (file ),
308
- byref (line ),
309
- byref (column ),
310
- byref (offset ))
311
-
312
- self ._spelling = Location (file , line , column , offset )
313
- return self ._spelling
314
-
315
255
@property
316
256
def file (self ):
317
- """Get the file represented by this source location.
318
-
319
- DEPRECATED: use expansion.file."""
320
- return self .expansion .file
257
+ """Get the file represented by this source location."""
258
+ return self ._get_instantiation ()[0 ]
321
259
322
260
@property
323
261
def line (self ):
324
- """Get the line represented by this source location.
325
-
326
- DEPRECATED: use expansion.line."""
327
- return self .expansion .line
262
+ """Get the line represented by this source location."""
263
+ return self ._get_instantiation ()[1 ]
328
264
329
265
@property
330
266
def column (self ):
331
- """Get the column represented by this source location.
332
-
333
- DEPRECATED: use expansion.column."""
334
- return self .expansion .column
267
+ """Get the column represented by this source location."""
268
+ return self ._get_instantiation ()[2 ]
335
269
336
270
@property
337
271
def offset (self ):
338
- """Get the file offset represented by this source location.
339
-
340
- DEPRECATED: use expansion.offset."""
341
- return self .expansion .offset
272
+ """Get the file offset represented by this source location."""
273
+ return self ._get_instantiation ()[3 ]
342
274
343
275
def __eq__ (self , other ):
344
276
return conf .lib .clang_equalLocations (self , other )
@@ -1611,7 +1543,8 @@ def mangled_name(self):
1611
1543
@property
1612
1544
def location (self ):
1613
1545
"""
1614
- Return the source locations of the entity pointed at by the cursor.
1546
+ Return the source location (the starting character) of the entity
1547
+ pointed at by the cursor.
1615
1548
"""
1616
1549
if not hasattr (self , '_loc' ):
1617
1550
self ._loc = conf .lib .clang_getCursorLocation (self )
@@ -3759,11 +3692,7 @@ def cursor(self):
3759
3692
("clang_getInclusions" ,
3760
3693
[TranslationUnit , callbacks ['translation_unit_includes' ], py_object ]),
3761
3694
3762
- ("clang_getExpansionLocation" ,
3763
- [SourceLocation , POINTER (c_object_p ), POINTER (c_uint ), POINTER (c_uint ),
3764
- POINTER (c_uint )]),
3765
-
3766
- ("clang_getSpellingLocation" ,
3695
+ ("clang_getInstantiationLocation" ,
3767
3696
[SourceLocation , POINTER (c_object_p ), POINTER (c_uint ), POINTER (c_uint ),
3768
3697
POINTER (c_uint )]),
3769
3698
@@ -4225,7 +4154,6 @@ def register_enumerations():
4225
4154
'FixIt' ,
4226
4155
'Index' ,
4227
4156
'LinkageKind' ,
4228
- 'Location' ,
4229
4157
'SourceLocation' ,
4230
4158
'SourceRange' ,
4231
4159
'TLSKind' ,
0 commit comments