Debian Codegraph @

libgrust/libproc_macro_internal/proc_macro.h

raw
1 // Copyright (C) 2023-2024 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU Proc Macro Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // Under Section 7 of GPL version 3, you are granted additional
15 // permissions described in the GCC Runtime Library Exception, version
16 // 3.1, as published by the Free Software Foundation.
17
18 // You should have received a copy of the GNU General Public License and
19 // a copy of the GCC Runtime Library Exception along with this program;
20 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21 // <http://www.gnu.org/licenses/>.
22
23 #ifndef PROC_MACRO_H
24 #define PROC_MACRO_H
25
26 #include <cstdint>
27 #include "literal.h"
28 #include "tokenstream.h"
29 #include "tokentree.h"
30 #include "group.h"
31 #include "punct.h"
32 #include "ident.h"
33 #include "registration.h"
34
35 namespace ProcMacro {
36
37 extern "C" {
38
39 using CustomDeriveMacro = TokenStream (*) (TokenStream);
40 using AttributeMacro = TokenStream (*) (TokenStream, TokenStream);
41 using BangMacro = TokenStream (*) (TokenStream);
42
43 struct CustomDerive
44 {
45 // TODO: UTF-8 function name
46 const char *trait_name;
47 // TODO: UTF-8 attributes
48 const char **attributes;
49 std::uint64_t attr_size;
50 CustomDeriveMacro macro;
51 };
52
53 struct Attribute
54 {
55 // TODO: UTF-8 function name
56 const char *name;
57 AttributeMacro macro;
58 };
59
60 struct Bang
61 {
62 const char *name;
63 BangMacro macro;
64 };
65 }
66
67 enum ProcmacroTag
68 {
69 CUSTOM_DERIVE = 0,
70 ATTR,
71 BANG,
72 };
73
74 union ProcmacroPayload
75 {
76 CustomDerive custom_derive;
77 Attribute attribute;
78 Bang bang;
79 };
80
81 struct Procmacro
82 {
83 ProcmacroTag tag;
84 ProcmacroPayload payload;
85
86 public:
87 Procmacro make_derive (const char *trait_name, const char **attribute,
88 std::uint64_t size, CustomDeriveMacro macro);
89 Procmacro make_attribute (const char *name, AttributeMacro macro);
90 Procmacro make_bang (const char *name, BangMacro macro);
91 };
92
93 struct ProcmacroArray
94 {
95 std::uint64_t length;
96 Procmacro *macros;
97 };
98
99 extern "C" bool
100 bridge_is_available ();
101
102 } // namespace ProcMacro
103
104 #endif /* ! PROC_MACRO_H */