[clang] [clang][deps] Serialize JSON without creating intermediate objects (PR #111734)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 9 14:52:59 PDT 2024


================
@@ -450,58 +458,65 @@ class FullDeps {
       ModuleIDs.push_back(M.first);
     llvm::sort(ModuleIDs);
 
-    using namespace llvm::json;
-
-    Array OutModules;
-    for (auto &&ModID : ModuleIDs) {
-      auto &MD = Modules[ModID];
-      Object O{{"name", MD.ID.ModuleName},
-               {"context-hash", MD.ID.ContextHash},
-               {"file-deps", toJSONSorted(MD.FileDeps)},
-               {"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)},
-               {"clang-modulemap-file", MD.ClangModuleMapFile},
-               {"command-line", MD.getBuildArguments()},
-               {"link-libraries", toJSONSorted(MD.LinkLibraries)}};
-      OutModules.push_back(std::move(O));
-    }
-
-    Array TUs;
-    for (auto &&I : Inputs) {
-      Array Commands;
-      if (I.DriverCommandLine.empty()) {
-        for (const auto &Cmd : I.Commands) {
-          Object O{
-              {"input-file", I.FileName},
-              {"clang-context-hash", I.ContextHash},
-              {"file-deps", I.FileDeps},
-              {"clang-module-deps", toJSONSorted(I.ModuleDeps)},
-              {"executable", Cmd.Executable},
-              {"command-line", Cmd.Arguments},
-          };
-          Commands.push_back(std::move(O));
+    llvm::json::OStream JOS(OS, /*IndentSize=*/2);
+
+    JOS.object([&]() {
----------------
jansvoboda11 wrote:

Thanks! I got confused by my IDE telling me that `"Lambda without a parameter clause is a C++23 extension"`. Now that I'm testing this, that's only true if you also specify it as `noexcept`, `mutable` or similar.

https://github.com/llvm/llvm-project/pull/111734


More information about the cfe-commits mailing list