]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add rib kind debug representation
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 27 Feb 2025 11:28:32 +0000 (12:28 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:07:13 +0000 (13:07 +0100)
Rib kind had no string representation, and thus were not used in the
debug string representation.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Output rib kind.
* resolve/rust-rib.h: Add function to get string representation from
a rib kind.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/resolve/rust-forever-stack.hxx
gcc/rust/resolve/rust-rib.h

index c1407344b523bd004ed763d928ab9d7b8c55da8c..9e66c802d5f20bf7a20ae6a728b40d4a90eef28c 100644 (file)
@@ -781,13 +781,17 @@ ForeverStack<N>::stream_rib (std::stringstream &stream, const Rib &rib,
                             const std::string &next,
                             const std::string &next_next) const
 {
+  std::string rib_kind = Rib::kind_to_string (rib.kind);
+  stream << next << "rib [" << rib_kind << "]: {";
   if (rib.get_values ().empty ())
     {
-      stream << next << "rib: {},\n";
+      stream << "}\n";
       return;
     }
-
-  stream << next << "rib: {\n";
+  else
+    {
+      stream << "\n";
+    }
 
   for (const auto &kv : rib.get_values ())
     stream << next_next << kv.first << ": " << kv.second.to_string () << "\n";
index 2eb8de8f0efd9f978256ac437d18f610559ae07c..767547f985f76c4e41a6cc8ca740740a1df35016 100644 (file)
@@ -175,6 +175,35 @@ public:
     ConstParamType,
   } kind;
 
+  static std::string kind_to_string (Rib::Kind kind)
+  {
+    switch (kind)
+      {
+      case Rib::Kind::Normal:
+       return "Normal";
+      case Rib::Kind::Module:
+       return "Module";
+      case Rib::Kind::Function:
+       return "Function";
+      case Rib::Kind::ConstantItem:
+       return "ConstantItem";
+      case Rib::Kind::TraitOrImpl:
+       return "TraitOrImpl";
+      case Rib::Kind::Item:
+       return "Item";
+      case Rib::Kind::Closure:
+       return "Closure";
+      case Rib::Kind::MacroDefinition:
+       return "Macro definition";
+      case Rib::Kind::ForwardTypeParamBan:
+       return "Forward type param ban";
+      case Rib::Kind::ConstParamType:
+       return "Const Param Type";
+      default:
+       rust_unreachable ();
+      }
+  }
+
   Rib (Kind kind);
   Rib (Kind kind, std::string identifier, NodeId id);
   Rib (Kind kind, std::unordered_map<std::string, NodeId> values);