[llvm] [NFC][TableGen] Refactor JSON and detailed record emitter (PR #105770)

Rahul Joshi via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 13:05:47 PDT 2024


================
@@ -153,38 +147,36 @@ void JSONEmitter::run(raw_ostream &OS) {
     obj["!fields"] = std::move(fields);
 
     json::Array superclasses;
-    for (const auto &SuperPair : Def.getSuperClasses())
-      superclasses.push_back(SuperPair.first->getNameInitAsString());
+    // Add this def to the instance list for each of its superclasses.
+    for (const auto &[SuperClass, Loc] : Def->getSuperClasses()) {
+      std::string SuperName = SuperClass->getNameInitAsString();
+      superclasses.push_back(SuperName);
+      instance_lists[SuperName].push_back(Name);
+    }
+
     obj["!superclasses"] = std::move(superclasses);
 
     obj["!name"] = Name;
-    obj["!anonymous"] = Def.isAnonymous();
+    obj["!anonymous"] = Def->isAnonymous();
 
     json::Array locs;
-    for (const SMLoc Loc : Def.getLoc())
+    for (const SMLoc Loc : Def->getLoc())
       locs.push_back(SrcMgr.getFormattedLocationNoOffset(Loc));
     obj["!locs"] = std::move(locs);
 
     root[Name] = std::move(obj);
-
-    // Add this def to the instance list for each of its superclasses.
-    for (const auto &SuperPair : Def.getSuperClasses()) {
-      auto SuperName = SuperPair.first->getNameInitAsString();
-      instance_lists[SuperName].push_back(Name);
-    }
   }
 
   // Make a JSON object from the std::map of instance lists.
   json::Object instanceof;
-  for (auto kv: instance_lists)
-    instanceof[kv.first] = std::move(kv.second);
+  for (auto &[ClassName, Instances] : instance_lists)
+    instanceof [ ClassName ] = std::move(Instances);
----------------
jurahul wrote:

yeah. CI for "Check code formatting" installs clangformat 18.1.7. So I guess when we upgrade it to a version that has the fix, we will have to update the formatting here.

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


More information about the llvm-commits mailing list