mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
v: use -check-unused-fn-args
to cleanup the compiler code itself
This commit is contained in:
parent
647901d6ab
commit
791d0d30ea
@ -147,13 +147,13 @@ fn (mut p Process) win_is_alive() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
fn (mut p Process) win_write_string(idx int, s string) {
|
||||
fn (mut p Process) win_write_string(_idx int, _s string) {
|
||||
}
|
||||
|
||||
fn (mut p Process) win_read_string(idx int, maxbytes int) (string, int) {
|
||||
fn (mut p Process) win_read_string(_idx int, _maxbytes int) (string, int) {
|
||||
return '', 0
|
||||
}
|
||||
|
||||
fn (mut p Process) win_slurp(idx int) string {
|
||||
fn (mut p Process) win_slurp(_idx int) string {
|
||||
return ''
|
||||
}
|
||||
|
@ -197,11 +197,11 @@ fn (mut p Process) win_is_alive() bool {
|
||||
|
||||
///////////////
|
||||
|
||||
fn (mut p Process) win_write_string(idx int, s string) {
|
||||
fn (mut p Process) win_write_string(idx int, _s string) {
|
||||
panic('Process.write_string ${idx} is not implemented yet')
|
||||
}
|
||||
|
||||
fn (mut p Process) win_read_string(idx int, maxbytes int) (string, int) {
|
||||
fn (mut p Process) win_read_string(idx int, _maxbytes int) (string, int) {
|
||||
mut wdata := unsafe { &WProcess(p.wdata) }
|
||||
if unsafe { wdata == 0 } {
|
||||
return '', 0
|
||||
|
@ -21,7 +21,7 @@ pub fn signal_opt(signum Signal, handler SignalHandler) !SignalHandler {
|
||||
// So a global variable is introduced to make the distinction.
|
||||
|
||||
// An empty system signal handler (callback function) used to mask the specified system signal.
|
||||
fn ignore_signal_handler(signal Signal) {
|
||||
fn ignore_signal_handler(_signal Signal) {
|
||||
}
|
||||
|
||||
// signal_ignore to mask system signals, e.g.: signal_ignore(.pipe, .urg, ...)
|
||||
|
@ -14,5 +14,5 @@ pub fn is_main_thread() bool {
|
||||
}
|
||||
|
||||
// The windows platform does not need to be handled.
|
||||
fn signal_ignore_internal(args ...Signal) {
|
||||
fn signal_ignore_internal(_args ...Signal) {
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ mut:
|
||||
|
||||
pub type ThreadCB = fn (mut p PoolProcessor, idx int, task_id int) voidptr
|
||||
|
||||
fn empty_cb(mut p PoolProcessor, idx int, task_id int) voidptr {
|
||||
fn empty_cb(mut _p PoolProcessor, _idx int, _task_id int) voidptr {
|
||||
unsafe {
|
||||
return nil
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ pub const map_cname_escape_seq = ['[', '_T_', ', ', '_', ']', '']
|
||||
|
||||
pub type FnPanicHandler = fn (&Table, string)
|
||||
|
||||
fn default_table_panic_handler(t &Table, message string) {
|
||||
fn default_table_panic_handler(_t &Table, message string) {
|
||||
panic(message)
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ mut:
|
||||
pub type InspectorFn = fn (node &ast.Node, data voidptr) bool
|
||||
|
||||
fn empty_callback(node &ast.Node, data voidptr) bool {
|
||||
panic('empty ast.walker')
|
||||
panic('empty ast.walker, node: ${voidptr(node)}, data: ${voidptr(data)}')
|
||||
}
|
||||
|
||||
struct Inspector {
|
||||
|
@ -6,7 +6,7 @@ import v.util
|
||||
import v.builder
|
||||
import sync.pool
|
||||
|
||||
fn parallel_cc(mut b builder.Builder, header string, res string, out_str string, out_fn_start_pos []int) {
|
||||
fn parallel_cc(mut b builder.Builder, header string, _res string, out_str string, out_fn_start_pos []int) {
|
||||
c_files := util.nr_jobs
|
||||
println('> c_files: ${c_files} | util.nr_jobs: ${util.nr_jobs}')
|
||||
out_h := header.replace_once('static char * v_typeof_interface_IError', 'char * v_typeof_interface_IError')
|
||||
@ -67,7 +67,7 @@ fn parallel_cc(mut b builder.Builder, header string, res string, out_str string,
|
||||
eprint_time('link_cmd', link_cmd, link_res, sw_link)
|
||||
}
|
||||
|
||||
fn build_parallel_o_cb(mut p pool.PoolProcessor, idx int, wid int) voidptr {
|
||||
fn build_parallel_o_cb(mut p pool.PoolProcessor, idx int, _wid int) voidptr {
|
||||
postfix := p.get_item[string](idx)
|
||||
sw := time.new_stopwatch()
|
||||
cmd := '${os.quoted_path(cc_compiler)} ${cc_cflags} -c -w -o out_${postfix}.o out_${postfix}.c'
|
||||
|
@ -386,7 +386,7 @@ pub fn (mut v Builder) cc_msvc() {
|
||||
// println('C OUTPUT:')
|
||||
}
|
||||
|
||||
fn (mut v Builder) build_thirdparty_obj_file_with_msvc(mod string, path string, moduleflags []cflag.CFlag) {
|
||||
fn (mut v Builder) build_thirdparty_obj_file_with_msvc(_mod string, path string, moduleflags []cflag.CFlag) {
|
||||
msvc := v.cached_msvc
|
||||
if msvc.valid == false {
|
||||
verror('cannot find MSVC on this OS')
|
||||
|
@ -36,8 +36,7 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) ast.Type {
|
||||
}
|
||||
|
||||
info := table_sym.info as ast.Struct
|
||||
mut fields := c.fetch_and_check_orm_fields(info, node.table_expr.pos, table_sym.name,
|
||||
node)
|
||||
mut fields := c.fetch_and_check_orm_fields(info, node.table_expr.pos, table_sym.name)
|
||||
non_primitive_fields := c.get_orm_non_primitive_fields(fields)
|
||||
mut sub_structs := map[int]ast.SqlExpr{}
|
||||
|
||||
@ -269,8 +268,7 @@ fn (mut c Checker) sql_stmt_line(mut node ast.SqlStmtLine) ast.Type {
|
||||
}
|
||||
|
||||
info := table_sym.info as ast.Struct
|
||||
mut fields := c.fetch_and_check_orm_fields(info, node.table_expr.pos, table_sym.name,
|
||||
ast.SqlExpr{})
|
||||
mut fields := c.fetch_and_check_orm_fields(info, node.table_expr.pos, table_sym.name)
|
||||
|
||||
for field in fields {
|
||||
c.check_orm_struct_field_attrs(node, field)
|
||||
@ -397,7 +395,7 @@ fn (mut c Checker) check_orm_non_primitive_struct_field_attrs(field ast.StructFi
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut c Checker) fetch_and_check_orm_fields(info ast.Struct, pos token.Pos, table_name string, sql_expr ast.SqlExpr) []ast.StructField {
|
||||
fn (mut c Checker) fetch_and_check_orm_fields(info ast.Struct, pos token.Pos, table_name string) []ast.StructField {
|
||||
if cache := c.orm_table_fields[table_name] {
|
||||
return cache
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
|
||||
} else if elem_sym.kind == .array_fixed && expr is ast.CallExpr
|
||||
&& g.table.final_sym(expr.return_type).kind == .array_fixed {
|
||||
elem_info := elem_sym.array_fixed_info()
|
||||
tmp_var := g.expr_with_var(expr, node.expr_types[i], node.expr_types[i])
|
||||
tmp_var := g.expr_with_var(expr, node.expr_types[i])
|
||||
g.fixed_array_var_init(tmp_var, false, elem_info.elem_type, elem_info.size)
|
||||
} else {
|
||||
if expr.is_auto_deref_var() {
|
||||
|
@ -195,7 +195,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
|
||||
af = false
|
||||
}
|
||||
}
|
||||
g.gen_assign_vars_autofree(node)
|
||||
// TODO: g.gen_assign_vars_autofree(node)
|
||||
// json_test failed w/o this check
|
||||
if return_type != ast.void_type && return_type != 0 {
|
||||
sym := g.table.sym(return_type)
|
||||
@ -959,48 +959,6 @@ fn (mut g Gen) gen_multi_return_assign(node &ast.AssignStmt, return_type ast.Typ
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut g Gen) gen_assign_vars_autofree(node &ast.AssignStmt) {
|
||||
// Autofree tmp arg vars
|
||||
// first_right := node.right[0]
|
||||
// af := g.autofree && first_right is ast.CallExpr && !g.is_builtin_mod
|
||||
// if af {
|
||||
// g.autofree_call_pregen(first_right as ast.CallExpr)
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Handle options. We need to declare a temp variable for them, that's why they are handled
|
||||
// here, not in call_expr().
|
||||
// `pos := s.index('x') or { return }`
|
||||
// ==========>
|
||||
// Option_int _t190 = string_index(s, _STR("x")); // _STR() no more used!!
|
||||
// if (_t190.state != 2) {
|
||||
// Error err = _t190.err;
|
||||
// return;
|
||||
// }
|
||||
// int pos = *(int*)_t190.data;
|
||||
// mut tmp_opt := ''
|
||||
/*
|
||||
is_option := false && g.is_autofree && (node.op in [.decl_assign, .assign])
|
||||
&& node.left_types.len == 1 && node.right[0] is ast.CallExpr
|
||||
if is_option {
|
||||
// g.write('/* option assignment */')
|
||||
call_expr := node.right[0] as ast.CallExpr
|
||||
if call_expr.or_block.kind != .absent {
|
||||
styp := g.styp(call_expr.return_type.set_flag(.option))
|
||||
tmp_opt = g.new_tmp_var()
|
||||
g.write('/*AF opt*/$styp $tmp_opt = ')
|
||||
g.expr(node.right[0])
|
||||
g.or_block(tmp_opt, call_expr.or_block, call_expr.return_type)
|
||||
g.writeln('/*=============ret*/')
|
||||
// if af && is_option {
|
||||
// g.autofree_call_postgen()
|
||||
// }
|
||||
// return
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
fn (mut g Gen) gen_cross_var_assign(node &ast.AssignStmt) {
|
||||
for i, left in node.left {
|
||||
left_is_auto_deref_var := left.is_auto_deref_var()
|
||||
|
@ -68,7 +68,7 @@ fn (mut g Gen) gen_free_method(typ ast.Type) string {
|
||||
g.gen_free_for_array(sym.info, styp, fn_name)
|
||||
}
|
||||
ast.Map {
|
||||
g.gen_free_for_map(objtyp, sym.info, styp, fn_name)
|
||||
g.gen_free_for_map(objtyp, styp, fn_name)
|
||||
}
|
||||
ast.Interface {
|
||||
g.gen_free_for_interface(sym, sym.info, styp, fn_name)
|
||||
@ -200,7 +200,7 @@ fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
|
||||
fn_builder.writeln('}')
|
||||
}
|
||||
|
||||
fn (mut g Gen) gen_free_for_map(typ ast.Type, info ast.Map, styp string, fn_name string) {
|
||||
fn (mut g Gen) gen_free_for_map(typ ast.Type, styp string, fn_name string) {
|
||||
g.definitions.writeln('${g.static_modifier} void ${fn_name}(${styp}* it); // auto')
|
||||
mut fn_builder := strings.new_builder(128)
|
||||
defer {
|
||||
|
@ -2554,7 +2554,7 @@ fn (mut g Gen) call_cfn_for_casting_expr(fname string, expr ast.Expr, exp_is_ptr
|
||||
}
|
||||
|
||||
// use instead of expr() when you need a var to use as reference
|
||||
fn (mut g Gen) expr_with_var(expr ast.Expr, got_type_raw ast.Type, expected_type ast.Type) string {
|
||||
fn (mut g Gen) expr_with_var(expr ast.Expr, expected_type ast.Type) string {
|
||||
stmt_str := g.go_before_last_stmt().trim_space()
|
||||
g.empty_line = true
|
||||
tmp_var := g.new_tmp_var()
|
||||
@ -3201,8 +3201,7 @@ fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int
|
||||
// Do not free vars that were declared after this scope
|
||||
continue
|
||||
}
|
||||
is_option := obj.typ.has_flag(.option)
|
||||
g.autofree_variable(obj, is_option)
|
||||
g.autofree_variable(obj)
|
||||
}
|
||||
else {}
|
||||
}
|
||||
@ -3226,7 +3225,7 @@ fn (mut g Gen) autofree_scope_vars2(scope &ast.Scope, start_pos int, end_pos int
|
||||
}
|
||||
}
|
||||
|
||||
fn (mut g Gen) autofree_variable(v ast.Var, is_option bool) {
|
||||
fn (mut g Gen) autofree_variable(v ast.Var) {
|
||||
// filter out invalid variables
|
||||
if v.typ == 0 {
|
||||
return
|
||||
|
@ -1223,7 +1223,7 @@ fn (mut g Gen) gen_array_method_call(node ast.CallExpr, left_type ast.Type, left
|
||||
return true
|
||||
}
|
||||
|
||||
fn (mut g Gen) gen_fixed_array_method_call(node ast.CallExpr, left_type ast.Type, left_sym ast.TypeSymbol) bool {
|
||||
fn (mut g Gen) gen_fixed_array_method_call(node ast.CallExpr, left_type ast.Type) bool {
|
||||
match node.name {
|
||||
'index' {
|
||||
g.gen_array_index(node)
|
||||
@ -1773,7 +1773,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||
}
|
||||
if final_left_sym.kind == .array_fixed && !(left_sym.kind == .alias
|
||||
&& left_sym.has_method(node.name)) {
|
||||
if g.gen_fixed_array_method_call(node, left_type, final_left_sym) {
|
||||
if g.gen_fixed_array_method_call(node, left_type) {
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -2504,11 +2504,6 @@ fn (mut g Gen) autofree_call_postgen(node_pos int) {
|
||||
for _, mut obj in scope.objects {
|
||||
match mut obj {
|
||||
ast.Var {
|
||||
// if var.typ == 0 {
|
||||
// // TODO: why 0?
|
||||
// continue
|
||||
// }
|
||||
is_option := obj.typ.has_flag(.option)
|
||||
is_result := obj.typ.has_flag(.result)
|
||||
if is_result {
|
||||
// TODO: free results
|
||||
@ -2522,7 +2517,7 @@ fn (mut g Gen) autofree_call_postgen(node_pos int) {
|
||||
continue
|
||||
}
|
||||
obj.is_used = true // TODO: bug? sets all vars is_used to true
|
||||
g.autofree_variable(obj, is_option)
|
||||
g.autofree_variable(obj)
|
||||
// g.nr_vars_to_free--
|
||||
}
|
||||
else {}
|
||||
|
@ -688,13 +688,13 @@ fn (mut g Gen) struct_init_field(sfield ast.StructInitField, language ast.Langua
|
||||
field_unwrap_sym.info.elem_type, field_unwrap_sym.info.size)
|
||||
}
|
||||
ast.CallExpr {
|
||||
tmp_var := g.expr_with_var(sfield.expr, sfield.typ, sfield.expected_type)
|
||||
tmp_var := g.expr_with_var(sfield.expr, sfield.expected_type)
|
||||
g.fixed_array_var_init(tmp_var, false, field_unwrap_sym.info.elem_type,
|
||||
field_unwrap_sym.info.size)
|
||||
}
|
||||
ast.ArrayInit {
|
||||
if sfield.expr.has_index {
|
||||
tmp_var := g.expr_with_var(sfield.expr, sfield.typ, sfield.expected_type)
|
||||
tmp_var := g.expr_with_var(sfield.expr, sfield.expected_type)
|
||||
g.fixed_array_var_init(tmp_var, false, field_unwrap_sym.info.elem_type,
|
||||
field_unwrap_sym.info.size)
|
||||
} else if sfield.expr.has_callexpr {
|
||||
|
@ -115,7 +115,7 @@ fn (mut mcache ModFileCacher) traverse(mfolder string) ([]string, ModFileAndFold
|
||||
}
|
||||
return folders_so_far, res
|
||||
}
|
||||
if mcache.check_for_stop(cfolder, files) {
|
||||
if mcache.check_for_stop(files) {
|
||||
break
|
||||
}
|
||||
cfolder = os.dir(cfolder)
|
||||
@ -143,7 +143,7 @@ fn (mut mcache ModFileCacher) mark_folders_as_vmod_free(folders_so_far []string)
|
||||
}
|
||||
}
|
||||
|
||||
fn (mcache &ModFileCacher) check_for_stop(cfolder string, files []string) bool {
|
||||
fn (mcache &ModFileCacher) check_for_stop(files []string) bool {
|
||||
for i in mod_file_stop_paths {
|
||||
if i in files {
|
||||
return true
|
||||
|
Loading…
x
Reference in New Issue
Block a user