]> gcc.gnu.org Git - gcc.git/commitdiff
gccrs: format_args: Parse entire token invocation
authorArthur Cohen <arthur.cohen@embecosm.com>
Wed, 7 Feb 2024 11:46:16 +0000 (12:46 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 1 Aug 2024 11:11:29 +0000 (13:11 +0200)
gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler):
Transform entire invocation token stream into string for the parser.

gcc/rust/expand/rust-macro-builtins.cc

index 19ea9109453964f2982619a6cbc963e284426e17..2af05a5e3777741f8e965952f91849006388242d 100644 (file)
@@ -16,6 +16,8 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 
+#include "libproc_macro_internal/tokenstream.h"
+#include "rust-token-converter.h"
 #include "rust-system.h"
 #include "rust-macro-builtins.h"
 #include "rust-ast-fragment.h"
@@ -947,24 +949,26 @@ tl::optional<AST::Fragment>
 MacroBuiltin::format_args_handler (location_t invoc_locus,
                                   AST::MacroInvocData &invoc)
 {
-  auto fmt_expr
-    = parse_single_string_literal (BuiltinMacro::FormatArgs,
-                                  invoc.get_delim_tok_tree (), invoc_locus,
-                                  invoc.get_expander ());
-
-  if (!fmt_expr)
-    return AST::Fragment::create_error ();
-
-  // if it is not a literal, it's an eager macro invocation - return it
-  if (!fmt_expr->is_literal ())
-    {
-      auto token_tree = invoc.get_delim_tok_tree ();
-      return AST::Fragment ({AST::SingleASTNode (std::move (fmt_expr))},
-                           token_tree.to_token_stream ());
-    }
-
-  auto format_string = fmt_expr->as_string ();
-  auto pieces = Fmt::Pieces::collect (format_string);
+  auto tokens = invoc.get_delim_tok_tree ().to_token_stream ();
+  tokens.erase (tokens.begin ());
+  tokens.pop_back ();
+
+  std::stringstream stream;
+  for (const auto &tok : tokens)
+    stream << tok->as_string () << ' ';
+
+  rust_debug ("[ARTHU]: `%s`", stream.str ().c_str ());
+
+  // FIXME: We need to handle this
+  // // if it is not a literal, it's an eager macro invocation - return it
+  // if (!fmt_expr->is_literal ())
+  //   {
+  //     auto token_tree = invoc.get_delim_tok_tree ();
+  //     return AST::Fragment ({AST::SingleASTNode (std::move (fmt_expr))},
+  //       token_tree.to_token_stream ());
+  //   }
+
+  auto pieces = Fmt::Pieces::collect (stream.str ());
 
   return AST::Fragment::create_empty ();
 }
This page took 0.065118 seconds and 5 git commands to generate.