Skip to content

Commit

Permalink
fmt: implement wrapping function's super long arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Jul 1, 2024
1 parent 387a01f commit ef53234
Show file tree
Hide file tree
Showing 35 changed files with 492 additions and 63 deletions.
3 changes: 2 additions & 1 deletion cmd/tools/check_os_api_parity.v
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ fn gen_api_for_module_in_os(mod_name string, os_ pref.OS) string {
if s is ast.FnDecl && s.is_pub {
fn_mod := s.modname()
if fn_mod == mod_name {
fn_signature := b.table.stringify_fn_decl(&s, mod_name, map[string]string{})
fn_signature := b.table.stringify_fn_decl(&s, mod_name, map[string]string{},
false)
fline := '${fn_mod}: ${fn_signature}'
res << fline
}
Expand Down
46 changes: 41 additions & 5 deletions vlib/builtin/cfns.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,25 @@ fn C.GetModuleFileName(hModule voidptr, lpFilename &u16, nSize u32) u32

fn C.GetModuleFileNameW(hModule voidptr, lpFilename &u16, nSize u32) u32

fn C.CreateFile(lpFilename &u16, dwDesiredAccess u32, dwShareMode u32, lpSecurityAttributes &u16, dwCreationDisposition u32, dwFlagsAndAttributes u32, hTemplateFile voidptr) voidptr

fn C.CreateFileW(lpFilename &u16, dwDesiredAccess u32, dwShareMode u32, lpSecurityAttributes &u16, dwCreationDisposition u32, dwFlagsAndAttributes u32, hTemplateFile voidptr) voidptr
fn C.CreateFile(
lpFilename &u16,
dwDesiredAccess u32,
dwShareMode u32,
lpSecurityAttributes &u16,
dwCreationDisposition u32,
dwFlagsAndAttributes u32,
hTemplateFile voidptr
) voidptr

fn C.CreateFileW(
lpFilename &u16,
dwDesiredAccess u32,
dwShareMode u32,
lpSecurityAttributes &u16,
dwCreationDisposition u32,
dwFlagsAndAttributes u32,
hTemplateFile voidptr
) voidptr

fn C.GetFinalPathNameByHandleW(hFile voidptr, lpFilePath &u16, nSize u32, dwFlags u32) u32

Expand All @@ -258,7 +274,18 @@ fn C.SendMessageTimeout() isize

fn C.SendMessageTimeoutW(hWnd voidptr, msg u32, wParam &u16, lParam &u32, fuFlags u32, uTimeout u32, lpdwResult &u64) isize

fn C.CreateProcessW(lpApplicationName &u16, lpCommandLine &u16, lpProcessAttributes voidptr, lpThreadAttributes voidptr, bInheritHandles bool, dwCreationFlags u32, lpEnvironment voidptr, lpCurrentDirectory &u16, lpStartupInfo voidptr, lpProcessInformation voidptr) bool
fn C.CreateProcessW(
lpApplicationName &u16,
lpCommandLine &u16,
lpProcessAttributes voidptr,
lpThreadAttributes voidptr,
bInheritHandles bool,
dwCreationFlags u32,
lpEnvironment voidptr,
lpCurrentDirectory &u16,
lpStartupInfo voidptr,
lpProcessInformation voidptr
) bool

fn C.ReadFile(hFile voidptr, lpBuffer voidptr, nNumberOfBytesToRead u32, lpNumberOfBytesRead &u32, lpOverlapped voidptr) bool

Expand Down Expand Up @@ -302,7 +329,16 @@ fn C.MultiByteToWideChar(codePage u32, dwFlags u32, lpMultiMyteStr &char, cbMult

fn C.wcslen(str voidptr) usize

fn C.WideCharToMultiByte(codePage u32, dwFlags u32, lpWideCharStr &u16, cchWideChar int, lpMultiByteStr &char, cbMultiByte int, lpDefaultChar &char, lpUsedDefaultChar &int) int
fn C.WideCharToMultiByte(
codePage u32,
dwFlags u32,
lpWideCharStr &u16,
cchWideChar int,
lpMultiByteStr &char,
cbMultiByte int,
lpDefaultChar &char,
lpUsedDefaultChar &int
) int

fn C._wstat(path &u16, buffer &C._stat) int

Expand Down
12 changes: 11 additions & 1 deletion vlib/builtin/map.v
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,17 @@ fn new_map(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqFn,
}
}

fn new_map_init(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn, n int, key_bytes int, value_bytes int, keys voidptr, values voidptr) map {
fn new_map_init(
hash_fn MapHashFn,
key_eq_fn MapEqFn,
clone_fn MapCloneFn,
free_fn MapFreeFn,
n int,
key_bytes int,
value_bytes int,
keys voidptr,
values voidptr
) map {
mut out := new_map(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn)
// TODO: pre-allocate n slots
mut pkey := &u8(keys)
Expand Down
45 changes: 41 additions & 4 deletions vlib/builtin/map_d_gcboehm_opt.v
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ fn new_map_noscan_value(key_bytes int, value_bytes int, hash_fn MapHashFn, key_e
}
}

fn new_map_noscan_key_value(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn) map {
fn new_map_noscan_key_value(
key_bytes int,
value_bytes int,
hash_fn MapHashFn,
key_eq_fn MapEqFn,
clone_fn MapCloneFn,
free_fn MapFreeFn
) map {
metasize := int(sizeof(u32) * (init_capicity + extra_metas_inc))
// for now assume anything bigger than a pointer is a string
has_string_keys := key_bytes > sizeof(voidptr)
Expand All @@ -95,7 +102,17 @@ fn new_map_noscan_key_value(key_bytes int, value_bytes int, hash_fn MapHashFn, k
}
}

fn new_map_init_noscan_key(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn, n int, key_bytes int, value_bytes int, keys voidptr, values voidptr) map {
fn new_map_init_noscan_key(
hash_fn MapHashFn,
key_eq_fn MapEqFn,
clone_fn MapCloneFn,
free_fn MapFreeFn,
n int,
key_bytes int,
value_bytes int,
keys voidptr,
values voidptr
) map {
mut out := new_map_noscan_key(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn,
free_fn)
// TODO: pre-allocate n slots
Expand All @@ -111,7 +128,17 @@ fn new_map_init_noscan_key(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapClo
return out
}

fn new_map_init_noscan_value(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn, n int, key_bytes int, value_bytes int, keys voidptr, values voidptr) map {
fn new_map_init_noscan_value(
hash_fn MapHashFn,
key_eq_fn MapEqFn,
clone_fn MapCloneFn,
free_fn MapFreeFn,
n int,
key_bytes int,
value_bytes int,
keys voidptr,
values voidptr
) map {
mut out := new_map_noscan_value(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn,
free_fn)
// TODO: pre-allocate n slots
Expand All @@ -127,7 +154,17 @@ fn new_map_init_noscan_value(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapC
return out
}

fn new_map_init_noscan_key_value(hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn, n int, key_bytes int, value_bytes int, keys voidptr, values voidptr) map {
fn new_map_init_noscan_key_value(
hash_fn MapHashFn,
key_eq_fn MapEqFn,
clone_fn MapCloneFn,
free_fn MapFreeFn,
n int,
key_bytes int,
value_bytes int,
keys voidptr,
values voidptr
) map {
mut out := new_map_noscan_key_value(key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn,
free_fn)
// TODO: pre-allocate n slots
Expand Down
22 changes: 20 additions & 2 deletions vlib/builtin/string_interpolation.v
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,16 @@ fn abs64(x i64) u64 {
//---------------------------------------

// convert from data format to compact u64
pub fn get_str_intp_u64_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch u8, in_base int, in_upper_case bool) u64 {
pub fn get_str_intp_u64_format(
fmt_type StrIntpType,
in_width int,
in_precision int,
in_tail_zeros bool,
in_sign bool,
in_pad_ch u8,
in_base int,
in_upper_case bool
) u64 {
width := if in_width != 0 { abs64(in_width) } else { u64(0) }
align := if in_width > 0 { u64(1 << 5) } else { u64(0) } // two bit 0 .left 1 .right, for now we use only one
upper_case := if in_upper_case { u64(1 << 7) } else { u64(0) }
Expand All @@ -134,7 +143,16 @@ pub fn get_str_intp_u64_format(fmt_type StrIntpType, in_width int, in_precision
}

// convert from data format to compact u32
pub fn get_str_intp_u32_format(fmt_type StrIntpType, in_width int, in_precision int, in_tail_zeros bool, in_sign bool, in_pad_ch u8, in_base int, in_upper_case bool) u32 {
pub fn get_str_intp_u32_format(
fmt_type StrIntpType,
in_width int,
in_precision int,
in_tail_zeros bool,
in_sign bool,
in_pad_ch u8,
in_base int,
in_upper_case bool
) u32 {
width := if in_width != 0 { abs64(in_width) } else { u32(0) }
align := if in_width > 0 { u32(1 << 5) } else { u32(0) } // two bit 0 .left 1 .right, for now we use only one
upper_case := if in_upper_case { u32(1 << 7) } else { u32(0) }
Expand Down
15 changes: 14 additions & 1 deletion vlib/clipboard/clipboard_windows.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,20 @@ fn C.RegisterClassEx(class &WndClassEx) int

fn C.GetClipboardOwner() C.HWND

fn C.CreateWindowEx(dwExStyle i64, lpClassName &u16, lpWindowName &u16, dwStyle i64, x int, y int, nWidth int, nHeight int, hWndParent i64, hMenu voidptr, h_instance voidptr, lpParam voidptr) C.HWND
fn C.CreateWindowEx(
dwExStyle i64,
lpClassName &u16,
lpWindowName &u16,
dwStyle i64,
x int,
y int,
nWidth int,
nHeight int,
hWndParent i64,
hMenu voidptr,
h_instance voidptr,
lpParam voidptr
) C.HWND

// fn C.MultiByteToWideChar(CodePage u32, dw_flags u16, lpMultiByteStr byteptr, cbMultiByte int, lpWideCharStr u16, cchWideChar int) int
fn C.EmptyClipboard()
Expand Down
27 changes: 25 additions & 2 deletions vlib/clipboard/x11/clipboard.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,38 @@ fn C.XSendEvent(d &C.Display, requestor Window, propagate int, mask i64, event &

fn C.XInternAtom(d &C.Display, typ &u8, only_if_exists int) Atom

fn C.XCreateSimpleWindow(d &C.Display, root Window, x int, y int, width u32, height u32, border_width u32, border u64, background u64) Window
fn C.XCreateSimpleWindow(
d &C.Display,
root Window,
x int,
y int,
width u32,
height u32,
border_width u32,
border u64,
background u64
) Window

fn C.XOpenDisplay(name &u8) &C.Display

fn C.XConvertSelection(d &C.Display, selection Atom, target Atom, property Atom, requestor Window, time int) int

fn C.XSync(d &C.Display, discard int) int

fn C.XGetWindowProperty(d &C.Display, w Window, property Atom, offset i64, length i64, delete int, req_type Atom, actual_type_return &Atom, actual_format_return &int, nitems &u64, bytes_after_return &u64, prop_return &&u8) int
fn C.XGetWindowProperty(
d &C.Display,
w Window,
property Atom,
offset i64,
length i64,
delete int,
req_type Atom,
actual_type_return &Atom,
actual_format_return &int,
nitems &u64,
bytes_after_return &u64,
prop_return &&u8
) int

fn C.XDeleteProperty(d &C.Display, w Window, property Atom) int

Expand Down
41 changes: 37 additions & 4 deletions vlib/db/mssql/_cdefs.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,57 @@ fn C.SQLAllocHandle(handle_type C.SQLSMALLINT, input_handle C.SQLHANDLE, output_

fn C.SQLSetEnvAttr(environment_handle C.SQLHENV, attribute C.SQLINTEGER, value C.SQLPOINTER, string_length C.SQLINTEGER) C.SQLRETURN

fn C.SQLGetDiagRec(handle_type C.SQLSMALLINT, handle C.SQLHANDLE, rec_number C.SQLSMALLINT, sql_state &C.SQLCHAR, native_error &C.SQLINTEGER, message_text &C.SQLCHAR, buffer_length C.SQLSMALLINT, text_length &C.SQLSMALLINT) C.SQLRETURN
fn C.SQLGetDiagRec(
handle_type C.SQLSMALLINT,
handle C.SQLHANDLE,
rec_number C.SQLSMALLINT,
sql_state &C.SQLCHAR,
native_error &C.SQLINTEGER,
message_text &C.SQLCHAR,
buffer_length C.SQLSMALLINT,
text_length &C.SQLSMALLINT
) C.SQLRETURN

fn C.SQLSetConnectAttr(connection_handle C.SQLHDBC, attribute C.SQLINTEGER, value C.SQLPOINTER, string_length C.SQLINTEGER) C.SQLRETURN

fn C.SQLDriverConnect(hdbc C.SQLHDBC, hwnd C.SQLHWND, sz_conn_str_in &C.SQLCHAR, cb_conn_str_in C.SQLSMALLINT, sz_conn_str_out &C.SQLCHAR, cb_conn_str_out_max C.SQLSMALLINT, pcb_conn_str_out &C.SQLSMALLINT, f_driver_completion C.SQLUSMALLINT) C.SQLRETURN
fn C.SQLDriverConnect(
hdbc C.SQLHDBC,
hwnd C.SQLHWND,
sz_conn_str_in &C.SQLCHAR,
cb_conn_str_in C.SQLSMALLINT,
sz_conn_str_out &C.SQLCHAR,
cb_conn_str_out_max C.SQLSMALLINT,
pcb_conn_str_out &C.SQLSMALLINT,
f_driver_completion C.SQLUSMALLINT
) C.SQLRETURN

fn C.SQLDisconnect(connection_handle C.SQLHDBC) C.SQLRETURN

fn C.SQLExecDirect(statement_handle C.SQLHSTMT, statement_text &C.SQLCHAR, text_length C.SQLINTEGER) C.SQLRETURN

fn C.SQLBindCol(statement_handle C.SQLHSTMT, column_number C.SQLUSMALLINT, target_type C.SQLSMALLINT, target_value C.SQLPOINTER, buffer_length C.SQLLEN, str_len_or_ind &C.SQLLEN) C.SQLRETURN
fn C.SQLBindCol(
statement_handle C.SQLHSTMT,
column_number C.SQLUSMALLINT,
target_type C.SQLSMALLINT,
target_value C.SQLPOINTER,
buffer_length C.SQLLEN,
str_len_or_ind &C.SQLLEN
) C.SQLRETURN

fn C.SQLFetch(statement_handle C.SQLHSTMT) C.SQLRETURN

fn C.SQLFreeHandle(handle_type C.SQLSMALLINT, handle C.SQLHANDLE) C.SQLRETURN

fn C.SQLNumResultCols(statement_handle C.SQLHSTMT, column_count &C.SQLSMALLINT) C.SQLRETURN

fn C.SQLColAttribute(statement_handle C.SQLHSTMT, column_number C.SQLUSMALLINT, field_identifier C.SQLUSMALLINT, character_attribute C.SQLPOINTER, buffer_length C.SQLSMALLINT, string_length C.SQLSMALLINT, numeric_attribute &C.SQLLEN) C.SQLRETURN
fn C.SQLColAttribute(
statement_handle C.SQLHSTMT,
column_number C.SQLUSMALLINT,
field_identifier C.SQLUSMALLINT,
character_attribute C.SQLPOINTER,
buffer_length C.SQLSMALLINT,
string_length C.SQLSMALLINT,
numeric_attribute &C.SQLLEN
) C.SQLRETURN

fn C.SQLRowCount(statement_handle C.SQLHSTMT, row_count &C.SQLLEN) C.SQLRETURN
11 changes: 10 additions & 1 deletion vlib/db/mysql/_cdefs.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ pub struct C.MYSQL_FIELD {
fn C.mysql_init(mysql &C.MYSQL) &C.MYSQL

// C.mysql_real_connect attempts to establish a connection to a MySQL server running on `host`.
fn C.mysql_real_connect(mysql &C.MYSQL, host &char, user &char, passwd &char, db &char, port u32, unix_socket &char, client_flag ConnectionFlag) &C.MYSQL
fn C.mysql_real_connect(
mysql &C.MYSQL,
host &char,
user &char,
passwd &char,
db &char,
port u32,
unix_socket &char,
client_flag ConnectionFlag
) &C.MYSQL

// C.mysql_query executes the SQL statement pointed to by the null-terminated string `stmt_str`.
fn C.mysql_query(mysql &C.MYSQL, q &u8) int
Expand Down
11 changes: 10 additions & 1 deletion vlib/db/pg/pg.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,16 @@ fn C.PQnfields(const_res &C.PGresult) int
// const char *const *paramValues
// const int *paramLengths
// const int *paramFormats
fn C.PQexecParams(conn &C.PGconn, const_command &char, nParams int, const_paramTypes &int, const_paramValues &char, const_paramLengths &int, const_paramFormats &int, resultFormat int) &C.PGresult
fn C.PQexecParams(
conn &C.PGconn,
const_command &char,
nParams int,
const_paramTypes &int,
const_paramValues &char,
const_paramLengths &int,
const_paramFormats &int,
resultFormat int
) &C.PGresult

fn C.PQputCopyData(conn &C.PGconn, const_buffer &char, nbytes int) int

Expand Down
8 changes: 7 additions & 1 deletion vlib/db/sqlite/sqlite_vfs_lowlevel_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,13 @@ fn example_vfs_access(vfs &sqlite.Sqlite3_vfs, zPath &char, flags int, pResOut &
return sqlite.sqlite_ok
}

fn example_vfs_open(vfs &sqlite.Sqlite3_vfs, file_name_or_null_for_tempfile &char, vfs_opened_file &sqlite.Sqlite3_file, in_flags int, out_flags &int) int {
fn example_vfs_open(
vfs &sqlite.Sqlite3_vfs,
file_name_or_null_for_tempfile &char,
vfs_opened_file &sqlite.Sqlite3_file,
in_flags int,
out_flags &int
) int {
println('open called')

mut is_temp := false
Expand Down
Loading

0 comments on commit ef53234

Please sign in to comment.