Add (gen > c) -> Added callconv attribute for function type aliases
parent
6d12f57d14
commit
77efa1f074
|
|
@ -1343,7 +1343,21 @@ pub fn (mut g Gen) write_fn_typesymbol_declaration(sym ast.TypeSymbol) {
|
|||
if !info.has_decl && (not_anon || is_fn_sig) && !func.return_type.has_flag(.generic)
|
||||
&& !has_generic_arg {
|
||||
fn_name := sym.cname
|
||||
g.type_definitions.write_string('typedef ${g.typ(func.return_type)} (*$fn_name)(')
|
||||
|
||||
mut call_conv := ""
|
||||
|
||||
for attr in func.attrs {
|
||||
match attr.name {
|
||||
"callconv" {
|
||||
if attr.has_arg {
|
||||
call_conv = "__$attr.arg "
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
||||
|
||||
g.type_definitions.write_string('typedef ${g.typ(func.return_type)} ($call_conv*$fn_name)(')
|
||||
for i, param in func.params {
|
||||
g.type_definitions.write_string(g.typ(param.typ))
|
||||
if i < func.params.len - 1 {
|
||||
|
|
|
|||
|
|
@ -229,6 +229,20 @@ pub fn (mut p Parser) parse_multi_return_type() ast.Type {
|
|||
pub fn (mut p Parser) parse_fn_type(name string) ast.Type {
|
||||
// p.warn('parse fn')
|
||||
p.check(.key_fn)
|
||||
|
||||
for attr in p.attrs {
|
||||
match attr.name {
|
||||
"callconv" {
|
||||
if attr.has_arg {
|
||||
if attr.arg !in ['stdcall', 'fastcall', 'cdecl'] {
|
||||
p.error_with_pos('unsupported calling convention, supported are stdcall, fastcall and cdecl', p.prev_tok.pos())
|
||||
}
|
||||
}
|
||||
}
|
||||
else {}
|
||||
}
|
||||
}
|
||||
|
||||
mut has_generic := false
|
||||
line_nr := p.tok.line_nr
|
||||
args, _, is_variadic := p.fn_args()
|
||||
|
|
@ -255,6 +269,7 @@ pub fn (mut p Parser) parse_fn_type(name string) ast.Type {
|
|||
return_type: return_type
|
||||
return_type_pos: return_type_pos
|
||||
is_method: false
|
||||
attrs: p.attrs
|
||||
}
|
||||
// MapFooFn typedefs are manually added in cheaders.v
|
||||
// because typedefs get generated after the map struct is generated
|
||||
|
|
|
|||
Loading…
Reference in New Issue