[gcc r15-8839] gccrs: Add rib kind debug representation
Arthur Cohen
cohenarthur@gcc.gnu.org
Mon Mar 24 12:39:21 GMT 2025
https://gcc.gnu.org/g:f0de6f162374464f9cc15c395cb9e1db50044395
commit r15-8839-gf0de6f162374464f9cc15c395cb9e1db50044395
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu Feb 27 12:28:32 2025 +0100
gccrs: Add rib kind debug representation
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>
Diff:
---
gcc/rust/resolve/rust-forever-stack.hxx | 10 +++++++---
gcc/rust/resolve/rust-rib.h | 29 +++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx b/gcc/rust/resolve/rust-forever-stack.hxx
index c1407344b523..9e66c802d5f2 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -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";
diff --git a/gcc/rust/resolve/rust-rib.h b/gcc/rust/resolve/rust-rib.h
index 2eb8de8f0efd..767547f985f7 100644
--- a/gcc/rust/resolve/rust-rib.h
+++ b/gcc/rust/resolve/rust-rib.h
@@ -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);
More information about the Gcc-cvs
mailing list