mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
expose is_embed in FieldData
This commit is contained in:
parent
f6b60e4d9f
commit
627f308943
5 changed files with 16 additions and 7 deletions
|
@ -124,9 +124,10 @@ pub:
|
||||||
typ int // the internal TypeID of the field f,
|
typ int // the internal TypeID of the field f,
|
||||||
unaliased_typ int // if f's type was an alias of int, this will be TypeID(int)
|
unaliased_typ int // if f's type was an alias of int, this will be TypeID(int)
|
||||||
|
|
||||||
attrs []string // the attributes of the field f
|
attrs []string // the attributes of the field f
|
||||||
is_pub bool // f is in a `pub:` section
|
is_pub bool // f is in a `pub:` section
|
||||||
is_mut bool // f is in a `mut:` section
|
is_mut bool // f is in a `mut:` section
|
||||||
|
is_embed bool // f is a embedded struct
|
||||||
|
|
||||||
is_shared bool // `f shared Abc`
|
is_shared bool // `f shared Abc`
|
||||||
is_atomic bool // `f atomic int` , TODO
|
is_atomic bool // `f atomic int` , TODO
|
||||||
|
|
|
@ -1398,7 +1398,7 @@ fn (mut c Checker) comptime_if_cond(mut cond ast.Expr, mut sb strings.Builder) (
|
||||||
}
|
}
|
||||||
ast.SelectorExpr {
|
ast.SelectorExpr {
|
||||||
if c.comptime.comptime_for_field_var != '' && cond.expr is ast.Ident {
|
if c.comptime.comptime_for_field_var != '' && cond.expr is ast.Ident {
|
||||||
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'] {
|
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'] {
|
||||||
is_true = c.type_resolver.get_comptime_selector_bool_field(cond.field_name)
|
is_true = c.type_resolver.get_comptime_selector_bool_field(cond.field_name)
|
||||||
sb.write_string('${is_true}')
|
sb.write_string('${is_true}')
|
||||||
return is_true, true
|
return is_true, true
|
||||||
|
|
|
@ -740,6 +740,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
|
||||||
g.writeln('\t${node.val_var}.unaliased_typ = ${int(unaliased_styp.idx())};\t// ${g.table.type_to_str(unaliased_styp)}')
|
g.writeln('\t${node.val_var}.unaliased_typ = ${int(unaliased_styp.idx())};\t// ${g.table.type_to_str(unaliased_styp)}')
|
||||||
g.writeln('\t${node.val_var}.is_pub = ${field.is_pub};')
|
g.writeln('\t${node.val_var}.is_pub = ${field.is_pub};')
|
||||||
g.writeln('\t${node.val_var}.is_mut = ${field.is_mut};')
|
g.writeln('\t${node.val_var}.is_mut = ${field.is_mut};')
|
||||||
|
g.writeln('\t${node.val_var}.is_embed = ${field.is_embed};')
|
||||||
|
|
||||||
g.writeln('\t${node.val_var}.is_shared = ${field.typ.has_flag(.shared_f)};')
|
g.writeln('\t${node.val_var}.is_shared = ${field.typ.has_flag(.shared_f)};')
|
||||||
g.writeln('\t${node.val_var}.is_atomic = ${field.typ.has_flag(.atomic_f)};')
|
g.writeln('\t${node.val_var}.is_atomic = ${field.typ.has_flag(.atomic_f)};')
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
struct App {
|
struct App {
|
||||||
|
Inner
|
||||||
a string
|
a string
|
||||||
b string
|
b string
|
||||||
mut:
|
mut:
|
||||||
|
@ -12,6 +13,8 @@ pub mut:
|
||||||
h u8
|
h u8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Inner {}
|
||||||
|
|
||||||
@['foo/bar/three']
|
@['foo/bar/three']
|
||||||
fn (mut app App) run() {
|
fn (mut app App) run() {
|
||||||
}
|
}
|
||||||
|
@ -85,13 +88,16 @@ fn test_comptime_for_fields() {
|
||||||
assert field.name in ['d', 'e']
|
assert field.name in ['d', 'e']
|
||||||
}
|
}
|
||||||
if field.is_mut {
|
if field.is_mut {
|
||||||
assert field.name in ['c', 'd', 'g', 'h']
|
assert field.name in ['c', 'd', 'g', 'h', 'Inner']
|
||||||
}
|
}
|
||||||
if field.is_pub {
|
if field.is_pub {
|
||||||
assert field.name in ['e', 'f', 'g', 'h']
|
assert field.name in ['e', 'f', 'g', 'h', 'Inner']
|
||||||
}
|
}
|
||||||
if field.is_pub && field.is_mut {
|
if field.is_pub && field.is_mut {
|
||||||
assert field.name in ['g', 'h']
|
assert field.name in ['g', 'h', 'Inner']
|
||||||
|
}
|
||||||
|
if field.is_embed {
|
||||||
|
assert field.name == 'Inner'
|
||||||
}
|
}
|
||||||
if field.name == 'f' {
|
if field.name == 'f' {
|
||||||
assert sizeof(field) == 8
|
assert sizeof(field) == 8
|
||||||
|
|
|
@ -224,6 +224,7 @@ pub fn (mut t TypeResolver) get_comptime_selector_bool_field(field_name string)
|
||||||
match field_name {
|
match field_name {
|
||||||
'is_pub' { return field.is_pub }
|
'is_pub' { return field.is_pub }
|
||||||
'is_mut' { return field.is_mut }
|
'is_mut' { return field.is_mut }
|
||||||
|
'is_embed' { return field.is_embed }
|
||||||
'is_shared' { return field_typ.has_flag(.shared_f) }
|
'is_shared' { return field_typ.has_flag(.shared_f) }
|
||||||
'is_atomic' { return field_typ.has_flag(.atomic_f) }
|
'is_atomic' { return field_typ.has_flag(.atomic_f) }
|
||||||
'is_option' { return field.typ.has_flag(.option) }
|
'is_option' { return field.typ.has_flag(.option) }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue