This is an archive of the discontinued LLVM Phabricator instance.

[CrossTU] Add a function to retrieve original source location.
ClosedPublic

Authored by balazske on Jul 22 2019, 12:37 AM.

Details

Summary

A new function will be added to get the original SourceLocation
for a SourceLocation that was imported as result of getCrossTUDefinition.
The returned SourceLocation is in the context of the (original)
SourceManager for the original source file. Additionally the
ASTUnit object for that source file is returned. This is needed
to get a SourceManager to operate on with the returned source location.

The new function works if multiple different source files are loaded
with the same CrossTU context.

Event Timeline

balazske created this revision.Jul 22 2019, 12:37 AM
martong accepted this revision.Jul 22 2019, 2:37 AM

LGTM! Thanks!

This revision is now accepted and ready to land.Jul 22 2019, 2:37 AM
martong added inline comments.Jul 22 2019, 2:45 AM
clang/lib/CrossTU/CrossTranslationUnit.cpp
476

The Importer is not used, perhaps it is not needed in the lambda?

Or we might have the mapping of ToID->FromID in the ASTImporter, and the FromID->FromUnit mapping in the CTUContext?

balazske updated this revision to Diff 211059.Jul 22 2019, 5:45 AM
balazske marked an inline comment as done.

Removed ASTImporter from "callback" function.

balazske added inline comments.Jul 22 2019, 5:47 AM
clang/lib/CrossTU/CrossTranslationUnit.cpp
476

Yes the Importer is not needed (if needed later it can be added to the lambda as a variable).
Additional mappings of FileID seems not needed now, the current solution is sufficient for this use case. If there is a ToID->FromID in the ASTImporter a "callback" lambda would be still needed to make the FromID->FromUnit mapping.

balazske marked an inline comment as done.Jul 23 2019, 7:26 AM
balazske added inline comments.
clang/include/clang/CrossTU/CrossTranslationUnit.h
175

It would be better to use std::tuple<SourceLocation, Preprocessor &, ASTContext &> here. (Or * if & does not work.)

balazske updated this revision to Diff 211454.Jul 24 2019, 3:05 AM

Update diff to one commit with all changes.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJul 24 2019, 3:16 AM