This is an archive of the discontinued LLVM Phabricator instance.

Fix for clang_Cursor_getSpellingNameRange() reportage of C++ functions
ClosedPublic

Authored by craigt on Aug 23 2014, 4:19 AM.

Details

Summary

Currently, there is a minor defect in the source range reported by libclang's clang_Cursor_getSpellingNameRange() function such that destructor spellings are reported to only be one character wide (hence, only covering the leading '~' tilde), and only covers the initial 'operator' segment of any overloaded operator. The kdev-clang plugin for the KDevelop IDE uses this function to aid in syntax highlighting, so these shortfalls result in erroneous highlighting. The issue obviously seemed to be a lexical one, the transition from one token-type to another seemed to be tripping things up, and after a sense, this is, indeed, what's going wrong, but not quite. In attempting to trace the origin of the problem, I discovered that the C++ interface to the AST doesn't have this issue despite depending on the same tokenization constructs (as far as I could tell, anyway). Rather, the default approach libclang uses breaks on a single token type; in line with the special treatment given to some ObjC constructs, I felt this problem would be best handled by special-casing destructor, C++ method, and C++ conversion function cursors (more on that later) depending on the underlying C++ logic as the ObjC cases do.

Additionally, in the process of writing regression tests and testing the patch, I also discovered that C++ conversion functions were having the same issue as destructors and operator overloads.

Diff Detail

Event Timeline

craigt updated this revision to Diff 12881.Aug 23 2014, 4:19 AM
craigt retitled this revision from to Fix for clang_Cursor_getSpellingNameRange() reportage of C++ functions.
craigt updated this object.
craigt edited the test plan for this revision. (Show Details)
craigt added a reviewer: akyrtzi.
craigt updated this object.
craigt added a subscriber: Unknown Object (MLST).
milianw added a project: Restricted Project.
milianw edited edge metadata.

+1 from my side, but someone else has to approve.

rsmith accepted this revision.Mar 24 2016, 5:24 PM
rsmith added a reviewer: rsmith.
rsmith added a subscriber: rsmith.

LGTM

This revision is now accepted and ready to land.Mar 24 2016, 5:24 PM
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in rL216480.