[PATCH] D39024: [clang-format] Sort whole block of using declarations while partially formatting
Daniel Jasper via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 18 11:31:07 PDT 2017
djasper added inline comments.
================
Comment at: lib/Format/UsingDeclarationsSorter.cpp:79
const SourceManager &SourceMgr, tooling::Replacements *Fixes) {
- SmallVector<UsingDeclaration, 4> SortedUsingDeclarations(
- UsingDeclarations->begin(), UsingDeclarations->end());
- std::stable_sort(SortedUsingDeclarations.begin(),
- SortedUsingDeclarations.end());
- for (size_t I = 0, E = UsingDeclarations->size(); I < E; ++I) {
- if ((*UsingDeclarations)[I].Line == SortedUsingDeclarations[I].Line)
- continue;
- auto Begin = (*UsingDeclarations)[I].Line->First->Tok.getLocation();
- auto End = (*UsingDeclarations)[I].Line->Last->Tok.getEndLoc();
- auto SortedBegin =
- SortedUsingDeclarations[I].Line->First->Tok.getLocation();
- auto SortedEnd = SortedUsingDeclarations[I].Line->Last->Tok.getEndLoc();
- StringRef Text(SourceMgr.getCharacterData(SortedBegin),
- SourceMgr.getCharacterData(SortedEnd) -
- SourceMgr.getCharacterData(SortedBegin));
- DEBUG({
- StringRef OldText(SourceMgr.getCharacterData(Begin),
- SourceMgr.getCharacterData(End) -
- SourceMgr.getCharacterData(Begin));
- llvm::dbgs() << "Replacing '" << OldText << "' with '" << Text << "'\n";
- });
- auto Range = CharSourceRange::getCharRange(Begin, End);
- auto Err = Fixes->add(tooling::Replacement(SourceMgr, Range, Text));
- if (Err) {
- llvm::errs() << "Error while sorting using declarations: "
- << llvm::toString(std::move(Err)) << "\n";
+ if (*BlockAffected) {
+ SmallVector<UsingDeclaration, 4> SortedUsingDeclarations(
----------------
I'd prefer to iterator over UsingDeclarations here and see whether any of the contained lines is Affected. Seems like a much more encapsulated way to do this and prevents you from needing the awkward in-out parameter.
https://reviews.llvm.org/D39024
More information about the cfe-commits
mailing list