mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 20:31:11 +00:00
explicitly declare enum values (#7811)
This commit is contained in:
@@ -45,26 +45,26 @@ namespace flatbuffers {
|
|||||||
// of type tokens.
|
// of type tokens.
|
||||||
// clang-format off
|
// clang-format off
|
||||||
#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
|
#define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \
|
||||||
TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \
|
TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 0) \
|
||||||
TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) /* begin scalar/int */ \
|
TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 1) /* begin scalar/int */ \
|
||||||
TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool) \
|
TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean, Bool, 2) \
|
||||||
TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte, Int8) \
|
TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte, Int8, 3) \
|
||||||
TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8) \
|
TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte, UInt8, 4) \
|
||||||
TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short, Int16) \
|
TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short, Int16, 5) \
|
||||||
TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort, UInt16) \
|
TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort, UInt16, 6) \
|
||||||
TD(INT, "int", int32_t, int, int32, int, int32, i32, Int, Int32) \
|
TD(INT, "int", int32_t, int, int32, int, int32, i32, Int, Int32, 7) \
|
||||||
TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt, UInt32) \
|
TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt, UInt32, 8) \
|
||||||
TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long, Int64) \
|
TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long, Int64, 9) \
|
||||||
TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64) /* end int */ \
|
TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong, UInt64, 10) /* end int */ \
|
||||||
TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32) /* begin float */ \
|
TD(FLOAT, "float", float, float, float32, float, float32, f32, Float, Float32, 11) /* begin float */ \
|
||||||
TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double) /* end float/scalar */
|
TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double, Double, 12) /* end float/scalar */
|
||||||
#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
|
#define FLATBUFFERS_GEN_TYPES_POINTER(TD) \
|
||||||
TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int, Offset<String>) \
|
TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int, Offset<String>, 13) \
|
||||||
TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>) \
|
TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int, Offset<UOffset>, 14) \
|
||||||
TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>) \
|
TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>, 15) \
|
||||||
TD(UNION, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>)
|
TD(UNION, "", Offset<void>, int, int, int, int, unused, Int, Offset<UOffset>, 16)
|
||||||
#define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \
|
#define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \
|
||||||
TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>)
|
TD(ARRAY, "", int, int, int, int, int, unused, Int, Offset<UOffset>, 17)
|
||||||
// The fields are:
|
// The fields are:
|
||||||
// - enum
|
// - enum
|
||||||
// - FlatBuffers schema type.
|
// - FlatBuffers schema type.
|
||||||
@@ -75,13 +75,15 @@ namespace flatbuffers {
|
|||||||
// - Python type.
|
// - Python type.
|
||||||
// - Kotlin type.
|
// - Kotlin type.
|
||||||
// - Rust type.
|
// - Rust type.
|
||||||
|
// - Swift type.
|
||||||
|
// - enum value (matches the reflected values)
|
||||||
|
|
||||||
// using these macros, we can now write code dealing with types just once, e.g.
|
// using these macros, we can now write code dealing with types just once, e.g.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
switch (type) {
|
switch (type) {
|
||||||
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \
|
#define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \
|
||||||
RTYPE, KTYPE) \
|
RTYPE, KTYPE, STYPE, ...) \
|
||||||
case BASE_TYPE_ ## ENUM: \
|
case BASE_TYPE_ ## ENUM: \
|
||||||
// do something specific to CTYPE here
|
// do something specific to CTYPE here
|
||||||
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
||||||
@@ -113,8 +115,9 @@ switch (type) {
|
|||||||
__extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
|
__extension__ // Stop GCC complaining about trailing comma with -Wpendantic.
|
||||||
#endif
|
#endif
|
||||||
enum BaseType {
|
enum BaseType {
|
||||||
#define FLATBUFFERS_TD(ENUM, ...) \
|
#define FLATBUFFERS_TD(ENUM, IDLTYPE, \
|
||||||
BASE_TYPE_ ## ENUM,
|
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE, ENUM_VALUE) \
|
||||||
|
BASE_TYPE_ ## ENUM = ENUM_VALUE,
|
||||||
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
||||||
#undef FLATBUFFERS_TD
|
#undef FLATBUFFERS_TD
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1881,7 +1881,7 @@ class SwiftGenerator : public BaseGenerator {
|
|||||||
// clang-format off
|
// clang-format off
|
||||||
static const char * const swift_type[] = {
|
static const char * const swift_type[] = {
|
||||||
#define FLATBUFFERS_TD(ENUM, IDLTYPE, \
|
#define FLATBUFFERS_TD(ENUM, IDLTYPE, \
|
||||||
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE) \
|
CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, RTYPE, KTYPE, STYPE, ...) \
|
||||||
#STYPE,
|
#STYPE,
|
||||||
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD)
|
||||||
#undef FLATBUFFERS_TD
|
#undef FLATBUFFERS_TD
|
||||||
|
|||||||
Reference in New Issue
Block a user