[clang-tools-extra] r217442 - clang-apply-replacements: For-rangify.

Benjamin Kramer benny.kra at googlemail.com
Tue Sep 9 07:09:49 PDT 2014


Author: d0k
Date: Tue Sep  9 09:09:48 2014
New Revision: 217442

URL: http://llvm.org/viewvc/llvm-project?rev=217442&view=rev
Log:
clang-apply-replacements: For-rangify.

No functionality change.

Modified:
    clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
    clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp

Modified: clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?rev=217442&r1=217441&r2=217442&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp (original)
+++ clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp Tue Sep  9 09:09:48 2014
@@ -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 &R
 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";
     }

Modified: clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp?rev=217442&r1=217441&r2=217442&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp (original)
+++ clang-tools-extra/trunk/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp Tue Sep  9 09:09:48 2014
@@ -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);





More information about the cfe-commits mailing list