all: replace enum field name struct_ with struct (#22466)

This commit is contained in:
yuyi 2024-10-10 09:41:15 +08:00 committed by GitHub
parent 72b48047b5
commit b97b2b1c9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
63 changed files with 247 additions and 251 deletions

View file

@ -78,7 +78,7 @@ enum DeclType {
type_ // type ...
enum_ // enum ...
fn_ // fn ...
struct_ // struct ...
struct // struct ...
interface_ // interface ...
stmt_ // statement
}
@ -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
@ -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 {
@ -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 {

View file

@ -144,7 +144,7 @@ pub enum ComptimeTypeKind {
map_
int
float
struct_
struct
iface
array
array_fixed
@ -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' }

View file

@ -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 {
@ -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())
}
}

View file

@ -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{
@ -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 {
@ -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 {
@ -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
@ -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 {
@ -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 {

View file

@ -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()
@ -799,7 +799,7 @@ pub enum Kind {
map
chan
any
struct_
struct
generic_inst
multi_return
sum_type
@ -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 {
@ -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' }
@ -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 {
@ -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 {
@ -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

View file

@ -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
@ -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())
}
@ -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)
@ -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) {

View file

@ -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 {

View file

@ -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
}
@ -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}`')
}
@ -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
}
@ -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 {
@ -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 {
@ -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)

View file

@ -558,7 +558,7 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
c.error('type `${parent_typ_sym.str()}` is an alias, use the original alias type `${orig_sym}` instead',
node.type_pos)
}
.struct_ {
.struct {
if mut parent_typ_sym.info is ast.Struct {
// check if the generic param types have been defined
for ct in parent_typ_sym.info.concrete_types {
@ -576,7 +576,7 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
// check if embed types are struct
for embed_type in parent_typ_sym.info.embeds {
final_embed_sym := c.table.final_sym(embed_type)
if final_embed_sym.kind != .struct_ {
if final_embed_sym.kind != .struct {
c.error('cannot embed non-struct `${c.table.sym(embed_type).name}`',
node.type_pos)
}
@ -585,7 +585,7 @@ fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl) {
for field in parent_typ_sym.info.fields {
field_sym := c.table.sym(field.typ)
if field_sym.info is ast.Alias {
if c.table.sym(field_sym.info.parent_type).kind != .struct_ {
if c.table.sym(field_sym.info.parent_type).kind != .struct {
c.error('cannot embed non-struct `${field_sym.name}`',
field.type_pos)
}
@ -680,7 +680,7 @@ fn (mut c Checker) sum_type_decl(node ast.SumTypeDecl) {
sym := c.table.sym(variant.typ)
if variant.typ.is_ptr() || (sym.info is ast.Alias && sym.info.parent_type.is_ptr()) {
variant_name := sym.name.all_after_last('.')
lb, rb := if sym.kind == .struct_ { '{', '}' } else { '(', ')' }
lb, rb := if sym.kind == .struct { '{', '}' } else { '(', ')' }
msg := if sym.info is ast.Alias && sym.info.parent_type.is_ptr() {
'alias as non-reference type'
} else {
@ -698,7 +698,7 @@ and use a reference to the sum type instead: `var := &${node.name}(${variant_nam
c.error('unknown type `${sym.name}`', variant.pos)
} 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 {
} else if sym.kind == .struct && sym.language == .js {
c.error('sum type cannot hold a JS struct', variant.pos)
} else if sym.info is ast.Struct {
if sym.info.is_generic {
@ -896,7 +896,7 @@ fn (mut c Checker) fail_if_immutable(mut expr ast.Expr) (string, token.Pos) {
}
mut typ_sym := c.table.final_sym(c.unwrap_generic(expr.expr_type))
match typ_sym.kind {
.struct_ {
.struct {
mut has_field := true
mut field_info := c.table.find_field_with_embeds(typ_sym, expr.field_name) or {
has_field = false
@ -1687,7 +1687,7 @@ fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type {
if !c.inside_unsafe {
rec_sym := c.table.sym(receiver.set_nr_muls(0))
if !rec_sym.is_heap() {
suggestion := if rec_sym.kind == .struct_ {
suggestion := if rec_sym.kind == .struct {
'declaring `${rec_sym.name}` as `@[heap]`'
} else {
'wrapping the `${rec_sym.name}` object in a `struct` declared as `@[heap]`'
@ -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))
@ -3254,21 +3254,21 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
tt := c.table.type_to_str(to_type)
c.error('cannot cast `${ft}` to `${tt}`', node.pos)
}
} else if mut to_sym.info is ast.Alias && !(final_to_sym.kind == .struct_ && final_to_is_ptr) {
} 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_to_sym.kind == .struct_
|| (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)
tt := c.table.type_to_str(to_type)
c.error('cannot cast `${ft}` to `${tt}` (alias to `${final_to_sym.name}`)',
node.pos)
}
} else if to_sym.kind == .struct_ && mut to_sym.info is ast.Struct
} else if to_sym.kind == .struct && mut to_sym.info is ast.Struct
&& (!to_sym.info.is_typedef || from_type.idx() in [ast.voidptr_type_idx, ast.nil_type_idx])
&& !final_to_is_ptr {
// For now we ignore C typedef because of `C.Window(C.None)` in vlib/clipboard (except for `from_type` is voidptr/nil)
if from_sym.kind == .struct_ && from_sym.info is ast.Struct && !from_type.is_ptr() {
if from_sym.kind == .struct && from_sym.info is ast.Struct && !from_type.is_ptr() {
if !to_type.has_flag(.option) {
c.warn('casting to struct is deprecated, use e.g. `Struct{...expr}` instead',
node.pos)
@ -3281,7 +3281,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
ft := c.table.type_to_str(from_type)
c.error('cannot cast `${ft}` to struct', node.pos)
}
} else if to_sym.kind == .struct_ && final_to_is_ptr {
} else if to_sym.kind == .struct && final_to_is_ptr {
if from_sym.info is ast.Alias {
from_type = from_sym.info.parent_type.derive_add_muls(from_type)
}
@ -3345,7 +3345,7 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
} else if from_type == ast.none_type && !to_type.has_flag(.option) && !to_type.has_flag(.result) {
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() {
} 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 {
from_type_name := c.table.type_to_str(from_type)
type_name := c.table.type_to_str(to_type)
@ -4389,7 +4389,7 @@ fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool) {
type_sym := c.table.sym(obj.typ.set_nr_muls(0))
if obj.is_stack_obj && !type_sym.is_heap() && !c.pref.translated
&& !c.file.is_translated {
suggestion := if type_sym.kind == .struct_ {
suggestion := if type_sym.kind == .struct {
'declaring `${type_sym.name}` as `@[heap]`'
} else {
'wrapping the `${type_sym.name}` object in a `struct` declared as `@[heap]`'
@ -4402,7 +4402,7 @@ fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool) {
node.pos)
} else {
match type_sym.kind {
.struct_ {
.struct {
info := type_sym.info as ast.Struct
if !info.is_heap {
node.obj.is_auto_heap = true
@ -4472,7 +4472,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
if expr_sym.kind == .struct && (expr_sym.info as ast.Struct).is_minify
&& (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)) {
@ -4717,8 +4717,8 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
}
}
if (typ.is_ptr() && !typ.has_flag(.shared_f) && (!node.left.is_auto_deref_var()
|| (typ_sym.kind == .struct_ && typ_sym.name != 'array')))
if (typ.is_ptr() && !typ.has_flag(.shared_f)
&& (!node.left.is_auto_deref_var() || (typ_sym.kind == .struct && typ_sym.name != 'array')))
|| typ.is_pointer() {
mut is_ok := false
mut is_mut_struct := false
@ -4726,10 +4726,10 @@ fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type {
if mut node.left.obj is ast.Var {
// `mut param []T` function parameter
is_ok = node.left.obj.is_mut && node.left.obj.is_arg && !typ.deref().is_ptr()
&& typ_sym.kind != .struct_
&& typ_sym.kind != .struct
// `mut param Struct`
is_mut_struct = node.left.obj.is_mut && node.left.obj.is_arg
&& typ_sym.kind == .struct_
&& typ_sym.kind == .struct
}
}
if !is_ok && node.index is ast.RangeExpr {
@ -4895,7 +4895,7 @@ fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type {
fn (mut c Checker) offset_of(node ast.OffsetOf) ast.Type {
sym := c.table.final_sym(node.struct_type)
if sym.kind != .struct_ {
if sym.kind != .struct {
c.error('first argument of __offsetof must be struct', node.pos)
return ast.u32_type
}
@ -4982,7 +4982,7 @@ fn (mut c Checker) fetch_field_name(field ast.StructField) string {
}
}
sym := c.table.sym(field.typ)
if sym.kind == .struct_ && sym.name != 'time.Time' {
if sym.kind == .struct && sym.name != 'time.Time' {
name = '${name}_id'
}
return name
@ -5060,7 +5060,7 @@ fn (mut c Checker) ensure_generic_type_specify_type_names(typ ast.Type, pos toke
return false
}
}
.struct_ {
.struct {
info := sym.info as ast.Struct
if info.generic_types.len > 0 && !typ.has_flag(.generic) && info.concrete_types.len == 0 {
c.error('`${sym.name}` type is generic struct, must specify the generic type names, e.g. ${sym.name}[T], ${sym.name}[int]',
@ -5103,7 +5103,7 @@ fn (mut c Checker) ensure_type_exists(typ ast.Type, pos token.Pos) bool {
return false
}
sym := c.table.sym(typ)
if !c.is_builtin_mod && sym.kind == .struct_ && !sym.is_pub && sym.mod != c.mod {
if !c.is_builtin_mod && sym.kind == .struct && !sym.is_pub && sym.mod != c.mod {
c.error('struct `${sym.name}` was declared as private to module `${sym.mod}`, so it can not be used inside module `${c.mod}`',
pos)
return false
@ -5268,7 +5268,7 @@ fn (mut c Checker) fail_if_stack_struct_action_outside_unsafe(mut ident ast.Iden
if obj.is_stack_obj && !c.inside_unsafe {
sym := c.table.sym(obj.typ.set_nr_muls(0))
if !sym.is_heap() && !c.pref.translated && !c.file.is_translated {
suggestion := if sym.kind == .struct_ {
suggestion := if sym.kind == .struct {
'declaring `${sym.name}` as `@[heap]`'
} else {
'wrapping the `${sym.name}` object in a `struct` declared as `@[heap]`'

View file

@ -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 {

View file

@ -433,7 +433,7 @@ fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
node.value_type = info.value_type
return node.typ
} else {
if sym.kind == .struct_ {
if sym.kind == .struct {
c.error('`{}` can not be used for initialising empty structs any more. Use `${c.table.type_to_str(c.expected_type)}{}` instead.',
node.pos)
} else {
@ -451,7 +451,7 @@ fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
c.error('cannot use Result type as map value type', node.pos)
}
val_sym := c.table.sym(info.value_type)
if val_sym.kind == .struct_ {
if val_sym.kind == .struct {
val_info := val_sym.info as ast.Struct
if val_info.generic_types.len > 0 && val_info.concrete_types.len == 0
&& !info.value_type.has_flag(.generic) {
@ -550,7 +550,7 @@ fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
if val_type == map_val_type {
continue
}
if val_type_sym.kind == .struct_
if val_type_sym.kind == .struct
&& c.type_implements(val_type, map_val_type, val.pos()) {
node.vals[i] = ast.CastExpr{
expr: val

View file

@ -18,7 +18,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
typ_vweb_result := c.table.find_type_idx('veb.Result')
if node.return_type == typ_vweb_result {
rec_sym := c.table.sym(node.receiver.typ)
if rec_sym.kind == .struct_ {
if rec_sym.kind == .struct {
if _ := c.table.find_field_with_embeds(rec_sym, 'Context') {
// there is no point in the message here, for methods
// that are not public; since they will not be available as routes anyway
@ -136,7 +136,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
node.return_type_pos)
}
}
if gs.kind == .struct_ && c.needs_unwrap_generic_type(node.return_type) {
if gs.kind == .struct && c.needs_unwrap_generic_type(node.return_type) {
// resolve generic Array[T], Map[T] generics, avoid recursive generic resolving type
if c.ensure_generic_type_specify_type_names(node.return_type, node.return_type_pos,
false, false)
@ -363,8 +363,8 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) {
if param_sym.kind == .string && receiver_sym.kind == .string {
// bypass check for strings
// TODO: there must be a better way to handle that
} else if param_sym.kind !in [.struct_, .alias]
|| receiver_sym.kind !in [.struct_, .alias] {
} else if param_sym.kind !in [.struct, .alias]
|| receiver_sym.kind !in [.struct, .alias] {
c.error('operator methods are only allowed for struct and type alias',
node.pos)
} else {
@ -890,7 +890,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
if sym.info is ast.Alias {
kind = c.table.sym(sym.info.parent_type).kind
}
if kind !in [.struct_, .sum_type, .map, .array] {
if kind !in [.struct, .sum_type, .map, .array] {
c.error('json.decode: expected sum type, struct, map or array, found ${kind}',
expr.pos)
}
@ -1344,7 +1344,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
}
e_sym := c.table.sym(c.expected_type)
if call_arg.expr is ast.MapInit && e_sym.kind == .struct_ {
if call_arg.expr is ast.MapInit && e_sym.kind == .struct {
c.error('cannot initialize a struct with a map', call_arg.pos)
continue
} else if call_arg.expr is ast.StructInit && e_sym.kind == .map {
@ -1583,7 +1583,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
*/
c.error('${err.msg()} in argument ${i + 1} to `${fn_name}`', call_arg.pos)
}
if final_param_sym.kind == .struct_ && arg_typ !in [ast.voidptr_type, ast.nil_type]
if final_param_sym.kind == .struct && arg_typ !in [ast.voidptr_type, ast.nil_type]
&& !c.check_multiple_ptr_match(arg_typ, param.typ, param, call_arg) {
got_typ_str, expected_typ_str := c.get_string_names_of(arg_typ, param.typ)
c.error('cannot use `${got_typ_str}` as `${expected_typ_str}` in argument ${i + 1} to `${fn_name}`',
@ -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 {
@ -2116,7 +2116,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
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 {
@ -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)
@ -2613,7 +2613,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
arg.pos)
}
param_typ_sym := c.table.sym(exp_arg_typ)
if param_typ_sym.kind == .struct_ && got_arg_typ !in [ast.voidptr_type, ast.nil_type]
if param_typ_sym.kind == .struct && got_arg_typ !in [ast.voidptr_type, ast.nil_type]
&& !c.check_multiple_ptr_match(got_arg_typ, param.typ, param, arg) {
got_typ_str, expected_typ_str := c.get_string_names_of(got_arg_typ, param.typ)
c.error('cannot use `${got_typ_str}` as `${expected_typ_str}` in argument ${i + 1} to `${method_name}`',

View file

@ -114,7 +114,7 @@ fn (mut c Checker) for_in_stmt(mut node ast.ForInStmt) {
c.error('string type is immutable, it cannot be changed', node.pos)
return
}
if sym.kind == .struct_ {
if sym.kind == .struct {
// iterators
next_fn := sym.find_method_with_generic_parent('next') or {
c.error('a struct must have a `next()` method to be an iterator', node.cond.pos())

View file

@ -459,7 +459,7 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
continue
}
if (node.typ.has_option_or_result())
&& c.table.sym(stmt.typ).kind == .struct_
&& c.table.sym(stmt.typ).kind == .struct
&& c.type_implements(stmt.typ, ast.error_type, node.pos) {
stmt.expr = ast.CastExpr{
expr: stmt.expr

View file

@ -379,7 +379,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
c.error('infix `${node.op}` is not defined for pointer values', left_right_pos)
}
if !c.pref.translated && left_sym.kind in [.array, .array_fixed, .map, .struct_] {
if !c.pref.translated && left_sym.kind in [.array, .array_fixed, .map, .struct] {
if left_sym.has_method_with_generic_parent(node.op.str()) {
if method := left_sym.find_method_with_generic_parent(node.op.str()) {
return_type = method.return_type
@ -397,7 +397,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
left_right_pos)
}
}
} else if !c.pref.translated && right_sym.kind in [.array, .array_fixed, .map, .struct_] {
} else if !c.pref.translated && right_sym.kind in [.array, .array_fixed, .map, .struct] {
if right_sym.has_method_with_generic_parent(node.op.str()) {
if method := right_sym.find_method_with_generic_parent(node.op.str()) {
return_type = method.return_type
@ -505,12 +505,11 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
right_sym = c.table.sym(unwrapped_right_type)
if left_sym.kind in [.array, .array_fixed] && right_sym.kind in [.array, .array_fixed] {
c.error('only `==` and `!=` are defined on arrays', node.pos)
} else if left_sym.kind == .struct_
} else if left_sym.kind == .struct
&& (left_sym.info as ast.Struct).generic_types.len > 0 {
node.promoted_type = ast.bool_type
return ast.bool_type
} else if left_sym.kind == .struct_ && right_sym.kind == .struct_
&& node.op in [.eq, .lt] {
} else if left_sym.kind == .struct && right_sym.kind == .struct && node.op in [.eq, .lt] {
if !(left_sym.has_method(node.op.str()) && right_sym.has_method(node.op.str())) {
left_name := c.table.type_to_str(unwrapped_left_type)
right_name := c.table.type_to_str(unwrapped_right_type)
@ -527,7 +526,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
}
}
if left_sym.kind == .struct_ && right_sym.kind == .struct_ {
if left_sym.kind == .struct && right_sym.kind == .struct {
if !left_sym.has_method('<') && node.op in [.ge, .le] {
c.error('cannot use `${node.op}` as `<` operator method is not defined',
left_right_pos)
@ -539,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',

View file

@ -101,7 +101,7 @@ fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type {
} else {
if ret_type.idx() != expr_type.idx() {
if node.expected_type.has_option_or_result()
&& c.table.sym(stmt.typ).kind == .struct_
&& c.table.sym(stmt.typ).kind == .struct
&& (c.table.sym(ret_type).kind != .sum_type
|| !c.check_types(expr_type, ret_type))
&& c.type_implements(stmt.typ, ast.error_type, node.pos) {
@ -322,7 +322,7 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
// ensure that the sub expressions of the branch are actually checked, before anything else:
_ := c.expr(mut expr)
}
if expr is ast.TypeNode && cond_sym.kind == .struct_ {
if expr is ast.TypeNode && cond_sym.kind == .struct {
c.error('struct instances cannot be matched by type name, they can only be matched to other instances of the same struct type',
branch.pos)
}

View file

@ -46,7 +46,7 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) ast.Type {
for field in fields {
field_typ, field_sym := c.get_non_array_type(field.typ)
if field_sym.kind == .struct_ && (field_typ.idx() == node.table_expr.typ.idx()
if field_sym.kind == .struct && (field_typ.idx() == node.table_expr.typ.idx()
|| c.check_recursive_structs(field_sym, table_sym.name)) {
c.orm_error('invalid recursive struct `${field_sym.name}`', field.pos)
return ast.void_type
@ -281,7 +281,7 @@ fn (mut c Checker) sql_stmt_line(mut node ast.SqlStmtLine) ast.Type {
for field in non_primitive_fields {
field_typ, field_sym := c.get_non_array_type(field.typ)
if field_sym.kind == .struct_ && (field_typ.idx() == node.table_expr.typ.idx()
if field_sym.kind == .struct && (field_typ.idx() == node.table_expr.typ.idx()
|| c.check_recursive_structs(field_sym, table_sym.name)) {
c.orm_error('invalid recursive struct `${field_sym.name}`', field.pos)
return ast.void_type
@ -364,7 +364,7 @@ fn (mut c Checker) check_orm_non_primitive_struct_field_attrs(field ast.StructFi
for attr in field.attrs {
if attr.name == 'fkey' {
if field_type.kind != .array && field_type.kind != .struct_ {
if field_type.kind != .array && field_type.kind != .struct {
c.orm_error('the `fkey` attribute must be used only with arrays and structures',
attr.pos)
return
@ -408,14 +408,14 @@ fn (mut c Checker) fetch_and_check_orm_fields(info ast.Struct, pos token.Pos, ta
}
field_sym := c.table.sym(field.typ)
is_primitive := field.typ.is_string() || field.typ.is_bool() || field.typ.is_number()
is_struct := field_sym.kind == .struct_
is_struct := field_sym.kind == .struct
is_array := field_sym.kind == .array
is_enum := field_sym.kind == .enum_
mut is_array_of_structs := false
if is_array {
array_info := field_sym.array_info()
elem_sym := c.table.sym(array_info.elem_type)
is_array_of_structs = elem_sym.kind == .struct_
is_array_of_structs = elem_sym.kind == .struct
if attr := field.attrs.find_first('fkey') {
if attr.arg == '' {
@ -674,7 +674,7 @@ fn (mut c Checker) check_orm_table_expr_type(type_node &ast.TypeNode) bool {
// is referred to by the provided field. For example, the `[]Child` field
// refers to the foreign table `Child`.
fn (c &Checker) get_field_foreign_table_type(table_field &ast.StructField) ast.Type {
if c.table.sym(table_field.typ).kind == .struct_ {
if c.table.sym(table_field.typ).kind == .struct {
return table_field.typ
} else if c.table.sym(table_field.typ).kind == .array {
return c.table.sym(table_field.typ).array_info().elem_type
@ -689,10 +689,10 @@ fn (c &Checker) get_orm_non_primitive_fields(fields []ast.StructField) []ast.Str
mut res := []ast.StructField{}
for field in fields {
type_with_no_option_flag := field.typ.clear_flag(.option)
is_struct := c.table.type_symbols[int(type_with_no_option_flag)].kind == .struct_
is_struct := c.table.type_symbols[int(type_with_no_option_flag)].kind == .struct
is_array := c.table.sym(type_with_no_option_flag).kind == .array
is_array_with_struct_elements := is_array
&& c.table.sym(c.table.sym(type_with_no_option_flag).array_info().elem_type).kind == .struct_
&& c.table.sym(c.table.sym(type_with_no_option_flag).array_info().elem_type).kind == .struct
is_time := c.table.get_type_name(type_with_no_option_flag) == 'time.Time'
if (is_struct || is_array_with_struct_elements) && !is_time {
@ -753,7 +753,7 @@ fn (mut c Checker) check_recursive_structs(ts &ast.TypeSymbol, struct_name strin
if ts.info is ast.Struct {
for field in ts.info.fields {
_, field_sym := c.get_non_array_type(field.typ)
if field_sym.kind == .struct_ && field_sym.name == struct_name {
if field_sym.kind == .struct && field_sym.name == struct_name {
return true
}
}

View file

@ -164,8 +164,7 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
mut expr_ := node.exprs[0]
got_type := c.expr(mut expr_)
got_type_sym := c.table.sym(got_type)
if got_type_sym.kind == .struct_
&& c.type_implements(got_type, ast.error_type, node.pos) {
if got_type_sym.kind == .struct && c.type_implements(got_type, ast.error_type, node.pos) {
node.exprs[0] = ast.CastExpr{
expr: node.exprs[0]
typname: 'IError'
@ -244,7 +243,7 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
}
}
// `fn foo() !int { return Err{} }`
if got_type_sym.kind == .struct_
if got_type_sym.kind == .struct
&& c.type_implements(got_type, ast.error_type, node.pos) {
node.exprs[expr_idxs[i]] = ast.CastExpr{
expr: node.exprs[expr_idxs[i]]

View file

@ -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)}`',

View file

@ -28,11 +28,11 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
embed_sym := c.table.sym(embed.typ)
if embed_sym.info is ast.Alias {
parent_sym := c.table.sym(embed_sym.info.parent_type)
if parent_sym.kind != .struct_ {
if parent_sym.kind != .struct {
c.error('`${embed_sym.name}` (alias of `${parent_sym.name}`) is not a struct',
embed.pos)
}
} else if embed_sym.kind != .struct_ {
} else if embed_sym.kind != .struct {
c.error('`${embed_sym.name}` is not a struct', embed.pos)
} else if (embed_sym.info as ast.Struct).is_heap && !embed.typ.is_ptr() {
struct_sym.info.is_heap = true
@ -186,7 +186,7 @@ fn (mut c Checker) struct_decl(mut node ast.StructDecl) {
}
}
match sym.kind {
.struct_ {
.struct {
info := sym.info as ast.Struct
if info.is_heap && !field.typ.is_ptr() {
struct_sym.info.is_heap = true
@ -528,8 +528,8 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
&& c.table.cur_concrete_types.len == 0 {
pos := type_sym.name.last_index_u8(`.`)
first_letter := type_sym.name[pos + 1]
if !first_letter.is_capital() && (type_sym.kind != .struct_
|| !(type_sym.info is ast.Struct && type_sym.info.is_anon))
if !first_letter.is_capital()
&& (type_sym.kind != .struct || !(type_sym.info is ast.Struct && type_sym.info.is_anon))
&& type_sym.kind != .placeholder {
c.error('cannot initialize builtin type `${type_sym.name}`', node.pos)
}
@ -613,7 +613,7 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
}
}
// string & array are also structs but .kind of string/array
.struct_, .string, .array, .alias {
.struct, .string, .array, .alias {
mut info := ast.Struct{}
if type_sym.kind == .alias {
info_t := type_sym.info as ast.Alias
@ -623,7 +623,7 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
return ast.void_type
}
match sym.kind {
.struct_ {
.struct {
info = sym.info as ast.Struct
}
.array, .array_fixed {
@ -707,10 +707,10 @@ fn (mut c Checker) struct_init(mut node ast.StructInit, is_field_zero_struct_ini
c.check_expr_option_or_result_call(init_field.expr, init_field.typ)
}
if exp_type.has_flag(.option) && got_type.is_ptr() && !(exp_type.is_ptr()
&& exp_type_sym.kind == .struct_) {
&& exp_type_sym.kind == .struct) {
c.error('cannot assign a pointer to option struct field', init_field.pos)
}
if exp_type_sym.kind == .voidptr && got_type_sym.kind == .struct_
if exp_type_sym.kind == .voidptr && got_type_sym.kind == .struct
&& !got_type.is_ptr() {
c.error('allocate `${got_type_sym.name}` on the heap for use in other functions',
init_field.pos)
@ -806,7 +806,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
// all the fields of initialized embedded struct are ignored, they are considered initialized
sym := c.table.sym(init_field.typ)
if init_field.name != '' && init_field.name[0].is_capital() && sym.kind == .struct_
if init_field.name != '' && init_field.name[0].is_capital() && sym.kind == .struct
&& sym.language == .v {
struct_fields := c.table.struct_fields(sym)
for struct_field in struct_fields {
@ -814,7 +814,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
}
}
expected_type_sym := c.table.final_sym(init_field.expected_type)
if expected_type_sym.kind in [.string, .array, .map, .array_fixed, .chan, .struct_]
if expected_type_sym.kind in [.string, .array, .map, .array_fixed, .chan, .struct]
&& init_field.expr.is_nil() && !init_field.expected_type.is_ptr()
&& mut init_field.expr is ast.UnsafeExpr {
c.error('cannot assign `nil` to struct field `${init_field.name}` with type `${expected_type_sym.name}`',
@ -828,7 +828,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
.sum_type {
first_typ := (type_sym.info as ast.SumType).variants[0]
first_sym := c.table.final_sym(first_typ)
if first_sym.kind == .struct_ {
if first_sym.kind == .struct {
mut info := first_sym.info as ast.Struct
c.check_uninitialized_struct_fields_and_embeds(node, first_sym, mut info, mut
inited_fields)
@ -842,7 +842,7 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
expr_sym := c.table.final_sym(c.unwrap_generic(update_type))
if node.update_expr is ast.ComptimeSelector {
c.error('cannot use struct update syntax in compile time expressions', node.update_expr_pos)
} else if expr_sym.kind != .struct_ {
} else if expr_sym.kind != .struct {
s := c.table.type_to_str(update_type)
c.error('expected struct, found `${s}`', node.update_expr.pos())
} else if update_type != node.typ {
@ -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)
}
}
@ -964,12 +964,12 @@ fn (mut c Checker) check_uninitialized_struct_fields_and_embeds(node ast.StructI
continue
}
if !field.typ.has_flag(.option) {
if sym.kind == .struct_ {
if sym.kind == .struct {
c.check_ref_fields_initialized(sym, mut checked_types, '${type_sym.name}.${field.name}',
node.pos)
} else if sym.kind == .alias {
parent_sym := c.table.sym((sym.info as ast.Alias).parent_type)
if parent_sym.kind == .struct_ {
if parent_sym.kind == .struct {
c.check_ref_fields_initialized(parent_sym, mut checked_types, '${type_sym.name}.${field.name}',
node.pos)
}
@ -998,7 +998,7 @@ fn (mut c Checker) check_uninitialized_struct_fields_and_embeds(node ast.StructI
if !node.has_update_expr && !field.has_default_expr && !field.typ.is_ptr()
&& !field.typ.has_flag(.option) {
field_final_sym := c.table.final_sym(field.typ)
if field_final_sym.kind == .struct_ {
if field_final_sym.kind == .struct {
mut zero_struct_init := ast.StructInit{
pos: node.pos
typ: field.typ
@ -1072,7 +1072,7 @@ fn (mut c Checker) check_ref_fields_initialized(struct_sym &ast.TypeSymbol, mut
pos)
} else if sym.info is ast.Alias {
psym := c.table.sym(sym.info.parent_type)
if psym.kind == .struct_ {
if psym.kind == .struct {
checked_types << field.typ
c.check_ref_fields_initialized(psym, mut checked_types, '${linked_name}.${field.name}',
pos)
@ -1115,7 +1115,7 @@ fn (mut c Checker) check_ref_fields_initialized_note(struct_sym &ast.TypeSymbol,
pos)
} else if sym.info is ast.Alias {
psym := c.table.sym(sym.info.parent_type)
if psym.kind == .struct_ {
if psym.kind == .struct {
checked_types << field.typ
c.check_ref_fields_initialized(psym, mut checked_types, '${linked_name}.${field.name}',
pos)

View file

@ -195,7 +195,7 @@ pub fn (mut ct ComptimeInfo) get_comptime_selector_bool_field(field_name string)
'is_array' { return field_sym.kind in [.array, .array_fixed] }
'is_map' { return field_sym.kind == .map }
'is_chan' { return field_sym.kind == .chan }
'is_struct' { return field_sym.kind == .struct_ }
'is_struct' { return field_sym.kind == .struct }
'is_alias' { return field_sym.kind == .alias }
'is_enum' { return field_sym.kind == .enum_ }
else { return false }
@ -221,8 +221,8 @@ pub fn (mut ct ComptimeInfo) is_comptime_type(x ast.Type, y ast.ComptimeType) bo
.float {
return x_kind in [.f32, .f64, .float_literal]
}
.struct_ {
return x_kind == .struct_
.struct {
return x_kind == .struct
}
.iface {
return x_kind == .interface_

View file

@ -23,7 +23,7 @@ pub enum SymbolKind {
typedef
enum_
enum_field
struct_
struct
struct_field
}
@ -91,7 +91,7 @@ pub fn (sk SymbolKind) str() string {
.interface_ { 'interface' }
.typedef { 'type' }
.enum_ { 'enum' }
.struct_ { 'struct' }
.struct { 'struct' }
else { '' }
}
}
@ -255,7 +255,7 @@ pub fn (mut d Doc) stmt(mut stmt ast.Stmt, filename string) !DocNode {
node.kind = .interface_
}
ast.StructDecl {
node.kind = .struct_
node.kind = .struct
if d.extract_vars {
for mut field in stmt.fields {
ret_type := if field.typ == 0 && field.has_default_expr {

View file

@ -789,7 +789,7 @@ pub fn (mut f Fmt) expr(node_ ast.Expr) {
.array { f.write('\$array') }
.array_dynamic { f.write('\$array_dynamic') }
.array_fixed { f.write('\$array_fixed') }
.struct_ { f.write('\$struct') }
.struct { f.write('\$struct') }
.iface { f.write('\$interface') }
.map_ { f.write('\$map') }
.int { f.write('\$int') }

View file

@ -149,7 +149,7 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl, is_anon bool) {
fn (mut f Fmt) write_anon_struct_field_decl(field_typ ast.Type, field_anon_decl ast.StructDecl) bool {
sym := f.table.sym(field_typ)
match sym.kind {
.struct_ {
.struct {
info := sym.info as ast.Struct
if info.is_anon {
f.indent++

View file

@ -154,7 +154,7 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st
elem_type := (array_type.unaliased_sym.info as ast.ArrayFixed).elem_type
mut elem_sym := g.table.final_sym(elem_type)
is_struct := g.inside_array_fixed_struct && elem_sym.kind == .struct_
is_struct := g.inside_array_fixed_struct && elem_sym.kind == .struct
if !is_struct {
g.write('{')
@ -266,7 +266,7 @@ fn (mut g Gen) expr_with_init(node ast.ArrayInit) {
fn (mut g Gen) struct_has_array_or_map_field(elem_typ ast.Type) bool {
unaliased_sym := g.table.final_sym(elem_typ)
if unaliased_sym.kind == .struct_ {
if unaliased_sym.kind == .struct {
info := unaliased_sym.info as ast.Struct
for field in info.fields {
field_sym := g.table.final_sym(field.typ)
@ -450,7 +450,7 @@ fn (mut g Gen) array_init_with_fields(node ast.ArrayInit, elem_type Type, is_amp
g.write('&(${elem_styp}[]){')
g.write('_SLIT("")')
g.write('})')
} else if node.has_len && elem_type.unaliased_sym.kind in [.struct_, .array, .map] {
} else if node.has_len && elem_type.unaliased_sym.kind in [.struct, .array, .map] {
g.write('(voidptr)&(${elem_styp}[]){')
g.write(g.type_default(node.elem_type))
g.write('}[0])')
@ -996,7 +996,7 @@ fn (mut g Gen) gen_array_contains_methods() {
} else if elem_kind == .map && elem_is_not_ptr {
ptr_typ := g.equality_fn(elem_type)
fn_builder.writeln('\t\tif (${ptr_typ}_map_eq(((${elem_type_str}*)a.data)[i], v)) {')
} else if elem_kind == .struct_ && elem_is_not_ptr {
} 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 {
@ -1035,7 +1035,7 @@ fn (mut g Gen) gen_array_contains_methods() {
} else if elem_kind == .map && elem_is_not_ptr {
ptr_typ := g.equality_fn(elem_type)
fn_builder.writeln('\t\tif (${ptr_typ}_map_eq(a[i], v)) {')
} else if elem_kind == .struct_ && elem_is_not_ptr {
} 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 {
@ -1080,7 +1080,7 @@ 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
|| (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('*')
@ -1131,7 +1131,7 @@ fn (mut g Gen) gen_array_index_methods() {
} else if elem_sym.kind == .map && !info.elem_type.is_ptr() {
ptr_typ := g.equality_fn(info.elem_type)
fn_builder.writeln('\t\tif (${ptr_typ}_map_eq((*pelem, v))) {')
} else if elem_sym.kind == .struct_ && !info.elem_type.is_ptr() {
} 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_ {

View file

@ -92,7 +92,7 @@ fn (mut g Gen) assert_subexpression_to_ctemp(expr ast.Expr, expr_type ast.Type)
ast.SelectorExpr {
if expr.expr is ast.CallExpr {
sym := g.table.final_sym(g.unwrap_generic(expr.expr.return_type))
if sym.kind == .struct_ {
if sym.kind == .struct {
if (sym.info as ast.Struct).is_union {
return unsupported_ctemp_assert_transform
}

View file

@ -490,7 +490,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
mut op_expected_left := ast.no_type
mut op_expected_right := ast.no_type
is_shared_re_assign := !is_decl && node.left_types[i].has_flag(.shared_f)
&& left is ast.Ident && left_sym.kind in [.array, .map, .struct_]
&& left is ast.Ident && left_sym.kind in [.array, .map, .struct]
if node.op == .plus_assign && unaliased_right_sym.kind == .string {
if mut left is ast.IndexExpr {
if g.table.sym(left.left_type).kind == .array_fixed {
@ -515,7 +515,7 @@ fn (mut g Gen) assign_stmt(node_ ast.AssignStmt) {
str_add = true
}
// Assignment Operator Overloading
if ((left_sym.kind == .struct_ && right_sym.kind == .struct_)
if ((left_sym.kind == .struct && right_sym.kind == .struct)
|| (left_sym.kind == .alias && right_sym.kind == .alias))
&& node.op in [.plus_assign, .minus_assign, .div_assign, .mult_assign, .mod_assign] {
extracted_op := match node.op {

View file

@ -24,7 +24,7 @@ fn (mut g Gen) gen_equality_fns() {
.sum_type {
g.gen_sumtype_equality_fn(needed_typ)
}
.struct_ {
.struct {
g.gen_struct_equality_fn(needed_typ)
}
.array {
@ -84,7 +84,7 @@ fn (mut g Gen) gen_sumtype_equality_fn(left_type ast.Type) string {
} else if variant.sym.kind == .sum_type && !typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(typ)
fn_builder.writeln('\t\treturn ${eq_fn}_sumtype_eq(*${left_arg}, *${right_arg});')
} else if variant.sym.kind == .struct_ && !typ.is_ptr() {
} else if variant.sym.kind == .struct && !typ.is_ptr() {
eq_fn := g.gen_struct_equality_fn(typ)
fn_builder.writeln('\t\treturn ${eq_fn}_struct_eq(*${left_arg}, *${right_arg});')
} else if variant.sym.kind == .array && !typ.is_ptr() {
@ -229,7 +229,7 @@ fn (mut g Gen) gen_struct_equality_fn(left_type ast.Type) string {
} else if field_type.sym.kind == .sum_type && !field.typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(field.typ)
fn_builder.write_string('${eq_fn}_sumtype_eq(${left_arg}, ${right_arg})')
} else if field_type.sym.kind == .struct_ && !field.typ.is_ptr() {
} else if field_type.sym.kind == .struct && !field.typ.is_ptr() {
eq_fn := g.gen_struct_equality_fn(field.typ)
fn_builder.write_string('${eq_fn}_struct_eq(${left_arg}, ${right_arg})')
} else if field_type.sym.kind == .array && !field.typ.is_ptr() {
@ -301,7 +301,7 @@ fn (mut g Gen) gen_alias_equality_fn(left_type ast.Type) string {
} else if sym.kind == .sum_type && !left.typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(info.parent_type)
fn_builder.writeln('\treturn ${eq_fn}_sumtype_eq(${left_var}, ${right_var});')
} else if sym.kind == .struct_ && !left.typ.is_ptr() {
} 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() {
@ -369,7 +369,7 @@ fn (mut g Gen) gen_array_equality_fn(left_type ast.Type) string {
} else if elem.sym.kind == .sum_type && !elem.typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(elem.typ)
fn_builder.writeln('\t\tif (!${eq_fn}_sumtype_eq(((${ptr_elem_styp}*)${left_data})[i], ((${ptr_elem_styp}*)${right_data})[i])) {')
} else if elem.sym.kind == .struct_ && !elem.typ.is_ptr() {
} 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() {
@ -428,7 +428,7 @@ fn (mut g Gen) gen_fixed_array_equality_fn(left_type ast.Type) string {
} else if elem.sym.kind == .sum_type && !elem.typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(elem.typ)
fn_builder.writeln('\t\tif (!${eq_fn}_sumtype_eq(${left}[i], ${right}[i])) {')
} else if elem.sym.kind == .struct_ && !elem.typ.is_ptr() {
} 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() {
@ -507,7 +507,7 @@ fn (mut g Gen) gen_map_equality_fn(left_type ast.Type) string {
eq_fn := g.gen_sumtype_equality_fn(value.typ)
fn_builder.writeln('\t\tif (!${eq_fn}_sumtype_eq(*(${ptr_value_styp}*)map_get(${b}, k, &(${ptr_value_styp}[]){ 0 }), v)) {')
}
.struct_ {
.struct {
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)) {')
}
@ -583,7 +583,7 @@ fn (mut g Gen) gen_interface_equality_fn(left_type ast.Type) string {
fn_builder.writeln('\t\tif (idx == ${typ.idx()}) {')
fn_builder.write_string('\t\t\treturn ')
match g.table.type_kind(typ.set_nr_muls(0)) {
.struct_ {
.struct {
eq_fn := g.gen_struct_equality_fn(typ)
l_eqfn := g.read_field(left_type, '_${eq_fn}', 'a')
r_eqfn := g.read_field(left_type, '_${eq_fn}', 'b')

View file

@ -78,7 +78,7 @@ fn (mut g Gen) gen_free_for_struct(typ ast.Type, info ast.Struct, styp string, f
field_name := c_name(field.name)
sym := g.table.sym(g.unwrap_generic(field.typ))
if sym.kind !in [.string, .array, .map, .struct_] {
if sym.kind !in [.string, .array, .map, .struct] {
continue
}
mut field_styp := g.typ(field.typ.set_nr_muls(0).clear_flag(.option)).replace('*',
@ -135,7 +135,7 @@ fn (mut g Gen) gen_free_for_array(info ast.Array, styp string, fn_name string) {
fn_builder.writeln('${g.static_modifier} void ${fn_name}(${styp}* it) {')
sym := g.table.sym(g.unwrap_generic(info.elem_type))
if sym.kind in [.string, .array, .map, .struct_] {
if sym.kind in [.string, .array, .map, .struct] {
fn_builder.writeln('\tfor (int i = 0; i < it->len; i++) {')
mut elem_styp := g.typ(info.elem_type).replace('*', '')

View file

@ -903,8 +903,8 @@ 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, .function, .alias, .chan, .thread] {
} 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 {
return .si_s
@ -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("<probably circular>") : '
}
// eprintln('>>> caller_should_free: ${caller_should_free:6s} | funcprefix: $funcprefix | func: $func')
@ -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) {

View file

@ -1178,7 +1178,7 @@ fn (mut g Gen) option_type_name(t ast.Type) (string, string) {
if sym.info is ast.FnType {
base = 'anon_fn_${g.table.fn_type_signature(sym.info.func)}'
}
if sym.language == .c && sym.kind == .struct_ {
if sym.language == .c && sym.kind == .struct {
styp = '${option_name}_${base.replace(' ', '_')}'
} else {
styp = '${option_name}_${base}'
@ -1200,7 +1200,7 @@ fn (mut g Gen) result_type_name(t ast.Type) (string, string) {
if sym.info is ast.FnType {
base = 'anon_fn_${g.table.fn_type_signature(sym.info.func)}'
}
if sym.language == .c && sym.kind == .struct_ {
if sym.language == .c && sym.kind == .struct {
styp = '${result_name}_${base.replace(' ', '_')}'
} else {
styp = '${result_name}_${base}'
@ -1508,7 +1508,7 @@ fn (mut g Gen) cc_type(typ ast.Type, is_prefix_struct bool) string {
}
if is_prefix_struct && sym.language == .c {
styp = styp[3..]
if sym.kind == .struct_ {
if sym.kind == .struct {
info := sym.info as ast.Struct
if !info.is_typedef {
styp = 'struct ${styp}'
@ -5124,7 +5124,7 @@ fn (mut g Gen) cast_expr(node ast.CastExpr) {
} else {
g.expr_with_cast(node.expr, expr_type, node_typ)
}
} else if !node.typ.has_flag(.option) && sym.kind == .struct_ && !node.typ.is_ptr()
} else if !node.typ.has_flag(.option) && sym.kind == .struct && !node.typ.is_ptr()
&& !(sym.info as ast.Struct).is_typedef {
// deprecated, replaced by Struct{...exr}
styp := g.typ(node.typ)
@ -7375,7 +7375,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
return init_str
}
}
.struct_ {
.struct {
mut has_none_zero := false
info := sym.info as ast.Struct
mut init_str := if info.is_anon && !g.inside_global_decl {
@ -7392,7 +7392,7 @@ fn (mut g Gen) type_default(typ_ ast.Type) string {
for field in info.fields {
field_sym := g.table.sym(field.typ)
if field.has_default_expr
|| field_sym.kind in [.array, .map, .string, .bool, .alias, .i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .voidptr, .byteptr, .charptr, .struct_, .chan, .sum_type] {
|| field_sym.kind in [.array, .map, .string, .bool, .alias, .i8, .i16, .int, .i64, .u8, .u16, .u32, .u64, .f32, .f64, .char, .voidptr, .byteptr, .charptr, .struct, .chan, .sum_type] {
if sym.language == .c && !field.has_default_expr {
continue
}
@ -7808,7 +7808,7 @@ fn (mut g Gen) interface_table() string {
if st == ast.voidptr_type || st == ast.nil_type {
cast_struct.write_string('/*.... ast.voidptr_type */')
} else {
if st_sym.kind == .struct_ {
if st_sym.kind == .struct {
if _, embeds := g.table.find_field_from_embeds(st_sym,
field.name)
{
@ -8161,7 +8161,7 @@ pub fn (mut g Gen) contains_ptr(el_typ ast.Type) bool {
info := sym.info as ast.ArrayFixed
return g.contains_ptr(info.elem_type)
}
.struct_ {
.struct {
info := sym.info as ast.Struct
for embed in info.embeds {
if g.contains_ptr(embed) {

View file

@ -820,7 +820,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
// filter vweb route methods (non-generic method)
if method.receiver_type != 0 && method.return_type == typ_vweb_result {
rec_sym := g.table.sym(method.receiver_type)
if rec_sym.kind == .struct_ {
if rec_sym.kind == .struct {
if _ := g.table.find_field_with_embeds(rec_sym, 'Context') {
if method.generic_names.len > 0
|| (method.params.len > 1 && method.attrs.len == 0) {
@ -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
@ -938,7 +938,7 @@ fn (mut g Gen) comptime_for(node ast.ComptimeFor) {
g.writeln('\t${node.val_var}.is_array = ${field_sym.kind in [.array, .array_fixed]};')
g.writeln('\t${node.val_var}.is_map = ${field_sym.kind == .map};')
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_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_};')

View file

@ -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 {
@ -2157,7 +2157,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
mut is_cast_needed := true
if node.left_type != 0 {
left_sym := g.table.sym(node.left_type)
if left_sym.kind == .struct_ && node.name == obj.name {
if left_sym.kind == .struct && node.name == obj.name {
is_cast_needed = false
}
}
@ -2669,7 +2669,7 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
if arg.is_mut && !exp_is_ptr {
g.write('&/*mut*/')
} else if arg.is_mut && arg_typ.is_ptr() && expected_type.is_ptr()
&& g.table.sym(arg_typ).kind == .struct_ && expected_type == arg_typ.ref() {
&& g.table.sym(arg_typ).kind == .struct && expected_type == arg_typ.ref() {
if arg.expr is ast.PrefixExpr && arg.expr.op == .amp {
g.arg_no_auto_deref = true
g.expr(arg.expr)

View file

@ -420,7 +420,7 @@ fn (mut g Gen) for_in_stmt(node_ ast.ForInStmt) {
g.expr(cond)
g.writeln('${field_accessor}str[${i}];')
}
} else if node.kind == .struct_ {
} else if node.kind == .struct {
cond_type_sym := g.table.sym(node.cond_type)
next_fn := cond_type_sym.find_method_with_generic_parent('next') or {
verror('`next` method not found')

View file

@ -396,7 +396,7 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) {
g.typ(val_type.clear_flag(.result))
}
}
get_and_set_types := val_sym.kind in [.struct_, .map, .array, .array_fixed]
get_and_set_types := val_sym.kind in [.struct, .map, .array, .array_fixed]
if g.is_assign_lhs && !g.is_arraymap_set && !get_and_set_types {
if g.assign_op == .assign || info.value_type == ast.string_type {
g.cur_indexexpr << node.pos.pos

View file

@ -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
@ -257,7 +257,7 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
g.expr(node.right)
g.write(')')
}
.struct_ {
.struct {
ptr_typ := g.equality_fn(left.unaliased)
if node.op == .ne {
g.write('!')
@ -353,7 +353,7 @@ fn (mut g Gen) infix_expr_cmp_op(node ast.InfixExpr) {
g.gen_plain_infix_expr(node)
return
}
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 {
if node.op in [.le, .ge] {
g.write('!')
}
@ -635,7 +635,7 @@ 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
@ -654,7 +654,7 @@ fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, right ast.ArrayInit) {
g.write('${ptr_typ}_interface_eq(')
} else if elem_sym.kind == .array {
g.write('${ptr_typ}_arr_eq(')
} else if elem_sym.kind == .struct_ {
} else if elem_sym.kind == .struct {
g.write('${ptr_typ}_struct_eq(')
}
}
@ -841,7 +841,7 @@ fn (mut g Gen) infix_expr_left_shift_op(node ast.InfixExpr) {
array_info := left.unaliased_sym.info as ast.Array
noscan := g.check_noscan(array_info.elem_type)
if (right.unaliased_sym.kind == .array
|| (right.unaliased_sym.kind == .struct_ && right.unaliased_sym.name == 'array'))
|| (right.unaliased_sym.kind == .struct && right.unaliased_sym.name == 'array'))
&& left.sym.nr_dims() == right.sym.nr_dims() && array_info.elem_type != right.typ
&& !(right.sym.kind == .alias
&& g.table.sumtype_has_variant(array_info.elem_type, node.right_type, false)) {

View file

@ -58,7 +58,7 @@ fn (mut g Gen) gen_jsons() {
mut init_styp := '${styp} res'
if utyp.has_flag(.option) {
if sym.kind == .struct_ && !utyp.is_ptr() {
if sym.kind == .struct && !utyp.is_ptr() {
init_styp += ' = '
g.set_current_pos_as_last_stmt_pos()
pos := g.out.len
@ -70,7 +70,7 @@ fn (mut g Gen) gen_jsons() {
init_styp += ' = (${styp}){ .state=2, .err=${none_str}, .data={EMPTY_STRUCT_INITIALIZATION} }'
}
} else {
if sym.kind == .struct_ {
if sym.kind == .struct {
init_styp += ' = '
g.set_current_pos_as_last_stmt_pos()
pos := g.out.len
@ -385,7 +385,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
fv_sym := g.table.sym(first_variant)
first_variant_name := fv_sym.cname
// println('KIND=${fv_sym.kind}')
if fv_sym.kind == .struct_ && !is_option && field_op != '->' {
if fv_sym.kind == .struct && !is_option && field_op != '->' {
dec.writeln('/*sum type ${fv_sym.name} ret_styp=${ret_styp}*/\tif (root->type == cJSON_NULL) { ')
dec.writeln('\t\tstruct ${first_variant_name} empty = {0};')
dec.writeln('res = ${variant_typ}_to_sumtype_${ret_styp}(&empty); } \n else ')
@ -580,7 +580,7 @@ fn (mut g Gen) gen_sumtype_enc_dec(utyp ast.Type, sym ast.TypeSymbol, mut enc st
'cJSON_IsString(root->child)'
} else if var_t.ends_with('bool') {
'cJSON_IsBool(root->child)'
} else if g.table.sym(g.table.value_type(ast.idx_to_type(variant_symbols[i].idx))).kind == .struct_ {
} else if g.table.sym(g.table.value_type(ast.idx_to_type(variant_symbols[i].idx))).kind == .struct {
'cJSON_IsObject(root->child)'
} else {
'cJSON_IsNumber(root->child)'
@ -842,7 +842,7 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
} else if field.typ == ast.string_type {
enc.writeln('${indent}if (${prefix_enc}${op}${c_name(field.name)}.len != 0)')
} else {
if field_sym.kind in [.alias, .sum_type, .map, .array, .struct_] {
if field_sym.kind in [.alias, .sum_type, .map, .array, .struct] {
ptr_typ := g.equality_fn(field.typ)
if field_sym.kind == .alias {
enc.writeln('${indent}if (!${ptr_typ}_alias_eq(${prefix_enc}${op}${c_name(field.name)}, ${g.type_default(field.typ)}))')
@ -852,7 +852,7 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
enc.writeln('${indent}if (!${ptr_typ}_map_eq(${prefix_enc}${op}${c_name(field.name)}, ${g.type_default(field.typ)}))')
} else if field_sym.kind == .array {
enc.writeln('${indent}if (!${ptr_typ}_arr_eq(${prefix_enc}${op}${c_name(field.name)}, ${g.type_default(field.typ)}))')
} else if field_sym.kind == .struct_ {
} else if field_sym.kind == .struct {
enc.writeln('${indent}if (!${ptr_typ}_struct_eq(${prefix_enc}${op}${c_name(field.name)}, ${g.type_default(field.typ)}))')
}
} else {

View file

@ -496,7 +496,7 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
g.expr(expr)
g.write(')')
}
.struct_ {
.struct {
derefs_expr := '*'.repeat(g.get_expr_type(expr).nr_muls())
derefs_ctype := '*'.repeat(node.cond_type.nr_muls())
ptr_typ := g.equality_fn(node.cond_type)

View file

@ -309,7 +309,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
for field in node.fields {
sym := g.table.sym(field.typ)
if sym.kind == .struct_ && sym.name != 'time.Time' {
if sym.kind == .struct && sym.name != 'time.Time' {
subs << unsafe { node.sub_structs[int(field.typ)] }
unwrapped_c_typ := g.typ(field.typ.clear_flag(.option))
subs_unwrapped_c_typ << if field.typ.has_flag(.option) { unwrapped_c_typ } else { '' }
@ -405,7 +405,7 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
mut sym := g.table.sym(field.typ)
mut typ := sym.cname
mut ctyp := sym.cname
if sym.kind == .struct_ && typ != 'time__Time' {
if sym.kind == .struct && typ != 'time__Time' {
g.writeln('(*(orm__Primitive*) array_get(${last_ids_arr}, ${structs})),')
structs++
continue
@ -900,7 +900,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
types << '_const_orm__time_'
continue
}
if sym.kind == .struct_ {
if sym.kind == .struct {
types << int(ast.int_type).str()
continue
} else if sym.kind == .enum_ {
@ -1039,7 +1039,7 @@ fn (mut g Gen) write_orm_select(node ast.SqlExpr, connection_var_name string, re
sym := g.table.sym(field.typ)
field_var := '${tmp}.${c_name(field.name)}'
field_c_typ := g.typ(field.typ)
if sym.kind == .struct_ && sym.name != 'time.Time' {
if sym.kind == .struct && sym.name != 'time.Time' {
mut sub := node.sub_structs[int(field.typ)]
mut where_expr := sub.where_expr as ast.InfixExpr
mut ident := where_expr.right as ast.Ident
@ -1247,7 +1247,7 @@ fn (g &Gen) get_orm_column_name_from_struct_field(field ast.StructField) string
}
sym := g.table.sym(field.typ)
if sym.kind == .struct_ && sym.name != 'time.Time' {
if sym.kind == .struct && sym.name != 'time.Time' {
name = '${name}_id'
}

View file

@ -80,7 +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_, .struct_, .enum_, .interface_] {
kind_name := if tsym.kind in [.none_, .enum_, .interface_] {
tsym.kind.str() + '_'
} else {
tsym.kind.str()
@ -159,7 +159,7 @@ fn (mut g Gen) gen_reflection_sym_info(tsym ast.TypeSymbol) string {
s := 'ADDR(${cprefix}SumType,(((${cprefix}SumType){.parent_idx=${info.parent_type.idx()},.variants=${g.gen_type_array(info.variants)}})))'
return '(${cprefix}TypeInfo){._${cprefix}SumType=memdup(${s},sizeof(${cprefix}SumType)),._typ=${g.table.find_type_idx('v.reflection.SumType')}}'
}
.struct_ {
.struct {
info := tsym.info as ast.Struct
attrs := g.gen_attrs_array(info.attrs)
fields := g.gen_fields_array(info.fields)

View file

@ -96,7 +96,7 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
name
}
if !(expr.is_method && (g.table.sym(expr.receiver_type).kind == .interface_
|| (g.table.sym(expr.receiver_type).kind == .struct_ && expr.is_field))) {
|| (g.table.sym(expr.receiver_type).kind == .struct && expr.is_field))) {
g.writeln('${arg_tmp_var}${dot}fn = ${fn_name};')
}
if expr.is_method {
@ -321,7 +321,7 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
g.gowrappers.write_string('${idot}_typ]._method_${mname}(')
g.gowrappers.write_string('arg->arg0')
g.gowrappers.write_string('${idot}_object')
} else if typ_sym.kind == .struct_ && expr.is_field {
} else if typ_sym.kind == .struct && expr.is_field {
g.gowrappers.write_string('arg->arg0')
idot := if expr.left_type.is_ptr() { '->' } else { '.' }
mname := c_name(expr.name)
@ -330,7 +330,7 @@ fn (mut g Gen) spawn_and_go_expr(node ast.SpawnExpr, mode SpawnGoMode) {
g.gowrappers.write_string('arg->fn(')
g.gowrappers.write_string('arg->arg0')
}
if expr.args.len > 0 && (typ_sym.kind != .struct_ || !expr.is_field) {
if expr.args.len > 0 && (typ_sym.kind != .struct || !expr.is_field) {
g.gowrappers.write_string(', ')
}
} else {

View file

@ -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()

View file

@ -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 {

View file

@ -57,7 +57,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
if sym.kind == .array_fixed {
arr_info := sym.array_fixed_info()
is_array_fixed_struct_init = g.inside_return
&& g.table.final_sym(arr_info.elem_type).kind == .struct_
&& g.table.final_sym(arr_info.elem_type).kind == .struct
}
// detect if we need type casting on msvc initialization
@ -145,14 +145,14 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
g.is_shared = false
}
mut field_name := init_field.name
if node.no_keys && sym.kind == .struct_ {
if node.no_keys && sym.kind == .struct {
info := sym.info as ast.Struct
if info.fields.len == node.init_fields.len {
field_name = info.fields[i].name
}
}
inited_fields[field_name] = i
if sym.kind != .struct_ && (sym.kind == .string || !sym.is_primitive()) {
if sym.kind != .struct && (sym.kind == .string || !sym.is_primitive()) {
if init_field.typ == 0 {
g.checker_bug('struct init, field.typ is 0', init_field.pos)
}
@ -172,7 +172,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
// The rest of the fields are zeroed.
// `inited_fields` is a list of fields that have been init'ed, they are skipped
mut nr_fields := 1
if sym.kind == .struct_ {
if sym.kind == .struct {
mut info := sym.info as ast.Struct
nr_fields = info.fields.len
if info.is_union && node.init_fields.len > 1 {
@ -267,7 +267,7 @@ fn (mut g Gen) struct_init(node ast.StructInit) {
sfield.expected_type = tt
}
}
if node.no_keys && sym.kind == .struct_ {
if node.no_keys && sym.kind == .struct {
sym_info := sym.info as ast.Struct
if sym_info.fields.len == node.init_fields.len {
sfield.name = sym_info.fields[already_inited_node_field_index].name

View file

@ -31,7 +31,7 @@ fn (mut g Gen) unwrap_generic(typ ast.Type) ast.Type {
}
}
}
} else if typ.has_flag(.generic) && g.table.sym(typ).kind == .struct_ {
} else if typ.has_flag(.generic) && g.table.sym(typ).kind == .struct {
// resolve selector `a.foo` where `a` is struct[T] on non generic function
sym := g.table.sym(typ)
if sym.info is ast.Struct {

View file

@ -666,7 +666,7 @@ pub fn (mut f Gen) expr(node_ ast.Expr) {
.array { f.write('\$array') }
.array_dynamic { f.write('\$array_dynamic') }
.array_fixed { f.write('\$array_fixed') }
.struct_ { f.write('\$struct') }
.struct { f.write('\$struct') }
.iface { f.write('\$interface') }
.map_ { f.write('\$map') }
.int { f.write('\$int') }

View file

@ -38,7 +38,7 @@ fn (mut g JsGen) gen_array_index_method(left_type ast.Type) string {
} else if elem_sym.kind == .map && !info.elem_type.is_ptr() {
ptr_typ := g.gen_map_equality_fn(info.elem_type)
fn_builder.writeln('\t\tif (${ptr_typ}_map_eq(pelem.get(new int(i)), v).val) {')
} else if elem_sym.kind == .struct_ && !info.elem_type.is_ptr() {
} else if elem_sym.kind == .struct && !info.elem_type.is_ptr() {
ptr_typ := g.gen_struct_equality_fn(info.elem_type)
fn_builder.writeln('\t\tif (${ptr_typ}_struct_eq(pelem.get(new int(i)), v)) {')
} else {
@ -187,7 +187,7 @@ fn (mut g JsGen) gen_array_contains_method(left_type ast.Type) string {
} else if elem_sym.kind == .map && left_info.elem_type.nr_muls() == 0 {
ptr_typ := g.gen_map_equality_fn(left_info.elem_type)
fn_builder.writeln('\t\tif (${ptr_typ}_map_eq(a.arr.get(new int(i)),v).val) {')
} else if elem_sym.kind == .struct_ && left_info.elem_type.nr_muls() == 0 {
} else if elem_sym.kind == .struct && left_info.elem_type.nr_muls() == 0 {
ptr_typ := g.gen_struct_equality_fn(left_info.elem_type)
fn_builder.writeln('\t\tif (${ptr_typ}_struct_eq(a.arr.get(new int(i)),v).val) {')
} else {

View file

@ -27,7 +27,7 @@ fn (mut g JsGen) gen_sumtype_equality_fn(left_type ast.Type) string {
} else if variant.sym.kind == .sum_type && !typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(typ)
fn_builder.writeln('\t\treturn ${eq_fn}_sumtype_eq(a,b);')
} else if variant.sym.kind == .struct_ && !typ.is_ptr() {
} else if variant.sym.kind == .struct && !typ.is_ptr() {
eq_fn := g.gen_struct_equality_fn(typ)
fn_builder.writeln('\t\treturn ${eq_fn}_struct_eq(a,b);')
} else if variant.sym.kind == .array && !typ.is_ptr() {
@ -90,7 +90,7 @@ fn (mut g JsGen) gen_struct_equality_fn(left_type ast.Type) string {
} else if field_type.sym.kind == .sum_type && !field.typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(field.typ)
fn_builder.write_string('${eq_fn}_sumtype_eq(a.${field_name}, b.${field_name})')
} else if field_type.sym.kind == .struct_ && !field.typ.is_ptr() {
} else if field_type.sym.kind == .struct && !field.typ.is_ptr() {
eq_fn := g.gen_struct_equality_fn(field.typ)
fn_builder.write_string('${eq_fn}_struct_eq(a.${field_name}, b.${field_name})')
} else if field_type.sym.kind == .array && !field.typ.is_ptr() {
@ -140,7 +140,7 @@ fn (mut g JsGen) gen_alias_equality_fn(left_type ast.Type) string {
} else if sym.kind == .sum_type && !left.typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(info.parent_type)
fn_builder.writeln('\treturn ${eq_fn}_sumtype_eq(a, b);')
} else if sym.kind == .struct_ && !left.typ.is_ptr() {
} 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(a, b);')
} else if sym.kind == .array && !left.typ.is_ptr() {
@ -186,7 +186,7 @@ fn (mut g JsGen) gen_array_equality_fn(left_type ast.Type) string {
} else if elem.sym.kind == .sum_type && !elem.typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(elem.typ)
fn_builder.writeln('\t\tif (!${eq_fn}_sumtype_eq(a.arr.get(new int(i)),b.arr.get(new int(i))).val) {')
} else if elem.sym.kind == .struct_ && !elem.typ.is_ptr() {
} 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(a.arr.get(new int(i)),b.arr.get(new int(i))).val) {')
} else if elem.sym.kind == .array && !elem.typ.is_ptr() {
@ -238,7 +238,7 @@ fn (mut g JsGen) gen_fixed_array_equality_fn(left_type ast.Type) string {
} else if elem.sym.kind == .sum_type && !elem.typ.is_ptr() {
eq_fn := g.gen_sumtype_equality_fn(elem.typ)
fn_builder.writeln('\t\tif (!${eq_fn}_sumtype_eq(a.arr.get(new int(i)), b.arr.get(new int(i))).val) {')
} else if elem.sym.kind == .struct_ && !elem.typ.is_ptr() {
} 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(a.arr.get(new int(i)), b.arr.get(new int(i))).val) {')
} else if elem.sym.kind == .array && !elem.typ.is_ptr() {
@ -295,7 +295,7 @@ fn (mut g JsGen) gen_map_equality_fn(left_type ast.Type) string {
} else if kind == .sum_type {
eq_fn := g.gen_sumtype_equality_fn(value.typ)
fn_builder.writeln('\t\tif (!${eq_fn}_sumtype_eq(x,y).val) {')
} else if kind == .struct_ {
} else if kind == .struct {
eq_fn := g.gen_struct_equality_fn(value.typ)
fn_builder.writeln('\t\tif (!${eq_fn}_struct_eq(x,y).val) {')
} else if kind == .array {

View file

@ -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,8 +662,8 @@ 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, .function, .alias, .chan] {
} 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 {
return .si_s
@ -759,7 +759,7 @@ fn (mut g JsGen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name st
fn_builder.write_string('isnil(it.${g.js_name(field.name)})')
fn_builder.write_string(' ? new string("nil") : ')
// struct, floats and ints have a special case through the _str function
if sym.kind != .struct_ && !field.typ.is_int_valptr() && !field.typ.is_float_valptr() {
if sym.kind != .struct && !field.typ.is_int_valptr() && !field.typ.is_float_valptr() {
fn_builder.write_string('*')
}
}
@ -771,7 +771,7 @@ fn (mut g JsGen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name st
if field.typ in ast.charptr_types {
fn_builder.write_string('tos4((byteptr)${func})')
} else {
if field.typ.is_ptr() && sym.kind == .struct_ {
if field.typ.is_ptr() && sym.kind == .struct {
fn_builder.write_string('(indent_count > 25)? new string("<probably circular>") : ')
}
fn_builder.write_string(func)

View file

@ -41,7 +41,7 @@ fn (mut g JsGen) to_js_typ_val(t ast.Type) string {
.array {
styp = 'empty_array()'
}
.struct_ {
.struct {
styp = 'new ${g.js_name(sym.name)}(${g.to_js_typ_def_val(sym.name)})'
}
.voidptr {
@ -197,7 +197,7 @@ pub fn (mut g JsGen) doc_typ(t ast.Type) string {
styp = 'any'
}
// ns.Foo => alias["Foo"]["prototype"]
.struct_ {
.struct {
styp = g.struct_typ(sym.name)
}
.generic_inst {}

View file

@ -95,7 +95,7 @@ fn (mut g JsGen) infix_expr_eq_op(node ast.InfixExpr) {
g.write('.valueOf()')
}
} else if left.typ.idx() == right.typ.idx()
&& left.sym.kind in [.array, .array_fixed, .alias, .map, .struct_, .sum_type] {
&& left.sym.kind in [.array, .array_fixed, .alias, .map, .struct, .sum_type] {
match left.sym.kind {
.alias {
ptr_typ := g.gen_alias_equality_fn(left.typ)
@ -161,7 +161,7 @@ fn (mut g JsGen) infix_expr_eq_op(node ast.InfixExpr) {
g.write('.valueOf()')
}
}
.struct_ {
.struct {
ptr_typ := g.gen_struct_equality_fn(left.unaliased)
if node.op == .ne {
g.write('!')

View file

@ -1093,7 +1093,7 @@ fn (mut g JsGen) assert_subexpression_to_ctemp(expr ast.Expr, expr_type ast.Type
ast.SelectorExpr {
if expr.expr is ast.CallExpr {
sym := g.table.final_sym(g.unwrap_generic(expr.expr.return_type))
if sym.kind == .struct_ {
if sym.kind == .struct {
if (sym.info as ast.Struct).is_union {
return unsupported_ctemp_assert_transform
}
@ -2263,7 +2263,7 @@ fn (mut g JsGen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var M
g.expr(expr)
g.write('.str')
}
.struct_ {
.struct {
ptr_typ := g.gen_struct_equality_fn(node.cond_type)
g.write('${ptr_typ}_struct_eq(')
@ -3304,7 +3304,7 @@ fn (mut g JsGen) gen_string_inter_literal(it ast.StringInterLiteral) {
typ := g.unwrap_generic(it.expr_types[i])
/*
g.expr(expr)
if sym.kind == .struct_ && sym.has_method('str') {
if sym.kind == .struct && sym.has_method('str') {
g.write('.str()')
}*/
g.gen_expr_to_string(expr, typ)
@ -3346,7 +3346,7 @@ fn (mut g JsGen) gen_struct_init(it ast.StructInit) {
name = name[0..name.index('<') or { name.len }]
}
if it.init_fields.len == 0 && type_sym.kind != .interface_ {
if type_sym.kind == .struct_ && type_sym.language == .js {
if type_sym.kind == .struct && type_sym.language == .js {
g.write('{}')
} else {
g.write('new ${g.js_name(name)}({})')
@ -3366,7 +3366,7 @@ fn (mut g JsGen) gen_struct_init(it ast.StructInit) {
g.writeln('return tmp')
g.dec_indent()
g.writeln('})()')
} else if type_sym.kind == .struct_ && type_sym.language == .js {
} else if type_sym.kind == .struct && type_sym.language == .js {
g.writeln('{')
g.inc_indent()
for i, init_field in it.init_fields {

View file

@ -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}(')
@ -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)

View file

@ -1729,7 +1729,7 @@ pub fn (mut c Amd64) call_fn(node ast.CallExpr) {
return_size := c.g.get_type_size(node.return_type)
mut return_pos := i32(-1)
mut is_struct_return := false
if ts.kind in [.struct_, .multi_return] {
if ts.kind in [.struct, .multi_return] {
return_pos = c.g.allocate_by_type('', node.return_type)
if return_size > 16 {
is_struct_return = true
@ -1802,7 +1802,7 @@ pub fn (mut c Amd64) call_fn(node ast.CallExpr) {
continue
}
c.g.expr(args[i].expr)
if c.g.table.sym(args[i].typ).kind == .struct_ && !args[i].typ.is_ptr() {
if c.g.table.sym(args[i].typ).kind == .struct && !args[i].typ.is_ptr() {
match args_size[i] {
1...8 {
c.mov_deref(Amd64Register.rax, Amd64Register.rax, ast.i64_type_idx)
@ -1877,7 +1877,7 @@ pub fn (mut c Amd64) call_fn(node ast.CallExpr) {
}
c.g.println('call `${n}()`')
if ts.kind in [.struct_, .multi_return] {
if ts.kind in [.struct, .multi_return] {
match return_size {
1...7 {
c.mov_var_to_reg(Amd64Register.rdx, LocalVar{
@ -2323,7 +2323,7 @@ fn (mut c Amd64) return_stmt(node ast.Return) {
size := c.g.get_type_size(typ)
if c.g.pref.arch == .amd64 {
match ts.kind {
.struct_, .multi_return {
.struct, .multi_return {
if size <= 8 {
c.mov_deref(Amd64Register.rax, Amd64Register.rax, ast.i64_type_idx)
if size != 8 {
@ -2631,7 +2631,7 @@ fn (mut c Amd64) assign_stmt(node ast.AssignStmt) {
}
ts := c.g.table.sym(typ)
match ts.kind {
.struct_ {
.struct {
size := c.g.get_type_size(typ)
if size >= 8 {
for j in 0 .. size / 8 {
@ -3096,7 +3096,7 @@ fn (mut c Amd64) fn_decl(node ast.FnDecl) {
// The first parameter is an address of returned struct if size > 16
ts := c.g.table.sym(node.return_type)
return_size := c.g.get_type_size(node.return_type)
if ts.kind in [.struct_, .multi_return] {
if ts.kind in [.struct, .multi_return] {
if return_size > 16 {
params << ast.Param{
name: '_return_val_addr'

View file

@ -368,7 +368,7 @@ fn (mut g Gen) gen_print_from_expr(expr ast.Expr, typ ast.Type, name string) {
ast.OffsetOf {
styp := g.typ(expr.struct_type)
field_name := expr.field
if styp.kind == .struct_ {
if styp.kind == .struct {
off := g.get_field_offset(expr.struct_type, field_name)
if newline {
g.code_gen.gen_print('${off}\n', fd)

View file

@ -316,7 +316,7 @@ fn (mut g Gen) for_in_stmt(node ast.ForInStmt) { // Work on that
} else if node.kind == .array_fixed {
} else if node.kind == .map {
} else if node.kind == .string {
} else if node.kind == .struct_ {
} else if node.kind == .struct {
} else if it.kind in [.array, .string] || it.cond_type.has_flag(.variadic) {
} else if it.kind == .map {
*/

View file

@ -853,7 +853,7 @@ pub fn (mut g Gen) expr(node ast.Expr, expected ast.Type) {
}
ast.OffsetOf {
styp := g.table.sym(node.struct_type)
if styp.kind != .struct_ {
if styp.kind != .struct {
g.v_error('__offsetof expects a struct Type as first argument', node.pos)
}
off := g.get_field_offset(node.struct_type, node.field)

View file

@ -165,7 +165,7 @@ pub fn (mut w Walker) stmt(node_ ast.Stmt) {
if node.kind == .map {
w.table.used_maps++
}
if node.kind == .struct_ {
if node.kind == .struct {
if node.cond_type == 0 {
return
}
@ -327,7 +327,7 @@ fn (mut w Walker) expr(node_ ast.Expr) {
return
}
sym := w.table.sym(node.left_type)
if sym.kind == .struct_ {
if sym.kind == .struct {
if opmethod := sym.find_method(node.op.str()) {
unsafe {
w.fn_decl(mut &ast.FnDecl(opmethod.source_fn))
@ -432,7 +432,7 @@ fn (mut w Walker) expr(node_ ast.Expr) {
return
}
sym := w.table.sym(node.typ)
if sym.kind == .struct_ {
if sym.kind == .struct {
info := sym.info as ast.Struct
w.a_struct_info(sym.name, info)
}
@ -496,7 +496,7 @@ pub fn (mut w Walker) a_struct_info(sname string, info ast.Struct) {
if fsym.kind == .map {
w.table.used_maps++
}
if fsym.kind == .struct_ {
if fsym.kind == .struct {
w.a_struct_info(fsym.name, fsym.struct_info())
}
}

View file

@ -25,7 +25,7 @@ fn (mut p Parser) parse_comptime_type() ast.ComptimeType {
.map_
}
'struct' {
.struct_
.struct
}
'interface' {
.iface

View file

@ -766,7 +766,7 @@ fn (mut p Parser) fn_receiver(mut params []ast.Param, mut rec ReceiverParsingInf
// optimize method `automatic use fn (a &big_foo) instead of fn (a big_foo)`
type_sym := p.table.sym(rec.typ)
mut is_auto_rec := false
if type_sym.kind == .struct_ {
if type_sym.kind == .struct {
info := type_sym.info as ast.Struct
if !rec.is_mut && !rec.typ.is_ptr() && info.fields.len > 8 {
rec.typ = rec.typ.ref()
@ -988,7 +988,7 @@ fn (mut p Parser) fn_params() ([]ast.Param, bool, bool, bool) {
p.error_with_pos('generic object cannot be `atomic`or `shared`', pos)
return []ast.Param{}, false, false, false
}
if param_type.is_ptr() && p.table.sym(param_type).kind == .struct_ {
if param_type.is_ptr() && p.table.sym(param_type).kind == .struct {
param_type = param_type.ref()
} else {
param_type = param_type.set_nr_muls(1)
@ -1117,7 +1117,7 @@ fn (mut p Parser) fn_params() ([]ast.Param, bool, bool, bool) {
pos)
return []ast.Param{}, false, false, false
}
if typ.is_ptr() && p.table.sym(typ).kind == .struct_ {
if typ.is_ptr() && p.table.sym(typ).kind == .struct {
typ = typ.ref()
} else {
typ = typ.set_nr_muls(1)
@ -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
}
@ -1291,7 +1291,7 @@ fn (mut p Parser) check_fn_shared_arguments(typ ast.Type, pos token.Pos) {
if sym.kind == .generic_inst {
sym = p.table.type_symbols[(sym.info as ast.GenericInst).parent_idx]
}
if sym.kind !in [.array, .struct_, .map, .placeholder] && !typ.is_ptr() {
if sym.kind !in [.array, .struct, .map, .placeholder] && !typ.is_ptr() {
p.error_with_pos('shared arguments are only allowed for arrays, maps, and structs\n',
pos)
}

View file

@ -354,7 +354,7 @@ fn (mut p Parser) struct_decl(is_anon bool) ast.StructDecl {
}
is_minify := attrs.contains('minify')
mut sym := ast.TypeSymbol{
kind: .struct_
kind: .struct
language: language
name: name
cname: util.no_dots(name)

View file

@ -71,7 +71,7 @@ pub enum VKind {
map
chan
any
struct_
struct
generic_inst
multi_return
sum_type
@ -258,7 +258,7 @@ pub fn get_funcs() []Function {
}
pub fn get_structs() []Type {
struct_idxs := g_reflection.type_symbols.filter(it.kind == .struct_).map(it.idx)
struct_idxs := g_reflection.type_symbols.filter(it.kind == .struct).map(it.idx)
return g_reflection.types.filter(it.idx in struct_idxs)
}

View file

@ -94,7 +94,7 @@ fn test_enum_sym() {
fn test_struct_sym() {
var := reflection.type_of(Test{})
assert var.sym.kind == .struct_
assert var.sym.kind == .struct
assert (var.sym.info as reflection.Struct).attrs.len == 1
assert (var.sym.info as reflection.Struct).attrs == ['test_struct']