]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
format_args: Parse format string properly
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 30 Jan 2024 15:16:36 +0000 (16:16 +0100)
committerCohenArthur <arthur.cohen@embecosm.com>
Mon, 26 Feb 2024 17:32:38 +0000 (17:32 +0000)
gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler):
Construct string to parser properly.

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

index 0e57406f10f82faa35d3b9540e2bb81b801308c9..19ea9109453964f2982619a6cbc963e284426e17 100644 (file)
@@ -947,7 +947,24 @@ tl::optional<AST::Fragment>
 MacroBuiltin::format_args_handler (location_t invoc_locus,
                                   AST::MacroInvocData &invoc)
 {
-  Fmt::Pieces::collect ("heyo this {is} what I {} want to {3}, {parse}");
+  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);
 
   return AST::Fragment::create_empty ();
 }