@@ -99,6 +99,25 @@ def prepare_array_de_serialization(site, t):
99
99
dimsizes_expr = expr .mkLit (site , dimsizes_lit , TPtr (TInt (32 , False )))
100
100
return (base , dims , sizeof_base , dimsizes_expr )
101
101
102
+ def mkSubRefLit (site , expr , sub , typ , op ):
103
+ real_etype = safe_realtype_shallow (expr .ctype ())
104
+
105
+ if isinstance (real_etype , TPtr ):
106
+ if op == '.' :
107
+ raise ENOSTRUCT (site , expr )
108
+ basetype = real_etype .base
109
+ real_basetype = safe_realtype (basetype )
110
+ else :
111
+ if op == '->' :
112
+ raise ENOPTR (site , expr )
113
+ real_basetype = safe_realtype (etype )
114
+
115
+ real_basetype = real_basetype .resolve ()
116
+
117
+ return ctree .StructMember (site , expr , sub ,
118
+ conv_const (real_basetype .const , typ ), op )
119
+
120
+
102
121
# This works on the assumption that args do not need to be hard-cast
103
122
# to fit the actual fun signature
104
123
def apply_c_fun (site , fun , args , rettype ):
@@ -354,7 +373,7 @@ def map_dmltype_to_attrtype(site, dmltype):
354
373
return 'f'
355
374
if isinstance (real_type , TStruct ):
356
375
return '[%s]' % "" .join ([map_dmltype_to_attrtype (site , mt )
357
- for mt in real_type .members . values () ])
376
+ for ( _ , mt ) in real_type .members ])
358
377
if isinstance (real_type , TArray ):
359
378
assert real_type .size .constant
360
379
arr_attr_type = map_dmltype_to_attrtype (site , real_type .base )
@@ -375,7 +394,7 @@ def mark_for_serialization(site, dmltype):
375
394
'''
376
395
real_type = safe_realtype (dmltype )
377
396
if isinstance (real_type , TStruct ):
378
- for mt in real_type .members . values () :
397
+ for ( _ , mt ) in real_type .members :
379
398
mark_for_serialization (site , mt )
380
399
elif isinstance (real_type , TArray ):
381
400
# Can only serialize constant-size arrays
@@ -496,9 +515,12 @@ def generate_serialize(real_type):
496
515
in_arg_decl .toc ()
497
516
out_arg_decl .toc ()
498
517
if isinstance (real_type , TStruct ):
499
- sources = ((ctree .mkSubRef (site , in_arg , name , "->" ),
500
- safe_realtype (typ ))
501
- for (name , typ ) in real_type .members .items ())
518
+ sources = (
519
+ (mkSubRefLit (
520
+ site , in_arg , name or TStruct .anon_member_cident (i ),
521
+ typ , "->" ),
522
+ safe_realtype (typ ))
523
+ for (i , (name , typ )) in enumerate (real_type .members ))
502
524
serialize_sources_to_list (site , sources , out_arg )
503
525
elif isinstance (real_type , TVector ):
504
526
raise ICE (site , "TODO: serialize vector" )
@@ -619,9 +641,12 @@ def error_out(exc, msg):
619
641
else ctree .mkCast (site , tmp_out_ref , TPtr (void )))
620
642
cleanup .append (ctree .mkDelete (site , cleanup_ref ))
621
643
tmp_out_decl .toc ()
622
- targets = tuple ((ctree .mkSubRef (site , tmp_out_ref , name , "->" ),
623
- conv_const (real_type .const , safe_realtype (typ )))
624
- for (name , typ ) in real_type .members .items ())
644
+ targets = tuple (
645
+ (mkSubRefLit (
646
+ site , tmp_out_ref ,
647
+ name or TStruct .anon_member_cident (i ), typ , "->" ),
648
+ conv_const (real_type .const , safe_realtype (typ )))
649
+ for (i , (name , typ )) in enumerate (real_type .members ))
625
650
def error_out_at_index (_i , exc , msg ):
626
651
return error_out (exc , msg )
627
652
deserialize_list_to_targets (site , in_arg , targets ,
0 commit comments