diff options
author | Paulo Pinheiro <paulovictor.pinheiro@gmail.com> | 2019-07-22 20:05:15 -0300 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2019-07-22 16:05:15 -0700 |
commit | de9aa0cdee04fb2e73fc956657f89a0e6100a10a (patch) | |
tree | ee87cd850c8b3860d8a99c85b5e246b356750d15 /include/flatbuffers/idl.h | |
parent | a752d1b88c88477a1a8b254683590fa4d1d992d5 (diff) | |
download | flatbuffers-de9aa0cdee04fb2e73fc956657f89a0e6100a10a.tar.gz |
Add basic Kotlin support (#5409)
* [Kotlin] Add kotlin generate code for tests and add
kotlin test to TestAll.sh
* [Kotlin] Add Kotlin generator
This change adds support for generating Kotlin classes.
The approach of this generator is to keep it as close
as possible to the java generator for now, in order
to keep the change simple.
It uses the already implemented java runtime,
so we don't support cross-platform nor js Kotlin yet.
Kotlin tests are just a copy of the java tests.
* Add optional ident support for CodeWriter
Identation is important for some languages and
different projects have different ways of ident
code, e.g. tabs vs spaces, so we are adding optional
support on CodeWriter for identation.
* [Kotlin] Add Documentation for Kotlin
* [Kotlin] Modify generated code to use experimental Unsigned types.
Diffstat (limited to 'include/flatbuffers/idl.h')
-rw-r--r-- | include/flatbuffers/idl.h | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 2ec53919..44e35665 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -47,26 +47,26 @@ namespace flatbuffers { // of type tokens. // clang-format off #define FLATBUFFERS_GEN_TYPES_SCALAR(TD) \ - TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8) \ - TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8) /* begin scalar/int */ \ - TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool) \ - TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8) \ - TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8) \ - TD(SHORT, "short", int16_t, short, int16, short, int16, i16) \ - TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16) \ - TD(INT, "int", int32_t, int, int32, int, int32, i32) \ - TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32) \ - TD(LONG, "long", int64_t, long, int64, long, int64, i64) \ - TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64) /* end int */ \ - TD(FLOAT, "float", float, float, float32, float, float32, f32) /* begin float */ \ - TD(DOUBLE, "double", double, double, float64, double, float64, f64) /* end float/scalar */ + TD(NONE, "", uint8_t, byte, byte, byte, uint8, u8, UByte) \ + TD(UTYPE, "", uint8_t, byte, byte, byte, uint8, u8, UByte) /* begin scalar/int */ \ + TD(BOOL, "bool", uint8_t, boolean,bool, bool, bool, bool, Boolean) \ + TD(CHAR, "byte", int8_t, byte, int8, sbyte, int8, i8, Byte) \ + TD(UCHAR, "ubyte", uint8_t, byte, byte, byte, uint8, u8, UByte) \ + TD(SHORT, "short", int16_t, short, int16, short, int16, i16, Short) \ + TD(USHORT, "ushort", uint16_t, short, uint16, ushort, uint16, u16, UShort) \ + TD(INT, "int", int32_t, int, int32, int, int32, i32, Int) \ + TD(UINT, "uint", uint32_t, int, uint32, uint, uint32, u32, UInt) \ + TD(LONG, "long", int64_t, long, int64, long, int64, i64, Long) \ + TD(ULONG, "ulong", uint64_t, long, uint64, ulong, uint64, u64, ULong) /* end int */ \ + TD(FLOAT, "float", float, float, float32, float, float32, f32, Float) /* begin float */ \ + TD(DOUBLE, "double", double, double, float64, double, float64, f64, Double) /* end float/scalar */ #define FLATBUFFERS_GEN_TYPES_POINTER(TD) \ - TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused) \ - TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused) \ - TD(STRUCT, "", Offset<void>, int, int, int, int, unused) \ - TD(UNION, "", Offset<void>, int, int, int, int, unused) + TD(STRING, "string", Offset<void>, int, int, StringOffset, int, unused, Int) \ + TD(VECTOR, "", Offset<void>, int, int, VectorOffset, int, unused, Int) \ + TD(STRUCT, "", Offset<void>, int, int, int, int, unused, Int) \ + TD(UNION, "", Offset<void>, int, int, int, int, unused, Int) #define FLATBUFFERS_GEN_TYPE_ARRAY(TD) \ - TD(ARRAY, "", int, int, int, int, int, unused) + TD(ARRAY, "", int, int, int, int, int, unused, Int) // The fields are: // - enum // - FlatBuffers schema type. @@ -76,13 +76,14 @@ namespace flatbuffers { // - C# / .Net type. // - Python type. // - Rust type. +// - Kotlin type. // using these macros, we can now write code dealing with types just once, e.g. /* switch (type) { #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ - RTYPE) \ + RTYPE, KTYPE) \ case BASE_TYPE_ ## ENUM: \ // do something specific to CTYPE here FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) @@ -101,14 +102,14 @@ __extension__ // Stop GCC complaining about trailing comma with -Wpendantic. #endif enum BaseType { #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ - RTYPE) \ + RTYPE, KTYPE) \ BASE_TYPE_ ## ENUM, FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) #undef FLATBUFFERS_TD }; #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE, \ - RTYPE) \ + RTYPE, KTYPE) \ static_assert(sizeof(CTYPE) <= sizeof(largest_scalar_t), \ "define largest_scalar_t as " #CTYPE); FLATBUFFERS_GEN_TYPES(FLATBUFFERS_TD) @@ -546,6 +547,7 @@ struct IDLOptions { kLua = 1 << 12, kLobster = 1 << 13, kRust = 1 << 14, + kKotlin = 1 << 15, kMAX }; @@ -1009,6 +1011,9 @@ extern bool GenerateJsonSchema(const Parser &parser, const std::string &path, const std::string &file_name); +extern bool GenerateKotlin(const Parser &parser, const std::string &path, + const std::string &file_name); + // Generate Java/C#/.. files from the definitions in the Parser object. // See idl_gen_general.cpp. extern bool GenerateGeneral(const Parser &parser, |