all: volatile globals

pull/13991/merge
Alexander Medvednikov 2022-04-15 02:39:38 +03:00
parent 0dff050735
commit 3b36f16365
3 changed files with 8 additions and 1 deletions

View File

@ -663,6 +663,7 @@ pub:
pos token.Pos
typ_pos token.Pos
is_markused bool // an explict `[markused]` tag; the global will NOT be removed by `-skip-unused`
is_volatile bool
pub mut:
expr Expr
typ Type

View File

@ -4417,7 +4417,8 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
g.definitions.writeln('$fn_type_name = ${g.table.sym(field.typ).name}; // global2')
continue
}
g.definitions.write_string('$visibility_kw$styp $attributes $field.name')
modifier := if field.is_volatile { ' volatile ' } else { '' }
g.definitions.write_string('$visibility_kw$modifier$styp $attributes $field.name')
if field.has_expr || cinit {
if g.pref.translated {
g.definitions.write_string(' = ${g.expr_string(field.expr)}')

View File

@ -3364,6 +3364,10 @@ fn (mut p Parser) global_decl() ast.GlobalDecl {
mut comments := []ast.Comment{}
for {
comments = p.eat_comments()
is_volatile := p.tok.kind == .key_volatile
if is_volatile {
p.next()
}
if is_block && p.tok.kind == .eof {
p.error('unexpected eof, expecting `)`')
return ast.GlobalDecl{}
@ -3416,6 +3420,7 @@ fn (mut p Parser) global_decl() ast.GlobalDecl {
typ: typ
comments: comments
is_markused: is_markused
is_volatile: is_volatile
}
fields << field
p.table.global_scope.register(field)