Skip to content

Commit e747d1a

Browse files
committed
format_args: Parse entire token invocation
gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler): Transform entire invocation token stream into string for the parser.
1 parent 51345d2 commit e747d1a

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// along with GCC; see the file COPYING3. If not see
1717
// <http://www.gnu.org/licenses/>.
1818

19+
#include "libproc_macro_internal/tokenstream.h"
20+
#include "rust-token-converter.h"
1921
#include "rust-system.h"
2022
#include "rust-macro-builtins.h"
2123
#include "rust-ast-fragment.h"
@@ -947,24 +949,26 @@ tl::optional<AST::Fragment>
947949
MacroBuiltin::format_args_handler (location_t invoc_locus,
948950
AST::MacroInvocData &invoc)
949951
{
950-
auto fmt_expr
951-
= parse_single_string_literal (BuiltinMacro::FormatArgs,
952-
invoc.get_delim_tok_tree (), invoc_locus,
953-
invoc.get_expander ());
954-
955-
if (!fmt_expr)
956-
return AST::Fragment::create_error ();
957-
958-
// if it is not a literal, it's an eager macro invocation - return it
959-
if (!fmt_expr->is_literal ())
960-
{
961-
auto token_tree = invoc.get_delim_tok_tree ();
962-
return AST::Fragment ({AST::SingleASTNode (std::move (fmt_expr))},
963-
token_tree.to_token_stream ());
964-
}
965-
966-
auto format_string = fmt_expr->as_string ();
967-
auto pieces = Fmt::Pieces::collect (format_string);
952+
auto tokens = invoc.get_delim_tok_tree ().to_token_stream ();
953+
tokens.erase (tokens.begin ());
954+
tokens.pop_back ();
955+
956+
std::stringstream stream;
957+
for (const auto &tok : tokens)
958+
stream << tok->as_string () << ' ';
959+
960+
rust_debug ("[ARTHU]: `%s`", stream.str ().c_str ());
961+
962+
// FIXME: We need to handle this
963+
// // if it is not a literal, it's an eager macro invocation - return it
964+
// if (!fmt_expr->is_literal ())
965+
// {
966+
// auto token_tree = invoc.get_delim_tok_tree ();
967+
// return AST::Fragment ({AST::SingleASTNode (std::move (fmt_expr))},
968+
// token_tree.to_token_stream ());
969+
// }
970+
971+
auto pieces = Fmt::Pieces::collect (stream.str ());
968972

969973
return AST::Fragment::create_empty ();
970974
}

0 commit comments

Comments
 (0)