- Implement clang::tooling::Replacements as a class to provide interfaces to control how replacements for a single file are combined and provide guarantee on the order of replacements being applied.
- tooling::Replacements only contains replacements for the same file now. Use std::map<std::string, tooling::Replacements> to represent multi-file replacements.
- Error handling for the interface change will be improved in followup patches.
Details
Diff Detail
Event Timeline
lib/Format/Format.cpp | ||
---|---|---|
859 | Not sure about the appropriate error handling here. Another option is calculating the range of the conflicting replacement in the code after replacements are applied and then use merge to add the replacement with new range. For example: auto Err = Replaces.add(R); if (Err) { auto NewRanges = calculateRangesAfterReplacements(Replaces, {R.getRange()}); R = tooling::Replacement(R.getFilePath(), NewRange.getOffset(), NewRange.getLength(), R.getReplacementText()); Replaces = Replaces.merge(R); } And we might want to make this a member function as well? |
include/clang/Tooling/Core/Replacement.h | ||
---|---|---|
160 | a conflict | |
163 | This prevents users from adding order-dependent replacements. | |
172โ173 | That sentence doesn't parse... | |
176 | merges | |
179 | Here, above and below: | |
lib/Tooling/Core/Replacement.cpp | ||
299 | I'd probably add a single-replacement constructor for convenience. | |
305 | So, this doesn't do the same as Replacements::merge, right? I think we're getting into a bit confusing terminology - perhaps we can find a better name for this? | |
327 | This function could need a comment on how it actually works - I don't remember, and the function names called don't really give us a good explanation. I know this is just code you're moving, but I think we can make it a bit easier to understand while we're at it :) |
- Merge branch 'master' of http://llvm.org/git/clang into replace
- Addressed reviewer's comments.
unittests/Tooling/RefactoringTest.cpp | ||
---|---|---|
102 | Looks like we should put this function into some header, so we don't need to re-implement it in every test? |
- Moved ReplacementTest and toReplacements to ReplacementTest.h
- Merge branch 'master' of http://llvm.org/git/clang into replace
unittests/Tooling/RefactoringTest.cpp | ||
---|---|---|
102 | Done. Added unittests/Tooling/ReplacementTest.h that contains ReplacementTest class and toReplacements, both of which are used in multiple test files. |
s/This //