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) {
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");
}
}
}
filepath += filename;
+ // Ignore './' at the start of filepath.
+ if (filepath[0] == '.' && filepath[1] == kPathSeparator) {
+ filepath.erase(0, 2);
+ }
return filepath;
}
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);
}
return true;
}
-
- protected:
- const Parser &parser_;
- const std::string &path_, &file_name_;
};
bool GenerateJavaGRPC(const Parser &parser, const std::string &path,
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;
return true;
}
- bool generateStructs() {
+ bool GenerateStructs() {
for (auto it = parser_.structs_.vec.begin();
it != parser_.structs_.vec.end(); ++it) {
auto &struct_def = **it;
}
// 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";
}
// 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";
}
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 << "."; }
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 &&
}
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);
// 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,
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 }",
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");
}