diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-03-22 20:57:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-22 20:57:05 +0000 |
commit | fb886737e23eef762c8c164c53168ebfd86e9435 (patch) | |
tree | 1fcf347ffc63ae0e07a9f4914a0f4f8d103d9293 | |
parent | cc6e405912c83aee41efd3015d9157cdbe9134fe (diff) | |
parent | 651d9a77cec0e9db1fbaf3f8a501cfbfc338cea3 (diff) | |
download | gcc-fb886737e23eef762c8c164c53168ebfd86e9435.zip gcc-fb886737e23eef762c8c164c53168ebfd86e9435.tar.gz gcc-fb886737e23eef762c8c164c53168ebfd86e9435.tar.bz2 |
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>
-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 6b26f98..30f0f30 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -963,6 +963,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, @@ -982,9 +996,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)); |