clang-apply-replacements: For-rangify.

No functionality change.

llvm-svn: 217442
This commit is contained in:
Benjamin Kramer 2014-09-09 14:09:48 +00:00
parent 83a7ddbc9a
commit 91ea478d7c
2 changed files with 20 additions and 29 deletions

View File

@ -98,29 +98,26 @@ static void reportConflict(
// FIXME: Output something a little more user-friendly (e.g. unified diff?)
errs() << "The following changes conflict:\n";
for (const tooling::Replacement *I = ConflictingReplacements.begin(),
*E = ConflictingReplacements.end();
I != E; ++I) {
if (I->getLength() == 0) {
errs() << " Insert at " << SM.getLineNumber(FID, I->getOffset()) << ":"
<< SM.getColumnNumber(FID, I->getOffset()) << " "
<< I->getReplacementText() << "\n";
for (const tooling::Replacement &R : ConflictingReplacements) {
if (R.getLength() == 0) {
errs() << " Insert at " << SM.getLineNumber(FID, R.getOffset()) << ":"
<< SM.getColumnNumber(FID, R.getOffset()) << " "
<< R.getReplacementText() << "\n";
} else {
if (I->getReplacementText().empty())
if (R.getReplacementText().empty())
errs() << " Remove ";
else
errs() << " Replace ";
errs() << SM.getLineNumber(FID, I->getOffset()) << ":"
<< SM.getColumnNumber(FID, I->getOffset()) << "-"
<< SM.getLineNumber(FID, I->getOffset() + I->getLength() - 1)
<< ":"
<< SM.getColumnNumber(FID, I->getOffset() + I->getLength() - 1);
errs() << SM.getLineNumber(FID, R.getOffset()) << ":"
<< SM.getColumnNumber(FID, R.getOffset()) << "-"
<< SM.getLineNumber(FID, R.getOffset() + R.getLength() - 1) << ":"
<< SM.getColumnNumber(FID, R.getOffset() + R.getLength() - 1);
if (I->getReplacementText().empty())
if (R.getReplacementText().empty())
errs() << "\n";
else
errs() << " with \"" << I->getReplacementText() << "\"\n";
errs() << " with \"" << R.getReplacementText() << "\"\n";
}
}
}
@ -218,11 +215,7 @@ RangeVector calculateChangedRanges(
// NOTE: This is O(n^2) in the number of replacements. If this starts to
// become a problem inline shiftedCodePosition() here and do shifts in a
// single run through this loop.
for (std::vector<clang::tooling::Replacement>::const_iterator
I = Replaces.begin(),
E = Replaces.end();
I != E; ++I) {
const tooling::Replacement &R = *I;
for (const tooling::Replacement &R : Replaces) {
unsigned Offset = tooling::shiftedCodePosition(Replaces, R.getOffset());
unsigned Length = R.getReplacementText().size();
@ -255,13 +248,12 @@ bool writeFiles(const clang::Rewriter &Rewrites) {
bool deleteReplacementFiles(const TUReplacementFiles &Files,
clang::DiagnosticsEngine &Diagnostics) {
bool Success = true;
for (TUReplacementFiles::const_iterator I = Files.begin(), E = Files.end();
I != E; ++I) {
std::error_code Error = llvm::sys::fs::remove(*I);
for (const auto &Filename : Files) {
std::error_code Error = llvm::sys::fs::remove(Filename);
if (Error) {
Success = false;
// FIXME: Use Diagnostics for outputting errors.
errs() << "Error deleting file: " << *I << "\n";
errs() << "Error deleting file: " << Filename << "\n";
errs() << Error.message() << "\n";
errs() << "Please delete the file manually\n";
}

View File

@ -199,11 +199,10 @@ int main(int argc, char **argv) {
// Only include our options in -help output.
StringMap<cl::Option*> OptMap;
cl::getRegisteredOptions(OptMap);
const char **EndOpts = OptionsToShow + array_lengthof(OptionsToShow);
for (StringMap<cl::Option *>::iterator I = OptMap.begin(), E = OptMap.end();
I != E; ++I) {
if (std::find(OptionsToShow, EndOpts, I->getKey()) == EndOpts)
I->getValue()->setHiddenFlag(cl::ReallyHidden);
const char **EndOpts = std::end(OptionsToShow);
for (const auto &Opt : OptMap) {
if (std::find(OptionsToShow, EndOpts, Opt.getKey()) == EndOpts)
Opt.getValue()->setHiddenFlag(cl::ReallyHidden);
}
cl::SetVersionPrinter(&printVersion);