diff --git a/libgrust/libproc_macro/proc_macro.cc b/libgrust/libproc_macro/proc_macro.cc index 03beb89a33e..2e50f0afb01 100644 --- a/libgrust/libproc_macro/proc_macro.cc +++ b/libgrust/libproc_macro/proc_macro.cc @@ -21,3 +21,32 @@ // . #include "proc_macro.h" + +namespace ProcMacro { + +Procmacro +Procmacro::make_derive (const char *trait_name, const char **attributes, + std::uint64_t size, CustomDeriveMacro macro) +{ + ProcmacroPayload payload; + payload.custom_derive = {trait_name, attributes, size, macro}; + return {CUSTOM_DERIVE, payload}; +} + +Procmacro +Procmacro::make_attribute (const char *name, AttributeMacro macro) +{ + ProcmacroPayload payload; + payload.attribute = {name, macro}; + return {ATTR, payload}; +} + +Procmacro +Procmacro::make_bang (const char *name, BangMacro macro) +{ + ProcmacroPayload payload; + payload.bang = {name, macro}; + return {BANG, payload}; +} + +} // namespace ProcMacro diff --git a/libgrust/libproc_macro/proc_macro.h b/libgrust/libproc_macro/proc_macro.h index a5ee77435fe..3022203a5dd 100644 --- a/libgrust/libproc_macro/proc_macro.h +++ b/libgrust/libproc_macro/proc_macro.h @@ -42,9 +42,9 @@ using BangMacro = TokenStream (*) (TokenStream); struct CustomDerivePayload { // TODO: UTF-8 function name - char *trait_name; + const char *trait_name; // TODO: UTF-8 attributes - char **attributes; + const char **attributes; std::uint64_t attr_size; CustomDeriveMacro macro; }; @@ -52,13 +52,13 @@ struct CustomDerivePayload struct AttrPayload { // TODO: UTF-8 function name - char *name; + const char *name; AttributeMacro macro; }; struct BangPayload { - char *name; + const char *name; BangMacro macro; }; } @@ -81,6 +81,12 @@ struct Procmacro { ProcmacroTag tag; ProcmacroPayload payload; + +public: + Procmacro make_derive (const char *trait_name, const char **attribute, + std::uint64_t size, CustomDeriveMacro macro); + Procmacro make_attribute (const char *name, AttributeMacro macro); + Procmacro make_bang (const char *name, BangMacro macro); }; } // namespace ProcMacro