mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-06 05:27:24 +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:
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2021 Google Inc. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FLATBUFFERS_BFBS_GENERATOR_H_
|
||||
#define FLATBUFFERS_BFBS_GENERATOR_H_
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
enum GeneratorStatus {
|
||||
OK,
|
||||
FAILED,
|
||||
FAILED_VERIFICATION,
|
||||
};
|
||||
|
||||
// A Flatbuffer Code Generator that receives a binary serialized reflection.fbs
|
||||
// and generates code from it.
|
||||
class BfbsGenerator {
|
||||
public:
|
||||
virtual ~BfbsGenerator() {}
|
||||
|
||||
// Generate code from the provided `buffer` of given `length`. The buffer is
|
||||
// a serialized reflection.fbs.
|
||||
virtual GeneratorStatus Generate(const uint8_t *buffer, int64_t length) = 0;
|
||||
};
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // FLATBUFFERS_BFBS_GENERATOR_H_
|
||||
@@ -32,7 +32,8 @@ class CodeGenerator {
|
||||
enum Status {
|
||||
OK = 0,
|
||||
ERROR = 1,
|
||||
NOT_IMPLEMENTED = 2,
|
||||
FAILED_VERIFICATION = 2,
|
||||
NOT_IMPLEMENTED = 3
|
||||
};
|
||||
|
||||
// Generate code from the provided `parser`.
|
||||
@@ -52,11 +53,17 @@ class CodeGenerator {
|
||||
virtual Status GenerateGrpcCode(const Parser &parser, const std::string &path,
|
||||
const std::string &filename) = 0;
|
||||
|
||||
virtual Status GenerateRootFile(const Parser &parser,
|
||||
const std::string &path) = 0;
|
||||
|
||||
virtual bool IsSchemaOnly() const = 0;
|
||||
|
||||
virtual bool SupportsBfbsGeneration() const = 0;
|
||||
|
||||
virtual bool SupportsRootFileGeneration() const = 0;
|
||||
|
||||
virtual IDLOptions::Language Language() const = 0;
|
||||
|
||||
virtual std::string LanguageName() const = 0;
|
||||
|
||||
protected:
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/bfbs_generator.h"
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
@@ -69,29 +68,6 @@ struct FlatCOption {
|
||||
|
||||
class FlatCompiler {
|
||||
public:
|
||||
// Output generator for the various programming languages and formats we
|
||||
// support.
|
||||
struct Generator {
|
||||
typedef bool (*GenerateFn)(const flatbuffers::Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name);
|
||||
typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name);
|
||||
typedef bool (*ParsingCompletedFn)(const flatbuffers::Parser &parser,
|
||||
const std::string &output_path);
|
||||
|
||||
GenerateFn generate;
|
||||
const char *lang_name;
|
||||
bool schema_only;
|
||||
GenerateFn generateGRPC;
|
||||
flatbuffers::IDLOptions::Language lang;
|
||||
FlatCOption option;
|
||||
MakeRuleFn make_rule;
|
||||
BfbsGenerator *bfbs_generator;
|
||||
ParsingCompletedFn parsing_completed;
|
||||
};
|
||||
|
||||
typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn,
|
||||
bool show_exe_name);
|
||||
|
||||
@@ -100,14 +76,8 @@ class FlatCompiler {
|
||||
|
||||
// Parameters required to initialize the FlatCompiler.
|
||||
struct InitParams {
|
||||
InitParams()
|
||||
: generators(nullptr),
|
||||
num_generators(0),
|
||||
warn_fn(nullptr),
|
||||
error_fn(nullptr) {}
|
||||
InitParams() : warn_fn(nullptr), error_fn(nullptr) {}
|
||||
|
||||
const Generator *generators;
|
||||
size_t num_generators;
|
||||
WarnFn warn_fn;
|
||||
ErrorFn error_fn;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user