diff options
| author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-07-27 16:21:25 +0200 |
|---|---|---|
| committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 18:56:02 +0100 |
| commit | 0680907b3b19273b908c91306932abbf82f85cce (patch) | |
| tree | f49ce96a39b9455891185efed2629703523a9f1f /libgrust | |
| parent | ff773b9030e443dbea0b4357bd10b480ff39c987 (diff) | |
gccrs: 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.
libgrust/ChangeLog:
* libproc_macro/literal.cc (Literal__from_string): Add
implementation with call to constructor.
(Literal::make_literal): Add new constructor which calls the
callback.
* libproc_macro/literal.h: Add new constructor's
prototype.
* libproc_macro/proc_macro.cc (bridge_is_available):
Change symbol name to match convention.
* libproc_macro/registration.h: Add lit_from_str
symbol.
* 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 'libgrust')
| -rw-r--r-- | libgrust/libproc_macro/literal.cc | 16 | ||||
| -rw-r--r-- | libgrust/libproc_macro/literal.h | 1 | ||||
| -rw-r--r-- | libgrust/libproc_macro/proc_macro.cc | 8 | ||||
| -rw-r--r-- | libgrust/libproc_macro/registration.h | 9 | ||||
| -rw-r--r-- | libgrust/libproc_macro/tokenstream.cc | 2 |
5 files changed, 25 insertions, 11 deletions
diff --git a/libgrust/libproc_macro/literal.cc b/libgrust/libproc_macro/literal.cc index 8e1e0a4a116..ea09106cd62 100644 --- a/libgrust/libproc_macro/literal.cc +++ b/libgrust/libproc_macro/literal.cc @@ -24,15 +24,19 @@ #include <cstring> #include <cstdlib> +#include "registration.h" + namespace ProcMacro { extern "C" { bool Literal__from_string (FFIString str, Literal *lit) { - // FIXME: implement this function with lexer - std::abort (); - return false; + bool result; + auto source = str.to_string (); + + *lit = Literal::make_literal (source, result); + return result; } } @@ -50,6 +54,12 @@ Literal::clone () const } Literal +Literal::make_literal (const std::string &text, bool &has_error) +{ + return __gccrs_proc_macro_lit_from_str_ (text, has_error); +} + +Literal Literal::make_literal (LitKind kind, Span span, const std::string &text, const std::string &suffix) { diff --git a/libgrust/libproc_macro/literal.h b/libgrust/libproc_macro/literal.h index fb8a8b442e2..37ba0891dbe 100644 --- a/libgrust/libproc_macro/literal.h +++ b/libgrust/libproc_macro/literal.h @@ -77,6 +77,7 @@ public: Literal clone () const; bool has_suffix () const { return suffix.len != 0; }; + static Literal make_literal (const std::string &text, bool &has_error); static Literal make_literal (const LitKind kind, Span span, const std::string &text, const std::string &suffix = ""); diff --git a/libgrust/libproc_macro/proc_macro.cc b/libgrust/libproc_macro/proc_macro.cc index 293fc957038..0490673b656 100644 --- a/libgrust/libproc_macro/proc_macro.cc +++ b/libgrust/libproc_macro/proc_macro.cc @@ -53,12 +53,12 @@ Procmacro::make_bang (const char *name, BangMacro macro) extern "C" bool bridge_is_available () { - return __gccrs_proc_macro_is_available_fn - == ProcMacro::BridgeState::Available; + return __gccrs_proc_macro_is_available_ == ProcMacro::BridgeState::Available; } } // namespace ProcMacro -ProcMacro::from_str_function_t __gccrs_proc_macro_from_str_fn = nullptr; -ProcMacro::BridgeState __gccrs_proc_macro_is_available_fn +ProcMacro::ts_from_str_fn_t __gccrs_proc_macro_ts_from_str_ = nullptr; +ProcMacro::lit_from_str_fn_t __gccrs_proc_macro_lit_from_str_ = nullptr; +ProcMacro::BridgeState __gccrs_proc_macro_is_available_ = ProcMacro::BridgeState::Unavailable; diff --git a/libgrust/libproc_macro/registration.h b/libgrust/libproc_macro/registration.h index aba7edd81fb..98e7c139c27 100644 --- a/libgrust/libproc_macro/registration.h +++ b/libgrust/libproc_macro/registration.h @@ -26,14 +26,17 @@ #include <string> #include "tokenstream.h" #include "bridge.h" +#include "literal.h" namespace ProcMacro { -using from_str_function_t = ProcMacro::TokenStream (*) (std::string &, bool &); +using ts_from_str_fn_t = ProcMacro::TokenStream (*) (std::string &, bool &); +using lit_from_str_fn_t = ProcMacro::Literal (*) (const std::string &, bool &); } // namespace ProcMacro -extern "C" ProcMacro::from_str_function_t __gccrs_proc_macro_from_str_fn; -extern "C" ProcMacro::BridgeState __gccrs_proc_macro_is_available_fn; +extern "C" ProcMacro::ts_from_str_fn_t __gccrs_proc_macro_ts_from_str_; +extern "C" ProcMacro::lit_from_str_fn_t __gccrs_proc_macro_lit_from_str_; +extern "C" ProcMacro::BridgeState __gccrs_proc_macro_is_available_; #endif /* !REGISTRATION_H */ diff --git a/libgrust/libproc_macro/tokenstream.cc b/libgrust/libproc_macro/tokenstream.cc index 0f7f1f2079b..685f28424d2 100644 --- a/libgrust/libproc_macro/tokenstream.cc +++ b/libgrust/libproc_macro/tokenstream.cc @@ -49,7 +49,7 @@ TokenStream::make_tokenstream (std::uint64_t capacity) TokenStream TokenStream::make_tokenstream (std::string &source, bool &has_error) { - return __gccrs_proc_macro_from_str_fn (source, has_error); + return __gccrs_proc_macro_ts_from_str_ (source, has_error); } void |
