mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-17 01:26:45 +00:00
Audit and fixups for GCC and Clang (#7212)
Added (for compiler versions that support it): -Wmissing-declarations -Wzero-as-null-pointer-constant Then, fixes to problems identified by the extra warnings Tested only on GCC 9.4.0 Adjusted the CPP code generator to output nullptr where appropriate, to satisfy -Wzero-as-null-pointer-constant Added a lot of 'static' declarations in front of functions, to satisfy -Wmissing-declarations, and wrap static function defs in anonymous namespaces. There are advantages to both anonymous namespaces and static, it seems that marking a function as static will not publish the name in the symbol table at all, thus giving the linker less work to do.
This commit is contained in:
@@ -24,7 +24,10 @@ namespace flatbuffers {
|
||||
|
||||
namespace jsons {
|
||||
|
||||
template<class T> std::string GenFullName(const T *enum_def) {
|
||||
namespace {
|
||||
|
||||
template<class T>
|
||||
static std::string GenFullName(const T *enum_def) {
|
||||
std::string full_name;
|
||||
const auto &name_spaces = enum_def->defined_namespace->components;
|
||||
for (auto ns = name_spaces.cbegin(); ns != name_spaces.cend(); ++ns) {
|
||||
@@ -34,15 +37,16 @@ template<class T> std::string GenFullName(const T *enum_def) {
|
||||
return full_name;
|
||||
}
|
||||
|
||||
template<class T> std::string GenTypeRef(const T *enum_def) {
|
||||
template<class T>
|
||||
static std::string GenTypeRef(const T *enum_def) {
|
||||
return "\"$ref\" : \"#/definitions/" + GenFullName(enum_def) + "\"";
|
||||
}
|
||||
|
||||
std::string GenType(const std::string &name) {
|
||||
static std::string GenType(const std::string &name) {
|
||||
return "\"type\" : \"" + name + "\"";
|
||||
}
|
||||
|
||||
std::string GenType(BaseType type) {
|
||||
static std::string GenType(BaseType type) {
|
||||
switch (type) {
|
||||
case BASE_TYPE_BOOL: return "\"type\" : \"boolean\"";
|
||||
case BASE_TYPE_CHAR:
|
||||
@@ -84,13 +88,13 @@ std::string GenType(BaseType type) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string GenBaseType(const Type &type) {
|
||||
static std::string GenBaseType(const Type &type) {
|
||||
if (type.struct_def != nullptr) { return GenTypeRef(type.struct_def); }
|
||||
if (type.enum_def != nullptr) { return GenTypeRef(type.enum_def); }
|
||||
return GenType(type.base_type);
|
||||
}
|
||||
|
||||
std::string GenArrayType(const Type &type) {
|
||||
static std::string GenArrayType(const Type &type) {
|
||||
std::string element_type;
|
||||
if (type.struct_def != nullptr) {
|
||||
element_type = GenTypeRef(type.struct_def);
|
||||
@@ -103,7 +107,7 @@ std::string GenArrayType(const Type &type) {
|
||||
return "\"type\" : \"array\", \"items\" : {" + element_type + "}";
|
||||
}
|
||||
|
||||
std::string GenType(const Type &type) {
|
||||
static std::string GenType(const Type &type) {
|
||||
switch (type.base_type) {
|
||||
case BASE_TYPE_ARRAY: FLATBUFFERS_FALLTHROUGH(); // fall thru
|
||||
case BASE_TYPE_VECTOR: {
|
||||
@@ -136,6 +140,8 @@ std::string GenType(const Type &type) {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class JsonSchemaGenerator : public BaseGenerator {
|
||||
private:
|
||||
std::string code_;
|
||||
|
||||
Reference in New Issue
Block a user