[cfe-dev] libclang source location from buffer index

Douglas Gregor dgregor at apple.com
Fri Oct 15 10:19:45 PDT 2010


On Oct 15, 2010, at 10:13 AM, David Chisnall wrote:

> On 15 Oct 2010, at 18:01, Douglas Gregor wrote:
> 
>> 
>> On Oct 15, 2010, at 6:05 AM, David Chisnall wrote:
>> 
>>> Hi,
>>> 
>>> When interacting with the libclang stuff for an in-memory file, it seems quite common not to have the line and column indexes.  I've added a function for generating locations from simple offsets into a file, but I'm not overly familiar with the SourceLocation stuff, so it might not be the most sensible way of doing it.  I have two questions:
>>> 
>>> - Does anyone object to this interface?
>> 
>> Nope, it looks good. The patch needs updates to clang-c/Index.h and the exports file, of course :)
> 
> Yup, I've done both of those in my local copy, I just didn't attach them in the diff.
> 
>>> - Is this implementation sane?
>> 
>> Yes, but please check for offset >= the size of the file and that Start is not invalid, so that this routine returns clang_getNullLocation() rather than a potentially-invalid location. libclang needs to be resilient to API use errors.
> 
> Done.  I also added the same check to the other method that gets a source location.  The absence of this check is probably the cause of some of the other strangeness I was seeing yesterday.

Very possible!

	- Doug



More information about the cfe-dev mailing list