I am trying to create a clang Tool using ASTMatchers which renames a particular function invocation. However, when it renames a call in a file which is included in multiple TUs (header files for example), the tool duplicates the replacement. Here is an example:
I think the problem you have is similar to the one clang-tidy has. If you have 2 threads/processes that process the same header file, you’ll suggest the Sam change twice.
You can run your program single threaded/process. However clang-tidy also has the flag --export-fixes=<filename> with as documentation: YAML file to store suggested fixes in. The stored fixes can be applied to the input source code with clang-apply-replacements.
This way, the program can suggest duplicate fixes and only one of them gets applied.
Hi,
sorry for the late reply. I took your advice and used clang-tidy. However, I find it strange that in spite of clang having multi-TU refactoring headers and functions, I have not found a simple enough tool which deals with multi-TU refactoring without having to use yaml files for deduplication. Do you know of such a tool which is simple enough to understand? I have searched for days altogether but didn’t find any. One which comes close is HIPIFY, but I haven’t actually used it so can’t say it works for multi-TU setting.