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

all: v.ast.byte_type -> v.ast.u8_type (#14964)

This commit is contained in:
zakuro 2022-07-06 19:32:30 +09:00 committed by GitHub
parent 00dfce655e
commit a46bcf3571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 46 additions and 50 deletions

View File

@ -209,7 +209,7 @@ fn buffer_to_primitive(data_list []&u8, types []int) ?[]orm.Primitive {
orm.type_idx['i64'] {
primitive = *(unsafe { &i64(data) })
}
orm.type_idx['byte'] {
orm.type_idx['u8'] {
primitive = *(unsafe { &u8(data) })
}
orm.type_idx['u16'] {
@ -249,7 +249,7 @@ fn buffer_to_primitive(data_list []&u8, types []int) ?[]orm.Primitive {
fn mysql_type_from_v(typ int) ?string {
str := match typ {
orm.type_idx['i8'], orm.type_idx['byte'] {
orm.type_idx['i8'], orm.type_idx['u8'] {
'TINYINT'
}
orm.type_idx['i16'], orm.type_idx['u16'] {

View File

@ -9,7 +9,7 @@ pub const (
ast.i8_type_idx,
ast.i16_type_idx,
ast.int_type_idx,
ast.byte_type_idx,
ast.u8_type_idx,
ast.u16_type_idx,
ast.u32_type_idx,
ast.bool_type_idx,
@ -26,7 +26,7 @@ pub const (
'i16': ast.i16_type_idx
'int': ast.int_type_idx
'i64': ast.i64_type_idx
'byte': ast.byte_type_idx
'u8': ast.u8_type_idx
'u16': ast.u16_type_idx
'u32': ast.u32_type_idx
'u64': ast.u64_type_idx

View File

@ -184,7 +184,7 @@ fn pg_stmt_match(mut types []u32, mut vals []&char, mut lens []int, mut formats
fn pg_type_from_v(typ int) ?string {
str := match typ {
orm.type_idx['i8'], orm.type_idx['i16'], orm.type_idx['byte'], orm.type_idx['u16'] {
orm.type_idx['i8'], orm.type_idx['i16'], orm.type_idx['u8'], orm.type_idx['u16'] {
'SMALLINT'
}
orm.type_idx['bool'] {
@ -240,8 +240,8 @@ fn str_to_primitive(str string, typ int) ?orm.Primitive {
orm.type_idx['i64'] {
return orm.Primitive(str.i64())
}
// byte
orm.type_idx['byte'] {
// u8
orm.type_idx['u8'] {
data := str.i8()
return orm.Primitive(*unsafe { &u8(&data) })
}

View File

@ -2253,7 +2253,7 @@ pub fn (expr Expr) is_literal() bool {
CastExpr {
return !expr.has_arg && expr.expr.is_literal()
&& (expr.typ.is_ptr() || expr.typ.is_pointer()
|| expr.typ in [i8_type, i16_type, int_type, i64_type, byte_type, u16_type, u32_type, u64_type, f32_type, f64_type, char_type, bool_type, rune_type])
|| expr.typ in [i8_type, i16_type, int_type, i64_type, u8_type, u16_type, u32_type, u64_type, f32_type, f64_type, char_type, bool_type, rune_type])
}
SizeOf, IsRefType {
return expr.is_type || expr.expr.is_literal()

View File

@ -1259,7 +1259,7 @@ pub fn (t &Table) value_type(typ Type) Type {
return string_type
}
if sym.kind in [.byteptr, .string] {
return byte_type
return u8_type
}
if typ.is_ptr() {
// byte* => byte
@ -1436,7 +1436,7 @@ pub fn (mut t Table) bitsize_to_type(bit_size int) Type {
if bit_size % 8 != 0 { // there is no way to do `i2131(32)` so this should never be reached
t.panic('compiler bug: bitsizes must be multiples of 8')
}
return new_type(t.find_or_register_array_fixed(byte_type, bit_size / 8, empty_expr()))
return new_type(t.find_or_register_array_fixed(u8_type, bit_size / 8, empty_expr()))
}
}
}

View File

@ -378,12 +378,12 @@ pub fn (typ Type) is_unsigned() bool {
pub fn (typ Type) flip_signedness() Type {
return match typ {
ast.i8_type { ast.byte_type }
ast.i8_type { ast.u8_type }
ast.i16_type { ast.u16_type }
ast.int_type { ast.u32_type }
ast.isize_type { ast.usize_type }
ast.i64_type { ast.u64_type }
ast.byte_type { ast.i8_type }
ast.u8_type { ast.i8_type }
ast.u16_type { ast.i16_type }
ast.u32_type { ast.int_type }
ast.usize_type { ast.isize_type }
@ -422,7 +422,7 @@ pub const (
int_type_idx = 7
i64_type_idx = 8
isize_type_idx = 9
byte_type_idx = 10
u8_type_idx = 10
u16_type_idx = 11
u32_type_idx = 12
u64_type_idx = 13
@ -443,7 +443,6 @@ pub const (
thread_type_idx = 28
error_type_idx = 29
nil_type_idx = 30
// u8_type_idx = 30
)
// Note: builtin_type_names must be in the same order as the idx consts above
@ -454,21 +453,19 @@ pub const builtin_type_names = ['void', 'voidptr', 'byteptr', 'charptr', 'i8', '
pub const builtin_type_names_matcher = build_builtin_type_names_matcher()
pub const (
integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx,
byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, isize_type_idx, usize_type_idx,
integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, u8_type_idx,
u16_type_idx, u32_type_idx, u64_type_idx, isize_type_idx, usize_type_idx,
int_literal_type_idx, rune_type_idx]
signed_integer_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, int_type_idx,
i64_type_idx, isize_type_idx]
unsigned_integer_type_idxs = [byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx,
unsigned_integer_type_idxs = [u8_type_idx, u16_type_idx, u32_type_idx, u64_type_idx,
usize_type_idx]
// C will promote any type smaller than int to int in an expression
int_promoted_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, byte_type_idx,
u16_type_idx]
int_promoted_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, u8_type_idx, u16_type_idx]
float_type_idxs = [f32_type_idx, f64_type_idx, float_literal_type_idx]
number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx,
byte_type_idx, char_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, isize_type_idx,
usize_type_idx, f32_type_idx, f64_type_idx, int_literal_type_idx, float_literal_type_idx,
rune_type_idx]
number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, u8_type_idx,
char_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, isize_type_idx, usize_type_idx,
f32_type_idx, f64_type_idx, int_literal_type_idx, float_literal_type_idx, rune_type_idx]
pointer_type_idxs = [voidptr_type_idx, byteptr_type_idx, charptr_type_idx]
string_type_idxs = [string_type_idx]
)
@ -485,8 +482,7 @@ pub const (
i16_type = new_type(i16_type_idx)
i64_type = new_type(i64_type_idx)
isize_type = new_type(isize_type_idx)
byte_type = new_type(byte_type_idx)
// u8_type = new_type(u8_type_idx)
u8_type = new_type(u8_type_idx)
u16_type = new_type(u16_type_idx)
u32_type = new_type(u32_type_idx)
u64_type = new_type(u64_type_idx)
@ -518,7 +514,7 @@ fn new_charptr_types() []Type {
}
fn new_byteptr_types() []Type {
return [ast.byteptr_type, new_type(ast.byte_type_idx).set_nr_muls(1)]
return [ast.byteptr_type, new_type(ast.u8_type_idx).set_nr_muls(1)]
}
fn new_voidptr_types() []Type {

View File

@ -81,7 +81,7 @@ fn test_derive() {
}
fn test_flip_signedness() {
assert ast.i8_type.flip_signedness() == ast.byte_type
assert ast.i8_type.flip_signedness() == ast.u8_type
assert ast.u16_type.flip_signedness() == ast.i16_type
assert ast.isize_type.flip_signedness() == ast.usize_type
}

View File

@ -113,7 +113,7 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
return true
}
if exp_idx == ast.voidptr_type_idx || exp_idx == ast.byteptr_type_idx
|| (expected.is_ptr() && expected.deref().idx() == ast.byte_type_idx) {
|| (expected.is_ptr() && expected.deref().idx() == ast.u8_type_idx) {
if got.is_ptr() || got.is_pointer() {
return true
}
@ -126,7 +126,7 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
}
}
if got_idx == ast.voidptr_type_idx || got_idx == ast.byteptr_type_idx
|| (got_idx == ast.byte_type_idx && got.is_ptr()) {
|| (got_idx == ast.u8_type_idx && got.is_ptr()) {
if expected.is_ptr() || expected.is_pointer() {
return true
}
@ -150,9 +150,9 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
return false
}
if got.is_number() && expected.is_number() {
if got == ast.rune_type && expected == ast.byte_type {
if got == ast.rune_type && expected == ast.u8_type {
return true
} else if expected == ast.rune_type && got == ast.byte_type {
} else if expected == ast.rune_type && got == ast.u8_type {
return true
}
if c.promote_num(expected, got) != expected {
@ -215,11 +215,11 @@ pub fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type,
}
muls_got := got.nr_muls()
muls_expected := expected.nr_muls()
if idx_got == ast.byteptr_type_idx && idx_expected == ast.byte_type_idx
if idx_got == ast.byteptr_type_idx && idx_expected == ast.u8_type_idx
&& muls_got + 1 == muls_expected {
return
}
if idx_expected == ast.byteptr_type_idx && idx_got == ast.byte_type_idx
if idx_expected == ast.byteptr_type_idx && idx_got == ast.u8_type_idx
&& muls_expected + 1 == muls_got {
return
}
@ -478,7 +478,7 @@ fn (mut c Checker) check_shift(mut node ast.InfixExpr, left_type ast.Type, right
ast.int_type { 31 }
ast.i64_type { 63 }
//
ast.byte_type { 7 }
ast.u8_type { 7 }
// ast.u8_type { 7 }
ast.u16_type { 15 }
ast.u32_type { 31 }
@ -567,12 +567,12 @@ fn (c &Checker) promote_num(left_type ast.Type, right_type ast.Type) ast.Type {
} else { // f64, float_literal
return type_hi
}
} else if idx_lo >= ast.byte_type_idx { // both operands are unsigned
} else if idx_lo >= ast.u8_type_idx { // both operands are unsigned
return type_hi
} else if idx_lo >= ast.i8_type_idx
&& (idx_hi <= ast.isize_type_idx || idx_hi == ast.rune_type_idx) { // both signed
return if idx_lo == ast.i64_type_idx { type_lo } else { type_hi }
} else if idx_hi - idx_lo < (ast.byte_type_idx - ast.i8_type_idx) {
} else if idx_hi - idx_lo < (ast.u8_type_idx - ast.i8_type_idx) {
return type_lo // conversion unsigned -> signed if signed type is larger
} else if c.pref.translated {
return type_hi

View File

@ -2274,7 +2274,7 @@ pub fn (mut c Checker) expr(node_ ast.Expr) ast.Type {
ast.StringLiteral {
if node.language == .c {
// string literal starts with "c": `C.printf(c'hello')`
return ast.byte_type.set_nr_muls(1)
return ast.u8_type.set_nr_muls(1)
}
return c.string_lit(mut node)
}
@ -2464,7 +2464,7 @@ pub fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
}
if to_type == ast.string_type {
if from_type in [ast.byte_type, ast.bool_type] {
if from_type in [ast.u8_type, ast.bool_type] {
snexpr := node.expr.str()
ft := c.table.type_to_str(from_type)
c.error('cannot cast type `$ft` to string, use `${snexpr}.str()` instead.',

View File

@ -205,7 +205,7 @@ fn (mut c Checker) eval_comptime_const_expr(expr ast.Expr, nlevel int) ?ast.Comp
return cast_expr_value.i64() or { return none }
}
//
if expr.typ == ast.byte_type {
if expr.typ == ast.u8_type {
return cast_expr_value.u8() or { return none }
}
if expr.typ == ast.u16_type {

View File

@ -1924,7 +1924,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
'\ne.g. `users.sort(a.id < b.id)`', node.pos)
}
} else if !(c.table.sym(elem_typ).has_method('<')
|| c.table.unalias_num_type(elem_typ) in [ast.int_type, ast.int_type.ref(), ast.string_type, ast.string_type.ref(), ast.i8_type, ast.i16_type, ast.i64_type, ast.byte_type, ast.rune_type, ast.u16_type, ast.u32_type, ast.u64_type, ast.f32_type, ast.f64_type, ast.char_type, ast.bool_type, ast.float_literal_type, ast.int_literal_type]) {
|| c.table.unalias_num_type(elem_typ) in [ast.int_type, ast.int_type.ref(), ast.string_type, ast.string_type.ref(), ast.i8_type, ast.i16_type, ast.i64_type, ast.u8_type, ast.rune_type, ast.u16_type, ast.u32_type, ast.u64_type, ast.f32_type, ast.f64_type, ast.char_type, ast.bool_type, ast.float_literal_type, ast.int_literal_type]) {
c.error('custom sorting condition must be supplied for type `${c.table.type_to_str(elem_typ)}`',
node.pos)
}

View File

@ -113,7 +113,7 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
}
mut value_type := c.table.value_type(typ)
if sym.kind == .string {
value_type = ast.byte_type
value_type = ast.u8_type
}
if value_type == ast.void_type || typ.has_flag(.optional) {
if typ != ast.void_type {

View File

@ -533,7 +533,7 @@ fn (e Eval) type_to_size(typ ast.Type) u64 {
ast.i8_type_idx, ast.i16_type_idx, ast.int_type_idx, ast.i64_type_idx {
return u64(math.exp2(f64(typ - 2))) // this formula converts the type number to the bitsize
}
ast.byte_type_idx, ast.u16_type_idx, ast.u32_type_idx, ast.u64_type_idx {
ast.u8_type_idx, ast.u16_type_idx, ast.u32_type_idx, ast.u64_type_idx {
return u64(math.exp2(f64(typ - 6))) // this formula converts the type number to the bitsize
}
ast.int_literal_type_idx, ast.float_literal_type_idx {

View File

@ -761,7 +761,7 @@ fn (mut g Gen) gen_str_for_map(info ast.Map, styp string, str_fn_name string) {
}
fn (g &Gen) type_to_fmt(typ ast.Type) StrIntpType {
if typ == ast.byte_type_idx {
if typ == ast.u8_type_idx {
return .si_u8
}
if typ == ast.char_type_idx {

View File

@ -31,14 +31,14 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) {
tmp_opt := g.new_tmp_var()
cur_line := g.go_before_stmt(0)
g.out.write_string(util.tabs(g.indent))
opt_elem_type := g.typ(ast.byte_type.set_flag(.optional))
opt_elem_type := g.typ(ast.u8_type.set_flag(.optional))
g.write('$opt_elem_type $tmp_opt = string_at_with_check(')
g.expr(node.left)
g.write(', ')
g.expr(node.index)
g.writeln(');')
if !node.is_option {
g.or_block(tmp_opt, node.or_expr, ast.byte_type)
g.or_block(tmp_opt, node.or_expr, ast.u8_type)
}
g.write('\n$cur_line*(byte*)&${tmp_opt}.data')
} else {

View File

@ -86,7 +86,7 @@ fn (mut g Gen) str_format(node ast.StringInterLiteral, i int) (u64, string) {
} else {
match typ {
ast.i8_type { fmt_type = .si_i8 }
ast.byte_type { fmt_type = .si_u8 }
ast.u8_type { fmt_type = .si_u8 }
ast.i16_type { fmt_type = .si_i16 }
ast.u16_type { fmt_type = .si_u16 }
ast.i64_type { fmt_type = .si_i64 }

View File

@ -645,7 +645,7 @@ fn (mut g JsGen) gen_str_for_map(info ast.Map, styp string, str_fn_name string)
}
fn (g &JsGen) type_to_fmt(typ ast.Type) StrIntpType {
if typ == ast.byte_type_idx {
if typ == ast.u8_type_idx {
return .si_u8
}
if typ == ast.char_type_idx {

View File

@ -3229,8 +3229,8 @@ fn (mut g JsGen) greater_typ(left ast.Type, right ast.Type) ast.Type {
if ast.i16_type_idx in lr {
return ast.Type(ast.i16_type_idx)
}
if ast.byte_type_idx in lr {
return ast.Type(ast.byte_type_idx)
if ast.u8_type_idx in lr {
return ast.Type(ast.u8_type_idx)
}
if ast.i8_type_idx in lr {
return ast.Type(ast.i8_type_idx)

View File

@ -578,7 +578,7 @@ pub fn (mut p Parser) parse_any_type(language ast.Language, is_ptr bool, check_d
ret = ast.i64_type
}
'u8' {
ret = ast.byte_type
ret = ast.u8_type
}
'u16' {
ret = ast.u16_type