From 1ff234bffdbd1e25636e2a382c8400fb1702ed13 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Patry Date: Mon, 24 Apr 2023 16:46:23 +0200 Subject: [PATCH] gccrs: libproc_macro: Add proc_macro interface structures Add the structures that should be used by a compiler opening a procedural macro to either identify or execute it. libgrust/ChangeLog: * libproc_macro/proc_macro.h (struct CustomDerivePayload): Add C compatible payload structure. (struct AttrPayload): Likewise. (struct BangPayload): Likewise. (enum ProcmacroTag): Add tag for tagged union. (union ProcmacroPayload): Proc macro payload union. (struct Procmacro): Tagged union. Signed-off-by: Pierre-Emmanuel Patry --- libgrust/libproc_macro/proc_macro.h | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/libgrust/libproc_macro/proc_macro.h b/libgrust/libproc_macro/proc_macro.h index 5778098bd4b..a5ee77435fe 100644 --- a/libgrust/libproc_macro/proc_macro.h +++ b/libgrust/libproc_macro/proc_macro.h @@ -23,6 +23,7 @@ #ifndef PROC_MACRO_H #define PROC_MACRO_H +#include #include "literal.h" #include "tokenstream.h" #include "tokentree.h" @@ -30,4 +31,58 @@ #include "punct.h" #include "ident.h" +namespace ProcMacro { + +extern "C" { + +using CustomDeriveMacro = TokenStream (*) (TokenStream); +using AttributeMacro = TokenStream (*) (TokenStream, TokenStream); +using BangMacro = TokenStream (*) (TokenStream); + +struct CustomDerivePayload +{ + // TODO: UTF-8 function name + char *trait_name; + // TODO: UTF-8 attributes + char **attributes; + std::uint64_t attr_size; + CustomDeriveMacro macro; +}; + +struct AttrPayload +{ + // TODO: UTF-8 function name + char *name; + AttributeMacro macro; +}; + +struct BangPayload +{ + char *name; + BangMacro macro; +}; +} + +enum ProcmacroTag +{ + CUSTOM_DERIVE, + ATTR, + BANG, +}; + +union ProcmacroPayload +{ + CustomDerivePayload custom_derive; + AttrPayload attribute; + BangPayload bang; +}; + +struct Procmacro +{ + ProcmacroTag tag; + ProcmacroPayload payload; +}; + +} // namespace ProcMacro + #endif /* ! PROC_MACRO_H */