Skip to content

Commit

Permalink
Update flatbuffers dependency to the latest.
Browse files Browse the repository at this point in the history
  • Loading branch information
liuliu committed Jun 10, 2022
1 parent 0139d00 commit 432407d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 32 deletions.
2 changes: 1 addition & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ swift_library(
srcs = ["//src:DflatFiles"],
module_name = "Dflat",
deps = [
"@flatbuffers//:FlatBuffers",
"@flatbuffers//swift",
"@swift-atomics//:SwiftAtomics",
],
)
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import PackageDescription
var dependencies: [Package.Dependency] = [
.package(
name: "FlatBuffers", url: "https://github.com/mustiikhalil/flatbuffers.git",
.revision("7d043834fd9e1dc0dcc2a5bea2852210433b597a")),
.revision("b52c73460318ab1fef4a68913c9870eb2c2dd5a7")),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.1"),
.package(
name: "SQLite3", url: "https://github.com/liuliu/swift-sqlite3-support.git", from: "3.38.5"),
Expand All @@ -17,7 +17,7 @@ import PackageDescription
var dependencies: [Package.Dependency] = [
.package(
name: "FlatBuffers", url: "https://github.com/mustiikhalil/flatbuffers.git",
.revision("7d043834fd9e1dc0dcc2a5bea2852210433b597a")),
.revision("b52c73460318ab1fef4a68913c9870eb2c2dd5a7")),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.1"),
]
let sqliteDflatDependencies: [Target.Dependency] = ["Dflat", "_SQLiteDflatOSShim"]
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ git_repository(
new_git_repository(
name = "flatbuffers",
build_file = "flatbuffers.BUILD",
commit = "354d97f6da18cbbdeddfcdd2d5aebf1bcc57a092",
commit = "11a19887053534c43f73e74786b46a615ecbf28e",
remote = "https://github.com/google/flatbuffers.git",
shallow_since = "1632261689 -0700",
shallow_since = "1654463045 +0200",
)

new_git_repository(
Expand Down
45 changes: 35 additions & 10 deletions external/flatbuffers.BUILD
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
licenses(["notice"])

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")

licenses(["notice"])

package(
default_visibility = ["//visibility:public"],
)

exports_files([
"LICENSE",
"tsconfig.json",
])

config_setting(
name = "platform_freebsd",
constraint_values = [
"@platforms//os:freebsd",
],
)

config_setting(
name = "platform_openbsd",
constraint_values = [
"@platforms//os:openbsd",
],
)

# Public flatc library to compile flatbuffer files at runtime.
cc_library(
name = "flatbuffers",
Expand All @@ -24,18 +38,34 @@ cc_library(
filegroup(
name = "public_headers",
srcs = [
"include/flatbuffers/allocator.h",
"include/flatbuffers/array.h",
"include/flatbuffers/base.h",
"include/flatbuffers/bfbs_generator.h",
"include/flatbuffers/buffer.h",
"include/flatbuffers/buffer_ref.h",
"include/flatbuffers/code_generators.h",
"include/flatbuffers/default_allocator.h",
"include/flatbuffers/detached_buffer.h",
"include/flatbuffers/flatbuffer_builder.h",
"include/flatbuffers/flatbuffers.h",
"include/flatbuffers/flex_flat_util.h",
"include/flatbuffers/flexbuffers.h",
"include/flatbuffers/grpc.h",
"include/flatbuffers/hash.h",
"include/flatbuffers/idl.h",
"include/flatbuffers/minireflect.h",
"include/flatbuffers/reflection.h",
"include/flatbuffers/reflection_generated.h",
"include/flatbuffers/registry.h",
"include/flatbuffers/stl_emulation.h",
"include/flatbuffers/string.h",
"include/flatbuffers/struct.h",
"include/flatbuffers/table.h",
"include/flatbuffers/util.h",
"include/flatbuffers/vector.h",
"include/flatbuffers/vector_downward.h",
"include/flatbuffers/verifier.h",
],
)

Expand All @@ -51,7 +81,6 @@ cc_library(
# Public flatc compiler.
cc_library(
name = "flatc",
linkopts = ["-lm"],
deps = [
"//src:flatc",
],
Expand All @@ -74,13 +103,9 @@ cc_library(
"include/flatbuffers/flexbuffers.h",
"include/flatbuffers/stl_emulation.h",
"include/flatbuffers/util.h",
"include/flatbuffers/vector.h",
"include/flatbuffers/verifier.h",
],
linkstatic = 1,
strip_include_prefix = "/include",
)

swift_library(
name = "FlatBuffers",
srcs = glob(["swift/Sources/FlatBuffers/*.swift"]),
module_name = "FlatBuffers",
)
5 changes: 4 additions & 1 deletion src/parser/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ package(
cc_binary(
name = "dflats",
srcs = ["dflats.cpp"],
deps = ["@flatbuffers//:flatc"],
deps = [
"@flatbuffers",
"@flatbuffers//:flatc",
],
)

swift_binary(
Expand Down
32 changes: 16 additions & 16 deletions src/parser/dflats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,31 @@ static const char *idl_types[] = {

const std::string GenJSONType(const flatbuffers::Type &type) {
if (type.base_type == flatbuffers::BASE_TYPE_STRUCT) {
return std::string("{\"type\": \"struct\", \"struct\": \"") + type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.struct_def->name, false)) + "\"}";
return std::string("{\"type\": \"struct\", \"struct\": \"") + type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.struct_def->name, flatbuffers::Case::kLowerCamel)) + "\"}";
} else if (flatbuffers::IsSeries(type)) {
if (type.element == flatbuffers::BASE_TYPE_STRUCT) {
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"struct\", \"struct\": \"") + type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.struct_def->name, false)) + "\"}}";
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"struct\", \"struct\": \"") + type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.struct_def->name, flatbuffers::Case::kLowerCamel)) + "\"}}";
} else if (type.element == flatbuffers::BASE_TYPE_UNION) {
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"union\", \"union\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}}";
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"union\", \"union\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}}";
} else if (type.element == flatbuffers::BASE_TYPE_UTYPE) {
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"utype\", \"utype\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}}";
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"utype\", \"utype\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}}";
} else if (type.enum_def) {
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"enum\", \"enum\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}}";
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"enum\", \"enum\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}}";
} else if (type.element == flatbuffers::BASE_TYPE_VECTOR || type.element == flatbuffers::BASE_TYPE_ARRAY) {
exit(-1);
} else {
return std::string("{\"type\": \"vector\", \"element\": {\"type\": \"") + idl_types[type.element] + "\"}}";
}
} else if (flatbuffers::IsUnion(type)) {
if (type.base_type == flatbuffers::BASE_TYPE_UTYPE) {
return std::string("{\"type\": \"utype\", \"utype\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}";
return std::string("{\"type\": \"utype\", \"utype\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}";
} else if (type.base_type == flatbuffers::BASE_TYPE_UNION) {
return std::string("{\"type\": \"union\", \"union\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}";
return std::string("{\"type\": \"union\", \"union\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}";
} else {
exit(-1);
}
} else if (flatbuffers::IsEnum(type)) {
return std::string("{\"type\": \"enum\", \"enum\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(type.enum_def->name, false)) + "\"}";
return std::string("{\"type\": \"enum\", \"enum\": \"") + type.enum_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(type.enum_def->name, flatbuffers::Case::kLowerCamel)) + "\"}";
} else {
return std::string("{\"type\": \"") + idl_types[type.base_type] + "\"}";
}
Expand Down Expand Up @@ -111,7 +111,7 @@ const std::string GenAttributes(const flatbuffers::SymbolTable<flatbuffers::Valu

const std::string GenUnion(const flatbuffers::EnumDef &enum_def) {
std::string json = std::string("{\"is_union\": ") + (enum_def.is_union ? "true" : "false") + ", ";
json += "\"name\": \"" + flatbuffers::MakeCamel(enum_def.name, false) + "\", ";
json += "\"name\": \"" + flatbuffers::ConvertCase(enum_def.name, flatbuffers::Case::kLowerCamel) + "\", ";
json += "\"generated\": ";
json += (enum_def.generated ? "true, " : "false, ");
json += "\"namespace\": [" + GenNamespace(*enum_def.defined_namespace) + "], ";
Expand All @@ -123,9 +123,9 @@ const std::string GenUnion(const flatbuffers::EnumDef &enum_def) {
for (auto it = vals.begin(); it != vals.end(); ++it) {
const auto &enum_val = **it;
if (enum_val.union_type.struct_def) {
json += "{\"name\": \"" + flatbuffers::MakeCamel(enum_val.name, false) + "\", \"type\": \"struct\", \"struct\": \"" + enum_val.union_type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::MakeCamel(enum_val.union_type.struct_def->name, false)) + "\", \"value\": " + enum_def.ToString(enum_val) + "}, ";
json += "{\"name\": \"" + flatbuffers::ConvertCase(enum_val.name, flatbuffers::Case::kLowerCamel) + "\", \"type\": \"struct\", \"struct\": \"" + enum_val.union_type.struct_def->defined_namespace->GetFullyQualifiedName(flatbuffers::ConvertCase(enum_val.union_type.struct_def->name, flatbuffers::Case::kLowerCamel)) + "\", \"value\": " + enum_def.ToString(enum_val) + "}, ";
} else {
json += "{\"name\": \"" + flatbuffers::MakeCamel(enum_val.name, false) + "\", \"type\": \"\", \"value\": " + enum_def.ToString(enum_val) + "}, ";
json += "{\"name\": \"" + flatbuffers::ConvertCase(enum_val.name, flatbuffers::Case::kLowerCamel) + "\", \"type\": \"\", \"value\": " + enum_def.ToString(enum_val) + "}, ";
}
}
if (vals.size() > 0) {
Expand All @@ -138,7 +138,7 @@ const std::string GenUnion(const flatbuffers::EnumDef &enum_def) {

const std::string GenStruct(const flatbuffers::StructDef &struct_def) {
std::string json = std::string("{\"fixed\": ") + (struct_def.fixed ? "true" : "false") + ", ";
json += "\"name\": \"" + flatbuffers::MakeCamel(struct_def.name, false) + "\", ";
json += "\"name\": \"" + flatbuffers::ConvertCase(struct_def.name, flatbuffers::Case::kLowerCamel) + "\", ";
json += "\"generated\": ";
json += (struct_def.generated ? "true, " : "false, ");
json += "\"namespace\": [" + GenNamespace(*struct_def.defined_namespace) + "], ";
Expand All @@ -147,9 +147,9 @@ const std::string GenStruct(const flatbuffers::StructDef &struct_def) {
for (auto it = struct_def.fields.vec.begin(); it != struct_def.fields.vec.end(); ++it) {
const auto &field_def = **it;
if (field_def.value.constant != "0") {
json += "{\"name\": \"" + flatbuffers::MakeCamel(field_def.name, false) + "\", \"deprecated\": " + (field_def.deprecated ? "true" : "false") + ", \"type\": " + GenJSONType(field_def.value.type) + ", \"offset\": " + std::to_string(field_def.value.offset) + ", \"default\": \"" + field_def.value.constant + "\", " + GenAttributes(field_def.attributes) + "}, ";
json += "{\"name\": \"" + flatbuffers::ConvertCase(field_def.name, flatbuffers::Case::kLowerCamel) + "\", \"deprecated\": " + (field_def.deprecated ? "true" : "false") + ", \"type\": " + GenJSONType(field_def.value.type) + ", \"offset\": " + std::to_string(field_def.value.offset) + ", \"default\": \"" + field_def.value.constant + "\", " + GenAttributes(field_def.attributes) + "}, ";
} else {
json += "{\"name\": \"" + flatbuffers::MakeCamel(field_def.name, false) + "\", \"deprecated\": " + (field_def.deprecated ? "true" : "false") + ", \"type\": " + GenJSONType(field_def.value.type) + ", \"offset\": " + std::to_string(field_def.value.offset) + ", " + GenAttributes(field_def.attributes) + "}, ";
json += "{\"name\": \"" + flatbuffers::ConvertCase(field_def.name, flatbuffers::Case::kLowerCamel) + "\", \"deprecated\": " + (field_def.deprecated ? "true" : "false") + ", \"type\": " + GenJSONType(field_def.value.type) + ", \"offset\": " + std::to_string(field_def.value.offset) + ", " + GenAttributes(field_def.attributes) + "}, ";
}
}
if (struct_def.fields.vec.size() > 0) {
Expand Down Expand Up @@ -185,9 +185,9 @@ static void GenerateJSONAdapter(const flatbuffers::Parser &parser, const std::st
}
if (parser.root_struct_def_) {
if (parser.structs_.vec.size() > 0) {
json = json.substr(0, json.size() - 2) + "], \"root\": {\"namespace\": [" + GenNamespace(*parser.root_struct_def_->defined_namespace) + "], \"name\": \"" + flatbuffers::MakeCamel(parser.root_struct_def_->name, false) + "\"}}";
json = json.substr(0, json.size() - 2) + "], \"root\": {\"namespace\": [" + GenNamespace(*parser.root_struct_def_->defined_namespace) + "], \"name\": \"" + flatbuffers::ConvertCase(parser.root_struct_def_->name, flatbuffers::Case::kLowerCamel) + "\"}}";
} else {
json = json + "], \"root\": {\"namespace\": [" + GenNamespace(*parser.root_struct_def_->defined_namespace) + "], \"name\": \"" + flatbuffers::MakeCamel(parser.root_struct_def_->name, false) + "\"}}";
json = json + "], \"root\": {\"namespace\": [" + GenNamespace(*parser.root_struct_def_->defined_namespace) + "], \"name\": \"" + flatbuffers::ConvertCase(parser.root_struct_def_->name, flatbuffers::Case::kLowerCamel) + "\"}}";
}
} else {
json = json + "]}";
Expand Down

0 comments on commit 432407d

Please sign in to comment.