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-02-23 13:37:07 +0000
committerGitHub <noreply@github.com>2022-02-23 13:37:07 +0000
commitbf92a1012264f2544e73a7a8dd0ac1e473c7f658 (patch)
treef7a3fd3afb0c2e2b2678d80dcd742da23c1b8f9a /gcc/rust/expand/rust-macro-expand.cc
parent10de9cf4f3765526a1a82a4a7d14908b58c6538c (diff)
parent48b3fe622e9a582b076c6f4b19b5e8b69891ac31 (diff)
downloadgcc-bf92a1012264f2544e73a7a8dd0ac1e473c7f658.zip
gcc-bf92a1012264f2544e73a7a8dd0ac1e473c7f658.tar.gz
gcc-bf92a1012264f2544e73a7a8dd0ac1e473c7f658.tar.bz2
Merge #969
969: Add builtin macros framework r=CohenArthur a=CohenArthur This PR adds bases to define new builtin macro functions. Since we operate at the `insert_macro_def` level, this requires builtin macros to be defined, as is the case in the rust standard library: ```rust macro_rules! assert { ($cond:expr $(,)?) => {{ /* compiler built-in */ }}; ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }}; } ``` 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.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index b54aa01..7552e82 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -3194,8 +3194,14 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc)
bool ok = mappings->lookup_macro_def (resolved_node, &rules_def);
rust_assert (ok);
- auto fragment
- = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def, false);
+ auto fragment = AST::ASTFragment::create_empty ();
+
+ if (rules_def->is_builtin ())
+ fragment
+ = rules_def->get_builtin_transcriber () (invoc.get_locus (), invoc_data);
+ else
+ fragment
+ = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def, false);
// lets attach this fragment to the invocation
invoc.set_fragment (std::move (fragment));
@@ -3229,8 +3235,14 @@ MacroExpander::expand_invoc_semi (AST::MacroInvocationSemi &invoc)
bool ok = mappings->lookup_macro_def (resolved_node, &rules_def);
rust_assert (ok);
- auto fragment
- = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def, true);
+ auto fragment = AST::ASTFragment::create_empty ();
+
+ if (rules_def->is_builtin ())
+ fragment
+ = rules_def->get_builtin_transcriber () (invoc.get_locus (), invoc_data);
+ else
+ fragment
+ = expand_decl_macro (invoc.get_locus (), invoc_data, *rules_def, true);
// lets attach this fragment to the invocation
invoc.set_fragment (std::move (fragment));