From f730dff1738a93b0bd6f4f82cca04689e7f52187 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Thu, 11 May 2023 12:23:38 +0200 Subject: [PATCH] gccrs: converter: Merge dispatch into one function Floating point and integer dispatch now have almost the same behavior, their code could therefore be merged. gcc/rust/ChangeLog: * util/rust-token-converter.cc (dispatch_float_literals): Remove function. (handle_suffix): Rename old dispatch and add one LitKind argument. (dispatch_integer_literals): Remove function. (convert): Change call from dispatch to suffix handler. Signed-off-by: Pierre-Emmanuel Patry --- gcc/rust/util/rust-token-converter.cc | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc index d56493f5411..871c8e092c1 100644 --- a/gcc/rust/util/rust-token-converter.cc +++ b/gcc/rust/util/rust-token-converter.cc @@ -51,23 +51,10 @@ pop_group (std::vector &streams, } static void -dispatch_float_literals (ProcMacro::TokenStream &ts, - const const_TokenPtr &token) +handle_suffix (ProcMacro::TokenStream &ts, const const_TokenPtr &token, + ProcMacro::LitKind kind) { auto str = token->as_string (); - auto kind = ProcMacro::LitKind::make_float (); - auto lookup = suffixes.lookup (token->get_type_hint ()); - auto suffix = suffixes.is_iter_ok (lookup) ? lookup->second : ""; - ts.push (ProcMacro::TokenTree::make_tokentree ( - ProcMacro::Literal::make_literal (kind, str, suffix))); -} - -static void -dispatch_integer_literals (ProcMacro::TokenStream &ts, - const const_TokenPtr &token) -{ - auto str = token->as_string (); - auto kind = ProcMacro::LitKind::make_integer (); auto lookup = suffixes.lookup (token->get_type_hint ()); auto suffix = suffixes.is_iter_ok (lookup) ? lookup->second : ""; ts.push (ProcMacro::TokenTree::make_tokentree ( @@ -85,10 +72,12 @@ convert (const std::vector &tokens) { // Literals case FLOAT_LITERAL: - dispatch_float_literals (trees.back (), token); + handle_suffix (trees.back (), token, + ProcMacro::LitKind::make_float ()); break; case INT_LITERAL: - dispatch_integer_literals (trees.back (), token); + handle_suffix (trees.back (), token, + ProcMacro::LitKind::make_integer ()); break; case CHAR_LITERAL: trees.back ().push (ProcMacro::TokenTree::make_tokentree (