libclang source location from buffer index

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?
- Is this implementation sane?

David

-- Sent from my Cray X1

Index: CIndex.cpp

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 :slight_smile:

- 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.

  - Doug

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 :slight_smile:

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.

David

Very possible!

  - Doug