]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: expand: Switch semicolon boolean to an enum instead.
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 18 Jun 2024 11:47:57 +0000 (13:47 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:49 +0000 (16:35 +0100)
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.

14 files changed:
gcc/rust/ast/rust-ast-fragment.h
gcc/rust/ast/rust-macro.h
gcc/rust/expand/rust-expand-visitor.cc
gcc/rust/expand/rust-macro-builtins-asm.cc
gcc/rust/expand/rust-macro-builtins-asm.h
gcc/rust/expand/rust-macro-builtins-format-args.cc
gcc/rust/expand/rust-macro-builtins-include.cc
gcc/rust/expand/rust-macro-builtins-location.cc
gcc/rust/expand/rust-macro-builtins-log-debug.cc
gcc/rust/expand/rust-macro-builtins-utility.cc
gcc/rust/expand/rust-macro-builtins.cc
gcc/rust/expand/rust-macro-builtins.h
gcc/rust/expand/rust-macro-expand.cc
gcc/rust/expand/rust-macro-expand.h

index daa511226e3bbb0c75143fcec89b9c402e192739..7d01fd7904f3f50be86517cc80991b82949eac11 100644 (file)
@@ -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
index fbd9bd086340f6887bc7c5a70eaec3b7a8c2a390..76b3b2a3a8fde4915a078875082654b9010c9a84 100644 (file)
@@ -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 ();
index 78b78bca44981a14ffb830eeb932539e40b7fdcc..61147e2d7264c366afdd8e9bdbd3fa31a3bbf38e 100644 (file)
@@ -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
index 31457698ae9acbe4a01fecbf81c0521a27e46e1b..5b4661a40fdf0e4ec00a88016e37bbf2e32029dc 100644 (file)
@@ -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)));
 
index b290ebce4586cd4f5b61db4015c2dc18c4c38dea..30a68e620922acb19c3407b08c36d866ebf5e39a 100644 (file)
@@ -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);
index 72327d2d6eb9b0c22a747da6da9665a477a5a6af..031007b418bf788b72c99e28bd99822cb2a686bd 100644 (file)
@@ -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);
index c66db9225ba4567b4f2aea4524f86f8a44ee9b3c..cf3f93da094dc85cee88f59873016b0f1826322b 100644 (file)
@@ -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).  */
index 35cb88df73e4483b92b42dbc008a1d86eb3cd0fd..e588273ac3af314839ce0c13e4182af1d8ede863 100644 (file)
 // 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);
 
index 3919a24b9892af3bdca4b4d326b45ac73e75a7e5..49670d2b986aa9c12435c7fc04f31660624bbdc8 100644 (file)
 // 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");
 
index d3be4b73142be88941dfd5fad7c2ef49e82295cb..2da7d1865de97dca335855ffddd528024280cc5b 100644 (file)
@@ -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 ();
index 298711f162964cb4cc2f8792a6c100cf615489d1..2457bc030f86cff9294553b7aa1c9d6f8c97f52d 100644 (file)
@@ -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 ());
index 7ed751578e311b76d33eb04e0e31d9599d0b93fe..6a9b31cb80c2bd2ee347035c320f4d7887e573cc 100644 (file)
@@ -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
 
index 8a384a738df1bf76a83de67b8c3e553ffb9b6fb8..4d9cadec53c8f836d11e67ce32aaa5ce0a6f1050 100644 (file)
@@ -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 ();
index 9717999bfc322e9c08e0425dbd34e2f59f367a4c..5e127906bb76cfa8e6ecaa5e4dc17b57cde70505 100644 (file)
@@ -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);