diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-05-11 12:23:38 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:37:20 +0100 |
commit | f730dff1738a93b0bd6f4f82cca04689e7f52187 (patch) | |
tree | af4e532cd322731920be4a057f3dfa71bc1830b4 | |
parent | 10c9b9f0ccc340e53e1dfd3e8ca9125f280d8e66 (diff) | |
download | gcc-f730dff1738a93b0bd6f4f82cca04689e7f52187.zip gcc-f730dff1738a93b0bd6f4f82cca04689e7f52187.tar.gz gcc-f730dff1738a93b0bd6f4f82cca04689e7f52187.tar.bz2 |
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 <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | gcc/rust/util/rust-token-converter.cc | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/gcc/rust/util/rust-token-converter.cc b/gcc/rust/util/rust-token-converter.cc index d56493f..871c8e0 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<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 ( |