1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

Revert "make function arguments immutable"

This reverts commit 0f0ed8d716.
This commit is contained in:
Alexander Medvednikov 2019-07-05 02:44:22 +02:00
parent 0f0ed8d716
commit d47e2f113f
8 changed files with 33 additions and 42 deletions

View File

@ -443,8 +443,8 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type
// Normal function => just its name, method => TYPE_FNNAME
mut fn_name := f.name
if f.is_method {
_receiver_type := receiver_type.replace('*', '')
fn_name = '${_receiver_type}_${f.name}'
receiver_type = receiver_type.replace('*', '')
fn_name = '${receiver_type}_${f.name}'
}
// Generate tmp struct with args
arg_struct_name := 'thread_arg_$fn_name'

View File

@ -115,8 +115,8 @@ fn is_js_prim(typ string) bool {
typ == 'i8' || typ == 'i16' || typ == 'i32' || typ == 'i64'
}
fn (p mut Parser) decode_array(_typ string) string {
typ := _typ.replace('array_', '')
fn (p mut Parser) decode_array(typ string) string {
typ = typ.replace('array_', '')
t := p.table.find_type(typ)
fn_name := js_dec_name(typ)
// If we have `[]Profile`, have to register a Profile en(de)coder first
@ -149,8 +149,8 @@ fn js_dec_name(typ string) string {
return name
}
fn (p &Parser) encode_array(_typ string) string {
typ := _typ.replace('array_', '')
fn (p &Parser) encode_array(typ string) string {
typ = typ.replace('array_', '')
fn_name := js_enc_name(typ)
return '
o = cJSON_CreateArray();

View File

@ -418,7 +418,7 @@ string _STR_TMP(const char *fmt, ...) {
}
}
fn (c mut V) cc_windows_cross() {
fn (c &V) cc_windows_cross() {
if !c.out_name.ends_with('.exe') {
c.out_name = c.out_name + '.exe'
}

View File

@ -1044,8 +1044,7 @@ fn (p mut Parser) statement(add_semi bool) string {
fn (p mut Parser) assign_statement(v Var, ph int, is_map bool) {
p.log('assign_statement() name=$v.name tok=')
tok := p.tok
//if !v.is_mut && !v.is_arg && !p.pref.translated && !v.is_global{
if !v.is_mut && !p.pref.translated && !v.is_global{
if !v.is_mut && !v.is_arg && !p.pref.translated && !v.is_global{
p.error('`$v.name` is immutable')
}
is_str := v.typ == 'string'
@ -1455,7 +1454,7 @@ fn (p mut Parser) var_expr(v Var) string {
}
// a++ and a--
if p.tok == INC || p.tok == DEC {
if !v.is_mut && !p.pref.translated {
if !v.is_mut && !v.is_arg && !p.pref.translated {
p.error('`$v.name` is immutable')
}
if typ != 'int' {
@ -1582,12 +1581,11 @@ fn (p mut Parser) dot(str_typ string, method_ph int) string {
return method.typ
}
fn (p mut Parser) index_expr(_typ string, fn_ph int) string {
fn (p mut Parser) index_expr(typ string, fn_ph int) string {
//if p.fileis('main.v') {
//println('index expr typ=$typ')
//}
// a[0]
mut typ := _typ
v := p.expr_var
is_map := typ.starts_with('map_')
is_str := typ == 'string'
@ -2135,8 +2133,8 @@ fn (p mut Parser) typ_to_fmt(typ string) string {
return ''
}
fn format_str(_str string) string {
mut str := _str.replace('"', '\\"')
fn format_str(str string) string {
str = str.replace('"', '\\"')
$if windows {
str = str.replace('\r\n', '\\n')
}
@ -3079,8 +3077,7 @@ fn (p mut Parser) go_statement() {
}
}
fn (p mut Parser) register_var(var Var) {
mut v := var
fn (p mut Parser) register_var(v Var) {
if v.line_nr == 0 {
v.line_nr = p.scanner.line_nr
}
@ -3144,8 +3141,8 @@ fn (p mut Parser) js_decode() string {
return ''
}
fn is_compile_time_const(_s string) bool {
s := _s.trim_space()
fn is_compile_time_const(s string) bool {
s = s.trim_space()
if s == '' {
return false
}
@ -3169,17 +3166,15 @@ fn (p &Parser) building_v() bool {
///////////////////////////////////////////////////////////////////////////////
// fmt helpers
fn (scanner mut Scanner) fgen(_s string) {
mut s := _s
fn (scanner mut Scanner) fgen(s string) {
if scanner.fmt_line_empty {
s = strings.repeat(`\t`, scanner.fmt_indent) + s
s = strings.repeat(`\t`, scanner.fmt_indent) + s
}
scanner.fmt_out.write(s)
scanner.fmt_line_empty = false
}
fn (scanner mut Scanner) fgenln(_s string) {
mut s := _s
fn (scanner mut Scanner) fgenln(s string) {
if scanner.fmt_line_empty {
s = strings.repeat(`\t`, scanner.fmt_indent) + s
}

View File

@ -184,8 +184,7 @@ fn (t mut Table) register_fn(new_fn Fn) {
t.fns[new_fn.name] = new_fn
}
fn (table &Table) known_type(_typ string) bool {
mut typ := _typ
fn (table &Table) known_type(typ string) bool {
// 'byte*' => look up 'byte', but don't mess up fns
if typ.ends_with('*') && !typ.contains(' ') {
typ = typ.left(typ.len - 1)
@ -381,8 +380,7 @@ fn (p &Parser) find_type(name string) *Type {
return typ
}
fn (t &Table) find_type(_name string) *Type {
mut name := _name
fn (t &Table) find_type(name string) *Type {
if name.ends_with('*') && !name.contains(' ') {
name = name.left(name.len - 1)
}
@ -395,9 +393,7 @@ fn (t &Table) find_type(_name string) *Type {
return &Type{}
}
fn (p mut Parser) _check_types(_got, _expected string, throw bool) bool {
mut expected := _expected
mut got := _got
fn (p mut Parser) _check_types(got, expected string, throw bool) bool {
p.log('check types got="$got" exp="$expected" ')
if p.pref.translated {
return true
@ -522,8 +518,8 @@ fn (p mut Parser) satisfies_interface(interface_name, _typ string, throw bool) b
fn type_default(typ string) string {
if typ.starts_with('array_') {
elm_type := typ.right(6)
return 'new_array(0, 1, sizeof($elm_type))'
typ = typ.right(6)
return 'new_array(0, 1, sizeof($typ))'
}
// Always set pointers to 0
if typ.ends_with('*') {

View File

@ -642,14 +642,14 @@ pub fn (s string) ustring_tmp() ustring {
}
fn (u ustring) substr(start, end int) string {
_start := u.runes[start]
_end := if end >= u.runes.len {
u.s.len
start = u.runes[start]
if end >= u.runes.len {
end = u.s.len
}
else {
u.runes[end]
end = u.runes[end]
}
return u.s.substr(_start, _end)
return u.s.substr(start, end)
}
fn (u ustring) left(pos int) string {

View File

@ -262,8 +262,8 @@ fn popen(path string) *FILE {
}
// exec starts the specified command, waits for it to complete, and returns its output.
pub fn exec(_cmd string) string {
cmd := '$_cmd 2>&1'
pub fn exec(cmd string) string {
cmd = '$cmd 2>&1'
f := popen(cmd)
if isnil(f) {
// TODO optional or error code
@ -331,8 +331,8 @@ pub fn dir_exists(path string) bool {
// mkdir creates a new directory with the specified path.
pub fn mkdir(path string) {
$if windows {
_path := path.replace('/', '\\')
C.CreateDirectory(_path.cstr(), 0)
path = path.replace('/', '\\')
C.CreateDirectory(path.cstr(), 0)
}
$else {
C.mkdir(path.cstr(), 511)// S_IRWXU | S_IRWXG | S_IRWXO

View File

@ -33,7 +33,7 @@ pub fn (b Builder) str() string {
return tos(b.buf.data, b.len)
}
pub fn (b mut Builder) cut(n int) {
pub fn (b Builder) cut(n int) {
b.len -= n
}