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] rust/expand: merge expand_invoc and expand_invoc_semi functions Date: Fri, 22 Jul 2022 13:34:21 +0000 (GMT) [thread overview] Message-ID: <20220722133421.057E23857C5D@sourceware.org> (raw) https://gcc.gnu.org/g:903b7de01555f2e09df3ec3ccb0edcc3e77f9a5e commit 903b7de01555f2e09df3ec3ccb0edcc3e77f9a5e Author: liushuyu <liushuyu011@gmail.com> Date: Wed Jul 13 23:17:40 2022 -0600 rust/expand: merge expand_invoc and expand_invoc_semi functions Diff: --- gcc/rust/expand/rust-attribute-visitor.cc | 5 +-- gcc/rust/expand/rust-macro-expand.cc | 55 ++++++------------------------- gcc/rust/expand/rust-macro-expand.h | 3 +- 3 files changed, 12 insertions(+), 51 deletions(-) diff --git a/gcc/rust/expand/rust-attribute-visitor.cc b/gcc/rust/expand/rust-attribute-visitor.cc index 9332bb6ebfc..6cd894d261e 100644 --- a/gcc/rust/expand/rust-attribute-visitor.cc +++ b/gcc/rust/expand/rust-attribute-visitor.cc @@ -402,10 +402,7 @@ AttrVisitor::visit (AST::MacroInvocation ¯o_invoc) // I don't think any macro token trees can be stripped in any way // TODO: maybe have cfg! macro stripping behaviour here? - if (macro_invoc.has_semicolon ()) - expander.expand_invoc_semi (macro_invoc); - else - expander.expand_invoc (macro_invoc); + expander.expand_invoc (macro_invoc, macro_invoc.has_semicolon ()); } void diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 189d377ccc4..e27adf5de5e 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -106,7 +106,7 @@ MacroExpander::expand_decl_macro (Location invoc_locus, } void -MacroExpander::expand_invoc (AST::MacroInvocation &invoc) +MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon) { if (depth_exceeds_recursion_limit ()) { @@ -136,54 +136,19 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc) // lookup the rules for this macro NodeId resolved_node = UNKNOWN_NODEID; - bool found = resolver->get_macro_scope ().lookup ( - Resolver::CanonicalPath::new_seg (invoc.get_pattern_node_id (), - invoc_data.get_path ().as_string ()), - &resolved_node); - if (!found) - { - rust_error_at (invoc.get_locus (), "unknown macro 1"); - return; - } - - // lookup the rules - AST::MacroRulesDefinition *rules_def = nullptr; - bool ok = mappings->lookup_macro_def (resolved_node, &rules_def); - rust_assert (ok); - - auto fragment = AST::ASTFragment::create_error (); - - if (rules_def->is_builtin ()) - fragment - = rules_def->get_builtin_transcriber () (invoc.get_locus (), invoc_data); + NodeId source_node = UNKNOWN_NODEID; + if (has_semicolon) + source_node = invoc.get_macro_node_id (); else - fragment - = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def, false); - - set_expanded_fragment (std::move (fragment)); -} - -// FIXME: Arthur: Refactor these two functions, they're really similar -void -MacroExpander::expand_invoc_semi (AST::MacroInvocation &invoc) -{ - if (depth_exceeds_recursion_limit ()) - { - rust_error_at (invoc.get_locus (), "reached recursion limit"); - return; - } - - AST::MacroInvocData &invoc_data = invoc.get_invoc_data (); - - // lookup the rules for this macro - NodeId resolved_node = UNKNOWN_NODEID; + source_node = invoc.get_pattern_node_id (); auto seg - = Resolver::CanonicalPath::new_seg (invoc.get_macro_node_id (), + = Resolver::CanonicalPath::new_seg (source_node, invoc_data.get_path ().as_string ()); + bool found = resolver->get_macro_scope ().lookup (seg, &resolved_node); if (!found) { - rust_error_at (invoc.get_locus (), "unknown macro 2: [%s]", + rust_error_at (invoc.get_locus (), "unknown macro: [%s]", seg.get ().c_str ()); return; } @@ -199,8 +164,8 @@ MacroExpander::expand_invoc_semi (AST::MacroInvocation &invoc) fragment = rules_def->get_builtin_transcriber () (invoc.get_locus (), invoc_data); else - fragment - = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def, true); + fragment = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def, + has_semicolon); set_expanded_fragment (std::move (fragment)); } diff --git a/gcc/rust/expand/rust-macro-expand.h b/gcc/rust/expand/rust-macro-expand.h index a5825249f33..2c3380bebdb 100644 --- a/gcc/rust/expand/rust-macro-expand.h +++ b/gcc/rust/expand/rust-macro-expand.h @@ -213,8 +213,7 @@ struct MacroExpander /* Expands a macro invocation - possibly make both * have similar duck-typed interface and use templates?*/ // should this be public or private? - void expand_invoc (AST::MacroInvocation &invoc); - void expand_invoc_semi (AST::MacroInvocation &invoc); + void expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon); // Expands a single declarative macro. AST::ASTFragment expand_decl_macro (Location locus,
reply other threads:[~2022-07-22 13:34 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=20220722133421.057E23857C5D@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).