mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.table: correct table.types
to table.type_symbols
This commit is contained in:
parent
4a12546971
commit
a386be6505
@ -7,11 +7,11 @@ import v.table
|
||||
//
|
||||
// generic struct instantiations to concrete types
|
||||
pub fn (b &Builder) generic_struct_insts_to_concrete() {
|
||||
for idx, _ in b.table.types {
|
||||
mut typ := unsafe { &b.table.types[idx] }
|
||||
for idx, _ in b.table.type_symbols {
|
||||
mut typ := unsafe { &b.table.type_symbols[idx] }
|
||||
if typ.kind == .generic_struct_inst {
|
||||
info := typ.info as table.GenericStructInst
|
||||
parent := b.table.types[info.parent_idx]
|
||||
parent := b.table.type_symbols[info.parent_idx]
|
||||
if parent.kind == .placeholder {
|
||||
typ.kind = .placeholder
|
||||
continue
|
||||
|
@ -5954,7 +5954,7 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) table.Type {
|
||||
info := sym.info as table.Struct
|
||||
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, sym.name)
|
||||
mut sub_structs := map[int]ast.SqlExpr{}
|
||||
for f in fields.filter(c.table.types[int(it.typ)].kind == .struct_) {
|
||||
for f in fields.filter(c.table.type_symbols[int(it.typ)].kind == .struct_) {
|
||||
mut n := ast.SqlExpr{
|
||||
pos: node.pos
|
||||
has_where: true
|
||||
@ -6030,7 +6030,7 @@ fn (mut c Checker) sql_stmt(mut node ast.SqlStmt) table.Type {
|
||||
info := table_sym.info as table.Struct
|
||||
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, table_sym.name)
|
||||
mut sub_structs := map[int]ast.SqlStmt{}
|
||||
for f in fields.filter(c.table.types[int(it.typ)].kind == .struct_) {
|
||||
for f in fields.filter(c.table.type_symbols[int(it.typ)].kind == .struct_) {
|
||||
mut n := ast.SqlStmt{
|
||||
pos: node.pos
|
||||
db_expr: node.db_expr
|
||||
@ -6061,7 +6061,7 @@ fn (mut c Checker) sql_stmt(mut node ast.SqlStmt) table.Type {
|
||||
|
||||
fn (mut c Checker) fetch_and_verify_orm_fields(info table.Struct, pos token.Position, table_name string) []table.Field {
|
||||
fields := info.fields.filter((it.typ in [table.string_type, table.int_type, table.bool_type]
|
||||
|| c.table.types[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
|
||||
|| c.table.type_symbols[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
|
||||
if fields.len == 0 {
|
||||
c.error('V orm: select: empty fields in `$table_name`', pos)
|
||||
return []table.Field{}
|
||||
|
@ -252,14 +252,14 @@ pub fn gen(files []ast.File, table &table.Table, pref &pref.Preferences) string
|
||||
}
|
||||
// to make sure type idx's are the same in cached mods
|
||||
if g.pref.build_mode == .build_module {
|
||||
for idx, typ in g.table.types {
|
||||
for idx, typ in g.table.type_symbols {
|
||||
if idx == 0 {
|
||||
continue
|
||||
}
|
||||
g.definitions.writeln('int _v_type_idx_${typ.cname}();')
|
||||
}
|
||||
} else if g.pref.use_cache {
|
||||
for idx, typ in g.table.types {
|
||||
for idx, typ in g.table.type_symbols {
|
||||
if idx == 0 {
|
||||
continue
|
||||
}
|
||||
@ -454,7 +454,7 @@ pub fn (mut g Gen) init() {
|
||||
i++
|
||||
}
|
||||
// methods
|
||||
for type_sym in g.table.types {
|
||||
for type_sym in g.table.type_symbols {
|
||||
if type_sym.mod != 'main' {
|
||||
continue
|
||||
}
|
||||
@ -491,7 +491,7 @@ pub fn (mut g Gen) finish() {
|
||||
pub fn (mut g Gen) write_typeof_functions() {
|
||||
g.writeln('')
|
||||
g.writeln('// >> typeof() support for sum types / interfaces')
|
||||
for typ in g.table.types {
|
||||
for typ in g.table.type_symbols {
|
||||
if typ.kind == .sum_type {
|
||||
sum_info := typ.info as table.SumType
|
||||
g.writeln('static char * v_typeof_sumtype_${typ.cname}(int sidx) { /* $typ.name */ ')
|
||||
|
@ -125,7 +125,7 @@ fn (mut g Gen) comptime_call(node ast.ComptimeCall) {
|
||||
idx := i - node.args.len
|
||||
if m.params[i].typ.is_int() || m.params[i].typ.idx() == table.bool_type_idx {
|
||||
// Gets the type name and cast the string to the type with the string_<type> function
|
||||
type_name := g.table.types[int(m.params[i].typ)].str()
|
||||
type_name := g.table.type_symbols[int(m.params[i].typ)].str()
|
||||
g.write('string_${type_name}(((string*)${node.args[node.args.len - 1]}.data) [$idx])')
|
||||
} else {
|
||||
g.write('((string*)${node.args[node.args.len - 1]}.data) [$idx] ')
|
||||
|
@ -135,7 +135,7 @@ fn (mut g Gen) sqlite3_stmt(node ast.SqlStmt, typ SqlType) {
|
||||
x := '${node.object_var_name}.$field.name'
|
||||
if field.typ == table.string_type {
|
||||
g.writeln('sqlite3_bind_text($g.sql_stmt_name, ${i + 0}, ${x}.str, ${x}.len, 0);')
|
||||
} else if g.table.types[int(field.typ)].kind == .struct_ {
|
||||
} else if g.table.type_symbols[int(field.typ)].kind == .struct_ {
|
||||
// insert again
|
||||
expr := node.sub_structs[int(field.typ)]
|
||||
tmp_sql_stmt_name := g.sql_stmt_name
|
||||
@ -300,7 +300,7 @@ fn (mut g Gen) sqlite3_select_expr(node ast.SqlExpr, sub bool, line string, sql_
|
||||
g.writeln('if ($string_data != NULL) {')
|
||||
g.writeln('\t${tmp}.$field.name = tos_clone($string_data);')
|
||||
g.writeln('}')
|
||||
} else if g.table.types[int(field.typ)].kind == .struct_ {
|
||||
} else if g.table.type_symbols[int(field.typ)].kind == .struct_ {
|
||||
id_name := g.new_tmp_var()
|
||||
g.writeln('//parse struct start')
|
||||
g.writeln('int $id_name = ${func}($g.sql_stmt_name, $i);')
|
||||
|
@ -69,7 +69,7 @@ mut:
|
||||
label_names []string
|
||||
in_generic_params bool // indicates if parsing between `<` and `>` of a method/function
|
||||
name_error bool // indicates if the token is not a name or the name is on another line
|
||||
n_asm int // controls assembly labels
|
||||
n_asm int // controls assembly labels
|
||||
inside_asm_template bool
|
||||
inside_asm bool
|
||||
}
|
||||
@ -877,7 +877,7 @@ fn (mut p Parser) asm_stmt(is_top_level bool) ast.AsmStmt {
|
||||
parent: 0 // you shouldn't be able to reference other variables in assembly blocks
|
||||
detached_from_parent: true
|
||||
start_pos: p.tok.pos
|
||||
objects: ast.all_registers(mut p.table, arch) //
|
||||
objects: ast.all_registers(mut p.table, arch) //
|
||||
}
|
||||
|
||||
mut local_labels := []string{}
|
||||
|
@ -192,7 +192,9 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||
pos: pos
|
||||
}
|
||||
} else {
|
||||
p.register_used_import(p.tok.lit)
|
||||
if p.tok.kind == .name {
|
||||
p.register_used_import(p.tok.lit)
|
||||
}
|
||||
save_expr_mod := p.expr_mod
|
||||
p.expr_mod = ''
|
||||
sizeof_type := p.parse_type()
|
||||
|
@ -9,7 +9,7 @@ import v.util
|
||||
|
||||
pub struct Table {
|
||||
pub mut:
|
||||
types []TypeSymbol
|
||||
type_symbols []TypeSymbol
|
||||
type_idxs map[string]int
|
||||
fns map[string]Fn
|
||||
dumps map[int]string // needed for efficiently generating all _v_dump_expr_TNAME() functions
|
||||
@ -92,7 +92,7 @@ mut:
|
||||
|
||||
pub fn new_table() &Table {
|
||||
mut t := &Table{
|
||||
types: []TypeSymbol{cap: 64000}
|
||||
type_symbols: []TypeSymbol{cap: 64000}
|
||||
}
|
||||
t.register_builtin_type_symbols()
|
||||
t.is_fmt = true
|
||||
@ -235,7 +235,7 @@ pub fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn {
|
||||
if ts.parent_idx == 0 {
|
||||
break
|
||||
}
|
||||
ts = unsafe { &t.types[ts.parent_idx] }
|
||||
ts = unsafe { &t.type_symbols[ts.parent_idx] }
|
||||
}
|
||||
return none
|
||||
}
|
||||
@ -308,7 +308,7 @@ pub fn (t &Table) find_field(s &TypeSymbol, name string) ?Field {
|
||||
if ts.parent_idx == 0 {
|
||||
break
|
||||
}
|
||||
ts = unsafe { &t.types[ts.parent_idx] }
|
||||
ts = unsafe { &t.type_symbols[ts.parent_idx] }
|
||||
}
|
||||
return none
|
||||
}
|
||||
@ -388,7 +388,7 @@ pub fn (t &Table) find_type_idx(name string) int {
|
||||
pub fn (t &Table) find_type(name string) ?TypeSymbol {
|
||||
idx := t.type_idxs[name]
|
||||
if idx > 0 {
|
||||
return t.types[idx]
|
||||
return t.type_symbols[idx]
|
||||
}
|
||||
return none
|
||||
}
|
||||
@ -398,7 +398,7 @@ pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol {
|
||||
// println('get_type_symbol $typ')
|
||||
idx := typ.idx()
|
||||
if idx > 0 {
|
||||
return unsafe { &t.types[idx] }
|
||||
return unsafe { &t.type_symbols[idx] }
|
||||
}
|
||||
// this should never happen
|
||||
panic('get_type_symbol: invalid type (typ=$typ idx=$idx). Compiler bug. This should never happen. Please create a GitHub issue.
|
||||
@ -410,12 +410,12 @@ pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol {
|
||||
pub fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol {
|
||||
idx := typ.idx()
|
||||
if idx > 0 {
|
||||
current_type := t.types[idx]
|
||||
current_type := t.type_symbols[idx]
|
||||
if current_type.kind == .alias {
|
||||
alias_info := current_type.info as Alias
|
||||
return t.get_final_type_symbol(alias_info.parent_type)
|
||||
}
|
||||
return unsafe { &t.types[idx] }
|
||||
return unsafe { &t.type_symbols[idx] }
|
||||
}
|
||||
// this should never happen
|
||||
panic('get_final_type_symbol: invalid type (typ=$typ idx=$idx). Compiler bug. This should never happen. Please create a GitHub issue.')
|
||||
@ -444,12 +444,12 @@ pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||
// println('register_type_symbol( $typ.name )')
|
||||
existing_idx := t.type_idxs[typ.name]
|
||||
if existing_idx > 0 {
|
||||
ex_type := t.types[existing_idx]
|
||||
ex_type := t.type_symbols[existing_idx]
|
||||
match ex_type.kind {
|
||||
.placeholder {
|
||||
// override placeholder
|
||||
// println('overriding type placeholder `$typ.name`')
|
||||
t.types[existing_idx] = TypeSymbol{
|
||||
t.type_symbols[existing_idx] = TypeSymbol{
|
||||
...typ
|
||||
methods: ex_type.methods
|
||||
}
|
||||
@ -462,13 +462,13 @@ pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||
if (existing_idx >= string_type_idx && existing_idx <= map_type_idx)
|
||||
|| existing_idx == error_type_idx {
|
||||
if existing_idx == string_type_idx {
|
||||
// existing_type := t.types[existing_idx]
|
||||
t.types[existing_idx] = TypeSymbol{
|
||||
// existing_type := t.type_symbols[existing_idx]
|
||||
t.type_symbols[existing_idx] = TypeSymbol{
|
||||
...typ
|
||||
kind: ex_type.kind
|
||||
}
|
||||
} else {
|
||||
t.types[existing_idx] = typ
|
||||
t.type_symbols[existing_idx] = typ
|
||||
}
|
||||
return existing_idx
|
||||
}
|
||||
@ -476,8 +476,8 @@ pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||
}
|
||||
}
|
||||
}
|
||||
typ_idx := t.types.len
|
||||
t.types << typ
|
||||
typ_idx := t.type_symbols.len
|
||||
t.type_symbols << typ
|
||||
t.type_idxs[typ.name] = typ_idx
|
||||
return typ_idx
|
||||
}
|
||||
@ -772,7 +772,7 @@ pub fn (mut t Table) find_or_register_fn_type(mod string, f Fn, is_anon bool, ha
|
||||
anon := f.name.len == 0 || is_anon
|
||||
// existing
|
||||
existing_idx := t.type_idxs[name]
|
||||
if existing_idx > 0 && t.types[existing_idx].kind != .placeholder {
|
||||
if existing_idx > 0 && t.type_symbols[existing_idx].kind != .placeholder {
|
||||
return existing_idx
|
||||
}
|
||||
return t.register_type_symbol(
|
||||
@ -906,15 +906,15 @@ pub fn (mytable &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool
|
||||
|
||||
// bitsize_to_type returns a type corresponding to the bit_size
|
||||
// Examples:
|
||||
//
|
||||
//
|
||||
// `8 > i8`
|
||||
//
|
||||
//
|
||||
// `32 > int`
|
||||
//
|
||||
//
|
||||
// `123 > panic()`
|
||||
//
|
||||
//
|
||||
// `128 > [16]byte`
|
||||
//
|
||||
//
|
||||
// `608 > [76]byte`
|
||||
pub fn (mut t Table) bitsize_to_type(bit_size int) Type {
|
||||
match bit_size {
|
||||
|
Loading…
Reference in New Issue
Block a user