diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-06-18 13:47:57 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2024-06-18 12:24:32 +0000 |
commit | 7d22e900b069c5acdff8272da89b959c50dcb666 (patch) | |
tree | f8fe54ff3039a6171bc3100bfeff287ae8052e3b /gcc/rust/expand/rust-macro-expand.cc | |
parent | fb906a41a4e911f7f0d7b506347286c7d942995e (diff) | |
download | gcc-7d22e900b069c5acdff8272da89b959c50dcb666.zip gcc-7d22e900b069c5acdff8272da89b959c50dcb666.tar.gz gcc-7d22e900b069c5acdff8272da89b959c50dcb666.tar.bz2 |
expand: Switch semicolon boolean to an enum instead.
gcc/rust/ChangeLog:
* ast/rust-ast-fragment.h (enum class): Add InvocKind and AsmKind enums.
* ast/rust-macro.h: Switch semicolon boolean to InvocKind enum.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* expand/rust-macro-builtins-asm.cc (MacroBuiltin::asm_handler): Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (parse_asm): Likewise.
* expand/rust-macro-builtins-format-args.cc (MacroBuiltin::format_args_handler): Likewise.
* expand/rust-macro-builtins-include.cc (MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
* expand/rust-macro-builtins-location.cc (MacroBuiltin::file_handler): Likewise.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* expand/rust-macro-builtins-log-debug.cc (MacroBuiltin::assert_handler): Likewise.
* expand/rust-macro-builtins-utility.cc (MacroBuiltin::compile_error_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::stringify_handler): Likewise.
* expand/rust-macro-builtins.cc (format_args_maker): Likewise.
(enum class): Likewise.
(inline_asm_maker): Likewise.
(MacroBuiltin::sorry): Likewise.
(MacroBuiltin::proc_macro_builtin): Likewise.
* expand/rust-macro-builtins.h: Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Likewise.
(MacroExpander::expand_eager_invocations): Likewise.
(MacroExpander::expand_invoc): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
Diffstat (limited to 'gcc/rust/expand/rust-macro-expand.cc')
-rw-r--r-- | gcc/rust/expand/rust-macro-expand.cc | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc index 9742bbc..7c558f7 100644 --- a/gcc/rust/expand/rust-macro-expand.cc +++ b/gcc/rust/expand/rust-macro-expand.cc @@ -18,6 +18,7 @@ #include "rust-macro-expand.h" #include "optional.h" +#include "rust-ast-fragment.h" #include "rust-macro-substitute-ctx.h" #include "rust-ast-full.h" #include "rust-ast-visitor.h" @@ -34,7 +35,7 @@ AST::Fragment MacroExpander::expand_decl_macro (location_t invoc_locus, AST::MacroInvocData &invoc, AST::MacroRulesDefinition &rules_def, - bool semicolon) + AST::InvocKind semicolon) { // ensure that both invocation and rules are in a valid state rust_assert (!invoc.is_marked_for_strip ()); @@ -201,7 +202,7 @@ MacroExpander::expand_eager_invocations (AST::MacroInvocation &invoc) for (auto kv : substitution_map) { auto &to_expand = kv.second; - expand_invoc (*to_expand, false); + expand_invoc (*to_expand, AST::InvocKind::Expr); auto fragment = take_expanded_fragment (); auto &new_tokens = fragment.get_tokens (); @@ -239,7 +240,8 @@ MacroExpander::expand_eager_invocations (AST::MacroInvocation &invoc) } void -MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon) +MacroExpander::expand_invoc (AST::MacroInvocation &invoc, + AST::InvocKind semicolon) { if (depth_exceeds_recursion_limit ()) { @@ -288,16 +290,14 @@ MacroExpander::expand_invoc (AST::MacroInvocation &invoc, bool has_semicolon) last_invoc = *invoc.clone_macro_invocation_impl (); last_def = *rdef; - rust_debug ("[ARTHUR] semicolon: %s", has_semicolon ? "yes" : "no"); - if (rdef->is_builtin ()) fragment = rdef ->get_builtin_transcriber () (invoc.get_locus (), invoc_data, - has_semicolon) + semicolon) .value_or (AST::Fragment::create_empty ()); else - fragment = expand_decl_macro (invoc.get_locus (), invoc_data, *rdef, - has_semicolon); + fragment + = expand_decl_macro (invoc.get_locus (), invoc_data, *rdef, semicolon); set_expanded_fragment (std::move (fragment)); } @@ -1021,8 +1021,10 @@ AST::Fragment MacroExpander::transcribe_rule ( AST::MacroRule &match_rule, AST::DelimTokenTree &invoc_token_tree, std::map<std::string, MatchedFragmentContainer *> &matched_fragments, - bool semicolon, ContextType ctx) + AST::InvocKind invoc_kind, ContextType ctx) { + bool semicolon = invoc_kind == AST::InvocKind::Semicoloned; + // we can manipulate the token tree to substitute the dollar identifiers so // that when we call parse its already substituted for us AST::MacroTranscriber &transcriber = match_rule.get_transcriber (); |