Iterate through all definitions we haven't generate code for (enums, structs, and tables) and output them to a single file.
| 234 | // Iterate through all definitions we haven't generate code for (enums, |
| 235 | // structs, and tables) and output them to a single file. |
| 236 | bool generate() { |
| 237 | bool need_flatbuffer_include = true; |
| 238 | code_.Clear(); |
| 239 | code_ += "// " + std::string(FlatBuffersGeneratedWarning()) + "\n\n"; |
| 240 | |
| 241 | const auto include_guard = GenIncludeGuard(); |
| 242 | code_ += "#ifndef " + include_guard; |
| 243 | code_ += "#define " + include_guard; |
| 244 | code_ += ""; |
| 245 | |
| 246 | if (parser_.opts.gen_nullable) { |
| 247 | code_ += "#pragma clang system_header\n\n"; |
| 248 | } |
| 249 | for (auto& iter : parser_.included_files_) { |
| 250 | if (!iter.second.empty()) { |
| 251 | need_flatbuffer_include = false; |
| 252 | } |
| 253 | } |
| 254 | need_flatbuffer_include = need_flatbuffer_include && parser_.native_included_files_.empty(); |
| 255 | if (need_flatbuffer_include) { |
| 256 | code_ += "#include \"flatbuffers/flatbuffers.h\""; |
| 257 | if (parser_.uses_flexbuffers_) { |
| 258 | code_ += "#include \"flatbuffers/flexbuffers.h\""; |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | code_ += ""; |
| 263 | |
| 264 | if (parser_.opts.include_dependence_headers) { GenIncludeDependencies(); } |
| 265 | |
| 266 | FLATBUFFERS_ASSERT(!cur_name_space_); |
| 267 | |
| 268 | // Generate forward declarations for all structs/tables, since they may |
| 269 | // have circular references. |
| 270 | for (auto it = parser_.structs_.vec.begin(); |
| 271 | it != parser_.structs_.vec.end(); ++it) { |
| 272 | const auto &struct_def = **it; |
| 273 | if (!struct_def.generated) { |
| 274 | SetNameSpace(struct_def.defined_namespace); |
| 275 | code_ += "struct " + Name(struct_def) + ";"; |
| 276 | if (parser_.opts.generate_object_based_api) { |
| 277 | auto nativeName = NativeName(Name(struct_def), &struct_def, parser_.opts); |
| 278 | if (!struct_def.fixed) { |
| 279 | code_ += "struct " + nativeName + ";"; |
| 280 | } |
| 281 | } |
| 282 | code_ += ""; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // Generate forward declarations for all equal operators |
| 287 | if (parser_.opts.generate_object_based_api && parser_.opts.gen_compare) { |
| 288 | for (auto it = parser_.structs_.vec.begin(); |
| 289 | it != parser_.structs_.vec.end(); ++it) { |
| 290 | const auto &struct_def = **it; |
| 291 | if (!struct_def.generated) { |
| 292 | SetNameSpace(struct_def.defined_namespace); |
| 293 | auto nativeName = NativeName(Name(struct_def), &struct_def, parser_.opts); |
no test coverage detected