mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-03 12:21:23 +00:00
removed extern code generation declarations preferring direct includes (#7948)
* removed extern code generation definitions, preferring direct includes * add static to functions * remove idl_gen_lua
This commit is contained in:
@@ -104,7 +104,7 @@ struct JsonPrinter {
|
||||
// "[]".
|
||||
template<typename Container, typename SizeT = typename Container::size_type>
|
||||
const char *PrintContainer(PrintScalarTag, const Container &c, SizeT size,
|
||||
const Type &type, int indent, const uint8_t *) {
|
||||
const Type &type, int indent, const uint8_t *) {
|
||||
const auto elem_indent = indent + Indent();
|
||||
text += '[';
|
||||
AddNewLine();
|
||||
@@ -126,7 +126,8 @@ struct JsonPrinter {
|
||||
// "[]".
|
||||
template<typename Container, typename SizeT = typename Container::size_type>
|
||||
const char *PrintContainer(PrintPointerTag, const Container &c, SizeT size,
|
||||
const Type &type, int indent, const uint8_t *prev_val) {
|
||||
const Type &type, int indent,
|
||||
const uint8_t *prev_val) {
|
||||
const auto is_struct = IsStruct(type);
|
||||
const auto elem_indent = indent + Indent();
|
||||
text += '[';
|
||||
@@ -152,7 +153,7 @@ struct JsonPrinter {
|
||||
|
||||
template<typename T, typename SizeT = uoffset_t>
|
||||
const char *PrintVector(const void *val, const Type &type, int indent,
|
||||
const uint8_t *prev_val) {
|
||||
const uint8_t *prev_val) {
|
||||
typedef Vector<T, SizeT> Container;
|
||||
typedef typename PrintTag<typename Container::return_type>::type tag;
|
||||
auto &vec = *reinterpret_cast<const Container *>(val);
|
||||
@@ -163,8 +164,8 @@ struct JsonPrinter {
|
||||
// Print an array a sequence of JSON values, comma separated, wrapped in "[]".
|
||||
template<typename T>
|
||||
const char *PrintArray(const void *val, uint16_t size, const Type &type,
|
||||
|
||||
int indent) {
|
||||
|
||||
int indent) {
|
||||
typedef Array<T, 0xFFFF> Container;
|
||||
typedef typename PrintTag<typename Container::return_type>::type tag;
|
||||
auto &arr = *reinterpret_cast<const Container *>(val);
|
||||
@@ -172,7 +173,7 @@ struct JsonPrinter {
|
||||
}
|
||||
|
||||
const char *PrintOffset(const void *val, const Type &type, int indent,
|
||||
const uint8_t *prev_val, soffset_t vector_index) {
|
||||
const uint8_t *prev_val, soffset_t vector_index) {
|
||||
switch (type.base_type) {
|
||||
case BASE_TYPE_UNION: {
|
||||
// If this assert hits, you have an corrupt buffer, a union type field
|
||||
@@ -196,8 +197,8 @@ struct JsonPrinter {
|
||||
indent);
|
||||
case BASE_TYPE_STRING: {
|
||||
auto s = reinterpret_cast<const String *>(val);
|
||||
bool ok = EscapeString(s->c_str(), s->size(), &text, opts.allow_non_utf8,
|
||||
opts.natural_utf8);
|
||||
bool ok = EscapeString(s->c_str(), s->size(), &text,
|
||||
opts.allow_non_utf8, opts.natural_utf8);
|
||||
return ok ? nullptr : "string contains non-utf8 bytes";
|
||||
}
|
||||
case BASE_TYPE_VECTOR: {
|
||||
@@ -235,9 +236,7 @@ struct JsonPrinter {
|
||||
// clang-format on
|
||||
return nullptr;
|
||||
}
|
||||
default:
|
||||
FLATBUFFERS_ASSERT(0);
|
||||
return "unknown type";
|
||||
default: FLATBUFFERS_ASSERT(0); return "unknown type";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,15 +264,14 @@ struct JsonPrinter {
|
||||
text += "null";
|
||||
}
|
||||
} else {
|
||||
PrintScalar(
|
||||
table->GetField<T>(fd.value.offset, GetFieldDefault<T>(fd)),
|
||||
fd.value.type, indent);
|
||||
PrintScalar(table->GetField<T>(fd.value.offset, GetFieldDefault<T>(fd)),
|
||||
fd.value.type, indent);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate text for non-scalar field.
|
||||
const char *GenFieldOffset(const FieldDef &fd, const Table *table, bool fixed,
|
||||
int indent, const uint8_t *prev_val) {
|
||||
int indent, const uint8_t *prev_val) {
|
||||
const void *val = nullptr;
|
||||
if (fixed) {
|
||||
// The only non-scalar fields in structs are structs or arrays.
|
||||
@@ -372,7 +370,8 @@ struct JsonPrinter {
|
||||
};
|
||||
|
||||
static const char *GenerateTextImpl(const Parser &parser, const Table *table,
|
||||
const StructDef &struct_def, std::string *_text) {
|
||||
const StructDef &struct_def,
|
||||
std::string *_text) {
|
||||
JsonPrinter printer(parser, *_text);
|
||||
auto err = printer.GenStruct(struct_def, table, 0);
|
||||
if (err) return err;
|
||||
@@ -382,7 +381,8 @@ static const char *GenerateTextImpl(const Parser &parser, const Table *table,
|
||||
|
||||
// Generate a text representation of a flatbuffer in JSON format.
|
||||
const char *GenerateTextFromTable(const Parser &parser, const void *table,
|
||||
const std::string &table_name, std::string *_text) {
|
||||
const std::string &table_name,
|
||||
std::string *_text) {
|
||||
auto struct_def = parser.LookupStruct(table_name);
|
||||
if (struct_def == nullptr) { return "unknown struct"; }
|
||||
auto root = static_cast<const Table *>(table);
|
||||
@@ -391,7 +391,7 @@ const char *GenerateTextFromTable(const Parser &parser, const void *table,
|
||||
|
||||
// Generate a text representation of a flatbuffer in JSON format.
|
||||
const char *GenerateText(const Parser &parser, const void *flatbuffer,
|
||||
std::string *_text) {
|
||||
std::string *_text) {
|
||||
FLATBUFFERS_ASSERT(parser.root_struct_def_); // call SetRootType()
|
||||
auto root = parser.opts.size_prefixed ? GetSizePrefixedRoot<Table>(flatbuffer)
|
||||
: GetRoot<Table>(flatbuffer);
|
||||
@@ -403,8 +403,9 @@ static std::string TextFileName(const std::string &path,
|
||||
return path + file_name + ".json";
|
||||
}
|
||||
|
||||
const char *GenerateTextFile(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name) {
|
||||
static const char *GenerateTextFile(const Parser &parser,
|
||||
const std::string &path,
|
||||
const std::string &file_name) {
|
||||
if (parser.opts.use_flexbuffers) {
|
||||
std::string json;
|
||||
parser.flex_root_.ToString(true, parser.opts.strict_json, json);
|
||||
@@ -423,8 +424,8 @@ const char *GenerateTextFile(const Parser &parser, const std::string &path,
|
||||
: "SaveFile failed";
|
||||
}
|
||||
|
||||
std::string TextMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name) {
|
||||
static std::string TextMakeRule(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name) {
|
||||
if (!parser.builder_.GetSize() || !parser.root_struct_def_) return "";
|
||||
std::string filebase =
|
||||
flatbuffers::StripPath(flatbuffers::StripExtension(file_name));
|
||||
|
||||
Reference in New Issue
Block a user