public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] rust/expand: merge expand_invoc and expand_invoc_semi functions
@ 2022-07-22 13:34 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-07-22 13:34 UTC (permalink / raw)
To: gcc-cvs
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,
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-22 13:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-22 13:34 [gcc/devel/rust/master] rust/expand: merge expand_invoc and expand_invoc_semi functions Thomas Schwinge
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).