mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-09 14:46:26 +00:00
Made all C++ files clang-formatted.
Also added missing generated files. Change-Id: Ifd22a643a08e3f2edfce92812ed57b87fc0e1875
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
|
||||
// independent from idl_parser, since this code is not needed for most clients
|
||||
|
||||
#include "flatbuffers/code_generators.h"
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/util.h"
|
||||
#include "flatbuffers/code_generators.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
|
||||
@@ -27,16 +27,15 @@ static std::string GenType(const Type &type, bool underlying = false) {
|
||||
switch (type.base_type) {
|
||||
case BASE_TYPE_STRUCT:
|
||||
return type.struct_def->defined_namespace->GetFullyQualifiedName(
|
||||
type.struct_def->name);
|
||||
case BASE_TYPE_VECTOR:
|
||||
return "[" + GenType(type.VectorType()) + "]";
|
||||
type.struct_def->name);
|
||||
case BASE_TYPE_VECTOR: return "[" + GenType(type.VectorType()) + "]";
|
||||
default:
|
||||
if (type.enum_def && !underlying) {
|
||||
return type.enum_def->defined_namespace->GetFullyQualifiedName(
|
||||
type.enum_def->name);
|
||||
} else {
|
||||
return kTypeNames[type.base_type];
|
||||
}
|
||||
if (type.enum_def && !underlying) {
|
||||
return type.enum_def->defined_namespace->GetFullyQualifiedName(
|
||||
type.enum_def->name);
|
||||
} else {
|
||||
return kTypeNames[type.base_type];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +46,7 @@ static void GenNameSpace(const Namespace &name_space, std::string *_schema,
|
||||
auto &schema = *_schema;
|
||||
schema += "namespace ";
|
||||
for (auto it = name_space.components.begin();
|
||||
it != name_space.components.end(); ++it) {
|
||||
it != name_space.components.end(); ++it) {
|
||||
if (it != name_space.components.begin()) schema += ".";
|
||||
schema += *it;
|
||||
}
|
||||
@@ -69,6 +68,7 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name) {
|
||||
std::string schema;
|
||||
schema += "// Generated from " + file_name + ".proto\n\n";
|
||||
if (parser.opts.include_dependence_headers) {
|
||||
// clang-format off
|
||||
#ifdef FBS_GEN_INCLUDES // TODO: currently all in one file.
|
||||
int num_includes = 0;
|
||||
for (auto it = parser.included_files_.begin();
|
||||
@@ -82,18 +82,19 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name) {
|
||||
}
|
||||
if (num_includes) schema += "\n";
|
||||
#endif
|
||||
// clang-format on
|
||||
}
|
||||
// Generate code for all the enum declarations.
|
||||
const Namespace *last_namespace = nullptr;
|
||||
for (auto enum_def_it = parser.enums_.vec.begin();
|
||||
enum_def_it != parser.enums_.vec.end(); ++enum_def_it) {
|
||||
enum_def_it != parser.enums_.vec.end(); ++enum_def_it) {
|
||||
EnumDef &enum_def = **enum_def_it;
|
||||
GenNameSpace(*enum_def.defined_namespace, &schema, &last_namespace);
|
||||
GenComment(enum_def.doc_comment, &schema, nullptr);
|
||||
schema += "enum " + enum_def.name + " : ";
|
||||
schema += GenType(enum_def.underlying_type, true) + " {\n";
|
||||
for (auto it = enum_def.vals.vec.begin();
|
||||
it != enum_def.vals.vec.end(); ++it) {
|
||||
for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end();
|
||||
++it) {
|
||||
auto &ev = **it;
|
||||
GenComment(ev.doc_comment, &schema, nullptr, " ");
|
||||
schema += " " + ev.name + " = " + NumToString(ev.value) + ",\n";
|
||||
@@ -101,14 +102,14 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name) {
|
||||
schema += "}\n\n";
|
||||
}
|
||||
// Generate code for all structs/tables.
|
||||
for (auto it = parser.structs_.vec.begin();
|
||||
it != parser.structs_.vec.end(); ++it) {
|
||||
for (auto it = parser.structs_.vec.begin(); it != parser.structs_.vec.end();
|
||||
++it) {
|
||||
StructDef &struct_def = **it;
|
||||
GenNameSpace(*struct_def.defined_namespace, &schema, &last_namespace);
|
||||
GenComment(struct_def.doc_comment, &schema, nullptr);
|
||||
schema += "table " + struct_def.name + " {\n";
|
||||
for (auto field_it = struct_def.fields.vec.begin();
|
||||
field_it != struct_def.fields.vec.end(); ++field_it) {
|
||||
field_it != struct_def.fields.vec.end(); ++field_it) {
|
||||
auto &field = **field_it;
|
||||
if (field.value.type.base_type != BASE_TYPE_UTYPE) {
|
||||
GenComment(field.doc_comment, &schema, nullptr, " ");
|
||||
@@ -123,12 +124,10 @@ std::string GenerateFBS(const Parser &parser, const std::string &file_name) {
|
||||
return schema;
|
||||
}
|
||||
|
||||
bool GenerateFBS(const Parser &parser,
|
||||
const std::string &path,
|
||||
bool GenerateFBS(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name) {
|
||||
return SaveFile((path + file_name + ".fbs").c_str(),
|
||||
GenerateFBS(parser, file_name), false);
|
||||
}
|
||||
|
||||
} // namespace flatbuffers
|
||||
|
||||
|
||||
Reference in New Issue
Block a user