From 6bd22e89ed48ca79739c8413e006f69147c90269 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Tue, 17 Sep 2024 09:44:18 -0300 Subject: [PATCH] rename MethodArgs to MethodParam --- vlib/builtin/builtin.v | 6 +++--- vlib/v/ast/ast.v | 2 +- vlib/v/ast/str.v | 2 +- vlib/v/checker/comptime.v | 4 ++-- vlib/v/comptime/comptimeinfo.v | 12 ++++++------ vlib/v/gen/c/comptime.v | 10 +++++----- vlib/v/parser/comptime.v | 8 ++++---- ...d_arg_test.v => comptime_for_method_param_test.v} | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) rename vlib/v/tests/comptime/{comptime_for_method_arg_test.v => comptime_for_method_param_test.v} (94%) diff --git a/vlib/builtin/builtin.v b/vlib/builtin/builtin.v index 264cb5b2fa9ebb..9f7a2d30799510 100644 --- a/vlib/builtin/builtin.v +++ b/vlib/builtin/builtin.v @@ -90,8 +90,8 @@ fn __print_assert_failure(i &VAssertMetaInfo) { } } -// MethodArgs holds type information for function and/or method arguments. -pub struct MethodArgs { +// MethodParam holds type information for function and/or method arguments. +pub struct MethodParam { pub: typ int name string @@ -102,7 +102,7 @@ pub struct FunctionData { pub: name string attrs []string - args []MethodArgs + args []MethodParam return_type int typ int } diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 7b9c188eb51ab1..3f3d30f04e30a8 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -1241,12 +1241,12 @@ pub mut: } pub enum ComptimeForKind { - args methods fields attributes values variants + params } pub struct ComptimeFor { diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index aa9bb12219dd6f..cf7aa132fa9e1c 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -891,11 +891,11 @@ fn field_to_string(f ConstField) string { pub fn (e ComptimeForKind) str() string { match e { - .args { return 'args' } .methods { return 'methods' } .fields { return 'fields' } .attributes { return 'attributes' } .values { return 'values' } .variants { return 'variants' } + .params { return 'params' } } } diff --git a/vlib/v/checker/comptime.v b/vlib/v/checker/comptime.v index 6f62053193e234..286c35d34abfaa 100644 --- a/vlib/v/checker/comptime.v +++ b/vlib/v/checker/comptime.v @@ -325,10 +325,10 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { c.stmts(mut node.stmts) c.pop_comptime_info() } - } else if node.kind == .args { + } else if node.kind == .params { c.push_new_comptime_info() c.comptime.inside_comptime_for = true - c.comptime.comptime_for_method_arg_var = node.val_var + c.comptime.comptime_for_method_param_var = node.val_var c.stmts(mut node.stmts) c.pop_comptime_info() } else if node.kind == .variants { diff --git a/vlib/v/comptime/comptimeinfo.v b/vlib/v/comptime/comptimeinfo.v index 71c54c31587d33..3d340a8277bded 100644 --- a/vlib/v/comptime/comptimeinfo.v +++ b/vlib/v/comptime/comptimeinfo.v @@ -114,8 +114,8 @@ pub fn (mut ct ComptimeInfo) get_type_from_comptime_var(var ast.Ident) ast.Type ct.comptime_for_variant_var { ct.type_map['${ct.comptime_for_variant_var}.typ'] } - ct.comptime_for_method_arg_var { - ct.type_map['${ct.comptime_for_method_arg_var}.typ'] + ct.comptime_for_method_param_var { + ct.type_map['${ct.comptime_for_method_param_var}.typ'] } else { // field_var.typ from $for field @@ -155,7 +155,7 @@ pub fn (mut ct ComptimeInfo) is_comptime_selector_field_name(node ast.SelectorEx pub fn (mut ct ComptimeInfo) is_comptime_selector_type(node ast.SelectorExpr) bool { if ct.inside_comptime_for && node.expr is ast.Ident { return - node.expr.name in [ct.comptime_for_enum_var, ct.comptime_for_variant_var, ct.comptime_for_field_var, ct.comptime_for_method_arg_var] + node.expr.name in [ct.comptime_for_enum_var, ct.comptime_for_variant_var, ct.comptime_for_field_var, ct.comptime_for_method_param_var] && node.field_name == 'typ' } return false @@ -276,8 +276,8 @@ fn (mut ct ComptimeInfo) comptime_get_kind_var(var ast.Ident) ?ast.ComptimeForKi ct.comptime_for_attr_var { return .attributes } - ct.comptime_for_method_arg_var { - return .args + ct.comptime_for_method_param_var { + return .params } else { return none @@ -348,5 +348,5 @@ pub mut: comptime_for_method &ast.Fn = unsafe { nil } comptime_for_method_ret_type ast.Type // .args - comptime_for_method_arg_var string + comptime_for_method_param_var string } diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index ea6e3d37123bde..3539aa6e7ecac5 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -842,10 +842,10 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { } if method.params.len < 2 { // 0 or 1 (the receiver) args - g.writeln('\t${node.val_var}.args = __new_array_with_default(0, 0, sizeof(MethodArgs), 0);') + g.writeln('\t${node.val_var}.args = __new_array_with_default(0, 0, sizeof(MethodParam), 0);') } else { len := method.params.len - 1 - g.write('\t${node.val_var}.args = new_array_from_c_array(${len}, ${len}, sizeof(MethodArgs), _MOV((MethodArgs[${len}]){') + g.write('\t${node.val_var}.args = new_array_from_c_array(${len}, ${len}, sizeof(MethodParam), _MOV((MethodParam[${len}]){') // Skip receiver arg for j, arg in method.params[1..] { typ := arg.typ.idx() @@ -1020,15 +1020,15 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { } g.pop_comptime_info() } - } else if node.kind == .args { + } else if node.kind == .params { method := g.comptime.comptime_for_method if method.params.len > 0 { - g.writeln('\tMethodArgs ${node.val_var} = {0};') + g.writeln('\tMethodParam ${node.val_var} = {0};') } g.push_new_comptime_info() g.comptime.inside_comptime_for = true - g.comptime.comptime_for_method_arg_var = node.val_var + g.comptime.comptime_for_method_param_var = node.val_var for param in method.params[1..] { g.comptime.type_map['${node.val_var}.typ'] = param.typ diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 4ec5c214153c34..16e4510d16a1d7 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -363,13 +363,13 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor { p.close_scope() } match for_val { - 'args' { + 'params' { p.scope.register(ast.Var{ name: val_var - typ: p.table.find_type_idx('MethodArgs') + typ: p.table.find_type_idx('MethodParam') pos: var_pos }) - kind = .args + kind = .params } 'methods' { p.scope.register(ast.Var{ @@ -411,7 +411,7 @@ fn (mut p Parser) comptime_for() ast.ComptimeFor { kind = .attributes } else { - p.error_with_pos('unknown kind `${for_val}`, available are: `methods`, `fields`, `values`, `variants` or `attributes`', + p.error_with_pos('unknown kind `${for_val}`, available are: `methods`, `fields`, `values`, `variants`, `attributes` or `params`', p.prev_tok.pos()) return ast.ComptimeFor{} } diff --git a/vlib/v/tests/comptime/comptime_for_method_arg_test.v b/vlib/v/tests/comptime/comptime_for_method_param_test.v similarity index 94% rename from vlib/v/tests/comptime/comptime_for_method_arg_test.v rename to vlib/v/tests/comptime/comptime_for_method_param_test.v index b78e21939a8b34..d01c43b625868f 100644 --- a/vlib/v/tests/comptime/comptime_for_method_arg_test.v +++ b/vlib/v/tests/comptime/comptime_for_method_param_test.v @@ -11,7 +11,7 @@ fn (mut s Struct1) do_thing(a f32, b voidptr) bool { fn register[T]() []string { mut args := []string{} $for method in T.methods { - $for arg in method.args { + $for arg in method.params { $if arg.typ is f32 { args << 'f32: ${arg.name} ${typeof(arg.typ).name}' } $else $if arg.typ is voidptr {