From 79f62ee35383f44f98cf6c61b5cff1a9cd901f2c Mon Sep 17 00:00:00 2001 From: Flaviu <cflaviu@users.noreply.github.com> Date: Fri, 23 Mar 2018 17:58:07 +0200 Subject: [PATCH] Const correctness in generated code and in code generators. Added missing \reflection\generate_code.bat file. (#4679) --- include/flatbuffers/flatbuffers.h | 8 +- include/flatbuffers/idl.h | 6 +- include/flatbuffers/reflection_generated.h | 37 +++-- include/flatbuffers/util.h | 2 +- reflection/generate_code.bat | 18 +++ samples/monster_generated.h | 72 ++++----- src/idl_gen_cpp.cpp | 33 ++-- src/idl_gen_general.cpp | 76 ++++----- src/idl_gen_go.cpp | 2 +- src/idl_parser.cpp | 8 +- tests/monster_test.bfbs | Bin 6112 -> 6184 bytes tests/monster_test_generated.h | 148 +++++++++--------- .../namespace_test1_generated.h | 40 ++--- .../namespace_test2_generated.h | 42 ++--- .../namespace_test2_generated.ts | 20 +-- tests/union_vector/union_vector_generated.h | 64 ++++---- 16 files changed, 306 insertions(+), 270 deletions(-) create mode 100644 reflection/generate_code.bat diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index c1550f75..81aa9ac6 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -2185,8 +2185,8 @@ enum ElementaryType { #undef FLATBUFFERS_ET }; -inline const char **ElementaryTypeNames() { - static const char *names[] = { +inline const char * const *ElementaryTypeNames() { + static const char * const names[] = { #define FLATBUFFERS_ET(E) #E, FLATBUFFERS_GEN_ELEMENTARY_TYPES(FLATBUFFERS_ET) #undef FLATBUFFERS_ET @@ -2207,7 +2207,7 @@ static_assert(sizeof(TypeCode) == 2, "TypeCode"); struct TypeTable; // Signature of the static method present in each type. -typedef TypeTable *(*TypeFunction)(); +typedef const TypeTable *(*TypeFunction)(); struct TypeTable { SequenceType st; @@ -2215,7 +2215,7 @@ struct TypeTable { const TypeCode *type_codes; const TypeFunction *type_refs; const int32_t *values; // Only set for non-consecutive enum/union or structs. - const char **names; // Only set if compiled with --reflect-names. + const char * const *names; // Only set if compiled with --reflect-names. }; // String which identifies the current version of FlatBuffers. diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 4f569071..a811fcb7 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -600,10 +600,10 @@ class Parser : public ParserState { FLATBUFFERS_CHECKED_ERROR ParseHexNum(int nibbles, uint64_t *val); FLATBUFFERS_CHECKED_ERROR Next(); FLATBUFFERS_CHECKED_ERROR SkipByteOrderMark(); - bool Is(int t); - bool IsIdent(const char *id); + bool Is(int t) const; + bool IsIdent(const char *id) const; FLATBUFFERS_CHECKED_ERROR Expect(int t); - std::string TokenToStringId(int t); + std::string TokenToStringId(int t) const; EnumDef *LookupEnum(const std::string &id); FLATBUFFERS_CHECKED_ERROR ParseNamespacing(std::string *id, std::string *last); diff --git a/include/flatbuffers/reflection_generated.h b/include/flatbuffers/reflection_generated.h index 3bbab112..2cc21bb3 100644 --- a/include/flatbuffers/reflection_generated.h +++ b/include/flatbuffers/reflection_generated.h @@ -42,8 +42,8 @@ enum BaseType { Union = 16 }; -inline BaseType (&EnumValuesBaseType())[17] { - static BaseType values[] = { +inline const BaseType (&EnumValuesBaseType())[17] { + static const BaseType values[] = { None, UType, Bool, @@ -65,8 +65,8 @@ inline BaseType (&EnumValuesBaseType())[17] { return values; } -inline const char **EnumNamesBaseType() { - static const char *names[] = { +inline const char * const *EnumNamesBaseType() { + static const char * const names[] = { "None", "UType", "Bool", @@ -130,7 +130,7 @@ struct TypeBuilder { void add_index(int32_t index) { fbb_.AddElement<int32_t>(Type::VT_INDEX, index, -1); } - TypeBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit TypeBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } @@ -190,7 +190,7 @@ struct KeyValueBuilder { void add_value(flatbuffers::Offset<flatbuffers::String> value) { fbb_.AddOffset(KeyValue::VT_VALUE, value); } - KeyValueBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit KeyValueBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } @@ -283,7 +283,7 @@ struct EnumValBuilder { void add_union_type(flatbuffers::Offset<Type> union_type) { fbb_.AddOffset(EnumVal::VT_UNION_TYPE, union_type); } - EnumValBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit EnumValBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } @@ -398,7 +398,7 @@ struct EnumBuilder { void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) { fbb_.AddOffset(Enum::VT_DOCUMENTATION, documentation); } - EnumBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit EnumBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } @@ -561,7 +561,7 @@ struct FieldBuilder { void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) { fbb_.AddOffset(Field::VT_DOCUMENTATION, documentation); } - FieldBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit FieldBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } @@ -712,7 +712,7 @@ struct ObjectBuilder { void add_documentation(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>> documentation) { fbb_.AddOffset(Object::VT_DOCUMENTATION, documentation); } - ObjectBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit ObjectBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } @@ -825,7 +825,7 @@ struct SchemaBuilder { void add_root_table(flatbuffers::Offset<Object> root_table) { fbb_.AddOffset(Schema::VT_ROOT_TABLE, root_table); } - SchemaBuilder(flatbuffers::FlatBufferBuilder &_fbb) + explicit SchemaBuilder(flatbuffers::FlatBufferBuilder &_fbb) : fbb_(_fbb) { start_ = fbb_.StartTable(); } @@ -875,6 +875,10 @@ inline const reflection::Schema *GetSchema(const void *buf) { return flatbuffers::GetRoot<reflection::Schema>(buf); } +inline const reflection::Schema *GetSizePrefixedSchema(const void *buf) { + return flatbuffers::GetSizePrefixedRoot<reflection::Schema>(buf); +} + inline const char *SchemaIdentifier() { return "BFBS"; } @@ -889,6 +893,11 @@ inline bool VerifySchemaBuffer( return verifier.VerifyBuffer<reflection::Schema>(SchemaIdentifier()); } +inline bool VerifySizePrefixedSchemaBuffer( + flatbuffers::Verifier &verifier) { + return verifier.VerifySizePrefixedBuffer<reflection::Schema>(SchemaIdentifier()); +} + inline const char *SchemaExtension() { return "bfbs"; } @@ -899,6 +908,12 @@ inline void FinishSchemaBuffer( fbb.Finish(root, SchemaIdentifier()); } +inline void FinishSizePrefixedSchemaBuffer( + flatbuffers::FlatBufferBuilder &fbb, + flatbuffers::Offset<reflection::Schema> root) { + fbb.FinishSizePrefixed(root, SchemaIdentifier()); +} + } // namespace reflection #endif // FLATBUFFERS_GENERATED_REFLECTION_REFLECTION_H_ diff --git a/include/flatbuffers/util.h b/include/flatbuffers/util.h index 7cadd0b5..e6540105 100644 --- a/include/flatbuffers/util.h +++ b/include/flatbuffers/util.h @@ -321,7 +321,7 @@ inline int FromUTF8(const char **in) { break; } } - if ((static_cast<unsigned char>(**in) << len) & 0x80) return -1; // Bit after leading 1's must be 0. + if ((static_cast<const unsigned char>(**in) << len) & 0x80) return -1; // Bit after leading 1's must be 0. if (!len) return *(*in)++; // UTF-8 encoded values with a length are between 2 and 4 bytes. if (len < 2 || len > 4) { return -1; } diff --git a/reflection/generate_code.bat b/reflection/generate_code.bat new file mode 100644 index 00000000..8f58c0c7 --- /dev/null +++ b/reflection/generate_code.bat @@ -0,0 +1,18 @@ +:: Copyright 2015 Google Inc. All rights reserved. +:: +:: Licensed under the Apache License, Version 2.0 (the "License"); +:: you may not use this file except in compliance with the License. +:: You may obtain a copy of the License at +:: +:: http://www.apache.org/licenses/LICENSE-2.0 +:: +:: Unless required by applicable law or agreed to in writing, software +:: distributed under the License is distributed on an "AS IS" BASIS, +:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +:: See the License for the specific language governing permissions and +:: limitations under the License. + +set buildtype=Release +if "%1"=="-b" set buildtype=%2 + +..\%buildtype%\flatc.exe --cpp --no-prefix -o ../include/flatbuffers reflection.fbs diff --git a/samples/monster_generated.h b/samples/monster_generated.h index 00c0595e..4a766069 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -17,11 +17,11 @@ struct MonsterT; struct Weapon; struct WeaponT; -inline flatbuffers::TypeTable *Vec3TypeTable(); +inline const flatbuffers::TypeTable *Vec3TypeTable(); -inline flatbuffers::TypeTable *MonsterTypeTable(); +inline const flatbuffers::TypeTable *MonsterTypeTable(); -inline flatbuffers::TypeTable *WeaponTypeTable(); +inline const flatbuffers::TypeTable *WeaponTypeTable(); enum Color { Color_Red = 0, @@ -31,8 +31,8 @@ enum Color { Color_MAX = Color_Blue }; -inline Color (&EnumValuesColor())[3] { - static Color values[] = { +inline const Color (&EnumValuesColor())[3] { + static const Color values[] = { Color_Red, Color_Green, Color_Blue @@ -40,8 +40,8 @@ inline Color (&EnumValuesColor())[3] { return values; } -inline const char **EnumNamesColor() { - static const char *names[] = { +inline const char * const *EnumNamesColor() { + static const char * const names[] = { "Red", "Green", "Blue", @@ -62,16 +62,16 @@ enum Equipment { Equipment_MAX = Equipment_Weapon }; -inline Equipment (&EnumValuesEquipment())[2] { - static Equipment values[] = { +inline const Equipment (&EnumValuesEquipment())[2] { + static const Equipment values[] = { Equipment_NONE, Equipment_Weapon }; return values; } -inline const char **EnumNamesEquipment() { - static const char *names[] = { +inline const char * const *EnumNamesEquipment() { + static const char * const names[] = { "NONE", "Weapon", nullptr @@ -191,7 +191,7 @@ struct MonsterT : public flatbuffers::NativeTable { struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef MonsterT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return MonsterTypeTable(); } enum { @@ -393,7 +393,7 @@ struct WeaponT : public flatbuffers::NativeTable { struct Weapon FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef WeaponT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return WeaponTypeTable(); } enum { @@ -615,64 +615,64 @@ inline void EquipmentUnion::Reset() { type = Equipment_NONE; } -inline flatbuffers::TypeTable *ColorTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *ColorTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_CHAR, 0, 0 }, { flatbuffers::ET_CHAR, 0, 0 }, { flatbuffers::ET_CHAR, 0, 0 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { ColorTypeTable }; - static const char *names[] = { + static const char * const names[] = { "Red", "Green", "Blue" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *EquipmentTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *EquipmentTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SEQUENCE, 0, -1 }, { flatbuffers::ET_SEQUENCE, 0, 0 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { WeaponTypeTable }; - static const char *names[] = { + static const char * const names[] = { "NONE", "Weapon" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_UNION, 2, type_codes, type_refs, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *Vec3TypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *Vec3TypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_FLOAT, 0, -1 }, { flatbuffers::ET_FLOAT, 0, -1 }, { flatbuffers::ET_FLOAT, 0, -1 } }; static const int32_t values[] = { 0, 4, 8, 12 }; - static const char *names[] = { + static const char * const names[] = { "x", "y", "z" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_STRUCT, 3, type_codes, nullptr, values, names }; return &tt; } -inline flatbuffers::TypeTable *MonsterTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *MonsterTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SEQUENCE, 0, 0 }, { flatbuffers::ET_SHORT, 0, -1 }, { flatbuffers::ET_SHORT, 0, -1 }, @@ -684,13 +684,13 @@ inline flatbuffers::TypeTable *MonsterTypeTable() { { flatbuffers::ET_UTYPE, 0, 3 }, { flatbuffers::ET_SEQUENCE, 0, 3 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { Vec3TypeTable, ColorTypeTable, WeaponTypeTable, EquipmentTypeTable }; - static const char *names[] = { + static const char * const names[] = { "pos", "mana", "hp", @@ -702,22 +702,22 @@ inline flatbuffers::TypeTable *MonsterTypeTable() { "equipped_type", "equipped" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 10, type_codes, type_refs, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *WeaponTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *WeaponTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_STRING, 0, -1 }, { flatbuffers::ET_SHORT, 0, -1 } }; - static const char *names[] = { + static const char * const names[] = { "name", "damage" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 2, type_codes, nullptr, nullptr, names }; return &tt; diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index de19219e..7c041a2f 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -21,6 +21,8 @@ #include "flatbuffers/idl.h" #include "flatbuffers/util.h" +#include <unordered_set> + namespace flatbuffers { // Pedantic warning free version of toupper(). @@ -38,7 +40,8 @@ class CppGenerator : public BaseGenerator { const std::string &file_name) : BaseGenerator(parser, path, file_name, "", "::"), cur_name_space_(nullptr) { - const char *keywords[] = { "alignas", + static const char * const keywords[] = { + "alignas", "alignof", "and", "and_eq", @@ -142,7 +145,7 @@ class CppGenerator : public BaseGenerator { std::string guard = file_name_; // Remove any non-alpha-numeric characters that may appear in a filename. struct IsAlnum { - bool operator()(char c) { return !isalnum(c); } + bool operator()(char c) const { return !isalnum(c); } }; guard.erase(std::remove_if(guard.begin(), guard.end(), IsAlnum()), guard.end()); @@ -445,7 +448,7 @@ class CppGenerator : public BaseGenerator { private: CodeWriter code_; - std::set<std::string> keywords_; + std::unordered_set<std::string> keywords_; // This tracks the current namespace so we can insert namespace declarations. const Namespace *cur_name_space_; @@ -472,7 +475,7 @@ class CppGenerator : public BaseGenerator { // Return a C++ type from the table in idl.h std::string GenTypeBasic(const Type &type, bool user_facing_type) const { - static const char *ctypename[] = { + static const char * const ctypename[] = { // clang-format off #define FLATBUFFERS_TD(ENUM, IDLTYPE, CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ #CTYPE, @@ -734,7 +737,7 @@ class CppGenerator : public BaseGenerator { void GenMiniReflectPre(const StructDef *struct_def) { code_.SetValue("NAME", struct_def->name); - code_ += "inline flatbuffers::TypeTable *{{NAME}}TypeTable();"; + code_ += "inline const flatbuffers::TypeTable *{{NAME}}TypeTable();"; code_ += ""; } @@ -830,14 +833,14 @@ class CppGenerator : public BaseGenerator { code_.SetValue("REFS", rs); code_.SetValue("NAMES", ns); code_.SetValue("VALUES", vs); - code_ += "inline flatbuffers::TypeTable *{{NAME}}TypeTable() {"; + code_ += "inline const flatbuffers::TypeTable *{{NAME}}TypeTable() {"; if (num_fields) { - code_ += " static flatbuffers::TypeCode type_codes[] = {"; + code_ += " static const flatbuffers::TypeCode type_codes[] = {"; code_ += " {{TYPES}}"; code_ += " };"; } if (!type_refs.empty()) { - code_ += " static flatbuffers::TypeFunction type_refs[] = {"; + code_ += " static const flatbuffers::TypeFunction type_refs[] = {"; code_ += " {{REFS}}"; code_ += " };"; } @@ -847,11 +850,11 @@ class CppGenerator : public BaseGenerator { auto has_names = num_fields && parser_.opts.mini_reflect == IDLOptions::kTypesAndNames; if (has_names) { - code_ += " static const char *names[] = {"; + code_ += " static const char * const names[] = {"; code_ += " {{NAMES}}"; code_ += " };"; } - code_ += " static flatbuffers::TypeTable tt = {"; + code_ += " static const flatbuffers::TypeTable tt = {"; code_ += std::string(" flatbuffers::{{SEQ_TYPE}}, {{NUM_FIELDS}}, ") + (num_fields ? "type_codes, " : "nullptr, ") + (!type_refs.empty() ? "type_refs, " : "nullptr, ") + @@ -925,9 +928,9 @@ class CppGenerator : public BaseGenerator { // Generate an array of all enumeration values auto num_fields = NumToString(enum_def.vals.vec.size()); - code_ += "inline {{ENUM_NAME}} (&EnumValues{{ENUM_NAME}}())[" + num_fields + + code_ += "inline const {{ENUM_NAME}} (&EnumValues{{ENUM_NAME}}())[" + num_fields + "] {"; - code_ += " static {{ENUM_NAME}} values[] = {"; + code_ += " static const {{ENUM_NAME}} values[] = {"; for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end(); ++it) { const auto &ev = **it; @@ -951,8 +954,8 @@ class CppGenerator : public BaseGenerator { static const int kMaxSparseness = 5; if (range / static_cast<int64_t>(enum_def.vals.vec.size()) < kMaxSparseness) { - code_ += "inline const char **EnumNames{{ENUM_NAME}}() {"; - code_ += " static const char *names[] = {"; + code_ += "inline const char * const *EnumNames{{ENUM_NAME}}() {"; + code_ += " static const char * const names[] = {"; auto val = enum_def.vals.vec.front()->value; for (auto it = enum_def.vals.vec.begin(); it != enum_def.vals.vec.end(); @@ -1548,7 +1551,7 @@ class CppGenerator : public BaseGenerator { code_ += " typedef {{NATIVE_NAME}} NativeTableType;"; } if (parser_.opts.mini_reflect != IDLOptions::kNone) { - code_ += " static flatbuffers::TypeTable *MiniReflectTypeTable() {"; + code_ += " static const flatbuffers::TypeTable *MiniReflectTypeTable() {"; code_ += " return {{STRUCT_NAME}}TypeTable();"; code_ += " }"; } diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp index 970f08cc..358169be 100644 --- a/src/idl_gen_general.cpp +++ b/src/idl_gen_general.cpp @@ -60,7 +60,7 @@ struct LanguageParameters { }; const LanguageParameters &GetLangParams(IDLOptions::Language lang) { - static LanguageParameters language_parameters[] = { + static const LanguageParameters language_parameters[] = { { IDLOptions::kJava, false, @@ -191,7 +191,7 @@ class GeneralGenerator : public BaseGenerator { // Save out the generated code for a single class while adding // declaration boilerplate. bool SaveType(const std::string &defname, const Namespace &ns, - const std::string &classcode, bool needs_includes) { + const std::string &classcode, bool needs_includes) const { if (!classcode.length()) return true; std::string code; @@ -226,13 +226,13 @@ class GeneralGenerator : public BaseGenerator { const Namespace *CurrentNameSpace() const { return cur_name_space_; } - std::string FunctionStart(char upper) { + std::string FunctionStart(char upper) const { return std::string() + (lang_.language == IDLOptions::kJava ? static_cast<char>(tolower(upper)) : upper); } - std::string GenNullableAnnotation(const Type &t) { + std::string GenNullableAnnotation(const Type &t) const { return lang_.language == IDLOptions::kJava && parser_.opts.gen_nullable && !IsScalar(DestinationType(t, true).base_type) ? " @Nullable " @@ -243,9 +243,9 @@ class GeneralGenerator : public BaseGenerator { return type.enum_def != nullptr && IsInteger(type.base_type); } - std::string GenTypeBasic(const Type &type, bool enableLangOverrides) { + std::string GenTypeBasic(const Type &type, bool enableLangOverrides) const { // clang-format off - static const char *java_typename[] = { + static const char * const java_typename[] = { #define FLATBUFFERS_TD(ENUM, IDLTYPE, \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ #JTYPE, @@ -253,7 +253,7 @@ class GeneralGenerator : public BaseGenerator { #undef FLATBUFFERS_TD }; - static const char *csharp_typename[] = { + static const char * const csharp_typename[] = { #define FLATBUFFERS_TD(ENUM, IDLTYPE, \ CTYPE, JTYPE, GTYPE, NTYPE, PTYPE) \ #NTYPE, @@ -279,11 +279,11 @@ class GeneralGenerator : public BaseGenerator { } } - std::string GenTypeBasic(const Type &type) { + std::string GenTypeBasic(const Type &type) const { return GenTypeBasic(type, true); } - std::string GenTypePointer(const Type &type) { + std::string GenTypePointer(const Type &type) const { switch (type.base_type) { case BASE_TYPE_STRING: return lang_.string_type; case BASE_TYPE_VECTOR: return GenTypeGet(type.VectorType()); @@ -296,13 +296,13 @@ class GeneralGenerator : public BaseGenerator { } } - std::string GenTypeGet(const Type &type) { + std::string GenTypeGet(const Type &type) const { return IsScalar(type.base_type) ? GenTypeBasic(type) : GenTypePointer(type); } // Find the destination type the user wants to receive the value in (e.g. // one size higher signed types for unsigned serialized values in Java). - Type DestinationType(const Type &type, bool vectorelem) { + Type DestinationType(const Type &type, bool vectorelem) const { if (lang_.language != IDLOptions::kJava) return type; switch (type.base_type) { // We use int for both uchar/ushort, since that generally means less @@ -317,7 +317,7 @@ class GeneralGenerator : public BaseGenerator { } } - std::string GenOffsetType(const StructDef &struct_def) { + std::string GenOffsetType(const StructDef &struct_def) const { if (lang_.language == IDLOptions::kCSharp) { return "Offset<" + WrapInNameSpace(struct_def) + ">"; } else { @@ -326,7 +326,7 @@ class GeneralGenerator : public BaseGenerator { } std::string GenOffsetConstruct(const StructDef &struct_def, - const std::string &variable_name) { + const std::string &variable_name) const { if (lang_.language == IDLOptions::kCSharp) { return "new Offset<" + WrapInNameSpace(struct_def) + ">(" + variable_name + ")"; @@ -334,7 +334,7 @@ class GeneralGenerator : public BaseGenerator { return variable_name; } - std::string GenVectorOffsetType() { + std::string GenVectorOffsetType() const { if (lang_.language == IDLOptions::kCSharp) { return "VectorOffset"; } else { @@ -343,12 +343,12 @@ class GeneralGenerator : public BaseGenerator { } // Generate destination type name - std::string GenTypeNameDest(const Type &type) { + std::string GenTypeNameDest(const Type &type) const { return GenTypeGet(DestinationType(type, true)); } // Mask to turn serialized value into destination type value. - std::string DestinationMask(const Type &type, bool vectorelem) { + std::string DestinationMask(const Type &type, bool vectorelem) const { if (lang_.language != IDLOptions::kJava) return ""; switch (type.base_type) { case BASE_TYPE_UCHAR: return " & 0xFF"; @@ -362,7 +362,7 @@ class GeneralGenerator : public BaseGenerator { } // Casts necessary to correctly read serialized data - std::string DestinationCast(const Type &type) { + std::string DestinationCast(const Type &type) const { if (type.base_type == BASE_TYPE_VECTOR) { return DestinationCast(type.VectorType()); } else { @@ -389,7 +389,7 @@ class GeneralGenerator : public BaseGenerator { // would be cast down to int before being put onto the buffer. In C#, one cast // directly cast an Enum to its underlying type, which is essential before // putting it onto the buffer. - std::string SourceCast(const Type &type, bool castFromDest) { + std::string SourceCast(const Type &type, bool castFromDest) const { if (type.base_type == BASE_TYPE_VECTOR) { return SourceCast(type.VectorType(), castFromDest); } else { @@ -413,17 +413,17 @@ class GeneralGenerator : public BaseGenerator { return ""; } - std::string SourceCast(const Type &type) { return SourceCast(type, true); } + std::string SourceCast(const Type &type) const { return SourceCast(type, true); } - std::string SourceCastBasic(const Type &type, bool castFromDest) { + std::string SourceCastBasic(const Type &type, bool castFromDest) const { return IsScalar(type.base_type) ? SourceCast(type, castFromDest) : ""; } - std::string SourceCastBasic(const Type &type) { + std::string SourceCastBasic(const Type &type) const { return SourceCastBasic(type, true); } - std::string GenEnumDefaultValue(const Value &value) { + std::string GenEnumDefaultValue(const Value &value) const { auto enum_def = value.type.enum_def; auto vec = enum_def->vals.vec; auto default_value = StringToInt(value.constant.c_str()); @@ -440,7 +440,7 @@ class GeneralGenerator : public BaseGenerator { return result; } - std::string GenDefaultValue(const Value &value, bool enableLangOverrides) { + std::string GenDefaultValue(const Value &value, bool enableLangOverrides) const { if (enableLangOverrides) { // handles both enum case and vector of enum case if (lang_.language == IDLOptions::kCSharp && @@ -466,12 +466,12 @@ class GeneralGenerator : public BaseGenerator { } } - std::string GenDefaultValue(const Value &value) { + std::string GenDefaultValue(const Value &value) const { return GenDefaultValue(value, true); } std::string GenDefaultValueBasic(const Value &value, - bool enableLangOverrides) { + bool enableLangOverrides) const { if (!IsScalar(value.type.base_type)) { if (enableLangOverrides) { if (lang_.language == IDLOptions::kCSharp) { @@ -490,11 +490,11 @@ class GeneralGenerator : public BaseGenerator { return GenDefaultValue(value, enableLangOverrides); } - std::string GenDefaultValueBasic(const Value &value) { + std::string GenDefaultValueBasic(const Value &value) const { return GenDefaultValueBasic(value, true); } - void GenEnum(EnumDef &enum_def, std::string *code_ptr) { + void GenEnum(EnumDef &enum_def, std::string *code_ptr) const { std::string &code = *code_ptr; if (enum_def.generated) return; @@ -569,7 +569,7 @@ class GeneralGenerator : public BaseGenerator { } // Returns the function name that is able to read a value of the given type. - std::string GenGetter(const Type &type) { + std::string GenGetter(const Type &type) const { switch (type.base_type) { case BASE_TYPE_STRING: return lang_.accessor_prefix + "__string"; case BASE_TYPE_STRUCT: return lang_.accessor_prefix + "__struct"; @@ -591,7 +591,7 @@ class GeneralGenerator : public BaseGenerator { // Returns the function name that is able to read a value of the given type. std::string GenGetterForLookupByKey(flatbuffers::FieldDef *key_field, const std::string &data_buffer, - const char *num = nullptr) { + const char *num = nullptr) const { auto type = key_field->value.type; auto dest_mask = DestinationMask(type, true); auto dest_cast = DestinationCast(type); @@ -606,7 +606,7 @@ class GeneralGenerator : public BaseGenerator { // Direct mutation is only allowed for scalar fields. // Hence a setter method will only be generated for such fields. - std::string GenSetter(const Type &type) { + std::string GenSetter(const Type &type) const { if (IsScalar(type.base_type)) { std::string setter = lang_.accessor_prefix + "bb." + FunctionStart('P') + "ut"; @@ -621,7 +621,7 @@ class GeneralGenerator : public BaseGenerator { } // Returns the method name for use with add/put calls. - std::string GenMethod(const Type &type) { + std::string GenMethod(const Type &type) const { return IsScalar(type.base_type) ? MakeCamel(GenTypeBasic(type, false)) : (IsStruct(type) ? "Struct" : "Offset"); } @@ -629,7 +629,7 @@ class GeneralGenerator : public BaseGenerator { // Recursively generate arguments for a constructor, to deal with nested // structs. void GenStructArgs(const StructDef &struct_def, std::string *code_ptr, - const char *nameprefix) { + const char *nameprefix) const { std::string &code = *code_ptr; for (auto it = struct_def.fields.vec.begin(); it != struct_def.fields.vec.end(); ++it) { @@ -654,7 +654,7 @@ class GeneralGenerator : public BaseGenerator { // builder.putType(name); // and insert manual padding. void GenStructBody(const StructDef &struct_def, std::string *code_ptr, - const char *nameprefix) { + const char *nameprefix) const { std::string &code = *code_ptr; code += " builder." + FunctionStart('P') + "rep("; code += NumToString(struct_def.minalign) + ", "; @@ -681,7 +681,7 @@ class GeneralGenerator : public BaseGenerator { } } - std::string GenByteBufferLength(const char *bb_name) { + std::string GenByteBufferLength(const char *bb_name) const { std::string bb_len = bb_name; if (lang_.language == IDLOptions::kCSharp) bb_len += ".Length"; @@ -691,7 +691,7 @@ class GeneralGenerator : public BaseGenerator { } std::string GenOffsetGetter(flatbuffers::FieldDef *key_field, - const char *num = nullptr) { + const char *num = nullptr) const { std::string key_offset = ""; key_offset += lang_.accessor_prefix_static + "__offset(" + NumToString(key_field->value.offset) + ", "; @@ -707,7 +707,7 @@ class GeneralGenerator : public BaseGenerator { return key_offset; } - std::string GenLookupKeyGetter(flatbuffers::FieldDef *key_field) { + std::string GenLookupKeyGetter(flatbuffers::FieldDef *key_field) const { std::string key_getter = " "; key_getter += "int tableOffset = " + lang_.accessor_prefix_static; key_getter += "__indirect(vectorLocation + 4 * (start + middle)"; @@ -730,7 +730,7 @@ class GeneralGenerator : public BaseGenerator { return key_getter; } - std::string GenKeyGetter(flatbuffers::FieldDef *key_field) { + std::string GenKeyGetter(flatbuffers::FieldDef *key_field) const { std::string key_getter = ""; auto data_buffer = (lang_.language == IDLOptions::kCSharp) ? "builder.DataBuffer" : "_bb"; @@ -762,7 +762,7 @@ class GeneralGenerator : public BaseGenerator { return key_getter; } - void GenStruct(StructDef &struct_def, std::string *code_ptr) { + void GenStruct(StructDef &struct_def, std::string *code_ptr) const { if (struct_def.generated) return; std::string &code = *code_ptr; diff --git a/src/idl_gen_go.cpp b/src/idl_gen_go.cpp index ddf60a59..810751e4 100644 --- a/src/idl_gen_go.cpp +++ b/src/idl_gen_go.cpp @@ -43,7 +43,7 @@ static std::string GeneratedFileName(const std::string &path, namespace go { // see https://golang.org/ref/spec#Keywords -static const char *g_golang_keywords[] = { +static const char * const g_golang_keywords[] = { "break", "default", "func", "interface", "select", "case", "defer", "go", "map", "struct", "chan", "else", "goto", "package", "switch", "const", "fallthrough", "if", "range", "type", "continue", diff --git a/src/idl_parser.cpp b/src/idl_parser.cpp index 2607c0cd..b16e3e13 100644 --- a/src/idl_parser.cpp +++ b/src/idl_parser.cpp @@ -205,7 +205,7 @@ enum { }; static std::string TokenToString(int t) { - static const char *tokens[] = { + static const char * const tokens[] = { #define FLATBUFFERS_TOKEN(NAME, VALUE, STRING) STRING, FLATBUFFERS_GEN_TOKENS(FLATBUFFERS_TOKEN) #undef FLATBUFFERS_TOKEN @@ -225,7 +225,7 @@ static std::string TokenToString(int t) { } // clang-format on -std::string Parser::TokenToStringId(int t) { +std::string Parser::TokenToStringId(int t) const { return t == kTokenIdentifier ? attribute_ : TokenToString(t); } @@ -478,9 +478,9 @@ CheckedError Parser::Next() { } // Check if a given token is next. -bool Parser::Is(int t) { return t == token_; } +bool Parser::Is(int t) const { return t == token_; } -bool Parser::IsIdent(const char *id) { +bool Parser::IsIdent(const char *id) const { return token_ == kTokenIdentifier && attribute_ == id; } diff --git a/tests/monster_test.bfbs b/tests/monster_test.bfbs index 76057281704be584128772e75e929d6ede2867cb..0093defa39236196ec7a5b46b46b6c25ac81c770 100644 GIT binary patch literal 6184 zcmai&ZHQIJ8OLYWefRFJS&dnZHAic$wX*oKl^{jb>Lw9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XLiDM4B-n63im=ngNoKbIQ zCbqlF)h=t<0hjF7+Gl~-Zms2O!1KT`pk%m4cL`{+4kv<{?beRW)h>@$?%i?k!-^WG ztJWCw@;I5Ji=O^|%~6fhRVoktDlAR<*6V%g);fz;wcvGd&ECShJnb6g_DjI~d^d~x zbOW8vsyFyf>RoD}IStLb#P~t`=sD&$1Bv{d#N1{-u|XN%8?~>rLUD`NxNSw<*19&f z_x*a`kD;&IIv?U+EG2W${qD%1ML8;r<R}N?Jka-9U?<RI-DN*BaX$JxGl+WgwzeQO z8M~|Q-1X<mH2nQ&RF1D~-OTvBlx?w1ib#f<U9UH*wU#+x44KlCtYe@Wejkm0UmYEZ zAL!v%@JU{M&7KX9x(AwmhI8*T$$cB%2d%m6kd5xw)4iP0&gXPZ&O5yI=}eR_)2vG4 zuZHqyE%*oN*;AjZ+nM;S&}rYdyhh$8Sn4gEPs?%EJw<gTKCi7$b>7EYzn8_iBvAwR VbLl~AAp4u!_`R@N=EqXn{{a6@Xv+Wq diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index c2a71ab1..fd0f7843 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -44,31 +44,31 @@ struct TypeAliasesT; } // namespace Example -inline flatbuffers::TypeTable *InParentNamespaceTypeTable(); +inline const flatbuffers::TypeTable *InParentNamespaceTypeTable(); namespace Example2 { -inline flatbuffers::TypeTable *MonsterTypeTable(); +inline const flatbuffers::TypeTable *MonsterTypeTable(); } // namespace Example2 namespace Example { -inline flatbuffers::TypeTable *TestTypeTable(); +inline const flatbuffers::TypeTable *TestTypeTable(); -inline flatbuffers::TypeTable *TestSimpleTableWithEnumTypeTable(); +inline const flatbuffers::TypeTable *TestSimpleTableWithEnumTypeTable(); -inline flatbuffers::TypeTable *Vec3TypeTable(); +inline const flatbuffers::TypeTable *Vec3TypeTable(); -inline flatbuffers::TypeTable *AbilityTypeTable(); +inline const flatbuffers::TypeTable *AbilityTypeTable(); -inline flatbuffers::TypeTable *StatTypeTable(); +inline const flatbuffers::TypeTable *StatTypeTable(); -inline flatbuffers::TypeTable *ReferrableTypeTable(); +inline const flatbuffers::TypeTable *ReferrableTypeTable(); -inline flatbuffers::TypeTable *MonsterTypeTable(); +inline const flatbuffers::TypeTable *MonsterTypeTable(); -inline flatbuffers::TypeTable *TypeAliasesTypeTable(); +inline const flatbuffers::TypeTable *TypeAliasesTypeTable(); enum Color { Color_Red = 1, @@ -78,8 +78,8 @@ enum Color { Color_ANY = 11 }; -inline Color (&EnumValuesColor())[3] { - static Color values[] = { +inline const Color (&EnumValuesColor())[3] { + static const Color values[] = { Color_Red, Color_Green, Color_Blue @@ -87,8 +87,8 @@ inline Color (&EnumValuesColor())[3] { return values; } -inline const char **EnumNamesColor() { - static const char *names[] = { +inline const char * const *EnumNamesColor() { + static const char * const names[] = { "Red", "Green", "", @@ -116,8 +116,8 @@ enum Any { Any_MAX = Any_MyGame_Example2_Monster }; -inline Any (&EnumValuesAny())[4] { - static Any values[] = { +inline const Any (&EnumValuesAny())[4] { + static const Any values[] = { Any_NONE, Any_Monster, Any_TestSimpleTableWithEnum, @@ -126,8 +126,8 @@ inline Any (&EnumValuesAny())[4] { return values; } -inline const char **EnumNamesAny() { - static const char *names[] = { +inline const char * const *EnumNamesAny() { + static const char * const names[] = { "NONE", "Monster", "TestSimpleTableWithEnum", @@ -363,7 +363,7 @@ struct InParentNamespaceT : public flatbuffers::NativeTable { struct InParentNamespace FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef InParentNamespaceT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return InParentNamespaceTypeTable(); } bool Verify(flatbuffers::Verifier &verifier) const { @@ -408,7 +408,7 @@ struct MonsterT : public flatbuffers::NativeTable { struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef MonsterT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return MonsterTypeTable(); } bool Verify(flatbuffers::Verifier &verifier) const { @@ -457,7 +457,7 @@ struct TestSimpleTableWithEnumT : public flatbuffers::NativeTable { struct TestSimpleTableWithEnum FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef TestSimpleTableWithEnumT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return TestSimpleTableWithEnumTypeTable(); } enum { @@ -520,7 +520,7 @@ struct StatT : public flatbuffers::NativeTable { struct Stat FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef StatT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return StatTypeTable(); } enum { @@ -619,7 +619,7 @@ struct ReferrableT : public flatbuffers::NativeTable { struct Referrable FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef ReferrableT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return ReferrableTypeTable(); } enum { @@ -750,7 +750,7 @@ struct MonsterT : public flatbuffers::NativeTable { /// an example documentation comment: monster object struct Monster FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef MonsterT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return MonsterTypeTable(); } enum { @@ -1518,7 +1518,7 @@ struct TypeAliasesT : public flatbuffers::NativeTable { struct TypeAliases FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef TypeAliasesT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return TypeAliasesTypeTable(); } enum { @@ -2207,46 +2207,46 @@ inline void AnyUnion::Reset() { type = Any_NONE; } -inline flatbuffers::TypeTable *ColorTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *ColorTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_CHAR, 0, 0 }, { flatbuffers::ET_CHAR, 0, 0 }, { flatbuffers::ET_CHAR, 0, 0 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { ColorTypeTable }; static const int32_t values[] = { 1, 2, 8 }; - static const char *names[] = { + static const char * const names[] = { "Red", "Green", "Blue" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_ENUM, 3, type_codes, type_refs, values, names }; return &tt; } -inline flatbuffers::TypeTable *AnyTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *AnyTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SEQUENCE, 0, -1 }, { flatbuffers::ET_SEQUENCE, 0, 0 }, { flatbuffers::ET_SEQUENCE, 0, 1 }, { flatbuffers::ET_SEQUENCE, 0, 2 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { MonsterTypeTable, TestSimpleTableWithEnumTypeTable, MyGame::Example2::MonsterTypeTable }; - static const char *names[] = { + static const char * const names[] = { "NONE", "Monster", "TestSimpleTableWithEnum", "MyGame_Example2_Monster" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_UNION, 4, type_codes, type_refs, nullptr, names }; return &tt; @@ -2254,8 +2254,8 @@ inline flatbuffers::TypeTable *AnyTypeTable() { } // namespace Example -inline flatbuffers::TypeTable *InParentNamespaceTypeTable() { - static flatbuffers::TypeTable tt = { +inline const flatbuffers::TypeTable *InParentNamespaceTypeTable() { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 0, nullptr, nullptr, nullptr, nullptr }; return &tt; @@ -2263,8 +2263,8 @@ inline flatbuffers::TypeTable *InParentNamespaceTypeTable() { namespace Example2 { -inline flatbuffers::TypeTable *MonsterTypeTable() { - static flatbuffers::TypeTable tt = { +inline const flatbuffers::TypeTable *MonsterTypeTable() { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 0, nullptr, nullptr, nullptr, nullptr }; return &tt; @@ -2274,40 +2274,40 @@ inline flatbuffers::TypeTable *MonsterTypeTable() { namespace Example { -inline flatbuffers::TypeTable *TestTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *TestTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SHORT, 0, -1 }, { flatbuffers::ET_CHAR, 0, -1 } }; static const int32_t values[] = { 0, 2, 4 }; - static const char *names[] = { + static const char * const names[] = { "a", "b" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_STRUCT, 2, type_codes, nullptr, values, names }; return &tt; } -inline flatbuffers::TypeTable *TestSimpleTableWithEnumTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *TestSimpleTableWithEnumTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_CHAR, 0, 0 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { ColorTypeTable }; - static const char *names[] = { + static const char * const names[] = { "color" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 1, type_codes, type_refs, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *Vec3TypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *Vec3TypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_FLOAT, 0, -1 }, { flatbuffers::ET_FLOAT, 0, -1 }, { flatbuffers::ET_FLOAT, 0, -1 }, @@ -2315,12 +2315,12 @@ inline flatbuffers::TypeTable *Vec3TypeTable() { { flatbuffers::ET_CHAR, 0, 0 }, { flatbuffers::ET_SEQUENCE, 0, 1 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { ColorTypeTable, TestTypeTable }; static const int32_t values[] = { 0, 4, 8, 16, 24, 26, 32 }; - static const char *names[] = { + static const char * const names[] = { "x", "y", "z", @@ -2328,60 +2328,60 @@ inline flatbuffers::TypeTable *Vec3TypeTable() { "test2", "test3" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_STRUCT, 6, type_codes, type_refs, values, names }; return &tt; } -inline flatbuffers::TypeTable *AbilityTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *AbilityTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_UINT, 0, -1 }, { flatbuffers::ET_UINT, 0, -1 } }; static const int32_t values[] = { 0, 4, 8 }; - static const char *names[] = { + static const char * const names[] = { "id", "distance" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_STRUCT, 2, type_codes, nullptr, values, names }; return &tt; } -inline flatbuffers::TypeTable *StatTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *StatTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_STRING, 0, -1 }, { flatbuffers::ET_LONG, 0, -1 }, { flatbuffers::ET_USHORT, 0, -1 } }; - static const char *names[] = { + static const char * const names[] = { "id", "val", "count" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 3, type_codes, nullptr, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *ReferrableTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *ReferrableTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_ULONG, 0, -1 } }; - static const char *names[] = { + static const char * const names[] = { "id" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 1, type_codes, nullptr, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *MonsterTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *MonsterTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SEQUENCE, 0, 0 }, { flatbuffers::ET_SHORT, 0, -1 }, { flatbuffers::ET_SHORT, 0, -1 }, @@ -2426,7 +2426,7 @@ inline flatbuffers::TypeTable *MonsterTypeTable() { { flatbuffers::ET_ULONG, 0, -1 }, { flatbuffers::ET_ULONG, 1, -1 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { Vec3TypeTable, ColorTypeTable, AnyTypeTable, @@ -2437,7 +2437,7 @@ inline flatbuffers::TypeTable *MonsterTypeTable() { MyGame::InParentNamespaceTypeTable, ReferrableTypeTable }; - static const char *names[] = { + static const char * const names[] = { "pos", "mana", "hp", @@ -2482,14 +2482,14 @@ inline flatbuffers::TypeTable *MonsterTypeTable() { "non_owning_reference", "vector_of_non_owning_references" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 43, type_codes, type_refs, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *TypeAliasesTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *TypeAliasesTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_CHAR, 0, -1 }, { flatbuffers::ET_UCHAR, 0, -1 }, { flatbuffers::ET_SHORT, 0, -1 }, @@ -2503,7 +2503,7 @@ inline flatbuffers::TypeTable *TypeAliasesTypeTable() { { flatbuffers::ET_CHAR, 1, -1 }, { flatbuffers::ET_DOUBLE, 1, -1 } }; - static const char *names[] = { + static const char * const names[] = { "i8", "u8", "i16", @@ -2517,7 +2517,7 @@ inline flatbuffers::TypeTable *TypeAliasesTypeTable() { "v8", "vf64" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 12, type_codes, nullptr, nullptr, names }; return &tt; diff --git a/tests/namespace_test/namespace_test1_generated.h b/tests/namespace_test/namespace_test1_generated.h index 4b85249a..2068d1fc 100644 --- a/tests/namespace_test/namespace_test1_generated.h +++ b/tests/namespace_test/namespace_test1_generated.h @@ -13,9 +13,9 @@ struct TableInNestedNS; struct StructInNestedNS; -inline flatbuffers::TypeTable *TableInNestedNSTypeTable(); +inline const flatbuffers::TypeTable *TableInNestedNSTypeTable(); -inline flatbuffers::TypeTable *StructInNestedNSTypeTable(); +inline const flatbuffers::TypeTable *StructInNestedNSTypeTable(); enum EnumInNestedNS { EnumInNestedNS_A = 0, @@ -25,8 +25,8 @@ enum EnumInNestedNS { EnumInNestedNS_MAX = EnumInNestedNS_C }; -inline EnumInNestedNS (&EnumValuesEnumInNestedNS())[3] { - static EnumInNestedNS values[] = { +inline const EnumInNestedNS (&EnumValuesEnumInNestedNS())[3] { + static const EnumInNestedNS values[] = { EnumInNestedNS_A, EnumInNestedNS_B, EnumInNestedNS_C @@ -34,8 +34,8 @@ inline EnumInNestedNS (&EnumValuesEnumInNestedNS())[3] { return values; } -inline const char **EnumNamesEnumInNestedNS() { - static const char *names[] = { +inline const char * const *EnumNamesEnumInNestedNS() { + static const char * const names[] = { "A", "B", "C", @@ -78,7 +78,7 @@ MANUALLY_ALIGNED_STRUCT(4) StructInNestedNS FLATBUFFERS_FINAL_CLASS { STRUCT_END(StructInNestedNS, 8); struct TableInNestedNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return TableInNestedNSTypeTable(); } enum { @@ -123,50 +123,50 @@ inline flatbuffers::Offset<TableInNestedNS> CreateTableInNestedNS( return builder_.Finish(); } -inline flatbuffers::TypeTable *EnumInNestedNSTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *EnumInNestedNSTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_CHAR, 0, 0 }, { flatbuffers::ET_CHAR, 0, 0 }, { flatbuffers::ET_CHAR, 0, 0 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { EnumInNestedNSTypeTable }; - static const char *names[] = { + static const char * const names[] = { "A", "B", "C" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_ENUM, 3, type_codes, type_refs, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *TableInNestedNSTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *TableInNestedNSTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_INT, 0, -1 } }; - static const char *names[] = { + static const char * const names[] = { "foo" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 1, type_codes, nullptr, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *StructInNestedNSTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *StructInNestedNSTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_INT, 0, -1 }, { flatbuffers::ET_INT, 0, -1 } }; static const int32_t values[] = { 0, 4, 8 }; - static const char *names[] = { + static const char * const names[] = { "a", "b" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_STRUCT, 2, type_codes, nullptr, values, names }; return &tt; diff --git a/tests/namespace_test/namespace_test2_generated.h b/tests/namespace_test/namespace_test2_generated.h index 510e1de3..4a111dc8 100644 --- a/tests/namespace_test/namespace_test2_generated.h +++ b/tests/namespace_test/namespace_test2_generated.h @@ -24,22 +24,22 @@ namespace NamespaceA { struct SecondTableInA; -inline flatbuffers::TypeTable *TableInFirstNSTypeTable(); +inline const flatbuffers::TypeTable *TableInFirstNSTypeTable(); } // namespace NamespaceA namespace NamespaceC { -inline flatbuffers::TypeTable *TableInCTypeTable(); +inline const flatbuffers::TypeTable *TableInCTypeTable(); } // namespace NamespaceC namespace NamespaceA { -inline flatbuffers::TypeTable *SecondTableInATypeTable(); +inline const flatbuffers::TypeTable *SecondTableInATypeTable(); struct TableInFirstNS FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return TableInFirstNSTypeTable(); } enum { @@ -116,7 +116,7 @@ inline flatbuffers::Offset<TableInFirstNS> CreateTableInFirstNS( namespace NamespaceC { struct TableInC FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return TableInCTypeTable(); } enum { @@ -181,7 +181,7 @@ inline flatbuffers::Offset<TableInC> CreateTableInC( namespace NamespaceA { struct SecondTableInA FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return SecondTableInATypeTable(); } enum { @@ -235,23 +235,23 @@ namespace NamespaceC { namespace NamespaceA { -inline flatbuffers::TypeTable *TableInFirstNSTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *TableInFirstNSTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SEQUENCE, 0, 0 }, { flatbuffers::ET_CHAR, 0, 1 }, { flatbuffers::ET_SEQUENCE, 0, 2 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { NamespaceA::NamespaceB::TableInNestedNSTypeTable, NamespaceA::NamespaceB::EnumInNestedNSTypeTable, NamespaceA::NamespaceB::StructInNestedNSTypeTable }; - static const char *names[] = { + static const char * const names[] = { "foo_table", "foo_enum", "foo_struct" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 3, type_codes, type_refs, nullptr, names }; return &tt; @@ -261,20 +261,20 @@ inline flatbuffers::TypeTable *TableInFirstNSTypeTable() { namespace NamespaceC { -inline flatbuffers::TypeTable *TableInCTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *TableInCTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SEQUENCE, 0, 0 }, { flatbuffers::ET_SEQUENCE, 0, 1 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { NamespaceA::TableInFirstNSTypeTable, NamespaceA::SecondTableInATypeTable }; - static const char *names[] = { + static const char * const names[] = { "refer_to_a1", "refer_to_a2" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 2, type_codes, type_refs, nullptr, names }; return &tt; @@ -284,17 +284,17 @@ inline flatbuffers::TypeTable *TableInCTypeTable() { namespace NamespaceA { -inline flatbuffers::TypeTable *SecondTableInATypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *SecondTableInATypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SEQUENCE, 0, 0 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { NamespaceC::TableInCTypeTable }; - static const char *names[] = { + static const char * const names[] = { "refer_to_c" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 1, type_codes, type_refs, nullptr, names }; return &tt; diff --git a/tests/namespace_test/namespace_test2_generated.ts b/tests/namespace_test/namespace_test2_generated.ts index aa623a87..61cf6312 100644 --- a/tests/namespace_test/namespace_test2_generated.ts +++ b/tests/namespace_test/namespace_test2_generated.ts @@ -1,6 +1,6 @@ // automatically generated by the FlatBuffers compiler, do not modify -import * as NS4989953370203581498 from "./namespace_test1_generated"; +import * as NS39599748 from "./namespace_test1_generated"; /** * @constructor */ @@ -39,24 +39,24 @@ static getRootAsTableInFirstNS(bb:flatbuffers.ByteBuffer, obj?:TableInFirstNS):T * @param {NamespaceA.NamespaceB.TableInNestedNS=} obj * @returns {NamespaceA.NamespaceB.TableInNestedNS|null} */ -fooTable(obj?:NS4989953370203581498.NamespaceA.NamespaceB.TableInNestedNS):NS4989953370203581498.NamespaceA.NamespaceB.TableInNestedNS|null { +fooTable(obj?:NS39599748.NamespaceA.NamespaceB.TableInNestedNS):NS39599748.NamespaceA.NamespaceB.TableInNestedNS|null { var offset = this.bb!.__offset(this.bb_pos, 4); - return offset ? (obj || new NS4989953370203581498.NamespaceA.NamespaceB.TableInNestedNS).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; + return offset ? (obj || new NS39599748.NamespaceA.NamespaceB.TableInNestedNS).__init(this.bb!.__indirect(this.bb_pos + offset), this.bb!) : null; }; /** * @returns {NamespaceA.NamespaceB.EnumInNestedNS} */ -fooEnum():NS4989953370203581498.NamespaceA.NamespaceB.EnumInNestedNS { +fooEnum():NS39599748.NamespaceA.NamespaceB.EnumInNestedNS { var offset = this.bb!.__offset(this.bb_pos, 6); - return offset ? /** @type {NamespaceA.NamespaceB.EnumInNestedNS} */ (this.bb!.readInt8(this.bb_pos + offset)) : NS4989953370203581498.NamespaceA.NamespaceB.EnumInNestedNS.A; + return offset ? /** @type {NamespaceA.NamespaceB.EnumInNestedNS} */ (this.bb!.readInt8(this.bb_pos + offset)) : NS39599748.NamespaceA.NamespaceB.EnumInNestedNS.A; }; /** * @param {NamespaceA.NamespaceB.EnumInNestedNS} value * @returns {boolean} */ -mutate_foo_enum(value:NS4989953370203581498.NamespaceA.NamespaceB.EnumInNestedNS):boolean { +mutate_foo_enum(value:NS39599748.NamespaceA.NamespaceB.EnumInNestedNS):boolean { var offset = this.bb!.__offset(this.bb_pos, 6); if (offset === 0) { @@ -71,9 +71,9 @@ mutate_foo_enum(value:NS4989953370203581498.NamespaceA.NamespaceB.EnumInNestedNS * @param {NamespaceA.NamespaceB.StructInNestedNS=} obj * @returns {NamespaceA.NamespaceB.StructInNestedNS|null} */ -fooStruct(obj?:NS4989953370203581498.NamespaceA.NamespaceB.StructInNestedNS):NS4989953370203581498.NamespaceA.NamespaceB.StructInNestedNS|null { +fooStruct(obj?:NS39599748.NamespaceA.NamespaceB.StructInNestedNS):NS39599748.NamespaceA.NamespaceB.StructInNestedNS|null { var offset = this.bb!.__offset(this.bb_pos, 8); - return offset ? (obj || new NS4989953370203581498.NamespaceA.NamespaceB.StructInNestedNS).__init(this.bb_pos + offset, this.bb!) : null; + return offset ? (obj || new NS39599748.NamespaceA.NamespaceB.StructInNestedNS).__init(this.bb_pos + offset, this.bb!) : null; }; /** @@ -95,8 +95,8 @@ static addFooTable(builder:flatbuffers.Builder, fooTableOffset:flatbuffers.Offse * @param {flatbuffers.Builder} builder * @param {NamespaceA.NamespaceB.EnumInNestedNS} fooEnum */ -static addFooEnum(builder:flatbuffers.Builder, fooEnum:NS4989953370203581498.NamespaceA.NamespaceB.EnumInNestedNS) { - builder.addFieldInt8(1, fooEnum, NS4989953370203581498.NamespaceA.NamespaceB.EnumInNestedNS.A); +static addFooEnum(builder:flatbuffers.Builder, fooEnum:NS39599748.NamespaceA.NamespaceB.EnumInNestedNS) { + builder.addFieldInt8(1, fooEnum, NS39599748.NamespaceA.NamespaceB.EnumInNestedNS.A); }; /** diff --git a/tests/union_vector/union_vector_generated.h b/tests/union_vector/union_vector_generated.h index ba9234da..07b17a9c 100644 --- a/tests/union_vector/union_vector_generated.h +++ b/tests/union_vector/union_vector_generated.h @@ -16,13 +16,13 @@ struct BookReader; struct Movie; struct MovieT; -inline flatbuffers::TypeTable *AttackerTypeTable(); +inline const flatbuffers::TypeTable *AttackerTypeTable(); -inline flatbuffers::TypeTable *RapunzelTypeTable(); +inline const flatbuffers::TypeTable *RapunzelTypeTable(); -inline flatbuffers::TypeTable *BookReaderTypeTable(); +inline const flatbuffers::TypeTable *BookReaderTypeTable(); -inline flatbuffers::TypeTable *MovieTypeTable(); +inline const flatbuffers::TypeTable *MovieTypeTable(); enum Character { Character_NONE = 0, @@ -36,8 +36,8 @@ enum Character { Character_MAX = Character_Unused }; -inline Character (&EnumValuesCharacter())[7] { - static Character values[] = { +inline const Character (&EnumValuesCharacter())[7] { + static const Character values[] = { Character_NONE, Character_MuLan, Character_Rapunzel, @@ -49,8 +49,8 @@ inline Character (&EnumValuesCharacter())[7] { return values; } -inline const char **EnumNamesCharacter() { - static const char *names[] = { +inline const char * const *EnumNamesCharacter() { + static const char * const names[] = { "NONE", "MuLan", "Rapunzel", @@ -191,7 +191,7 @@ struct AttackerT : public flatbuffers::NativeTable { struct Attacker FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef AttackerT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return AttackerTypeTable(); } enum { @@ -251,7 +251,7 @@ struct MovieT : public flatbuffers::NativeTable { struct Movie FLATBUFFERS_FINAL_CLASS : private flatbuffers::Table { typedef MovieT NativeTableType; - static flatbuffers::TypeTable *MiniReflectTypeTable() { + static const flatbuffers::TypeTable *MiniReflectTypeTable() { return MovieTypeTable(); } enum { @@ -609,8 +609,8 @@ inline void CharacterUnion::Reset() { type = Character_NONE; } -inline flatbuffers::TypeTable *CharacterTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *CharacterTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_SEQUENCE, 0, -1 }, { flatbuffers::ET_SEQUENCE, 0, 0 }, { flatbuffers::ET_SEQUENCE, 0, 1 }, @@ -619,12 +619,12 @@ inline flatbuffers::TypeTable *CharacterTypeTable() { { flatbuffers::ET_STRING, 0, -1 }, { flatbuffers::ET_STRING, 0, -1 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { AttackerTypeTable, RapunzelTypeTable, BookReaderTypeTable }; - static const char *names[] = { + static const char * const names[] = { "NONE", "MuLan", "Rapunzel", @@ -633,70 +633,70 @@ inline flatbuffers::TypeTable *CharacterTypeTable() { "Other", "Unused" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_UNION, 7, type_codes, type_refs, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *AttackerTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *AttackerTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_INT, 0, -1 } }; - static const char *names[] = { + static const char * const names[] = { "sword_attack_damage" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 1, type_codes, nullptr, nullptr, names }; return &tt; } -inline flatbuffers::TypeTable *RapunzelTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *RapunzelTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_INT, 0, -1 } }; static const int32_t values[] = { 0, 4 }; - static const char *names[] = { + static const char * const names[] = { "hair_length" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_STRUCT, 1, type_codes, nullptr, values, names }; return &tt; } -inline flatbuffers::TypeTable *BookReaderTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *BookReaderTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_INT, 0, -1 } }; static const int32_t values[] = { 0, 4 }; - static const char *names[] = { + static const char * const names[] = { "books_read" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_STRUCT, 1, type_codes, nullptr, values, names }; return &tt; } -inline flatbuffers::TypeTable *MovieTypeTable() { - static flatbuffers::TypeCode type_codes[] = { +inline const flatbuffers::TypeTable *MovieTypeTable() { + static const flatbuffers::TypeCode type_codes[] = { { flatbuffers::ET_UTYPE, 0, 0 }, { flatbuffers::ET_SEQUENCE, 0, 0 }, { flatbuffers::ET_UTYPE, 1, 0 }, { flatbuffers::ET_SEQUENCE, 1, 0 } }; - static flatbuffers::TypeFunction type_refs[] = { + static const flatbuffers::TypeFunction type_refs[] = { CharacterTypeTable }; - static const char *names[] = { + static const char * const names[] = { "main_character_type", "main_character", "characters_type", "characters" }; - static flatbuffers::TypeTable tt = { + static const flatbuffers::TypeTable tt = { flatbuffers::ST_TABLE, 4, type_codes, type_refs, nullptr, names }; return &tt; -- GitLab