applied struct parameter fix to Go and Python generated classes
authorMaor Itzkovitch <maor.tt@gmail.com>
Mon, 13 Jul 2015 19:53:59 +0000 (22:53 +0300)
committerMaor Itzkovitch <maor.tt@gmail.com>
Mon, 13 Jul 2015 19:53:59 +0000 (22:53 +0300)
src/idl_gen_go.cpp
src/idl_gen_python.cpp
tests/MyGame/Example/Vec3.go
tests/MyGame/Example/Vec3.py
tests/generate_code.sh

index 6f256bd..a2e185b 100644 (file)
@@ -332,7 +332,7 @@ static void StructBuilderArgs(const StructDef &struct_def,
       // don't clash, and to make it obvious these arguments are constructing
       // a nested struct, prefix the name with the struct name.
       StructBuilderArgs(*field.value.type.struct_def,
-                        (field.value.type.struct_def->name + "_").c_str(),
+                        (nameprefix + (field.name + "_")).c_str(),
                         code_ptr);
     } else {
       std::string &code = *code_ptr;
@@ -365,7 +365,7 @@ static void StructBuilderBody(const StructDef &struct_def,
       code += "    builder.Pad(" + NumToString(field.padding) + ")\n";
     if (IsStruct(field.value.type)) {
       StructBuilderBody(*field.value.type.struct_def,
-                        (field.value.type.struct_def->name + "_").c_str(),
+                        (nameprefix + (field.name + "_")).c_str(),
                         code_ptr);
     } else {
       code += "    builder.Prepend" + GenMethod(field) + "(";
index c03ac93..96f9c42 100644 (file)
@@ -307,9 +307,9 @@ static void StructBuilderArgs(const StructDef &struct_def,
     if (IsStruct(field.value.type)) {
       // Generate arguments for a struct inside a struct. To ensure names
       // don't clash, and to make it obvious these arguments are constructing
-      // a nested struct, prefix the name with the struct name.
+      // a nested struct, prefix the name with the field name.
       StructBuilderArgs(*field.value.type.struct_def,
-                        (field.value.type.struct_def->name + "_").c_str(),
+                        (nameprefix + (field.name + "_")).c_str(),
                         code_ptr);
     } else {
       std::string &code = *code_ptr;
@@ -341,7 +341,7 @@ static void StructBuilderBody(const StructDef &struct_def,
       code += "    builder.Pad(" + NumToString(field.padding) + ")\n";
     if (IsStruct(field.value.type)) {
       StructBuilderBody(*field.value.type.struct_def,
-                        (field.value.type.struct_def->name + "_").c_str(),
+                        (nameprefix + (field.name + "_")).c_str(),
                         code_ptr);
     } else {
       code += "    builder.Prepend" + GenMethod(field) + "(";
index d2bab2c..def0b4d 100644 (file)
@@ -27,13 +27,13 @@ func (rcv *Vec3) Test3(obj *Test) *Test {
        return obj
 }
 
-func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, test1 float64, test2 int8, Test_a int16, Test_b int8) flatbuffers.UOffsetT {
+func CreateVec3(builder *flatbuffers.Builder, x float32, y float32, z float32, test1 float64, test2 int8, test3_a int16, test3_b int8) flatbuffers.UOffsetT {
     builder.Prep(16, 32)
     builder.Pad(2)
     builder.Prep(2, 4)
     builder.Pad(1)
-    builder.PrependInt8(Test_b)
-    builder.PrependInt16(Test_a)
+    builder.PrependInt8(test3_b)
+    builder.PrependInt16(test3_a)
     builder.Pad(1)
     builder.PrependInt8(test2)
     builder.PrependFloat64(test1)
index 3010d5b..c4ddfe2 100644 (file)
@@ -27,13 +27,13 @@ class Vec3(object):
         return obj
 
 
-def CreateVec3(builder, x, y, z, test1, test2, Test_a, Test_b):
+def CreateVec3(builder, x, y, z, test1, test2, test3_a, test3_b):
     builder.Prep(16, 32)
     builder.Pad(2)
     builder.Prep(2, 4)
     builder.Pad(1)
-    builder.PrependInt8(Test_b)
-    builder.PrependInt16(Test_a)
+    builder.PrependInt8(test3_b)
+    builder.PrependInt16(test3_a)
     builder.Pad(1)
     builder.PrependInt8(test2)
     builder.PrependFloat64(test1)
index 5577d18..5b76819 100644 (file)
@@ -1,2 +1,2 @@
-../flatc -c -j -n -g -b --gen-mutable --no-includes monster_test.fbs monsterdata_test.json
+../flatc -c -j -n -g -b -p --gen-mutable --no-includes monster_test.fbs monsterdata_test.json
 ../flatc -b --schema monster_test.fbs