mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker,gen: remove automatic string to C string conversion (#10144)
This commit is contained in:
parent
afc81277be
commit
44d0305ca9
@ -411,9 +411,6 @@ pub const (
|
|||||||
error_type = new_type(error_type_idx)
|
error_type = new_type(error_type_idx)
|
||||||
charptr_types = [charptr_type, new_type(char_type_idx).set_nr_muls(1)]
|
charptr_types = [charptr_type, new_type(char_type_idx).set_nr_muls(1)]
|
||||||
byteptr_types = [byteptr_type, new_type(byte_type_idx).set_nr_muls(1)]
|
byteptr_types = [byteptr_type, new_type(byte_type_idx).set_nr_muls(1)]
|
||||||
cptr_or_bptr_types = [charptr_type, byteptr_type, new_type(char_type_idx).set_nr_muls(1),
|
|
||||||
new_type(byte_type_idx).set_nr_muls(1),
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
pub const (
|
pub const (
|
||||||
|
@ -34,12 +34,6 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
|
|||||||
&& got.idx() in [ast.int_type_idx, ast.int_literal_type_idx]) {
|
&& got.idx() in [ast.int_type_idx, ast.int_literal_type_idx]) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// allow `C.printf('foo')` instead of `C.printf(c'foo')`
|
|
||||||
if got.idx() == ast.string_type_idx
|
|
||||||
&& (expected in [ast.byteptr_type_idx, ast.charptr_type_idx]
|
|
||||||
|| (expected.idx() == ast.char_type_idx && expected.is_ptr())) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
exp_sym := c.table.get_type_symbol(expected)
|
exp_sym := c.table.get_type_symbol(expected)
|
||||||
// unknown C types are set to int, allow int to be used for types like `&C.FILE`
|
// unknown C types are set to int, allow int to be used for types like `&C.FILE`
|
||||||
// eg. `C.fflush(C.stderr)` - error: cannot use `int` as `&C.FILE` in argument 1 to `C.fflush`
|
// eg. `C.fflush(C.stderr)` - error: cannot use `int` as `&C.FILE` in argument 1 to `C.fflush`
|
||||||
@ -47,7 +41,6 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
|
|||||||
&& got == ast.int_type_idx {
|
&& got == ast.int_type_idx {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// return
|
|
||||||
}
|
}
|
||||||
if c.check_types(got, expected) {
|
if c.check_types(got, expected) {
|
||||||
return
|
return
|
||||||
|
@ -76,7 +76,6 @@ pub mut:
|
|||||||
inside_anon_fn bool
|
inside_anon_fn bool
|
||||||
inside_ref_lit bool
|
inside_ref_lit bool
|
||||||
inside_fn_arg bool // `a`, `b` in `a.f(b)`
|
inside_fn_arg bool // `a`, `b` in `a.f(b)`
|
||||||
inside_c_call bool // true inside C.printf( param ) calls, but NOT in nested calls, unless they are also C.
|
|
||||||
inside_ct_attr bool // true inside [if expr]
|
inside_ct_attr bool // true inside [if expr]
|
||||||
skip_flags bool // should `#flag` and `#include` be skipped
|
skip_flags bool // should `#flag` and `#include` be skipped
|
||||||
mut:
|
mut:
|
||||||
@ -1738,11 +1737,6 @@ fn (mut c Checker) check_map_and_filter(is_map bool, elem_typ ast.Type, call_exp
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut c Checker) method_call(mut call_expr ast.CallExpr) ast.Type {
|
pub fn (mut c Checker) method_call(mut call_expr ast.CallExpr) ast.Type {
|
||||||
was_inside_c_call := c.inside_c_call
|
|
||||||
c.inside_c_call = call_expr.language == .c
|
|
||||||
defer {
|
|
||||||
c.inside_c_call = was_inside_c_call
|
|
||||||
}
|
|
||||||
left_type := c.expr(call_expr.left)
|
left_type := c.expr(call_expr.left)
|
||||||
c.expected_type = left_type
|
c.expected_type = left_type
|
||||||
mut is_generic := left_type.has_flag(.generic)
|
mut is_generic := left_type.has_flag(.generic)
|
||||||
@ -2228,11 +2222,6 @@ fn (mut c Checker) array_builtin_method_call(mut call_expr ast.CallExpr, left_ty
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
|
pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
|
||||||
was_inside_c_call := c.inside_c_call
|
|
||||||
c.inside_c_call = call_expr.language == .c
|
|
||||||
defer {
|
|
||||||
c.inside_c_call = was_inside_c_call
|
|
||||||
}
|
|
||||||
fn_name := call_expr.name
|
fn_name := call_expr.name
|
||||||
if fn_name == 'main' {
|
if fn_name == 'main' {
|
||||||
c.error('the `main` function cannot be called in the program', call_expr.pos)
|
c.error('the `main` function cannot be called in the program', call_expr.pos)
|
||||||
@ -2567,10 +2556,6 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
|
|||||||
c.warn('automatic referencing/dereferencing is deprecated and will be removed soon (got: $typ.nr_muls() references, expected: $param.typ.nr_muls() references)',
|
c.warn('automatic referencing/dereferencing is deprecated and will be removed soon (got: $typ.nr_muls() references, expected: $param.typ.nr_muls() references)',
|
||||||
call_arg.pos)
|
call_arg.pos)
|
||||||
}
|
}
|
||||||
if func.language == .c && typ == ast.string_type && param.typ in ast.cptr_or_bptr_types {
|
|
||||||
c.warn("automatic string to C-string conversion is deprecated and will be removed on 2021-06-19, use `c'<string_value>'` and set the C function parameter type to `&u8`",
|
|
||||||
call_arg.pos)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if func.generic_names.len != call_expr.concrete_types.len {
|
if func.generic_names.len != call_expr.concrete_types.len {
|
||||||
// no type arguments given in call, attempt implicit instantiation
|
// no type arguments given in call, attempt implicit instantiation
|
||||||
|
@ -69,7 +69,6 @@ mut:
|
|||||||
last_fn_c_name string
|
last_fn_c_name string
|
||||||
tmp_count int // counter for unique tmp vars (_tmp1, tmp2 etc)
|
tmp_count int // counter for unique tmp vars (_tmp1, tmp2 etc)
|
||||||
tmp_count2 int // a separate tmp var counter for autofree fn calls
|
tmp_count2 int // a separate tmp var counter for autofree fn calls
|
||||||
is_c_call bool // e.g. `C.printf("v")`
|
|
||||||
is_assign_lhs bool // inside left part of assign expr (for array_set(), etc)
|
is_assign_lhs bool // inside left part of assign expr (for array_set(), etc)
|
||||||
discard_or_result bool // do not safe last ExprStmt of `or` block in tmp variable to defer ongoing expr usage
|
discard_or_result bool // do not safe last ExprStmt of `or` block in tmp variable to defer ongoing expr usage
|
||||||
is_void_expr_stmt bool // ExprStmt whos result is discarded
|
is_void_expr_stmt bool // ExprStmt whos result is discarded
|
||||||
|
@ -872,7 +872,6 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
|||||||
if node.language == .c {
|
if node.language == .c {
|
||||||
// Skip "C."
|
// Skip "C."
|
||||||
name = util.no_dots(name[2..])
|
name = util.no_dots(name[2..])
|
||||||
g.is_c_call = true
|
|
||||||
} else {
|
} else {
|
||||||
name = c_name(name)
|
name = c_name(name)
|
||||||
}
|
}
|
||||||
@ -968,7 +967,6 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g.is_c_call = false
|
|
||||||
g.is_json_fn = false
|
g.is_json_fn = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,15 +6,8 @@ import v.ast
|
|||||||
import v.util
|
import v.util
|
||||||
|
|
||||||
fn (mut g Gen) string_literal(node ast.StringLiteral) {
|
fn (mut g Gen) string_literal(node ast.StringLiteral) {
|
||||||
if node.is_raw {
|
escaped_val := util.smart_quote(node.val, node.is_raw)
|
||||||
escaped_val := util.smart_quote(node.val, true)
|
if node.language == .c {
|
||||||
g.write('_SLIT("$escaped_val")')
|
|
||||||
return
|
|
||||||
}
|
|
||||||
escaped_val := util.smart_quote(node.val, false)
|
|
||||||
if g.is_c_call || node.language == .c {
|
|
||||||
// In C calls we have to generate C strings
|
|
||||||
// `C.printf("hi")` => `printf("hi");`
|
|
||||||
g.write('"$escaped_val"')
|
g.write('"$escaped_val"')
|
||||||
} else {
|
} else {
|
||||||
g.write('_SLIT("$escaped_val")')
|
g.write('_SLIT("$escaped_val")')
|
||||||
|
Loading…
Reference in New Issue
Block a user