[clang-tools-extra] r288586 - [clang-move] don't miss ', ' in json output when there are duplicate elements.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Sat Dec 3 07:28:03 PST 2016


Author: ioeric
Date: Sat Dec  3 09:28:03 2016
New Revision: 288586

URL: http://llvm.org/viewvc/llvm-project?rev=288586&view=rev
Log:
[clang-move] don't miss ',' in json output when there are duplicate elements.

Modified:
    clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp

Modified: clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp?rev=288586&r1=288585&r2=288586&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp (original)
+++ clang-tools-extra/trunk/clang-move/tool/ClangMoveMain.cpp Sat Dec  3 09:28:03 2016
@@ -144,15 +144,13 @@ int main(int argc, const char **argv) {
   if (DumpDecls) {
     llvm::outs() << "[\n";
     const auto &Declarations = Reporter.getDeclarationList();
-    for (auto DeclPair : Declarations) {
+    for (auto I = Declarations.begin(), E = Declarations.end(); I != E; ++I) {
       llvm::outs() << "  {\n";
-      llvm::outs() << "    \"DeclarationName\": \"" << DeclPair.first
-                   << "\",\n";
-      llvm::outs() << "    \"DeclarationType\": \"" << DeclPair.second
-                   << "\"\n";
+      llvm::outs() << "    \"DeclarationName\": \"" << I->first << "\",\n";
+      llvm::outs() << "    \"DeclarationType\": \"" << I->second << "\"\n";
       llvm::outs() << "  }";
       // Don't print trailing "," at the end of last element.
-      if (DeclPair != *(--Declarations.end()))
+      if (I != std::prev(E))
         llvm::outs() << ",\n";
     }
     llvm::outs() << "\n]\n";
@@ -196,10 +194,10 @@ int main(int argc, const char **argv) {
       Files.insert(it.first);
     auto WriteToJson = [&](llvm::raw_ostream &OS) {
       OS << "[\n";
-      for (auto File : Files) {
+      for (auto I = Files.begin(), E = Files.end(); I != E; ++I) {
         OS << "  {\n";
-        OS << "    \"FilePath\": \"" << File << "\",\n";
-        const auto *Entry = FileMgr.getFile(File);
+        OS << "    \"FilePath\": \"" << *I << "\",\n";
+        const auto *Entry = FileMgr.getFile(*I);
         auto ID = SM.translateFile(Entry);
         std::string Content;
         llvm::raw_string_ostream ContentStream(Content);
@@ -207,7 +205,7 @@ int main(int argc, const char **argv) {
         OS << "    \"SourceText\": \""
            << llvm::yaml::escape(ContentStream.str()) << "\"\n";
         OS << "  }";
-        if (File != *(--Files.end()))
+        if (I != std::prev(E))
           OS << ",\n";
       }
       OS << "\n]\n";




More information about the cfe-commits mailing list