When issuing a reparse, the SourceManager is then rebuilt from the
FileMgr object it had in ASTUnit. This, however, issues an reload
of the files MemoryBuffer which could have been changed by some
analysis process.
For example, an tooling application can call overrideFileContents with
a new MemoryBuffer with modified pieces of code, and then issue a
reparse to either rebuild the tree or update the SourceLocations. This
is useful when used with the Rewriter object because one can do:
std::string *modified_str = new std::string(rewritebuf->begin(), rewritebuf->end()); auto new_membuff = llvm::MemoryBuffer::getMemBuffer(*modified_str); SM.overrideFileContents(file_entry, std::move(new_membuff)); AU->Reparse(..., /*KeepSourceManager=*/true);
And then the modifications to the file is loaded into the AU instance
of ASTUnit object. The test case in this patch reflects this use case.
Signed-off-by: Giuliano Belinassi <gbelinassi@suse.de>