Skip to content

Commit fb66ec7

Browse files
authored
cgen: fix codegen for aliases of fixed arrays of structs (fix #13037) (#13049)
1 parent fca699a commit fb66ec7

File tree

6 files changed

+79
-36
lines changed

6 files changed

+79
-36
lines changed

vlib/v/gen/c/auto_eq_methods.v

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn (mut g Gen) gen_sumtype_equality_fn(left_type ast.Type) string {
5959
g.generated_eq_fns << left_type
6060

6161
info := left.sym.sumtype_info()
62-
g.type_definitions.writeln('static bool ${ptr_styp}_sumtype_eq($ptr_styp a, $ptr_styp b); // auto')
62+
g.definitions.writeln('static bool ${ptr_styp}_sumtype_eq($ptr_styp a, $ptr_styp b); // auto')
6363

6464
mut fn_builder := strings.new_builder(512)
6565
fn_builder.writeln('static bool ${ptr_styp}_sumtype_eq($ptr_styp a, $ptr_styp b) {')
@@ -110,7 +110,7 @@ fn (mut g Gen) gen_struct_equality_fn(left_type ast.Type) string {
110110
}
111111
g.generated_eq_fns << left_type
112112
info := left.sym.struct_info()
113-
g.type_definitions.writeln('static bool ${fn_name}_struct_eq($ptr_styp a, $ptr_styp b); // auto')
113+
g.definitions.writeln('static bool ${fn_name}_struct_eq($ptr_styp a, $ptr_styp b); // auto')
114114

115115
mut fn_builder := strings.new_builder(512)
116116
defer {
@@ -178,7 +178,7 @@ fn (mut g Gen) gen_alias_equality_fn(left_type ast.Type) string {
178178
}
179179
g.generated_eq_fns << left_type
180180
info := left.sym.info as ast.Alias
181-
g.type_definitions.writeln('static bool ${ptr_styp}_alias_eq($ptr_styp a, $ptr_styp b); // auto')
181+
g.definitions.writeln('static bool ${ptr_styp}_alias_eq($ptr_styp a, $ptr_styp b); // auto')
182182

183183
mut fn_builder := strings.new_builder(512)
184184
fn_builder.writeln('static bool ${ptr_styp}_alias_eq($ptr_styp a, $ptr_styp b) {')
@@ -222,7 +222,7 @@ fn (mut g Gen) gen_array_equality_fn(left_type ast.Type) string {
222222
g.generated_eq_fns << left_type
223223
elem := g.unwrap(left.sym.array_info().elem_type)
224224
ptr_elem_styp := g.typ(elem.typ)
225-
g.type_definitions.writeln('static bool ${ptr_styp}_arr_eq($ptr_styp a, $ptr_styp b); // auto')
225+
g.definitions.writeln('static bool ${ptr_styp}_arr_eq($ptr_styp a, $ptr_styp b); // auto')
226226

227227
mut fn_builder := strings.new_builder(512)
228228
fn_builder.writeln('static bool ${ptr_styp}_arr_eq($ptr_styp a, $ptr_styp b) {')
@@ -278,7 +278,7 @@ fn (mut g Gen) gen_fixed_array_equality_fn(left_type ast.Type) string {
278278
elem_info := left.sym.array_fixed_info()
279279
elem := g.unwrap(elem_info.elem_type)
280280
size := elem_info.size
281-
g.type_definitions.writeln('static bool ${ptr_styp}_arr_eq($ptr_styp a, $ptr_styp b); // auto')
281+
g.definitions.writeln('static bool ${ptr_styp}_arr_eq($ptr_styp a, $ptr_styp b); // auto')
282282

283283
mut fn_builder := strings.new_builder(512)
284284
fn_builder.writeln('static bool ${ptr_styp}_arr_eq($ptr_styp a, $ptr_styp b) {')
@@ -330,7 +330,7 @@ fn (mut g Gen) gen_map_equality_fn(left_type ast.Type) string {
330330
g.generated_eq_fns << left_type
331331
value := g.unwrap(left.sym.map_info().value_type)
332332
ptr_value_styp := g.typ(value.typ)
333-
g.type_definitions.writeln('static bool ${ptr_styp}_map_eq($ptr_styp a, $ptr_styp b); // auto')
333+
g.definitions.writeln('static bool ${ptr_styp}_map_eq($ptr_styp a, $ptr_styp b); // auto')
334334

335335
mut fn_builder := strings.new_builder(512)
336336
fn_builder.writeln('static bool ${ptr_styp}_map_eq($ptr_styp a, $ptr_styp b) {')
@@ -415,7 +415,7 @@ fn (mut g Gen) gen_interface_equality_fn(left_type ast.Type) string {
415415
}
416416
g.generated_eq_fns << left_type
417417
info := left.sym.info
418-
g.type_definitions.writeln('static bool ${ptr_styp}_interface_eq($ptr_styp a, $ptr_styp b); // auto')
418+
g.definitions.writeln('static bool ${ptr_styp}_interface_eq($ptr_styp a, $ptr_styp b); // auto')
419419

420420
mut fn_builder := strings.new_builder(512)
421421
defer {

vlib/v/gen/c/auto_free_methods.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn (mut g Gen) gen_free_method_for_type(typ ast.Type) string {
3737
}
3838

3939
fn (mut g Gen) gen_free_for_struct(info ast.Struct, styp string, fn_name string) {
40-
g.type_definitions.writeln('void ${fn_name}($styp* it); // auto')
40+
g.definitions.writeln('void ${fn_name}($styp* it); // auto')
4141
mut fn_builder := strings.new_builder(128)
4242
defer {
4343
g.auto_fn_definitions << fn_builder.str()
@@ -61,7 +61,7 @@ fn (mut g Gen) gen_free_for_struct(info ast.Struct, styp string, fn_name string)
6161
}
6262

6363
fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
64-
g.type_definitions.writeln('void ${fn_name}($styp* it); // auto')
64+
g.definitions.writeln('void ${fn_name}($styp* it); // auto')
6565
mut fn_builder := strings.new_builder(128)
6666
defer {
6767
g.auto_fn_definitions << fn_builder.str()
@@ -86,7 +86,7 @@ fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
8686
}
8787

8888
fn (mut g Gen) gen_free_for_map(info ast.Map, styp string, fn_name string) {
89-
g.type_definitions.writeln('void ${fn_name}($styp* it); // auto')
89+
g.definitions.writeln('void ${fn_name}($styp* it); // auto')
9090
mut fn_builder := strings.new_builder(128)
9191
defer {
9292
g.auto_fn_definitions << fn_builder.str()

vlib/v/gen/c/auto_str_methods.v

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn (mut g Gen) gen_str_default(sym ast.TypeSymbol, styp string, str_fn_name stri
107107
} else {
108108
verror('could not generate string method for type `$styp`')
109109
}
110-
g.type_definitions.writeln('string ${str_fn_name}($styp it); // auto')
110+
g.definitions.writeln('string ${str_fn_name}($styp it); // auto')
111111
g.auto_str_funcs.writeln('string ${str_fn_name}($styp it) {')
112112
if convertor == 'bool' {
113113
g.auto_str_funcs.writeln('\tstring tmp1 = string__plus(_SLIT("${styp}("), ($convertor)it ? _SLIT("true") : _SLIT("false"));')
@@ -234,9 +234,9 @@ fn (mut g Gen) gen_str_for_option(typ ast.Type, styp string, str_fn_name string)
234234
sym_has_str_method, _, _ := sym.str_method_info()
235235
parent_str_fn_name := g.get_str_fn(parent_type)
236236

237-
g.type_definitions.writeln('string ${str_fn_name}($styp it); // auto')
237+
g.definitions.writeln('string ${str_fn_name}($styp it); // auto')
238238
g.auto_str_funcs.writeln('string ${str_fn_name}($styp it) { return indent_${str_fn_name}(it, 0); }')
239-
g.type_definitions.writeln('string indent_${str_fn_name}($styp it, int indent_count); // auto')
239+
g.definitions.writeln('string indent_${str_fn_name}($styp it, int indent_count); // auto')
240240
g.auto_str_funcs.writeln('string indent_${str_fn_name}($styp it, int indent_count) {')
241241
g.auto_str_funcs.writeln('\tstring res;')
242242
g.auto_str_funcs.writeln('\tif (it.state == 0) {')
@@ -264,9 +264,9 @@ fn (mut g Gen) gen_str_for_alias(info ast.Alias, styp string, str_fn_name string
264264
eprintln('> gen_str_for_alias: $parent_str_fn_name | $styp | $str_fn_name')
265265
}
266266
mut clean_type_v_type_name := util.strip_main_name(styp.replace('__', '.'))
267-
g.type_definitions.writeln('static string ${str_fn_name}($styp it); // auto')
267+
g.definitions.writeln('static string ${str_fn_name}($styp it); // auto')
268268
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp it) { return indent_${str_fn_name}(it, 0); }')
269-
g.type_definitions.writeln('static string indent_${str_fn_name}($styp it, int indent_count); // auto')
269+
g.definitions.writeln('static string indent_${str_fn_name}($styp it, int indent_count); // auto')
270270
g.auto_str_funcs.writeln('static string indent_${str_fn_name}($styp it, int indent_count) {')
271271
g.auto_str_funcs.writeln('\tstring indents = string_repeat(_SLIT(" "), indent_count);')
272272
g.auto_str_funcs.writeln('\tstring tmp_ds = ${parent_str_fn_name}(it);')
@@ -285,7 +285,7 @@ fn (mut g Gen) gen_str_for_multi_return(info ast.MultiReturn, styp string, str_f
285285
$if trace_autostr ? {
286286
eprintln('> gen_str_for_multi_return: $info.types | $styp | $str_fn_name')
287287
}
288-
g.type_definitions.writeln('static string ${str_fn_name}($styp a); // auto')
288+
g.definitions.writeln('static string ${str_fn_name}($styp a); // auto')
289289
mut fn_builder := strings.new_builder(512)
290290
fn_builder.writeln('static string ${str_fn_name}($styp a) {')
291291
fn_builder.writeln('\tstrings__Builder sb = strings__new_builder($info.types.len * 10);')
@@ -333,7 +333,7 @@ fn (mut g Gen) gen_str_for_enum(info ast.Enum, styp string, str_fn_name string)
333333
eprintln('> gen_str_for_enum: $info | $styp | $str_fn_name')
334334
}
335335
s := util.no_dots(styp)
336-
g.type_definitions.writeln('static string ${str_fn_name}($styp it); // auto')
336+
g.definitions.writeln('static string ${str_fn_name}($styp it); // auto')
337337
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp it) { /* gen_str_for_enum */')
338338
// Enums tagged with `[flag]` are special in that they can be a combination of enum values
339339
if info.is_flag {
@@ -368,9 +368,9 @@ fn (mut g Gen) gen_str_for_interface(info ast.Interface, styp string, str_fn_nam
368368
eprintln('> gen_str_for_interface: $info.types | $styp | $str_fn_name')
369369
}
370370
// _str() functions should have a single argument, the indenting ones take 2:
371-
g.type_definitions.writeln('static string ${str_fn_name}($styp x); // auto')
371+
g.definitions.writeln('static string ${str_fn_name}($styp x); // auto')
372372
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp x) { return indent_${str_fn_name}(x, 0); }')
373-
g.type_definitions.writeln('static string indent_${str_fn_name}($styp x, int indent_count); // auto')
373+
g.definitions.writeln('static string indent_${str_fn_name}($styp x, int indent_count); // auto')
374374
mut fn_builder := strings.new_builder(512)
375375
mut clean_interface_v_type_name := styp.replace('__', '.')
376376
if styp.ends_with('*') {
@@ -429,9 +429,9 @@ fn (mut g Gen) gen_str_for_union_sum_type(info ast.SumType, styp string, str_fn_
429429
eprintln('> gen_str_for_union_sum_type: $info.variants | $styp | $str_fn_name')
430430
}
431431
// _str() functions should have a single argument, the indenting ones take 2:
432-
g.type_definitions.writeln('static string ${str_fn_name}($styp x); // auto')
432+
g.definitions.writeln('static string ${str_fn_name}($styp x); // auto')
433433
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp x) { return indent_${str_fn_name}(x, 0); }')
434-
g.type_definitions.writeln('static string indent_${str_fn_name}($styp x, int indent_count); // auto')
434+
g.definitions.writeln('static string indent_${str_fn_name}($styp x, int indent_count); // auto')
435435
mut fn_builder := strings.new_builder(512)
436436
fn_builder.writeln('static string indent_${str_fn_name}($styp x, int indent_count) {')
437437
mut clean_sum_type_v_type_name := ''
@@ -521,7 +521,7 @@ fn (mut g Gen) gen_str_for_fn_type(info ast.FnType, styp string, str_fn_name str
521521
$if trace_autostr ? {
522522
eprintln('> gen_str_for_fn_type: $info.func.name | $styp | $str_fn_name')
523523
}
524-
g.type_definitions.writeln('static string ${str_fn_name}(); // auto')
524+
g.definitions.writeln('static string ${str_fn_name}(); // auto')
525525
g.auto_str_funcs.writeln('static string ${str_fn_name}() { return _SLIT("${g.fn_decl_str(info)}");}')
526526
}
527527

@@ -530,7 +530,7 @@ fn (mut g Gen) gen_str_for_chan(info ast.Chan, styp string, str_fn_name string)
530530
eprintln('> gen_str_for_chan: $info.elem_type.debug() | $styp | $str_fn_name')
531531
}
532532
elem_type_name := util.strip_main_name(g.table.get_type_name(g.unwrap_generic(info.elem_type)))
533-
g.type_definitions.writeln('static string ${str_fn_name}($styp x); // auto')
533+
g.definitions.writeln('static string ${str_fn_name}($styp x); // auto')
534534
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp x) { return sync__Channel_auto_str(x, _SLIT("$elem_type_name")); }')
535535
}
536536

@@ -539,7 +539,7 @@ fn (mut g Gen) gen_str_for_thread(info ast.Thread, styp string, str_fn_name stri
539539
eprintln('> gen_str_for_thread: $info.return_type.debug() | $styp | $str_fn_name')
540540
}
541541
ret_type_name := util.strip_main_name(g.table.get_type_name(info.return_type))
542-
g.type_definitions.writeln('static string ${str_fn_name}($styp _); // auto}')
542+
g.definitions.writeln('static string ${str_fn_name}($styp _); // auto}')
543543
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp _) { return _SLIT("thread($ret_type_name)");}')
544544
}
545545

@@ -578,9 +578,9 @@ fn (mut g Gen) gen_str_for_array(info ast.Array, styp string, str_fn_name string
578578
elem_str_fn_name = elem_str_fn_name + '_escaped'
579579
}
580580

581-
g.type_definitions.writeln('static string ${str_fn_name}($styp a); // auto')
581+
g.definitions.writeln('static string ${str_fn_name}($styp a); // auto')
582582
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp a) { return indent_${str_fn_name}(a, 0);}')
583-
g.type_definitions.writeln('static string indent_${str_fn_name}($styp a, int indent_count); // auto')
583+
g.definitions.writeln('static string indent_${str_fn_name}($styp a, int indent_count); // auto')
584584
g.auto_str_funcs.writeln('static string indent_${str_fn_name}($styp a, int indent_count) {')
585585
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(a.len * 10);')
586586
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _SLIT("["));')
@@ -650,9 +650,9 @@ fn (mut g Gen) gen_str_for_array_fixed(info ast.ArrayFixed, styp string, str_fn_
650650
sym_has_str_method, str_method_expects_ptr, _ := sym.str_method_info()
651651
elem_str_fn_name := g.get_str_fn(typ)
652652

653-
g.type_definitions.writeln('static string ${str_fn_name}($styp a); // auto')
653+
g.definitions.writeln('static string ${str_fn_name}($styp a); // auto')
654654
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp a) { return indent_${str_fn_name}(a, 0);}')
655-
g.type_definitions.writeln('static string indent_${str_fn_name}($styp a, int indent_count); // auto')
655+
g.definitions.writeln('static string indent_${str_fn_name}($styp a, int indent_count); // auto')
656656
g.auto_str_funcs.writeln('static string indent_${str_fn_name}($styp a, int indent_count) {')
657657
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder($info.size * 10);')
658658
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _SLIT("["));')
@@ -727,9 +727,9 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
727727
g.get_str_fn(val_typ)
728728
}
729729

730-
g.type_definitions.writeln('static string ${str_fn_name}($styp m); // auto')
730+
g.definitions.writeln('static string ${str_fn_name}($styp m); // auto')
731731
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp m) { return indent_${str_fn_name}(m, 0);}')
732-
g.type_definitions.writeln('static string indent_${str_fn_name}($styp m, int indent_count); // auto')
732+
g.definitions.writeln('static string indent_${str_fn_name}($styp m, int indent_count); // auto')
733733
g.auto_str_funcs.writeln('static string indent_${str_fn_name}($styp m, int indent_count) { /* gen_str_for_map */')
734734
g.auto_str_funcs.writeln('\tstrings__Builder sb = strings__new_builder(m.key_values.len*10);')
735735
g.auto_str_funcs.writeln('\tstrings__Builder_write_string(&sb, _SLIT("{"));')
@@ -827,9 +827,9 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
827827
eprintln('> gen_str_for_struct: $info.parent_type.debug() | $styp | $str_fn_name')
828828
}
829829
// _str() functions should have a single argument, the indenting ones take 2:
830-
g.type_definitions.writeln('static string ${str_fn_name}($styp it); // auto')
830+
g.definitions.writeln('static string ${str_fn_name}($styp it); // auto')
831831
g.auto_str_funcs.writeln('static string ${str_fn_name}($styp it) { return indent_${str_fn_name}(it, 0);}')
832-
g.type_definitions.writeln('static string indent_${str_fn_name}($styp it, int indent_count); // auto')
832+
g.definitions.writeln('static string indent_${str_fn_name}($styp it, int indent_count); // auto')
833833
mut fn_builder := strings.new_builder(512)
834834
defer {
835835
g.auto_fn_definitions << fn_builder.str()

0 commit comments

Comments
 (0)