@@ -381,8 +381,8 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
381
381
if fv_sym.kind == .struct && ! is_option && field_op != '->' {
382
382
dec.writeln ('\t if (root->type == cJSON_NULL) { ' )
383
383
dec.writeln ('\t\t struct ${first_variant_name} empty = {0};' )
384
- dec.writeln ('res = ${variant_typ} _to_sumtype_${ret_styp} (&empty); } \n else ' )
385
- // dec.writeln('res = ${variant_typ}_to_sumtype_${sym.cname}(&empty); } \n else ')
384
+ dec.writeln ('res = ${variant_typ} _to_sumtype_${ret_styp} (&empty, false ); } \n else ' )
385
+ // dec.writeln('res = ${variant_typ}_to_sumtype_${sym.cname}(&empty, false ); } \n else ')
386
386
}
387
387
//
388
388
dec.writeln ('if (cJSON_IsObject(root) || (cJSON_IsArray(root) && cJSON_IsObject(root->child))) {' )
@@ -409,7 +409,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
409
409
410
410
// Helpers for decoding
411
411
g.get_sumtype_casting_fn (variant, typ)
412
- g.definitions.writeln ('static inline ${sym.cname} ${variant_typ} _to_sumtype_${sym.cname} (${variant_typ} * x);' )
412
+ g.definitions.writeln ('static inline ${sym.cname} ${variant_typ} _to_sumtype_${sym.cname} (${variant_typ} * x, bool is_mut );' )
413
413
414
414
// ENCODING
415
415
enc.writeln ('\t if (${var_data}${field_op} _typ == ${int(variant.idx())} ) {' )
@@ -485,9 +485,9 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
485
485
dec.writeln ('\t\t ${variant_typ} value = *(${variant_typ} *)(${tmp} .data);' )
486
486
}
487
487
if is_option {
488
- dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${variant_typ} _to_sumtype_${sym.cname} (&value) }, (${option_name} *)&res, sizeof(${sym.cname} ));' )
488
+ dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${variant_typ} _to_sumtype_${sym.cname} (&value, false ) }, (${option_name} *)&res, sizeof(${sym.cname} ));' )
489
489
} else {
490
- dec.writeln ('\t\t res = ${variant_typ} _to_sumtype_${ret_styp} (&value);' )
490
+ dec.writeln ('\t\t res = ${variant_typ} _to_sumtype_${ret_styp} (&value, false );' )
491
491
}
492
492
dec.writeln ('\t }' )
493
493
} $else {
@@ -498,10 +498,10 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
498
498
if utyp.has_flag (.option) {
499
499
dec.writeln ('\t\t\t\t ${prefix} res.state = 0;' )
500
500
tmp_time_var := g.new_tmp_var ()
501
- dec.writeln ('\t\t\t\t ${g.base_type(utyp)} ${tmp_time_var} = ${variant_typ} _to_sumtype_${sym.cname} (&${tmp} );' )
501
+ dec.writeln ('\t\t\t\t ${g.base_type(utyp)} ${tmp_time_var} = ${variant_typ} _to_sumtype_${sym.cname} (&${tmp} , false );' )
502
502
dec.writeln ('\t\t\t\t vmemcpy(&${prefix} res.data, ${tmp_time_var} ._time__Time, sizeof(${variant_typ} ));' )
503
503
} else {
504
- dec.writeln ('\t\t\t\t ${prefix} res = ${variant_typ} _to_sumtype_${sym.cname} (&${tmp} );' )
504
+ dec.writeln ('\t\t\t\t ${prefix} res = ${variant_typ} _to_sumtype_${sym.cname} (&${tmp} , false );' )
505
505
}
506
506
dec.writeln ('\t\t\t }' )
507
507
} else if ! is_js_prim (variant_typ) && variant_sym.kind != .enum {
@@ -512,9 +512,9 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
512
512
dec.writeln ('\t\t\t\t\t return (${result_name} _${ret_styp} ){ .is_error = true, .err = ${tmp} .err, .data = {0} };' )
513
513
dec.writeln ('\t\t\t\t }' )
514
514
if is_option {
515
- dec.writeln ('\t\t\t\t _option_ok(&(${sym.cname} []){ ${variant_typ} _to_sumtype_${sym.cname} ((${variant_typ} *)${tmp} .data) }, (${option_name} *)&res, sizeof(${sym.cname} ));' )
515
+ dec.writeln ('\t\t\t\t _option_ok(&(${sym.cname} []){ ${variant_typ} _to_sumtype_${sym.cname} ((${variant_typ} *)${tmp} .data, false ) }, (${option_name} *)&res, sizeof(${sym.cname} ));' )
516
516
} else {
517
- dec.writeln ('\t\t\t\t ${prefix} res = ${variant_typ} _to_sumtype_${sym.cname} ((${variant_typ} *)${tmp} .data);' )
517
+ dec.writeln ('\t\t\t\t ${prefix} res = ${variant_typ} _to_sumtype_${sym.cname} ((${variant_typ} *)${tmp} .data, false );' )
518
518
}
519
519
dec.writeln ('\t\t\t }' )
520
520
}
@@ -536,7 +536,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
536
536
var_t := 'bool'
537
537
dec.writeln ('\t\t if (cJSON_IsBool(root)) {' )
538
538
dec.writeln ('\t\t\t ${var_t} value = ${js_dec_name(var_t)} (root);' )
539
- dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} (&value);' )
539
+ dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} (&value, false );' )
540
540
dec.writeln ('\t\t }' )
541
541
}
542
542
@@ -552,9 +552,9 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
552
552
dec.writeln ('\t\t if (cJSON_IsNumber(root)) {' )
553
553
dec.writeln ('\t\t\t ${var_t} value = ${js_dec_name('u64')} (root);' )
554
554
if utyp.has_flag (.option) {
555
- dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${var_t} _to_sumtype_${sym.cname} (&value) }, (${option_name} *)&${prefix} res, sizeof(${sym.cname} ));' )
555
+ dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${var_t} _to_sumtype_${sym.cname} (&value, false ) }, (${option_name} *)&${prefix} res, sizeof(${sym.cname} ));' )
556
556
} else {
557
- dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} (&value);' )
557
+ dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} (&value, false );' )
558
558
}
559
559
dec.writeln ('\t\t }' )
560
560
}
@@ -568,9 +568,9 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
568
568
dec.writeln ('\t\t if (cJSON_IsString(root)) {' )
569
569
dec.writeln ('\t\t\t ${var_t} value = ${js_dec_name(var_t)} (root);' )
570
570
if utyp.has_flag (.option) {
571
- dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${var_t} _to_sumtype_${sym.cname} (&value) }, (${option_name} *)&${prefix} res, sizeof(${sym.cname} ));' )
571
+ dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${var_t} _to_sumtype_${sym.cname} (&value, false ) }, (${option_name} *)&${prefix} res, sizeof(${sym.cname} ));' )
572
572
} else {
573
- dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} (&value);' )
573
+ dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} (&value, false );' )
574
574
}
575
575
dec.writeln ('\t\t }' )
576
576
}
@@ -592,9 +592,9 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
592
592
dec.writeln ('\t\t\t\t return (${result_name} _${ret_styp} ){ .is_error = true, .err = ${tmp} .err, .data = {0} };' )
593
593
dec.writeln ('\t\t\t }' )
594
594
if utyp.has_flag (.option) {
595
- dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${var_t} _to_sumtype_${sym.cname} ((${var_t} *)${tmp} .data) }, (${option_name} *)&${prefix} res, sizeof(${sym.cname} ));' )
595
+ dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${var_t} _to_sumtype_${sym.cname} ((${var_t} *)${tmp} .data, false ) }, (${option_name} *)&${prefix} res, sizeof(${sym.cname} ));' )
596
596
} else {
597
- dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} ((${var_t} *)${tmp} .data);' )
597
+ dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} ((${var_t} *)${tmp} .data, false );' )
598
598
}
599
599
dec.writeln ('\t\t }' )
600
600
}
@@ -611,9 +611,9 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
611
611
dec.writeln ('\t\t if (cJSON_IsNumber(root)) {' )
612
612
dec.writeln ('\t\t\t ${var_t} value = ${js_dec_name(var_t)} (root);' )
613
613
if utyp.has_flag (.option) {
614
- dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${var_t} _to_sumtype_${sym.cname} (&value) }, (${option_name} *)&${prefix} res, sizeof(${sym.cname} ));' )
614
+ dec.writeln ('\t\t\t _option_ok(&(${sym.cname} []){ ${var_t} _to_sumtype_${sym.cname} (&value, false ) }, (${option_name} *)&${prefix} res, sizeof(${sym.cname} ));' )
615
615
} else {
616
- dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} (&value);' )
616
+ dec.writeln ('\t\t\t ${prefix} res = ${var_t} _to_sumtype_${sym.cname} (&value, false );' )
617
617
}
618
618
dec.writeln ('\t\t }' )
619
619
}
0 commit comments