This is an archive of the discontinued LLVM Phabricator instance.

[clangd] cleanup: unify the implemenation of checking a location is inside main file.
ClosedPublic

Authored by hokein on Jul 18 2019, 6:02 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

hokein created this revision.Jul 18 2019, 6:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2019, 6:02 AM

Neat! Many thanks, that's a very useful cleanup.
A few suggestions from my side.

clang-tools-extra/clangd/SourceCode.cpp
332 ↗(On Diff #210542)

NIT: why not getExpansionLoc? Its implementation and description seems simpler and (I believe) it produces locations inside the same files as getFileLoc (as both the macro arg and the macro name of the expansion are always coming from the same file)

clang-tools-extra/clangd/SourceCode.h
81 ↗(On Diff #210542)

Could we add a description without mentioning other SourceManager functions here?
I believe this should be a fair description of what this function is doing:

For macro locations, returns iff the macro is being expanded inside the main file.
hokein updated this revision to Diff 210569.Jul 18 2019, 7:58 AM
hokein marked 3 inline comments as done.

address review comments, and add unittest.

hokein added inline comments.Jul 18 2019, 7:59 AM
clang-tools-extra/clangd/SourceCode.cpp
332 ↗(On Diff #210542)

yes, since we are checking the file (not the range), there is no difference between these two methods. Changed to getExpansionLoc

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

LGTM

clang-tools-extra/clangd/unittests/SourceCodeTests.cpp
448 ↗(On Diff #210569)

NIT: not sure if it's easy to get a hold of those, but ...
maybe add tests for locations inside the <builtin>, <command-line> and <scratch> buffers?

This revision is now accepted and ready to land.Jul 18 2019, 8:25 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 19 2019, 1:35 AM