cgen: fix shadowing warning (#7289)

pull/7296/head
ka-weihe 2020-12-12 23:06:02 +01:00 committed by GitHub
parent f3aac0bc6c
commit 4d025582c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 26 deletions

View File

@ -33,12 +33,12 @@ pub fn setenv(name string, value string, overwrite bool) int {
format := '$name=$value'
if overwrite {
unsafe {
return C._putenv(format.str)
return C._putenv(charptr(format.str))
}
} else {
if getenv(name).len == 0 {
unsafe {
return C._putenv(format.str)
return C._putenv(charptr(format.str))
}
}
}
@ -54,7 +54,7 @@ pub fn setenv(name string, value string, overwrite bool) int {
pub fn unsetenv(name string) int {
$if windows {
format := '${name}='
return C._putenv(format.str)
return C._putenv(charptr(format.str))
} $else {
return C.unsetenv(charptr(name.str))
}

View File

@ -925,7 +925,7 @@ pub fn executable() string {
if is_set != 0 { // it's a windows symlink
// gets handle with GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0
file := C.CreateFile(result, 0x80000000, 1, 0, 3, 0x80, 0)
if file != -1 {
if file != voidptr(-1) {
final_path := &u16(vcalloc(size))
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew
final_len := C.GetFinalPathNameByHandleW(file, final_path, size, 0)
@ -1127,7 +1127,7 @@ pub fn real_path(fpath string) string {
mut fullpath := vcalloc(max_path_len)
mut ret := charptr(0)
$if windows {
ret = charptr(C._fullpath(fullpath, fpath.str, max_path_len))
ret = charptr(C._fullpath(charptr(fullpath), charptr(fpath.str), max_path_len))
if ret == 0 {
return fpath
}

View File

@ -247,7 +247,9 @@ fn (mut v Builder) cc() {
// TODO : try and remove the below workaround options when the corresponding
// warnings are totally fixed/removed
mut args := [v.pref.cflags, '-std=gnu99', '-Wall', '-Wextra', '-Wno-unused-variable', '-Wno-unused-parameter',
'-Wno-unused-result', '-Wno-unused-function', '-Wno-missing-braces', '-Wno-unused-label']
'-Wno-unused-result', '-Wno-unused-function', '-Wno-missing-braces', '-Wno-unused-label', '-Wshadow',
'-Wno-unused',
]
if v.pref.os == .ios {
args << '-framework Foundation'
args << '-framework UIKit'

View File

@ -2605,8 +2605,8 @@ fn (mut g Gen) expr(node ast.Expr) {
return
}
mut sum_type_deref_field := ''
if field := g.table.struct_find_field(sym, node.field_name) {
field_sym := g.table.get_type_symbol(field.typ)
if f := g.table.struct_find_field(sym, node.field_name) {
field_sym := g.table.get_type_symbol(f.typ)
if field_sym.kind == .sum_type {
if !prevent_sum_type_unwrapping_once {
// check first if field is sum type because scope searching is expensive
@ -4425,14 +4425,15 @@ fn (mut g Gen) gen_array_equality_fn(left table.Type) string {
g.definitions.writeln('\tif (a.len != b.len) {')
g.definitions.writeln('\t\treturn false;')
g.definitions.writeln('\t}')
g.definitions.writeln('\tfor (int i = 0; i < a.len; ++i) {')
i := g.new_tmp_var()
g.definitions.writeln('\tfor (int $i = 0; $i < a.len; ++$i) {')
// compare every pair of elements of the two arrays
match elem_sym.kind {
.string { g.definitions.writeln('\t\tif (string_ne(*(($ptr_typ*)((byte*)a.data+(i*a.element_size))), *(($ptr_typ*)((byte*)b.data+(i*b.element_size))))) {') }
.struct_ { g.definitions.writeln('\t\tif (memcmp((byte*)a.data+(i*a.element_size), (byte*)b.data+(i*b.element_size), a.element_size)) {') }
.array { g.definitions.writeln('\t\tif (!${ptr_elem_typ}_arr_eq((($elem_typ*)a.data)[i], (($elem_typ*)b.data)[i])) {') }
.function { g.definitions.writeln('\t\tif (*((voidptr*)((byte*)a.data+(i*a.element_size))) != *((voidptr*)((byte*)b.data+(i*b.element_size)))) {') }
else { g.definitions.writeln('\t\tif (*(($ptr_typ*)((byte*)a.data+(i*a.element_size))) != *(($ptr_typ*)((byte*)b.data+(i*b.element_size)))) {') }
.string { g.definitions.writeln('\t\tif (string_ne(*(($ptr_typ*)((byte*)a.data+($i*a.element_size))), *(($ptr_typ*)((byte*)b.data+($i*b.element_size))))) {') }
.struct_ { g.definitions.writeln('\t\tif (memcmp((byte*)a.data+($i*a.element_size), (byte*)b.data+($i*b.element_size), a.element_size)) {') }
.array { g.definitions.writeln('\t\tif (!${ptr_elem_typ}_arr_eq((($elem_typ*)a.data)[$i], (($elem_typ*)b.data)[$i])) {') }
.function { g.definitions.writeln('\t\tif (*((voidptr*)((byte*)a.data+($i*a.element_size))) != *((voidptr*)((byte*)b.data+($i*b.element_size)))) {') }
else { g.definitions.writeln('\t\tif (*(($ptr_typ*)((byte*)a.data+($i*a.element_size))) != *(($ptr_typ*)((byte*)b.data+($i*b.element_size)))) {') }
}
g.definitions.writeln('\t\t\treturn false;')
g.definitions.writeln('\t\t}')
@ -4461,17 +4462,18 @@ fn (mut g Gen) gen_map_equality_fn(left table.Type) string {
g.definitions.writeln('\t\treturn false;')
g.definitions.writeln('\t}')
g.definitions.writeln('\tarray_string _keys = map_keys(&a);')
g.definitions.writeln('\tfor (int i = 0; i < _keys.len; ++i) {')
g.definitions.writeln('\t\tstring k = string_clone( ((string*)_keys.data)[i]);')
i := g.new_tmp_var()
g.definitions.writeln('\tfor (int $i = 0; $i < _keys.len; ++$i) {')
g.definitions.writeln('\t\tstring k = string_clone( ((string*)_keys.data)[$i]);')
if value_sym.kind == .function {
func := value_sym.info as table.FnType
ret_styp := g.typ(func.func.return_type)
g.definitions.write('\t\t$ret_styp (*v) (')
arg_len := func.func.params.len
for i, arg in func.func.params {
for j, arg in func.func.params {
arg_styp := g.typ(arg.typ)
g.definitions.write('$arg_styp $arg.name')
if i < arg_len - 1 {
if j < arg_len - 1 {
g.definitions.write(', ')
}
}
@ -4920,8 +4922,9 @@ fn (mut g Gen) gen_array_filter(node ast.CallExpr) {
g.writeln(';')
g.write('int ${tmp}_len = ${tmp}_orig.len;')
g.writeln('$styp $tmp = __new_array(0, ${tmp}_len, sizeof($elem_type_str));')
g.writeln('for (int i = 0; i < ${tmp}_len; ++i) {')
g.writeln(' $elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[i];')
i := g.new_tmp_var()
g.writeln('for (int $i = 0; $i < ${tmp}_len; ++$i) {')
g.writeln(' $elem_type_str it = (($elem_type_str*) ${tmp}_orig.data)[$i];')
g.write('if (')
expr := node.args[0].expr
match expr {
@ -5054,10 +5057,6 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
cvar_name := c_name(var_name)
mr_styp := g.base_type(return_type)
is_none_ok := mr_styp == 'void'
g.inside_or_block = true
defer {
g.inside_or_block = false
}
g.writeln(';') // or')
if is_none_ok {
g.writeln('if (!${cvar_name}.ok && !${cvar_name}.is_none) {')
@ -5065,8 +5064,17 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
g.writeln('if (!${cvar_name}.ok) {')
}
if or_block.kind == .block {
if g.inside_or_block {
g.writeln('\terr = ${cvar_name}.v_error;')
g.writeln('\terrcode = ${cvar_name}.ecode;')
} else {
g.writeln('\tstring err = ${cvar_name}.v_error;')
g.writeln('\tint errcode = ${cvar_name}.ecode;')
}
g.inside_or_block = true
defer {
g.inside_or_block = false
}
stmts := or_block.stmts
if stmts.len > 0 && stmts[or_block.stmts.len - 1] is ast.ExprStmt && (stmts[stmts.len -
1] as ast.ExprStmt).typ != table.void_type {