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 <pierre-emmanuel.patry@embecosm.com>
This commit is contained in:
Pierre-Emmanuel Patry 2023-04-24 16:46:23 +02:00 committed by Arthur Cohen
parent a365e3ed70
commit 1ff234bffd

View File

@ -23,6 +23,7 @@
#ifndef PROC_MACRO_H
#define PROC_MACRO_H
#include <cstdint>
#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 */