| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: enum.h,v 1.15 2021/01/30 15:48:42 rillig Exp $ */ | | 1 | /* $NetBSD: enum.h,v 1.16 2021/01/30 15:53:55 rillig Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | Copyright (c) 2020 Roland Illig <rillig@NetBSD.org> | | 4 | Copyright (c) 2020 Roland Illig <rillig@NetBSD.org> |
5 | All rights reserved. | | 5 | All rights reserved. |
6 | | | 6 | |
7 | Redistribution and use in source and binary forms, with or without | | 7 | Redistribution and use in source and binary forms, with or without |
8 | modification, are permitted provided that the following conditions | | 8 | modification, are permitted provided that the following conditions |
9 | are met: | | 9 | are met: |
10 | | | 10 | |
11 | 1. Redistributions of source code must retain the above copyright | | 11 | 1. Redistributions of source code must retain the above copyright |
12 | notice, this list of conditions and the following disclaimer. | | 12 | notice, this list of conditions and the following disclaimer. |
13 | 2. Redistributions in binary form must reproduce the above copyright | | 13 | 2. Redistributions in binary form must reproduce the above copyright |
14 | notice, this list of conditions and the following disclaimer in the | | 14 | notice, this list of conditions and the following disclaimer in the |
| @@ -94,38 +94,38 @@ const char *Enum_ValueToString(int, cons | | | @@ -94,38 +94,38 @@ const char *Enum_ValueToString(int, cons |
94 | #define ENUM__SPECS_2(part1, part2) \ | | 94 | #define ENUM__SPECS_2(part1, part2) \ |
95 | { part1, part2, { 0, "" } } | | 95 | { part1, part2, { 0, "" } } |
96 | #define ENUM__SPECS_3(part1, part2, part3) \ | | 96 | #define ENUM__SPECS_3(part1, part2, part3) \ |
97 | { part1, part2, part3, { 0, "" } } | | 97 | { part1, part2, part3, { 0, "" } } |
98 | #define ENUM__SPECS_4(part1, part2, part3, part4) \ | | 98 | #define ENUM__SPECS_4(part1, part2, part3, part4) \ |
99 | { part1, part2, part3, part4, { 0, "" } } | | 99 | { part1, part2, part3, part4, { 0, "" } } |
100 | #define ENUM__SPECS_5(part1, part2, part3, part4, part5) \ | | 100 | #define ENUM__SPECS_5(part1, part2, part3, part4, part5) \ |
101 | { part1, part2, part3, part4, part5, { 0, "" } } | | 101 | { part1, part2, part3, part4, part5, { 0, "" } } |
102 | | | 102 | |
103 | /* Declare the necessary data structures for calling Enum_ValueToString. */ | | 103 | /* Declare the necessary data structures for calling Enum_ValueToString. */ |
104 | #define ENUM__VALUE_RTTI(typnam, specs) \ | | 104 | #define ENUM__VALUE_RTTI(typnam, specs) \ |
105 | static const EnumToStringSpec typnam ## _ ## ToStringSpecs[] = specs; \ | | 105 | static const EnumToStringSpec typnam ## _ ## ToStringSpecs[] = specs; \ |
106 | MAKE_INLINE const char *typnam ## _ToString(typnam value) \ | | 106 | MAKE_INLINE const char *typnam ## _ToString(typnam value) \ |
107 | { return Enum_ValueToString(value, typnam ## _ ## ToStringSpecs); }; \ | | 107 | { return Enum_ValueToString(value, typnam ## _ ## ToStringSpecs); } \ |
108 | extern void enum_value_rtti_dummy(void) | | 108 | extern void enum_value_rtti_dummy(void) |
109 | | | 109 | |
110 | | | 110 | |
111 | /* Declare the necessary data structures for calling Enum_FlagsToString. */ | | 111 | /* Declare the necessary data structures for calling Enum_FlagsToString. */ |
112 | #define ENUM__FLAGS_RTTI(typnam, specs, joined) \ | | 112 | #define ENUM__FLAGS_RTTI(typnam, specs, joined) \ |
113 | static const EnumToStringSpec typnam ## _ ## ToStringSpecs[] = specs; \ | | 113 | static const EnumToStringSpec typnam ## _ ## ToStringSpecs[] = specs; \ |
114 | enum { typnam ## _ ## ToStringSize = sizeof (joined) }; \ | | 114 | enum { typnam ## _ ## ToStringSize = sizeof (joined) }; \ |
115 | MAKE_INLINE const char *typnam ## _ToString(char *buf, typnam value) \ | | 115 | MAKE_INLINE const char *typnam ## _ToString(char *buf, typnam value) \ |
116 | { return Enum_FlagsToString(buf, typnam ## _ ## ToStringSize, \ | | 116 | { return Enum_FlagsToString(buf, typnam ## _ ## ToStringSize, \ |
117 | value, typnam ## _ ## ToStringSpecs); \ | | 117 | value, typnam ## _ ## ToStringSpecs); \ |
118 | }; \ | | 118 | } \ |
119 | extern void enum_flags_rtti_dummy(void) | | 119 | extern void enum_flags_rtti_dummy(void) |
120 | | | 120 | |
121 | /* | | 121 | /* |
122 | * Declare the necessary data structures for calling Enum_FlagsToString | | 122 | * Declare the necessary data structures for calling Enum_FlagsToString |
123 | * for an enum with 2 flags. | | 123 | * for an enum with 2 flags. |
124 | */ | | 124 | */ |
125 | #define ENUM_FLAGS_RTTI_2(typnam, v1, v2) \ | | 125 | #define ENUM_FLAGS_RTTI_2(typnam, v1, v2) \ |
126 | ENUM__FLAGS_RTTI(typnam, \ | | 126 | ENUM__FLAGS_RTTI(typnam, \ |
127 | ENUM__SPECS_2( \ | | 127 | ENUM__SPECS_2( \ |
128 | ENUM__SPEC_1(v1), \ | | 128 | ENUM__SPEC_1(v1), \ |
129 | ENUM__SPEC_1(v2)), \ | | 129 | ENUM__SPEC_1(v2)), \ |
130 | ENUM__JOIN_2( \ | | 130 | ENUM__JOIN_2( \ |
131 | ENUM__JOIN_STR_1(v1), \ | | 131 | ENUM__JOIN_STR_1(v1), \ |