checker, cgen: c2v fixes

pull/12486/head
Alexander Medvednikov 2021-11-16 20:56:24 +03:00
parent 2984751a57
commit 49a36515dc
2 changed files with 35 additions and 0 deletions

View File

@ -2902,6 +2902,15 @@ pub fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool)
if param_is_number && typ_is_number {
continue
}
// Allow voidptrs for everything
if param.typ == ast.voidptr_type_idx || typ == ast.voidptr_type_idx {
continue
}
// Allow `[32]i8` as `&i8` etc
if (typ_sym.kind == .array_fixed && param_is_number)
|| (param_typ_sym.kind == .array_fixed && typ_is_number) {
continue
}
}
c.error('$err.msg in argument ${i + 1} to `$fn_name`', call_arg.pos)
}

View File

@ -219,6 +219,22 @@ fn (mut g Gen) gen_fn_decl(node &ast.FnDecl, skip bool) {
name = g.generic_fn_name(g.cur_concrete_types, name, true)
if g.pref.translated && node.attrs.contains('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
//
// =>
//
// 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
}
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') && !node.is_main
&& node.name != 'str' {
mut key := node.name
@ -1097,6 +1113,16 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
} else {
name = c_name(name)
}
if g.pref.translated {
// For `[c: 'P_TryMove'] fn p_trymove( ... `
// 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
}
}
}
// Obfuscate only functions in the main module for now
if g.pref.obfuscate && g.cur_mod.name == 'main' && name.starts_with('main__') {
key := node.name