Skip to content

Commit dec7030

Browse files
authored
builtin,cgen: add a source .location field to $for method in Type.methods { (#25976)
1 parent a8bded8 commit dec7030

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

‎vlib/builtin/meta_function.v‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub:
1111
pub struct FunctionData {
1212
pub:
1313
name string
14+
location string
1415
attrs []string
1516
args []FunctionParam
1617
return_type int

‎vlib/v/gen/c/comptime.v‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
662662
g.comptime.comptime_for_method_var = node.val_var
663663
g.writeln('/* method ${i} : ${method.name} */ {')
664664
g.writeln('\t${node.val_var}.name = _S("${method.name}");')
665+
mlocation := util.cescaped_path(util.path_styled_for_error_messages(method.file))
666+
g.writeln('\t${node.val_var}.location = _S("${mlocation}:${method.name_pos.line_nr + 1}:${method.name_pos.col}");')
665667
if method.attrs.len == 0 {
666668
g.writeln('\t${node.val_var}.attrs = builtin____new_array_with_default(0, 0, sizeof(string), 0);')
667669
} else {
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
FunctionData{
2-
name: 'sample_method'
3-
attrs: ['option: "1"']
4-
args: []
5-
return_type: 1
6-
typ: 0
7-
}
1+
['option: "1"']

‎vlib/v/gen/c/testdata/attr_string_quotes_escape.vv‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ fn (d Dummy) sample_method() {
66

77
fn main() {
88
$for method in Dummy.methods {
9-
println(method)
9+
println(method.attrs)
1010
}
1111
}

‎vlib/v/tests/comptime/comptime_call_test.v‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,23 @@ fn test_for_methods() {
3636
$if method.return_type is string {
3737
v := test.$method()
3838
r += v.str()
39+
if method.name == 's' {
40+
assert method.location.ends_with('vlib/v/tests/comptime/comptime_call_test.v:11:15')
41+
} else if method.name == 's2' {
42+
assert method.location.ends_with('vlib/v/tests/comptime/comptime_call_test.v:15:15')
43+
}
3944
} $else $if method.return_type is int {
4045
// TODO
4146
// v := test.$method()
4247
v := '?'
4348
r += v.str()
4449
assert method.name == 'i'
50+
assert method.location.ends_with('vlib/v/tests/comptime/comptime_call_test.v:7:15')
4551
} $else {
4652
// no return type
4753
test.$method()
4854
assert method.name == 'v'
55+
assert method.location.ends_with('vlib/v/tests/comptime/comptime_call_test.v:3:15')
4956
}
5057
}
5158
assert r == '?testTwo'

0 commit comments

Comments
 (0)