diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/flatbuffers/flatc.h | 45 | ||||
-rw-r--r-- | include/flatbuffers/idl.h | 11 |
2 files changed, 49 insertions, 7 deletions
diff --git a/include/flatbuffers/flatc.h b/include/flatbuffers/flatc.h index af4ccae7..23eefaa0 100644 --- a/include/flatbuffers/flatc.h +++ b/include/flatbuffers/flatc.h @@ -19,6 +19,7 @@ #include <functional> #include <limits> +#include <list> #include <string> #include "flatbuffers/bfbs_generator.h" @@ -31,6 +32,30 @@ namespace flatbuffers { extern void LogCompilerWarn(const std::string &warn); extern void LogCompilerError(const std::string &err); +struct FlatCOptions { + IDLOptions opts; + + std::string program_name; + + std::string output_path; + + std::vector<std::string> filenames; + + std::list<std::string> include_directories_storage; + std::vector<const char *> include_directories; + std::vector<const char *> conform_include_directories; + std::vector<bool> generator_enabled; + size_t binary_files_from = std::numeric_limits<size_t>::max(); + std::string conform_to_schema; + std::string annotate_schema; + bool any_generator = false; + bool print_make_rules = false; + bool raw_binary = false; + bool schema_binary = false; + bool grpc_enabled = false; + bool requires_bfbs = false; +}; + struct FlatCOption { std::string short_opt; std::string long_opt; @@ -85,15 +110,18 @@ class FlatCompiler { explicit FlatCompiler(const InitParams ¶ms) : params_(params) {} - int Compile(int argc, const char **argv); + int Compile(const FlatCOptions &options); + + std::string GetShortUsageString(const std::string& program_name) const; + std::string GetUsageString(const std::string& program_name) const; - std::string GetShortUsageString(const char *program_name) const; - std::string GetUsageString(const char *program_name) const; + // Parse the FlatC options from command line arguments. + FlatCOptions ParseFromCommandLineArguments(int argc, const char **argv); private: void ParseFile(flatbuffers::Parser &parser, const std::string &filename, const std::string &contents, - std::vector<const char *> &include_directories) const; + const std::vector<const char *> &include_directories) const; void LoadBinarySchema(Parser &parser, const std::string &filename, const std::string &contents); @@ -105,9 +133,16 @@ class FlatCompiler { void AnnotateBinaries(const uint8_t *binary_schema, uint64_t binary_schema_size, - const std::string & schema_filename, + const std::string &schema_filename, const std::vector<std::string> &binary_files); + void ValidateOptions(const FlatCOptions &options); + + Parser GetConformParser(const FlatCOptions &options); + + std::unique_ptr<Parser> GenerateCode(const FlatCOptions &options, + Parser &conform_parser); + InitParams params_; }; diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 9e5bb25e..f6526bd5 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -298,7 +298,7 @@ struct FieldDef : public Definition { presence(kDefault), nested_flatbuffer(nullptr), padding(0), - sibling_union_field(nullptr){} + sibling_union_field(nullptr) {} Offset<reflection::Field> Serialize(FlatBufferBuilder *builder, uint16_t id, const Parser &parser) const; @@ -803,7 +803,7 @@ struct ParserState { FLATBUFFERS_ASSERT(cursor_ && line_start_ && cursor_ >= line_start_); return static_cast<int64_t>(cursor_ - line_start_); } - + const char *prev_cursor_; const char *cursor_; const char *line_start_; @@ -910,6 +910,13 @@ class Parser : public ParserState { known_attributes_["private"] = true; } + // Copying is not allowed + Parser(const Parser &) = delete; + Parser &operator=(const Parser &) = delete; + + Parser(Parser &&) = default; + Parser &operator=(Parser &&) = default; + ~Parser() { for (auto it = namespaces_.begin(); it != namespaces_.end(); ++it) { delete *it; |