Skip to content

Commit 682db66

Browse files
authored
builtin, checker, cgen: expose is_embed in FieldData (#25232)
1 parent f6b60e4 commit 682db66

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

vlib/builtin/builtin.v

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ pub:
124124
typ int // the internal TypeID of the field f,
125125
unaliased_typ int // if f's type was an alias of int, this will be TypeID(int)
126126

127-
attrs []string // the attributes of the field f
128-
is_pub bool // f is in a `pub:` section
129-
is_mut bool // f is in a `mut:` section
127+
attrs []string // the attributes of the field f
128+
is_pub bool // f is in a `pub:` section
129+
is_mut bool // f is in a `mut:` section
130+
is_embed bool // f is a embedded struct
130131

131132
is_shared bool // `f shared Abc`
132133
is_atomic bool // `f atomic int` , TODO

vlib/v/checker/comptime.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1398,7 +1398,7 @@ fn (mut c Checker) comptime_if_cond(mut cond ast.Expr, mut sb strings.Builder) (
13981398
}
13991399
ast.SelectorExpr {
14001400
if c.comptime.comptime_for_field_var != '' && cond.expr is ast.Ident {
1401-
if (cond.expr as ast.Ident).name == c.comptime.comptime_for_field_var && cond.field_name in ['is_mut', 'is_pub', 'is_shared', 'is_atomic', 'is_option', 'is_array', 'is_map', 'is_chan', 'is_struct', 'is_alias', 'is_enum'] {
1401+
if (cond.expr as ast.Ident).name == c.comptime.comptime_for_field_var && cond.field_name in ['is_mut', 'is_pub', 'is_embed', 'is_shared', 'is_atomic', 'is_option', 'is_array', 'is_map', 'is_chan', 'is_struct', 'is_alias', 'is_enum'] {
14021402
is_true = c.type_resolver.get_comptime_selector_bool_field(cond.field_name)
14031403
sb.write_string('${is_true}')
14041404
return is_true, true

vlib/v/gen/c/comptime.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
740740
g.writeln('\t${node.val_var}.unaliased_typ = ${int(unaliased_styp.idx())};\t// ${g.table.type_to_str(unaliased_styp)}')
741741
g.writeln('\t${node.val_var}.is_pub = ${field.is_pub};')
742742
g.writeln('\t${node.val_var}.is_mut = ${field.is_mut};')
743+
g.writeln('\t${node.val_var}.is_embed = ${field.is_embed};')
743744

744745
g.writeln('\t${node.val_var}.is_shared = ${field.typ.has_flag(.shared_f)};')
745746
g.writeln('\t${node.val_var}.is_atomic = ${field.typ.has_flag(.atomic_f)};')

vlib/v/tests/comptime/comptime_for_test.v

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
struct App {
2+
Inner
23
a string
34
b string
45
mut:
@@ -12,6 +13,8 @@ pub mut:
1213
h u8
1314
}
1415

16+
struct Inner {}
17+
1518
@['foo/bar/three']
1619
fn (mut app App) run() {
1720
}
@@ -85,13 +88,16 @@ fn test_comptime_for_fields() {
8588
assert field.name in ['d', 'e']
8689
}
8790
if field.is_mut {
88-
assert field.name in ['c', 'd', 'g', 'h']
91+
assert field.name in ['c', 'd', 'g', 'h', 'Inner']
8992
}
9093
if field.is_pub {
91-
assert field.name in ['e', 'f', 'g', 'h']
94+
assert field.name in ['e', 'f', 'g', 'h', 'Inner']
9295
}
9396
if field.is_pub && field.is_mut {
94-
assert field.name in ['g', 'h']
97+
assert field.name in ['g', 'h', 'Inner']
98+
}
99+
if field.is_embed {
100+
assert field.name == 'Inner'
95101
}
96102
if field.name == 'f' {
97103
assert sizeof(field) == 8

vlib/v/type_resolver/comptime_resolver.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ pub fn (mut t TypeResolver) get_comptime_selector_bool_field(field_name string)
224224
match field_name {
225225
'is_pub' { return field.is_pub }
226226
'is_mut' { return field.is_mut }
227+
'is_embed' { return field.is_embed }
227228
'is_shared' { return field_typ.has_flag(.shared_f) }
228229
'is_atomic' { return field_typ.has_flag(.atomic_f) }
229230
'is_option' { return field.typ.has_flag(.option) }

0 commit comments

Comments
 (0)