Skip to content

Commit

Permalink
all: replace enum field name struct_ with struct (#22466)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Oct 10, 2024
1 parent 72b4804 commit b97b2b1
Show file tree
Hide file tree
Showing 63 changed files with 247 additions and 251 deletions.
8 changes: 4 additions & 4 deletions cmd/tools/vrepl.v
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ enum DeclType {
type_ // type ...
enum_ // enum ...
fn_ // fn ...
struct_ // struct ...
struct // struct ...
interface_ // interface ...
stmt_ // statement
}
Expand Down Expand Up @@ -265,7 +265,7 @@ fn (r &Repl) insert_source_code(typ DeclType, lines []string) string {
all_lines << lines
}
all_lines << r.structs
if typ == .struct_ {
if typ == .struct {
all_lines << lines
}
all_lines << r.interfaces
Expand Down Expand Up @@ -598,7 +598,7 @@ fn run_repl(workdir string, vrepl_prefix string) int {
if was_func {
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)
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)
} else if was_interface {
Expand All @@ -615,7 +615,7 @@ fn run_repl(workdir string, vrepl_prefix string) int {
} else if starts_with_enum {
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])
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])
} else if starts_with_type {
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/ast/ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub enum ComptimeTypeKind {
map_
int
float
struct_
struct
iface
array
array_fixed
Expand All @@ -169,7 +169,7 @@ pub fn (cty ComptimeType) str() string {
.map_ { '\$map' }
.int { '\$int' }
.float { '\$float' }
.struct_ { '\$struct' }
.struct { '\$struct' }
.iface { '\$interface' }
.array { '\$array' }
.array_dynamic { '\$array_dynamic' }
Expand Down
7 changes: 3 additions & 4 deletions vlib/v/ast/str.v
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn (t &Table) stringify_fn_after_name(node &FnDecl, mut f strings.Builder, cur_m
}
f.write_string(param.name)
param_sym := t.sym(param.typ)
if param_sym.kind == .struct_ && (param_sym.info as Struct).is_anon {
if param_sym.kind == .struct && (param_sym.info as Struct).is_anon {
f.write_string(' struct {')
struct_ := param_sym.info as Struct
for field in struct_.fields {
Expand All @@ -207,10 +207,9 @@ fn (t &Table) stringify_fn_after_name(node &FnDecl, mut f strings.Builder, cur_m
if param.is_mut {
if s.starts_with('&') && ((!param_sym.is_number() && param_sym.kind != .bool)
|| node.language != .v
|| (param.typ.is_ptr() && t.sym(param.typ).kind == .struct_)) {
|| (param.typ.is_ptr() && t.sym(param.typ).kind == .struct)) {
s = s[1..]
} else if param.typ.is_ptr() && t.sym(param.typ).kind == .struct_
&& !s.contains('[') {
} else if param.typ.is_ptr() && t.sym(param.typ).kind == .struct && !s.contains('[') {
s = t.type_to_str(param.typ.clear_flag(.shared_f).deref())
}
}
Expand Down
12 changes: 6 additions & 6 deletions vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ pub fn (mut t Table) find_or_register_promise(return_type Type) int {

promise_type := TypeSymbol{
parent_idx: t.type_idxs['Promise']
kind: .struct_
kind: .struct
name: name
cname: cname
info: Struct{
Expand Down Expand Up @@ -1433,7 +1433,7 @@ pub fn (mut t Table) complete_interface_check() {
util.timing_measure(@METHOD)
}
for tk, mut tsym in t.type_symbols {
if tsym.kind != .struct_ {
if tsym.kind != .struct {
continue
}
for _, mut idecl in t.interfaces {
Expand Down Expand Up @@ -1954,7 +1954,7 @@ pub fn (mut t Table) unwrap_generic_type_ex(typ Type, generic_names []string, co
if fields[i].typ.has_flag(.generic) {
orig_type := fields[i].typ
sym := t.sym(fields[i].typ)
if sym.kind == .struct_ && fields[i].typ.idx() != typ.idx() {
if sym.kind == .struct && fields[i].typ.idx() != typ.idx() {
fields[i].typ = t.unwrap_generic_type(fields[i].typ, t_generic_names,
t_concrete_types)
} else {
Expand Down Expand Up @@ -2026,7 +2026,7 @@ pub fn (mut t Table) unwrap_generic_type_ex(typ Type, generic_names []string, co
info.parent_type = typ.set_flag(.generic)
info.fields = fields
new_idx := t.register_sym(
kind: .struct_
kind: .struct
name: nrt
cname: util.no_dots(c_nrt)
mod: ts.mod
Expand All @@ -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 {
Expand Down Expand Up @@ -2266,7 +2266,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
for i in 0 .. variants.len {
if variants[i].has_flag(.generic) {
t_sym := t.sym(variants[i])
if t_sym.kind == .struct_ && variants[i].idx() != info.parent_idx {
if t_sym.kind == .struct && variants[i].idx() != info.parent_idx {
variants[i] = t.unwrap_generic_type(variants[i], generic_names,
info.concrete_types)
} else {
Expand Down
14 changes: 7 additions & 7 deletions vlib/v/ast/types.v
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ pub fn (t &Table) type_kind(typ Type) Kind {
}

pub fn (t &Table) type_is_for_pointer_arithmetic(typ Type) bool {
if t.sym(typ).kind == .struct_ {
if t.sym(typ).kind == .struct {
return false
} else {
return typ.is_any_kind_of_pointer() || typ.is_int_valptr()
Expand Down Expand Up @@ -799,7 +799,7 @@ pub enum Kind {
map
chan
any
struct_
struct
generic_inst
multi_return
sum_type
Expand Down Expand Up @@ -1164,7 +1164,7 @@ pub fn (t &Table) type_size(typ Type) (int, int) {
.alias {
size, align = t.type_size((sym.info as Alias).parent_type)
}
.struct_, .string, .multi_return {
.struct, .string, .multi_return {
mut max_alignment := 0
mut total_size := 0
types := if mut sym.info is Struct {
Expand Down Expand Up @@ -1237,7 +1237,7 @@ pub fn (k Kind) str() string {
.voidptr { 'voidptr' }
.charptr { 'charptr' }
.byteptr { 'byteptr' }
.struct_ { 'struct' }
.struct { 'struct' }
.int { 'int' }
.i8 { 'i8' }
.i16 { 'i16' }
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1864,7 +1864,7 @@ pub fn (t &Table) find_missing_variants(s &SumType, field_name string) string {
mut res := []string{cap: 5}
for variant in s.variants {
ts := t.sym(variant)
if ts.kind != .struct_ {
if ts.kind != .struct {
continue
}
mut found := false
Expand Down
15 changes: 7 additions & 8 deletions vlib/v/checker/assign.v
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
c.expected_type = c.unwrap_generic(left_type)
is_shared_re_assign = left is ast.Ident && left.info is ast.IdentVar
&& ((left.info as ast.IdentVar).share == .shared_t || left_type.has_flag(.shared_f))
&& c.table.sym(left_type).kind in [.array, .map, .struct_]
&& c.table.sym(left_type).kind in [.array, .map, .struct]
}
if c.comptime.comptime_for_field_var != '' && mut left is ast.ComptimeSelector {
left_type = c.comptime.comptime_for_field_type
Expand Down Expand Up @@ -669,22 +669,22 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
right.pos())
}
} else if !left_sym.is_number()
&& left_sym.kind !in [.byteptr, .charptr, .struct_, .alias] {
&& left_sym.kind !in [.byteptr, .charptr, .struct, .alias] {
c.error('operator `${node.op}` not defined on left operand type `${left_sym.name}`',
left.pos())
} else if !right_sym.is_number()
&& left_sym.kind !in [.byteptr, .charptr, .struct_, .alias] {
&& left_sym.kind !in [.byteptr, .charptr, .struct, .alias] {
c.error('invalid right operand: ${left_sym.name} ${node.op} ${right_sym.name}',
right.pos())
}
}
.mult_assign, .div_assign {
if !left_sym.is_number() && !c.table.final_sym(left_type_unwrapped).is_int()
&& left_sym.kind !in [.struct_, .alias] {
&& left_sym.kind !in [.struct, .alias] {
c.error('operator ${node.op.str()} not defined on left operand type `${left_sym.name}`',
left.pos())
} else if !right_sym.is_number() && !c.table.final_sym(left_type_unwrapped).is_int()
&& left_sym.kind !in [.struct_, .alias] {
&& left_sym.kind !in [.struct, .alias] {
c.error('operator ${node.op.str()} not defined on right operand type `${right_sym.name}`',
right.pos())
}
Expand Down Expand Up @@ -765,8 +765,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
else {}
}
if node.op in [.plus_assign, .minus_assign, .mod_assign, .mult_assign, .div_assign]
&& (left_sym.kind == .alias || (left_sym.kind == .struct_
&& right_sym.kind == .struct_)) {
&& (left_sym.kind == .alias || (left_sym.kind == .struct && right_sym.kind == .struct)) {
left_name := c.table.type_to_str(left_type_unwrapped)
right_name := c.table.type_to_str(right_type_unwrapped)
parent_sym := c.table.final_sym(left_type_unwrapped)
Expand All @@ -783,7 +782,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
.mult_assign { '*' }
else { 'unknown op' }
}
if left_sym.kind == .struct_ && (left_sym.info as ast.Struct).generic_types.len > 0 {
if left_sym.kind == .struct && (left_sym.info as ast.Struct).generic_types.len > 0 {
continue
}
if method := left_sym.find_method(extracted_op) {
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/checker/autocomplete.v
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn (mut c Checker) ident_autocomplete(node ast.Ident) {
*/

mut fields := []ACFieldMethod{cap: 10}
if sym.kind == .struct_ {
if sym.kind == .struct {
// Add fields, but only if it's a struct.
struct_info := sym.info as ast.Struct
// match struct_info {
Expand Down
12 changes: 6 additions & 6 deletions vlib/v/checker/check_types.v
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan
exp_sym := c.table.sym(expected)
// unknown C types are set to int, allow int to be used for types like `&C.FILE`
// eg. `C.fflush(C.stderr)` - error: cannot use `int` as `&C.FILE` in argument 1 to `C.fflush`
if expected.is_ptr() && exp_sym.language == .c && exp_sym.kind in [.placeholder, .struct_]
if expected.is_ptr() && exp_sym.language == .c && exp_sym.kind in [.placeholder, .struct]
&& got == ast.int_type_idx {
return
}
Expand Down Expand Up @@ -316,7 +316,7 @@ fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, lan
}
exp_sym := c.table.final_sym(expected)
if exp_sym.language == .v
&& exp_sym.kind !in [.voidptr, .charptr, .byteptr, .function, .placeholder, .array_fixed, .sum_type, .struct_] {
&& exp_sym.kind !in [.voidptr, .charptr, .byteptr, .function, .placeholder, .array_fixed, .sum_type, .struct] {
got_typ_str, expected_typ_str := c.get_string_names_of(got, expected)
return error('cannot use `${got_typ_str}` as `${expected_typ_str}`')
}
Expand Down Expand Up @@ -436,7 +436,7 @@ fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool {
return true
}
// struct
if exp_sym.kind == .struct_ && got_sym.kind == .struct_ {
if exp_sym.kind == .struct && got_sym.kind == .struct {
if c.table.type_to_str(expected) == c.table.type_to_str(got) {
return true
}
Expand Down Expand Up @@ -991,7 +991,7 @@ fn (mut c Checker) infer_fn_generic_types(func &ast.Fn, mut node ast.CallExpr) {
func_.name = ''
idx := c.table.find_or_register_fn_type(func_, true, false)
typ = ast.new_type(idx).derive(arg.typ)
} else if c.comptime.comptime_for_field_var != '' && sym.kind in [.struct_, .any]
} else if c.comptime.comptime_for_field_var != '' && sym.kind in [.struct, .any]
&& arg.expr is ast.ComptimeSelector {
comptime_typ := c.comptime.get_comptime_selector_type(arg.expr, ast.void_type)
if comptime_typ != ast.void_type {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -1184,7 +1184,7 @@ fn (mut c Checker) is_contains_any_kind_of_pointer(typ ast.Type, mut checked_typ
return c.is_contains_any_kind_of_pointer(sym.info.parent_type, mut checked_types)
}
ast.Struct {
if sym.kind == .struct_ && sym.language == .v {
if sym.kind == .struct && sym.language == .v {
fields := c.table.struct_fields(sym)
for field in fields {
ret := c.is_contains_any_kind_of_pointer(field.typ, mut checked_types)
Expand Down
Loading

0 comments on commit b97b2b1

Please sign in to comment.