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.
This commit is contained in:
Paulo Pinheiro
2019-07-22 20:05:15 -03:00
committed by Wouter van Oortmerssen
parent a752d1b88c
commit de9aa0cdee
54 changed files with 4995 additions and 64 deletions

View File

@@ -29,6 +29,8 @@
namespace flatbuffers {
void CodeWriter::operator+=(std::string text) {
if (!ignore_ident_ && !text.empty()) AppendIdent(stream_);
while (true) {
auto begin = text.find("{{");
if (begin == std::string::npos) { break; }
@@ -58,12 +60,21 @@ void CodeWriter::operator+=(std::string text) {
}
if (!text.empty() && string_back(text) == '\\') {
text.pop_back();
ignore_ident_ = true;
stream_ << text;
} else {
ignore_ident_ = false;
stream_ << text << std::endl;
}
}
void CodeWriter::AppendIdent(std::stringstream &stream) {
int lvl = cur_ident_lvl_;
while (lvl--) {
stream.write(pad_.c_str(), static_cast<std::streamsize>(pad_.size()));
}
}
const char *BaseGenerator::FlatBuffersGeneratedWarning() {
return "automatically generated by the FlatBuffers compiler,"
" do not modify";