cgen: fix for V structs fields (auto str and json_decode)

pull/5086/head
Delyan Angelov 2020-05-28 09:55:33 +03:00
parent 94f23d96e9
commit 55ef117531
2 changed files with 8 additions and 8 deletions

View File

@ -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] }
if sym.kind == .enum_ {
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_ {
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] {
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 {
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 {
g.auto_str_funcs.write(' ? _SLIT("true") : _SLIT("false")')
}

View File

@ -83,20 +83,20 @@ cJSON* ${enc_fn_name}($styp val) {
field_type := g.typ(field.typ)
enc_name := js_enc_name(field_type)
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 {
// Now generate decoders for all field types in this struct
// need to do it here so that these functions are generated first
g.gen_json_for_type(field.typ)
dec_name := js_dec_name(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 {
// 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