mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: remove hardcoded check for function calls for C.stat
, C.sigaction
, etc (#18535)
This commit is contained in:
parent
2c7643661e
commit
4c9c515f8b
@ -232,10 +232,10 @@ pub:
|
|||||||
|
|
||||||
type VectoredExceptionHandler = fn (&ExceptionPointers) int
|
type VectoredExceptionHandler = fn (&ExceptionPointers) int
|
||||||
|
|
||||||
fn C.AddVectoredExceptionHandler(int, C.PVECTORED_EXCEPTION_HANDLER)
|
fn C.AddVectoredExceptionHandler(int, voidptr)
|
||||||
|
|
||||||
fn add_vectored_exception_handler(handler VectoredExceptionHandler) {
|
fn add_vectored_exception_handler(handler VectoredExceptionHandler) {
|
||||||
C.AddVectoredExceptionHandler(1, C.PVECTORED_EXCEPTION_HANDLER(handler))
|
C.AddVectoredExceptionHandler(1, voidptr(handler))
|
||||||
}
|
}
|
||||||
|
|
||||||
[callconv: stdcall]
|
[callconv: stdcall]
|
||||||
|
@ -255,7 +255,7 @@ fn C.SendMessageTimeoutW(hWnd voidptr, msg u32, wParam &u16, lParam &u32, fuFlag
|
|||||||
|
|
||||||
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 C.LPDWORD, lpOverlapped voidptr) bool
|
fn C.ReadFile(hFile voidptr, lpBuffer voidptr, nNumberOfBytesToRead u32, lpNumberOfBytesRead &u32, lpOverlapped voidptr) bool
|
||||||
|
|
||||||
fn C.GetFileAttributesW(lpFileName &u8) u32
|
fn C.GetFileAttributesW(lpFileName &u8) u32
|
||||||
|
|
||||||
|
@ -558,7 +558,7 @@ pub fn get_raw_line() string {
|
|||||||
mut offset := 0
|
mut offset := 0
|
||||||
for {
|
for {
|
||||||
pos := buf + offset
|
pos := buf + offset
|
||||||
res := C.ReadFile(h_input, pos, 1, C.LPDWORD(&bytes_read), 0)
|
res := C.ReadFile(h_input, pos, 1, &u32(&bytes_read), 0)
|
||||||
if !res && offset == 0 {
|
if !res && offset == 0 {
|
||||||
return tos(buf, 0)
|
return tos(buf, 0)
|
||||||
}
|
}
|
||||||
@ -600,7 +600,7 @@ pub fn get_raw_stdin() []u8 {
|
|||||||
mut offset := 0
|
mut offset := 0
|
||||||
for {
|
for {
|
||||||
pos := buf + offset
|
pos := buf + offset
|
||||||
res := C.ReadFile(h_input, pos, block_bytes, C.LPDWORD(&bytes_read), 0)
|
res := C.ReadFile(h_input, pos, block_bytes, &u32(&bytes_read), 0)
|
||||||
offset += bytes_read
|
offset += bytes_read
|
||||||
if !res {
|
if !res {
|
||||||
break
|
break
|
||||||
|
@ -449,7 +449,7 @@ pub type VectoredExceptionHandler = fn (&ExceptionPointers) u32
|
|||||||
// duplicate definitions from displeasing the compiler
|
// duplicate definitions from displeasing the compiler
|
||||||
// fn C.AddVectoredExceptionHandler(u32, VectoredExceptionHandler)
|
// fn C.AddVectoredExceptionHandler(u32, VectoredExceptionHandler)
|
||||||
pub fn add_vectored_exception_handler(first bool, handler VectoredExceptionHandler) {
|
pub fn add_vectored_exception_handler(first bool, handler VectoredExceptionHandler) {
|
||||||
C.AddVectoredExceptionHandler(u32(first), C.PVECTORED_EXCEPTION_HANDLER(handler))
|
C.AddVectoredExceptionHandler(u32(first), voidptr(handler))
|
||||||
}
|
}
|
||||||
|
|
||||||
// uname returns information about the platform on which the program is running.
|
// uname returns information about the platform on which the program is running.
|
||||||
|
@ -18,7 +18,7 @@ fn C.time(t &C.time_t) C.time_t
|
|||||||
|
|
||||||
fn C.gmtime(t &C.time_t) &C.tm
|
fn C.gmtime(t &C.time_t) &C.tm
|
||||||
fn C.gmtime_r(t &C.time_t, res &C.tm) &C.tm
|
fn C.gmtime_r(t &C.time_t, res &C.tm) &C.tm
|
||||||
fn C.strftime(buf &C.char, maxsize C.size_t, fmt &C.char, tm &C.tm) C.size_t
|
fn C.strftime(buf &char, maxsize usize, const_format &char, const_tm &C.tm) usize
|
||||||
|
|
||||||
// now returns current local time.
|
// now returns current local time.
|
||||||
pub fn now() Time {
|
pub fn now() Time {
|
||||||
@ -129,8 +129,8 @@ pub fn (t Time) strftime(fmt string) string {
|
|||||||
} $else {
|
} $else {
|
||||||
C.gmtime_r(voidptr(&t.unix), tm)
|
C.gmtime_r(voidptr(&t.unix), tm)
|
||||||
}
|
}
|
||||||
mut buf := [1024]C.char{}
|
mut buf := [1024]char{}
|
||||||
fmt_c := unsafe { &C.char(fmt.str) }
|
fmt_c := unsafe { &char(fmt.str) }
|
||||||
C.strftime(&buf[0], C.size_t(sizeof(buf)), fmt_c, tm)
|
C.strftime(&buf[0], usize(sizeof(buf)), fmt_c, tm)
|
||||||
return unsafe { cstring_to_vstring(&char(&buf[0])) }
|
return unsafe { cstring_to_vstring(&char(&buf[0])) }
|
||||||
}
|
}
|
||||||
|
@ -2605,27 +2605,34 @@ fn (mut p Parser) name_expr() ast.Expr {
|
|||||||
&& p.peek_token(2).kind == .rsbr && (p.peek_token(4).kind == .lpar
|
&& p.peek_token(2).kind == .rsbr && (p.peek_token(4).kind == .lpar
|
||||||
|| p.peek_token(6).kind == .lpar)) {
|
|| p.peek_token(6).kind == .lpar)) {
|
||||||
// ?[]foo(), ?[1]foo, foo(), foo<int>() or type() cast
|
// ?[]foo(), ?[1]foo, foo(), foo<int>() or type() cast
|
||||||
mut name := if is_array {
|
mut original_name := if is_array {
|
||||||
p.peek_token(if is_fixed_array { 3 } else { 2 }).lit
|
p.peek_token(if is_fixed_array { 3 } else { 2 }).lit
|
||||||
} else {
|
} else {
|
||||||
p.tok.lit
|
p.tok.lit
|
||||||
}
|
}
|
||||||
if is_fixed_array && p.peek_token(4).kind == .dot {
|
if is_fixed_array && p.peek_token(4).kind == .dot {
|
||||||
mod = name
|
mod = original_name
|
||||||
name = p.peek_token(5).lit
|
original_name = p.peek_token(5).lit
|
||||||
} else if is_array && p.peek_token(3).kind == .dot {
|
} else if is_array && p.peek_token(3).kind == .dot {
|
||||||
mod = name
|
mod = original_name
|
||||||
name = p.peek_token(4).lit
|
original_name = p.peek_token(4).lit
|
||||||
}
|
}
|
||||||
|
mut name := original_name
|
||||||
if mod.len > 0 {
|
if mod.len > 0 {
|
||||||
name = '${mod}.${name}'
|
name = '${mod}.${name}'
|
||||||
}
|
}
|
||||||
name_w_mod := p.prepend_mod(name)
|
name_w_mod := p.prepend_mod(name)
|
||||||
|
is_c_pointer_cast := language == .c && prev_tok_kind == .amp // `&C.abc(x)` is *always* a cast
|
||||||
|
is_c_type_cast := language == .c && (original_name in ['intptr_t', 'uintptr_t']
|
||||||
|
|| (name in p.table.type_idxs && original_name[0].is_capital()))
|
||||||
|
is_js_cast := language == .js && name.all_after_last('.')[0].is_capital()
|
||||||
// type cast. TODO: finish
|
// type cast. TODO: finish
|
||||||
// if name in ast.builtin_type_names_to_idx {
|
// if name in ast.builtin_type_names_to_idx {
|
||||||
if (!known_var && (name in p.table.type_idxs || name_w_mod in p.table.type_idxs)
|
// handle the easy cases first, then check for an already known V typename, not shadowed by a local variable
|
||||||
&& name !in ['C.statvfs', 'C.stat', 'C.sigaction']) || is_mod_cast
|
if is_mod_cast || is_c_pointer_cast || is_c_type_cast || is_js_cast
|
||||||
|| is_generic_cast || (language == .v && name.len > 0 && (name[0].is_capital()
|
|| is_generic_cast || (language == .v && name.len > 0 && (name[0].is_capital()
|
||||||
|
|| (!known_var && (name in p.table.type_idxs
|
||||||
|
|| name_w_mod in p.table.type_idxs))
|
||||||
|| name.all_after_last('.')[0].is_capital())) {
|
|| name.all_after_last('.')[0].is_capital())) {
|
||||||
// MainLetter(x) is *always* a cast, as long as it is not `C.`
|
// MainLetter(x) is *always* a cast, as long as it is not `C.`
|
||||||
// TODO handle C.stat()
|
// TODO handle C.stat()
|
||||||
|
Loading…
Reference in New Issue
Block a user