• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 Google Inc. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "flatbuffers/flatc.h"
18 
19 #include <list>
20 
21 namespace flatbuffers {
22 
FLATC_VERSION()23 const char *FLATC_VERSION() { return FLATBUFFERS_VERSION(); }
24 
ParseFile(flatbuffers::Parser & parser,const std::string & filename,const std::string & contents,std::vector<const char * > & include_directories) const25 void FlatCompiler::ParseFile(
26     flatbuffers::Parser &parser, const std::string &filename,
27     const std::string &contents,
28     std::vector<const char *> &include_directories) const {
29   auto local_include_directory = flatbuffers::StripFileName(filename);
30   include_directories.push_back(local_include_directory.c_str());
31   include_directories.push_back(nullptr);
32   if (!parser.Parse(contents.c_str(), &include_directories[0],
33                     filename.c_str())) {
34     Error(parser.error_, false, false);
35   }
36   if (!parser.error_.empty()) { Warn(parser.error_, false); }
37   include_directories.pop_back();
38   include_directories.pop_back();
39 }
40 
LoadBinarySchema(flatbuffers::Parser & parser,const std::string & filename,const std::string & contents)41 void FlatCompiler::LoadBinarySchema(flatbuffers::Parser &parser,
42                                     const std::string &filename,
43                                     const std::string &contents) {
44   if (!parser.Deserialize(reinterpret_cast<const uint8_t *>(contents.c_str()),
45                           contents.size())) {
46     Error("failed to load binary schema: " + filename, false, false);
47   }
48 }
49 
Warn(const std::string & warn,bool show_exe_name) const50 void FlatCompiler::Warn(const std::string &warn, bool show_exe_name) const {
51   params_.warn_fn(this, warn, show_exe_name);
52 }
53 
Error(const std::string & err,bool usage,bool show_exe_name) const54 void FlatCompiler::Error(const std::string &err, bool usage,
55                          bool show_exe_name) const {
56   params_.error_fn(this, err, usage, show_exe_name);
57 }
58 
GetUsageString(const char * program_name) const59 std::string FlatCompiler::GetUsageString(const char *program_name) const {
60   std::stringstream ss;
61   ss << "Usage: " << program_name << " [OPTION]... FILE... [-- FILE...]\n";
62   for (size_t i = 0; i < params_.num_generators; ++i) {
63     const Generator &g = params_.generators[i];
64 
65     std::stringstream full_name;
66     full_name << std::setw(16) << std::left << g.generator_opt_long;
67     const char *name = g.generator_opt_short ? g.generator_opt_short : "  ";
68     const char *help = g.generator_help;
69 
70     ss << "  " << full_name.str() << " " << name << "    " << help << ".\n";
71   }
72   // clang-format off
73 
74   // Output width
75   // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
76   ss <<
77     "  -o PATH                Prefix PATH to all generated files.\n"
78     "  -I PATH                Search for includes in the specified path.\n"
79     "  -M                     Print make rules for generated files.\n"
80     "  --version              Print the version number of flatc and exit.\n"
81     "  --strict-json          Strict JSON: field names must be / will be quoted,\n"
82     "                         no trailing commas in tables/vectors.\n"
83     "  --allow-non-utf8       Pass non-UTF-8 input through parser and emit nonstandard\n"
84     "                         \\x escapes in JSON. (Default is to raise parse error on\n"
85     "                         non-UTF-8 input.)\n"
86     "  --natural-utf8         Output strings with UTF-8 as human-readable strings.\n"
87     "                         By default, UTF-8 characters are printed as \\uXXXX escapes.\n"
88     "  --defaults-json        Output fields whose value is the default when\n"
89     "                         writing JSON\n"
90     "  --unknown-json         Allow fields in JSON that are not defined in the\n"
91     "                         schema. These fields will be discared when generating\n"
92     "                         binaries.\n"
93     "  --no-prefix            Don\'t prefix enum values with the enum type in C++.\n"
94     "  --scoped-enums         Use C++11 style scoped and strongly typed enums.\n"
95     "                         also implies --no-prefix.\n"
96     "  --gen-includes         (deprecated), this is the default behavior.\n"
97     "                         If the original behavior is required (no include\n"
98     "                         statements) use --no-includes.\n"
99     "  --no-includes          Don\'t generate include statements for included\n"
100     "                         schemas the generated file depends on (C++ / Python).\n"
101     "  --gen-mutable          Generate accessors that can mutate buffers in-place.\n"
102     "  --gen-onefile          Generate single output file for C# and Go.\n"
103     "  --gen-name-strings     Generate type name functions for C++ and Rust.\n"
104     "  --gen-object-api       Generate an additional object-based API.\n"
105     "  --gen-compare          Generate operator== for object-based API types.\n"
106     "  --gen-nullable         Add Clang _Nullable for C++ pointer. or @Nullable for Java\n"
107     "  --java-checkerframe    work Add @Pure for Java.\n"
108     "  --gen-generated        Add @Generated annotation for Java\n"
109     "  --gen-all              Generate not just code for the current schema files,\n"
110     "                         but for all files it includes as well.\n"
111     "                         If the language uses a single file for output (by default\n"
112     "                         the case for C++ and JS), all code will end up in this one\n"
113     "                         file.\n"
114     "  --cpp-include          Adds an #include in generated file.\n"
115     "  --cpp-ptr-type T       Set object API pointer type (default std::unique_ptr).\n"
116     "  --cpp-str-type T       Set object API string type (default std::string).\n"
117     "                         T::c_str(), T::length() and T::empty() must be supported.\n"
118     "                         The custom type also needs to be constructible from std::string\n"
119     "                         (see the --cpp-str-flex-ctor option to change this behavior).\n"
120     "  --cpp-str-flex-ctor    Don't construct custom string types by passing std::string\n"
121     "                         from Flatbuffers, but (char* + length).\n"
122     "  --cpp-std CPP_STD      Generate a C++ code using features of selected C++ standard.\n"
123     "                         Supported CPP_STD values:\n"
124     "                          * 'c++0x' - generate code compatible with old compilers;\n"
125     "                          * 'c++11' - use C++11 code generator (default);\n"
126     "                          * 'c++17' - use C++17 features in generated code (experimental).\n"
127     "  --object-prefix        Customise class prefix for C++ object-based API.\n"
128     "  --object-suffix        Customise class suffix for C++ object-based API.\n"
129     "                         Default value is \"T\".\n"
130     "  --no-js-exports        Removes Node.js style export lines in JS.\n"
131     "  --goog-js-export       Uses goog.exports* for closure compiler exporting in JS.\n"
132     "  --es6-js-export        Uses ECMAScript 6 export style lines in JS.\n"
133     "  --go-namespace         Generate the overrided namespace in Golang.\n"
134     "  --go-import            Generate the overrided import for flatbuffers in Golang\n"
135     "                         (default is \"github.com/google/flatbuffers/go\").\n"
136     "  --raw-binary           Allow binaries without file_indentifier to be read.\n"
137     "                         This may crash flatc given a mismatched schema.\n"
138     "  --size-prefixed        Input binaries are size prefixed buffers.\n"
139     "  --proto                Input is a .proto, translate to .fbs.\n"
140     "  --proto-namespace-suffix Add this namespace to any flatbuffers generated\n"
141     "    SUFFIX                 from protobufs.\n"
142     "  --oneof-union          Translate .proto oneofs to flatbuffer unions.\n"
143     "  --grpc                 Generate GRPC interfaces for the specified languages.\n"
144     "  --schema               Serialize schemas instead of JSON (use with -b).\n"
145     "  --bfbs-comments        Add doc comments to the binary schema files.\n"
146     "  --bfbs-builtins        Add builtin attributes to the binary schema files.\n"
147     "  --bfbs-gen-embed       Generate code to embed the bfbs schema to the source.\n"
148     "  --conform FILE         Specify a schema the following schemas should be\n"
149     "                         an evolution of. Gives errors if not.\n"
150     "  --conform-includes     Include path for the schema given with --conform PATH\n"
151     "  --filename-suffix      The suffix appended to the generated file names.\n"
152     "                         Default is '_generated'.\n"
153     "  --filename-ext         The extension appended to the generated file names.\n"
154     "                         Default is language-specific (e.g., '.h' for C++)\n"
155     "  --include-prefix       Prefix this path to any generated include statements.\n"
156     "    PATH\n"
157     "  --keep-prefix          Keep original prefix of schema include statement.\n"
158     "  --no-fb-import         Don't include flatbuffers import statement for TypeScript.\n"
159     "  --no-ts-reexport       Don't re-export imported dependencies for TypeScript.\n"
160     "  --short-names          Use short function names for JS and TypeScript.\n"
161     "  --reflect-types        Add minimal type reflection to code generation.\n"
162     "  --reflect-names        Add minimal type/name reflection.\n"
163     "  --root-type T          Select or override the default root_type\n"
164     "  --force-defaults       Emit default values in binary output from JSON\n"
165     "  --force-empty          When serializing from object API representation,\n"
166     "                         force strings and vectors to empty rather than null.\n"
167     "  --force-empty-vectors  When serializing from object API representation,\n"
168     "                         force vectors to empty rather than null.\n"
169     "  --flexbuffers          Used with \"binary\" and \"json\" options, it generates\n"
170     "                         data using schema-less FlexBuffers.\n"
171     "FILEs may be schemas (must end in .fbs), binary schemas (must end in .bfbs),\n"
172     "or JSON files (conforming to preceding schema). FILEs after the -- must be\n"
173     "binary flatbuffer format files.\n"
174     "Output files are named using the base file name of the input,\n"
175     "and written to the current directory or the path given by -o.\n"
176     "example: " << program_name << " -c -b schema1.fbs schema2.fbs data.json\n";
177   // 12345678901234567890123456789012345678901234567890123456789012345678901234567890
178   // clang-format on
179   return ss.str();
180 }
181 
Compile(int argc,const char ** argv)182 int FlatCompiler::Compile(int argc, const char **argv) {
183   if (params_.generators == nullptr || params_.num_generators == 0) {
184     return 0;
185   }
186 
187   flatbuffers::IDLOptions opts;
188   std::string output_path;
189 
190   bool any_generator = false;
191   bool print_make_rules = false;
192   bool raw_binary = false;
193   bool schema_binary = false;
194   bool grpc_enabled = false;
195   std::vector<std::string> filenames;
196   std::list<std::string> include_directories_storage;
197   std::vector<const char *> include_directories;
198   std::vector<const char *> conform_include_directories;
199   std::vector<bool> generator_enabled(params_.num_generators, false);
200   size_t binary_files_from = std::numeric_limits<size_t>::max();
201   std::string conform_to_schema;
202 
203   for (int argi = 0; argi < argc; argi++) {
204     std::string arg = argv[argi];
205     if (arg[0] == '-') {
206       if (filenames.size() && arg[1] != '-')
207         Error("invalid option location: " + arg, true);
208       if (arg == "-o") {
209         if (++argi >= argc) Error("missing path following: " + arg, true);
210         output_path = flatbuffers::ConCatPathFileName(
211             flatbuffers::PosixPath(argv[argi]), "");
212       } else if (arg == "-I") {
213         if (++argi >= argc) Error("missing path following: " + arg, true);
214         include_directories_storage.push_back(
215             flatbuffers::PosixPath(argv[argi]));
216         include_directories.push_back(
217             include_directories_storage.back().c_str());
218       } else if (arg == "--conform") {
219         if (++argi >= argc) Error("missing path following: " + arg, true);
220         conform_to_schema = flatbuffers::PosixPath(argv[argi]);
221       } else if (arg == "--conform-includes") {
222         if (++argi >= argc) Error("missing path following: " + arg, true);
223         include_directories_storage.push_back(
224             flatbuffers::PosixPath(argv[argi]));
225         conform_include_directories.push_back(
226             include_directories_storage.back().c_str());
227       } else if (arg == "--include-prefix") {
228         if (++argi >= argc) Error("missing path following: " + arg, true);
229         opts.include_prefix = flatbuffers::ConCatPathFileName(
230             flatbuffers::PosixPath(argv[argi]), "");
231       } else if (arg == "--keep-prefix") {
232         opts.keep_include_path = true;
233       } else if (arg == "--strict-json") {
234         opts.strict_json = true;
235       } else if (arg == "--allow-non-utf8") {
236         opts.allow_non_utf8 = true;
237       } else if (arg == "--natural-utf8") {
238         opts.natural_utf8 = true;
239       } else if (arg == "--no-js-exports") {
240         opts.skip_js_exports = true;
241       } else if (arg == "--goog-js-export") {
242         opts.use_goog_js_export_format = true;
243         opts.use_ES6_js_export_format = false;
244       } else if (arg == "--es6-js-export") {
245         opts.use_goog_js_export_format = false;
246         opts.use_ES6_js_export_format = true;
247       } else if (arg == "--go-namespace") {
248         if (++argi >= argc) Error("missing golang namespace" + arg, true);
249         opts.go_namespace = argv[argi];
250       } else if (arg == "--go-import") {
251         if (++argi >= argc) Error("missing golang import" + arg, true);
252         opts.go_import = argv[argi];
253       } else if (arg == "--defaults-json") {
254         opts.output_default_scalars_in_json = true;
255       } else if (arg == "--unknown-json") {
256         opts.skip_unexpected_fields_in_json = true;
257       } else if (arg == "--no-prefix") {
258         opts.prefixed_enums = false;
259       } else if (arg == "--scoped-enums") {
260         opts.prefixed_enums = false;
261         opts.scoped_enums = true;
262       } else if (arg == "--no-union-value-namespacing") {
263         opts.union_value_namespacing = false;
264       } else if (arg == "--gen-mutable") {
265         opts.mutable_buffer = true;
266       } else if (arg == "--gen-name-strings") {
267         opts.generate_name_strings = true;
268       } else if (arg == "--gen-object-api") {
269         opts.generate_object_based_api = true;
270       } else if (arg == "--gen-compare") {
271         opts.gen_compare = true;
272       } else if (arg == "--cpp-include") {
273         if (++argi >= argc) Error("missing include following: " + arg, true);
274         opts.cpp_includes.push_back(argv[argi]);
275       } else if (arg == "--cpp-ptr-type") {
276         if (++argi >= argc) Error("missing type following: " + arg, true);
277         opts.cpp_object_api_pointer_type = argv[argi];
278       } else if (arg == "--cpp-str-type") {
279         if (++argi >= argc) Error("missing type following: " + arg, true);
280         opts.cpp_object_api_string_type = argv[argi];
281       } else if (arg == "--cpp-str-flex-ctor") {
282         opts.cpp_object_api_string_flexible_constructor = true;
283       } else if (arg == "--gen-nullable") {
284         opts.gen_nullable = true;
285       } else if (arg == "--java-checkerframework") {
286         opts.java_checkerframework = true;
287       } else if (arg == "--gen-generated") {
288         opts.gen_generated = true;
289       } else if (arg == "--object-prefix") {
290         if (++argi >= argc) Error("missing prefix following: " + arg, true);
291         opts.object_prefix = argv[argi];
292       } else if (arg == "--object-suffix") {
293         if (++argi >= argc) Error("missing suffix following: " + arg, true);
294         opts.object_suffix = argv[argi];
295       } else if (arg == "--gen-all") {
296         opts.generate_all = true;
297         opts.include_dependence_headers = false;
298       } else if (arg == "--gen-includes") {
299         // Deprecated, remove this option some time in the future.
300         Warn("warning: --gen-includes is deprecated (it is now default)\n");
301       } else if (arg == "--no-includes") {
302         opts.include_dependence_headers = false;
303       } else if (arg == "--gen-onefile") {
304         opts.one_file = true;
305       } else if (arg == "--raw-binary") {
306         raw_binary = true;
307       } else if (arg == "--size-prefixed") {
308         opts.size_prefixed = true;
309       } else if (arg == "--") {  // Separator between text and binary inputs.
310         binary_files_from = filenames.size();
311       } else if (arg == "--proto") {
312         opts.proto_mode = true;
313       } else if (arg == "--proto-namespace-suffix") {
314         if (++argi >= argc) Error("missing namespace suffix" + arg, true);
315         opts.proto_namespace_suffix = argv[argi];
316       } else if (arg == "--oneof-union") {
317         opts.proto_oneof_union = true;
318       } else if (arg == "--schema") {
319         schema_binary = true;
320       } else if (arg == "-M") {
321         print_make_rules = true;
322       } else if (arg == "--version") {
323         printf("flatc version %s\n", FLATC_VERSION());
324         exit(0);
325       } else if (arg == "--grpc") {
326         grpc_enabled = true;
327       } else if (arg == "--bfbs-comments") {
328         opts.binary_schema_comments = true;
329       } else if (arg == "--bfbs-builtins") {
330         opts.binary_schema_builtins = true;
331       } else if (arg == "--bfbs-gen-embed") {
332         opts.binary_schema_gen_embed = true;
333       } else if (arg == "--no-fb-import") {
334         opts.skip_flatbuffers_import = true;
335       } else if (arg == "--no-ts-reexport") {
336         opts.reexport_ts_modules = false;
337       } else if (arg == "--short-names") {
338         opts.js_ts_short_names = true;
339       } else if (arg == "--reflect-types") {
340         opts.mini_reflect = IDLOptions::kTypes;
341       } else if (arg == "--reflect-names") {
342         opts.mini_reflect = IDLOptions::kTypesAndNames;
343       } else if (arg == "--root-type") {
344         if (++argi >= argc) Error("missing type following: " + arg, true);
345         opts.root_type = argv[argi];
346       } else if (arg == "--filename-suffix") {
347         if (++argi >= argc) Error("missing filename suffix: " + arg, true);
348         opts.filename_suffix = argv[argi];
349       } else if (arg == "--filename-ext") {
350         if (++argi >= argc) Error("missing filename extension: " + arg, true);
351         opts.filename_extension = argv[argi];
352       } else if (arg == "--force-defaults") {
353         opts.force_defaults = true;
354       } else if (arg == "--force-empty") {
355         opts.set_empty_strings_to_null = false;
356         opts.set_empty_vectors_to_null = false;
357       } else if (arg == "--force-empty-vectors") {
358         opts.set_empty_vectors_to_null = false;
359       } else if (arg == "--java-primitive-has-method") {
360         opts.java_primitive_has_method = true;
361       } else if (arg == "--cs-gen-json-serializer") {
362         opts.cs_gen_json_serializer = true;
363       } else if (arg == "--flexbuffers") {
364         opts.use_flexbuffers = true;
365       } else if (arg == "--cpp-std") {
366         if (++argi >= argc)
367           Error("missing C++ standard specification" + arg, true);
368         opts.cpp_std = argv[argi];
369       } else {
370         for (size_t i = 0; i < params_.num_generators; ++i) {
371           if (arg == params_.generators[i].generator_opt_long ||
372               (params_.generators[i].generator_opt_short &&
373                arg == params_.generators[i].generator_opt_short)) {
374             generator_enabled[i] = true;
375             any_generator = true;
376             opts.lang_to_generate |= params_.generators[i].lang;
377             goto found;
378           }
379         }
380         Error("unknown commandline argument: " + arg, true);
381       found:;
382       }
383     } else {
384       filenames.push_back(flatbuffers::PosixPath(argv[argi]));
385     }
386   }
387 
388   if (!filenames.size()) Error("missing input files", false, true);
389 
390   if (opts.proto_mode) {
391     if (any_generator)
392       Error("cannot generate code directly from .proto files", true);
393   } else if (!any_generator && conform_to_schema.empty()) {
394     Error("no options: specify at least one generator.", true);
395   }
396 
397   flatbuffers::Parser conform_parser;
398   if (!conform_to_schema.empty()) {
399     std::string contents;
400     if (!flatbuffers::LoadFile(conform_to_schema.c_str(), true, &contents))
401       Error("unable to load schema: " + conform_to_schema);
402 
403     if (flatbuffers::GetExtension(conform_to_schema) ==
404         reflection::SchemaExtension()) {
405       LoadBinarySchema(conform_parser, conform_to_schema, contents);
406     } else {
407       ParseFile(conform_parser, conform_to_schema, contents,
408                 conform_include_directories);
409     }
410   }
411 
412   std::unique_ptr<flatbuffers::Parser> parser(new flatbuffers::Parser(opts));
413 
414   for (auto file_it = filenames.begin(); file_it != filenames.end();
415        ++file_it) {
416     auto &filename = *file_it;
417     std::string contents;
418     if (!flatbuffers::LoadFile(filename.c_str(), true, &contents))
419       Error("unable to load file: " + filename);
420 
421     bool is_binary =
422         static_cast<size_t>(file_it - filenames.begin()) >= binary_files_from;
423     auto ext = flatbuffers::GetExtension(filename);
424     auto is_schema = ext == "fbs" || ext == "proto";
425     auto is_binary_schema = ext == reflection::SchemaExtension();
426     if (is_binary) {
427       parser->builder_.Clear();
428       parser->builder_.PushFlatBuffer(
429           reinterpret_cast<const uint8_t *>(contents.c_str()),
430           contents.length());
431       if (!raw_binary) {
432         // Generally reading binaries that do not correspond to the schema
433         // will crash, and sadly there's no way around that when the binary
434         // does not contain a file identifier.
435         // We'd expect that typically any binary used as a file would have
436         // such an identifier, so by default we require them to match.
437         if (!parser->file_identifier_.length()) {
438           Error("current schema has no file_identifier: cannot test if \"" +
439                 filename +
440                 "\" matches the schema, use --raw-binary to read this file"
441                 " anyway.");
442         } else if (!flatbuffers::BufferHasIdentifier(
443                        contents.c_str(), parser->file_identifier_.c_str(),
444                        opts.size_prefixed)) {
445           Error("binary \"" + filename +
446                 "\" does not have expected file_identifier \"" +
447                 parser->file_identifier_ +
448                 "\", use --raw-binary to read this file anyway.");
449         }
450       }
451     } else {
452       // Check if file contains 0 bytes.
453       if (!opts.use_flexbuffers && !is_binary_schema &&
454           contents.length() != strlen(contents.c_str())) {
455         Error("input file appears to be binary: " + filename, true);
456       }
457       if (is_schema) {
458         // If we're processing multiple schemas, make sure to start each
459         // one from scratch. If it depends on previous schemas it must do
460         // so explicitly using an include.
461         parser.reset(new flatbuffers::Parser(opts));
462       }
463       if (is_binary_schema) {
464         LoadBinarySchema(*parser.get(), filename, contents);
465       }
466       if (opts.use_flexbuffers) {
467         if (opts.lang_to_generate == IDLOptions::kJson) {
468           parser->flex_root_ = flexbuffers::GetRoot(
469               reinterpret_cast<const uint8_t *>(contents.c_str()),
470               contents.size());
471         } else {
472           parser->flex_builder_.Clear();
473           ParseFile(*parser.get(), filename, contents, include_directories);
474         }
475       } else {
476         ParseFile(*parser.get(), filename, contents, include_directories);
477         if (!is_schema && !parser->builder_.GetSize()) {
478           // If a file doesn't end in .fbs, it must be json/binary. Ensure we
479           // didn't just parse a schema with a different extension.
480           Error("input file is neither json nor a .fbs (schema) file: " +
481                     filename,
482                 true);
483         }
484       }
485       if ((is_schema || is_binary_schema) && !conform_to_schema.empty()) {
486         auto err = parser->ConformTo(conform_parser);
487         if (!err.empty()) Error("schemas don\'t conform: " + err);
488       }
489       if (schema_binary || opts.binary_schema_gen_embed) {
490         parser->Serialize();
491       }
492       if (schema_binary) {
493         parser->file_extension_ = reflection::SchemaExtension();
494       }
495     }
496 
497     std::string filebase =
498         flatbuffers::StripPath(flatbuffers::StripExtension(filename));
499 
500     for (size_t i = 0; i < params_.num_generators; ++i) {
501       parser->opts.lang = params_.generators[i].lang;
502       if (generator_enabled[i]) {
503         if (!print_make_rules) {
504           flatbuffers::EnsureDirExists(output_path);
505           if ((!params_.generators[i].schema_only ||
506                (is_schema || is_binary_schema)) &&
507               !params_.generators[i].generate(*parser.get(), output_path,
508                                               filebase)) {
509             Error(std::string("Unable to generate ") +
510                   params_.generators[i].lang_name + " for " + filebase);
511           }
512         } else {
513           if (params_.generators[i].make_rule == nullptr) {
514             Error(std::string("Cannot generate make rule for ") +
515                   params_.generators[i].lang_name);
516           } else {
517             std::string make_rule = params_.generators[i].make_rule(
518                 *parser.get(), output_path, filename);
519             if (!make_rule.empty())
520               printf("%s\n",
521                      flatbuffers::WordWrap(make_rule, 80, " ", " \\").c_str());
522           }
523         }
524         if (grpc_enabled) {
525           if (params_.generators[i].generateGRPC != nullptr) {
526             if (!params_.generators[i].generateGRPC(*parser.get(), output_path,
527                                                     filebase)) {
528               Error(std::string("Unable to generate GRPC interface for") +
529                     params_.generators[i].lang_name);
530             }
531           } else {
532             Warn(std::string("GRPC interface generator not implemented for ") +
533                  params_.generators[i].lang_name);
534           }
535         }
536       }
537     }
538 
539     if (!opts.root_type.empty()) {
540       if (!parser->SetRootType(opts.root_type.c_str()))
541         Error("unknown root type: " + opts.root_type);
542       else if (parser->root_struct_def_->fixed)
543         Error("root type must be a table");
544     }
545 
546     if (opts.proto_mode) GenerateFBS(*parser.get(), output_path, filebase);
547 
548     // We do not want to generate code for the definitions in this file
549     // in any files coming up next.
550     parser->MarkGenerated();
551   }
552   return 0;
553 }
554 
555 }  // namespace flatbuffers
556