Skip to content

Commit

Permalink
rename MethodArgs to MethodParam
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Sep 17, 2024
1 parent c6742ec commit 6bd22e8
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions vlib/builtin/builtin.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -102,7 +102,7 @@ pub struct FunctionData {
pub:
name string
attrs []string
args []MethodArgs
args []MethodParam
return_type int
typ int
}
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/ast/ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -1241,12 +1241,12 @@ pub mut:
}

pub enum ComptimeForKind {
args
methods
fields
attributes
values
variants
params
}

pub struct ComptimeFor {
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/ast/str.v
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
}
}
4 changes: 2 additions & 2 deletions vlib/v/checker/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions vlib/v/comptime/comptimeinfo.v
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
10 changes: 5 additions & 5 deletions vlib/v/gen/c/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions vlib/v/parser/comptime.v
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6bd22e8

Please sign in to comment.