From: John L. <jr...@us...> - 2009-09-25 18:48:14
|
Update of /cvsroot/wxlua/wxLua/bindings In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv3461/wxLua/bindings Modified Files: genwxbind.lua Log Message: Fix multiple inheritance by adding the offset to the vtable for base classes that are second or higher. Index: genwxbind.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/bindings/genwxbind.lua,v retrieving revision 1.181 retrieving revision 1.182 diff -C2 -d -r1.181 -r1.182 *** genwxbind.lua 24 May 2009 03:19:59 -0000 1.181 --- genwxbind.lua 25 Sep 2009 18:47:57 -0000 1.182 *************** *** 18,25 **** -- --------------------------------------------------------------------------- ! WXLUA_BINDING_VERSION = 27 -- Used to verify that the bindings are updated -- This must match modules/wxlua/include/wxldefs.h -- otherwise a compile time error will be generated. bindingKeywordTable = {} -- Binding keywords used by the generator %XXX skipBindingKeywordTable = {} -- Binding keywords to skip and not handle (for testing?) --- 18,28 ---- -- --------------------------------------------------------------------------- ! WXLUA_BINDING_VERSION = 28 -- Used to verify that the bindings are updated -- This must match modules/wxlua/include/wxldefs.h -- otherwise a compile time error will be generated. + -- Test the interface files by casting the object to the baseclasses, use only temporarily for debugging + testInheritanceByCasting = false + bindingKeywordTable = {} -- Binding keywords used by the generator %XXX skipBindingKeywordTable = {} -- Binding keywords to skip and not handle (for testing?) *************** *** 3787,3790 **** --- 3790,3801 ---- table.insert(codeList, " "..memberTypeWithAttrib.." returns = new "..parseObject.Name.."("..argList..");\n") + -- Test the interface files by casting the object to the baseclasses + if testInheritanceByCasting then + local BaseClasses = dataTypeTable[parseObject.Name].BaseClasses + for i = 1, #(BaseClasses or {}) do + table.insert(codeList, " "..BaseClasses[i].."* returns_"..BaseClasses[i].." = dynamic_cast<"..BaseClasses[i].."*>(returns);\n") + end + end + if parseObject["%gc_this"] or (parseObject["%delete"] and (not parseObject["%ungc_this"])) then CommentBindingTable(codeList, " // add to tracked memory list\n") *************** *** 3833,3836 **** --- 3844,3855 ---- end + -- Test the interface files by casting the object to the baseclasses + if testInheritanceByCasting then + local BaseClasses = dataTypeTable[parseObject.Name].BaseClasses + for i = 1, #(BaseClasses or {}) do + table.insert(codeList, " "..BaseClasses[i].."* self_"..BaseClasses[i].." = dynamic_cast<"..BaseClasses[i].."*>(self);\n") + end + end + requiredParamCount = requiredParamCount + 1 paramCount = paramCount + 1 *************** *** 4025,4029 **** -- Figure out if we really need to have member enums for the class ! local enumArrayName = "g_wxluanumberArray_None" local enumArrayCountName = 0 local ExternEnumDeclaration = "" --- 4044,4048 ---- -- Figure out if we really need to have member enums for the class ! local enumArrayName = "NULL" local enumArrayCountName = 0 local ExternEnumDeclaration = "" *************** *** 4069,4077 **** --- 4088,4143 ---- local baseclassNames = "NULL" local baseclassBinds = "NULL" + local baseclassVtableOffsets = nil + local baseclassTypes = nil + local baseclassVtableOffsets_name = "NULL" + local baseclassTypes_name = "NULL" + if dataTypeTable[parseObject.Name].BaseClasses then baseclassNames = "wxluabaseclassnames_"..MakeVar(parseObject.Name) baseclassBinds = "wxluabaseclassbinds_"..MakeVar(parseObject.Name) + + + local a = {parseObject.Name} + local base_diff_table = {} + local base_type_table = {} + local has_multiple_base_classes = false + + local function iter_baseclasses(name, level) + if dataTypeTable[name].BaseClasses then + for i = 1, #dataTypeTable[name].BaseClasses do + if #dataTypeTable[name].BaseClasses > 1 then + has_multiple_base_classes = true + end + -- only increment level since the rest of this branch is from a second or higher base class + if i > 1 then + level = 2 + end + + a[#a+1] = dataTypeTable[name].BaseClasses[i] + + -- only store the ptr_diffs to higher base classes, the 1st level is always 0 + if level > 1 then + local ptr_diff = "((long int)("..dataTypeTable[name].BaseClasses[i].."*)("..parseObject.Name.."*)&wxluatype_TNONE) - ((long int)("..parseObject.Name.."*)&wxluatype_TNONE)" + base_diff_table[#base_diff_table+1] = ptr_diff + base_type_table[#base_type_table+1] = "&wxluatype_"..dataTypeTable[name].BaseClasses[i] + end + + iter_baseclasses(dataTypeTable[name].BaseClasses[i], level) + end + end + end + + iter_baseclasses(parseObject.Name, 1) + if has_multiple_base_classes then + baseclassVtableOffsets = "{ "..table.concat(base_diff_table, ", ").." };" + baseclassTypes = "{ "..table.concat(base_type_table, ", ")..", NULL };" + baseclassVtableOffsets_name = "wxluabaseclass_vtable_offsets_"..MakeClassVar(parseObject.Name) + baseclassTypes_name = "wxluabaseclass_wxluatypes_"..MakeClassVar(parseObject.Name) + print(table.concat(a, " ")) + end + end + local classinfo = "NULL" if not parseObject["%noclassinfo"] then *************** *** 4141,4149 **** ..baseclassNames..", " ..baseclassBinds..", " ..enumArrayName..", " ..enumArrayCountName..", " .."}, \n", ! BaseClasses = dataTypeTable[parseObject.Name].BaseClasses, ! Condition = classcondition } --- 4207,4219 ---- ..baseclassNames..", " ..baseclassBinds..", " + ..baseclassTypes_name..", " + ..baseclassVtableOffsets_name..", " ..enumArrayName..", " ..enumArrayCountName..", " .."}, \n", ! BaseClasses = dataTypeTable[parseObject.Name].BaseClasses, ! BaseClassTypes = baseclassTypes, ! BaseClassVtableOffsets = baseclassVtableOffsets, ! Condition = classcondition } *************** *** 4475,4478 **** --- 4545,4553 ---- table.insert(fileData, s.." NULL };\n") table.insert(fileData, "static wxLuaBindClass* wxluabaseclassbinds_"..sortedBindings[n][i].LuaName.."[] = { "..string.sub(string.rep("NULL, ", bc_n), 1, -3).." };\n") + + if sortedBindings[n][i].BaseClassVtableOffsets then + table.insert(fileData, "static wxLuaArgType wxluabaseclass_wxluatypes_"..sortedBindings[n][i].LuaName.."[] = "..sortedBindings[n][i].BaseClassTypes.."\n") + table.insert(fileData, "static int wxluabaseclass_vtable_offsets_"..sortedBindings[n][i].LuaName.."[] = "..sortedBindings[n][i].BaseClassVtableOffsets.."\n") + end end end |