mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 21:37:36 +00:00
Final refactor for bfsb_generator* and text generator (#7806)
* Refactor BfbsGenerator to use CodeGenerator interface * Update * Refactor bfbs generator * Refactor bfbs generator for lua and nim. Remove old code that use Generator interface. * Update import * Update CMakeLists * Update BUILD file * Update BUILD file for src * Remove from Android CMakeLists and add error message * Update * Add generate root file function to Code Generator interface * Update * Update * Minor format fix
This commit is contained in:
@@ -26,7 +26,6 @@
|
||||
// Ensure no includes to flatc internals. bfbs_gen.h and generator.h are OK.
|
||||
#include "bfbs_gen.h"
|
||||
#include "bfbs_namer.h"
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
|
||||
// The intermediate representation schema.
|
||||
#include "flatbuffers/reflection.h"
|
||||
@@ -96,8 +95,7 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||
flatc_version_(flatc_version),
|
||||
namer_(NimDefaultConfig(), NimKeywords()) {}
|
||||
|
||||
GeneratorStatus GenerateFromSchema(const r::Schema *schema)
|
||||
FLATBUFFERS_OVERRIDE {
|
||||
Status GenerateFromSchema(const r::Schema *schema) FLATBUFFERS_OVERRIDE {
|
||||
ForAllEnums(schema->enums(), [&](const r::Enum *enum_def) {
|
||||
StartCodeBlock(enum_def);
|
||||
GenerateEnum(enum_def);
|
||||
@@ -109,6 +107,51 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||
return OK;
|
||||
}
|
||||
|
||||
using BaseBfbsGenerator::GenerateCode;
|
||||
|
||||
Status GenerateCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &filename,
|
||||
std::string &output) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
(void)output;
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
(void)filename;
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
Status GenerateRootFile(const Parser &parser,
|
||||
const std::string &path) override {
|
||||
(void)parser;
|
||||
(void)path;
|
||||
return NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
bool IsSchemaOnly() const override { return true; }
|
||||
|
||||
bool SupportsBfbsGeneration() const override { return true; }
|
||||
|
||||
bool SupportsRootFileGeneration() const override { return false; }
|
||||
|
||||
IDLOptions::Language Language() const override { return IDLOptions::kNim; }
|
||||
|
||||
std::string LanguageName() const override { return "Nim"; }
|
||||
|
||||
uint64_t SupportedAdvancedFeatures() const FLATBUFFERS_OVERRIDE {
|
||||
return r::AdvancedArrayFeatures | r::AdvancedUnionFeatures |
|
||||
r::OptionalScalars | r::DefaultVectorsAndStrings;
|
||||
@@ -472,9 +515,11 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||
if (IsFloatingPoint(base_type)) {
|
||||
if (field->default_real() != field->default_real()) {
|
||||
return "NaN";
|
||||
} else if (field->default_real() == std::numeric_limits<double>::infinity()) {
|
||||
} else if (field->default_real() ==
|
||||
std::numeric_limits<double>::infinity()) {
|
||||
return "Inf";
|
||||
} else if (field->default_real() == -std::numeric_limits<double>::infinity()) {
|
||||
} else if (field->default_real() ==
|
||||
-std::numeric_limits<double>::infinity()) {
|
||||
return "-Inf";
|
||||
}
|
||||
return NumToString(field->default_real());
|
||||
@@ -639,7 +684,7 @@ class NimBfbsGenerator : public BaseBfbsGenerator {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<BfbsGenerator> NewNimBfbsGenerator(
|
||||
std::unique_ptr<CodeGenerator> NewNimBfbsGenerator(
|
||||
const std::string &flatc_version) {
|
||||
return std::unique_ptr<NimBfbsGenerator>(new NimBfbsGenerator(flatc_version));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user