This is an archive of the discontinued LLVM Phabricator instance.

[LibTooling] Add function to translate and validate source range for editing
ClosedPublic

Authored by ymandel on Jul 18 2019, 7:54 AM.

Details

Summary

Adds the function getRangeForEdit to validate that a given source range is
editable and, if needed, translate it into a range in the source file (for
example, if it's sourced in macro expansions).

Diff Detail

Repository
rL LLVM

Event Timeline

ymandel created this revision.Jul 18 2019, 7:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2019, 7:54 AM
ymandel updated this revision to Diff 210573.Jul 18 2019, 8:03 AM

define matcher instead of operator==

ilya-biryukov accepted this revision.Jul 18 2019, 9:18 AM

LGTM

clang/include/clang/Tooling/Refactoring/SourceCode.h
80 ↗(On Diff #210573)

NIT: I can see why passing two structs instead of a single ASTContext is annoying, but still suggest adding an overload that accepts a SourceManager and LangOptions.
(The current overload would trivially call into the other one).

The reason is that ASTContext is not available where you would need this function.
In any case, having the ASTContext overload is convenient.

This revision is now accepted and ready to land.Jul 18 2019, 9:18 AM
ymandel updated this revision to Diff 210608.Jul 18 2019, 9:44 AM

Added overload.

ymandel marked 2 inline comments as done.Jul 18 2019, 9:45 AM
ymandel added inline comments.
clang/include/clang/Tooling/Refactoring/SourceCode.h
80 ↗(On Diff #210573)

good point!

This revision was automatically updated to reflect the committed changes.
ymandel marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2019, 10:26 AM