mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 15:43:56 +00:00
Remove unused variables (#5382)
- Fix GenerateTextFromTable (aliasing typo) - Fix unused variable in idl_gen_dart.cpp - Fix std::string passing (should be non-const value or const-reference) - Remove unused variables
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
7d7d796cd0
commit
7a63792929
@@ -82,8 +82,8 @@ class BaseGenerator {
|
|||||||
protected:
|
protected:
|
||||||
BaseGenerator(const Parser &parser, const std::string &path,
|
BaseGenerator(const Parser &parser, const std::string &path,
|
||||||
const std::string &file_name,
|
const std::string &file_name,
|
||||||
const std::string qualifying_start,
|
std::string qualifying_start,
|
||||||
const std::string qualifying_separator)
|
std::string qualifying_separator)
|
||||||
: parser_(parser),
|
: parser_(parser),
|
||||||
path_(path),
|
path_(path),
|
||||||
file_name_(file_name),
|
file_name_(file_name),
|
||||||
|
|||||||
@@ -790,7 +790,7 @@ class Parser : public ParserState {
|
|||||||
|
|
||||||
StructDef *LookupStruct(const std::string &id) const;
|
StructDef *LookupStruct(const std::string &id) const;
|
||||||
|
|
||||||
std::string UnqualifiedName(std::string fullQualifiedName);
|
std::string UnqualifiedName(const std::string &fullQualifiedName);
|
||||||
|
|
||||||
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg);
|
FLATBUFFERS_CHECKED_ERROR Error(const std::string &msg);
|
||||||
|
|
||||||
|
|||||||
@@ -72,13 +72,13 @@ const char *BaseGenerator::FlatBuffersGeneratedWarning() {
|
|||||||
std::string BaseGenerator::NamespaceDir(const Parser &parser,
|
std::string BaseGenerator::NamespaceDir(const Parser &parser,
|
||||||
const std::string &path,
|
const std::string &path,
|
||||||
const Namespace &ns) {
|
const Namespace &ns) {
|
||||||
EnsureDirExists(path.c_str());
|
EnsureDirExists(path);
|
||||||
if (parser.opts.one_file) return path;
|
if (parser.opts.one_file) return path;
|
||||||
std::string namespace_dir = path; // Either empty or ends in separator.
|
std::string namespace_dir = path; // Either empty or ends in separator.
|
||||||
auto &namespaces = ns.components;
|
auto &namespaces = ns.components;
|
||||||
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
|
||||||
namespace_dir += *it + kPathSeparator;
|
namespace_dir += *it + kPathSeparator;
|
||||||
EnsureDirExists(namespace_dir.c_str());
|
EnsureDirExists(namespace_dir);
|
||||||
}
|
}
|
||||||
return namespace_dir;
|
return namespace_dir;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ class CppGenerator : public BaseGenerator {
|
|||||||
static std::string TranslateNameSpace(const std::string &qualified_name) {
|
static std::string TranslateNameSpace(const std::string &qualified_name) {
|
||||||
std::string cpp_qualified_name = qualified_name;
|
std::string cpp_qualified_name = qualified_name;
|
||||||
size_t start_pos = 0;
|
size_t start_pos = 0;
|
||||||
while ((start_pos = cpp_qualified_name.find(".", start_pos)) !=
|
while ((start_pos = cpp_qualified_name.find('.', start_pos)) !=
|
||||||
std::string::npos) {
|
std::string::npos) {
|
||||||
cpp_qualified_name.replace(start_pos, 1, "::");
|
cpp_qualified_name.replace(start_pos, 1, "::");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,10 +105,10 @@ class DartGenerator : public BaseGenerator {
|
|||||||
static std::string ImportAliasName(const std::string &ns) {
|
static std::string ImportAliasName(const std::string &ns) {
|
||||||
std::string ret;
|
std::string ret;
|
||||||
ret.assign(ns);
|
ret.assign(ns);
|
||||||
size_t pos = ret.find(".");
|
size_t pos = ret.find('.');
|
||||||
while (pos != std::string::npos) {
|
while (pos != std::string::npos) {
|
||||||
ret.replace(pos, 1, "_");
|
ret.replace(pos, 1, "_");
|
||||||
pos = ret.find(".", pos + 1);
|
pos = ret.find('.', pos + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -409,23 +409,23 @@ class DartGenerator : public BaseGenerator {
|
|||||||
auto object_namespace = BuildNamespaceName(*struct_def.defined_namespace);
|
auto object_namespace = BuildNamespaceName(*struct_def.defined_namespace);
|
||||||
std::string code;
|
std::string code;
|
||||||
|
|
||||||
auto object_name = struct_def.name;
|
const auto &object_name = struct_def.name;
|
||||||
|
|
||||||
// Emit constructor
|
// Emit constructor
|
||||||
|
|
||||||
GenDocComment(struct_def.doc_comment, &code, "");
|
GenDocComment(struct_def.doc_comment, &code, "");
|
||||||
|
|
||||||
auto reader_name = "_" + struct_def.name + "Reader";
|
auto reader_name = "_" + object_name + "Reader";
|
||||||
auto builder_name = struct_def.name + "Builder";
|
auto builder_name = object_name + "Builder";
|
||||||
auto object_builder_name = struct_def.name + "ObjectBuilder";
|
auto object_builder_name = object_name + "ObjectBuilder";
|
||||||
|
|
||||||
std::string reader_code, builder_code;
|
std::string reader_code, builder_code;
|
||||||
|
|
||||||
code += "class " + struct_def.name + " {\n";
|
code += "class " + object_name + " {\n";
|
||||||
|
|
||||||
code += " " + struct_def.name + "._(this._bc, this._bcOffset);\n";
|
code += " " + object_name + "._(this._bc, this._bcOffset);\n";
|
||||||
if (!struct_def.fixed) {
|
if (!struct_def.fixed) {
|
||||||
code += " factory " + struct_def.name + "(List<int> bytes) {\n";
|
code += " factory " + object_name + "(List<int> bytes) {\n";
|
||||||
code += " " + _kFb + ".BufferContext rootRef = new " + _kFb +
|
code += " " + _kFb + ".BufferContext rootRef = new " + _kFb +
|
||||||
".BufferContext.fromBytes(bytes);\n";
|
".BufferContext.fromBytes(bytes);\n";
|
||||||
code += " return reader.read(rootRef, 0);\n";
|
code += " return reader.read(rootRef, 0);\n";
|
||||||
@@ -433,7 +433,7 @@ class DartGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
code += "\n";
|
code += "\n";
|
||||||
code += " static const " + _kFb + ".Reader<" + struct_def.name +
|
code += " static const " + _kFb + ".Reader<" + object_name +
|
||||||
"> reader = const " + reader_name + "();\n\n";
|
"> reader = const " + reader_name + "();\n\n";
|
||||||
|
|
||||||
code += " final " + _kFb + ".BufferContext _bc;\n";
|
code += " final " + _kFb + ".BufferContext _bc;\n";
|
||||||
@@ -454,7 +454,7 @@ class DartGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string NamespaceAliasFromUnionType(const std::string &in) {
|
std::string NamespaceAliasFromUnionType(const std::string &in) {
|
||||||
if (in.find("_") == std::string::npos) { return in; }
|
if (in.find('_') == std::string::npos) { return in; }
|
||||||
|
|
||||||
std::stringstream ss(in);
|
std::stringstream ss(in);
|
||||||
std::string item;
|
std::string item;
|
||||||
|
|||||||
@@ -1611,7 +1611,7 @@ std::string GeneralMakeRule(const Parser &parser, const std::string &path,
|
|||||||
for (auto it = parser.enums_.vec.begin(); it != parser.enums_.vec.end();
|
for (auto it = parser.enums_.vec.begin(); it != parser.enums_.vec.end();
|
||||||
++it) {
|
++it) {
|
||||||
auto &enum_def = **it;
|
auto &enum_def = **it;
|
||||||
if (make_rule != "") make_rule += " ";
|
if (!make_rule.empty()) make_rule += " ";
|
||||||
std::string directory =
|
std::string directory =
|
||||||
BaseGenerator::NamespaceDir(parser, path, *enum_def.defined_namespace);
|
BaseGenerator::NamespaceDir(parser, path, *enum_def.defined_namespace);
|
||||||
make_rule += directory + enum_def.name + lang.file_extension;
|
make_rule += directory + enum_def.name + lang.file_extension;
|
||||||
@@ -1620,7 +1620,7 @@ std::string GeneralMakeRule(const Parser &parser, const std::string &path,
|
|||||||
for (auto it = parser.structs_.vec.begin(); it != parser.structs_.vec.end();
|
for (auto it = parser.structs_.vec.begin(); it != parser.structs_.vec.end();
|
||||||
++it) {
|
++it) {
|
||||||
auto &struct_def = **it;
|
auto &struct_def = **it;
|
||||||
if (make_rule != "") make_rule += " ";
|
if (!make_rule.empty()) make_rule += " ";
|
||||||
std::string directory = BaseGenerator::NamespaceDir(
|
std::string directory = BaseGenerator::NamespaceDir(
|
||||||
parser, path, *struct_def.defined_namespace);
|
parser, path, *struct_def.defined_namespace);
|
||||||
make_rule += directory + struct_def.name + lang.file_extension;
|
make_rule += directory + struct_def.name + lang.file_extension;
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ class GoGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A single enum name member.
|
// A single enum name member.
|
||||||
void EnumNameMember(const EnumDef &enum_def, const EnumVal ev,
|
void EnumNameMember(const EnumDef &enum_def, const EnumVal &ev,
|
||||||
size_t max_name_length, std::string *code_ptr) {
|
size_t max_name_length, std::string *code_ptr) {
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
code += "\t";
|
code += "\t";
|
||||||
@@ -228,7 +228,7 @@ class GoGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A single enum value member.
|
// A single enum value member.
|
||||||
void EnumValueMember(const EnumDef &enum_def, const EnumVal ev,
|
void EnumValueMember(const EnumDef &enum_def, const EnumVal &ev,
|
||||||
size_t max_name_length, std::string *code_ptr) {
|
size_t max_name_length, std::string *code_ptr) {
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
code += "\t\"";
|
code += "\t\"";
|
||||||
@@ -895,7 +895,7 @@ class GoGenerator : public BaseGenerator {
|
|||||||
EndBuilderBody(code_ptr);
|
EndBuilderBody(code_ptr);
|
||||||
}
|
}
|
||||||
// Begin by declaring namespace and imports.
|
// Begin by declaring namespace and imports.
|
||||||
void BeginFile(const std::string name_space_name, const bool needs_imports,
|
void BeginFile(const std::string &name_space_name, const bool needs_imports,
|
||||||
const bool is_enum, std::string *code_ptr) {
|
const bool is_enum, std::string *code_ptr) {
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
code = code + "// Code generated by the FlatBuffers compiler. DO NOT EDIT.\n\n";
|
code = code + "// Code generated by the FlatBuffers compiler. DO NOT EDIT.\n\n";
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ class FlatBufPrinter : public grpc_generator::Printer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Print(const char *s) {
|
void Print(const char *s) {
|
||||||
if (s == nullptr || std::strlen(s) == 0) { return; }
|
if (s == nullptr || *s == '\0') { return; }
|
||||||
// Add this string, but for each part separated by \n, add indentation.
|
// Add this string, but for each part separated by \n, add indentation.
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Current indentation.
|
// Current indentation.
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ class JsTsGenerator : public BaseGenerator {
|
|||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
std::string &exports = *exports_ptr;
|
std::string &exports = *exports_ptr;
|
||||||
for (auto it = sorted_namespaces.begin(); it != sorted_namespaces.end();
|
for (auto it = sorted_namespaces.begin(); it != sorted_namespaces.end();
|
||||||
it++) {
|
++it) {
|
||||||
if (lang_.language == IDLOptions::kTs) {
|
if (lang_.language == IDLOptions::kTs) {
|
||||||
if (it->find('.') == std::string::npos) {
|
if (it->find('.') == std::string::npos) {
|
||||||
code += "import { flatbuffers } from \"./flatbuffers\"\n";
|
code += "import { flatbuffers } from \"./flatbuffers\"\n";
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ namespace lua {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Begin enum code with a class declaration.
|
// Begin enum code with a class declaration.
|
||||||
void BeginEnum(const std::string class_name, std::string *code_ptr) {
|
void BeginEnum(const std::string &class_name, std::string *code_ptr) {
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
code += "local " + class_name + " = {\n";
|
code += "local " + class_name + " = {\n";
|
||||||
}
|
}
|
||||||
@@ -683,7 +683,7 @@ namespace lua {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Begin by declaring namespace and imports.
|
// Begin by declaring namespace and imports.
|
||||||
void BeginFile(const std::string name_space_name, const bool needs_imports,
|
void BeginFile(const std::string &name_space_name, const bool needs_imports,
|
||||||
std::string *code_ptr) {
|
std::string *code_ptr) {
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
code += std::string(Comment) + FlatBuffersGeneratedWarning() + "\n\n";
|
code += std::string(Comment) + FlatBuffersGeneratedWarning() + "\n\n";
|
||||||
|
|||||||
@@ -232,7 +232,6 @@ class PhpGenerator : public BaseGenerator {
|
|||||||
// Get the value of a table's scalar.
|
// Get the value of a table's scalar.
|
||||||
void GetScalarFieldOfTable(const FieldDef &field, std::string *code_ptr) {
|
void GetScalarFieldOfTable(const FieldDef &field, std::string *code_ptr) {
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
std::string getter = GenGetter(field.value.type);
|
|
||||||
|
|
||||||
code += Indent + "/**\n";
|
code += Indent + "/**\n";
|
||||||
code += Indent + " * @return " + GenTypeGet(field.value.type) + "\n";
|
code += Indent + " * @return " + GenTypeGet(field.value.type) + "\n";
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class PythonGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Begin enum code with a class declaration.
|
// Begin enum code with a class declaration.
|
||||||
void BeginEnum(const std::string class_name, std::string *code_ptr) {
|
void BeginEnum(const std::string &class_name, std::string *code_ptr) {
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
code += "class " + class_name + "(object):\n";
|
code += "class " + class_name + "(object):\n";
|
||||||
}
|
}
|
||||||
@@ -750,7 +750,7 @@ class PythonGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Begin by declaring namespace and imports.
|
// Begin by declaring namespace and imports.
|
||||||
void BeginFile(const std::string name_space_name, const bool needs_imports,
|
void BeginFile(const std::string &name_space_name, const bool needs_imports,
|
||||||
std::string *code_ptr) {
|
std::string *code_ptr) {
|
||||||
std::string &code = *code_ptr;
|
std::string &code = *code_ptr;
|
||||||
code = code + "# " + FlatBuffersGeneratedWarning() + "\n\n";
|
code = code + "# " + FlatBuffersGeneratedWarning() + "\n\n";
|
||||||
|
|||||||
@@ -449,7 +449,7 @@ class RustGenerator : public BaseGenerator {
|
|||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
|
|
||||||
stream << "::";
|
stream << "::";
|
||||||
for (auto d = dst->components.begin(); d != dst->components.end(); d++) {
|
for (auto d = dst->components.begin(); d != dst->components.end(); ++d) {
|
||||||
stream << MakeSnakeCase(*d) + "::";
|
stream << MakeSnakeCase(*d) + "::";
|
||||||
}
|
}
|
||||||
return stream.str();
|
return stream.str();
|
||||||
@@ -481,15 +481,15 @@ class RustGenerator : public BaseGenerator {
|
|||||||
if (s == src->components.end()) { break; }
|
if (s == src->components.end()) { break; }
|
||||||
if (d == dst->components.end()) { break; }
|
if (d == dst->components.end()) { break; }
|
||||||
if (*s != *d) { break; }
|
if (*s != *d) { break; }
|
||||||
s++;
|
++s;
|
||||||
d++;
|
++d;
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; s != src->components.end(); s++) {
|
for (; s != src->components.end(); ++s) {
|
||||||
stream << "super::";
|
stream << "super::";
|
||||||
}
|
}
|
||||||
for (; d != dst->components.end(); d++) {
|
for (; d != dst->components.end(); ++d) {
|
||||||
stream << MakeSnakeCase(*d) + "::";
|
stream << MakeSnakeCase(*d) + "::";
|
||||||
}
|
}
|
||||||
return stream.str();
|
return stream.str();
|
||||||
@@ -758,7 +758,7 @@ class RustGenerator : public BaseGenerator {
|
|||||||
// the vtable, or
|
// the vtable, or
|
||||||
// 3) return a hardcoded value because the vtable field value is set to zero.
|
// 3) return a hardcoded value because the vtable field value is set to zero.
|
||||||
std::string TableBuilderArgsDefnType(const FieldDef &field,
|
std::string TableBuilderArgsDefnType(const FieldDef &field,
|
||||||
const std::string lifetime) {
|
const std::string &lifetime) {
|
||||||
const Type& type = field.value.type;
|
const Type& type = field.value.type;
|
||||||
|
|
||||||
switch (GetFullType(type)) {
|
switch (GetFullType(type)) {
|
||||||
@@ -786,7 +786,6 @@ class RustGenerator : public BaseGenerator {
|
|||||||
return typname;
|
return typname;
|
||||||
}
|
}
|
||||||
case ftUnionValue: {
|
case ftUnionValue: {
|
||||||
const auto typname = WrapInNameSpace(*type.enum_def);
|
|
||||||
return "Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>";
|
return "Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,10 +835,11 @@ class RustGenerator : public BaseGenerator {
|
|||||||
return GetDefaultScalarValue(field);
|
return GetDefaultScalarValue(field);
|
||||||
}
|
}
|
||||||
std::string TableBuilderAddFuncDefaultValue(const FieldDef &field) {
|
std::string TableBuilderAddFuncDefaultValue(const FieldDef &field) {
|
||||||
|
// All branches of switch do the same action!
|
||||||
switch (GetFullType(field.value.type)) {
|
switch (GetFullType(field.value.type)) {
|
||||||
case ftUnionKey:
|
case ftUnionKey:
|
||||||
case ftEnumKey: {
|
case ftEnumKey: {
|
||||||
const std::string basetype = GetTypeBasic(field.value.type);
|
const std::string basetype = GetTypeBasic(field.value.type); //<- never used
|
||||||
return GetDefaultScalarValue(field);
|
return GetDefaultScalarValue(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -848,7 +848,7 @@ class RustGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string TableBuilderArgsAddFuncType(const FieldDef &field,
|
std::string TableBuilderArgsAddFuncType(const FieldDef &field,
|
||||||
const std::string lifetime) {
|
const std::string &lifetime) {
|
||||||
const Type& type = field.value.type;
|
const Type& type = field.value.type;
|
||||||
|
|
||||||
switch (GetFullType(field.value.type)) {
|
switch (GetFullType(field.value.type)) {
|
||||||
@@ -883,7 +883,6 @@ class RustGenerator : public BaseGenerator {
|
|||||||
", " + typname + ">>";
|
", " + typname + ">>";
|
||||||
}
|
}
|
||||||
case ftVectorOfUnionValue: {
|
case ftVectorOfUnionValue: {
|
||||||
const auto typname = WrapInNameSpace(*type.enum_def);
|
|
||||||
return "flatbuffers::WIPOffset<flatbuffers::Vector<" + lifetime + \
|
return "flatbuffers::WIPOffset<flatbuffers::Vector<" + lifetime + \
|
||||||
", flatbuffers::ForwardsUOffset<flatbuffers::Table<" + \
|
", flatbuffers::ForwardsUOffset<flatbuffers::Table<" + \
|
||||||
lifetime + ">>>";
|
lifetime + ">>>";
|
||||||
@@ -916,7 +915,6 @@ class RustGenerator : public BaseGenerator {
|
|||||||
return typname;
|
return typname;
|
||||||
}
|
}
|
||||||
case ftUnionValue: {
|
case ftUnionValue: {
|
||||||
const auto typname = WrapInNameSpace(*type.enum_def);
|
|
||||||
return "flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>";
|
return "flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -970,7 +968,7 @@ class RustGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string GenTableAccessorFuncReturnType(const FieldDef &field,
|
std::string GenTableAccessorFuncReturnType(const FieldDef &field,
|
||||||
const std::string lifetime) {
|
const std::string &lifetime) {
|
||||||
const Type& type = field.value.type;
|
const Type& type = field.value.type;
|
||||||
|
|
||||||
switch (GetFullType(field.value.type)) {
|
switch (GetFullType(field.value.type)) {
|
||||||
@@ -1041,8 +1039,8 @@ class RustGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string GenTableAccessorFuncBody(const FieldDef &field,
|
std::string GenTableAccessorFuncBody(const FieldDef &field,
|
||||||
const std::string lifetime,
|
const std::string &lifetime,
|
||||||
const std::string offset_prefix) {
|
const std::string &offset_prefix) {
|
||||||
const std::string offset_name = offset_prefix + "::" + \
|
const std::string offset_name = offset_prefix + "::" + \
|
||||||
GetFieldOffsetName(field);
|
GetFieldOffsetName(field);
|
||||||
const Type& type = field.value.type;
|
const Type& type = field.value.type;
|
||||||
@@ -1072,7 +1070,7 @@ class RustGenerator : public BaseGenerator {
|
|||||||
}
|
}
|
||||||
case ftUnionKey:
|
case ftUnionKey:
|
||||||
case ftEnumKey: {
|
case ftEnumKey: {
|
||||||
const auto underlying_typname = GetTypeBasic(type);
|
const auto underlying_typname = GetTypeBasic(type); //<- never used
|
||||||
const auto typname = WrapInNameSpace(*type.enum_def);
|
const auto typname = WrapInNameSpace(*type.enum_def);
|
||||||
const auto default_value = GetDefaultScalarValue(field);
|
const auto default_value = GetDefaultScalarValue(field);
|
||||||
return "self._tab.get::<" + typname + ">(" + offset_name + \
|
return "self._tab.get::<" + typname + ">(" + offset_name + \
|
||||||
@@ -1394,8 +1392,6 @@ class RustGenerator : public BaseGenerator {
|
|||||||
const bool is_scalar = IsScalar(field.value.type.base_type);
|
const bool is_scalar = IsScalar(field.value.type.base_type);
|
||||||
|
|
||||||
std::string offset = GetFieldOffsetName(field);
|
std::string offset = GetFieldOffsetName(field);
|
||||||
std::string name = Name(field);
|
|
||||||
std::string value = GetDefaultScalarValue(field);
|
|
||||||
|
|
||||||
// Generate functions to add data, which take one of two forms.
|
// Generate functions to add data, which take one of two forms.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -309,10 +309,10 @@ bool GenerateTextFromTable(const Parser &parser, const void *table,
|
|||||||
if (struct_def == nullptr) {
|
if (struct_def == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto text = *_text;
|
auto &text = *_text;
|
||||||
text.reserve(1024); // Reduce amount of inevitable reallocs.
|
text.reserve(1024); // Reduce amount of inevitable reallocs.
|
||||||
auto root = static_cast<const Table *>(table);
|
auto root = static_cast<const Table *>(table);
|
||||||
if (!GenStruct(*struct_def, root, 0, parser.opts, _text)) {
|
if (!GenStruct(*struct_def, root, 0, parser.opts, &text)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
text += NewLine(parser.opts);
|
text += NewLine(parser.opts);
|
||||||
|
|||||||
@@ -2099,7 +2099,7 @@ Namespace *Parser::UniqueNamespace(Namespace *ns) {
|
|||||||
return ns;
|
return ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Parser::UnqualifiedName(std::string full_qualified_name) {
|
std::string Parser::UnqualifiedName(const std::string &full_qualified_name) {
|
||||||
Namespace *ns = new Namespace();
|
Namespace *ns = new Namespace();
|
||||||
|
|
||||||
std::size_t current, previous = 0;
|
std::size_t current, previous = 0;
|
||||||
@@ -3066,13 +3066,12 @@ bool StructDef::Deserialize(Parser &parser, const reflection::Object *object) {
|
|||||||
name = parser.UnqualifiedName(object->name()->str());
|
name = parser.UnqualifiedName(object->name()->str());
|
||||||
predecl = false;
|
predecl = false;
|
||||||
sortbysize = attributes.Lookup("original_order") == nullptr && !fixed;
|
sortbysize = attributes.Lookup("original_order") == nullptr && !fixed;
|
||||||
std::vector<uoffset_t> indexes =
|
const auto& of = *(object->fields());
|
||||||
std::vector<uoffset_t>(object->fields()->size());
|
auto indexes = std::vector<uoffset_t>(of.size());
|
||||||
for (uoffset_t i = 0; i < object->fields()->size(); i++)
|
for (uoffset_t i = 0; i < of.size(); i++) indexes[of.Get(i)->id()] = i;
|
||||||
indexes[object->fields()->Get(i)->id()] = i;
|
|
||||||
size_t tmp_struct_size = 0;
|
size_t tmp_struct_size = 0;
|
||||||
for (size_t i = 0; i < indexes.size(); i++) {
|
for (size_t i = 0; i < indexes.size(); i++) {
|
||||||
auto field = object->fields()->Get(indexes[i]);
|
auto field = of.Get(indexes[i]);
|
||||||
auto field_def = new FieldDef();
|
auto field_def = new FieldDef();
|
||||||
if (!field_def->Deserialize(parser, field) ||
|
if (!field_def->Deserialize(parser, field) ||
|
||||||
fields.Add(field_def->name, field_def)) {
|
fields.Add(field_def->name, field_def)) {
|
||||||
@@ -3084,7 +3083,7 @@ bool StructDef::Deserialize(Parser &parser, const reflection::Object *object) {
|
|||||||
auto size = InlineSize(field_def->value.type);
|
auto size = InlineSize(field_def->value.type);
|
||||||
auto next_field =
|
auto next_field =
|
||||||
i + 1 < indexes.size()
|
i + 1 < indexes.size()
|
||||||
? object->fields()->Get(indexes[i+1])
|
? of.Get(indexes[i+1])
|
||||||
: nullptr;
|
: nullptr;
|
||||||
tmp_struct_size += size;
|
tmp_struct_size += size;
|
||||||
field_def->padding =
|
field_def->padding =
|
||||||
|
|||||||
@@ -127,12 +127,12 @@ static const char kPathSeparatorWindows = '\\';
|
|||||||
static const char *PathSeparatorSet = "\\/"; // Intentionally no ':'
|
static const char *PathSeparatorSet = "\\/"; // Intentionally no ':'
|
||||||
|
|
||||||
std::string StripExtension(const std::string &filepath) {
|
std::string StripExtension(const std::string &filepath) {
|
||||||
size_t i = filepath.find_last_of(".");
|
size_t i = filepath.find_last_of('.');
|
||||||
return i != std::string::npos ? filepath.substr(0, i) : filepath;
|
return i != std::string::npos ? filepath.substr(0, i) : filepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetExtension(const std::string &filepath) {
|
std::string GetExtension(const std::string &filepath) {
|
||||||
size_t i = filepath.find_last_of(".");
|
size_t i = filepath.find_last_of('.');
|
||||||
return i != std::string::npos ? filepath.substr(i + 1) : "";
|
return i != std::string::npos ? filepath.substr(i + 1) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user