Skip to content

Commit 126680c

Browse files
committed
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 <[email protected]>
1 parent 6029cc9 commit 126680c

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

gcc/rust/resolve/rust-forever-stack.hxx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,13 +781,17 @@ ForeverStack<N>::stream_rib (std::stringstream &stream, const Rib &rib,
781781
const std::string &next,
782782
const std::string &next_next) const
783783
{
784+
std::string rib_kind = Rib::kind_to_string (rib.kind);
785+
stream << next << "rib [" << rib_kind << "]: {";
784786
if (rib.get_values ().empty ())
785787
{
786-
stream << next << "rib: {},\n";
788+
stream << "}\n";
787789
return;
788790
}
789-
790-
stream << next << "rib: {\n";
791+
else
792+
{
793+
stream << "\n";
794+
}
791795

792796
for (const auto &kv : rib.get_values ())
793797
stream << next_next << kv.first << ": " << kv.second.to_string () << "\n";

gcc/rust/resolve/rust-rib.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,35 @@ class Rib
175175
ConstParamType,
176176
} kind;
177177

178+
static std::string kind_to_string (Rib::Kind kind)
179+
{
180+
switch (kind)
181+
{
182+
case Rib::Kind::Normal:
183+
return "Normal";
184+
case Rib::Kind::Module:
185+
return "Module";
186+
case Rib::Kind::Function:
187+
return "Function";
188+
case Rib::Kind::ConstantItem:
189+
return "ConstantItem";
190+
case Rib::Kind::TraitOrImpl:
191+
return "TraitOrImpl";
192+
case Rib::Kind::Item:
193+
return "Item";
194+
case Rib::Kind::Closure:
195+
return "Closure";
196+
case Rib::Kind::MacroDefinition:
197+
return "Macro definition";
198+
case Rib::Kind::ForwardTypeParamBan:
199+
return "Forward type param ban";
200+
case Rib::Kind::ConstParamType:
201+
return "Const Param Type";
202+
default:
203+
rust_unreachable ();
204+
}
205+
}
206+
178207
Rib (Kind kind);
179208
Rib (Kind kind, std::string identifier, NodeId id);
180209
Rib (Kind kind, std::unordered_map<std::string, NodeId> values);

0 commit comments

Comments
 (0)