mirror of
https://github.com/gcc-mirror/gcc.git
synced 2024-11-21 13:40:47 +00:00
gccrs: libproc_macro: Add helpers to construct Procmacro
Add some helper functions to create Procmacro tagged unions. libgrust/ChangeLog: * libproc_macro/proc_macro.cc (Procmacro::make_derive): Add custom derive macro constructor. (Procmacro::make_attribute): Add attribute macro constructor. (Procmacro::make_bang): Add bang macro constructor. * libproc_macro/proc_macro.h (struct Procmacro): Add helper function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This commit is contained in:
parent
1ff234bffd
commit
fb3eb13f0f
@ -21,3 +21,32 @@
|
||||
// <http://www.gnu.org/licenses/>.
|
||||
|
||||
#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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user