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,12 +678,12 @@ 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";
|
||||
|
@ -699,10 +699,8 @@ class JsGenerator : public BaseGenerator {
|
|||
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