diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-21 16:52:31 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-03-21 16:52:31 +0100 |
commit | 651d9a77cec0e9db1fbaf3f8a501cfbfc338cea3 (patch) | |
tree | d62dd97d755d38d08351b8f6f297195e4068ff24 | |
parent | 1bb9a29688ab4ddfec7f8d36ca2cee63c5f258d2 (diff) | |
download | gcc-651d9a77cec0e9db1fbaf3f8a501cfbfc338cea3.zip gcc-651d9a77cec0e9db1fbaf3f8a501cfbfc338cea3.tar.gz gcc-651d9a77cec0e9db1fbaf3f8a501cfbfc338cea3.tar.bz2 |
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>
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 3bdb8c6..f6d63d2 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -960,6 +960,20 @@ transcribe_context (MacroExpander::ContextType ctx, } } +static std::string +tokens_to_str (std::vector<std::unique_ptr<AST::Token>> &tokens) +{ + std::string str; + if (!tokens.empty ()) + { + str += tokens[0]->as_string (); + for (size_t i = 1; i < tokens.size (); i++) + str += " " + tokens[i]->as_string (); + } + + return str; +} + AST::ASTFragment MacroExpander::transcribe_rule ( AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree, @@ -979,9 +993,8 @@ MacroExpander::transcribe_rule ( std::vector<std::unique_ptr<AST::Token>> substituted_tokens = substitute_context.substitute_tokens (); - // handy for debugging - // for (auto &tok : substituted_tokens) - // rust_debug ("[tok] %s", tok->as_string ().c_str ()); + rust_debug ("substituted tokens: %s", + tokens_to_str (substituted_tokens).c_str ()); // parse it to an ASTFragment MacroInvocLexer lex (std::move (substituted_tokens)); |