v.ast,v.fmt: support attributes on FnTypeDecl too

pull/14027/head
Delyan Angelov 2022-04-14 08:37:22 +03:00
parent 778614bcc9
commit e99059471b
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 15 additions and 0 deletions

View File

@ -1152,6 +1152,7 @@ pub:
pos token.Pos pos token.Pos
type_pos token.Pos type_pos token.Pos
comments []Comment comments []Comment
attrs []Attr // attributes of type declaration
} }
// TODO: handle this differently // TODO: handle this differently

View File

@ -1290,6 +1290,7 @@ pub fn (mut f Fmt) alias_type_decl(node ast.AliasTypeDecl) {
} }
pub fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl) { pub fn (mut f Fmt) fn_type_decl(node ast.FnTypeDecl) {
f.attrs(node.attrs)
if node.is_pub { if node.is_pub {
f.write('pub ') f.write('pub ')
} }

View File

@ -0,0 +1,10 @@
[callconv: 'stdcall']
fn C.DefWindowProc(hwnd int, msg int, lparam int, wparam int)
[callconv: 'stdcall']
type FastFn = fn (int) bool
[callconv: 'fastcall']
fn zzz(x int, y int) int {
return x + y * 2
}

View File

@ -3579,6 +3579,8 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
p.table.sym(fn_type).is_pub = is_pub p.table.sym(fn_type).is_pub = is_pub
type_pos = type_pos.extend(p.tok.pos()) type_pos = type_pos.extend(p.tok.pos())
comments = p.eat_comments(same_line: true) comments = p.eat_comments(same_line: true)
attrs := p.attrs
p.attrs = []
return ast.FnTypeDecl{ return ast.FnTypeDecl{
name: fn_name name: fn_name
is_pub: is_pub is_pub: is_pub
@ -3586,6 +3588,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl {
pos: decl_pos pos: decl_pos
type_pos: type_pos type_pos: type_pos
comments: comments comments: comments
attrs: attrs
} }
} }
sum_variants << p.parse_sum_type_variants() sum_variants << p.parse_sum_type_variants()