Skip to content

Commit fb88673

Browse files
Merge #1047
1047: Add helper debugging function for substituted tokens r=CohenArthur a=CohenArthur Since this is less noisy, I guess we can keep it in at all times instead of commenting it. Doing it like so - through a single function call - means that we avoid creating the string entirely in release builds Fixes #967 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 parents cc6e405 + 651d9a7 commit fb88673

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

gcc/rust/expand/rust-macro-expand.cc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,20 @@ transcribe_context (MacroExpander::ContextType ctx,
963963
}
964964
}
965965

966+
static std::string
967+
tokens_to_str (std::vector<std::unique_ptr<AST::Token>> &tokens)
968+
{
969+
std::string str;
970+
if (!tokens.empty ())
971+
{
972+
str += tokens[0]->as_string ();
973+
for (size_t i = 1; i < tokens.size (); i++)
974+
str += " " + tokens[i]->as_string ();
975+
}
976+
977+
return str;
978+
}
979+
966980
AST::ASTFragment
967981
MacroExpander::transcribe_rule (
968982
AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree,
@@ -982,9 +996,8 @@ MacroExpander::transcribe_rule (
982996
std::vector<std::unique_ptr<AST::Token>> substituted_tokens
983997
= substitute_context.substitute_tokens ();
984998

985-
// handy for debugging
986-
// for (auto &tok : substituted_tokens)
987-
// rust_debug ("[tok] %s", tok->as_string ().c_str ());
999+
rust_debug ("substituted tokens: %s",
1000+
tokens_to_str (substituted_tokens).c_str ());
9881001

9891002
// parse it to an ASTFragment
9901003
MacroInvocLexer lex (std::move (substituted_tokens));

0 commit comments

Comments
 (0)