cgen: implement `[export: 'FooBar']` attribute (#6278)

pull/6280/head
spaceface777 2020-08-31 21:52:25 +02:00 committed by GitHub
parent 39da5eca89
commit 60a9d49382
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

View File

@ -108,7 +108,9 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl, skip bool) {
g.definitions.write(fn_header)
g.write(fn_header)
}
arg_start_pos := g.out.len
fargs, fargtypes := g.fn_args(it.args, it.is_variadic)
arg_str := g.out.after(arg_start_pos)
if it.no_body || (g.pref.use_cache && it.is_builtin) || skip {
// Just a function header. Builtin function bodies are defined in builtin.o
g.definitions.writeln(');') // // NO BODY')
@ -160,6 +162,18 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl, skip bool) {
if g.pref.printfn_list.len > 0 && g.last_fn_c_name in g.pref.printfn_list {
println(g.out.after(fn_start_pos))
}
for attr in it.attrs {
if attr.name == 'export' {
g.writeln('// export alias: $attr.arg -> $name')
export_alias := '$type_name ${attr.arg}($arg_str)'
g.definitions.writeln('$export_alias;')
g.writeln('$export_alias {')
g.write('\treturn ${name}(')
g.write(fargs.join(', '))
g.writeln(');')
g.writeln('}')
}
}
}
fn (mut g Gen) write_autofree_stmts_when_needed(r ast.Return) {