-
Notifications
You must be signed in to change notification settings - Fork 0
/
pudef.h
206 lines (192 loc) · 4.23 KB
/
pudef.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#ifndef pudef
#error "pudef ain't defined, yall."
#endif
#ifndef NTYPES
#error "pustr.h ain't included, yall."
#endif
#ifndef NPUSTR
/* Want to compute NTYPES + 1 without incrementing NTYPES, as we want to
use pusnprintf (which uses NTYPES) in the old scope while defining the
new. */
#if !NEXTNTYPES
#define NEXTNTYPES 1
#elif NEXTNTYPES == 1
#undef NEXTNTYPES
#define NEXTNTYPES 2
#elif NEXTNTYPES == 2
#undef NEXTNTYPES
#define NEXTNTYPES 3
#elif NEXTNTYPES == 3
#undef NEXTNTYPES
#define NEXTNTYPES 4
#elif NEXTNTYPES == 4
#undef NEXTNTYPES
#define NEXTNTYPES 5
#elif NEXTNTYPES == 5
#undef NEXTNTYPES
#define NEXTNTYPES 6
#elif NEXTNTYPES == 6
#undef NEXTNTYPES
#define NEXTNTYPES 7
#elif NEXTNTYPES == 7
#undef NEXTNTYPES
#define NEXTNTYPES 8
#elif NEXTNTYPES == 8
#undef NEXTNTYPES
#define NEXTNTYPES 9
#elif NEXTNTYPES == 9
#undef NEXTNTYPES
#define NEXTNTYPES 10
#elif NEXTNTYPES == 10
#undef NEXTNTYPES
#define NEXTNTYPES 11
#elif NEXTNTYPES == 11
#undef NEXTNTYPES
#define NEXTNTYPES 12
#elif NEXTNTYPES == 12
#undef NEXTNTYPES
#define NEXTNTYPES 13
#elif NEXTNTYPES == 13
#undef NEXTNTYPES
#define NEXTNTYPES 14
#elif NEXTNTYPES == 14
#undef NEXTNTYPES
#define NEXTNTYPES 15
#elif NEXTNTYPES == 15
#undef NEXTNTYPES
#define NEXTNTYPES 16
#elif NEXTNTYPES == 16
#undef NEXTNTYPES
#define NEXTNTYPES 17
#elif NEXTNTYPES == 17
#undef NEXTNTYPES
#define NEXTNTYPES 18
#elif NEXTNTYPES == 18
#undef NEXTNTYPES
#define NEXTNTYPES 19
#elif NEXTNTYPES == 19
#undef NEXTNTYPES
#define NEXTNTYPES 20
#elif NEXTNTYPES == 20
#undef NEXTNTYPES
#define NEXTNTYPES 21
#elif NEXTNTYPES == 21
#undef NEXTNTYPES
#define NEXTNTYPES 22
#elif NEXTNTYPES == 22
#undef NEXTNTYPES
#define NEXTNTYPES 23
#elif NEXTNTYPES == 23
#undef NEXTNTYPES
#define NEXTNTYPES 24
#elif NEXTNTYPES == 24
#undef NEXTNTYPES
#define NEXTNTYPES 25
#else
#error "So many types! Too many to count!"
#endif /* NEXTNTYPES */
#define PU_FIRST(a, ...) a
#define PU_SECOND(_, a, ...) a
#define PU_TAIL(_, __, a...) a
#define PU_T(d) PU_FIRST d
#define PU_FMT(d) PU_SECOND d
#define PU_FARGS(d) PU_TAIL d
typedef PU_T(pudef) PU_CONCAT(putype_, NEXTNTYPES);
static
size_t PU_CONCAT(pusnprint_, NEXTNTYPES)
(char *b, size_t l, const PU_T(pudef) *a){
return pusnprintf(b, l, PU_FMT(pudef), PU_FARGS(pudef));
}
static
size_t PU_CONCAT(pusnprint_ptr_, NEXTNTYPES)
(char *b, size_t l, const PU_T(pudef) *const *apt){
const PU_T(pudef) *a = *apt;
if(!a)
return pusnprint_ptr_char(b, l, (const char*[]){(char *) "<nil>"});
return pusnprintf(b, l, "%:&"PU_FMT(pudef),
(const void *) a, PU_FARGS(pudef));
}
/* static size_t CONCAT(pusnprint_, NEXTNTYPES) */
/* (char *b, size_t l, volatile const PU_T(pudef) *a) */
/* __attribute__((alias(STRLIT(CONCAT(pusnprint_, PU_T(pudef)))))); */
/* static size_t CONCAT(pusnprint_ptr_, NEXTNTYPES) */
/* (char *b, size_t l, volatile const PU_T(pudef) **apt) */
/* __attribute__((alias(STRLIT(CONCAT(pusnprint_ptr_, PU_T(pudef)))))); */
#if !NTYPES
#undef NTYPES
#define NTYPES 1
#elif NTYPES == 1
#undef NTYPES
#define NTYPES 2
#elif NTYPES == 2
#undef NTYPES
#define NTYPES 3
#elif NTYPES == 3
#undef NTYPES
#define NTYPES 4
#elif NTYPES == 4
#undef NTYPES
#define NTYPES 5
#elif NTYPES == 5
#undef NTYPES
#define NTYPES 6
#elif NTYPES == 6
#undef NTYPES
#define NTYPES 7
#elif NTYPES == 7
#undef NTYPES
#define NTYPES 8
#elif NTYPES == 8
#undef NTYPES
#define NTYPES 9
#elif NTYPES == 9
#undef NTYPES
#define NTYPES 10
#elif NTYPES == 10
#undef NTYPES
#define NTYPES 11
#elif NTYPES == 11
#undef NTYPES
#define NTYPES 12
#elif NTYPES == 12
#undef NTYPES
#define NTYPES 13
#elif NTYPES == 13
#undef NTYPES
#define NTYPES 14
#elif NTYPES == 14
#undef NTYPES
#define NTYPES 15
#elif NTYPES == 15
#undef NTYPES
#define NTYPES 16
#elif NTYPES == 16
#undef NTYPES
#define NTYPES 17
#elif NTYPES == 17
#undef NTYPES
#define NTYPES 18
#elif NTYPES == 18
#undef NTYPES
#define NTYPES 19
#elif NTYPES == 19
#undef NTYPES
#define NTYPES 20
#elif NTYPES == 20
#undef NTYPES
#define NTYPES 21
#elif NTYPES == 21
#undef NTYPES
#define NTYPES 22
#elif NTYPES == 22
#undef NTYPES
#define NTYPES 23
#elif NTYPES == 23
#undef NTYPES
#define NTYPES 24
#elif NTYPES == 24
#undef NTYPES
#define NTYPES 25
#endif /* NTYPES */
#endif /* NPUSTR */
#undef pudef