[Nim] Bfbs Nim Generator (#7534)

* Bfbs Nim Generator

* Remove commented out tests

* add missing line to idl.h

* Commit python reflection changes

* Commit python reflection changes and move tests

* Remove default string addition

* Move tests to python file

* Fix element size check when element is table

* remove whitespace changes

* add element_type docs and commit further to namer and remove kkeep

* Bfbs Nim Generator

* Remove commented out tests

* add missing line to idl.h

* Commit python reflection changes

* Commit python reflection changes and move tests

* Remove default string addition

* Move tests to python file

* Fix element size check when element is table

* remove whitespace changes

* add element_type docs and commit further to namer and remove kkeep

* remove unused variables

* added tests to ci

* added tests to ci

* fixes

* Added reflection type Field, Variable to namer

* Moved reflection namer impl to bfbsnamer

* Remove whitespace at end of line

* Added nim to generated code

* Revert whitespace removal

Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
Dan Lapid
2022-10-21 21:30:04 +03:00
committed by GitHub
parent e301702964
commit 872a497464
57 changed files with 3344 additions and 34 deletions

View File

@@ -38,8 +38,9 @@ static void ForAllObjects(
for (auto it = objects->cbegin(); it != objects->cend(); ++it) { func(*it); }
}
static void ForAllEnumValues(const reflection::Enum *enum_def,
std::function<void(const reflection::EnumVal *)> func) {
static void ForAllEnumValues(
const reflection::Enum *enum_def,
std::function<void(const reflection::EnumVal *)> func) {
for (auto it = enum_def->values()->cbegin(); it != enum_def->values()->cend();
++it) {
func(*it);
@@ -91,7 +92,7 @@ static bool IsVector(const reflection::BaseType base_type) {
return base_type == reflection::Vector;
}
} // namespace
} // namespace
// A concrete base Flatbuffer Generator that specific language generators can
// derive from.
@@ -130,17 +131,29 @@ class BaseBfbsGenerator : public BfbsGenerator {
}
protected:
const reflection::Object *GetObject(const reflection::Type *type) const {
if (type->index() >= 0 && IsStructOrTable(type->base_type())) {
// GetObject returns the underlying object struct of the given type
// if element_type is true and GetObject is a list of objects then
// GetObject will correctly return the object struct of the vector's elements
const reflection::Object *GetObject(const reflection::Type *type,
bool element_type = false) const {
const reflection::BaseType base_type =
element_type ? type->element() : type->base_type();
if (type->index() >= 0 && IsStructOrTable(base_type)) {
return GetObjectByIndex(type->index());
}
return nullptr;
}
const reflection::Enum *GetEnum(const reflection::Type *type) const {
// GetEnum returns the underlying enum struct of the given type
// if element_type is true and GetEnum is a list of enums then
// GetEnum will correctly return the enum struct of the vector's elements
const reflection::Enum *GetEnum(const reflection::Type *type,
bool element_type = false) const {
const reflection::BaseType base_type =
element_type ? type->element() : type->base_type();
// TODO(derekbailey): it would be better to have a explicit list of allowed
// base types, instead of negating Obj types.
if (type->index() >= 0 && !IsStructOrTable(type->base_type())) {
if (type->index() >= 0 && !IsStructOrTable(base_type)) {
return GetEnumByIndex(type->index());
}
return nullptr;