aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2023-07-27 16:21:25 +0200
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2023-07-28 09:15:21 +0000
commitfe6ad2e676ee5734856d86cf1dbbc12aef7e5561 (patch)
treeb7844fb216a15b089864aafef98f20f65b6e4157 /gcc/rust
parent69454e53048e24c80c725f4258d6dfd13f7ed023 (diff)
downloadgcc-fe6ad2e676ee5734856d86cf1dbbc12aef7e5561.zip
gcc-fe6ad2e676ee5734856d86cf1dbbc12aef7e5561.tar.gz
gcc-fe6ad2e676ee5734856d86cf1dbbc12aef7e5561.tar.bz2
proc_macro: Add literal_from_string callback
The function to get a literal from a string missed an implementation. It did require a conversion function to achieve it, now that callback system has been merged this function can be easily implemented. gcc/rust/ChangeLog: * expand/rust-proc-macro.cc (literal_from_string): Add callback function. (load_macros_array): Likewise. ChangeLog: * libgrust/libproc_macro/literal.cc (Literal__from_string): Add implementation with call to constructor. (Literal::make_literal): Add new constructor which calls the callback. * libgrust/libproc_macro/literal.h: Add new constructor's prototype. * libgrust/libproc_macro/proc_macro.cc (bridge_is_available): Change symbol name to match convention. * libgrust/libproc_macro/registration.h: Add lit_from_str symbol. * libgrust/libproc_macro/tokenstream.cc (TokenStream::make_tokenstream): Change symbol name to disambiguate with literal from string. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/expand/rust-proc-macro.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/gcc/rust/expand/rust-proc-macro.cc b/gcc/rust/expand/rust-proc-macro.cc
index c664e20..69de989 100644
--- a/gcc/rust/expand/rust-proc-macro.cc
+++ b/gcc/rust/expand/rust-proc-macro.cc
@@ -28,6 +28,22 @@ const std::string PROC_MACRO_DECL_PREFIX = "__gccrs_proc_macro_decls_";
namespace {
+ProcMacro::Literal
+literal_from_string (const std::string &data, bool &error)
+{
+ Lexer lex (data);
+ const_TokenPtr output = lex.build_token ();
+ if (output == nullptr || !output->is_literal ())
+ {
+ error = true;
+ // We should probably rework this
+ return ProcMacro::Literal::make_usize (0);
+ }
+
+ error = false;
+ return convert_literal (output);
+}
+
ProcMacro::TokenStream
tokenstream_from_string (std::string &data, bool &lex_error)
{
@@ -55,7 +71,12 @@ tokenstream_from_string (std::string &data, bool &lex_error)
static_assert (
std::is_same<decltype (tokenstream_from_string) *,
- ProcMacro::from_str_function_t>::value,
+ ProcMacro::ts_from_str_fn_t>::value,
+ "Registration callback signature not synced, check proc macro internals.");
+
+static_assert (
+ std::is_same<decltype (literal_from_string) *,
+ ProcMacro::lit_from_str_fn_t>::value,
"Registration callback signature not synced, check proc macro internals.");
} // namespace
@@ -96,10 +117,13 @@ load_macros_array (std::string path)
return nullptr;
}
- if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_from_str_fn,
+ if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_ts_from_str_,
tokenstream_from_string))
return nullptr;
- if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_is_available_fn,
+ if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_lit_from_str_,
+ literal_from_string))
+ return nullptr;
+ if (!REGISTER_CALLBACK (handle, __gccrs_proc_macro_is_available_,
ProcMacro::BridgeState::Available))
return nullptr;