summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Glavnyy <31897320+vglavnyy@users.noreply.github.com>2019-07-02 01:38:21 +0700
committerWouter van Oortmerssen <aardappel@gmail.com>2019-07-01 11:38:21 -0700
commit7a63792929e2ab6edbbc2b6270a48c74e7022f96 (patch)
tree7701e36dfdaa27f591e439d2b1a62d1e9af9f2a2
parent7d7d796cd09dfaed3aed5cd1f973b86f8c2d79bb (diff)
downloadflatbuffers-7a63792929e2ab6edbbc2b6270a48c74e7022f96.tar.gz
flatbuffers-7a63792929e2ab6edbbc2b6270a48c74e7022f96.tar.bz2
flatbuffers-7a63792929e2ab6edbbc2b6270a48c74e7022f96.zip
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
-rw-r--r--include/flatbuffers/code_generators.h4
-rw-r--r--include/flatbuffers/idl.h2
-rw-r--r--src/code_generators.cpp4
-rw-r--r--src/idl_gen_cpp.cpp2
-rw-r--r--src/idl_gen_dart.cpp22
-rw-r--r--src/idl_gen_general.cpp4
-rw-r--r--src/idl_gen_go.cpp6
-rw-r--r--src/idl_gen_grpc.cpp2
-rw-r--r--src/idl_gen_js_ts.cpp2
-rw-r--r--src/idl_gen_lua.cpp4
-rw-r--r--src/idl_gen_php.cpp1
-rw-r--r--src/idl_gen_python.cpp4
-rw-r--r--src/idl_gen_rust.cpp32
-rw-r--r--src/idl_gen_text.cpp4
-rw-r--r--src/idl_parser.cpp13
-rw-r--r--src/util.cpp4
16 files changed, 52 insertions, 58 deletions
diff --git a/include/flatbuffers/code_generators.h b/include/flatbuffers/code_generators.h
index 33307750..ae3229d0 100644
--- a/include/flatbuffers/code_generators.h
+++ b/include/flatbuffers/code_generators.h
@@ -82,8 +82,8 @@ class BaseGenerator {
protected:
BaseGenerator(const Parser &parser, const std::string &path,
const std::string &file_name,
- const std::string qualifying_start,
- const std::string qualifying_separator)
+ std::string qualifying_start,
+ std::string qualifying_separator)
: parser_(parser),
path_(path),
file_name_(file_name),
diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h
index 48dda408..2ec53919 100644
--- a/include/flatbuffers/idl.h
+++ b/include/flatbuffers/idl.h
@@ -790,7 +790,7 @@ class Parser : public ParserState {
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);
diff --git a/src/code_generators.cpp b/src/code_generators.cpp
index 9e6a2690..a3078e02 100644
--- a/src/code_generators.cpp
+++ b/src/code_generators.cpp
@@ -72,13 +72,13 @@ const char *BaseGenerator::FlatBuffersGeneratedWarning() {
std::string BaseGenerator::NamespaceDir(const Parser &parser,
const std::string &path,
const Namespace &ns) {
- EnsureDirExists(path.c_str());
+ EnsureDirExists(path);
if (parser.opts.one_file) return path;
std::string namespace_dir = path; // Either empty or ends in separator.
auto &namespaces = ns.components;
for (auto it = namespaces.begin(); it != namespaces.end(); ++it) {
namespace_dir += *it + kPathSeparator;
- EnsureDirExists(namespace_dir.c_str());
+ EnsureDirExists(namespace_dir);
}
return namespace_dir;
}
diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp
index 6b33f1d9..322b7f5f 100644
--- a/src/idl_gen_cpp.cpp
+++ b/src/idl_gen_cpp.cpp
@@ -520,7 +520,7 @@ class CppGenerator : public BaseGenerator {
static std::string TranslateNameSpace(const std::string &qualified_name) {
std::string cpp_qualified_name = qualified_name;
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) {
cpp_qualified_name.replace(start_pos, 1, "::");
}
diff --git a/src/idl_gen_dart.cpp b/src/idl_gen_dart.cpp
index 3cbcd990..2346a85e 100644
--- a/src/idl_gen_dart.cpp
+++ b/src/idl_gen_dart.cpp
@@ -105,10 +105,10 @@ class DartGenerator : public BaseGenerator {
static std::string ImportAliasName(const std::string &ns) {
std::string ret;
ret.assign(ns);
- size_t pos = ret.find(".");
+ size_t pos = ret.find('.');
while (pos != std::string::npos) {
ret.replace(pos, 1, "_");
- pos = ret.find(".", pos + 1);
+ pos = ret.find('.', pos + 1);
}
return ret;
@@ -409,23 +409,23 @@ class DartGenerator : public BaseGenerator {
auto object_namespace = BuildNamespaceName(*struct_def.defined_namespace);
std::string code;
- auto object_name = struct_def.name;
+ const auto &object_name = struct_def.name;
// Emit constructor
GenDocComment(struct_def.doc_comment, &code, "");
- auto reader_name = "_" + struct_def.name + "Reader";
- auto builder_name = struct_def.name + "Builder";
- auto object_builder_name = struct_def.name + "ObjectBuilder";
+ auto reader_name = "_" + object_name + "Reader";
+ auto builder_name = object_name + "Builder";
+ auto object_builder_name = object_name + "ObjectBuilder";
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) {
- code += " factory " + struct_def.name + "(List<int> bytes) {\n";
+ code += " factory " + object_name + "(List<int> bytes) {\n";
code += " " + _kFb + ".BufferContext rootRef = new " + _kFb +
".BufferContext.fromBytes(bytes);\n";
code += " return reader.read(rootRef, 0);\n";
@@ -433,7 +433,7 @@ class DartGenerator : public BaseGenerator {
}
code += "\n";
- code += " static const " + _kFb + ".Reader<" + struct_def.name +
+ code += " static const " + _kFb + ".Reader<" + object_name +
"> reader = const " + reader_name + "();\n\n";
code += " final " + _kFb + ".BufferContext _bc;\n";
@@ -454,7 +454,7 @@ class DartGenerator : public BaseGenerator {
}
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::string item;
diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp
index dd98c0e6..5f41e5aa 100644
--- a/src/idl_gen_general.cpp
+++ b/src/idl_gen_general.cpp
@@ -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();
++it) {
auto &enum_def = **it;
- if (make_rule != "") make_rule += " ";
+ if (!make_rule.empty()) make_rule += " ";
std::string directory =
BaseGenerator::NamespaceDir(parser, path, *enum_def.defined_namespace);
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();
++it) {
auto &struct_def = **it;
- if (make_rule != "") make_rule += " ";
+ if (!make_rule.empty()) make_rule += " ";
std::string directory = BaseGenerator::NamespaceDir(
parser, path, *struct_def.defined_namespace);
make_rule += directory + struct_def.name + lang.file_extension;
diff --git a/src/idl_gen_go.cpp b/src/idl_gen_go.cpp
index 2be00767..80ce1925 100644
--- a/src/idl_gen_go.cpp
+++ b/src/idl_gen_go.cpp
@@ -188,7 +188,7 @@ class GoGenerator : public BaseGenerator {
}
// 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) {
std::string &code = *code_ptr;
code += "\t";
@@ -228,7 +228,7 @@ class GoGenerator : public BaseGenerator {
}
// 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) {
std::string &code = *code_ptr;
code += "\t\"";
@@ -895,7 +895,7 @@ class GoGenerator : public BaseGenerator {
EndBuilderBody(code_ptr);
}
// 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) {
std::string &code = *code_ptr;
code = code + "// Code generated by the FlatBuffers compiler. DO NOT EDIT.\n\n";
diff --git a/src/idl_gen_grpc.cpp b/src/idl_gen_grpc.cpp
index d682a553..1d5e8e5e 100644
--- a/src/idl_gen_grpc.cpp
+++ b/src/idl_gen_grpc.cpp
@@ -149,7 +149,7 @@ class FlatBufPrinter : public grpc_generator::Printer {
}
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.
for (;;) {
// Current indentation.
diff --git a/src/idl_gen_js_ts.cpp b/src/idl_gen_js_ts.cpp
index cd59f4a1..9c89c1ab 100644
--- a/src/idl_gen_js_ts.cpp
+++ b/src/idl_gen_js_ts.cpp
@@ -214,7 +214,7 @@ class JsTsGenerator : public BaseGenerator {
std::string &code = *code_ptr;
std::string &exports = *exports_ptr;
for (auto it = sorted_namespaces.begin(); it != sorted_namespaces.end();
- it++) {
+ ++it) {
if (lang_.language == IDLOptions::kTs) {
if (it->find('.') == std::string::npos) {
code += "import { flatbuffers } from \"./flatbuffers\"\n";
diff --git a/src/idl_gen_lua.cpp b/src/idl_gen_lua.cpp
index d94c2155..d25e7795 100644
--- a/src/idl_gen_lua.cpp
+++ b/src/idl_gen_lua.cpp
@@ -88,7 +88,7 @@ namespace lua {
}
// 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;
code += "local " + class_name + " = {\n";
}
@@ -683,7 +683,7 @@ namespace lua {
}
// 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 = *code_ptr;
code += std::string(Comment) + FlatBuffersGeneratedWarning() + "\n\n";
diff --git a/src/idl_gen_php.cpp b/src/idl_gen_php.cpp
index 906d0bcd..30512ee1 100644
--- a/src/idl_gen_php.cpp
+++ b/src/idl_gen_php.cpp
@@ -232,7 +232,6 @@ class PhpGenerator : public BaseGenerator {
// Get the value of a table's scalar.
void GetScalarFieldOfTable(const FieldDef &field, std::string *code_ptr) {
std::string &code = *code_ptr;
- std::string getter = GenGetter(field.value.type);
code += Indent + "/**\n";
code += Indent + " * @return " + GenTypeGet(field.value.type) + "\n";
diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp
index 05367d4b..643ab198 100644
--- a/src/idl_gen_python.cpp
+++ b/src/idl_gen_python.cpp
@@ -95,7 +95,7 @@ class PythonGenerator : public BaseGenerator {
}
// 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;
code += "class " + class_name + "(object):\n";
}
@@ -750,7 +750,7 @@ class PythonGenerator : public BaseGenerator {
}
// 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 = *code_ptr;
code = code + "# " + FlatBuffersGeneratedWarning() + "\n\n";
diff --git a/src/idl_gen_rust.cpp b/src/idl_gen_rust.cpp
index cdd5d843..409f7a11 100644
--- a/src/idl_gen_rust.cpp
+++ b/src/idl_gen_rust.cpp
@@ -449,7 +449,7 @@ class RustGenerator : public BaseGenerator {
std::stringstream 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) + "::";
}
return stream.str();
@@ -481,15 +481,15 @@ class RustGenerator : public BaseGenerator {
if (s == src->components.end()) { break; }
if (d == dst->components.end()) { break; }
if (*s != *d) { break; }
- s++;
- d++;
- i++;
+ ++s;
+ ++d;
+ ++i;
}
- for (; s != src->components.end(); s++) {
+ for (; s != src->components.end(); ++s) {
stream << "super::";
}
- for (; d != dst->components.end(); d++) {
+ for (; d != dst->components.end(); ++d) {
stream << MakeSnakeCase(*d) + "::";
}
return stream.str();
@@ -758,7 +758,7 @@ class RustGenerator : public BaseGenerator {
// the vtable, or
// 3) return a hardcoded value because the vtable field value is set to zero.
std::string TableBuilderArgsDefnType(const FieldDef &field,
- const std::string lifetime) {
+ const std::string &lifetime) {
const Type& type = field.value.type;
switch (GetFullType(type)) {
@@ -786,7 +786,6 @@ class RustGenerator : public BaseGenerator {
return typname;
}
case ftUnionValue: {
- const auto typname = WrapInNameSpace(*type.enum_def);
return "Option<flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>>";
}
@@ -836,10 +835,11 @@ class RustGenerator : public BaseGenerator {
return GetDefaultScalarValue(field);
}
std::string TableBuilderAddFuncDefaultValue(const FieldDef &field) {
+ // All branches of switch do the same action!
switch (GetFullType(field.value.type)) {
case ftUnionKey:
case ftEnumKey: {
- const std::string basetype = GetTypeBasic(field.value.type);
+ const std::string basetype = GetTypeBasic(field.value.type); //<- never used
return GetDefaultScalarValue(field);
}
@@ -848,7 +848,7 @@ class RustGenerator : public BaseGenerator {
}
std::string TableBuilderArgsAddFuncType(const FieldDef &field,
- const std::string lifetime) {
+ const std::string &lifetime) {
const Type& type = field.value.type;
switch (GetFullType(field.value.type)) {
@@ -883,7 +883,6 @@ class RustGenerator : public BaseGenerator {
", " + typname + ">>";
}
case ftVectorOfUnionValue: {
- const auto typname = WrapInNameSpace(*type.enum_def);
return "flatbuffers::WIPOffset<flatbuffers::Vector<" + lifetime + \
", flatbuffers::ForwardsUOffset<flatbuffers::Table<" + \
lifetime + ">>>";
@@ -916,7 +915,6 @@ class RustGenerator : public BaseGenerator {
return typname;
}
case ftUnionValue: {
- const auto typname = WrapInNameSpace(*type.enum_def);
return "flatbuffers::WIPOffset<flatbuffers::UnionWIPOffset>";
}
}
@@ -970,7 +968,7 @@ class RustGenerator : public BaseGenerator {
}
std::string GenTableAccessorFuncReturnType(const FieldDef &field,
- const std::string lifetime) {
+ const std::string &lifetime) {
const Type& type = field.value.type;
switch (GetFullType(field.value.type)) {
@@ -1041,8 +1039,8 @@ class RustGenerator : public BaseGenerator {
}
std::string GenTableAccessorFuncBody(const FieldDef &field,
- const std::string lifetime,
- const std::string offset_prefix) {
+ const std::string &lifetime,
+ const std::string &offset_prefix) {
const std::string offset_name = offset_prefix + "::" + \
GetFieldOffsetName(field);
const Type& type = field.value.type;
@@ -1072,7 +1070,7 @@ class RustGenerator : public BaseGenerator {
}
case ftUnionKey:
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 default_value = GetDefaultScalarValue(field);
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);
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.
//
diff --git a/src/idl_gen_text.cpp b/src/idl_gen_text.cpp
index 77088d22..c417bbf0 100644
--- a/src/idl_gen_text.cpp
+++ b/src/idl_gen_text.cpp
@@ -309,10 +309,10 @@ bool GenerateTextFromTable(const Parser &parser, const void *table,
if (struct_def == nullptr) {
return false;
}
- auto text = *_text;
+ auto &text = *_text;
text.reserve(1024); // Reduce amount of inevitable reallocs.
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;
}
text += NewLine(parser.opts);
diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp
index ea289143..794165f7 100644
--- a/src/idl_parser.cpp
+++ b/src/idl_parser.cpp
@@ -2099,7 +2099,7 @@ Namespace *Parser::UniqueNamespace(Namespace *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();
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());
predecl = false;
sortbysize = attributes.Lookup("original_order") == nullptr && !fixed;
- std::vector<uoffset_t> indexes =
- std::vector<uoffset_t>(object->fields()->size());
- for (uoffset_t i = 0; i < object->fields()->size(); i++)
- indexes[object->fields()->Get(i)->id()] = i;
+ const auto& of = *(object->fields());
+ auto indexes = std::vector<uoffset_t>(of.size());
+ for (uoffset_t i = 0; i < of.size(); i++) indexes[of.Get(i)->id()] = i;
size_t tmp_struct_size = 0;
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();
if (!field_def->Deserialize(parser, field) ||
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 next_field =
i + 1 < indexes.size()
- ? object->fields()->Get(indexes[i+1])
+ ? of.Get(indexes[i+1])
: nullptr;
tmp_struct_size += size;
field_def->padding =
diff --git a/src/util.cpp b/src/util.cpp
index cfa3f8be..5483cee1 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -127,12 +127,12 @@ static const char kPathSeparatorWindows = '\\';
static const char *PathSeparatorSet = "\\/"; // Intentionally no ':'
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;
}
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) : "";
}