From: Arthur Cohen <arthur.co...@embecosm.com>

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.
---
 gcc/rust/ast/rust-ast-fragment.h              | 14 ++++++-
 gcc/rust/ast/rust-macro.h                     |  2 +-
 gcc/rust/expand/rust-expand-visitor.cc        |  5 ++-
 gcc/rust/expand/rust-macro-builtins-asm.cc    | 20 ++++++----
 gcc/rust/expand/rust-macro-builtins-asm.h     |  3 +-
 .../expand/rust-macro-builtins-format-args.cc |  4 +-
 .../expand/rust-macro-builtins-include.cc     | 10 +++--
 .../expand/rust-macro-builtins-location.cc    |  9 +++--
 .../expand/rust-macro-builtins-log-debug.cc   |  4 +-
 .../expand/rust-macro-builtins-utility.cc     | 13 ++++---
 gcc/rust/expand/rust-macro-builtins.cc        | 30 ++++++---------
 gcc/rust/expand/rust-macro-builtins.h         | 37 ++++++++++---------
 gcc/rust/expand/rust-macro-expand.cc          | 20 +++++-----
 gcc/rust/expand/rust-macro-expand.h           |  7 ++--
 14 files changed, 105 insertions(+), 73 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-fragment.h b/gcc/rust/ast/rust-ast-fragment.h
index daa511226e3..7d01fd7904f 100644
--- a/gcc/rust/ast/rust-ast-fragment.h
+++ b/gcc/rust/ast/rust-ast-fragment.h
@@ -123,13 +123,25 @@ private:
   void assert_single_fragment (SingleASTNode::NodeType expected) const;
 };
 
+enum class InvocKind
+{
+  Expr,
+  Semicoloned,
+};
+
+enum class AsmKind
+{
+  Global,
+  Inline
+};
+
 /**
  * This is the type for transcriber functions found in
  * rust-macro-builtins.{h,cc}.
  */
 using MacroTranscriberFunc
   = std::function<tl::optional<Fragment> (location_t, MacroInvocData &,
-                                         bool semicolon)>;
+                                         InvocKind semicolon)>;
 
 } // namespace AST
 } // namespace Rust
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index fbd9bd08634..76b3b2a3a8f 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -482,7 +482,7 @@ private:
    * should make use of the actual rules. If the macro is builtin, then another
    * associated transcriber should be used
    */
-  static Fragment dummy_builtin (location_t, MacroInvocData &, bool)
+  static Fragment dummy_builtin (location_t, MacroInvocData &, AST::InvocKind)
   {
     rust_unreachable ();
     return Fragment::create_error ();
diff --git a/gcc/rust/expand/rust-expand-visitor.cc 
b/gcc/rust/expand/rust-expand-visitor.cc
index 78b78bca449..61147e2d726 100644
--- a/gcc/rust/expand/rust-expand-visitor.cc
+++ b/gcc/rust/expand/rust-expand-visitor.cc
@@ -17,6 +17,7 @@
 // <http://www.gnu.org/licenses/>.
 
 #include "rust-expand-visitor.h"
+#include "rust-ast-fragment.h"
 #include "rust-proc-macro.h"
 #include "rust-attributes.h"
 #include "rust-ast.h"
@@ -467,7 +468,9 @@ void
 ExpandVisitor::visit (AST::MacroInvocation &macro_invoc)
 {
   // TODO: Can we do the AST fragment replacing here? Probably not, right?
-  expander.expand_invoc (macro_invoc, macro_invoc.has_semicolon ());
+  expander.expand_invoc (macro_invoc, macro_invoc.has_semicolon ()
+                                       ? AST::InvocKind::Semicoloned
+                                       : AST::InvocKind::Expr);
 }
 
 void
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 31457698ae9..5b4661a40fd 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -16,7 +16,9 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include "rust-make-unique.h"
 #include "rust-macro-builtins-asm.h"
+#include "rust-ast-fragment.h"
 #include "rust-ast.h"
 #include "rust-stmt.h"
 
@@ -537,9 +539,9 @@ parse_format_string (InlineAsmContext &inline_asm_ctx)
 
 tl::optional<AST::Fragment>
 MacroBuiltin::asm_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                          bool semicolon, bool is_global_asm)
+                          AST::InvocKind semicolon, AST::AsmKind is_global_asm)
 {
-  return parse_asm (invoc_locus, invoc, is_global_asm, semicolon);
+  return parse_asm (invoc_locus, invoc, semicolon, is_global_asm);
 }
 
 tl::expected<InlineAsmContext, std::string>
@@ -609,7 +611,7 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx)
 
 tl::optional<AST::Fragment>
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
-          bool is_global_asm, bool semicolon)
+          AST::InvocKind semicolon, AST::AsmKind is_global_asm)
 {
   // From the rule of asm.
   // We first peek and see if it is a format string or not.
@@ -631,7 +633,8 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
   Parser<MacroInvocLexer> parser (lex);
   auto last_token_id = macro_end_token (invoc.get_delim_tok_tree (), parser);
 
-  AST::InlineAsm inline_asm (invoc_locus, is_global_asm);
+  AST::InlineAsm inline_asm (invoc_locus,
+                            is_global_asm == AST::AsmKind::Global);
   auto inline_asm_ctx = InlineAsmContext (inline_asm, parser, last_token_id);
 
   // operands stream, also handles the optional ","
@@ -654,10 +657,11 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData 
&invoc,
 
       // If the macro invocation has a semicolon (`asm!("...");`), then we need
       // to make it a statement. This way, it will be expanded properly.
-      if (semicolon)
-       single_vec.emplace_back (
-         AST::SingleASTNode (std::unique_ptr<AST::Stmt> (
-           new AST::ExprStmt (std::move (node), invoc_locus, semicolon))));
+      if (semicolon == AST::InvocKind::Semicoloned)
+       single_vec.emplace_back (AST::SingleASTNode (
+         Rust::make_unique<AST::ExprStmt> (std::move (node), invoc_locus,
+                                           semicolon
+                                             == AST::InvocKind::Semicoloned)));
       else
        single_vec.emplace_back (AST::SingleASTNode (std::move (node)));
 
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index b290ebce458..30a68e62092 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -1,4 +1,5 @@
 
+#include "rust-ast-fragment.h"
 #include "rust-macro-builtins.h"
 #include "rust-macro-builtins-helpers.h"
 #include "expected.h"
@@ -59,7 +60,7 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx);
 
 tl::optional<AST::Fragment>
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
-          bool is_global_asm, bool semicolon);
+          AST::InvocKind semicolon, AST::AsmKind is_global_asm);
 
 bool
 check_identifier (Parser<MacroInvocLexer> &parser, std::string ident);
diff --git a/gcc/rust/expand/rust-macro-builtins-format-args.cc 
b/gcc/rust/expand/rust-macro-builtins-format-args.cc
index 72327d2d6eb..031007b418b 100644
--- a/gcc/rust/expand/rust-macro-builtins-format-args.cc
+++ b/gcc/rust/expand/rust-macro-builtins-format-args.cc
@@ -15,6 +15,7 @@
 // You should have received a copy of the GNU General Public License
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
+#include "rust-ast-fragment.h"
 #include "rust-macro-builtins-helpers.h"
 #include "rust-expand-format-args.h"
 
@@ -115,7 +116,8 @@ format_args_parse_arguments (AST::MacroInvocData &invoc)
 
 tl::optional<AST::Fragment>
 MacroBuiltin::format_args_handler (location_t invoc_locus,
-                                  AST::MacroInvocData &invoc, bool semicolon,
+                                  AST::MacroInvocData &invoc,
+                                  AST::InvocKind semicolon,
                                   AST::FormatArgs::Newline nl)
 {
   auto input = format_args_parse_arguments (invoc);
diff --git a/gcc/rust/expand/rust-macro-builtins-include.cc 
b/gcc/rust/expand/rust-macro-builtins-include.cc
index c66db9225ba..cf3f93da094 100644
--- a/gcc/rust/expand/rust-macro-builtins-include.cc
+++ b/gcc/rust/expand/rust-macro-builtins-include.cc
@@ -16,6 +16,7 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include "rust-ast-fragment.h"
 #include "rust-common.h"
 #include "rust-macro-builtins.h"
 #include "rust-macro-builtins-helpers.h"
@@ -27,7 +28,8 @@ of the given file as reference to a byte array. Yields an 
expression of type
 
 tl::optional<AST::Fragment>
 MacroBuiltin::include_bytes_handler (location_t invoc_locus,
-                                    AST::MacroInvocData &invoc, bool semicolon)
+                                    AST::MacroInvocData &invoc,
+                                    AST::InvocKind semicolon)
 {
   /* Get target filename from the macro invocation, which is treated as a path
      relative to the include!-ing file (currently being compiled).  */
@@ -93,7 +95,8 @@ MacroBuiltin::include_bytes_handler (location_t invoc_locus,
 
 tl::optional<AST::Fragment>
 MacroBuiltin::include_str_handler (location_t invoc_locus,
-                                  AST::MacroInvocData &invoc, bool semicolon)
+                                  AST::MacroInvocData &invoc,
+                                  AST::InvocKind semicolon)
 {
   /* Get target filename from the macro invocation, which is treated as a path
      relative to the include!-ing file (currently being compiled).  */
@@ -182,7 +185,8 @@ scope compile time. */
 
 tl::optional<AST::Fragment>
 MacroBuiltin::include_handler (location_t invoc_locus,
-                              AST::MacroInvocData &invoc, bool semicolon)
+                              AST::MacroInvocData &invoc,
+                              AST::InvocKind semicolon)
 {
   /* Get target filename from the macro invocation, which is treated as a path
      relative to the include!-ing file (currently being compiled).  */
diff --git a/gcc/rust/expand/rust-macro-builtins-location.cc 
b/gcc/rust/expand/rust-macro-builtins-location.cc
index 35cb88df73e..e588273ac3a 100644
--- a/gcc/rust/expand/rust-macro-builtins-location.cc
+++ b/gcc/rust/expand/rust-macro-builtins-location.cc
@@ -16,12 +16,14 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include "rust-ast-fragment.h"
 #include "rust-macro-builtins.h"
 #include "rust-macro-builtins-helpers.h"
 
 namespace Rust {
 tl::optional<AST::Fragment>
-MacroBuiltin::file_handler (location_t invoc_locus, AST::MacroInvocData &, 
bool)
+MacroBuiltin::file_handler (location_t invoc_locus, AST::MacroInvocData &,
+                           AST::InvocKind)
 {
   auto current_file = LOCATION_FILE (invoc_locus);
   auto file_str = AST::SingleASTNode (make_string (invoc_locus, current_file));
@@ -33,7 +35,7 @@ MacroBuiltin::file_handler (location_t invoc_locus, 
AST::MacroInvocData &, bool)
 
 tl::optional<AST::Fragment>
 MacroBuiltin::column_handler (location_t invoc_locus, AST::MacroInvocData &,
-                             bool)
+                             AST::InvocKind)
 {
   auto current_column = LOCATION_COLUMN (invoc_locus);
 
@@ -47,7 +49,8 @@ MacroBuiltin::column_handler (location_t invoc_locus, 
AST::MacroInvocData &,
 }
 
 tl::optional<AST::Fragment>
-MacroBuiltin::line_handler (location_t invoc_locus, AST::MacroInvocData &, 
bool)
+MacroBuiltin::line_handler (location_t invoc_locus, AST::MacroInvocData &,
+                           AST::InvocKind)
 {
   auto current_line = LOCATION_LINE (invoc_locus);
 
diff --git a/gcc/rust/expand/rust-macro-builtins-log-debug.cc 
b/gcc/rust/expand/rust-macro-builtins-log-debug.cc
index 3919a24b989..49670d2b986 100644
--- a/gcc/rust/expand/rust-macro-builtins-log-debug.cc
+++ b/gcc/rust/expand/rust-macro-builtins-log-debug.cc
@@ -16,13 +16,15 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include "rust-ast-fragment.h"
 #include "rust-macro-builtins.h"
 #include "rust-macro-builtins-helpers.h"
 
 namespace Rust {
 tl::optional<AST::Fragment>
 MacroBuiltin::assert_handler (location_t invoc_locus,
-                             AST::MacroInvocData &invoc, bool semicolon)
+                             AST::MacroInvocData &invoc,
+                             AST::InvocKind semicolon)
 {
   rust_debug ("assert!() called");
 
diff --git a/gcc/rust/expand/rust-macro-builtins-utility.cc 
b/gcc/rust/expand/rust-macro-builtins-utility.cc
index d3be4b73142..2da7d1865de 100644
--- a/gcc/rust/expand/rust-macro-builtins-utility.cc
+++ b/gcc/rust/expand/rust-macro-builtins-utility.cc
@@ -26,7 +26,8 @@ namespace Rust {
    during the compile time. */
 tl::optional<AST::Fragment>
 MacroBuiltin::compile_error_handler (location_t invoc_locus,
-                                    AST::MacroInvocData &invoc, bool semicolon)
+                                    AST::MacroInvocData &invoc,
+                                    AST::InvocKind semicolon)
 {
   auto lit_expr
     = parse_single_string_literal (BuiltinMacro::CompileError,
@@ -87,7 +88,8 @@ MacroBuiltin::compile_error_handler (location_t invoc_locus,
 // Can we do that easily?
 tl::optional<AST::Fragment>
 MacroBuiltin::concat_handler (location_t invoc_locus,
-                             AST::MacroInvocData &invoc, bool semicolon)
+                             AST::MacroInvocData &invoc,
+                             AST::InvocKind semicolon)
 {
   auto invoc_token_tree = invoc.get_delim_tok_tree ();
   MacroInvocLexer lex (invoc_token_tree.to_token_stream ());
@@ -152,7 +154,7 @@ MacroBuiltin::concat_handler (location_t invoc_locus,
    compile time. */
 tl::optional<AST::Fragment>
 MacroBuiltin::env_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                          bool semicolon)
+                          AST::InvocKind semicolon)
 {
   auto invoc_token_tree = invoc.get_delim_tok_tree ();
   MacroInvocLexer lex (invoc_token_tree.to_token_stream ());
@@ -226,7 +228,7 @@ MacroBuiltin::env_handler (location_t invoc_locus, 
AST::MacroInvocData &invoc,
 
 tl::optional<AST::Fragment>
 MacroBuiltin::cfg_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                          bool semicolon)
+                          AST::InvocKind semicolon)
 {
   // only parse if not already parsed
   if (!invoc.is_parsed ())
@@ -265,7 +267,8 @@ MacroBuiltin::cfg_handler (location_t invoc_locus, 
AST::MacroInvocData &invoc,
 
 tl::optional<AST::Fragment>
 MacroBuiltin::stringify_handler (location_t invoc_locus,
-                                AST::MacroInvocData &invoc, bool semicolon)
+                                AST::MacroInvocData &invoc,
+                                AST::InvocKind semicolon)
 {
   std::string content;
   auto invoc_token_tree = invoc.get_delim_tok_tree ();
diff --git a/gcc/rust/expand/rust-macro-builtins.cc 
b/gcc/rust/expand/rust-macro-builtins.cc
index 298711f1629..2457bc030f8 100644
--- a/gcc/rust/expand/rust-macro-builtins.cc
+++ b/gcc/rust/expand/rust-macro-builtins.cc
@@ -87,26 +87,19 @@ const BiMap<std::string, BuiltinMacro> 
MacroBuiltin::builtins = {{
 AST::MacroTranscriberFunc
 format_args_maker (AST::FormatArgs::Newline nl)
 {
-  return [nl] (location_t loc, AST::MacroInvocData &invoc, bool semicolon) {
+  return [nl] (location_t loc, AST::MacroInvocData &invoc,
+              AST::InvocKind semicolon) {
     return MacroBuiltin::format_args_handler (loc, invoc, semicolon, nl);
   };
 }
 
-enum class isGlobalAsm
-{
-  Global,
-  Inline,
-};
-
 AST::MacroTranscriberFunc
-inline_asm_maker (isGlobalAsm is_global_asm)
+inline_asm_maker (AST::AsmKind global_asm)
 {
-  bool global_asm = is_global_asm == isGlobalAsm::Global ? true : false;
-
-  return
-    [global_asm] (location_t loc, AST::MacroInvocData &invoc, bool semicolon) {
-      return MacroBuiltin::asm_handler (loc, invoc, semicolon, global_asm);
-    };
+  return [global_asm] (location_t loc, AST::MacroInvocData &invoc,
+                      AST::InvocKind semicolon) {
+    return MacroBuiltin::asm_handler (loc, invoc, semicolon, global_asm);
+  };
 }
 
 std::unordered_map<std::string, AST::MacroTranscriberFunc>
@@ -125,8 +118,8 @@ std::unordered_map<std::string, AST::MacroTranscriberFunc>
     {"include", MacroBuiltin::include_handler},
     {"format_args", format_args_maker (AST::FormatArgs::Newline::No)},
     {"format_args_nl", format_args_maker (AST::FormatArgs::Newline::Yes)},
-    {"asm", inline_asm_maker (isGlobalAsm::Inline)},
-    {"global_asm", inline_asm_maker (isGlobalAsm::Global)},
+    {"asm", inline_asm_maker (AST::AsmKind::Inline)},
+    {"global_asm", inline_asm_maker (AST::AsmKind::Global)},
     /* Unimplemented macro builtins */
     {"option_env", MacroBuiltin::sorry},
     {"concat_idents", MacroBuiltin::sorry},
@@ -169,7 +162,7 @@ builtin_macro_from_string (const std::string &identifier)
 
 tl::optional<AST::Fragment>
 MacroBuiltin::sorry (location_t invoc_locus, AST::MacroInvocData &invoc,
-                    bool semicolon)
+                    AST::InvocKind semicolon)
 {
   rust_sorry_at (invoc_locus, "unimplemented builtin macro: %qs",
                 invoc.get_path ().as_string ().c_str ());
@@ -179,7 +172,8 @@ MacroBuiltin::sorry (location_t invoc_locus, 
AST::MacroInvocData &invoc,
 
 tl::optional<AST::Fragment>
 MacroBuiltin::proc_macro_builtin (location_t invoc_locus,
-                                 AST::MacroInvocData &invoc, bool semicolon)
+                                 AST::MacroInvocData &invoc,
+                                 AST::InvocKind semicolon)
 {
   rust_error_at (invoc_locus, "cannot invoke derive macro: %qs",
                 invoc.get_path ().as_string ().c_str ());
diff --git a/gcc/rust/expand/rust-macro-builtins.h 
b/gcc/rust/expand/rust-macro-builtins.h
index 7ed751578e3..6a9b31cb80c 100644
--- a/gcc/rust/expand/rust-macro-builtins.h
+++ b/gcc/rust/expand/rust-macro-builtins.h
@@ -125,68 +125,69 @@ public:
 
   static tl::optional<AST::Fragment> assert_handler (location_t invoc_locus,
                                                     AST::MacroInvocData &invoc,
-                                                    bool semicolon);
+                                                    AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment> file_handler (location_t invoc_locus,
                                                   AST::MacroInvocData &invoc,
-                                                  bool semicolon);
+                                                  AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment> column_handler (location_t invoc_locus,
                                                     AST::MacroInvocData &invoc,
-                                                    bool semicolon);
+                                                    AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment>
   include_bytes_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                        bool semicolon);
+                        AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment>
   include_str_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                      bool semicolon);
+                      AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment>
   stringify_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                    bool semicolon);
+                    AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment>
   compile_error_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                        bool semicolon);
+                        AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment> concat_handler (location_t invoc_locus,
                                                     AST::MacroInvocData &invoc,
-                                                    bool semicolon);
+                                                    AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment> env_handler (location_t invoc_locus,
                                                  AST::MacroInvocData &invoc,
-                                                 bool semicolon);
+                                                 AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment> cfg_handler (location_t invoc_locus,
                                                  AST::MacroInvocData &invoc,
-                                                 bool semicolon);
+                                                 AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment>
   include_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                  bool semicolon);
+                  AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment> line_handler (location_t invoc_locus,
                                                   AST::MacroInvocData &invoc,
-                                                  bool semicolon);
+                                                  AST::InvocKind semicolon);
 
   static tl::optional<AST::Fragment> asm_handler (location_t invoc_locus,
                                                  AST::MacroInvocData &invoc,
-                                                 bool semicolon,
-                                                 bool is_global_asm);
+                                                 AST::InvocKind semicolon,
+                                                 AST::AsmKind is_global_asm);
 
   static tl::optional<AST::Fragment>
   format_args_handler (location_t invoc_locus, AST::MacroInvocData &invoc,
-                      bool semicolon, AST::FormatArgs::Newline nl);
+                      AST::InvocKind semicolon, AST::FormatArgs::Newline nl);
 
-  static tl::optional<AST::Fragment>
-  sorry (location_t invoc_locus, AST::MacroInvocData &invoc, bool semicolon);
+  static tl::optional<AST::Fragment> sorry (location_t invoc_locus,
+                                           AST::MacroInvocData &invoc,
+                                           AST::InvocKind semicolon);
 
   /* Builtin procedural macros do not work directly on tokens, but still need a
    * builtin transcriber to be considered proper builtin macros */
   static tl::optional<AST::Fragment>
-  proc_macro_builtin (location_t, AST::MacroInvocData &, bool);
+  proc_macro_builtin (location_t, AST::MacroInvocData &, AST::InvocKind);
 };
 } // namespace Rust
 
diff --git a/gcc/rust/expand/rust-macro-expand.cc 
b/gcc/rust/expand/rust-macro-expand.cc
index 8a384a738df..4d9cadec53c 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 ();
diff --git a/gcc/rust/expand/rust-macro-expand.h 
b/gcc/rust/expand/rust-macro-expand.h
index 9717999bfc3..5e127906bb7 100644
--- a/gcc/rust/expand/rust-macro-expand.h
+++ b/gcc/rust/expand/rust-macro-expand.h
@@ -20,6 +20,7 @@
 #define RUST_MACRO_EXPAND_H
 
 #include "optional.h"
+#include "rust-ast-fragment.h"
 #include "rust-buffered-queue.h"
 #include "rust-parse.h"
 #include "rust-token.h"
@@ -317,12 +318,12 @@ 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, bool has_semicolon);
+  void expand_invoc (AST::MacroInvocation &invoc, AST::InvocKind semicolon);
 
   // Expands a single declarative macro.
   AST::Fragment expand_decl_macro (location_t locus, AST::MacroInvocData 
&invoc,
                                   AST::MacroRulesDefinition &rules_def,
-                                  bool semicolon);
+                                  AST::InvocKind semicolon);
 
   bool depth_exceeds_recursion_limit () const;
 
@@ -332,7 +333,7 @@ struct MacroExpander
   AST::Fragment 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 match_fragment (Parser<MacroInvocLexer> &parser,
                       AST::MacroMatchFragment &fragment);
-- 
2.45.2

Reply via email to