Misc fixes from internal integration / clang tidy.
Change-Id: Ic5e8f6a423b426abb9f8b90d39db0f85f28b94be Tested: on Linux.
This commit is contained in:
parent
6a1acdc23b
commit
b513db86c7
|
@ -49,6 +49,7 @@ typedef grpc_generator::CommentHolder
|
|||
typedef grpc_generator::Method MethodDescriptor;
|
||||
|
||||
namespace grpc_java_generator {
|
||||
typedef std::string string;
|
||||
// Generates imports for the service
|
||||
void GenerateImports(grpc_generator::File* file,
|
||||
grpc_generator::Printer* printer, VARS& vars) {
|
||||
|
@ -60,7 +61,7 @@ void GenerateImports(grpc_generator::File* file,
|
|||
printer->Print(vars, "//source: $filename$.fbs\n\n");
|
||||
printer->Print(vars, "package $Package$;\n\n");
|
||||
vars["Package"] = vars["Package"] + ".";
|
||||
if (file->additional_headers() != "") {
|
||||
if (!file->additional_headers().empty()) {
|
||||
printer->Print(file->additional_headers().c_str());
|
||||
printer->Print("\n\n");
|
||||
}
|
||||
|
|
|
@ -231,6 +231,10 @@ inline std::string ConCatPathFileName(const std::string &path,
|
|||
}
|
||||
}
|
||||
filepath += filename;
|
||||
// Ignore './' at the start of filepath.
|
||||
if (filepath[0] == '.' && filepath[1] == kPathSeparator) {
|
||||
filepath.erase(0, 2);
|
||||
}
|
||||
return filepath;
|
||||
}
|
||||
|
||||
|
|
|
@ -314,10 +314,7 @@ class JavaGRPCGenerator : public flatbuffers::BaseGenerator {
|
|||
public:
|
||||
JavaGRPCGenerator(const Parser &parser, const std::string &path,
|
||||
const std::string &file_name)
|
||||
: BaseGenerator(parser, path, file_name, "", "." /*separator*/),
|
||||
parser_(parser),
|
||||
path_(path),
|
||||
file_name_(file_name) {}
|
||||
: BaseGenerator(parser, path, file_name, "", "." /*separator*/) {}
|
||||
|
||||
bool generate() {
|
||||
FlatBufFile file(parser_, file_name_, FlatBufFile::kLanguageJava);
|
||||
|
@ -335,10 +332,6 @@ class JavaGRPCGenerator : public flatbuffers::BaseGenerator {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
protected:
|
||||
const Parser &parser_;
|
||||
const std::string &path_, &file_name_;
|
||||
};
|
||||
|
||||
bool GenerateJavaGRPC(const Parser &parser, const std::string &path,
|
||||
|
|
|
@ -33,13 +33,13 @@ class PhpGenerator : public BaseGenerator {
|
|||
const std::string &file_name)
|
||||
: BaseGenerator(parser, path, file_name, "\\", "\\"){};
|
||||
bool generate() {
|
||||
if (!generateEnums()) return false;
|
||||
if (!generateStructs()) return false;
|
||||
if (!GenerateEnums()) return false;
|
||||
if (!GenerateStructs()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool generateEnums() {
|
||||
bool GenerateEnums() {
|
||||
for (auto it = parser_.enums_.vec.begin(); it != parser_.enums_.vec.end();
|
||||
++it) {
|
||||
auto &enum_def = **it;
|
||||
|
@ -50,7 +50,7 @@ class PhpGenerator : public BaseGenerator {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool generateStructs() {
|
||||
bool GenerateStructs() {
|
||||
for (auto it = parser_.structs_.vec.begin();
|
||||
it != parser_.structs_.vec.end(); ++it) {
|
||||
auto &struct_def = **it;
|
||||
|
@ -62,9 +62,9 @@ class PhpGenerator : 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;
|
||||
auto &code = *code_ptr;
|
||||
code += "<?php\n";
|
||||
code = code + "// " + FlatBuffersGeneratedWarning() + "\n\n";
|
||||
|
||||
|
@ -113,7 +113,7 @@ class PhpGenerator : public BaseGenerator {
|
|||
}
|
||||
|
||||
// Begin enum code with a class declaration.
|
||||
static void BeginEnum(const std::string class_name, std::string *code_ptr) {
|
||||
static void BeginEnum(const std::string &class_name, std::string *code_ptr) {
|
||||
std::string &code = *code_ptr;
|
||||
code += "class " + class_name + "\n{\n";
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ inline CheckedError atot<Offset<void>>(const char *s, Parser &parser,
|
|||
std::string Namespace::GetFullyQualifiedName(const std::string &name,
|
||||
size_t max_components) const {
|
||||
// Early exit if we don't have a defined namespace.
|
||||
if (components.size() == 0 || !max_components) { return name; }
|
||||
if (components.empty() || !max_components) { return name; }
|
||||
std::stringstream stream;
|
||||
for (size_t i = 0; i < std::min(components.size(), max_components); i++) {
|
||||
if (i) { stream << "."; }
|
||||
|
@ -648,10 +648,11 @@ CheckedError Parser::ParseField(StructDef &struct_def) {
|
|||
|
||||
if (token_ == '=') {
|
||||
NEXT();
|
||||
if (!IsScalar(type.base_type) || struct_def.fixed)
|
||||
ECHECK(ParseSingleValue(field->value));
|
||||
if (!IsScalar(type.base_type) ||
|
||||
(struct_def.fixed && field->value.constant != "0"))
|
||||
return Error(
|
||||
"default values currently only supported for scalars in tables");
|
||||
ECHECK(ParseSingleValue(field->value));
|
||||
}
|
||||
if (type.enum_def &&
|
||||
!type.enum_def->is_union &&
|
||||
|
@ -1492,7 +1493,7 @@ CheckedError Parser::ParseEnum(bool is_union, EnumDef **dest) {
|
|||
}
|
||||
auto prevsize = enum_def.vals.vec.size();
|
||||
auto value =
|
||||
enum_def.vals.vec.size() ? enum_def.vals.vec.back()->value + 1 : 0;
|
||||
!enum_def.vals.vec.empty() ? enum_def.vals.vec.back()->value + 1 : 0;
|
||||
auto &ev = *new EnumVal(value_name, value);
|
||||
if (enum_def.vals.Add(value_name, &ev))
|
||||
return Error("enum value already exists: " + value_name);
|
||||
|
|
|
@ -513,7 +513,7 @@ bool VerifyVectorOfStructs(flatbuffers::Verifier &v,
|
|||
// forward declare to resolve cyclic deps between VerifyObject and VerifyVector
|
||||
bool VerifyObject(flatbuffers::Verifier &v, const reflection::Schema &schema,
|
||||
const reflection::Object &obj,
|
||||
const flatbuffers::Table *table, bool isRequired);
|
||||
const flatbuffers::Table *table, bool required);
|
||||
|
||||
bool VerifyVector(flatbuffers::Verifier &v, const reflection::Schema &schema,
|
||||
const flatbuffers::Table &table,
|
||||
|
|
|
@ -1179,7 +1179,7 @@ void ErrorTest() {
|
|||
TestError("table X { Y:int; Y:int; }", "field already");
|
||||
TestError("table Y {} table X { Y:int; }", "same as table");
|
||||
TestError("struct X { Y:string; }", "only scalar");
|
||||
TestError("table X { Y:string = 1; }", "default values");
|
||||
TestError("table X { Y:string = \"\"; }", "default values");
|
||||
TestError("enum Y:byte { Z = 1 } table X { y:Y; }", "not part of enum");
|
||||
TestError("struct X { Y:int (deprecated); }", "deprecate");
|
||||
TestError("union Z { X } table X { Y:Z; } root_type X; { Y: {}, A:1 }",
|
||||
|
@ -1212,7 +1212,6 @@ void ErrorTest() {
|
|||
TestError("union X { Y }", "referenced");
|
||||
TestError("union Z { X } struct X { Y:int; }", "only tables");
|
||||
TestError("table X { Y:[int]; YLength:int; }", "clash");
|
||||
TestError("table X { Y:string = 1; }", "scalar");
|
||||
TestError("table X { Y:byte; } root_type X; { Y:1, Y:2 }", "more than once");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue