shared method that exits early if everything is generated
This commit is contained in:
parent
6765c19d45
commit
4a8801da34
|
@ -29,6 +29,18 @@ class BaseGenerator {
|
|||
protected:
|
||||
virtual ~BaseGenerator(){};
|
||||
|
||||
bool IsEverythingGenerated() {
|
||||
for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end();
|
||||
++it) {
|
||||
if (!(*it)->generated) return false;
|
||||
}
|
||||
for (auto it = parser_.structs_.vec.begin();
|
||||
it != parser_.structs_.vec.end(); ++it) {
|
||||
if (!(*it)->generated) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const Parser &parser_;
|
||||
const std::string &path_;
|
||||
const std::string &file_name_;
|
||||
|
|
|
@ -724,21 +724,7 @@ class CppGenerator : public BaseGenerator {
|
|||
// structs,
|
||||
// and tables) and output them to a single file.
|
||||
bool generate() {
|
||||
// Check if we have any code to generate at all, to avoid an empty header.
|
||||
for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end();
|
||||
++it) {
|
||||
if (!(*it)->generated) goto generate_code;
|
||||
}
|
||||
for (auto it = parser_.structs_.vec.begin(); it != parser_.structs_.vec.end();
|
||||
++it) {
|
||||
if (!(*it)->generated) goto generate_code;
|
||||
}
|
||||
// No code to generate, exit:
|
||||
return true;
|
||||
|
||||
generate_code:
|
||||
|
||||
using namespace cpp;
|
||||
if (IsEverythingGenerated()) return true;
|
||||
|
||||
std::string code;
|
||||
code =
|
||||
|
|
|
@ -678,31 +678,29 @@ class JsGenerator : public BaseGenerator {
|
|||
// Iterate through all definitions we haven't generate code for (enums,
|
||||
// structs, and tables) and output them to a single file.
|
||||
bool generate() {
|
||||
if (IsEverythingGenerated()) return true;
|
||||
|
||||
std::string enum_code, struct_code, exports_code, code;
|
||||
generateEnums(&enum_code, &exports_code);
|
||||
generateStructs(&struct_code, &exports_code);
|
||||
|
||||
// Only output file-level code if there were any declarations.
|
||||
if (enum_code.length() || struct_code.length()) {
|
||||
code +=
|
||||
"// automatically generated by the FlatBuffers compiler, do not "
|
||||
"modify\n\n";
|
||||
code +=
|
||||
"// automatically generated by the FlatBuffers compiler, do not "
|
||||
"modify\n\n";
|
||||
|
||||
// Generate code for all the namespace declarations.
|
||||
GenNamespaces(parser_, &code, &exports_code);
|
||||
// Generate code for all the namespace declarations.
|
||||
GenNamespaces(parser_, &code, &exports_code);
|
||||
|
||||
// Output the main declaration code from above.
|
||||
code += enum_code;
|
||||
code += struct_code;
|
||||
// Output the main declaration code from above.
|
||||
code += enum_code;
|
||||
code += struct_code;
|
||||
|
||||
if (!exports_code.empty() && !parser_.opts.skip_js_exports) {
|
||||
code += "// Exports for Node.js and RequireJS\n";
|
||||
code += exports_code;
|
||||
}
|
||||
if (!exports_code.empty() && !parser_.opts.skip_js_exports) {
|
||||
code += "// Exports for Node.js and RequireJS\n";
|
||||
code += exports_code;
|
||||
}
|
||||
|
||||
return !code.length() ||
|
||||
SaveFile(GeneratedFileName(path_, file_name_).c_str(), code, false);
|
||||
return SaveFile(GeneratedFileName(path_, file_name_).c_str(), code, false);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue