44from src .code_dom .common import write_c_line , WriteContext
55
66
7- # Recursively generate code to copy all the members of a struct and any contained by-valuestructs
8- def generate_field_copies (file , indent , known_by_value_structs , struct , prefix ):
7+ # Recursively generate code to copy all the members of a struct and any contained by-value structs
8+ def generate_field_copies (file , indent , known_by_value_structs , struct , prefix , to_cpp ):
99 # Emit code to copy each member
1010 for field in struct .list_directly_contained_children_of_type (code_dom .DOMFieldDeclaration ):
1111 if field .field_type .to_c_string () in known_by_value_structs :
@@ -15,10 +15,23 @@ def generate_field_copies(file, indent, known_by_value_structs, struct, prefix):
1515 indent ,
1616 known_by_value_structs ,
1717 known_by_value_structs [field .field_type .to_c_string ()],
18- prefix + name + "." )
18+ prefix + name + "." ,
19+ to_cpp )
1920 else :
2021 for name in field .names :
21- write_c_line (file , indent , WriteContext (), "dest." + prefix + name + " = src." + prefix + name + ";" )
22+ if field .field_type .is_pointer ():
23+ # Pointer-type fields need casting
24+ if to_cpp :
25+ cast_type = "::" + field .field_type .to_c_string ()
26+ else :
27+ cast_type = "cimgui::" + field .field_type .to_c_string ()
28+
29+ write_c_line (file , indent , WriteContext (),
30+ "dest." + prefix + name + " = reinterpret_cast<" + cast_type + ">(src." +
31+ prefix + name + ");" )
32+ else :
33+ write_c_line (file , indent , WriteContext (), "dest." + prefix + name + " = src." + prefix + name +
34+ ";" )
2235
2336
2437# Generate code to convert by-value types to/from their CPP version
@@ -55,7 +68,7 @@ def generate(dom_root, file, indent=0):
5568 write_c_line (file , indent , write_context , dest_type + " dest;" )
5669
5770 # Emit code to copy each member
58- generate_field_copies (file , indent , known_by_value_structs , struct , "" )
71+ generate_field_copies (file , indent , known_by_value_structs , struct , "" , to_cpp )
5972
6073 write_c_line (file , indent , write_context , "return dest;" )
6174 indent -= 1
0 commit comments