Change how replacements are filtered (#541)

This replaces the use of `isExpansionInMainFile` with instead taking the list of input files, and only touching them. This doesn't keep `isExpansionInMainFile` because it should be redundant, and as such it'd be easy to forget. Unless it starts being a performance issue, it's probably better to omit.
This commit is contained in:
Jon Meow
2021-06-03 16:35:55 -07:00
committed by GitHub
parent c836ae78bb
commit f180c64454
4 changed files with 36 additions and 21 deletions
+8 -1
View File
@@ -29,7 +29,14 @@ void Matcher::AddReplacement(const clang::SourceManager& sm,
}
auto rep = ct::Replacement(sm, sm.getExpansionRange(range), replacement_text);
auto err = (*replacements)[std::string(rep.getFilePath())].add(rep);
auto entry = replacements->find(std::string(rep.getFilePath()));
if (entry == replacements->end()) {
// The replacement was in a file which isn't being updated, such as a system
// header.
return;
}
auto err = entry->second.add(rep);
if (err) {
llvm::report_fatal_error("Error with replacement `" + rep.toString() +
"`: " + llvm::toString(std::move(err)) + "\n");