cgen: fix missing function names in declarations on `[c2v_variadic][c: xyz]fn deh_fprintf(fstream &C.FILE, fmt &i8)`

master
Delyan Angelov 2022-06-06 14:33:24 +03:00
parent 7f67981637
commit 6398043094
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 40 additions and 25 deletions

View File

@ -54,6 +54,25 @@ pub fn (attrs []Attr) contains(str string) bool {
return attrs.any(it.name == str)
}
pub fn (attrs []Attr) find_first(aname string) ?Attr {
for a in attrs {
if a.name == aname {
return a
}
}
return none
}
pub fn (attrs []Attr) find_last(aname string) ?Attr {
for idx := attrs.len - 1; idx > -1; idx-- {
a := attrs[idx]
if a.name == aname {
return a
}
}
return none
}
pub fn (attrs []Attr) find_comptime_define() ?int {
for idx in 0 .. attrs.len {
if attrs[idx].kind == .comptime_define {

View File

@ -3925,8 +3925,8 @@ fn (mut g Gen) ident(node ast.Ident) {
// `p_mobjthinker` => `P_MobjThinker`
if f := g.table.find_fn(node.name) {
// TODO PERF fn lookup for each fn call in translated mode
if f.attrs.contains('c') {
name = f.attrs[0].arg
if cattr := f.attrs.find_first('c') {
name = cattr.arg
}
}
}
@ -3970,8 +3970,8 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
// TODO handle the type in fn casts, not just exprs
/*
info := sym.info as ast.FnType
if info.func.attrs.contains('c') {
// name = f.attrs[0].arg
if cattr := info.func.attrs.find_first('c') {
name = cattr.arg
}
*/
}
@ -4398,11 +4398,11 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) {
}
}
name := c_name(field.name)
const_name := if node.attrs.contains('export') && !g.is_builtin_mod {
// TODO this only works for the first const in the group for now
node.attrs[0].arg
} else {
'_const_' + name
mut const_name := '_const_' + name
if !g.is_builtin_mod {
if cattr := node.attrs.find_first('export') {
const_name = cattr.arg
}
}
field_expr := field.expr
match field.expr {

View File

@ -446,20 +446,16 @@ fn (mut g Gen) c_fn_name(node &ast.FnDecl) ?string {
name = g.generic_fn_name(g.cur_concrete_types, name, true)
}
if (g.pref.translated || g.file.is_translated) && node.attrs.contains('c') {
// This fixes unknown symbols errors when building separate .c => .v files
// into .o files
//
if g.pref.translated || g.file.is_translated {
if cattr := node.attrs.find_first('c') {
// This fixes unknown symbols errors when building separate .c => .v files into .o files
// example:
// [c: 'P_TryMove']
// fn p_trymove(thing &Mobj_t, x int, y int) bool
//
// =>
//
// [c: 'P_TryMove'] fn p_trymove(thing &Mobj_t, x int, y int) bool
// translates to:
// bool P_TryMove(main__Mobj_t* thing, int x, int y);
//
// In fn_call every time `p_trymove` is called, `P_TryMove` will be generated instead.
name = node.attrs[0].arg
name = cattr.arg
}
}
return name
}
@ -1239,8 +1235,8 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
// every time `p_trymove` is called, `P_TryMove` must be generated instead.
if f := g.table.find_fn(node.name) {
// TODO PERF fn lookup for each fn call in translated mode
if f.attrs.contains('c') {
name = f.attrs[0].arg
if cattr := f.attrs.find_first('c') {
name = cattr.arg
}
}
}