Debian Codegraph @

src/imagination/pco/usclib/pp_macros.h

raw
1 /*
2 * Copyright © 2025 Imagination Technologies Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef PCO_PP_MACROS_H
7 #define PCO_PP_MACROS_H
8
9 #define _NUM_ARGS(_0, \
10 _1, \
11 _2, \
12 _3, \
13 _4, \
14 _5, \
15 _6, \
16 _7, \
17 _8, \
18 _9, \
19 _10, \
20 _11, \
21 _12, \
22 _13, \
23 _14, \
24 _15, \
25 _16, \
26 N, \
27 ...) \
28 N
29
30 /* Returns the numbers of arguments passed to the macro. */
31 #define NUM_ARGS(...) \
32 _NUM_ARGS(_, \
33 ##__VA_ARGS__, \
34 16, \
35 15, \
36 14, \
37 13, \
38 12, \
39 11, \
40 10, \
41 9, \
42 8, \
43 7, \
44 6, \
45 5, \
46 4, \
47 3, \
48 2, \
49 1, \
50 0)
51
52 /* Returns the numbers of arguments passed to the macro + 2. */
53 #define NUM_ARGS_PLUS_2(...) \
54 _NUM_ARGS(_, \
55 ##__VA_ARGS__, \
56 18, \
57 17, \
58 16, \
59 15, \
60 14, \
61 13, \
62 12, \
63 11, \
64 10, \
65 9, \
66 8, \
67 7, \
68 6, \
69 5, \
70 4, \
71 3, \
72 2)
73
74 #define _CAT2(a, b) a##b
75
76 /* Concatenates two tokens. */
77 #define CAT2(a, b) _CAT2(a, b)
78
79 #define _CAT3(a, b, c) a##b##c
80
81 /* Concatenates three tokens. */
82 #define CAT3(a, b, c) _CAT3(a, b, c)
83
84 /* Constructs a function name from its base name, separator, and the number of
85 * args passed to it.
86 */
87 #define SELECT_NAME(f, sep, ...) CAT3(f, sep, NUM_ARGS(__VA_ARGS__))
88
89 #endif /* ifndef PCO_PP_MACROS_H */