- 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
- Repository
- rL LLVM
Event Timeline
lib/Format/Format.cpp | ||
---|---|---|
860 ↗ | (On Diff #63662) | 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 ↗ | (On Diff #63662) | a conflict |
163 ↗ | (On Diff #63662) | This prevents users from adding order-dependent replacements. |
172–173 ↗ | (On Diff #63662) | That sentence doesn't parse... |
176 ↗ | (On Diff #63662) | merges |
179 ↗ | (On Diff #63662) | Here, above and below: |
lib/Tooling/Core/Replacement.cpp | ||
300 ↗ | (On Diff #63662) | I'd probably add a single-replacement constructor for convenience. |
306 ↗ | (On Diff #63662) | 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? |
332 ↗ | (On Diff #63662) | 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.
include/clang/Tooling/Core/Replacement.h | ||
---|---|---|
145 ↗ | (On Diff #64016) | s/This // |
lib/Tooling/Core/Replacement.cpp | ||
146 ↗ | (On Diff #64016) | DO NOT SCREAM!!! :D |
306 ↗ | (On Diff #64016) | I believe it's better. Can you add a comment expanding what this is for, so we don't have to re-think about that next time we stumble over it? :) |
unittests/Tooling/RefactoringTest.cpp | ||
---|---|---|
112 ↗ | (On Diff #64675) | 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 | ||
---|---|---|
112 ↗ | (On Diff #64675) | Done. Added unittests/Tooling/ReplacementTest.h that contains ReplacementTest class and toReplacements, both of which are used in multiple test files. |