mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 22:02:37 +01:00
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:
@@ -9,11 +9,27 @@
|
||||
namespace cam = ::clang::ast_matchers;
|
||||
namespace ct = ::clang::tooling;
|
||||
|
||||
// Initialize the files in replacements. Matcher will restrict replacements to
|
||||
// initialized files.
|
||||
static void InitReplacements(ct::RefactoringTool* tool) {
|
||||
auto& files = tool->getFiles();
|
||||
auto& repl = tool->getReplacements();
|
||||
for (const auto& path : tool->getSourcePaths()) {
|
||||
auto file = files.getFile(path);
|
||||
if (file.getError()) {
|
||||
llvm::report_fatal_error("Error accessing `" + path +
|
||||
"`: " + file.getError().message() + "\n");
|
||||
}
|
||||
repl.insert({files.getCanonicalName(*file).str(), {}});
|
||||
}
|
||||
}
|
||||
|
||||
auto main(int argc, const char** argv) -> int {
|
||||
llvm::cl::OptionCategory category("C++ refactoring options");
|
||||
auto parser = ct::CommonOptionsParser::create(argc, argv, category);
|
||||
ct::RefactoringTool tool(parser->getCompilations(),
|
||||
parser->getSourcePathList());
|
||||
InitReplacements(&tool);
|
||||
|
||||
// Set up AST matcher callbacks.
|
||||
cam::MatchFinder finder;
|
||||
|
||||
Reference in New Issue
Block a user