mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
global access modifier
This commit is contained in:
parent
dc83e30a44
commit
c72bf0e1b1
@ -161,6 +161,17 @@ fn (p mut Parser) struct_decl() {
|
|||||||
p.fmt_inc()
|
p.fmt_inc()
|
||||||
p.fgen_nl()
|
p.fgen_nl()
|
||||||
}
|
}
|
||||||
|
else if p.tok == .key_global {
|
||||||
|
new_access_mod = .global
|
||||||
|
if new_access_mod in used {
|
||||||
|
p.error('structs can only have one `__global:`, all global fields have to be grouped')
|
||||||
|
}
|
||||||
|
p.fmt_dec()
|
||||||
|
p.check(.key_global)
|
||||||
|
p.check(.colon)
|
||||||
|
p.fmt_inc()
|
||||||
|
p.fgen_nl()
|
||||||
|
}
|
||||||
if new_access_mod != access_mod {
|
if new_access_mod != access_mod {
|
||||||
used << new_access_mod
|
used << new_access_mod
|
||||||
}
|
}
|
||||||
@ -246,9 +257,8 @@ fn (p mut Parser) struct_decl() {
|
|||||||
if attr == 'raw' && field_type != 'string' {
|
if attr == 'raw' && field_type != 'string' {
|
||||||
p.error('struct field with attribute "raw" should be of type "string" but got "$field_type"')
|
p.error('struct field with attribute "raw" should be of type "string" but got "$field_type"')
|
||||||
}
|
}
|
||||||
|
|
||||||
did_gen_something = true
|
did_gen_something = true
|
||||||
is_mut := access_mod in [.private_mut, .public_mut]
|
is_mut := access_mod in [.private_mut, .public_mut, .global]
|
||||||
if p.first_pass() {
|
if p.first_pass() {
|
||||||
p.table.add_field(typ.name, field_name, field_type, is_mut,
|
p.table.add_field(typ.name, field_name, field_type, is_mut,
|
||||||
attr, access_mod)
|
attr, access_mod)
|
||||||
|
@ -163,7 +163,7 @@ pub:
|
|||||||
d int // public immmutable (readonly)
|
d int // public immmutable (readonly)
|
||||||
pub mut:
|
pub mut:
|
||||||
e int // public, but mutable only in parent module
|
e int // public, but mutable only in parent module
|
||||||
//__global:
|
__global:
|
||||||
f int // public and mutable both inside and outside parent module
|
f int // public and mutable both inside and outside parent module
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user