Skip to content

Commit 651d9a7

Browse files
macros: Add helper debugging function for substituted tokens
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 Co-authored-by: philberty <philip.herron@embecosm.com>
1 parent 1bb9a29 commit 651d9a7

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
@@ -960,6 +960,20 @@ transcribe_context (MacroExpander::ContextType ctx,
960960
}
961961
}
962962

963+
static std::string
964+
tokens_to_str (std::vector<std::unique_ptr<AST::Token>> &tokens)
965+
{
966+
std::string str;
967+
if (!tokens.empty ())
968+
{
969+
str += tokens[0]->as_string ();
970+
for (size_t i = 1; i < tokens.size (); i++)
971+
str += " " + tokens[i]->as_string ();
972+
}
973+
974+
return str;
975+
}
976+
963977
AST::ASTFragment
964978
MacroExpander::transcribe_rule (
965979
AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree,
@@ -979,9 +993,8 @@ MacroExpander::transcribe_rule (
979993
std::vector<std::unique_ptr<AST::Token>> substituted_tokens
980994
= substitute_context.substitute_tokens ();
981995

982-
// handy for debugging
983-
// for (auto &tok : substituted_tokens)
984-
// rust_debug ("[tok] %s", tok->as_string ().c_str ());
996+
rust_debug ("substituted tokens: %s",
997+
tokens_to_str (substituted_tokens).c_str ());
985998

986999
// parse it to an ASTFragment
9871000
MacroInvocLexer lex (std::move (substituted_tokens));

0 commit comments

Comments
 (0)