diff options
author | Vladimir Glavnyy <31897320+vglavnyy@users.noreply.github.com> | 2019-11-26 03:54:59 +0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-11-25 12:54:59 -0800 |
commit | 075e8d676bbea12ca678409f413edbbe90276798 (patch) | |
tree | f5eb04dd847ca1de9ed52b286a8f86af9391b11b /include | |
parent | bcf1bd5c9e87df127f1647867574737e6e1674b0 (diff) | |
download | flatbuffers-075e8d676bbea12ca678409f413edbbe90276798.tar.gz flatbuffers-075e8d676bbea12ca678409f413edbbe90276798.tar.bz2 flatbuffers-075e8d676bbea12ca678409f413edbbe90276798.zip |
Simplify declarations of x-macro FLATBUFFERS_TD (#5638)
Diffstat (limited to 'include')
-rw-r--r-- | include/flatbuffers/idl.h | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 5c7fc11d..4e8f71d3 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -91,6 +91,20 @@ switch (type) { } */ +// If not all FLATBUFFERS_GEN_() arguments are necessary for implementation +// of FLATBUFFERS_TD, you can use a variadic macro (with __VA_ARGS__ if needed). +// In the above example, only CTYPE is used to generate the code, it can be rewritten: + +/* +switch (type) { + #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \ + case BASE_TYPE_ ## ENUM: \ + // do something specific to CTYPE here + FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) + #undef FLATBUFFERS_TD +} +*/ + #define FLATBUFFERS_GEN_TYPES(TD) \ FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ FLATBUFFERS_GEN_TYPES_POINTER(TD) \ @@ -101,17 +115,15 @@ switch (type) { __extension__ // Stop GCC complaining about trailing comma with -Wpendantic. #endif enum BaseType { - #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ - RTYPE, KTYPE) \ - BASE_TYPE_ ## ENUM, + #define FLATBUFFERS_TD(ENUM, ...) \ + BASE_TYPE_ ## ENUM, FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) #undef FLATBUFFERS_TD }; -#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ - RTYPE, KTYPE) \ - static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \ - "define largest_scalar_t as " #CTYPE); +#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, ...) \ + static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \ + "define largest_scalar_t as " #CTYPE); FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) #undef FLATBUFFERS_TD |