From 51b471b0609c764e5bc5672377ec63608198d44d Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 10 Oct 2024 14:17:19 +0800 Subject: [PATCH] all: replace enum field name 'xxx_' with 'xxx' (#22469) --- cmd/tools/vdoc/highlight.v | 4 +- cmd/tools/vdoc/html.v | 2 +- cmd/tools/vls.v | 10 +-- cmd/tools/vrepl.v | 50 +++++++-------- examples/2048/2048.v | 4 +- vlib/v/ast/ast.v | 8 +-- vlib/v/ast/table.v | 12 ++-- vlib/v/ast/types.v | 30 ++++----- vlib/v/checker/assign.v | 8 +-- vlib/v/checker/check_types.v | 10 +-- vlib/v/checker/checker.v | 56 ++++++++-------- vlib/v/checker/comptime.v | 6 +- vlib/v/checker/containers.v | 10 +-- vlib/v/checker/fn.v | 46 ++++++------- vlib/v/checker/for.v | 2 +- vlib/v/checker/if.v | 10 +-- vlib/v/checker/infix.v | 24 +++---- vlib/v/checker/interface.v | 2 +- vlib/v/checker/match.v | 20 +++--- vlib/v/checker/orm.v | 2 +- vlib/v/checker/return.v | 4 +- vlib/v/checker/str.v | 4 +- vlib/v/checker/struct.v | 20 +++--- .../import_mod_as_import_duplicate_err.out | 2 +- .../orm_fn_call_with_wrong_return_type.out | 2 +- ...n_infix_expr_has_no_struct_field_error.out | 2 +- vlib/v/checker/tests/orm_table_attributes.out | 2 +- ...ing_non_struct_field_in_order_by_error.out | 4 +- vlib/v/comptime/comptimeinfo.v | 10 +-- vlib/v/doc/doc.v | 20 +++--- vlib/v/eval/expr.c.v | 2 +- vlib/v/fmt/fmt.v | 4 +- vlib/v/gen/c/array.v | 17 +++-- vlib/v/gen/c/auto_eq_methods.v | 12 ++-- vlib/v/gen/c/auto_str_methods.v | 12 ++-- vlib/v/gen/c/cgen.v | 64 +++++++++---------- vlib/v/gen/c/comptime.v | 10 +-- vlib/v/gen/c/dumpexpr.v | 4 +- vlib/v/gen/c/fn.v | 26 ++++---- vlib/v/gen/c/infix.v | 24 +++---- vlib/v/gen/c/json.v | 20 +++--- vlib/v/gen/c/match.v | 6 +- vlib/v/gen/c/orm.v | 8 +-- vlib/v/gen/c/reflection.v | 10 +-- vlib/v/gen/c/spawn_and_go.v | 8 +-- vlib/v/gen/c/str.v | 6 +- vlib/v/gen/c/str_intp.v | 4 +- vlib/v/gen/c/struct.v | 2 +- vlib/v/gen/golang/golang.v | 4 +- vlib/v/gen/js/auto_str_methods.v | 6 +- vlib/v/gen/js/builtin_types.v | 6 +- vlib/v/gen/js/comptime.v | 2 +- vlib/v/gen/js/fn.v | 8 +-- vlib/v/gen/js/js.v | 16 ++--- vlib/v/gen/js/str.v | 12 ++-- vlib/v/gen/native/amd64.v | 2 +- vlib/v/markused/markused.v | 2 +- vlib/v/parser/comptime.v | 4 +- vlib/v/parser/fn.v | 6 +- vlib/v/parser/parse_type.v | 2 +- vlib/v/parser/parser.v | 4 +- vlib/v/parser/struct.v | 2 +- vlib/v/parser/tests/orm_no_error_handler.out | 2 +- vlib/v/reflection/reflection.v | 10 +-- vlib/v/tests/reflection_sym_test.v | 2 +- vlib/x/json2/decoder.v | 12 ++-- vlib/x/json2/scanner.v | 16 ++--- vlib/x/json2/scanner_test.v | 22 +++---- 68 files changed, 380 insertions(+), 385 deletions(-) diff --git a/cmd/tools/vdoc/highlight.v b/cmd/tools/vdoc/highlight.v index ca0279627a8fba..78ea72298f35b4 100644 --- a/cmd/tools/vdoc/highlight.v +++ b/cmd/tools/vdoc/highlight.v @@ -55,7 +55,7 @@ fn color_highlight(code string, tb &ast.Table) string { .boolean { lit = term.bright_magenta(tok.lit) } - .none_ { + .none { lit = term.red(tok.lit) } .prefix { @@ -133,7 +133,7 @@ fn color_highlight(code string, tb &ast.Table) string { tok_typ = .punctuation } .key_none { - tok_typ = .none_ + tok_typ = .none } else { if token.is_key(tok.lit) || token.is_decl(tok.kind) { diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index 9908dc3d77b87d..315f6d1f1e960b 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -39,7 +39,7 @@ enum HighlightTokenTyp { partial_string closing_string symbol - none_ + none module_ prefix } diff --git a/cmd/tools/vls.v b/cmd/tools/vls.v index e9024577b2c9f7..2cc12c93a02ba1 100644 --- a/cmd/tools/vls.v +++ b/cmd/tools/vls.v @@ -25,7 +25,7 @@ enum UpdateSource { } enum SetupKind { - none_ + none install update } @@ -39,7 +39,7 @@ enum OutputMode { struct VlsUpdater { mut: output OutputMode = .text - setup_kind SetupKind = .none_ + setup_kind SetupKind = .none update_source UpdateSource = .github_releases ls_path string // --path pass_to_ls bool // --ls @@ -348,7 +348,7 @@ fn (mut upd VlsUpdater) parse(mut fp flag.FlagParser) ! { upd.ls_path = ls_path - if upd.setup_kind != .none_ { + if upd.setup_kind != .none { upd.update_source = .local_file // use local path if both -p and --source are used } } @@ -368,7 +368,7 @@ fn (mut upd VlsUpdater) parse(mut fp flag.FlagParser) ! { } upd.ls_path = ls_path - } else if upd.setup_kind == .none_ { + } else if upd.setup_kind == .none { return server_not_found_err } } @@ -455,7 +455,7 @@ fn (upd VlsUpdater) check_installation() { fn (upd VlsUpdater) run(fp flag.FlagParser) ! { if upd.is_check { upd.check_installation() - } else if upd.setup_kind != .none_ { + } else if upd.setup_kind != .none { upd.check_or_create_vls_folder()! match upd.update_source { diff --git a/cmd/tools/vrepl.v b/cmd/tools/vrepl.v index c1312894c203d2..9cd5422d91a8e0 100644 --- a/cmd/tools/vrepl.v +++ b/cmd/tools/vrepl.v @@ -73,14 +73,14 @@ enum FnType { } enum DeclType { - include_ // #include ... - const_ // const ... - type_ // type ... - enum_ // enum ... - fn_ // fn ... - struct // struct ... - interface_ // interface ... - stmt_ // statement + include // #include ... + const // const ... + type // type ... + enum // enum ... + fn // fn ... + struct // struct ... + interface // interface ... + stmt // statement } fn new_repl(folder string) Repl { @@ -249,19 +249,19 @@ fn (r &Repl) insert_source_code(typ DeclType, lines []string) string { all_lines << r.vstartup_lines.filter(!it.starts_with('print')) } all_lines << r.includes - if typ == .include_ { + if typ == .include { all_lines << lines } all_lines << r.types - if typ == .type_ { + if typ == .type { all_lines << lines } all_lines << r.enums - if typ == .enum_ { + if typ == .enum { all_lines << lines } all_lines << r.consts - if typ == .const_ { + if typ == .const { all_lines << lines } all_lines << r.structs @@ -269,15 +269,15 @@ fn (r &Repl) insert_source_code(typ DeclType, lines []string) string { all_lines << lines } all_lines << r.interfaces - if typ == .interface_ { + if typ == .interface { all_lines << lines } all_lines << r.functions - if typ == .fn_ { + if typ == .fn { all_lines << lines } all_lines << r.lines - if typ == .stmt_ { + if typ == .stmt { all_lines << lines } return all_lines.join('\n') @@ -596,30 +596,30 @@ fn run_repl(workdir string, vrepl_prefix string) int { } } else if r.line.len == 0 { if was_func { - temp_source_code = r.insert_source_code(DeclType.fn_, r.temp_lines) + temp_source_code = r.insert_source_code(DeclType.fn, r.temp_lines) } else if was_struct { temp_source_code = r.insert_source_code(DeclType.struct, r.temp_lines) } else if was_enum { - temp_source_code = r.insert_source_code(DeclType.enum_, r.temp_lines) + temp_source_code = r.insert_source_code(DeclType.enum, r.temp_lines) } else if was_interface { - temp_source_code = r.insert_source_code(DeclType.interface_, r.temp_lines) + temp_source_code = r.insert_source_code(DeclType.interface, r.temp_lines) } else { - temp_source_code = r.insert_source_code(DeclType.stmt_, r.temp_lines) + temp_source_code = r.insert_source_code(DeclType.stmt, r.temp_lines) } } else if starts_with_include { - temp_source_code = r.insert_source_code(DeclType.include_, [r.line]) + temp_source_code = r.insert_source_code(DeclType.include, [r.line]) } else if starts_with_fn { - temp_source_code = r.insert_source_code(DeclType.fn_, [r.line]) + temp_source_code = r.insert_source_code(DeclType.fn, [r.line]) } else if starts_with_const { - temp_source_code = r.insert_source_code(DeclType.const_, [r.line]) + temp_source_code = r.insert_source_code(DeclType.const, [r.line]) } else if starts_with_enum { - temp_source_code = r.insert_source_code(DeclType.enum_, [r.line]) + temp_source_code = r.insert_source_code(DeclType.enum, [r.line]) } else if starts_with_struct { temp_source_code = r.insert_source_code(DeclType.struct, [r.line]) } else if starts_with_interface { - temp_source_code = r.insert_source_code(DeclType.interface_, [r.line]) + temp_source_code = r.insert_source_code(DeclType.interface, [r.line]) } else if starts_with_type { - temp_source_code = r.insert_source_code(DeclType.type_, [r.line]) + temp_source_code = r.insert_source_code(DeclType.type, [r.line]) } else { temp_source_code = r.current_source_code(true, false) + '\n${r.line}\n' } diff --git a/examples/2048/2048.v b/examples/2048/2048.v index e94f6e2ae49045..f2329cbf7447eb 100644 --- a/examples/2048/2048.v +++ b/examples/2048/2048.v @@ -162,7 +162,7 @@ enum TileFormat { log exponent shifts - none_ + none end_ // To know when to wrap around } @@ -671,7 +671,7 @@ fn (app &App) draw_tiles() { size: fs2 }) } - .none_ {} // Don't draw any text here, colors only + .none {} // Don't draw any text here, colors only .end_ {} // Should never get here } } diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 9297e15db5007e..c74acadbcc9365 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -141,7 +141,7 @@ pub mut: pub enum ComptimeTypeKind { unknown - map_ + map int float struct @@ -150,7 +150,7 @@ pub enum ComptimeTypeKind { array_fixed array_dynamic sum_type - enum_ + enum alias function option @@ -166,7 +166,7 @@ pub: pub fn (cty ComptimeType) str() string { return match cty.kind { .unknown { '\$unknown' } - .map_ { '\$map' } + .map { '\$map' } .int { '\$int' } .float { '\$float' } .struct { '\$struct' } @@ -175,7 +175,7 @@ pub fn (cty ComptimeType) str() string { .array_dynamic { '\$array_dynamic' } .array_fixed { '\$array_fixed' } .sum_type { '\$sumtype' } - .enum_ { '\$enum' } + .enum { '\$enum' } .alias { '\$alias' } .function { '\$function' } .option { '\$option' } diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index cc5210d1c22fba..ed6e9840965698 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -1386,13 +1386,13 @@ pub fn (t &Table) is_sumtype_or_in_variant(parent Type, typ Type) bool { @[inline] pub fn (t &Table) is_interface_var(var ScopeObject) bool { - return var is Var && var.orig_type != 0 && t.sym(var.orig_type).kind == .interface_ - && t.sym(var.smartcasts.last()).kind != .interface_ + return var is Var && var.orig_type != 0 && t.sym(var.orig_type).kind == .interface + && t.sym(var.smartcasts.last()).kind != .interface } @[inline] pub fn (t &Table) is_interface_smartcast(var ScopeObject) bool { - return var is Var && var.orig_type != 0 && t.sym(var.orig_type).kind == .interface_ + return var is Var && var.orig_type != 0 && t.sym(var.orig_type).kind == .interface && var.smartcasts.len > 0 } @@ -1510,7 +1510,7 @@ pub fn (t Table) does_type_implement_interface(typ Type, inter_typ Type) bool { } } mut inter_sym := t.sym(inter_typ) - if sym.kind == .interface_ && inter_sym.kind == .interface_ { + if sym.kind == .interface && inter_sym.kind == .interface { return false } if mut inter_sym.info is Interface { @@ -2043,7 +2043,7 @@ pub fn (mut t Table) unwrap_generic_type_ex(typ Type, generic_names []string, co for i in 0 .. variants.len { if variants[i].has_flag(.generic) { sym := t.sym(variants[i]) - if sym.kind in [.struct, .sum_type, .interface_] { + if sym.kind in [.struct, .sum_type, .interface] { variants[i] = t.unwrap_generic_type(variants[i], generic_names, concrete_types) } else { @@ -2106,7 +2106,7 @@ pub fn (mut t Table) unwrap_generic_type_ex(typ Type, generic_names []string, co info.fields = fields info.methods = imethods new_idx := t.register_sym( - kind: .interface_ + kind: .interface name: nrt cname: util.no_dots(c_nrt) mod: ts.mod diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 840d69a4e8ffde..fc4e5768c31c19 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -792,7 +792,7 @@ pub enum Kind { char rune bool - none_ + none string array array_fixed @@ -804,9 +804,9 @@ pub enum Kind { multi_return sum_type alias - enum_ + enum function - interface_ + interface float_literal int_literal aggregate @@ -1034,7 +1034,7 @@ pub fn (mut t Table) register_builtin_type_symbols() { t.register_sym(kind: .f64, name: 'f64', cname: 'f64', mod: 'builtin') // 17 t.register_sym(kind: .char, name: 'char', cname: 'char', mod: 'builtin') // 18 t.register_sym(kind: .bool, name: 'bool', cname: 'bool', mod: 'builtin') // 19 - t.register_sym(kind: .none_, name: 'none', cname: 'none', mod: 'builtin') // 20 + t.register_sym(kind: .none, name: 'none', cname: 'none', mod: 'builtin') // 20 t.register_sym(kind: .string, name: 'string', cname: 'string', mod: 'builtin') // 21 t.register_sym(kind: .rune, name: 'rune', cname: 'rune', mod: 'builtin') // 22 t.register_sym(kind: .array, name: 'array', cname: 'array', mod: 'builtin') // 23 @@ -1062,7 +1062,7 @@ pub fn (mut t Table) register_builtin_type_symbols() { return_type: void_type } ) // 29 - t.register_sym(kind: .interface_, name: 'IError', cname: 'IError', mod: 'builtin') // 30 + t.register_sym(kind: .interface, name: 'IError', cname: 'IError', mod: 'builtin') // 30 t.register_sym(kind: .voidptr, name: 'nil', cname: 'voidptr', mod: 'builtin') // 31 } @@ -1126,7 +1126,7 @@ pub fn (t &Table) type_size(typ Type) (int, int) { mut size := 0 mut align := 0 match sym.kind { - .placeholder, .void, .none_, .generic_inst {} + .placeholder, .void, .none, .generic_inst {} .voidptr, .byteptr, .charptr, .function, .usize, .isize, .any, .thread, .chan { size = t.pointer_size align = t.pointer_size @@ -1139,7 +1139,7 @@ pub fn (t &Table) type_size(typ Type) (int, int) { size = 2 align = 2 } - .i32, .u32, .rune, .f32, .enum_ { + .i32, .u32, .rune, .f32, .enum { size = 4 align = 4 } @@ -1182,7 +1182,7 @@ pub fn (t &Table) type_size(typ Type) (int, int) { size = round_up(total_size, max_alignment) align = max_alignment } - .sum_type, .interface_, .aggregate { + .sum_type, .interface, .aggregate { match mut sym.info { SumType, Aggregate { size = (sym.info.fields.len + 2) * t.pointer_size @@ -1256,7 +1256,7 @@ pub fn (k Kind) str() string { .string { 'string' } .char { 'char' } .bool { 'bool' } - .none_ { 'none' } + .none { 'none' } .array { 'array' } .array_fixed { 'array_fixed' } .map { 'map' } @@ -1264,10 +1264,10 @@ pub fn (k Kind) str() string { .multi_return { 'multi_return' } .sum_type { 'sum_type' } .alias { 'alias' } - .enum_ { 'enum' } + .enum { 'enum' } .any { 'any' } .function { 'function' } - .interface_ { 'interface' } + .interface { 'interface' } .generic_inst { 'generic_inst' } .rune { 'rune' } .aggregate { 'aggregate' } @@ -1365,7 +1365,7 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string] match sym.kind { .int_literal, .float_literal {} .i8, .i16, .i32, .int, .i64, .isize, .u8, .u16, .u32, .u64, .usize, .f32, .f64, .char, - .rune, .string, .bool, .none_, .voidptr, .byteptr, .charptr { + .rune, .string, .bool, .none, .voidptr, .byteptr, .charptr { // primitive types res = sym.kind.str() } @@ -1446,7 +1446,7 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string] } res += ')' } - .struct, .interface_, .sum_type { + .struct, .interface, .sum_type { if typ.has_flag(.generic) { match sym.info { Struct, Interface, SumType { @@ -1500,7 +1500,7 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string] res = 'thread ' + t.type_to_str_using_aliases(rtype, import_aliases) } } - .alias, .any, .placeholder, .enum_ { + .alias, .any, .placeholder, .enum { res = t.shorten_user_defined_typenames(res, import_aliases) /* if res.ends_with('.byte') { @@ -1706,7 +1706,7 @@ pub fn (t &TypeSymbol) find_method_with_generic_parent(name string) ?Fn { mut method := x generic_names := parent_sym.info.generic_types.map(table.sym(it).name) return_sym := table.sym(method.return_type) - if return_sym.kind in [.struct, .interface_, .sum_type] { + if return_sym.kind in [.struct, .interface, .sum_type] { method.return_type = table.unwrap_generic_type(method.return_type, generic_names, t.info.concrete_types) } else { diff --git a/vlib/v/checker/assign.v b/vlib/v/checker/assign.v index ce03a4fec9fd4f..5677bb5bd83c81 100644 --- a/vlib/v/checker/assign.v +++ b/vlib/v/checker/assign.v @@ -802,7 +802,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', } } } - if !is_blank_ident && right_sym.kind != .placeholder && left_sym.kind != .interface_ + if !is_blank_ident && right_sym.kind != .placeholder && left_sym.kind != .interface && ((!right_type.has_flag(.generic) && !left_type.has_flag(.generic)) || right_sym.kind != left_sym.kind) { // Dual sides check (compatibility check) @@ -837,7 +837,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', if c.comptime.comptime_for_field_var != '' && left is ast.ComptimeSelector { field_sym := c.table.sym(c.unwrap_generic(c.comptime.comptime_for_field_type)) - if field_sym.kind == .enum_ && !right_type.is_int() { + if field_sym.kind == .enum && !right_type.is_int() { c.error('enums can only be assigned `int` values', right.pos()) } } else { @@ -858,9 +858,9 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', } } } - if left_sym.kind == .interface_ { + if left_sym.kind == .interface { if c.type_implements(right_type, left_type, right.pos()) { - if !right_type.is_any_kind_of_pointer() && right_sym.kind != .interface_ + if !right_type.is_any_kind_of_pointer() && right_sym.kind != .interface && !c.inside_unsafe { c.mark_as_referenced(mut &node.right[i], true) } diff --git a/vlib/v/checker/check_types.v b/vlib/v/checker/check_types.v index 62281c3183f9fa..1eac083ddfb2b0 100644 --- a/vlib/v/checker/check_types.v +++ b/vlib/v/checker/check_types.v @@ -43,7 +43,7 @@ fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool { deref := expected.deref() // deref := expected.set_nr_muls(0) got_sym := c.table.sym(got) - if deref.is_number() && (got_sym.is_number() || got_sym.kind == .enum_) { + if deref.is_number() && (got_sym.is_number() || got_sym.kind == .enum) { return true } } @@ -71,7 +71,7 @@ fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool { } } - if got_sym.kind == .enum_ { + if got_sym.kind == .enum { // Allow ints as enums if expected_sym.is_number() { return true @@ -100,7 +100,7 @@ fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool { return true } } - if expected_sym.kind == .enum_ && got_sym.is_number() { + if expected_sym.kind == .enum && got_sym.is_number() { // Allow enums as numbers return true } @@ -329,7 +329,7 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan } else { got_typ_sym := c.table.sym(c.unwrap_generic(got)) expected_typ_sym := c.table.sym(c.unwrap_generic(expected)) - if expected_typ_sym.kind == .interface_ && c.type_implements(got, expected, token.Pos{}) { + if expected_typ_sym.kind == .interface && c.type_implements(got, expected, token.Pos{}) { return } @@ -1101,7 +1101,7 @@ fn (mut c Checker) infer_fn_generic_types(func &ast.Fn, mut node ast.CallExpr) { } } } - } else if arg_sym.kind in [.struct, .interface_, .sum_type] { + } else if arg_sym.kind in [.struct, .interface, .sum_type] { mut generic_types := []ast.Type{} mut concrete_types := []ast.Type{} match arg_sym.info { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 334f1d719f3a4a..e8575b46d14bb9 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -613,7 +613,7 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) { // type Sum = int | Alias // type Alias = Sum } - .none_ { + .none { c.error('cannot create a type alias of `none` as it is a value', node.type_pos) } // The rest of the parent symbol kinds are also allowed, since they are either primitive types, @@ -624,11 +624,11 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) { /* .voidptr, .byteptr, .charptr {} .char, .rune, .bool {} - .string, .enum_, .none_, .any {} + .string, .enum, .none, .any {} .i8, .i16, .int, .i64, .isize {} .u8, .u16, .u32, .u64, .usize {} .f32, .f64 {} - .interface_ {} + .interface {} .generic_inst {} .aggregate {} */ @@ -696,7 +696,7 @@ and use a reference to the sum type instead: `var := &${node.name}(${variant_nam variant.pos) } else if sym.kind in [.placeholder, .int_literal, .float_literal] { c.error('unknown type `${sym.name}`', variant.pos) - } else if sym.kind == .interface_ && sym.language != .js { + } else if sym.kind == .interface && sym.language != .js { c.error('sum type cannot hold an interface', variant.pos) } else if sym.kind == .struct && sym.language == .js { c.error('sum type cannot hold a JS struct', variant.pos) @@ -936,7 +936,7 @@ fn (mut c Checker) fail_if_immutable(mut expr ast.Expr) (string, token.Pos) { explicit_lock_needed = true } } - .interface_ { + .interface { interface_info := typ_sym.info as ast.Interface mut field_info := interface_info.find_field(expr.field_name) or { type_str := c.table.type_to_str(expr.expr_type) @@ -1080,12 +1080,12 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to // `none` "implements" the Error interface return true } - if typ_sym.kind == .interface_ && inter_sym.kind == .interface_ && !styp.starts_with('JS.') + if typ_sym.kind == .interface && inter_sym.kind == .interface && !styp.starts_with('JS.') && !inter_sym.name.starts_with('JS.') { c.error('cannot implement interface `${inter_sym.name}` with a different interface `${styp}`', pos) } - imethods := if inter_sym.kind == .interface_ { + imethods := if inter_sym.kind == .interface { (inter_sym.info as ast.Interface).methods } else { inter_sym.methods @@ -1658,7 +1658,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { if field.is_deprecated && is_used_outside { c.deprecate('field', field_name, field.attrs, node.pos) } - if field_sym.kind in [.sum_type, .interface_] { + if field_sym.kind in [.sum_type, .interface] { if !prevent_sum_type_unwrapping_once { if scope_field := node.scope.find_struct_field(node.expr.str(), typ, field_name) { return scope_field.smartcasts.last() @@ -1704,7 +1704,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type { node.typ = fn_type return fn_type } - if sym.kind !in [.struct, .aggregate, .interface_, .sum_type] { + if sym.kind !in [.struct, .aggregate, .interface, .sum_type] { if sym.kind != .placeholder { unwrapped_sym := c.table.sym(c.unwrap_generic(typ)) @@ -2821,9 +2821,9 @@ pub fn (mut c Checker) expr(mut node ast.Expr) ast.Type { c.error('cannot cast `${expr_type_sym.name}` to `${addr}${type_sym.name}`', node.pos) } - } else if expr_type_sym.kind == .interface_ { + } else if expr_type_sym.kind == .interface { c.ensure_type_exists(node.typ, node.pos) - if type_sym.kind != .interface_ { + if type_sym.kind != .interface { c.type_implements(node.typ, node.expr_type, node.pos) } } else if node.expr_type.clear_flag(.option) != node.typ.clear_flag(.option) { @@ -3256,7 +3256,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { } } else if mut to_sym.info is ast.Alias && !(final_to_sym.kind == .struct && final_to_is_ptr) { if (!c.check_types(from_type, to_sym.info.parent_type) && !(final_to_sym.is_int() - && final_from_sym.kind in [.enum_, .bool, .i8, .u8, .char])) + && final_from_sym.kind in [.enum, .bool, .i8, .u8, .char])) || (final_to_sym.kind == .struct && from_type.idx() in [ast.voidptr_type_idx, ast.nil_type_idx]) { ft := c.table.type_to_str(from_type) @@ -3313,7 +3313,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { && !c.file.is_translated { c.error('cannot cast voidptr to a struct outside `unsafe`', node.pos) } - if !from_type.is_int() && final_from_sym.kind != .enum_ + if !from_type.is_int() && final_from_sym.kind != .enum && !from_type.is_any_kind_of_pointer() { ft := c.table.type_to_str(from_type) tt := c.table.type_to_str(to_type) @@ -3321,7 +3321,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { } } else if !from_type.has_option_or_result() && mut to_sym.info is ast.Interface { if c.type_implements(from_type, to_type, node.pos) { - if !from_type.is_any_kind_of_pointer() && from_sym.kind != .interface_ + if !from_type.is_any_kind_of_pointer() && from_sym.kind != .interface && !c.inside_unsafe { c.mark_as_referenced(mut &node.expr, true) } @@ -3346,13 +3346,13 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { type_name := c.table.type_to_str(to_type) c.error('cannot cast `none` to `${type_name}`', node.pos) } else if !from_type.has_option_or_result() && from_sym.kind == .struct && !from_type.is_ptr() { - if (final_to_is_ptr || to_sym.kind !in [.sum_type, .interface_]) && !c.is_builtin_mod { + if (final_to_is_ptr || to_sym.kind !in [.sum_type, .interface]) && !c.is_builtin_mod { from_type_name := c.table.type_to_str(from_type) type_name := c.table.type_to_str(to_type) c.error('cannot cast struct `${from_type_name}` to `${type_name}`', node.pos) } } else if to_sym.kind == .u8 && !final_from_sym.is_number() - && !from_type.is_any_kind_of_pointer() && final_from_sym.kind !in [.char, .enum_, .bool] { + && !from_type.is_any_kind_of_pointer() && final_from_sym.kind !in [.char, .enum, .bool] { ft := c.table.type_to_str(from_type) tt := c.table.type_to_str(to_type) c.error('cannot cast type `${ft}` to `${tt}`', node.pos) @@ -3416,7 +3416,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { c.error('cannot cast `${ft}` to rune, use `${snexpr}.runes()` instead.', node.pos) } - if to_sym.kind == .enum_ && !(c.inside_unsafe || c.file.is_translated) && from_sym.is_int() { + if to_sym.kind == .enum && !(c.inside_unsafe || c.file.is_translated) && from_sym.is_int() { c.error('casting numbers to enums, should be done inside `unsafe{}` blocks', node.pos) } @@ -3457,7 +3457,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { c.error('cannot cast array to string, use `${snexpr}${first_elem_idx}.str()` instead.', node.pos) } - } else if final_from_sym.kind == .enum_ { + } else if final_from_sym.kind == .enum { snexpr := node.expr.str() c.error('cannot cast enum to string, use ${snexpr}.str() instead.', node.pos) } else if final_from_sym.kind == .map { @@ -3509,8 +3509,8 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { } } if from_sym.language == .v && !from_type.is_ptr() - && final_from_sym.kind in [.sum_type, .interface_] - && final_to_sym.kind !in [.sum_type, .interface_] { + && final_from_sym.kind in [.sum_type, .interface] + && final_to_sym.kind !in [.sum_type, .interface] { ft := c.table.type_to_str(from_type) tt := c.table.type_to_str(to_type) kind_name := if from_sym.kind == .sum_type { 'sum type' } else { 'interface' } @@ -3523,7 +3523,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type { } // checks on int literal to enum cast if the value represents a value on the enum - if to_sym.kind == .enum_ { + if to_sym.kind == .enum { if mut node.expr is ast.IntegerLiteral { enum_typ_name := c.table.get_type_name(to_type) node_val := node.expr.val.i64() @@ -4091,7 +4091,7 @@ fn (mut c Checker) concat_expr(mut node ast.ConcatExpr) ast.Type { fn (mut c Checker) smartcast(mut expr ast.Expr, cur_type ast.Type, to_type_ ast.Type, mut scope ast.Scope, is_comptime bool) { sym := c.table.sym(cur_type) - to_type := if sym.kind == .interface_ && c.table.sym(to_type_).kind != .interface_ { + to_type := if sym.kind == .interface && c.table.sym(to_type_).kind != .interface { to_type_.ref() } else { to_type_ @@ -4408,7 +4408,7 @@ fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool) { node.obj.is_auto_heap = true } } - .sum_type, .interface_ {} + .sum_type, .interface {} .function { if type_sym.info is ast.FnType { if type_sym.info.is_anon { @@ -4473,7 +4473,7 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type { right_sym := c.table.sym(right_type) expr_sym := c.table.sym(node.right.expr_type) if expr_sym.kind == .struct && (expr_sym.info as ast.Struct).is_minify - && (node.right.typ == ast.bool_type_idx || (right_sym.kind == .enum_ + && (node.right.typ == ast.bool_type_idx || (right_sym.kind == .enum && !(right_sym.info as ast.Enum).is_flag && !(right_sym.info as ast.Enum).uses_exprs)) { c.error('cannot take the address of field in struct `${c.table.type_to_str(node.right.expr_type)}`, which is tagged as `@[minify]`', @@ -4609,7 +4609,7 @@ fn (mut c Checker) check_index(typ_sym &ast.TypeSymbol, index ast.Expr, index_ty range_index bool, is_gated bool) { if typ_sym.kind in [.array, .array_fixed, .string] { index_type_sym := c.table.sym(index_type) - if !(index_type.is_int() || index_type_sym.kind == .enum_ + if !(index_type.is_int() || index_type_sym.kind == .enum || (index_type_sym.kind == .alias && (index_type_sym.info as ast.Alias).parent_type.is_int()) || (c.pref.translated && index_type.is_any_kind_of_pointer())) { @@ -4677,7 +4677,7 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type { is_aggregate_arr := typ_sym.kind == .aggregate && (typ_sym.info as ast.Aggregate).types.filter(c.table.type_kind(it) !in [.array, .array_fixed, .string, .map]).len == 0 if typ_sym.kind !in [.array, .array_fixed, .string, .map] - && (!typ.is_ptr() || typ_sym.kind in [.sum_type, .interface_]) + && (!typ.is_ptr() || typ_sym.kind in [.sum_type, .interface]) && typ !in [ast.byteptr_type, ast.charptr_type] && !typ.has_flag(.variadic) && !is_aggregate_arr { c.error('type `${typ_sym.name}` does not support indexing', node.pos) @@ -4845,7 +4845,7 @@ fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type { typ_sym = c.table.sym(typ) } fsym := c.table.final_sym(typ) - if fsym.kind != .enum_ && !c.pref.translated && !c.file.is_translated { + if fsym.kind != .enum && !c.pref.translated && !c.file.is_translated { // TODO: in C int fields can be compared to enums, need to handle that in C2V if typ_sym.kind == .placeholder { // If it's a placeholder, the type doesn't exist, print @@ -5068,7 +5068,7 @@ fn (mut c Checker) ensure_generic_type_specify_type_names(typ ast.Type, pos toke return false } } - .interface_ { + .interface { info := sym.info as ast.Interface if info.generic_types.len > 0 && !typ.has_flag(.generic) && info.concrete_types.len == 0 { c.error('`${sym.name}` type is generic interface, must specify the generic type names, e.g. ${sym.name}[T], ${sym.name}[int]', diff --git a/vlib/v/checker/comptime.v b/vlib/v/checker/comptime.v index 007d85a48cad23..09b466199c5672 100644 --- a/vlib/v/checker/comptime.v +++ b/vlib/v/checker/comptime.v @@ -246,7 +246,7 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { return } if node.kind == .fields { - if sym.kind in [.struct, .interface_] { + if sym.kind in [.struct, .interface] { mut fields := []ast.StructField{} match sym.info { ast.Struct { @@ -294,7 +294,7 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { return } } else if node.kind == .values { - if sym.kind == .enum_ { + if sym.kind == .enum { c.push_new_comptime_info() c.comptime.inside_comptime_for = true if c.enum_data_type == 0 { @@ -772,7 +772,7 @@ fn (mut c Checker) comptime_if_cond(mut cond ast.Expr, pos token.Pos) ComptimeBr if cond.left is ast.TypeNode && mut cond.right is ast.TypeNode { // `$if Foo is Interface {` sym := c.table.sym(cond.right.typ) - if sym.kind != .interface_ { + if sym.kind != .interface { c.expr(mut cond.left) } return .unknown diff --git a/vlib/v/checker/containers.v b/vlib/v/checker/containers.v index e1abbaf857871d..5475885fe8a05b 100644 --- a/vlib/v/checker/containers.v +++ b/vlib/v/checker/containers.v @@ -146,7 +146,7 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { if c.expected_type != 0 { expected_value_type = c.table.value_type(c.expected_type) expected_value_sym := c.table.sym(expected_value_type) - if expected_value_sym.kind == .interface_ { + if expected_value_sym.kind == .interface { // array of interfaces? (`[dog, cat]`) Save the interface type (`Animal`) expecting_interface_array = true } else if expected_value_sym.kind == .sum_type { @@ -168,7 +168,7 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { } if !typ.is_any_kind_of_pointer() && !c.inside_unsafe { typ_sym := c.table.sym(typ) - if typ_sym.kind != .interface_ { + if typ_sym.kind != .interface { c.mark_as_referenced(mut &expr, true) } } @@ -207,7 +207,7 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type { } } if expr !is ast.TypeNode { - if c.table.type_kind(elem_type) == .interface_ { + if c.table.type_kind(elem_type) == .interface { if c.type_implements(typ, elem_type, expr.pos()) { continue } @@ -526,7 +526,7 @@ fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type { node.value_type = map_val_type map_value_sym := c.table.sym(map_val_type) - expecting_interface_map := map_value_sym.kind == .interface_ + expecting_interface_map := map_value_sym.kind == .interface mut same_key_type := true for i, mut key in node.keys { if i == 0 && map_type == ast.void_type { @@ -672,7 +672,7 @@ fn (mut c Checker) check_elements_initialized(typ ast.Type) ! { } } sym := c.table.sym(typ) - if sym.kind == .interface_ { + if sym.kind == .interface { return err_interface_uninitialized } else if sym.kind == .sum_type { return err_sumtype_uninitialized diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index ed69100e44f97c..0d04e189caf134 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -1036,7 +1036,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. if idx > 0 { // is from another mod. if enum_name.contains('.') { - if !c.check_type_and_visibility(full_enum_name, idx, .enum_, node.pos) { + if !c.check_type_and_visibility(full_enum_name, idx, .enum, node.pos) { return ast.void_type } } @@ -1048,7 +1048,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. if idx < 1 { continue } - if !c.check_type_and_visibility(full_enum_name, idx, .enum_, node.pos) { + if !c.check_type_and_visibility(full_enum_name, idx, .enum, node.pos) { return ast.void_type } break @@ -1324,7 +1324,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. } if i == node.args.len - 1 { if c.table.sym(typ).kind == .array && call_arg.expr !is ast.ArrayDecompose - && c.table.sym(expected_type).kind !in [.sum_type, .interface_] + && c.table.sym(expected_type).kind !in [.sum_type, .interface] && !param.typ.has_flag(.generic) && expected_type != typ { styp := c.table.type_to_str(typ) elem_styp := c.table.type_to_str(expected_type) @@ -1368,7 +1368,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. } } arg_typ_sym := c.table.sym(arg_typ) - if arg_typ_sym.kind == .none_ && param.typ.has_flag(.generic) { + if arg_typ_sym.kind == .none && param.typ.has_flag(.generic) { c.error('cannot use `none` as generic argument', call_arg.pos) } param_typ_sym := c.table.sym(param.typ) @@ -1439,10 +1439,10 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. c.error('expression cannot be passed as `voidptr`', call_arg.expr.pos()) } // Handle expected interface - if final_param_sym.kind == .interface_ { + if final_param_sym.kind == .interface { if c.type_implements(arg_typ, final_param_typ, call_arg.expr.pos()) { if !arg_typ.is_any_kind_of_pointer() && !c.inside_unsafe - && arg_typ_sym.kind != .interface_ { + && arg_typ_sym.kind != .interface { c.mark_as_referenced(mut &call_arg.expr, true) } } @@ -1507,10 +1507,10 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. } // TODO: duplicated logic in check_types() (check_types.v) // Allow enums to be used as ints and vice versa in translated code - if param_type.idx() in ast.integer_type_idxs && arg_typ_sym.kind == .enum_ { + if param_type.idx() in ast.integer_type_idxs && arg_typ_sym.kind == .enum { continue } - if arg_typ.idx() in ast.integer_type_idxs && param_typ_sym.kind == .enum_ { + if arg_typ.idx() in ast.integer_type_idxs && param_typ_sym.kind == .enum { continue } @@ -1625,10 +1625,10 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast. { utyp := c.unwrap_generic(typ) unwrap_sym := c.table.sym(unwrap_typ) - if unwrap_sym.kind == .interface_ { + if unwrap_sym.kind == .interface { if c.type_implements(utyp, unwrap_typ, call_arg.expr.pos()) { if !utyp.is_any_kind_of_pointer() && !c.inside_unsafe - && c.table.sym(utyp).kind != .interface_ { + && c.table.sym(utyp).kind != .interface { c.mark_as_referenced(mut &call_arg.expr, true) } } @@ -1832,7 +1832,7 @@ fn (mut c Checker) resolve_comptime_args(func &ast.Fn, node_ ast.CallExpr, concr && param_typ_sym.kind == .array { ctyp = c.get_generic_array_element_type(arg_sym.info) comptime_args[k] = ctyp - } else if arg_sym.kind in [.struct, .interface_, .sum_type] { + } else if arg_sym.kind in [.struct, .interface, .sum_type] { mut generic_types := []ast.Type{} match arg_sym.info { ast.Struct, ast.Interface, ast.SumType { @@ -2037,7 +2037,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { c.error('Result type cannot be called directly', node.left.pos()) return ast.void_type } - if left_sym.kind in [.sum_type, .interface_] { + if left_sym.kind in [.sum_type, .interface] { if method_name == 'type_name' { return ast.string_type } @@ -2111,12 +2111,12 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { if m := c.table.find_method(left_sym, method_name) { method = m has_method = true - if left_sym.kind == .interface_ && m.from_embedded_type != 0 { + if left_sym.kind == .interface && m.from_embedded_type != 0 { is_method_from_embed = true node.from_embed_types = [m.from_embedded_type] } } else { - if final_left_sym.kind in [.struct, .sum_type, .interface_, .array] { + if final_left_sym.kind in [.struct, .sum_type, .interface, .array] { mut parent_type := ast.void_type match final_left_sym.info { ast.Struct, ast.SumType, ast.Interface { @@ -2134,7 +2134,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { method = m has_method = true is_generic = true - if left_sym.kind == .interface_ && m.from_embedded_type != 0 { + if left_sym.kind == .interface && m.from_embedded_type != 0 { is_method_from_embed = true node.from_embed_types = [m.from_embedded_type] } @@ -2166,7 +2166,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { if !has_method { // TODO: str methods if method_name == 'str' { - if left_sym.kind == .interface_ { + if left_sym.kind == .interface { iname := left_sym.name c.error('interface `${iname}` does not have a .str() method. Use typeof() instead', node.pos) @@ -2216,7 +2216,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { } // registers if the arg must be passed by ref to disable auto deref args arg.should_be_ptr = param.typ.is_ptr() && !param.is_mut - if c.table.sym(param.typ).kind == .interface_ { + if c.table.sym(param.typ).kind == .interface { // cannot hide interface expected type to make possible to pass its interface type automatically earg_types << if targ.idx() != param.typ.idx() { param.typ } else { targ } } else { @@ -2273,7 +2273,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { return info.func.return_type } } - if left_sym.kind in [.struct, .aggregate, .interface_, .sum_type] { + if left_sym.kind in [.struct, .aggregate, .interface, .sum_type] { if c.smartcast_mut_pos != token.Pos{} { c.note('smartcasting requires either an immutable value, or an explicit mut keyword before the value', c.smartcast_mut_pos) @@ -2480,7 +2480,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { typ := c.expr(mut arg.expr) if i == node.args.len - 1 { if c.table.sym(typ).kind == .array && arg.expr !is ast.ArrayDecompose - && c.table.sym(expected_type).kind !in [.sum_type, .interface_] + && c.table.sym(expected_type).kind !in [.sum_type, .interface] && !param.typ.has_flag(.generic) && expected_type != typ { styp := c.table.type_to_str(typ) elem_styp := c.table.type_to_str(expected_type) @@ -2564,11 +2564,11 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { } } // Handle expected interface - if final_arg_sym.kind == .interface_ { + if final_arg_sym.kind == .interface { if c.type_implements(got_arg_typ, final_arg_typ, arg.expr.pos()) { if !got_arg_typ.is_any_kind_of_pointer() && !c.inside_unsafe { got_arg_typ_sym := c.table.sym(got_arg_typ) - if got_arg_typ_sym.kind != .interface_ { + if got_arg_typ_sym.kind != .interface { c.mark_as_referenced(mut &arg.expr, true) } } @@ -2582,7 +2582,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { } continue } - if final_arg_sym.kind == .none_ && param.typ.has_flag(.generic) { + if final_arg_sym.kind == .none && param.typ.has_flag(.generic) { c.error('cannot use `none` as generic argument', arg.pos) } if param.typ.is_ptr() && !arg.typ.is_any_kind_of_pointer() && arg.expr.is_literal() @@ -2645,7 +2645,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type { } else { method.params[0].typ } - if left_sym.kind == .interface_ && is_method_from_embed && method.return_type.has_flag(.generic) + if left_sym.kind == .interface && is_method_from_embed && method.return_type.has_flag(.generic) && method.generic_names.len == 0 { method.generic_names = c.table.get_generic_names((rec_sym.info as ast.Interface).generic_types) } diff --git a/vlib/v/checker/for.v b/vlib/v/checker/for.v index 7b9795f8f588fb..76563fb02e4830 100644 --- a/vlib/v/checker/for.v +++ b/vlib/v/checker/for.v @@ -287,7 +287,7 @@ fn (mut c Checker) for_stmt(mut node ast.ForStmt) { if mut node.cond is ast.InfixExpr { if node.cond.op == .key_is { if node.cond.right is ast.TypeNode && node.cond.left in [ast.Ident, ast.SelectorExpr] { - if c.table.type_kind(node.cond.left_type) in [.sum_type, .interface_] { + if c.table.type_kind(node.cond.left_type) in [.sum_type, .interface] { c.smartcast(mut node.cond.left, node.cond.left_type, node.cond.right_type, mut node.scope, false) } diff --git a/vlib/v/checker/if.v b/vlib/v/checker/if.v index f1892ae877cf66..08de2bce35f266 100644 --- a/vlib/v/checker/if.v +++ b/vlib/v/checker/if.v @@ -13,7 +13,7 @@ fn (mut c Checker) check_compatible_types(left_type ast.Type, right ast.TypeNode return .skip } - if sym.kind == .interface_ { + if sym.kind == .interface { checked_type := c.unwrap_generic(left_type) return if c.table.does_type_implement_interface(checked_type, right_type) { .eval @@ -585,8 +585,8 @@ fn (mut c Checker) smartcast_if_conds(mut node ast.Expr, mut scope ast.Scope) { if left_sym.kind == .aggregate { expr_type = (left_sym.info as ast.Aggregate).sum_type } - if left_sym.kind == .interface_ { - if right_sym.kind != .interface_ { + if left_sym.kind == .interface { + if right_sym.kind != .interface { c.type_implements(right_type, expr_type, node.pos) } } else if !c.check_types(right_type, expr_type) && left_sym.kind != .sum_type { @@ -608,14 +608,14 @@ fn (mut c Checker) smartcast_if_conds(mut node ast.Expr, mut scope ast.Scope) { } // TODO: Add check for sum types in a way that it doesn't break a lot of compiler code if mut node.left is ast.Ident - && (left_sym.kind == .interface_ && right_sym.kind != .interface_) { + && (left_sym.kind == .interface && right_sym.kind != .interface) { v := scope.find_var(node.left.name) or { &ast.Var{} } if v.is_mut && !node.left.is_mut { c.error('smart casting a mutable interface value requires `if mut ${node.left.name} is ...`', node.left.pos) } } - if left_sym.kind in [.interface_, .sum_type] { + if left_sym.kind in [.interface, .sum_type] { c.smartcast(mut node.left, node.left_type, right_type, mut scope, is_comptime) } diff --git a/vlib/v/checker/infix.v b/vlib/v/checker/infix.v index 3f02136d7923ad..a0460377ed9efe 100644 --- a/vlib/v/checker/infix.v +++ b/vlib/v/checker/infix.v @@ -104,7 +104,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { left_pos := node.left.pos() right_pos := node.right.pos() left_right_pos := left_pos.extend(right_pos) - if left_sym.kind == .none_ && right_sym.kind == .none_ { + if left_sym.kind == .none && right_sym.kind == .none { c.invalid_operator_error(node.op, left_type, right_type, left_right_pos) } if left_sym.kind == .multi_return && right_sym.kind == .multi_return { @@ -232,7 +232,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { .key_in, .not_in { match right_final_sym.kind { .array { - if left_sym.kind !in [.sum_type, .interface_] { + if left_sym.kind !in [.sum_type, .interface] { elem_type := right_final_sym.array_info().elem_type if node.left.is_auto_deref_var() { left_type = left_type.deref() @@ -270,7 +270,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { node.left_type = map_info.key_type } .array_fixed { - if left_sym.kind !in [.sum_type, .interface_] { + if left_sym.kind !in [.sum_type, .interface] { elem_type := right_final_sym.array_fixed_info().elem_type c.check_expected(left_type, elem_type) or { c.error('left operand to `${node.op}` does not match the fixed array element type: ${err.msg()}', @@ -307,13 +307,13 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { if mut right_sym.info is ast.Alias && (right_sym.info.language != .c && c.mod == c.table.type_to_str(unwrapped_right_type).split('.')[0] && (c.table.sym(right_sym.info.parent_type).is_primitive() - || c.table.sym(right_sym.info.parent_type).kind == .enum_)) { + || c.table.sym(right_sym.info.parent_type).kind == .enum)) { right_sym = c.table.sym(right_sym.info.parent_type) } if mut left_sym.info is ast.Alias && (left_sym.info.language != .c && c.mod == c.table.type_to_str(unwrapped_left_type).split('.')[0] && (c.table.sym(left_sym.info.parent_type).is_primitive() - || c.table.sym(left_sym.info.parent_type).kind == .enum_)) { + || c.table.sym(left_sym.info.parent_type).kind == .enum)) { left_sym = c.table.sym(left_sym.info.parent_type) } @@ -538,7 +538,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { // the below check works as expected left_gen_type := c.unwrap_generic(left_type) gen_sym := c.table.sym(left_gen_type) - need_overload := gen_sym.kind in [.struct, .interface_] + need_overload := gen_sym.kind in [.struct, .interface] if need_overload && !gen_sym.has_method_with_generic_parent('<') && node.op in [.ge, .le] { c.error('cannot use `${node.op}` as `<` operator method is not defined', @@ -609,12 +609,12 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { c.error('unwrapped Option cannot be used in an infix expression', node.pos) } - if left_value_sym.kind == .interface_ { + if left_value_sym.kind == .interface { if right_final_sym.kind != .array { // []Animal << Cat if c.type_implements(right_type, left_value_type, right_pos) { if !right_type.is_any_kind_of_pointer() && !c.inside_unsafe - && right_sym.kind != .interface_ { + && right_sym.kind != .interface { c.mark_as_referenced(mut &node.right, true) } } @@ -755,7 +755,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { if typ != ast.none_type_idx { c.error('`${op}` can only be used to test for none in sql', node.pos) } - } else if left_sym.kind !in [.interface_, .sum_type] + } else if left_sym.kind !in [.interface, .sum_type] && !c.comptime.is_comptime_var(node.left) { c.error('`${op}` can only be used with interfaces and sum types', node.pos) // can be used in sql too, but keep err simple @@ -765,7 +765,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { right_pos) } } else if left_sym.info is ast.Interface { - if typ_sym.kind != .interface_ && !c.type_implements(typ, left_type, right_pos) { + if typ_sym.kind != .interface && !c.type_implements(typ, left_type, right_pos) { c.error("`${typ_sym.name}` doesn't implement interface `${left_sym.name}`", right_pos) } @@ -841,7 +841,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { // TODO: broken !in c.error('string types only have the following operators defined: `==`, `!=`, `<`, `>`, `<=`, `>=`, and `+`', node.pos) - } else if left_sym.kind == .enum_ && right_sym.kind == .enum_ && !eq_ne { + } else if left_sym.kind == .enum && right_sym.kind == .enum && !eq_ne { left_enum := left_sym.info as ast.Enum right_enum := right_sym.info as ast.Enum if left_enum.is_flag && right_enum.is_flag { @@ -870,7 +870,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type { if left_is_option || right_is_option { opt_infix_pos := if left_is_option { left_pos } else { right_pos } if (node.left !in [ast.Ident, ast.SelectorExpr, ast.ComptimeSelector] - || node.op in [.eq, .ne, .lt, .gt, .le, .ge]) && right_sym.kind != .none_ + || node.op in [.eq, .ne, .lt, .gt, .le, .ge]) && right_sym.kind != .none && !c.inside_sql { c.error('unwrapped Option cannot be used in an infix expression', opt_infix_pos) } diff --git a/vlib/v/checker/interface.v b/vlib/v/checker/interface.v index a8e3e3f6ede9e9..e546eceaa3ec48 100644 --- a/vlib/v/checker/interface.v +++ b/vlib/v/checker/interface.v @@ -35,7 +35,7 @@ fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl) { if embed.typ.has_flag(.generic) { has_generic_types = true } - if isym.kind != .interface_ { + if isym.kind != .interface { c.error('interface `${node.name}` tries to embed `${isym.name}`, but `${isym.name}` is not an interface, but `${isym.kind}`', embed.pos) continue diff --git a/vlib/v/checker/match.v b/vlib/v/checker/match.v index d0e8ef35764c71..68c91946a5ae33 100644 --- a/vlib/v/checker/match.v +++ b/vlib/v/checker/match.v @@ -32,7 +32,7 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { c.check_expr_option_or_result_call(node.cond, cond_type) cond_type_sym := c.table.sym(cond_type) cond_is_option := cond_type.has_flag(.option) - node.is_sum_type = cond_type_sym.kind in [.interface_, .sum_type] + node.is_sum_type = cond_type_sym.kind in [.interface, .sum_type] c.match_exprs(mut node, cond_type_sym) c.expected_type = cond_type mut first_iteration := true @@ -59,7 +59,7 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { c.error('`match` expression with Option type only checks against `none`, to match its value you must unwrap it first `var?`', branch.pos) } - if cond_type_sym.kind == .none_ { + if cond_type_sym.kind == .none { c.error('`none` cannot be a match condition', node.pos) } // If the last statement is an expression, return its type @@ -123,8 +123,8 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { if stmt.typ != ast.error_type { ret_sym := c.table.sym(ret_type) stmt_sym := c.table.sym(stmt.typ) - if ret_sym.kind !in [.sum_type, .interface_] - && stmt_sym.kind in [.sum_type, .interface_] { + if ret_sym.kind !in [.sum_type, .interface] + && stmt_sym.kind in [.sum_type, .interface] { c.error('return type mismatch, it should be `${ret_sym.name}`', stmt.pos) } @@ -140,13 +140,13 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type { expr_typ_sym := c.table.sym(stmt.expr.typ) if need_explicit_cast { if infer_cast_type != stmt.expr.typ - && expr_typ_sym.kind !in [.interface_, .sum_type] { + && expr_typ_sym.kind !in [.interface, .sum_type] { c.error('the type of the last expression in the first match branch was an explicit `${c.table.type_to_str(infer_cast_type)}`, not `${c.table.type_to_str(stmt.expr.typ)}`', stmt.pos) } } else { if infer_cast_type != stmt.expr.typ - && expr_typ_sym.kind !in [.interface_, .sum_type] + && expr_typ_sym.kind !in [.interface, .sum_type] && c.promote_num(stmt.expr.typ, ast.int_type) != ast.int_type { c.error('the type of the last expression of the first match branch was `${c.table.type_to_str(infer_cast_type)}`, which is not compatible with `${c.table.type_to_str(stmt.expr.typ)}`', stmt.pos) @@ -341,7 +341,7 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym if mut expr is ast.RangeExpr { // Allow for `match enum_value { 4..5 { } }`, even though usually int and enum values, // are considered incompatible outside unsafe{}, and are not allowed to be compared directly - if cond_sym.kind != .enum_ && !c.check_types(expr.typ, node.cond_type) { + if cond_sym.kind != .enum && !c.check_types(expr.typ, node.cond_type) { mcstype := c.table.type_to_str(node.cond_type) brstype := c.table.type_to_str(expr.typ) c.add_error_detail('') @@ -425,7 +425,7 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym return } expr_type_sym := c.table.sym(expr_type) - if cond_type_sym.kind == .interface_ { + if cond_type_sym.kind == .interface { // TODO // This generates a memory issue with TCC // Needs to be checked later when TCC errors are fixed @@ -434,7 +434,7 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym expr_pos := expr.pos() if c.type_implements(expr_type, c.expected_type, expr_pos) { if !expr_type.is_any_kind_of_pointer() && !c.inside_unsafe { - if expr_type_sym.kind != .interface_ { + if expr_type_sym.kind != .interface { c.mark_as_referenced(mut &branch.exprs[k], true) } } @@ -463,7 +463,7 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym } // when match is type matching, then register smart cast for every branch if expr_types.len > 0 { - if cond_type_sym.kind in [.sum_type, .interface_] { + if cond_type_sym.kind in [.sum_type, .interface] { mut expr_type := ast.no_type if expr_types.len > 1 { mut agg_name := strings.new_builder(20) diff --git a/vlib/v/checker/orm.v b/vlib/v/checker/orm.v index e83f2a021bb2f9..462ec75a8078e2 100644 --- a/vlib/v/checker/orm.v +++ b/vlib/v/checker/orm.v @@ -410,7 +410,7 @@ fn (mut c Checker) fetch_and_check_orm_fields(info ast.Struct, pos token.Pos, ta is_primitive := field.typ.is_string() || field.typ.is_bool() || field.typ.is_number() is_struct := field_sym.kind == .struct is_array := field_sym.kind == .array - is_enum := field_sym.kind == .enum_ + is_enum := field_sym.kind == .enum mut is_array_of_structs := false if is_array { array_info := field_sym.array_info() diff --git a/vlib/v/checker/return.v b/vlib/v/checker/return.v index 248c81c5fcec82..57eb9ac9b2826b 100644 --- a/vlib/v/checker/return.v +++ b/vlib/v/checker/return.v @@ -225,9 +225,9 @@ fn (mut c Checker) return_stmt(mut node ast.Return) { } } } else { - if exp_type_sym.kind == .interface_ { + if exp_type_sym.kind == .interface { if c.type_implements(got_type, exp_type, node.pos) { - if !got_type.is_any_kind_of_pointer() && got_type_sym.kind != .interface_ + if !got_type.is_any_kind_of_pointer() && got_type_sym.kind != .interface && !c.inside_unsafe { c.mark_as_referenced(mut &node.exprs[expr_idxs[i]], true) } diff --git a/vlib/v/checker/str.v b/vlib/v/checker/str.v index aca820149176ea..186fbe3145d6c5 100644 --- a/vlib/v/checker/str.v +++ b/vlib/v/checker/str.v @@ -31,7 +31,7 @@ fn (mut c Checker) get_default_fmt(ftyp ast.Type, typ ast.Type) u8 { return `s` } if ftyp in [ast.string_type, ast.bool_type] - || sym.kind in [.enum_, .array, .array_fixed, .struct, .map, .multi_return, .sum_type, .interface_, .none_] + || sym.kind in [.enum, .array, .array_fixed, .struct, .map, .multi_return, .sum_type, .interface, .none] || ftyp.has_option_or_result() || sym.has_method('str') { return `s` } else { @@ -105,7 +105,7 @@ fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type { c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`', node.fmt_poss[i]) } - if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct, .interface_, .none_, .map, .sum_type] + if c.table.final_sym(typ).kind in [.array, .array_fixed, .struct, .interface, .none, .map, .sum_type] && fmt in [`E`, `F`, `G`, `e`, `f`, `g`, `d`, `u`, `x`, `X`, `o`, `c`, `p`, `b`, `r`, `R`] && !(typ.is_ptr() && fmt in [`p`, `x`, `X`]) { c.error('illegal format specifier `${fmt:c}` for type `${c.table.get_type_name(ftyp)}`', diff --git a/vlib/v/checker/struct.v b/vlib/v/checker/struct.v index 1b9864cbc33a2c..806a0d6b49124a 100644 --- a/vlib/v/checker/struct.v +++ b/vlib/v/checker/struct.v @@ -201,7 +201,7 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) { .multi_return { c.error('cannot use multi return as field type', field.type_pos) } - .none_ { + .none { c.error('cannot use `none` as field type', field.type_pos) } .map { @@ -234,12 +234,12 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) { } } } - interface_implemented := sym.kind == .interface_ + interface_implemented := sym.kind == .interface && c.type_implements(field.default_expr_typ, field.typ, field.pos) c.check_expected(field.default_expr_typ, field.typ) or { - if sym.kind == .interface_ && interface_implemented { + if sym.kind == .interface && interface_implemented { if !c.inside_unsafe && !field.default_expr_typ.is_any_kind_of_pointer() { - if c.table.sym(field.default_expr_typ).kind != .interface_ { + if c.table.sym(field.default_expr_typ).kind != .interface { c.mark_as_referenced(mut &node.fields[i].default_expr, true) } @@ -533,7 +533,7 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini && type_sym.kind != .placeholder { c.error('cannot initialize builtin type `${type_sym.name}`', node.pos) } - if type_sym.kind == .enum_ && !c.pref.translated && !c.file.is_translated { + if type_sym.kind == .enum && !c.pref.translated && !c.file.is_translated { c.error('cannot initialize enums', node.pos) } } @@ -542,7 +542,7 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini c.error('cast to sum type using `${type_sym.name}(${sexpr})` not `${type_sym.name}{${sexpr}}`', node.pos) } - if type_sym.kind == .interface_ && type_sym.language != .js { + if type_sym.kind == .interface && type_sym.language != .js { c.error('cannot instantiate interface `${type_sym.name}`', node.pos) } if type_sym.info is ast.Alias { @@ -745,9 +745,9 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', node.init_fields[i].expr = right } } - if exp_type_sym.kind == .interface_ { + if exp_type_sym.kind == .interface { if c.type_implements(got_type, exp_type, init_field.pos) { - if !c.inside_unsafe && got_type_sym.kind != .interface_ + if !c.inside_unsafe && got_type_sym.kind != .interface && !got_type.is_any_kind_of_pointer() { c.mark_as_referenced(mut &init_field.expr, true) } @@ -876,7 +876,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.', continue } param_sym := c.table.sym(param.typ) - if param_sym.kind in [.struct, .interface_, .sum_type] { + if param_sym.kind in [.struct, .interface, .sum_type] { c.table.unwrap_generic_type(param.typ, generic_names, struct_sym.info.concrete_types) } } @@ -976,7 +976,7 @@ fn (mut c Checker) check_uninitialized_struct_fields_and_embeds(node ast.StructI } } // Do not allow empty uninitialized interfaces - if sym.kind == .interface_ && !node.has_update_expr && !field.typ.has_flag(.option) + if sym.kind == .interface && !node.has_update_expr && !field.typ.has_flag(.option) && sym.language != .js && !field.attrs.contains('noinit') { // TODO: should be an error instead, but first `ui` needs updating. c.note('interface field `${type_sym.name}.${field.name}` must be initialized', diff --git a/vlib/v/checker/tests/import_mod_as_import_duplicate_err.out b/vlib/v/checker/tests/import_mod_as_import_duplicate_err.out index e1aeede3481cb3..0c437ee865ef3e 100755 --- a/vlib/v/checker/tests/import_mod_as_import_duplicate_err.out +++ b/vlib/v/checker/tests/import_mod_as_import_duplicate_err.out @@ -3,4 +3,4 @@ vlib/v/checker/tests/import_mod_as_import_duplicate_err.vv:2:8: error: `x.json2` 2 | import json | ~~~~ 3 | - 4 | numbers := { \ No newline at end of file + 4 | numbers := { diff --git a/vlib/v/checker/tests/orm_fn_call_with_wrong_return_type.out b/vlib/v/checker/tests/orm_fn_call_with_wrong_return_type.out index 4957e56311a44c..e3d53990013782 100644 --- a/vlib/v/checker/tests/orm_fn_call_with_wrong_return_type.out +++ b/vlib/v/checker/tests/orm_fn_call_with_wrong_return_type.out @@ -1,5 +1,5 @@ vlib/v/checker/tests/orm_fn_call_with_wrong_return_type.vv:52:37: error: ORM: function calls must return only primitive types and time.Time, but `get_second_child` returns `Child` - 50 | + 50 | 51 | steve := sql db { 52 | select from Parent where child == get_second_child() | ~~~~~~~~~~~~~~~~~~ diff --git a/vlib/v/checker/tests/orm_left_side_expr_in_infix_expr_has_no_struct_field_error.out b/vlib/v/checker/tests/orm_left_side_expr_in_infix_expr_has_no_struct_field_error.out index 33c497857c961c..9979e4383d21a4 100644 --- a/vlib/v/checker/tests/orm_left_side_expr_in_infix_expr_has_no_struct_field_error.out +++ b/vlib/v/checker/tests/orm_left_side_expr_in_infix_expr_has_no_struct_field_error.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/orm_left_side_expr_in_infix_expr_has_no_struct_field_error.vv:18:26: error: ORM: left side of the `==` expression must be one of the `User`'s fields. 1 possibility: `id`. - 16 | + 16 | 17 | users := sql db { 18 | select from User where first == second | ~~~~~ diff --git a/vlib/v/checker/tests/orm_table_attributes.out b/vlib/v/checker/tests/orm_table_attributes.out index c23a10d45deaa6..d4ff5274340606 100644 --- a/vlib/v/checker/tests/orm_table_attributes.out +++ b/vlib/v/checker/tests/orm_table_attributes.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/orm_table_attributes.vv:3:1: error: ORM: table attribute must have an argument 1 | import db.sqlite - 2 | + 2 | 3 | @[table] | ~~~~~~~~ 4 | struct Foo { diff --git a/vlib/v/checker/tests/orm_using_non_struct_field_in_order_by_error.out b/vlib/v/checker/tests/orm_using_non_struct_field_in_order_by_error.out index 4968d5d88e164e..4b64425e5c766d 100644 --- a/vlib/v/checker/tests/orm_using_non_struct_field_in_order_by_error.out +++ b/vlib/v/checker/tests/orm_using_non_struct_field_in_order_by_error.out @@ -1,6 +1,6 @@ vlib/v/checker/tests/orm_using_non_struct_field_in_order_by_error.vv:14:29: error: ORM: `User` structure has no field with name `database`. 2 possibilities: `id`, `username`. - 12 | + 12 | 13 | users := sql db { 14 | select from User order by database | ~~~~~~~~ @@ -8,7 +8,7 @@ vlib/v/checker/tests/orm_using_non_struct_field_in_order_by_error.vv:14:29: erro 16 | vlib/v/checker/tests/orm_using_non_struct_field_in_order_by_error.vv:17:2: error: `println` can not print void expressions 15 | }! - 16 | + 16 | 17 | println(users) | ~~~~~~~~~~~~~~ 18 | } diff --git a/vlib/v/comptime/comptimeinfo.v b/vlib/v/comptime/comptimeinfo.v index d32a559b857240..2db852f1991b89 100644 --- a/vlib/v/comptime/comptimeinfo.v +++ b/vlib/v/comptime/comptimeinfo.v @@ -197,7 +197,7 @@ pub fn (mut ct ComptimeInfo) get_comptime_selector_bool_field(field_name string) 'is_chan' { return field_sym.kind == .chan } 'is_struct' { return field_sym.kind == .struct } 'is_alias' { return field_sym.kind == .alias } - 'is_enum' { return field_sym.kind == .enum_ } + 'is_enum' { return field_sym.kind == .enum } else { return false } } } @@ -208,7 +208,7 @@ pub fn (mut ct ComptimeInfo) is_comptime_type(x ast.Type, y ast.ComptimeType) bo .unknown { return false } - .map_ { + .map { return x_kind == .map } .string { @@ -225,7 +225,7 @@ pub fn (mut ct ComptimeInfo) is_comptime_type(x ast.Type, y ast.ComptimeType) bo return x_kind == .struct } .iface { - return x_kind == .interface_ + return x_kind == .interface } .array { return x_kind in [.array, .array_fixed] @@ -239,8 +239,8 @@ pub fn (mut ct ComptimeInfo) is_comptime_type(x ast.Type, y ast.ComptimeType) bo .sum_type { return x_kind == .sum_type } - .enum_ { - return x_kind == .enum_ + .enum { + return x_kind == .enum } .alias { return x_kind == .alias diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index 9da60e5e85c306..f236ce18867a4e 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -13,15 +13,15 @@ import v.token // SymbolKind categorizes the symbols it documents. // The names are intentionally not in order as a guide when sorting the nodes. pub enum SymbolKind { - none_ + none const_group constant variable function method - interface_ + interface typedef - enum_ + enum enum_field struct struct_field @@ -88,9 +88,9 @@ pub fn (sk SymbolKind) str() string { return match sk { .const_group { 'Constants' } .function, .method { 'fn' } - .interface_ { 'interface' } + .interface { 'interface' } .typedef { 'type' } - .enum_ { 'enum' } + .enum { 'enum' } .struct { 'struct' } else { '' } } @@ -225,7 +225,7 @@ pub fn (mut d Doc) stmt(mut stmt ast.Stmt, filename string) !DocNode { } } ast.EnumDecl { - node.kind = .enum_ + node.kind = .enum if d.extract_vars { for mut field in stmt.fields { ret_type := if field.has_expr { @@ -252,7 +252,7 @@ pub fn (mut d Doc) stmt(mut stmt ast.Stmt, filename string) !DocNode { } } ast.InterfaceDecl { - node.kind = .interface_ + node.kind = .interface } ast.StructDecl { node.kind = .struct @@ -492,7 +492,7 @@ pub fn (mut d Doc) file_asts(mut file_asts []ast.File) ! { d.head = DocNode{ name: module_name content: 'module ${module_name}' - kind: .none_ + kind: .none } } else if file_ast.mod.name != d.orig_mod_name { continue @@ -507,12 +507,12 @@ pub fn (mut d Doc) file_asts(mut file_asts []ast.File) ! { d.contents[name] = node continue } - if d.contents[name].kind == .typedef && node.kind !in [.typedef, .none_] { + if d.contents[name].kind == .typedef && node.kind !in [.typedef, .none] { old_children := d.contents[name].children.clone() d.contents[name] = node d.contents[name].children = old_children } - if d.contents[name].kind != .none_ || node.kind == .none_ { + if d.contents[name].kind != .none || node.kind == .none { d.contents[name].children << node.children d.contents[name].children.arrange() } diff --git a/vlib/v/eval/expr.c.v b/vlib/v/eval/expr.c.v index 486ce26941ee1c..0b29bc976639f1 100644 --- a/vlib/v/eval/expr.c.v +++ b/vlib/v/eval/expr.c.v @@ -398,7 +398,7 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object { } } } - } else if e.table.sym(expr.typ).kind in [.interface_, .sum_type] { + } else if e.table.sym(expr.typ).kind in [.interface, .sum_type] { if e.pref.is_verbose { util.show_compiler_message('warning:', pos: expr.pos diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 615d0645998799..9254e9b2df87c7 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -791,11 +791,11 @@ pub fn (mut f Fmt) expr(node_ ast.Expr) { .array_fixed { f.write('\$array_fixed') } .struct { f.write('\$struct') } .iface { f.write('\$interface') } - .map_ { f.write('\$map') } + .map { f.write('\$map') } .int { f.write('\$int') } .float { f.write('\$float') } .sum_type { f.write('\$sumtype') } - .enum_ { f.write('\$enum') } + .enum { f.write('\$enum') } .alias { f.write('\$alias') } .function { f.write('\$function') } .option { f.write('\$option') } diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index ff42e960061ab0..0d9afed5d17cdd 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -999,7 +999,7 @@ fn (mut g Gen) gen_array_contains_methods() { } else if elem_kind == .struct && elem_is_not_ptr { ptr_typ := g.equality_fn(elem_type) fn_builder.writeln('\t\tif (${ptr_typ}_struct_eq(((${elem_type_str}*)a.data)[i], v)) {') - } else if elem_kind == .interface_ && elem_is_not_ptr { + } else if elem_kind == .interface && elem_is_not_ptr { ptr_typ := g.equality_fn(elem_type) fn_builder.writeln('\t\tif (${ptr_typ}_interface_eq(((${elem_type_str}*)a.data)[i], v)) {') } else if elem_kind == .sum_type && elem_is_not_ptr { @@ -1038,7 +1038,7 @@ fn (mut g Gen) gen_array_contains_methods() { } else if elem_kind == .struct && elem_is_not_ptr { ptr_typ := g.equality_fn(elem_type) fn_builder.writeln('\t\tif (${ptr_typ}_struct_eq(a[i], v)) {') - } else if elem_kind == .interface_ && elem_is_not_ptr { + } else if elem_kind == .interface && elem_is_not_ptr { ptr_typ := g.equality_fn(elem_type) fn_builder.writeln('\t\tif (${ptr_typ}_interface_eq(a[i], v)) {') } else if elem_kind == .sum_type && elem_is_not_ptr { @@ -1080,12 +1080,11 @@ fn (mut g Gen) gen_array_contains(left_type ast.Type, left ast.Expr, right_type left_sym.array_fixed_info().elem_type } if (right.is_auto_deref_var() && !elem_typ.is_ptr()) - || (g.table.sym(elem_typ).kind !in [.interface_, .sum_type, .struct] && right is ast.Ident - && right.info is ast.IdentVar - && g.table.sym(right.obj.typ).kind in [.interface_, .sum_type]) { + || (g.table.sym(elem_typ).kind !in [.interface, .sum_type, .struct] && right is ast.Ident + && right.info is ast.IdentVar && g.table.sym(right.obj.typ).kind in [.interface, .sum_type]) { g.write('*') } - if g.table.sym(elem_typ).kind in [.interface_, .sum_type] { + if g.table.sym(elem_typ).kind in [.interface, .sum_type] { g.expr_with_cast(right, right_type, elem_typ) } else { g.expr(right) @@ -1134,7 +1133,7 @@ fn (mut g Gen) gen_array_index_methods() { } else if elem_sym.kind == .struct && !info.elem_type.is_ptr() { ptr_typ := g.equality_fn(info.elem_type) fn_builder.writeln('\t\tif (${ptr_typ}_struct_eq(*pelem, v)) {') - } else if elem_sym.kind == .interface_ { + } else if elem_sym.kind == .interface { ptr_typ := g.equality_fn(info.elem_type) if info.elem_type.is_ptr() { fn_builder.writeln('\t\tif (${ptr_typ}_interface_eq(**pelem, *v)) {') @@ -1176,10 +1175,10 @@ fn (mut g Gen) gen_array_index(node ast.CallExpr) { elem_typ := g.table.sym(node.left_type).array_info().elem_type // auto deref var is redundant for interfaces and sum types. if node.args[0].expr.is_auto_deref_var() - && g.table.sym(elem_typ).kind !in [.interface_, .sum_type] { + && g.table.sym(elem_typ).kind !in [.interface, .sum_type] { g.write('*') } - if g.table.sym(elem_typ).kind in [.interface_, .sum_type] { + if g.table.sym(elem_typ).kind in [.interface, .sum_type] { g.expr_with_cast(node.args[0].expr, node.args[0].typ, elem_typ) } else { g.expr(node.args[0].expr) diff --git a/vlib/v/gen/c/auto_eq_methods.v b/vlib/v/gen/c/auto_eq_methods.v index 745e07d23fa5a2..fda77744e1e524 100644 --- a/vlib/v/gen/c/auto_eq_methods.v +++ b/vlib/v/gen/c/auto_eq_methods.v @@ -39,7 +39,7 @@ fn (mut g Gen) gen_equality_fns() { .alias { g.gen_alias_equality_fn(needed_typ) } - .interface_ { + .interface { g.gen_interface_equality_fn(needed_typ) } else { @@ -246,7 +246,7 @@ fn (mut g Gen) gen_struct_equality_fn(left_type ast.Type) string { fn_builder.write_string('${eq_fn}_alias_eq(${left_arg}, ${right_arg})') } else if field_type.sym.kind == .function && !field.typ.has_flag(.option) { fn_builder.write_string('*((voidptr*)(${left_arg})) == *((voidptr*)(${right_arg}))') - } else if field_type.sym.kind == .interface_ + } else if field_type.sym.kind == .interface && (!field.typ.has_flag(.option) || !field.typ.is_ptr()) { ptr := if field.typ.is_ptr() { '*'.repeat(field.typ.nr_muls()) } else { '' } eq_fn := g.gen_interface_equality_fn(field.typ) @@ -304,7 +304,7 @@ fn (mut g Gen) gen_alias_equality_fn(left_type ast.Type) string { } else if sym.kind == .struct && !left.typ.is_ptr() { eq_fn := g.gen_struct_equality_fn(info.parent_type) fn_builder.writeln('\treturn ${eq_fn}_struct_eq(${left_var}, ${right_var});') - } else if sym.kind == .interface_ && !left.typ.is_ptr() { + } else if sym.kind == .interface && !left.typ.is_ptr() { eq_fn := g.gen_interface_equality_fn(info.parent_type) fn_builder.writeln('\treturn ${eq_fn}_interface_eq(${left_var}, ${right_var});') } else if sym.kind == .array && !left.typ.is_ptr() { @@ -372,7 +372,7 @@ fn (mut g Gen) gen_array_equality_fn(left_type ast.Type) string { } else if elem.sym.kind == .struct && !elem.typ.is_ptr() { eq_fn := g.gen_struct_equality_fn(elem.typ) fn_builder.writeln('\t\tif (!${eq_fn}_struct_eq(((${ptr_elem_styp}*)${left_data})[i], ((${ptr_elem_styp}*)${right_data})[i])) {') - } else if elem.sym.kind == .interface_ && !elem.typ.is_ptr() { + } else if elem.sym.kind == .interface && !elem.typ.is_ptr() { eq_fn := g.gen_interface_equality_fn(elem.typ) fn_builder.writeln('\t\tif (!${eq_fn}_interface_eq(((${ptr_elem_styp}*)${left_data})[i], ((${ptr_elem_styp}*)${right_data})[i])) {') } else if elem.sym.kind == .array && !elem.typ.is_ptr() { @@ -431,7 +431,7 @@ fn (mut g Gen) gen_fixed_array_equality_fn(left_type ast.Type) string { } else if elem.sym.kind == .struct && !elem.typ.is_ptr() { eq_fn := g.gen_struct_equality_fn(elem.typ) fn_builder.writeln('\t\tif (!${eq_fn}_struct_eq(${left}[i], ${right}[i])) {') - } else if elem.sym.kind == .interface_ && !elem.typ.is_ptr() { + } else if elem.sym.kind == .interface && !elem.typ.is_ptr() { eq_fn := g.gen_interface_equality_fn(elem.typ) fn_builder.writeln('\t\tif (!${eq_fn}_interface_eq(${left}[i], ${right}[i])) {') } else if elem.sym.kind == .array && !elem.typ.is_ptr() { @@ -511,7 +511,7 @@ fn (mut g Gen) gen_map_equality_fn(left_type ast.Type) string { eq_fn := g.gen_struct_equality_fn(value.typ) fn_builder.writeln('\t\tif (!${eq_fn}_struct_eq(*(${ptr_value_styp}*)map_get(${b}, k, &(${ptr_value_styp}[]){ 0 }), v)) {') } - .interface_ { + .interface { eq_fn := g.gen_interface_equality_fn(value.typ) fn_builder.writeln('\t\tif (!${eq_fn}_interface_eq(*(${ptr_value_styp}*)map_get(${b}, k, &(${ptr_value_styp}[]){ 0 }), v)) {') } diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index 32a7d466c28207..b83630776a3fd2 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -903,7 +903,7 @@ fn (g &Gen) type_to_fmt(typ ast.Type) StrIntpType { sym := g.table.sym(typ) if typ.is_int_valptr() || typ.is_float_valptr() { return .si_s - } else if sym.kind in [.struct, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type, + } else if sym.kind in [.struct, .array, .array_fixed, .map, .bool, .enum, .interface, .sum_type, .function, .alias, .chan, .thread] { return .si_s } else if sym.kind == .string { @@ -1076,7 +1076,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, lang ast.Language, styp strin funcprefix += ' ? _SLIT("nil") : ' // struct, floats and ints have a special case through the _str function if !ftyp_noshared.has_flag(.option) - && sym.kind !in [.struct, .alias, .enum_, .sum_type, .map, .interface_] + && sym.kind !in [.struct, .alias, .enum, .sum_type, .map, .interface] && !field.typ.is_int_valptr() && !field.typ.is_float_valptr() { funcprefix += '*' } @@ -1106,7 +1106,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, lang ast.Language, styp strin if field.typ in ast.charptr_types { fn_body.write_string('tos4((byteptr)${func})') } else { - if field.typ.is_ptr() && sym.kind in [.struct, .interface_] { + if field.typ.is_ptr() && sym.kind in [.struct, .interface] { funcprefix += '(indent_count > 25)? _SLIT("") : ' } // eprintln('>>> caller_should_free: ${caller_should_free:6s} | funcprefix: $funcprefix | func: $func') @@ -1157,12 +1157,12 @@ fn struct_auto_str_func(sym &ast.TypeSymbol, lang ast.Language, _field_type ast. final_field_name := if lang == .c { field_name } else { c_name(field_name) } op := if lang == .c { '->' } else { '.' } prefix := if sym.is_c_struct() { c_struct_ptr(sym, _field_type, expects_ptr) } else { deref } - if sym.kind == .enum_ { + if sym.kind == .enum { return '${fn_name}(${deref}(it${op}${final_field_name}))', true } else if _field_type.has_flag(.option) || should_use_indent_func(sym.kind) { obj := '${prefix}it${op}${final_field_name}${sufix}' if has_custom_str { - if sym.kind == .interface_ && (sym.info as ast.Interface).defines_method('str') { + if sym.kind == .interface && (sym.info as ast.Interface).defines_method('str') { iface_obj := '${prefix}it${op}${final_field_name}${sufix}' dot := if field_type.is_ptr() { '->' } else { '.' } return '${fn_name.trim_string_right('_str')}_name_table[${iface_obj}${dot}_typ]._method_str(${iface_obj}${dot}_object)', true @@ -1241,7 +1241,7 @@ fn data_str(x StrIntpType) string { } fn should_use_indent_func(kind ast.Kind) bool { - return kind in [.struct, .alias, .array, .array_fixed, .map, .sum_type, .interface_] + return kind in [.struct, .alias, .array, .array_fixed, .map, .sum_type, .interface] } fn (mut g Gen) get_enum_type_idx_from_fn_name(fn_name string) (string, int) { diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 8b4df4a0ca3807..08404d918572f0 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1044,7 +1044,7 @@ pub fn (mut g Gen) write_typeof_functions() { g.writeln('\t}') } g.writeln('}') - } else if sym.kind == .interface_ { + } else if sym.kind == .interface { if sym.info !is ast.Interface { continue } @@ -1618,12 +1618,12 @@ static inline void __${sym.cname}_pushval(${sym.cname} ch, ${push_arg} val) { // Generating interfaces after all the common types have been defined // to prevent generating interface struct before definition of field types for sym in g.table.type_symbols { - if sym.kind == .interface_ && sym.name !in builtins { + if sym.kind == .interface && sym.name !in builtins { g.write_interface_typedef(sym) } } for sym in g.table.type_symbols { - if sym.kind == .interface_ && sym.name !in builtins { + if sym.kind == .interface && sym.name !in builtins { g.write_interface_typesymbol_declaration(sym) } } @@ -2044,7 +2044,7 @@ fn (mut g Gen) expr_with_tmp_var(expr ast.Expr, expr_typ ast.Type, ret_typ ast.T mut styp := g.base_type(ret_typ) g.empty_line = true - if g.table.sym(expr_typ).kind == .none_ { + if g.table.sym(expr_typ).kind == .none { g.write('${g.typ(ret_typ)} ${tmp_var} = ') g.gen_option_error(ret_typ, expr) g.writeln(';') @@ -2513,7 +2513,7 @@ fn (mut g Gen) write_sumtype_casting_fn(fun SumtypeCastingFn) { type_cname = embed_sym.cname } field_styp := g.typ(field.typ) - if got_sym.kind in [.sum_type, .interface_] { + if got_sym.kind in [.sum_type, .interface] { // the field is already a wrapped pointer; we shouldn't wrap it once again sb.write_string(', .${c_name(field.name)} = ptr->${field.name}') } else { @@ -2580,7 +2580,7 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ g.write('.msg))') return } - if got_sym.kind == .none_ && exp_sym.idx == ast.error_type_idx { + if got_sym.kind == .none && exp_sym.idx == ast.error_type_idx { g.expr(expr) return } @@ -3338,7 +3338,7 @@ fn (mut g Gen) map_fn_ptrs(key_typ ast.TypeSymbol) (string, string, string, stri key_eq_fn = '&map_eq_int_2' clone_fn = '&map_clone_int_2' } - .int, .i32, .u32, .rune, .f32, .enum_ { + .int, .i32, .u32, .rune, .f32, .enum { // XTODO i64 hash_fn = '&map_hash_int_4' key_eq_fn = '&map_eq_int_4' @@ -3896,7 +3896,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) { g.write('(') } if node.or_block.kind != .absent && g.table.sym(node.typ).kind != .chan { - is_ptr := sym.kind in [.interface_, .sum_type] + is_ptr := sym.kind in [.interface, .sum_type] stmt_str := g.go_before_last_stmt().trim_space() styp := g.typ(g.unwrap_generic(node.typ)) g.empty_line = true @@ -3970,10 +3970,10 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) { if f := g.table.find_field_with_embeds(sym, node.field_name) { field_sym := g.table.sym(f.typ) field_typ = f.typ - if sym.kind in [.interface_, .sum_type] { + if sym.kind in [.interface, .sum_type] { g.write('(*(') } - if field_sym.kind in [.sum_type, .interface_] { + if field_sym.kind in [.sum_type, .interface] { if !prevent_sum_type_unwrapping_once { // check first if field is sum type because scope searching is expensive scope := g.file.scope.innermost(node.pos.pos) @@ -3987,7 +3987,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) { g.write('*') } cast_sym := g.table.sym(g.unwrap_generic(typ)) - if field_sym.kind == .interface_ && cast_sym.kind == .interface_ { + if field_sym.kind == .interface && cast_sym.kind == .interface { ptr := '*'.repeat(field.typ.nr_muls()) dot := if node.expr_type.is_ptr() { '->' } else { '.' } g.write('I_${field_sym.cname}_as_I_${cast_sym.cname}(${ptr}${node.expr}${dot}${node.field_name}))') @@ -4099,7 +4099,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) { return } } else { - if sym.kind in [.interface_, .sum_type] { + if sym.kind in [.interface, .sum_type] { g.write('(*(') } } @@ -4169,7 +4169,7 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) { if sum_type_deref_field != '' { g.write('${sum_type_dot}${sum_type_deref_field})') } - if sym.kind in [.interface_, .sum_type] { + if sym.kind in [.interface, .sum_type] { g.write('))') } } @@ -4293,10 +4293,10 @@ fn (mut g Gen) debugger_stmt(node ast.DebuggerStmt) { sym := g.table.sym(cast_sym.info.types[g.aggregate_type_idx]) func = g.get_str_fn(cast_sym.info.types[g.aggregate_type_idx]) param_var.write_string('${obj.name}${dot}_${sym.cname}') - } else if obj_sym.kind == .interface_ && cast_sym.kind == .interface_ { + } else if obj_sym.kind == .interface && cast_sym.kind == .interface { ptr := '*'.repeat(obj.typ.nr_muls()) param_var.write_string('I_${obj_sym.cname}_as_I_${cast_sym.cname}(${ptr}${obj.name})') - } else if obj_sym.kind in [.sum_type, .interface_] { + } else if obj_sym.kind in [.sum_type, .interface] { param_var.write_string('${obj.name}') if opt_cast { param_var.write_string('.data)') @@ -4994,7 +4994,7 @@ fn (mut g Gen) ident(node ast.Ident) { } } else if (g.inside_interface_deref && g.table.is_interface_var(node.obj)) || node.obj.ct_type_var == .smartcast - || (obj_sym.kind == .interface_ + || (obj_sym.kind == .interface && g.table.type_kind(node.obj.typ) == .any) { g.write('*') } else if is_option { @@ -5004,7 +5004,7 @@ fn (mut g Gen) ident(node ast.Ident) { for i, typ in node.obj.smartcasts { is_option_unwrap := is_option && typ == node.obj.typ.clear_flag(.option) cast_sym := g.table.sym(g.unwrap_generic(typ)) - if obj_sym.kind == .interface_ && cast_sym.kind == .interface_ { + if obj_sym.kind == .interface && cast_sym.kind == .interface { ptr := '*'.repeat(node.obj.typ.nr_muls()) g.write('I_${obj_sym.cname}_as_I_${cast_sym.cname}(${ptr}${node.name})') } else { @@ -5049,7 +5049,7 @@ fn (mut g Gen) ident(node ast.Ident) { cur_variant_sym)}') } } else if !is_option_unwrap - && obj_sym.kind in [.sum_type, .interface_] { + && obj_sym.kind in [.sum_type, .interface] { g.write('${dot}_${cast_sym.cname}') } } @@ -5116,7 +5116,7 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) { || node.expr is ast.ComptimeSelector { expr_type = g.unwrap_generic(g.comptime.get_comptime_var_type(node.expr)) } - if sym.kind in [.sum_type, .interface_] { + if sym.kind in [.sum_type, .interface] { if node.typ.has_flag(.option) && node.expr is ast.None { g.gen_option_error(node.typ, node.expr) } else if node.typ.has_flag(.option) { @@ -5656,7 +5656,7 @@ fn (mut g Gen) return_stmt(node ast.Return) { } if mr_info.types[i].has_flag(.option) { g.expr_with_opt(expr, node.types[i], mr_info.types[i]) - } else if g.table.sym(mr_info.types[i]).kind in [.sum_type, .interface_] { + } else if g.table.sym(mr_info.types[i]).kind in [.sum_type, .interface] { g.expr_with_cast(expr, node.types[i], mr_info.types[i]) } else { g.expr(expr) @@ -5750,7 +5750,7 @@ fn (mut g Gen) return_stmt(node ast.Return) { g.writeln('${ret_typ} ${tmpvar};') g.write('_result_ok(&(${styp}[]) { ') if !fn_ret_type.is_ptr() && node.types[0].is_ptr() { - if !((node.exprs[0] is ast.Ident && !g.is_amp) || sym.kind == .interface_) { + if !((node.exprs[0] is ast.Ident && !g.is_amp) || sym.kind == .interface) { g.write('*') } } @@ -5812,7 +5812,7 @@ fn (mut g Gen) return_stmt(node ast.Return) { g.write(var_str.trim('&')) } else if g.fn_decl.return_type.has_flag(.option) { g.expr_with_opt(expr0, node.types[0], g.fn_decl.return_type) - } else if g.table.sym(g.fn_decl.return_type).kind in [.sum_type, .interface_] { + } else if g.table.sym(g.fn_decl.return_type).kind in [.sum_type, .interface] { g.expr_with_cast(expr0, node.types[0], g.fn_decl.return_type) } else { g.write('*') @@ -6480,7 +6480,7 @@ fn (mut g Gen) write_debug_calls_typeof_functions() { } g.writeln('\tv_typeof_sumtype_${sym.cname}(0);') } - if sym.kind == .interface_ { + if sym.kind == .interface { if sym.info !is ast.Interface { continue } @@ -6678,7 +6678,7 @@ fn (mut g Gen) write_builtin_types() { // everything except builtin will get sorted for builtin_name in builtins { sym := g.table.sym_by_idx(g.table.type_idxs[builtin_name]) - if sym.kind == .interface_ { + if sym.kind == .interface { g.write_interface_typedef(sym) g.write_interface_typesymbol_declaration(sym) } else { @@ -6714,7 +6714,7 @@ fn (mut g Gen) write_types(symbols []&ast.TypeSymbol) { if sym.name.starts_with('C.') { continue } - if sym.kind == .none_ { + if sym.kind == .none { g.type_definitions.writeln('struct none {') g.type_definitions.writeln('\tEMPTY_STRUCT_DECLARATION;') g.type_definitions.writeln('};') @@ -6950,7 +6950,7 @@ fn (mut g Gen) sort_structs(typesa []&ast.TypeSymbol) []&ast.TypeSymbol { } // loop over types for sym in typesa { - if sym.kind == .interface_ { + if sym.kind == .interface { dep_graph.add(sym.name, []) continue } @@ -7323,7 +7323,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string { .sum_type { return '{0}' // g.type_default_sumtype(typ, sym) } - .interface_, .multi_return, .thread { + .interface, .multi_return, .thread { return '{0}' } .alias { @@ -7399,7 +7399,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string { field_name := c_name(field.name) if field.has_default_expr { mut expr_str := '' - if field_sym.kind in [.sum_type, .interface_] { + if field_sym.kind in [.sum_type, .interface] { expr_str = g.expr_string_with_cast(field.default_expr, field.default_expr_typ, field.typ) } else if field_sym.is_array_fixed() && g.inside_global_decl { @@ -7475,7 +7475,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string { return init_str } } - .enum_ { + .enum { // returns the enum's first value if enum_decl := g.table.enum_decls[sym.name] { return if enum_decl.fields[0].expr is ast.EmptyExpr { @@ -7614,7 +7614,7 @@ fn (mut g Gen) as_cast(node ast.AsCast) { variant_sym := g.table.sym(variant) g.as_cast_type_names[idx] = variant_sym.name } - } else if expr_type_sym.kind == .interface_ && sym.kind == .interface_ { + } else if expr_type_sym.kind == .interface && sym.kind == .interface { g.write('I_${expr_type_sym.cname}_as_I_${sym.cname}(') if node.expr_type.is_ptr() { g.write('*') @@ -7714,7 +7714,7 @@ fn (mut g Gen) interface_table() string { mut sb := strings.new_builder(100) mut conversion_functions := strings.new_builder(100) for isym in g.table.type_symbols { - if isym.kind != .interface_ { + if isym.kind != .interface { continue } if isym.info !is ast.Interface { @@ -8154,7 +8154,7 @@ pub fn (mut g Gen) contains_ptr(el_typ ast.Type) bool { return true } match sym.kind { - .i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .rune, .bool, .enum_ { + .i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .rune, .bool, .enum { return false } .array_fixed { diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index ec15740e085551..13b2cd480add45 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -10,7 +10,7 @@ import v.pref import v.comptime fn (mut g Gen) comptime_selector(node ast.ComptimeSelector) { - is_interface_field := g.table.sym(node.left_type).kind == .interface_ + is_interface_field := g.table.sym(node.left_type).kind == .interface if is_interface_field { g.write('*(') } @@ -553,7 +553,7 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) (bool, bool) { got_type := g.unwrap_generic((cond.right as ast.TypeNode).typ) got_sym := g.table.sym(got_type) - if got_sym.kind == .interface_ && got_sym.info is ast.Interface { + if got_sym.kind == .interface && got_sym.info is ast.Interface { is_true := exp_type.has_flag(.option) == got_type.has_flag(.option) && g.table.does_type_implement_interface(exp_type, got_type) if cond.op == .key_is { @@ -889,7 +889,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { g.pop_comptime_info() } } else if node.kind == .fields { - if sym.kind in [.struct, .interface_] { + if sym.kind in [.struct, .interface] { fields := match sym.info { ast.Struct { sym.info.fields @@ -940,7 +940,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { g.writeln('\t${node.val_var}.is_chan = ${field_sym.kind == .chan};') g.writeln('\t${node.val_var}.is_struct = ${field_sym.kind == .struct};') g.writeln('\t${node.val_var}.is_alias = ${field_sym.kind == .alias};') - g.writeln('\t${node.val_var}.is_enum = ${field_sym.kind == .enum_};') + g.writeln('\t${node.val_var}.is_enum = ${field_sym.kind == .enum};') g.writeln('\t${node.val_var}.indirections = ${field.typ.nr_muls()};') @@ -953,7 +953,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) { g.pop_comptime_info() } } else if node.kind == .values { - if sym.kind == .enum_ { + if sym.kind == .enum { if sym.info is ast.Enum { if sym.info.vals.len > 0 { g.writeln('\tEnumData ${node.val_var} = {0};') diff --git a/vlib/v/gen/c/dumpexpr.v b/vlib/v/gen/c/dumpexpr.v index fb3f1d5b1405a8..d75ab21536c3d1 100644 --- a/vlib/v/gen/c/dumpexpr.v +++ b/vlib/v/gen/c/dumpexpr.v @@ -109,7 +109,7 @@ fn (mut g Gen) dump_expr_definitions() { mut ptr_asterisk := if is_ptr { '*'.repeat(typ.nr_muls()) } else { '' } mut str_dumparg_type := '' mut str_dumparg_ret_type := '' - if dump_sym.kind == .none_ { + if dump_sym.kind == .none { str_dumparg_type = 'IError' + ptr_asterisk } else { if typ.has_flag(.option) { @@ -174,7 +174,7 @@ fn (mut g Gen) dump_expr_definitions() { surrounder.add('\tstring sline = int_str(line);', '\tstring_free(&sline);') if dump_sym.kind == .function { surrounder.add('\tstring value = ${to_string_fn_name}();', '\tstring_free(&value);') - } else if dump_sym.kind == .none_ { + } else if dump_sym.kind == .none { surrounder.add('\tstring value = _SLIT("none");', '\tstring_free(&value);') } else if is_ptr { if typ.has_flag(.option) { diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 9316db4cb16648..cbac82b09d9328 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1382,7 +1382,7 @@ fn (mut g Gen) resolve_comptime_args(func ast.Fn, mut node_ ast.CallExpr, concre && param_typ_sym.kind == .array { ctyp = g.get_generic_array_element_type(arg_sym.info as ast.Array) comptime_args[k] = ctyp - } else if arg_sym.kind in [.struct, .interface_, .sum_type] { + } else if arg_sym.kind in [.struct, .interface, .sum_type] { mut generic_types := []ast.Type{} match arg_sym.info { ast.Struct, ast.Interface, ast.SumType { @@ -1643,18 +1643,18 @@ fn (mut g Gen) method_call(node ast.CallExpr) { g.gen_fixed_array_wait(node) return } - if left_sym.kind in [.sum_type, .interface_] { + if left_sym.kind in [.sum_type, .interface] { prefix_name := if left_sym.kind == .sum_type { 'sumtype' } else { 'interface' } match node.name { 'type_name' { - if left_sym.kind in [.sum_type, .interface_] { + if left_sym.kind in [.sum_type, .interface] { g.conversion_function_call('charptr_vstring_literal( /* ${left_sym.name} */ v_typeof_${prefix_name}_${typ_sym.cname}', ')', node) return } } 'type_idx' { - if left_sym.kind in [.sum_type, .interface_] { + if left_sym.kind in [.sum_type, .interface] { g.conversion_function_call('/* ${left_sym.name} */ v_typeof_${prefix_name}_idx_${typ_sym.cname}', '', node) return @@ -1750,8 +1750,8 @@ fn (mut g Gen) method_call(node ast.CallExpr) { g.write('${name}(') } } - is_interface := left_sym.kind == .interface_ - && g.table.sym(node.receiver_type).kind == .interface_ + is_interface := left_sym.kind == .interface + && g.table.sym(node.receiver_type).kind == .interface if node.receiver_type.is_ptr() && (!left_type.is_ptr() || node.from_embed_types.len != 0 || (left_type.has_flag(.shared_f) && node.name != 'str')) { // The receiver is a reference, but the caller provided a value @@ -1905,7 +1905,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) { fn_typ = field.typ } } - if left_sym.kind == .interface_ || fn_typ.is_ptr() { + if left_sym.kind == .interface || fn_typ.is_ptr() { is_interface_call = true g.write('(*') } @@ -2060,7 +2060,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) { if typ != ast.string_type || g.comptime.comptime_for_method != unsafe { nil } { expr := node.args[0].expr typ_sym := g.table.sym(typ) - if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method('str') { + if typ_sym.kind == .interface && (typ_sym.info as ast.Interface).defines_method('str') { g.write('${c_fn_name(print_method)}(') rec_type_name := util.no_dots(g.cc_type(typ, false)) g.write('${c_name(rec_type_name)}_name_table[') @@ -2460,7 +2460,7 @@ fn (mut g Gen) call_args(node ast.CallExpr) { } else if arg.expr.obj.smartcasts.len > 0 { exp_sym := g.table.sym(expected_types[i]) orig_sym := g.table.sym(arg.expr.obj.orig_type) - if orig_sym.kind != .interface_ && (exp_sym.kind != .sum_type + if orig_sym.kind != .interface && (exp_sym.kind != .sum_type && expected_types[i] != arg.expr.obj.orig_type) { expected_types[i] = g.unwrap_generic(arg.expr.obj.smartcasts.last()) cast_sym := g.table.sym(expected_types[i]) @@ -2700,7 +2700,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as g.write('&/*sum*/') g.expr(arg.expr) return - } else if arg_sym.kind == .interface_ && exp_sym.kind == .interface_ + } else if arg_sym.kind == .interface && exp_sym.kind == .interface && arg.expr in [ast.Ident, ast.SelectorExpr] { g.write('&/*iface*/') g.expr(arg.expr) @@ -2718,7 +2718,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as expected_type } deref_sym := g.table.sym(expected_deref_type) - if arg_typ_sym.kind != .function && deref_sym.kind !in [.sum_type, .interface_] + if arg_typ_sym.kind != .function && deref_sym.kind !in [.sum_type, .interface] && lang != .c { if arg.expr.is_lvalue() { if expected_type.has_flag(.option) { @@ -2744,7 +2744,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as g.write('(voidptr)') } else { needs_closing = true - if arg_typ_sym.kind in [.sum_type, .interface_] { + if arg_typ_sym.kind in [.sum_type, .interface] { atype = arg_typ } g.write('ADDR(${g.typ(atype)}/*qq*/, ') @@ -2763,7 +2763,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as g.write(')') return } - } else if arg_sym.kind == .interface_ && exp_sym.kind == .interface_ { + } else if arg_sym.kind == .interface && exp_sym.kind == .interface { if exp_is_ptr && !arg_is_ptr { g.write('&') } diff --git a/vlib/v/gen/c/infix.v b/vlib/v/gen/c/infix.v index ea942fe5690e1c..f960b793039496 100644 --- a/vlib/v/gen/c/infix.v +++ b/vlib/v/gen/c/infix.v @@ -83,7 +83,7 @@ fn (mut g Gen) infix_expr_arrow_op(node ast.InfixExpr) { } g.expr(node.left) g.write(', ') - if g.table.sym(elem_type).kind in [.sum_type, .interface_] { + if g.table.sym(elem_type).kind in [.sum_type, .interface] { g.expr_with_cast(node.right, node.right_type, elem_type) } else { g.expr(node.right) @@ -159,7 +159,7 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) { g.expr(node.right) g.write(')') } else if left.unaliased.idx() == right.unaliased.idx() - && left.sym.kind in [.array, .array_fixed, .alias, .map, .struct, .sum_type, .interface_] { + && left.sym.kind in [.array, .array_fixed, .alias, .map, .struct, .sum_type, .interface] { if g.pref.translated && !g.is_builtin_mod { g.gen_plain_infix_expr(node) return @@ -291,7 +291,7 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) { g.expr(node.right) g.write(')') } - .interface_ { + .interface { ptr_typ := g.equality_fn(left.unaliased) if node.op == .ne { g.write('!') @@ -466,10 +466,10 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) { g.write('!') } if right.unaliased_sym.kind == .array { - if left.sym.kind in [.sum_type, .interface_] { + if left.sym.kind in [.sum_type, .interface] { if node.right is ast.ArrayInit { if node.right.exprs.len > 0 - && g.table.sym(node.right.expr_types[0]).kind !in [.sum_type, .interface_] { + && g.table.sym(node.right.expr_types[0]).kind !in [.sum_type, .interface] { mut infix_exprs := []ast.InfixExpr{} for i in 0 .. node.right.exprs.len { infix_exprs << ast.InfixExpr{ @@ -527,7 +527,7 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) { g.write(')') return } - } else if elem_type_.sym.kind == .interface_ { + } else if elem_type_.sym.kind == .interface { new_node_left := ast.CastExpr{ arg: ast.empty_expr typ: elem_type @@ -566,7 +566,7 @@ fn (mut g Gen) infix_expr_in_op(node ast.InfixExpr) { } g.write(')') } else if right.unaliased_sym.kind == .array_fixed { - if left.sym.kind in [.sum_type, .interface_] { + if left.sym.kind in [.sum_type, .interface] { if node.right is ast.ArrayInit { if node.right.exprs.len > 0 { mut infix_exprs := []ast.InfixExpr{} @@ -635,11 +635,11 @@ fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, right ast.ArrayInit) { mut elem_sym := g.table.sym(right.elem_type) for i, array_expr in right.exprs { match elem_sym.kind { - .string, .alias, .sum_type, .map, .interface_, .array, .struct { + .string, .alias, .sum_type, .map, .interface, .array, .struct { if elem_sym.kind == .string { g.write('string__eq(') if left.is_auto_deref_var() || (left is ast.Ident && left.info is ast.IdentVar - && g.table.sym(left.obj.typ).kind in [.interface_, .sum_type]) { + && g.table.sym(left.obj.typ).kind in [.interface, .sum_type]) { g.write('*') } } else { @@ -650,7 +650,7 @@ fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, right ast.ArrayInit) { g.write('${ptr_typ}_sumtype_eq(') } else if elem_sym.kind == .map { g.write('${ptr_typ}_map_eq(') - } else if elem_sym.kind == .interface_ { + } else if elem_sym.kind == .interface { g.write('${ptr_typ}_interface_eq(') } else if elem_sym.kind == .array { g.write('${ptr_typ}_arr_eq(') @@ -688,7 +688,7 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) { left_sym = g.table.sym(parent_left_type) } right_sym := g.table.sym(node.right_type) - if left_sym.kind == .interface_ && right_sym.kind == .interface_ { + if left_sym.kind == .interface && right_sym.kind == .interface { g.gen_interface_is_op(node) return } @@ -709,7 +709,7 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) { } else { g.write('.') } - if left_sym.kind == .interface_ { + if left_sym.kind == .interface { g.write('_typ ${cmp_op} ') // `_Animal_Dog_index` sub_type := match node.right { diff --git a/vlib/v/gen/c/json.v b/vlib/v/gen/c/json.v index b12d231a24eb72..83f934c815245a 100644 --- a/vlib/v/gen/c/json.v +++ b/vlib/v/gen/c/json.v @@ -168,7 +168,7 @@ ${enc_fn_dec} { } else if psym.info is ast.Struct { enc.writeln('\to = cJSON_CreateObject();') g.gen_struct_enc_dec(utyp, psym.info, ret_styp, mut enc, mut dec, '') - } else if psym.kind == .enum_ { + } else if psym.kind == .enum { g.gen_enum_enc_dec(utyp, psym, mut enc, mut dec) } else if psym.kind == .sum_type { verror('json: ${sym.name} aliased sumtypes does not work at the moment') @@ -190,7 +190,7 @@ ${enc_fn_dec} { verror('json: ${sym.name} is not a sumtype') } g.gen_sumtype_enc_dec(utyp, sym, mut enc, mut dec, ret_styp) - } else if sym.kind == .enum_ { + } else if sym.kind == .enum { g.gen_enum_enc_dec(utyp, sym, mut enc, mut dec) } else if utyp.has_flag(.option) && (is_js_prim(g.typ(utyp.clear_flag(.option))) || sym.info !is ast.Struct) { @@ -408,7 +408,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st variant_sym := g.table.sym(variant) variant_symbols << variant_sym at_least_one_prim = at_least_one_prim || is_js_prim(variant_typ) - || variant_sym.kind == .enum_ || variant_sym.name == 'time.Time' + || variant_sym.kind == .enum || variant_sym.name == 'time.Time' unmangled_variant_name := variant_sym.name.split('.').last() // TODO: Do not generate dec/enc for 'time.Time', because we handle it by saving it as u64 @@ -421,7 +421,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st // ENCODING enc.writeln('\tif (${var_data}${field_op}_typ == ${variant.idx()}) {') $if json_no_inline_sumtypes ? { - if variant_sym.kind == .enum_ { + if variant_sym.kind == .enum { enc.writeln('\t\tcJSON_AddItemToObject(o, "${unmangled_variant_name}", ${js_enc_name('u64')}(*${var_data}${field_op}_${variant_typ}));') } else if variant_sym.name == 'time.Time' { enc.writeln('\t\tcJSON_AddItemToObject(o, "${unmangled_variant_name}", ${js_enc_name('i64')}(${var_data}${field_op}_${variant_typ}->__v_unix));') @@ -431,7 +431,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st } $else { if is_js_prim(variant_typ) { enc.writeln('\t\tcJSON_free(o); return ${js_enc_name(variant_typ)}(*${var_data}${field_op}_${variant_typ});') - } else if variant_sym.kind == .enum_ { + } else if variant_sym.kind == .enum { if g.is_enum_as_int(variant_sym) { enc.writeln('\t\tcJSON_free(o); return ${js_enc_name('u64')}(*${var_data}${field_op}_${variant_typ});') } else { @@ -470,7 +470,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st if is_js_prim(variant_typ) { gen_js_get(ret_styp, tmp, unmangled_variant_name, mut dec, true) dec.writeln('\t\t${variant_typ} value = ${js_dec_name(variant_typ)}(jsonroot_${tmp});') - } else if variant_sym.kind == .enum_ { + } else if variant_sym.kind == .enum { if g.is_enum_as_int(variant_sym) { gen_js_get(ret_styp, tmp, unmangled_variant_name, mut dec, true) dec.writeln('\t\t${variant_typ} value = ${js_dec_name('u64')}(jsonroot_${tmp});') @@ -503,7 +503,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st dec.writeln('\t\t\t\t${variant_typ} ${tmp} = time__unix(${js_dec_name('i64')}(jsonroot_${tmp}));') dec.writeln('\t\t\t\t${prefix}res = ${variant_typ}_to_sumtype_${sym.cname}(&${tmp});') dec.writeln('\t\t\t}') - } else if !is_js_prim(variant_typ) && variant_sym.kind != .enum_ { + } else if !is_js_prim(variant_typ) && variant_sym.kind != .enum { dec.writeln('\t\t\tif (strcmp("${unmangled_variant_name}", ${type_var}) == 0 && ${variant_sym.kind == .array} == cJSON_IsArray(root)) {') dec.writeln('\t\t\t\t${result_name}_${variant_typ} ${tmp} = ${js_dec_name(variant_typ)}(root);') dec.writeln('\t\t\t\tif (${tmp}.is_error) {') @@ -540,7 +540,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st } for i, var_t in variant_types { - if variant_symbols[i].kind == .enum_ { + if variant_symbols[i].kind == .enum { if number_is_met { var_num := var_t.replace('__', '.') last_num := last_number_type.replace('__', '.') @@ -703,7 +703,7 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st dec.writeln('\t\t${prefix}${op}${c_name(field.name)} = ${g.expr_string(field.default_expr)};') } dec.writeln('\t}') - } else if field_sym.kind == .enum_ { + } else if field_sym.kind == .enum { tmp := g.new_tmp_var() is_option_field := field.typ.has_flag(.option) if field.typ.has_flag(.option) { @@ -870,7 +870,7 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st } } } - if field_sym.kind == .enum_ { + if field_sym.kind == .enum { if g.is_enum_as_int(field_sym) { if field.typ.has_flag(.option) { enc.writeln('${indent}\tcJSON_AddItemToObject(o, "${name}", json__encode_u64(*${prefix_enc}${op}${c_name(field.name)}.data));\n') diff --git a/vlib/v/gen/c/match.v b/vlib/v/gen/c/match.v index 2ac7db779b8ea4..2ac71f0f8b3192 100644 --- a/vlib/v/gen/c/match.v +++ b/vlib/v/gen/c/match.v @@ -11,7 +11,7 @@ fn (mut g Gen) need_tmp_var_in_match(node ast.MatchExpr) bool { || node.return_type.has_option_or_result() { return true } - if g.table.final_sym(node.cond_type).kind == .enum_ && node.branches.len > 5 { + if g.table.final_sym(node.cond_type).kind == .enum && node.branches.len > 5 { return true } if g.need_tmp_var_in_expr(node.cond) { @@ -140,7 +140,7 @@ fn (mut g Gen) match_expr(node ast.MatchExpr) { if can_be_a_switch && !is_expr && g.loop_depth == 0 && g.fn_decl != unsafe { nil } && cond_fsym.is_int() { g.match_expr_switch(node, is_expr, cond_var, tmp_var, cond_fsym) - } else if cond_fsym.kind == .enum_ && g.loop_depth == 0 && node.branches.len > 5 + } else if cond_fsym.kind == .enum && g.loop_depth == 0 && node.branches.len > 5 && g.fn_decl != unsafe { nil } { // do not optimize while in top-level g.match_expr_switch(node, is_expr, cond_var, tmp_var, cond_fsym) @@ -213,7 +213,7 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str } else { g.expr(cur_expr) } - } else if cond_sym.kind == .interface_ { + } else if cond_sym.kind == .interface { if cur_expr is ast.TypeNode { branch_sym := g.table.sym(g.unwrap_generic(cur_expr.typ)) g.write('${dot_or_ptr}_typ == _${cond_sym.cname}_${branch_sym.cname}_index') diff --git a/vlib/v/gen/c/orm.v b/vlib/v/gen/c/orm.v index 79de8fc0a6c34d..a4ca2d6ce29721 100644 --- a/vlib/v/gen/c/orm.v +++ b/vlib/v/gen/c/orm.v @@ -161,7 +161,7 @@ fn (mut g Gen) write_orm_create_table(node ast.SqlStmtLine, table_name string, c sym := g.table.sym(field.typ) typ := match true { sym.name == 'time.Time' { '_const_orm__time_' } - sym.kind == .enum_ { '_const_orm__enum_' } + sym.kind == .enum { '_const_orm__enum_' } else { field.typ.idx().str() } } g.writeln('(orm__TableField){') @@ -414,7 +414,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v if typ == 'time__Time' { ctyp = 'time__Time' typ = 'time' - } else if sym.kind == .enum_ { + } else if sym.kind == .enum { typ = 'i64' } var := '${node.object_var}${member_access_type}${c_name(field.name)}' @@ -903,7 +903,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re if sym.kind == .struct { types << int(ast.int_type).str() continue - } else if sym.kind == .enum_ { + } else if sym.kind == .enum { types << '_const_orm__enum_' continue } @@ -1138,7 +1138,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re g.writeln('else') g.writeln('\t_option_ok(${prim_var}->_${sym.cname}, (_option *)&${field_var}, sizeof(${sym.cname}));') fields_idx++ - } else if sym.kind == .enum_ { + } else if sym.kind == .enum { mut typ := sym.cname g.writeln('${tmp}.${c_name(field.name)} = (${typ}) (*(${array_get_call_code}._i64));') fields_idx++ diff --git a/vlib/v/gen/c/reflection.v b/vlib/v/gen/c/reflection.v index 120b194086f28e..5ef3e56cdc3d8f 100644 --- a/vlib/v/gen/c/reflection.v +++ b/vlib/v/gen/c/reflection.v @@ -80,11 +80,7 @@ fn (mut g Gen) gen_reflection_fn(node ast.Fn) string { // gen_reflection_sym generates C code for TypeSymbol struct @[inline] fn (mut g Gen) gen_reflection_sym(tsym ast.TypeSymbol) string { - kind_name := if tsym.kind in [.none_, .enum_, .interface_] { - tsym.kind.str() + '_' - } else { - tsym.kind.str() - } + kind_name := tsym.kind.str() info := g.gen_reflection_sym_info(tsym) methods := g.gen_function_array(tsym.methods) return '(${cprefix}TypeSymbol){.name=_SLIT("${tsym.name}"),.idx=${tsym.idx},.parent_idx=${tsym.parent_idx},.language=${cprefix}VLanguage__${tsym.language},.kind=${cprefix}VKind__${kind_name},.info=${info},.methods=${methods}}' @@ -166,7 +162,7 @@ fn (mut g Gen) gen_reflection_sym_info(tsym ast.TypeSymbol) string { s := 'ADDR(${cprefix}Struct,(((${cprefix}Struct){.parent_idx=${(tsym.info as ast.Struct).parent_type.idx()},.attrs=${attrs},.fields=${fields}})))' return '(${cprefix}TypeInfo){._${cprefix}Struct=memdup(${s},sizeof(${cprefix}Struct)),._typ=${g.table.find_type_idx('v.reflection.Struct')}}' } - .enum_ { + .enum { info := tsym.info as ast.Enum vals := g.gen_string_array(info.vals) s := 'ADDR(${cprefix}Enum,(((${cprefix}Enum){.vals=${vals},.is_flag=${info.is_flag}})))' @@ -177,7 +173,7 @@ fn (mut g Gen) gen_reflection_sym_info(tsym ast.TypeSymbol) string { s := 'ADDR(${cprefix}Function,${g.gen_reflection_fn(info.func)})' return '(${cprefix}TypeInfo){._${cprefix}Function=memdup(${s},sizeof(${cprefix}Function)),._typ=${g.table.find_type_idx('v.reflection.Function')}}' } - .interface_ { + .interface { name := tsym.name.all_after_last('.') info := tsym.info as ast.Interface methods := g.gen_function_array(info.methods) diff --git a/vlib/v/gen/c/spawn_and_go.v b/vlib/v/gen/c/spawn_and_go.v index 31488a6236c609..32117885aa0c59 100644 --- a/vlib/v/gen/c/spawn_and_go.v +++ b/vlib/v/gen/c/spawn_and_go.v @@ -95,7 +95,7 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) { } else { name } - if !(expr.is_method && (g.table.sym(expr.receiver_type).kind == .interface_ + if !(expr.is_method && (g.table.sym(expr.receiver_type).kind == .interface || (g.table.sym(expr.receiver_type).kind == .struct && expr.is_field))) { g.writeln('${arg_tmp_var}${dot}fn = ${fn_name};') } @@ -310,7 +310,7 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) { if expr.is_method { unwrapped_rec_type := g.unwrap_generic(expr.receiver_type) typ_sym := g.table.sym(unwrapped_rec_type) - if typ_sym.kind == .interface_ + if typ_sym.kind == .interface && (typ_sym.info as ast.Interface).defines_method(expr.name) { rec_cc_type := g.cc_type(unwrapped_rec_type, false) receiver_type_name := util.no_dots(rec_cc_type) @@ -339,8 +339,8 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) { if expr.args.len > 0 { mut has_cast := false for i in 0 .. expr.args.len { - if g.table.sym(expr.expected_arg_types[i]).kind == .interface_ - && g.table.sym(expr.args[i].typ).kind != .interface_ { + if g.table.sym(expr.expected_arg_types[i]).kind == .interface + && g.table.sym(expr.args[i].typ).kind != .interface { has_cast = true break } diff --git a/vlib/v/gen/c/str.v b/vlib/v/gen/c/str.v index 0234858be7e8ed..3d81d2308efca1 100644 --- a/vlib/v/gen/c/str.v +++ b/vlib/v/gen/c/str.v @@ -91,7 +91,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { } else if typ == ast.bool_type { g.expr(expr) g.write(' ? _SLIT("true") : _SLIT("false")') - } else if sym.kind == .none_ || typ == ast.void_type.set_flag(.option) { + } else if sym.kind == .none || typ == ast.void_type.set_flag(.option) { if expr is ast.CallExpr { stmt_str := g.go_before_last_stmt() g.expr(expr) @@ -99,7 +99,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { g.write(stmt_str) } g.write('_SLIT("")') - } else if sym.kind == .enum_ { + } else if sym.kind == .enum { if expr !is ast.EnumVal { str_fn_name := g.get_str_fn(typ) g.write('${str_fn_name}(') @@ -114,7 +114,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { g.write('")') } } else if sym_has_str_method - || sym.kind in [.array, .array_fixed, .map, .struct, .multi_return, .sum_type, .interface_] { + || sym.kind in [.array, .array_fixed, .map, .struct, .multi_return, .sum_type, .interface] { unwrap_option := expr is ast.Ident && expr.or_expr.kind == .propagate_option exp_typ := if unwrap_option { typ.clear_flag(.option) } else { typ } is_ptr := exp_typ.is_ptr() diff --git a/vlib/v/gen/c/str_intp.v b/vlib/v/gen/c/str_intp.v index 8227d46ebe0160..f4ade4adbba1cf 100644 --- a/vlib/v/gen/c/str_intp.v +++ b/vlib/v/gen/c/str_intp.v @@ -37,7 +37,7 @@ fn (mut g Gen) get_default_fmt(ftyp ast.Type, typ ast.Type) u8 { return `s` } if ftyp in [ast.string_type, ast.bool_type] - || sym.kind in [.enum_, .array, .array_fixed, .struct, .map, .multi_return, .sum_type, .interface_, .none_] + || sym.kind in [.enum, .array, .array_fixed, .struct, .map, .multi_return, .sum_type, .interface, .none] || ftyp.has_option_or_result() || sym.has_method('str') { return `s` } else { @@ -179,7 +179,7 @@ fn (mut g Gen) str_val(node ast.StringInterLiteral, i int, fmts []u8) { } g.expr(expr) } - } else if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method('str') { + } else if typ_sym.kind == .interface && (typ_sym.info as ast.Interface).defines_method('str') { rec_type_name := util.no_dots(g.cc_type(typ, false)) g.write('${c_name(rec_type_name)}_name_table[') g.expr(expr) diff --git a/vlib/v/gen/c/struct.v b/vlib/v/gen/c/struct.v index 15bc2d3ceb84cb..543c1966b19315 100644 --- a/vlib/v/gen/c/struct.v +++ b/vlib/v/gen/c/struct.v @@ -429,7 +429,7 @@ fn (mut g Gen) zero_struct_field(field ast.StructField) bool { } g.write('.${field_name} = ') if field.has_default_expr { - if sym.kind in [.sum_type, .interface_] { + if sym.kind in [.sum_type, .interface] { if field.typ.has_flag(.option) { g.expr_with_opt(field.default_expr, field.default_expr_typ, field.typ) } else { diff --git a/vlib/v/gen/golang/golang.v b/vlib/v/gen/golang/golang.v index bf537ef529f696..ed30117cdf8e4d 100644 --- a/vlib/v/gen/golang/golang.v +++ b/vlib/v/gen/golang/golang.v @@ -668,11 +668,11 @@ pub fn (mut f Gen) expr(node_ ast.Expr) { .array_fixed { f.write('\$array_fixed') } .struct { f.write('\$struct') } .iface { f.write('\$interface') } - .map_ { f.write('\$map') } + .map { f.write('\$map') } .int { f.write('\$int') } .float { f.write('\$float') } .sum_type { f.write('\$sumtype') } - .enum_ { f.write('\$enum') } + .enum { f.write('\$enum') } .alias { f.write('\$alias') } .function { f.write('\$function') } .option { f.write('\$option') } diff --git a/vlib/v/gen/js/auto_str_methods.v b/vlib/v/gen/js/auto_str_methods.v index 06247465a31f92..809d97df48f813 100644 --- a/vlib/v/gen/js/auto_str_methods.v +++ b/vlib/v/gen/js/auto_str_methods.v @@ -184,7 +184,7 @@ pub fn data_str(x StrIntpType) string { const si_s_code = '0xfe10' fn should_use_indent_func(kind ast.Kind) bool { - return kind in [.struct, .alias, .array, .array_fixed, .map, .sum_type, .interface_] + return kind in [.struct, .alias, .array, .array_fixed, .map, .sum_type, .interface] } fn (mut g JsGen) gen_str_default(sym ast.TypeSymbol, styp string, str_fn_name string) { @@ -662,7 +662,7 @@ fn (g &JsGen) type_to_fmt(typ ast.Type) StrIntpType { sym := g.table.sym(typ) if typ.is_int_valptr() || typ.is_float_valptr() { return .si_s - } else if sym.kind in [.struct, .array, .array_fixed, .map, .bool, .enum_, .interface_, .sum_type, + } else if sym.kind in [.struct, .array, .array_fixed, .map, .bool, .enum, .interface, .sum_type, .function, .alias, .chan] { return .si_s } else if sym.kind == .string { @@ -788,7 +788,7 @@ fn (mut g JsGen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name st fn struct_auto_str_func(mut g JsGen, sym &ast.TypeSymbol, field_type ast.Type, fn_name string, field_name string) string { has_custom_str, expects_ptr, _ := sym.str_method_info() - if sym.kind == .enum_ { + if sym.kind == .enum { return '${fn_name}(it.${g.js_name(field_name)})' } else if should_use_indent_func(sym.kind) { mut obj := 'it.${g.js_name(field_name)}' diff --git a/vlib/v/gen/js/builtin_types.v b/vlib/v/gen/js/builtin_types.v index 6021393c51dc14..2df29ade6f60e0 100644 --- a/vlib/v/gen/js/builtin_types.v +++ b/vlib/v/gen/js/builtin_types.v @@ -168,7 +168,7 @@ pub fn (mut g JsGen) doc_typ(t ast.Type) string { .bool { styp = '${g.sym_to_js_typ(sym)}' } - .none_ { + .none { styp = 'undefined' } .string, .char { @@ -217,7 +217,7 @@ pub fn (mut g JsGen) doc_typ(t ast.Type) string { name := g.js_name(fsym.name) styp += '${name}' } - .enum_ { + .enum { // Note: We could declare them as TypeScript enums but TS doesn't like // our namespacing so these break if declared in a different module. // Until this is fixed, We need to use the type of an enum's members @@ -229,7 +229,7 @@ pub fn (mut g JsGen) doc_typ(t ast.Type) string { info := sym.info as ast.FnType styp = g.fn_typ(info.func.params, info.func.return_type) } - .interface_ { + .interface { styp = g.js_name(sym.name) } .rune { diff --git a/vlib/v/gen/js/comptime.v b/vlib/v/gen/js/comptime.v index 87ecb13bd45ad4..292febee000def 100644 --- a/vlib/v/gen/js/comptime.v +++ b/vlib/v/gen/js/comptime.v @@ -95,7 +95,7 @@ fn (mut g JsGen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool { // Handle `$if x is Interface {` // mut matches_interface := 'false' if left is ast.TypeNode && cond.right is ast.TypeNode - && g.table.sym(got_type).kind == .interface_ { + && g.table.sym(got_type).kind == .interface { // `$if Foo is Interface {` interface_sym := g.table.sym(got_type) if interface_sym.info is ast.Interface { diff --git a/vlib/v/gen/js/fn.v b/vlib/v/gen/js/fn.v index d9e182ea7beee9..cf939049848f5f 100644 --- a/vlib/v/gen/js/fn.v +++ b/vlib/v/gen/js/fn.v @@ -250,7 +250,7 @@ fn (mut g JsGen) method_call(node ast.CallExpr) { typ_sym = g.table.sym(unwrapped_rec_type) } - if typ_sym.kind == .interface_ && (typ_sym.info as ast.Interface).defines_method(node.name) { + if typ_sym.kind == .interface && (typ_sym.info as ast.Interface).defines_method(node.name) { g.expr(it.left) g.gen_deref_ptr(it.left_type) g.write('.${it.name}(') @@ -501,7 +501,7 @@ enum FnGenType { fn (g &JsGen) fn_gen_type(it &ast.FnDecl) FnGenType { if it.is_method && g.table.sym(it.params[0].typ).kind == .alias { return .alias_method - } else if it.is_method && g.table.sym(it.params[0].typ).kind == .interface_ { + } else if it.is_method && g.table.sym(it.params[0].typ).kind == .interface { return .iface_method } else if it.is_method || it.no_body { return .struct_method @@ -686,7 +686,7 @@ fn (mut g JsGen) gen_method_decl(it ast.FnDecl, typ FnGenType) { g.writeln('${arg_name} = new array(new array_buffer({arr: ${arg_name},len: new int(${arg_name}.length),index_start: new int(0)}));') } else { asym := g.table.sym(arg.typ) - if asym.kind != .interface_ && asym.language != .js { + if asym.kind != .interface && asym.language != .js { if arg.typ.is_ptr() || arg.is_mut { g.writeln('${arg_name} = new \$ref(${arg_name})') } @@ -826,7 +826,7 @@ fn (mut g JsGen) gen_anon_fn(mut fun ast.AnonFn) { } else { asym := g.table.sym(arg.typ) - if arg.typ.is_ptr() || (arg.is_mut && asym.kind != .interface_ && asym.language != .js) { + if arg.typ.is_ptr() || (arg.is_mut && asym.kind != .interface && asym.language != .js) { g.writeln('${arg_name} = new \$ref(${arg_name})') } } diff --git a/vlib/v/gen/js/js.v b/vlib/v/gen/js/js.v index 0ca666275a9e91..5803c9f0206e5a 100644 --- a/vlib/v/gen/js/js.v +++ b/vlib/v/gen/js/js.v @@ -2170,7 +2170,7 @@ fn (mut g JsGen) need_tmp_var_in_match(node ast.MatchExpr) bool { if sym.kind == .multi_return { return false } - if cond_sym.kind == .enum_ && node.branches.len > 5 { + if cond_sym.kind == .enum && node.branches.len > 5 { return true } for branch in node.branches { @@ -2403,7 +2403,7 @@ fn (mut g JsGen) match_expr(node ast.MatchExpr) { cond_fsym := g.table.final_sym(node.cond_type) if node.is_sum_type { g.match_expr_sumtype(node, is_expr, cond_var, tmp_var) - } else if cond_fsym.kind == .enum_ && !g.inside_loop && node.branches.len > 5 + } else if cond_fsym.kind == .enum && !g.inside_loop && node.branches.len > 5 && unsafe { g.fn_decl != 0 } { // do not optimize while in top-level g.match_expr_switch(node, is_expr, cond_var, tmp_var, cond_fsym) } else { @@ -2489,7 +2489,7 @@ fn (mut g JsGen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var M } else { g.write('if (') } - if sym.kind == .sum_type || sym.kind == .interface_ { + if sym.kind == .sum_type || sym.kind == .interface { x := branch.exprs[sumtype_index] if x is ast.TypeNode { @@ -2519,7 +2519,7 @@ fn (mut g JsGen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var M g.write(' instanceof ') g.expr(branch.exprs[sumtype_index]) } - } else if sym.kind == .interface_ { + } else if sym.kind == .interface { if !sym.name.starts_with('JS.') { g.write('.val') } @@ -3273,7 +3273,7 @@ fn (mut g JsGen) gen_selector_expr(it ast.SelectorExpr) { g.expr(it.expr) mut ltyp := it.expr_type lsym := g.table.sym(ltyp) - if lsym.kind != .interface_ && lsym.language != .js { + if lsym.kind != .interface && lsym.language != .js { for ltyp.is_ptr() { g.write('.val') ltyp = ltyp.deref() @@ -3345,15 +3345,15 @@ fn (mut g JsGen) gen_struct_init(it ast.StructInit) { if name.contains('<') { name = name[0..name.index('<') or { name.len }] } - if it.init_fields.len == 0 && type_sym.kind != .interface_ { + if it.init_fields.len == 0 && type_sym.kind != .interface { if type_sym.kind == .struct && type_sym.language == .js { g.write('{}') } else { g.write('new ${g.js_name(name)}({})') } - } else if it.init_fields.len == 0 && type_sym.kind == .interface_ { + } else if it.init_fields.len == 0 && type_sym.kind == .interface { g.write('new ${g.js_name(name)}()') // JS interfaces can be instantiated with default ctor - } else if type_sym.kind == .interface_ && it.init_fields.len != 0 { + } else if type_sym.kind == .interface && it.init_fields.len != 0 { g.writeln('(function () {') g.inc_indent() g.writeln('let tmp = new ${g.js_name(name)}()') diff --git a/vlib/v/gen/js/str.v b/vlib/v/gen/js/str.v index 1fc4335a4e2073..e685afd16d9453 100644 --- a/vlib/v/gen/js/str.v +++ b/vlib/v/gen/js/str.v @@ -32,9 +32,9 @@ fn (mut g JsGen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { g.write('new string((') g.expr(expr) g.write(').valueOf()? "true" : "false")') - } else if sym.kind == .none_ { + } else if sym.kind == .none { g.write('new string("")') - } else if sym.kind == .enum_ { + } else if sym.kind == .enum { if expr !is ast.EnumVal { str_fn_name := g.gen_str_for_type(typ) g.write('${str_fn_name}(') @@ -46,7 +46,7 @@ fn (mut g JsGen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { g.write('")') } } else if sym_has_str_method - || sym.kind in [.array, .array_fixed, .map, .struct, .multi_return, .sum_type, .interface_] { + || sym.kind in [.array, .array_fixed, .map, .struct, .multi_return, .sum_type, .interface] { is_ptr := typ.is_ptr() str_fn_name := g.gen_str_for_type(typ) g.write('${str_fn_name}(') @@ -101,9 +101,9 @@ fn (mut g JsGen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { } else if typ == ast.bool_type { g.expr(expr) g.write('.valueOf()? new string("true") : new string("false")') - } else if sym.kind == .none_ { + } else if sym.kind == .none { g.write('new string("")') - } else if sym.kind == .enum_ { + } else if sym.kind == .enum { if expr !is ast.EnumVal { str_fn_name := g.get_str_fn(typ) g.write('${str_fn_name}(') @@ -115,7 +115,7 @@ fn (mut g JsGen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { g.write('")') } } else if sym_has_str_method - || sym.kind in [.array, .array_fixed, .map, .struct, .multi_return, .sum_type, .interface_] { + || sym.kind in [.array, .array_fixed, .map, .struct, .multi_return, .sum_type, .interface] { is_ptr := typ.is_ptr() is_var_mut := expr.is_auto_deref_var() str_fn_name := g.get_str_fn(typ) diff --git a/vlib/v/gen/native/amd64.v b/vlib/v/gen/native/amd64.v index df451f85983ebe..04864a5d3919f4 100644 --- a/vlib/v/gen/native/amd64.v +++ b/vlib/v/gen/native/amd64.v @@ -2676,7 +2676,7 @@ fn (mut c Amd64) assign_stmt(node ast.AssignStmt) { } } } - .enum_ { + .enum { c.mov_store(.rdx, .rax, ._32) } else {} diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index 4bceadc7ff094f..a2f15e560c4108 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -277,7 +277,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a // handle interface implementation methods: for isym in table.type_symbols { - if isym.kind != .interface_ { + if isym.kind != .interface { continue } if isym.info !is ast.Interface { diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index a503f03b36c9f9..690c6c94af9a55 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -22,7 +22,7 @@ fn (mut p Parser) parse_comptime_type() ast.ComptimeType { mut kind := ast.ComptimeTypeKind.unknown kind = match name { 'map' { - .map_ + .map } 'struct' { .struct @@ -52,7 +52,7 @@ fn (mut p Parser) parse_comptime_type() ast.ComptimeType { .array_dynamic } 'enum' { - .enum_ + .enum } 'sumtype' { .sum_type diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 2081af4fe2d5c2..cd2398e4d5f3d4 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -344,14 +344,14 @@ fn (mut p Parser) fn_decl() ast.FnDecl { if is_method { mut is_duplicate := type_sym.has_method(name) // make sure this is a normal method and not an interface method - if type_sym.kind == .interface_ && is_duplicate { + if type_sym.kind == .interface && is_duplicate { if mut type_sym.info is ast.Interface { // if the method is in info then its an interface method is_duplicate = !type_sym.info.has_method(name) } } if is_duplicate { - if type_sym.kind == .enum_ + if type_sym.kind == .enum && name in ['is_empty', 'has', 'all', 'set', 'set_all', 'clear', 'clear_all', 'toggle', 'zero', 'from'] { if enum_fn := type_sym.find_method(name) { name_pos = enum_fn.name_pos @@ -1265,7 +1265,7 @@ fn (mut p Parser) closure_vars() []ast.Param { fn (mut p Parser) check_fn_mutable_arguments(typ ast.Type, pos token.Pos) { sym := p.table.sym(typ) - if sym.kind in [.array, .array_fixed, .interface_, .map, .placeholder, .struct, .generic_inst, + if sym.kind in [.array, .array_fixed, .interface, .map, .placeholder, .struct, .generic_inst, .sum_type] { return } diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index a89f5c54fd8b27..2bc264f7d508c4 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -149,7 +149,7 @@ fn (mut p Parser) parse_map_type() ast.Type { key_sym := p.table.sym(key_type) is_alias := key_sym.kind == .alias key_type_supported := key_type in [ast.string_type_idx, ast.voidptr_type_idx] - || key_sym.kind in [.enum_, .placeholder, .any] + || key_sym.kind in [.enum, .placeholder, .any] || ((key_type.is_int() || key_type.is_float() || is_alias) && !key_type.is_ptr()) if !key_type_supported { if is_alias { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 73306a74887155..2d1890900db741 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -4321,7 +4321,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl { } idx := p.table.register_sym(ast.TypeSymbol{ - kind: .enum_ + kind: .enum name: name cname: util.no_dots(name) mod: p.mod @@ -4428,7 +4428,7 @@ fn (mut p Parser) type_decl() ast.TypeDecl { } variant_sym := p.table.sym(variant.typ) // TODO: implement this check for error too - if variant_sym.kind == .none_ { + if variant_sym.kind == .none { p.error_with_pos('named sum type cannot have none as its variant', variant.pos) return ast.AliasTypeDecl{} } diff --git a/vlib/v/parser/struct.v b/vlib/v/parser/struct.v index a66dddd3e42035..5950acb738d556 100644 --- a/vlib/v/parser/struct.v +++ b/vlib/v/parser/struct.v @@ -571,7 +571,7 @@ fn (mut p Parser) interface_decl() ast.InterfaceDecl { // Declare the type reg_idx := p.table.register_sym( is_pub: is_pub - kind: .interface_ + kind: .interface name: interface_name cname: util.no_dots(interface_name) mod: p.mod diff --git a/vlib/v/parser/tests/orm_no_error_handler.out b/vlib/v/parser/tests/orm_no_error_handler.out index d6b66cf8bf3cf9..c7102f74fe1e7e 100644 --- a/vlib/v/parser/tests/orm_no_error_handler.out +++ b/vlib/v/parser/tests/orm_no_error_handler.out @@ -1,6 +1,6 @@ vlib/v/parser/tests/orm_no_error_handler.vv:10:7: error: ORM returns a result, so it should have either an `or {}` block, or `!` at the end 8 | db := sqlite.connect(':memory:')! - 9 | + 9 | 10 | _ := sql db { | ~~~~~~~~ 11 | select from User diff --git a/vlib/v/reflection/reflection.v b/vlib/v/reflection/reflection.v index d7fe68af2e7b79..d7ae8c389b1d71 100644 --- a/vlib/v/reflection/reflection.v +++ b/vlib/v/reflection/reflection.v @@ -64,7 +64,7 @@ pub enum VKind { char rune bool - none_ + none string array array_fixed @@ -76,9 +76,9 @@ pub enum VKind { multi_return sum_type alias - enum_ + enum function - interface_ + interface float_literal int_literal aggregate @@ -269,7 +269,7 @@ pub fn get_types() []Type { // get_enums returns the registered enums pub fn get_enums() []Type { - enum_idxs := g_reflection.type_symbols.filter(it.kind == .enum_).map(it.idx) + enum_idxs := g_reflection.type_symbols.filter(it.kind == .enum).map(it.idx) return g_reflection.types.filter(it.idx in enum_idxs) } @@ -281,7 +281,7 @@ pub fn get_aliases() []Type { // get_interfaces returns the registered aliases pub fn get_interfaces() []Interface { - iface_idxs := g_reflection.type_symbols.filter(it.kind == .interface_).map(it.idx) + iface_idxs := g_reflection.type_symbols.filter(it.kind == .interface).map(it.idx) return g_reflection.types.filter(it.idx in iface_idxs).map(it.sym.info as Interface) } diff --git a/vlib/v/tests/reflection_sym_test.v b/vlib/v/tests/reflection_sym_test.v index b79f13c4fa17a9..049fd2850d75f7 100644 --- a/vlib/v/tests/reflection_sym_test.v +++ b/vlib/v/tests/reflection_sym_test.v @@ -87,7 +87,7 @@ fn test_enum_sym() { var := reflection.type_of(Flags.foo) assert var.sym.name == 'main.Flags' assert var.sym.parent_idx == 0 - assert var.sym.kind == .enum_ + assert var.sym.kind == .enum assert var.sym.language == .v assert (var.sym.info as reflection.Enum).vals == ['foo', 'bar'] } diff --git a/vlib/x/json2/decoder.v b/vlib/x/json2/decoder.v index 78bbb55b72cc8a..bf9904bc41f495 100644 --- a/vlib/x/json2/decoder.v +++ b/vlib/x/json2/decoder.v @@ -38,7 +38,7 @@ pub fn (err InvalidTokenError) code() int { // msg returns the message of the InvalidTokenError pub fn (err InvalidTokenError) msg() string { - footer_text := if err.expected != .none_ { ', expecting `${err.expected}`' } else { '' } + footer_text := if err.expected != .none { ', expecting `${err.expected}`' } else { '' } return format_message('invalid token `${err.token.kind}`${footer_text}', err.token.line, err.token.full_col()) } @@ -441,7 +441,7 @@ fn (mut p Parser) decode_value() !Any { .lcbr { return p.decode_object() } - .int_, .float { + .int, .float { tl := p.tok.lit.bytestr() kind := p.tok.kind p.next_with_err()! @@ -455,7 +455,7 @@ fn (mut p Parser) decode_value() !Any { } return Any(tl) } - .bool_ { + .bool { lit := p.tok.lit.bytestr() p.next_with_err()! if p.convert_type { @@ -470,7 +470,7 @@ fn (mut p Parser) decode_value() !Any { } return Any('null') } - .str_ { + .str { str := p.tok.lit.bytestr() p.next_with_err()! return Any(str) @@ -521,10 +521,10 @@ fn (mut p Parser) decode_object() !Any { // `}` for p.tok.kind != .rcbr { // step 1 -> key - if p.tok.kind != .str_ { + if p.tok.kind != .str { return InvalidTokenError{ token: p.tok - expected: .str_ + expected: .str } } diff --git a/vlib/x/json2/scanner.v b/vlib/x/json2/scanner.v index 90bb6709126f39..90702eba22c36a 100644 --- a/vlib/x/json2/scanner.v +++ b/vlib/x/json2/scanner.v @@ -14,13 +14,13 @@ mut: } enum TokenKind { - none_ + none error - str_ + str float - int_ + int null - bool_ + bool eof comma = 44 // , colon = 58 // : @@ -184,7 +184,7 @@ fn (mut s Scanner) text_scan() Token { } chrs << ch } - tok := s.tokenize(chrs, .str_) + tok := s.tokenize(chrs, .str) s.move() if !has_closed { return s.error('missing double quotes in string closing') @@ -237,7 +237,7 @@ fn (mut s Scanner) num_scan() Token { return s.error('invalid exponent') } } - kind := if is_fl { TokenKind.float } else { TokenKind.int_ } + kind := if is_fl { TokenKind.float } else { TokenKind.int } return s.tokenize(digits, kind) } @@ -266,7 +266,7 @@ fn (mut s Scanner) scan() Token { if ident == 'true' || ident == 'null' { mut kind := TokenKind.null if ident == 'true' { - kind = .bool_ + kind = .bool } unsafe { ident.free() } val := s.text[s.pos..s.pos + 4] @@ -284,7 +284,7 @@ fn (mut s Scanner) scan() Token { if ident == 'false' { unsafe { ident.free() } val := s.text[s.pos..s.pos + 5] - tok := s.tokenize(val, .bool_) + tok := s.tokenize(val, .bool) s.move() // f s.move() // a s.move() // l diff --git a/vlib/x/json2/scanner_test.v b/vlib/x/json2/scanner_test.v index c56ab8e44f5fd1..ab8f702fe40873 100644 --- a/vlib/x/json2/scanner_test.v +++ b/vlib/x/json2/scanner_test.v @@ -5,7 +5,7 @@ fn test_str() { text: '"test"'.bytes() } tok := sc.scan() - assert tok.kind == .str_ + assert tok.kind == .str assert tok.lit.len == 4 assert tok.lit.bytestr() == 'test' } @@ -15,7 +15,7 @@ fn test_str_valid_unicode_escape() { text: r'"\u0048"'.bytes() } tok := sc.scan() - assert tok.kind == .str_ + assert tok.kind == .str assert tok.lit.len == 1 assert tok.lit.bytestr() == 'H' } @@ -25,7 +25,7 @@ fn test_str_valid_unicode_escape_2() { text: r'"\u2714"'.bytes() } tok := sc.scan() - assert tok.kind == .str_ + assert tok.kind == .str assert tok.lit.len == 3 assert tok.lit.bytestr() == '✔' } @@ -91,7 +91,7 @@ fn test_int() { text: '10'.bytes() } tok := sc.scan() - assert tok.kind == .int_ + assert tok.kind == .int assert tok.lit.len == 2 assert tok.lit.bytestr() == '10' } @@ -101,7 +101,7 @@ fn test_int_negative() { text: '-10'.bytes() } tok := sc.scan() - assert tok.kind == .int_ + assert tok.kind == .int assert tok.lit.len == 3 assert tok.lit.bytestr() == '-10' } @@ -131,7 +131,7 @@ fn test_int_exp() { text: '1E22'.bytes() } tok := sc.scan() - assert tok.kind == .int_ + assert tok.kind == .int assert tok.lit.len == 4 assert tok.lit.bytestr() == '1E22' } @@ -141,7 +141,7 @@ fn test_int_exp_negative() { text: '1E-2'.bytes() } tok := sc.scan() - assert tok.kind == .int_ + assert tok.kind == .int assert tok.lit.len == 4 assert tok.lit.bytestr() == '1E-2' } @@ -151,7 +151,7 @@ fn test_int_exp_positive() { text: '1E+2'.bytes() } tok := sc.scan() - assert tok.kind == .int_ + assert tok.kind == .int assert tok.lit.len == 4 assert tok.lit.bytestr() == '1E+2' } @@ -191,7 +191,7 @@ fn test_number_with_space() { text: ' 4'.bytes() } tok := sc.scan() - assert tok.kind == .int_ + assert tok.kind == .int assert tok.lit.len == 1 assert tok.lit.bytestr() == '4' } @@ -314,7 +314,7 @@ fn test_bool_true() { text: 'true'.bytes() } tok := sc.scan() - assert tok.kind == .bool_ + assert tok.kind == .bool assert tok.lit.len == 4 assert tok.lit.bytestr() == 'true' } @@ -324,7 +324,7 @@ fn test_bool_false() { text: 'false'.bytes() } tok := sc.scan() - assert tok.kind == .bool_ + assert tok.kind == .bool assert tok.lit.len == 5 assert tok.lit.bytestr() == 'false' }