aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand/rust-macro-expand.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-06 20:50:55 +0000
committerGitHub <noreply@github.com>2022-03-06 20:50:55 +0000
commite2bccf43ed1bf33d5f454eab39a7a4a1f115b0bd (patch)
tree6e9e933267fd6c651c59607668e2fa08641b8b9d /gcc/rust/expand/rust-macro-expand.cc
parentd89c8ccf3237e66029125c0fe007297bb86eca74 (diff)
parent58d1721529e99c7c633615e7491b777a6198ed00 (diff)
downloadgcc-e2bccf43ed1bf33d5f454eab39a7a4a1f115b0bd.zip
gcc-e2bccf43ed1bf33d5f454eab39a7a4a1f115b0bd.tar.gz
gcc-e2bccf43ed1bf33d5f454eab39a7a4a1f115b0bd.tar.bz2
Merge #985
985: Parse macro!(); as MacroInvocation with semicolon r=CohenArthur a=CohenArthur When parsing a macro invocation as a statement, the parser would parse an expression and then try parsing a semicolon. Since no actual lookahead was done (which is a good thing), we couldn't convert a `MacroInvocation` to a `MacroInvocationSemi` after the fact. Since, unlike function calls, macro invocations can act differently based on whether or not they are followed by a semicolon, we actually need to differentiate between the two up until expansion. This commits adds a new virtual method for ExprWithoutBlock when converting to ExprStmtWithoutBlock so that classes inheriting ExprWithoutBlock can specify a new behavior. In the case of our MacroInvocation class, it simply means toggling a boolean: If we're converting a macro from an expression to a statement, it must mean that it should contain a semicolon. Closes #941 Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.cc')
-rw-r--r--gcc/rust/expand/rust-macro-expand.cc35
1 files changed, 9 insertions, 26 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index a4ed36b..26f584d 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -310,7 +310,8 @@ public:
{
// supposedly does not require - cfg does nothing
}
- void visit (AST::MacroInvocationSemi &macro_invoc) override
+
+ void visit (AST::MacroInvocation &macro_invoc) override
{
// initial strip test based on outer attrs
expander.expand_cfg_attrs (macro_invoc.get_outer_attrs ());
@@ -326,9 +327,13 @@ public:
// TODO: maybe have cfg! macro stripping behaviour here?
- expander.expand_invoc_semi (macro_invoc);
+ if (macro_invoc.has_semicolon ())
+ expander.expand_invoc_semi (macro_invoc);
+ else
+ expander.expand_invoc (macro_invoc);
- // we need to visit the expanded fragments since it may need cfg expansion
+ // we need to visit the expanded fragments since it may need cfg
+ // expansion
// and it may be recursive
for (auto &node : macro_invoc.get_fragment ().get_nodes ())
node.accept_vis (*this);
@@ -2534,28 +2539,6 @@ public:
expander.mappings->insert_macro_def (&rules_def);
}
- void visit (AST::MacroInvocation &macro_invoc) override
- {
- // FIXME
- // we probably need another recurision check here
-
- // initial strip test based on outer attrs
- expander.expand_cfg_attrs (macro_invoc.get_outer_attrs ());
- if (expander.fails_cfg_with_expand (macro_invoc.get_outer_attrs ()))
- {
- macro_invoc.mark_for_strip ();
- return;
- }
-
- // I don't think any macro token trees can be stripped in any way
- expander.expand_invoc (macro_invoc);
-
- // we need to visit the expanded fragments since it may need cfg expansion
- // and it may be recursive
- for (auto &node : macro_invoc.get_fragment ().get_nodes ())
- node.accept_vis (*this);
- }
-
void visit (AST::MetaItemPath &) override {}
void visit (AST::MetaItemSeq &) override {}
void visit (AST::MetaWord &) override {}
@@ -3209,7 +3192,7 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc)
}
void
-MacroExpander::expand_invoc_semi (AST::MacroInvocationSemi &invoc)
+MacroExpander::expand_invoc_semi (AST::MacroInvocation &invoc)
{
if (depth_exceeds_recursion_limit ())
{