public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] macros: Add helper debugging function for substituted tokens Date: Wed, 8 Jun 2022 12:21:42 +0000 (GMT) [thread overview] Message-ID: <20220608122142.D721A3852744@sourceware.org> (raw) https://gcc.gnu.org/g:651d9a77cec0e9db1fbaf3f8a501cfbfc338cea3 commit 651d9a77cec0e9db1fbaf3f8a501cfbfc338cea3 Author: Arthur Cohen <arthur.cohen@embecosm.com> Date: Mon Mar 21 16:52:31 2022 +0100 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> Diff: --- gcc/rust/expand/rust-macro-expand.cc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 3bdb8c685e6..f6d63d27d0b 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));
reply other threads:[~2022-06-08 12:21 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608122142.D721A3852744@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).