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) 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 { pub fn (attrs []Attr) find_comptime_define() ?int {
for idx in 0 .. attrs.len { for idx in 0 .. attrs.len {
if attrs[idx].kind == .comptime_define { if attrs[idx].kind == .comptime_define {

View File

@ -3925,8 +3925,8 @@ fn (mut g Gen) ident(node ast.Ident) {
// `p_mobjthinker` => `P_MobjThinker` // `p_mobjthinker` => `P_MobjThinker`
if f := g.table.find_fn(node.name) { if f := g.table.find_fn(node.name) {
// TODO PERF fn lookup for each fn call in translated mode // TODO PERF fn lookup for each fn call in translated mode
if f.attrs.contains('c') { if cattr := f.attrs.find_first('c') {
name = f.attrs[0].arg 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 // TODO handle the type in fn casts, not just exprs
/* /*
info := sym.info as ast.FnType info := sym.info as ast.FnType
if info.func.attrs.contains('c') { if cattr := info.func.attrs.find_first('c') {
// name = f.attrs[0].arg name = cattr.arg
} }
*/ */
} }
@ -4398,11 +4398,11 @@ fn (mut g Gen) const_decl(node ast.ConstDecl) {
} }
} }
name := c_name(field.name) name := c_name(field.name)
const_name := if node.attrs.contains('export') && !g.is_builtin_mod { mut const_name := '_const_' + name
// TODO this only works for the first const in the group for now if !g.is_builtin_mod {
node.attrs[0].arg if cattr := node.attrs.find_first('export') {
} else { const_name = cattr.arg
'_const_' + name }
} }
field_expr := field.expr field_expr := field.expr
match 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) name = g.generic_fn_name(g.cur_concrete_types, name, true)
} }
if (g.pref.translated || g.file.is_translated) && node.attrs.contains('c') { if g.pref.translated || g.file.is_translated {
// This fixes unknown symbols errors when building separate .c => .v files if cattr := node.attrs.find_first('c') {
// into .o files // This fixes unknown symbols errors when building separate .c => .v files into .o files
// // example:
// example: // [c: 'P_TryMove'] fn p_trymove(thing &Mobj_t, x int, y int) bool
// [c: 'P_TryMove'] // translates to:
// fn p_trymove(thing &Mobj_t, x int, y int) bool // 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 = cattr.arg
// }
// 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
} }
return name 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. // every time `p_trymove` is called, `P_TryMove` must be generated instead.
if f := g.table.find_fn(node.name) { if f := g.table.find_fn(node.name) {
// TODO PERF fn lookup for each fn call in translated mode // TODO PERF fn lookup for each fn call in translated mode
if f.attrs.contains('c') { if cattr := f.attrs.find_first('c') {
name = f.attrs[0].arg name = cattr.arg
} }
} }
} }