@@ -52,15 +52,7 @@ fn (mut g Gen) fn_decl(node ast.FnDecl) {
52
52
mut skip := false
53
53
pos := g.out.len
54
54
should_bundle_module := util.should_bundle_module (node.mod)
55
- /*
56
- if node.name.contains('i_error') {
57
- println(g.table.type_str(node.params[0].typ))
58
- }
59
- */
60
55
if g.pref.build_mode == .build_module {
61
- // if node.name.contains('parse_text') {
62
- // println('!!! $node.name mod=$node.mod, built=$g.module_built')
63
- // }
64
56
// TODO true for not just "builtin"
65
57
// TODO: clean this up
66
58
mod := if g.is_builtin_mod { 'builtin' } else { node.name.all_before_last ('.' ) }
@@ -120,7 +112,6 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
120
112
// as it's only informative, comment it for now
121
113
// g.gen_attrs(it.attrs)
122
114
if node.language == .c {
123
- // || node.no_body {
124
115
return
125
116
}
126
117
@@ -155,19 +146,15 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
155
146
*/
156
147
157
148
g.returned_var_name = ''
158
- //
159
149
old_g_autofree := g.is_autofree
160
150
if node.is_manualfree {
161
151
g.is_autofree = false
162
152
}
163
153
defer {
164
154
g.is_autofree = old_g_autofree
165
155
}
166
- //
167
- // if g.fileis('vweb.v') {
168
- // println('\ngen_fn_decl() $node.name $node.is_generic $g.cur_generic_type')
169
- // }
170
- if node.generic_names.len > 0 && g.cur_concrete_types.len == 0 { // need the cur_concrete_type check to avoid inf. recursion
156
+ if node.generic_names.len > 0 && g.cur_concrete_types.len == 0 {
157
+ // need the cur_concrete_type check to avoid inf. recursion
171
158
// loop thru each generic type and generate a function
172
159
nkey := node.fkey ()
173
160
generic_types_by_fn := g.table.fn_generic_types[nkey]
@@ -215,7 +202,7 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
215
202
if is_livefn && ! is_livemode {
216
203
eprintln ('INFO: compile with `v -live $g.pref.path `, if you want to use the [live] function $node.name .' )
217
204
}
218
- //
205
+
219
206
mut name := g.c_fn_name (node) or { return }
220
207
mut type_name := g.typ (g.unwrap_generic (node.return_type))
221
208
@@ -231,10 +218,6 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
231
218
panic ('cgen: fn_decl: obf name "$key " not found, this should never happen' )
232
219
}
233
220
}
234
- // if g.pref.show_cc && it.is_builtin {
235
- // println(name)
236
- // }
237
- // type_name := g.ast.Type_to_str(it.return_type)
238
221
// Live functions are protected by a mutex, because otherwise they
239
222
// can be changed by the live reload thread, *while* they are
240
223
// running, with unpredictable results (usually just crashing).
@@ -268,7 +251,6 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
268
251
// Private functions need to marked as static so that they are not exportable in the
269
252
// binaries
270
253
if g.pref.build_mode != .build_module && ! g.pref.use_cache {
271
- // if !(g.pref.build_mode == .build_module && g.is_builtin_mod) {
272
254
// If we are building vlib/builtin, we need all private functions like array_get
273
255
// to be public, so that all V programs can access them.
274
256
g.write ('VV_LOCAL_SYMBOL ' )
@@ -297,7 +279,7 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
297
279
if node.no_body || ((g.pref.use_cache && g.pref.build_mode != .build_module) && node.is_builtin
298
280
&& ! g.pref.is_test) || skip {
299
281
// Just a function header. Builtin function bodies are defined in builtin.o
300
- g.definitions.writeln (');' ) // // NO BODY')
282
+ g.definitions.writeln (');' ) // NO BODY')
301
283
g.writeln (');' )
302
284
return
303
285
}
@@ -395,14 +377,7 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
395
377
default_expr := g.type_default (node.return_type)
396
378
// TODO: perf?
397
379
if default_expr == '{0}' {
398
- // if node.return_type.idx() == 1 && node.return_type.has_flag(.optional) {
399
- // // The default return for anonymous functions that return `?,
400
- // // should have .ok = true set, otherwise calling them with
401
- // // optfn() or { panic(err) } will cause a panic:
402
- // g.writeln('\treturn (Option_void){0};')
403
- // } else {
404
380
g.writeln ('\t return ($type_name )$default_expr ;' )
405
- // }
406
381
} else {
407
382
g.writeln ('\t return $default_expr ;' )
408
383
}
@@ -437,7 +412,6 @@ fn (mut g Gen) c_fn_name(node &ast.FnDecl) ?string {
437
412
return none
438
413
}
439
414
name = g.cc_type (node.receiver.typ, false ) + '_' + name
440
- // name = g.table.sym(node.receiver.typ).name + '_' + name
441
415
}
442
416
if node.language == .c {
443
417
name = util.no_dots (name)
@@ -615,7 +589,6 @@ fn (mut g Gen) get_anon_fn_type_name(mut node ast.AnonFn, var_name string) strin
615
589
}
616
590
617
591
fn (mut g Gen) call_expr (node ast.CallExpr) {
618
- // g.write('/*call expr*/')
619
592
// NOTE: everything could be done this way
620
593
// see my comment in parser near anon_fn
621
594
if node.left is ast.AnonFn {
@@ -643,7 +616,6 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
643
616
// cut everything that has been generated to prepend optional variable creation
644
617
line := g.go_before_stmt (0 )
645
618
g.out.write_string (util.tabs (g.indent))
646
- // g.write('/*is_gen_or_and_assign_rhs*/')
647
619
line
648
620
} else {
649
621
''
@@ -668,10 +640,8 @@ fn (mut g Gen) call_expr(node ast.CallExpr) {
668
640
} else {
669
641
g.fn_call (node)
670
642
}
671
- if gen_or { // && !g.autofree {
672
- // if !g.is_autofree {
643
+ if gen_or {
673
644
g.or_block (tmp_opt, node.or_block, node.return_type)
674
- // }
675
645
unwrapped_typ := node.return_type.clear_flag (.optional).clear_flag (.result)
676
646
unwrapped_styp := g.typ (unwrapped_typ)
677
647
if unwrapped_typ == ast.void_type {
@@ -932,7 +902,6 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
932
902
}
933
903
}
934
904
} else if node.left is ast.None {
935
- // none.str()
936
905
g.gen_expr_to_string (node.left, ast.none_type)
937
906
return
938
907
}
@@ -1013,11 +982,6 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
1013
982
name = g.generic_fn_name (node.concrete_types, name, false )
1014
983
// TODO2
1015
984
// g.generate_tmp_autofree_arg_vars(node, name)
1016
- //
1017
- // if node.receiver_type != 0 {
1018
- // g.write('/*${g.typ(node.receiver_type)}*/')
1019
- // g.write('/*expr_type=${g.typ(node.left_type)} rec type=${g.typ(node.receiver_type)}*/')
1020
- // }
1021
985
if ! node.receiver_type.is_ptr () && node.left_type.is_ptr () && node.name == 'str' {
1022
986
g.write ('ptr_str(' )
1023
987
} else if node.receiver_type.is_ptr () && node.left_type.is_ptr () && node.name == 'str'
@@ -1065,10 +1029,6 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
1065
1029
}
1066
1030
}
1067
1031
1068
- // if node.left_type.idx() != node.receiver_type.idx() {
1069
- // println('${g.typ(node.left_type)} ${g.typ(node.receiver_type)}')
1070
- // }
1071
-
1072
1032
if g.is_autofree && node.free_receiver && ! g.inside_lambda && ! g.is_builtin_mod {
1073
1033
// The receiver expression needs to be freed, use the temp var.
1074
1034
fn_name := node.name.replace ('.' , '_' )
@@ -1113,18 +1073,6 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
1113
1073
if node.args.len > 0 || is_variadic {
1114
1074
g.write (', ' )
1115
1075
}
1116
- // /////////
1117
- /*
1118
- if name.contains('subkeys') {
1119
- println('call_args $name $node.arg_types.len')
1120
- for t in node.arg_types {
1121
- sym := g.table.sym(t)
1122
- print('$sym.name ')
1123
- }
1124
- println('')
1125
- }
1126
- */
1127
- // ///////
1128
1076
g.call_args (node)
1129
1077
if array_depth > = 0 {
1130
1078
g.write (', $array_depth ' )
@@ -1191,7 +1139,6 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
1191
1139
g.gen_json_for_type (node.args[0 ].typ)
1192
1140
json_type_str = g.typ (node.args[0 ].typ)
1193
1141
// `json__encode` => `json__encode_User`
1194
- // encode_name := c_name(name) + '_' + util.no_dots(json_type_str)
1195
1142
encode_name := js_enc_name (json_type_str)
1196
1143
g.empty_line = true
1197
1144
g.writeln ('// json.encode' )
@@ -1294,7 +1241,6 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
1294
1241
if g.is_autofree && ! typ.has_flag (.optional) {
1295
1242
// Create a temporary variable so that the value can be freed
1296
1243
tmp := g.new_tmp_var ()
1297
- // tmps << tmp
1298
1244
g.write ('string $tmp = ' )
1299
1245
g.gen_expr_to_string (expr, typ)
1300
1246
g.writeln ('; ${c_name(print_method)} ($tmp ); string_free(&$tmp );' )
@@ -1439,7 +1385,6 @@ fn (mut g Gen) autofree_call_pregen(node ast.CallExpr) {
1439
1385
},
1440
1386
]
1441
1387
args << node.args
1442
- // for i, arg in node.args {
1443
1388
for i, arg in args {
1444
1389
if ! arg.is_tmp_autofree {
1445
1390
continue
@@ -1450,11 +1395,8 @@ fn (mut g Gen) autofree_call_pregen(node ast.CallExpr) {
1450
1395
g.autofree_call_pregen (arg.expr)
1451
1396
}
1452
1397
free_tmp_arg_vars = true
1453
- // t := g.new_tmp_var() + '_arg_expr_${name}_$i'
1454
1398
fn_name := node.name.replace ('.' , '_' ) // can't use name...
1455
- // t := '_tt${g.tmp_count_af}_arg_expr_${fn_name}_$i'
1456
1399
t := '_arg_expr_${fn_name} _${i} _$node.pos.pos '
1457
- // g.called_fn_name = name
1458
1400
used := false // scope.known_var(t)
1459
1401
mut s := '$t = '
1460
1402
if used {
@@ -1479,9 +1421,7 @@ fn (mut g Gen) autofree_call_pregen(node ast.CallExpr) {
1479
1421
})
1480
1422
s = 'string $t = '
1481
1423
}
1482
- // g.expr(arg.expr)
1483
1424
s + = g.expr_string (arg.expr)
1484
- // g.writeln(';// new af pre')
1485
1425
s + = ';// new af2 pre'
1486
1426
g.strs_to_free0 << s
1487
1427
// This tmp arg var will be freed with the rest of the vars at the end of the scope.
@@ -1614,7 +1554,6 @@ fn (mut g Gen) call_args(node ast.CallExpr) {
1614
1554
if use_tmp_var_autofree {
1615
1555
// TODO copypasta, move to an inline fn
1616
1556
fn_name := node.name.replace ('.' , '_' )
1617
- // name := '_tt${g.tmp_count_af}_arg_expr_${fn_name}_$i'
1618
1557
name := '_arg_expr_${fn_name} _${i + 1} _$node.pos.pos '
1619
1558
g.write ('/*af arg2*/' + name)
1620
1559
} else {
@@ -1661,7 +1600,6 @@ fn (mut g Gen) call_args(node ast.CallExpr) {
1661
1600
if (g.pref.translated || g.file.is_translated) && args.len == 1 {
1662
1601
// Handle `foo(c'str')` for `fn foo(args ...&u8)`
1663
1602
// TODOC2V handle this in a better place
1664
- // println(g.table.type_to_str(args[0].typ))
1665
1603
g.expr (args[0 ].expr)
1666
1604
} else if args.len > 0 && args[args.len - 1 ].expr is ast.ArrayDecompose {
1667
1605
g.expr (args[args.len - 1 ].expr)
@@ -1741,12 +1679,6 @@ fn (mut g Gen) go_expr(node ast.GoExpr) {
1741
1679
g.writeln ('$wrapper_struct_name *$arg_tmp_var = malloc(sizeof(thread_arg_$name ));' )
1742
1680
if expr.is_method {
1743
1681
g.write ('$arg_tmp_var ->arg0 = ' )
1744
- // TODO is this needed?
1745
- /*
1746
- if false && !expr.return_type.is_ptr() {
1747
- g.write('&')
1748
- }
1749
- */
1750
1682
g.expr (expr.left)
1751
1683
g.writeln (';' )
1752
1684
}
@@ -1974,7 +1906,6 @@ fn (mut g Gen) keep_alive_call_pregen(node ast.CallExpr) int {
1974
1906
expected_type := node.expected_arg_types[i]
1975
1907
typ := g.table.sym (expected_type).cname
1976
1908
g.write ('$typ __tmp_arg_${tmp_cnt_save + i} = ' )
1977
- // g.expr(arg.expr)
1978
1909
g.ref_or_deref_arg (arg, expected_type, node.language)
1979
1910
g.writeln (';' )
1980
1911
}
0 commit comments