From 03ee3db2408e477137c83195e0e18c26f9d2ab25 Mon Sep 17 00:00:00 2001 From: Wouter van Oortmerssen Date: Mon, 19 Dec 2016 17:04:35 -0800 Subject: [PATCH] Fixed Windows build errors. Change-Id: I11548bfa3cfe307598eb59c56412974c349d614d --- samples/monster_generated.h | 2 +- src/idl_gen_cpp.cpp | 4 +- src/reflection.cpp | 76 +++++++++++++++++----------------- tests/monster_test_generated.h | 2 +- 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/samples/monster_generated.h b/samples/monster_generated.h index 1f9d9f15c..a3a2fb2a9 100644 --- a/samples/monster_generated.h +++ b/samples/monster_generated.h @@ -54,7 +54,7 @@ template<> struct EquipmentTraits { }; struct EquipmentUnion { - Equipment type = Equipment_NONE; + Equipment type; flatbuffers::NativeTable *table = nullptr; EquipmentUnion() : type(Equipment_NONE), table(nullptr) {} diff --git a/src/idl_gen_cpp.cpp b/src/idl_gen_cpp.cpp index 0436f4dcc..f308a7bcb 100644 --- a/src/idl_gen_cpp.cpp +++ b/src/idl_gen_cpp.cpp @@ -525,9 +525,7 @@ class CppGenerator : public BaseGenerator { if (parser_.opts.generate_object_based_api && enum_def.is_union) { // Generate a union type code += "struct " + enum_def.name + "Union {\n"; - code += " " + enum_def.name + " type = "; - code += GetEnumValUse(enum_def, *enum_def.vals.Lookup("NONE"), parser_.opts); - code += ";\n\n"; + code += " " + enum_def.name + " type;\n\n"; code += " flatbuffers::NativeTable *table = nullptr;\n"; code += " " + enum_def.name + "Union() : type("; code += GetEnumValUse(enum_def, *enum_def.vals.Lookup("NONE"), parser_.opts); diff --git a/src/reflection.cpp b/src/reflection.cpp index e2548a49d..10b62b2ad 100644 --- a/src/reflection.cpp +++ b/src/reflection.cpp @@ -485,14 +485,14 @@ bool VerifyStruct(flatbuffers::Verifier &v, const flatbuffers::Table &parent_table, voffset_t field_offset, const reflection::Object &obj, - bool required) { + bool required) { auto offset = parent_table.GetOptionalFieldOffset(field_offset); if (required && !offset) { return false; } return !offset || v.Verify(reinterpret_cast(&parent_table) - + offset, obj.bytesize()); + + offset, obj.bytesize()); } bool VerifyVectorOfStructs(flatbuffers::Verifier &v, @@ -520,34 +520,34 @@ bool VerifyVector(flatbuffers::Verifier &v, const reflection::Schema &schema, const flatbuffers::Table &table, const reflection::Field &vec_field) { - assert(vec_field.type()->base_type() == reflection::BaseType::Vector); + assert(vec_field.type()->base_type() == reflection::Vector); if (!table.VerifyField(v, vec_field.offset())) return false; switch (vec_field.type()->element()) { - case reflection::BaseType::None: + case reflection::None: assert(false); break; - case reflection::BaseType::UType: + case reflection::UType: return v.Verify(flatbuffers::GetFieldV(table, vec_field)); - case reflection::BaseType::Bool: - case reflection::BaseType::Byte: - case reflection::BaseType::UByte: + case reflection::Bool: + case reflection::Byte: + case reflection::UByte: return v.Verify(flatbuffers::GetFieldV(table, vec_field)); - case reflection::BaseType::Short: - case reflection::BaseType::UShort: + case reflection::Short: + case reflection::UShort: return v.Verify(flatbuffers::GetFieldV(table, vec_field)); - case reflection::BaseType::Int: - case reflection::BaseType::UInt: + case reflection::Int: + case reflection::UInt: return v.Verify(flatbuffers::GetFieldV(table, vec_field)); - case reflection::BaseType::Long: - case reflection::BaseType::ULong: + case reflection::Long: + case reflection::ULong: return v.Verify(flatbuffers::GetFieldV(table, vec_field)); - case reflection::BaseType::Float: + case reflection::Float: return v.Verify(flatbuffers::GetFieldV(table, vec_field)); - case reflection::BaseType::Double: + case reflection::Double: return v.Verify(flatbuffers::GetFieldV(table, vec_field)); - case reflection::BaseType::String: { + case reflection::String: { auto vecString = flatbuffers::GetFieldV>(table, vec_field); @@ -557,10 +557,10 @@ bool VerifyVector(flatbuffers::Verifier &v, return false; } } - case reflection::BaseType::Vector: + case reflection::Vector: assert(false); break; - case reflection::BaseType::Obj: { + case reflection::Obj: { auto obj = schema.objects()->Get(vec_field.type()->index()); if (obj->is_struct()) { if (!VerifyVectorOfStructs(v, table, vec_field.offset(), *obj, @@ -583,7 +583,7 @@ bool VerifyVector(flatbuffers::Verifier &v, } return true; } - case reflection::BaseType::Union: + case reflection::Union: assert(false); break; default: @@ -612,53 +612,53 @@ bool VerifyObject(flatbuffers::Verifier &v, for (size_t i = 0; i < obj.fields()->size(); i++) { auto field_def = obj.fields()->Get(i); switch (field_def->type()->base_type()) { - case reflection::BaseType::None: + case reflection::None: assert(false); break; - case reflection::BaseType::UType: + case reflection::UType: if (!table->VerifyField(v, field_def->offset())) return false; break; - case reflection::BaseType::Bool: - case reflection::BaseType::Byte: - case reflection::BaseType::UByte: + case reflection::Bool: + case reflection::Byte: + case reflection::UByte: if (!table->VerifyField(v, field_def->offset())) return false; break; - case reflection::BaseType::Short: - case reflection::BaseType::UShort: + case reflection::Short: + case reflection::UShort: if (!table->VerifyField(v, field_def->offset())) return false; break; - case reflection::BaseType::Int: - case reflection::BaseType::UInt: + case reflection::Int: + case reflection::UInt: if (!table->VerifyField(v, field_def->offset())) return false; break; - case reflection::BaseType::Long: - case reflection::BaseType::ULong: + case reflection::Long: + case reflection::ULong: if (!table->VerifyField(v, field_def->offset())) return false; break; - case reflection::BaseType::Float: + case reflection::Float: if (!table->VerifyField(v, field_def->offset())) return false; break; - case reflection::BaseType::Double: + case reflection::Double: if (!table->VerifyField(v, field_def->offset())) return false; break; - case reflection::BaseType::String: + case reflection::String: if (!table->VerifyField(v, field_def->offset()) || !v.Verify(flatbuffers::GetFieldS(*table, *field_def))) { return false; } break; - case reflection::BaseType::Vector: + case reflection::Vector: if (!VerifyVector(v, schema, *table, *field_def)) return false; break; - case reflection::BaseType::Obj: { + case reflection::Obj: { auto child_obj = schema.objects()->Get(field_def->type()->index()); if (child_obj->is_struct()) { if (!VerifyStruct(v, *table, field_def->offset(), *child_obj, @@ -674,8 +674,8 @@ bool VerifyObject(flatbuffers::Verifier &v, } break; } - case reflection::BaseType::Union: { - // get union type from the prev field + case reflection::Union: { + // get union type from the prev field voffset_t utype_offset = field_def->offset() - sizeof(voffset_t); auto utype = table->GetField(utype_offset, 0); if (utype != 0) { diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index eb7a9ffdd..e52992c32 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -76,7 +76,7 @@ template<> struct AnyTraits { }; struct AnyUnion { - Any type = Any_NONE; + Any type; flatbuffers::NativeTable *table = nullptr; AnyUnion() : type(Any_NONE), table(nullptr) {}