]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: converter: Merge dispatch into one function
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Thu, 11 May 2023 10:23:38 +0000 (12:23 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:20 +0000 (18:37 +0100)
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 <pierre-emmanuel.patry@embecosm.com>
gcc/rust/util/rust-token-converter.cc

index d56493f5411c2ef21589ede1b5d59f288932f40b..871c8e092c10dbccc42b282559909dff429d82c8 100644 (file)
@@ -51,23 +51,10 @@ pop_group (std::vector<ProcMacro::TokenStream> &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<const_TokenPtr> &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 (