2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 Google Inc. All rights reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef FLATBUFFERS_FLATC_H_
19 #define FLATBUFFERS_FLATC_H_
25 #include "flatbuffers/flatbuffers.h"
26 #include "flatbuffers/idl.h"
27 #include "flatbuffers/util.h"
32 extern void LogCompilerWarn(const std::string &warn);
33 extern void LogCompilerError(const std::string &err);
38 // Output generator for the various programming languages and formats we
42 typedef bool (*GenerateFn)(const flatbuffers::Parser &parser, const std::string &path,
43 const std::string &file_name);
44 typedef std::string (*MakeRuleFn)(const flatbuffers::Parser &parser, const std::string &path,
45 const std::string &file_name);
48 const char *generator_opt_short;
49 const char *generator_opt_long;
50 const char *lang_name;
52 GenerateFn generateGRPC;
53 flatbuffers::IDLOptions::Language lang;
54 const char *generator_help;
58 typedef void (*WarnFn)(const FlatCompiler *flatc, const std::string &warn, bool show_exe_name);
60 typedef void (*ErrorFn)(const FlatCompiler *flatc, const std::string &err, bool usage,
63 // Parameters required to initialize the FlatCompiler.
66 InitParams() : generators(nullptr), num_generators(0), warn_fn(nullptr), error_fn(nullptr) {}
68 const Generator *generators;
69 size_t num_generators;
74 explicit FlatCompiler(const InitParams ¶ms) : params_(params) {}
76 int Compile(int argc, const char **argv);
78 std::string GetUsageString(const char *program_name) const;
81 void ParseFile(flatbuffers::Parser &parser, const std::string &filename,
82 const std::string &contents, std::vector<const char *> &include_directories) const;
84 void LoadBinarySchema(Parser &parser, const std::string &filename, const std::string &contents);
86 void Warn(const std::string &warn, bool show_exe_name = true) const;
88 void Error(const std::string &err, bool usage = true, bool show_exe_name = true) const;
93 } // namespace flatbuffers
95 #endif // FLATBUFFERS_FLATC_H_