Skip to content

Commit

Permalink
Merge branch 'master' into upgrade-rules-go
Browse files Browse the repository at this point in the history
  • Loading branch information
le-michael authored Sep 20, 2023
2 parents 179993d + 5d4386b commit f985628
Show file tree
Hide file tree
Showing 14 changed files with 405 additions and 405 deletions.
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file"

http_archive(
name = "platforms",
sha256 = "379113459b0feaf6bfbb584a91874c065078aa673222846ac765f86661c27407",
sha256 = "3a561c99e7bdbe9173aa653fd579fe849f1d8d67395780ab4770b1f381431d51",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.5/platforms-0.0.5.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz",
"https://github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz",
],
)

Expand Down
2 changes: 1 addition & 1 deletion grpc/examples/go/greeter/server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ replace github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0 =>
require (
github.com/google/flatbuffers v1.12.0
github.com/google/flatbuffers/grpc/examples/go/greeter/models v0.0.0
google.golang.org/grpc v1.39.0-dev
google.golang.org/grpc v1.53.0
)
2 changes: 1 addition & 1 deletion include/flatbuffers/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ namespace flatbuffers {
#define FLATBUFFERS_FINAL_CLASS final
#define FLATBUFFERS_OVERRIDE override
#define FLATBUFFERS_EXPLICIT_CPP11 explicit
#define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : flatbuffers::voffset_t
#define FLATBUFFERS_VTABLE_UNDERLYING_TYPE : ::flatbuffers::voffset_t
#else
#define FLATBUFFERS_FINAL_CLASS
#define FLATBUFFERS_OVERRIDE
Expand Down
80 changes: 40 additions & 40 deletions samples/monster_generated.lobster
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// automatically generated by the FlatBuffers compiler, do not modify
import flatbuffers

namespace MyGame_Sample
namespace MyGame.Sample

enum Color:
Color_Red = 0
Expand All @@ -18,58 +18,58 @@ class Monster

class Weapon

class Vec3 : flatbuffers_handle
class Vec3 : flatbuffers.handle
def x() -> float:
return buf_.read_float32_le(pos_ + 0)
def y() -> float:
return buf_.read_float32_le(pos_ + 4)
def z() -> float:
return buf_.read_float32_le(pos_ + 8)

def CreateVec3(b_:flatbuffers_builder, x:float, y:float, z:float):
def CreateVec3(b_:flatbuffers.builder, x:float, y:float, z:float):
b_.Prep(4, 12)
b_.PrependFloat32(z)
b_.PrependFloat32(y)
b_.PrependFloat32(x)
return b_.Offset()

class Monster : flatbuffers_handle
def pos() -> MyGame_Sample_Vec3?:
let o = buf_.flatbuffers_field_struct(pos_, 4)
return if o: MyGame_Sample_Vec3 { buf_, o } else: nil
class Monster : flatbuffers.handle
def pos() -> MyGame.Sample.Vec3?:
let o = flatbuffers.field_struct(buf_, pos_, 4)
return if o: MyGame.Sample.Vec3 { buf_, o } else: nil
def mana() -> int:
return buf_.flatbuffers_field_int16(pos_, 6, 150)
return flatbuffers.field_int16(buf_, pos_, 6, 150)
def hp() -> int:
return buf_.flatbuffers_field_int16(pos_, 8, 100)
return flatbuffers.field_int16(buf_, pos_, 8, 100)
def name() -> string:
return buf_.flatbuffers_field_string(pos_, 10)
return flatbuffers.field_string(buf_, pos_, 10)
def inventory(i:int) -> int:
return buf_.read_uint8_le(buf_.flatbuffers_field_vector(pos_, 14) + i * 1)
return read_uint8_le(buf_, buf_.flatbuffers.field_vector(pos_, 14) + i * 1)
def inventory_length() -> int:
return buf_.flatbuffers_field_vector_len(pos_, 14)
return flatbuffers.field_vector_len(buf_, pos_, 14)
def color() -> Color:
return Color(buf_.flatbuffers_field_int8(pos_, 16, 2))
def weapons(i:int) -> MyGame_Sample_Weapon:
return MyGame_Sample_Weapon { buf_, buf_.flatbuffers_indirect(buf_.flatbuffers_field_vector(pos_, 18) + i * 4) }
return Color(flatbuffers.field_int8(buf_, pos_, 16, 2))
def weapons(i:int) -> MyGame.Sample.Weapon:
return MyGame.Sample.Weapon { buf_, flatbuffers.indirect(buf_, flatbuffers.field_vector(buf_, pos_, 18) + i * 4) }
def weapons_length() -> int:
return buf_.flatbuffers_field_vector_len(pos_, 18)
return flatbuffers.field_vector_len(buf_, pos_, 18)
def equipped_type() -> Equipment:
return Equipment(buf_.flatbuffers_field_uint8(pos_, 20, 0))
return Equipment(flatbuffers.field_uint8(buf_, pos_, 20, 0))
def equipped_as_Weapon():
return MyGame_Sample_Weapon { buf_, buf_.flatbuffers_field_table(pos_, 22) }
def path(i:int) -> MyGame_Sample_Vec3:
return MyGame_Sample_Vec3 { buf_, buf_.flatbuffers_field_vector(pos_, 24) + i * 12 }
return MyGame.Sample.Weapon { buf_, flatbuffers.field_table(buf_, pos_, 22) }
def path(i:int) -> MyGame.Sample.Vec3:
return MyGame.Sample.Vec3 { buf_, flatbuffers.field_vector(buf_, pos_, 24) + i * 12 }
def path_length() -> int:
return buf_.flatbuffers_field_vector_len(pos_, 24)
return flatbuffers.field_vector_len(buf_, pos_, 24)

def GetRootAsMonster(buf:string): return Monster { buf, buf.flatbuffers_indirect(0) }
def GetRootAsMonster(buf:string): return Monster { buf, flatbuffers.indirect(buf, 0) }

struct MonsterBuilder:
b_:flatbuffers_builder
b_:flatbuffers.builder
def start():
b_.StartObject(11)
return this
def add_pos(pos:flatbuffers_offset):
def add_pos(pos:flatbuffers.offset):
b_.PrependStructSlot(0, pos)
return this
def add_mana(mana:int):
Expand All @@ -78,61 +78,61 @@ struct MonsterBuilder:
def add_hp(hp:int):
b_.PrependInt16Slot(2, hp, 100)
return this
def add_name(name:flatbuffers_offset):
def add_name(name:flatbuffers.offset):
b_.PrependUOffsetTRelativeSlot(3, name)
return this
def add_inventory(inventory:flatbuffers_offset):
def add_inventory(inventory:flatbuffers.offset):
b_.PrependUOffsetTRelativeSlot(5, inventory)
return this
def add_color(color:Color):
b_.PrependInt8Slot(6, color, 2)
return this
def add_weapons(weapons:flatbuffers_offset):
def add_weapons(weapons:flatbuffers.offset):
b_.PrependUOffsetTRelativeSlot(7, weapons)
return this
def add_equipped_type(equipped_type:Equipment):
b_.PrependUint8Slot(8, equipped_type, 0)
return this
def add_equipped(equipped:flatbuffers_offset):
def add_equipped(equipped:flatbuffers.offset):
b_.PrependUOffsetTRelativeSlot(9, equipped)
return this
def add_path(path:flatbuffers_offset):
def add_path(path:flatbuffers.offset):
b_.PrependUOffsetTRelativeSlot(10, path)
return this
def end():
return b_.EndObject()

def MonsterStartInventoryVector(b_:flatbuffers_builder, n_:int):
def MonsterStartInventoryVector(b_:flatbuffers.builder, n_:int):
b_.StartVector(1, n_, 1)
def MonsterCreateInventoryVector(b_:flatbuffers_builder, v_:[int]):
def MonsterCreateInventoryVector(b_:flatbuffers.builder, v_:[int]):
b_.StartVector(1, v_.length, 1)
reverse(v_) e_: b_.PrependUint8(e_)
return b_.EndVector(v_.length)

def MonsterStartWeaponsVector(b_:flatbuffers_builder, n_:int):
def MonsterStartWeaponsVector(b_:flatbuffers.builder, n_:int):
b_.StartVector(4, n_, 4)
def MonsterCreateWeaponsVector(b_:flatbuffers_builder, v_:[flatbuffers_offset]):
def MonsterCreateWeaponsVector(b_:flatbuffers.builder, v_:[flatbuffers.offset]):
b_.StartVector(4, v_.length, 4)
reverse(v_) e_: b_.PrependUOffsetTRelative(e_)
return b_.EndVector(v_.length)

def MonsterStartPathVector(b_:flatbuffers_builder, n_:int):
def MonsterStartPathVector(b_:flatbuffers.builder, n_:int):
b_.StartVector(12, n_, 4)

class Weapon : flatbuffers_handle
class Weapon : flatbuffers.handle
def name() -> string:
return buf_.flatbuffers_field_string(pos_, 4)
return flatbuffers.field_string(buf_, pos_, 4)
def damage() -> int:
return buf_.flatbuffers_field_int16(pos_, 6, 0)
return flatbuffers.field_int16(buf_, pos_, 6, 0)

def GetRootAsWeapon(buf:string): return Weapon { buf, buf.flatbuffers_indirect(0) }
def GetRootAsWeapon(buf:string): return Weapon { buf, flatbuffers.indirect(buf, 0) }

struct WeaponBuilder:
b_:flatbuffers_builder
b_:flatbuffers.builder
def start():
b_.StartObject(2)
return this
def add_name(name:flatbuffers_offset):
def add_name(name:flatbuffers.offset):
b_.PrependUOffsetTRelativeSlot(0, name)
return this
def add_damage(damage:int):
Expand Down
1 change: 0 additions & 1 deletion src/bfbs_gen_nim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ Namer::Config NimDefaultConfig() {
/*filename_extension=*/".nim" };
}

const std::string Indent = " ";
const std::string Export = "*";
const std::set<std::string> builtin_types = {
"uint8", "uint8", "bool", "int8", "uint8", "int16",
Expand Down
46 changes: 24 additions & 22 deletions src/idl_gen_lobster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LobsterGenerator : public BaseGenerator {
public:
LobsterGenerator(const Parser &parser, const std::string &path,
const std::string &file_name)
: BaseGenerator(parser, path, file_name, "" /* not used */, "_",
: BaseGenerator(parser, path, file_name, "" /* not used */, ".",
"lobster") {
static const char *const keywords[] = {
"nil", "true", "false", "return", "struct", "class",
Expand Down Expand Up @@ -79,7 +79,7 @@ class LobsterGenerator : public BaseGenerator {
if (IsBool(type.base_type)) return "bool";
if (IsScalar(type.base_type) && type.enum_def)
return NormalizedName(*type.enum_def);
if (!IsScalar(type.base_type)) return "flatbuffers_offset";
if (!IsScalar(type.base_type)) return "flatbuffers.offset";
if (IsString(type)) return "string";
return "int";
}
Expand Down Expand Up @@ -119,15 +119,17 @@ class LobsterGenerator : public BaseGenerator {
offsets + ")";

} else {
auto defval = field.IsOptional() ? "0" : field.value.constant;
acc = "buf_.flatbuffers_field_" + GenTypeName(field.value.type) +
"(pos_, " + offsets + ", " + defval + ")";
auto defval = field.IsOptional()
? (IsFloat(field.value.type.base_type) ? "0.0" : "0")
: field.value.constant;
acc = "flatbuffers.field_" + GenTypeName(field.value.type) +
"(buf_, pos_, " + offsets + ", " + defval + ")";
if (IsBool(field.value.type.base_type)) acc = "bool(" + acc + ")";
}
if (field.value.type.enum_def)
acc = NormalizedName(*field.value.type.enum_def) + "(" + acc + ")";
if (field.IsOptional()) {
acc += ", buf_.flatbuffers_field_present(pos_, " + offsets + ")";
acc += ", flatbuffers.field_present(buf_, pos_, " + offsets + ")";
code += def + "() -> " + LobsterType(field.value.type) +
", bool:\n return " + acc + "\n";
} else {
Expand All @@ -144,26 +146,26 @@ class LobsterGenerator : public BaseGenerator {
code += "return " + name + "{ buf_, pos_ + " + offsets + " }\n";
} else {
code += def + "() -> " + name + "?:\n ";
code += std::string("let o = buf_.flatbuffers_field_") +
code += std::string("let o = flatbuffers.field_") +
(field.value.type.struct_def->fixed ? "struct" : "table") +
"(pos_, " + offsets + ")\n return if o: " + name +
"(buf_, pos_, " + offsets + ")\n return if o: " + name +
" { buf_, o } else: nil\n";
}
break;
}
case BASE_TYPE_STRING:
code += def +
"() -> string:\n return "
"buf_.flatbuffers_field_string(pos_, " +
"flatbuffers.field_string(buf_, pos_, " +
offsets + ")\n";
break;
case BASE_TYPE_VECTOR: {
auto vectortype = field.value.type.VectorType();
if (vectortype.base_type == BASE_TYPE_STRUCT) {
auto start = "buf_.flatbuffers_field_vector(pos_, " + offsets +
auto start = "flatbuffers.field_vector(buf_, pos_, " + offsets +
") + i * " + NumToString(InlineSize(vectortype));
if (!(vectortype.struct_def->fixed)) {
start = "buf_.flatbuffers_indirect(" + start + ")";
start = "flatbuffers.indirect(buf_, " + start + ")";
}
code += def + "(i:int) -> " +
NamespacedName(*field.value.type.struct_def) +
Expand All @@ -173,13 +175,13 @@ class LobsterGenerator : public BaseGenerator {
} else {
if (IsString(vectortype)) {
code += def + "(i:int) -> string:\n return ";
code += "buf_.flatbuffers_string";
code += "flatbuffers.string";
} else {
code += def + "(i:int) -> " + LobsterType(vectortype) +
":\n return ";
code += "buf_.read_" + GenTypeName(vectortype) + "_le";
code += "read_" + GenTypeName(vectortype) + "_le";
}
code += "(buf_.flatbuffers_field_vector(pos_, " + offsets +
code += "(buf_, buf_.flatbuffers.field_vector(pos_, " + offsets +
") + i * " + NumToString(InlineSize(vectortype)) + ")\n";
}
break;
Expand All @@ -191,7 +193,7 @@ class LobsterGenerator : public BaseGenerator {
if (ev.IsNonZero()) {
code += def + "_as_" + ev.name + "():\n return " +
NamespacedName(*ev.union_type.struct_def) +
" { buf_, buf_.flatbuffers_field_table(pos_, " + offsets +
" { buf_, flatbuffers.field_table(buf_, pos_, " + offsets +
") }\n";
}
}
Expand All @@ -202,7 +204,7 @@ class LobsterGenerator : public BaseGenerator {
if (IsVector(field.value.type)) {
code += def +
"_length() -> int:\n return "
"buf_.flatbuffers_field_vector_len(pos_, " +
"flatbuffers.field_vector_len(buf_, pos_, " +
offsets + ")\n";
}
}
Expand All @@ -211,7 +213,7 @@ class LobsterGenerator : public BaseGenerator {
void GenTableBuilders(const StructDef &struct_def, std::string *code_ptr) {
std::string &code = *code_ptr;
code += "struct " + NormalizedName(struct_def) +
"Builder:\n b_:flatbuffers_builder\n";
"Builder:\n b_:flatbuffers.builder\n";
code += " def start():\n b_.StartObject(" +
NumToString(struct_def.fields.vec.size()) +
")\n return this\n";
Expand All @@ -236,7 +238,7 @@ class LobsterGenerator : public BaseGenerator {
if (IsVector(field.value.type)) {
code += "def " + NormalizedName(struct_def) + "Start" +
ConvertCase(NormalizedName(field), Case::kUpperCamel) +
"Vector(b_:flatbuffers_builder, n_:int):\n b_.StartVector(";
"Vector(b_:flatbuffers.builder, n_:int):\n b_.StartVector(";
auto vector_type = field.value.type.VectorType();
auto alignment = InlineAlignment(vector_type);
auto elem_size = InlineSize(vector_type);
Expand All @@ -246,7 +248,7 @@ class LobsterGenerator : public BaseGenerator {
!vector_type.struct_def->fixed) {
code += "def " + NormalizedName(struct_def) + "Create" +
ConvertCase(NormalizedName(field), Case::kUpperCamel) +
"Vector(b_:flatbuffers_builder, v_:[" +
"Vector(b_:flatbuffers.builder, v_:[" +
LobsterType(vector_type) + "]):\n b_.StartVector(" +
NumToString(elem_size) + ", v_.length, " +
NumToString(alignment) + ")\n reverse(v_) e_: b_.Prepend" +
Expand All @@ -271,7 +273,7 @@ class LobsterGenerator : public BaseGenerator {
std::string &code = *code_ptr;
CheckNameSpace(struct_def, &code);
GenComment(struct_def.doc_comment, code_ptr, nullptr, "");
code += "class " + NormalizedName(struct_def) + " : flatbuffers_handle\n";
code += "class " + NormalizedName(struct_def) + " : flatbuffers.handle\n";
for (auto it = struct_def.fields.vec.begin();
it != struct_def.fields.vec.end(); ++it) {
auto &field = **it;
Expand All @@ -284,7 +286,7 @@ class LobsterGenerator : public BaseGenerator {
// the root type.
code += "def GetRootAs" + NormalizedName(struct_def) +
"(buf:string): return " + NormalizedName(struct_def) +
" { buf, buf.flatbuffers_indirect(0) }\n\n";
" { buf, flatbuffers.indirect(buf, 0) }\n\n";
}
if (struct_def.fixed) {
// create a struct constructor function
Expand Down Expand Up @@ -360,7 +362,7 @@ class LobsterGenerator : public BaseGenerator {
void GenStructBuilder(const StructDef &struct_def, std::string *code_ptr) {
std::string &code = *code_ptr;
code +=
"def Create" + NormalizedName(struct_def) + "(b_:flatbuffers_builder";
"def Create" + NormalizedName(struct_def) + "(b_:flatbuffers.builder";
StructBuilderArgs(struct_def, "", code_ptr);
code += "):\n";
StructBuilderBody(struct_def, "", code_ptr);
Expand Down
6 changes: 1 addition & 5 deletions src/idl_gen_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2000,11 +2000,7 @@ class TsGenerator : public BaseGenerator {
if (!IsScalar(field.value.type.base_type)) {
code += "0";
} else if (HasNullDefault(field)) {
if (IsLong(field.value.type.base_type)) {
code += "BigInt(0)";
} else {
code += "0";
}
code += "null";
} else {
if (field.value.type.base_type == BASE_TYPE_BOOL) { code += "+"; }
code += GenDefaultValue(field, imports);
Expand Down
3 changes: 3 additions & 0 deletions tests/LobsterTest.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
..\Release\flatc.exe --lobster -I include_test monster_test.fbs
..\Release\flatc.exe --lobster -I include_test optional_scalars.fbs
..\..\lobster\bin\lobster.exe .\lobstertest.lobster
Loading

0 comments on commit f985628

Please sign in to comment.