cgen: fix for V structs fields (auto str and json_decode)
parent
94f23d96e9
commit
55ef117531
|
@ -3766,15 +3766,15 @@ fn (mut g Gen) gen_str_for_struct(info table.Struct, styp, str_fn_name string) {
|
||||||
field_styp_fn_name := if has_custom_str { '${field_styp}_str' } else { fnames2strfunc[field_styp] }
|
field_styp_fn_name := if has_custom_str { '${field_styp}_str' } else { fnames2strfunc[field_styp] }
|
||||||
if sym.kind == .enum_ {
|
if sym.kind == .enum_ {
|
||||||
g.auto_str_funcs.write('indents, ')
|
g.auto_str_funcs.write('indents, ')
|
||||||
g.auto_str_funcs.write('${field_styp_fn_name}( it->${field.name} ) ')
|
g.auto_str_funcs.write('${field_styp_fn_name}( it->${c_name(field.name)} ) ')
|
||||||
} else if sym.kind == .struct_ {
|
} else if sym.kind == .struct_ {
|
||||||
g.auto_str_funcs.write('indents, ')
|
g.auto_str_funcs.write('indents, ')
|
||||||
g.auto_str_funcs.write('${field_styp_fn_name}( it->${field.name}${second_str_param} ) ')
|
g.auto_str_funcs.write('${field_styp_fn_name}( it->${c_name(field.name)}${second_str_param} ) ')
|
||||||
} else if sym.kind in [.array, .array_fixed, .map] {
|
} else if sym.kind in [.array, .array_fixed, .map] {
|
||||||
g.auto_str_funcs.write('indents, ')
|
g.auto_str_funcs.write('indents, ')
|
||||||
g.auto_str_funcs.write('${field_styp_fn_name}( it->${field.name}) ')
|
g.auto_str_funcs.write('${field_styp_fn_name}( it->${c_name(field.name)}) ')
|
||||||
} else {
|
} else {
|
||||||
g.auto_str_funcs.write('indents, it->${field.name}')
|
g.auto_str_funcs.write('indents, it->${c_name(field.name)}')
|
||||||
if field.typ == table.bool_type {
|
if field.typ == table.bool_type {
|
||||||
g.auto_str_funcs.write(' ? _SLIT("true") : _SLIT("false")')
|
g.auto_str_funcs.write(' ? _SLIT("true") : _SLIT("false")')
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,20 +83,20 @@ cJSON* ${enc_fn_name}($styp val) {
|
||||||
field_type := g.typ(field.typ)
|
field_type := g.typ(field.typ)
|
||||||
enc_name := js_enc_name(field_type)
|
enc_name := js_enc_name(field_type)
|
||||||
if 'raw' in field.attrs {
|
if 'raw' in field.attrs {
|
||||||
dec.writeln(' res . $field.name = tos2(cJSON_PrintUnformatted(' + 'js_get(root, "$name")));')
|
dec.writeln(' res . ${c_name(field.name)} = tos2(cJSON_PrintUnformatted(' + 'js_get(root, "$name")));')
|
||||||
} else {
|
} else {
|
||||||
// Now generate decoders for all field types in this struct
|
// Now generate decoders for all field types in this struct
|
||||||
// need to do it here so that these functions are generated first
|
// need to do it here so that these functions are generated first
|
||||||
g.gen_json_for_type(field.typ)
|
g.gen_json_for_type(field.typ)
|
||||||
dec_name := js_dec_name(field_type)
|
dec_name := js_dec_name(field_type)
|
||||||
if is_js_prim(field_type) {
|
if is_js_prim(field_type) {
|
||||||
dec.writeln(' res . $field.name = $dec_name (js_get(root, "$name"));')
|
dec.writeln(' res . ${c_name(field.name)} = $dec_name (js_get(root, "$name"));')
|
||||||
} else {
|
} else {
|
||||||
// dec.writeln(' $dec_name (js_get(root, "$name"), & (res . $field.name));')
|
// dec.writeln(' $dec_name (js_get(root, "$name"), & (res . $field.name));')
|
||||||
dec.writeln(' res . $field.name = *($field_type*) $dec_name (js_get(root,"$name")).data;')
|
dec.writeln(' res . ${c_name(field.name)} = *($field_type*) $dec_name (js_get(root,"$name")).data;')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enc.writeln('\tcJSON_AddItemToObject(o, "$name", ${enc_name}(val.$field.name));')
|
enc.writeln('\tcJSON_AddItemToObject(o, "$name", ${enc_name}(val.${c_name(field.name)}));')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cJSON_delete
|
// cJSON_delete
|
||||||
|
|
Loading…
Reference in New Issue