This is an archive of the discontinued LLVM Phabricator instance.

[libclang, bindings]: add spelling location
ClosedPublic

Authored by frutiger on Sep 15 2017, 8:12 AM.

Details

Reviewers
compnerd
Summary
  • Add two new properties to SourceLocation: expansion and spelling, allowing detailed source location information to be retrieved from a cursor.
  • Update the implementation to use clang_getExpansionLocation instead of the deprecated clang_getInstantiationLocation, which has been present since 2011.
  • Update the implementation of clang_getSpellingLocation to actually obtain spelling location instead of file location.

Diff Detail

Event Timeline

frutiger created this revision.Sep 15 2017, 8:12 AM

Please note:

  • this change means that versions of libclang built prior to the introduction of clang_getExpansionLocation will not work.
  • this change alters the behavior of clang_getSpellingLocation to return the spelling location

I would appreciate advice on if either of these changes are acceptable. Thank you.

Friendly poke!

compnerd requested changes to this revision.Sep 27 2017, 9:28 PM

If I'm not mistaken, the change just means that the python bindings need a "newer" libclang, libclang's interfaces don't really change. I think that is acceptable.

bindings/python/clang/cindex.py
320

Does it make sense to introduce two new properties expansion and spelling and have the four fields be properties on those properties? It seems like it would be more pythonic.

tools/libclang/CXSourceLocation.cpp
321

Remove the FIXME please.

This revision now requires changes to proceed.Sep 27 2017, 9:28 PM
frutiger added inline comments.Sep 28 2017, 10:40 AM
bindings/python/clang/cindex.py
320

I agree, but I was concerned about breaking existing users that might be using the expansion properties directly on this object. Would marking them deprecated in the documentation suffice?

frutiger edited the summary of this revision. (Show Details)Sep 28 2017, 11:37 AM
frutiger updated this revision to Diff 117041.Sep 28 2017, 12:55 PM
frutiger edited edge metadata.

Updated as per review.

compnerd accepted this revision.Sep 28 2017, 8:19 PM
compnerd added inline comments.
bindings/python/clang/cindex.py
320

Yeah, I think thats a great approach.

This revision is now accepted and ready to land.Sep 28 2017, 8:19 PM
jklaehn added inline comments.
bindings/python/clang/cindex.py
214

Can you also add Location to __all__?

frutiger updated this revision to Diff 119191.Oct 16 2017, 11:58 AM

Added 'Location' to 'all'.

frutiger marked an inline comment as done.Oct 16 2017, 11:58 AM
compnerd accepted this revision.Oct 17 2017, 9:25 PM

@frutiger you have commit rights now right?

frutiger closed this revision.Oct 21 2017, 1:56 PM

@compnerd I do now. Landed in rL316278.