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
|
// generic struct instantiations to concrete types
|
||||||
pub fn (b &Builder) generic_struct_insts_to_concrete() {
|
pub fn (b &Builder) generic_struct_insts_to_concrete() {
|
||||||
for idx, _ in b.table.types {
|
for idx, _ in b.table.type_symbols {
|
||||||
mut typ := unsafe { &b.table.types[idx] }
|
mut typ := unsafe { &b.table.type_symbols[idx] }
|
||||||
if typ.kind == .generic_struct_inst {
|
if typ.kind == .generic_struct_inst {
|
||||||
info := typ.info as table.GenericStructInst
|
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 {
|
if parent.kind == .placeholder {
|
||||||
typ.kind = .placeholder
|
typ.kind = .placeholder
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -5954,7 +5954,7 @@ fn (mut c Checker) sql_expr(mut node ast.SqlExpr) table.Type {
|
||||||
info := sym.info as table.Struct
|
info := sym.info as table.Struct
|
||||||
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, sym.name)
|
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, sym.name)
|
||||||
mut sub_structs := map[int]ast.SqlExpr{}
|
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{
|
mut n := ast.SqlExpr{
|
||||||
pos: node.pos
|
pos: node.pos
|
||||||
has_where: true
|
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
|
info := table_sym.info as table.Struct
|
||||||
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, table_sym.name)
|
fields := c.fetch_and_verify_orm_fields(info, node.table_expr.pos, table_sym.name)
|
||||||
mut sub_structs := map[int]ast.SqlStmt{}
|
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{
|
mut n := ast.SqlStmt{
|
||||||
pos: node.pos
|
pos: node.pos
|
||||||
db_expr: node.db_expr
|
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 {
|
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]
|
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 {
|
if fields.len == 0 {
|
||||||
c.error('V orm: select: empty fields in `$table_name`', pos)
|
c.error('V orm: select: empty fields in `$table_name`', pos)
|
||||||
return []table.Field{}
|
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
|
// to make sure type idx's are the same in cached mods
|
||||||
if g.pref.build_mode == .build_module {
|
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 {
|
if idx == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
g.definitions.writeln('int _v_type_idx_${typ.cname}();')
|
g.definitions.writeln('int _v_type_idx_${typ.cname}();')
|
||||||
}
|
}
|
||||||
} else if g.pref.use_cache {
|
} else if g.pref.use_cache {
|
||||||
for idx, typ in g.table.types {
|
for idx, typ in g.table.type_symbols {
|
||||||
if idx == 0 {
|
if idx == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,7 @@ pub fn (mut g Gen) init() {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
// methods
|
// methods
|
||||||
for type_sym in g.table.types {
|
for type_sym in g.table.type_symbols {
|
||||||
if type_sym.mod != 'main' {
|
if type_sym.mod != 'main' {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -491,7 +491,7 @@ pub fn (mut g Gen) finish() {
|
||||||
pub fn (mut g Gen) write_typeof_functions() {
|
pub fn (mut g Gen) write_typeof_functions() {
|
||||||
g.writeln('')
|
g.writeln('')
|
||||||
g.writeln('// >> typeof() support for sum types / interfaces')
|
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 {
|
if typ.kind == .sum_type {
|
||||||
sum_info := typ.info as table.SumType
|
sum_info := typ.info as table.SumType
|
||||||
g.writeln('static char * v_typeof_sumtype_${typ.cname}(int sidx) { /* $typ.name */ ')
|
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
|
idx := i - node.args.len
|
||||||
if m.params[i].typ.is_int() || m.params[i].typ.idx() == table.bool_type_idx {
|
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
|
// 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])')
|
g.write('string_${type_name}(((string*)${node.args[node.args.len - 1]}.data) [$idx])')
|
||||||
} else {
|
} else {
|
||||||
g.write('((string*)${node.args[node.args.len - 1]}.data) [$idx] ')
|
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'
|
x := '${node.object_var_name}.$field.name'
|
||||||
if field.typ == table.string_type {
|
if field.typ == table.string_type {
|
||||||
g.writeln('sqlite3_bind_text($g.sql_stmt_name, ${i + 0}, ${x}.str, ${x}.len, 0);')
|
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
|
// insert again
|
||||||
expr := node.sub_structs[int(field.typ)]
|
expr := node.sub_structs[int(field.typ)]
|
||||||
tmp_sql_stmt_name := g.sql_stmt_name
|
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('if ($string_data != NULL) {')
|
||||||
g.writeln('\t${tmp}.$field.name = tos_clone($string_data);')
|
g.writeln('\t${tmp}.$field.name = tos_clone($string_data);')
|
||||||
g.writeln('}')
|
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()
|
id_name := g.new_tmp_var()
|
||||||
g.writeln('//parse struct start')
|
g.writeln('//parse struct start')
|
||||||
g.writeln('int $id_name = ${func}($g.sql_stmt_name, $i);')
|
g.writeln('int $id_name = ${func}($g.sql_stmt_name, $i);')
|
||||||
|
|
|
@ -192,7 +192,9 @@ pub fn (mut p Parser) expr(precedence int) ast.Expr {
|
||||||
pos: pos
|
pos: pos
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
save_expr_mod := p.expr_mod
|
||||||
p.expr_mod = ''
|
p.expr_mod = ''
|
||||||
sizeof_type := p.parse_type()
|
sizeof_type := p.parse_type()
|
||||||
|
|
|
@ -9,7 +9,7 @@ import v.util
|
||||||
|
|
||||||
pub struct Table {
|
pub struct Table {
|
||||||
pub mut:
|
pub mut:
|
||||||
types []TypeSymbol
|
type_symbols []TypeSymbol
|
||||||
type_idxs map[string]int
|
type_idxs map[string]int
|
||||||
fns map[string]Fn
|
fns map[string]Fn
|
||||||
dumps map[int]string // needed for efficiently generating all _v_dump_expr_TNAME() functions
|
dumps map[int]string // needed for efficiently generating all _v_dump_expr_TNAME() functions
|
||||||
|
@ -92,7 +92,7 @@ mut:
|
||||||
|
|
||||||
pub fn new_table() &Table {
|
pub fn new_table() &Table {
|
||||||
mut t := &Table{
|
mut t := &Table{
|
||||||
types: []TypeSymbol{cap: 64000}
|
type_symbols: []TypeSymbol{cap: 64000}
|
||||||
}
|
}
|
||||||
t.register_builtin_type_symbols()
|
t.register_builtin_type_symbols()
|
||||||
t.is_fmt = true
|
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 {
|
if ts.parent_idx == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
ts = unsafe { &t.types[ts.parent_idx] }
|
ts = unsafe { &t.type_symbols[ts.parent_idx] }
|
||||||
}
|
}
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
|
@ -308,7 +308,7 @@ pub fn (t &Table) find_field(s &TypeSymbol, name string) ?Field {
|
||||||
if ts.parent_idx == 0 {
|
if ts.parent_idx == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
ts = unsafe { &t.types[ts.parent_idx] }
|
ts = unsafe { &t.type_symbols[ts.parent_idx] }
|
||||||
}
|
}
|
||||||
return none
|
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 {
|
pub fn (t &Table) find_type(name string) ?TypeSymbol {
|
||||||
idx := t.type_idxs[name]
|
idx := t.type_idxs[name]
|
||||||
if idx > 0 {
|
if idx > 0 {
|
||||||
return t.types[idx]
|
return t.type_symbols[idx]
|
||||||
}
|
}
|
||||||
return none
|
return none
|
||||||
}
|
}
|
||||||
|
@ -398,7 +398,7 @@ pub fn (t &Table) get_type_symbol(typ Type) &TypeSymbol {
|
||||||
// println('get_type_symbol $typ')
|
// println('get_type_symbol $typ')
|
||||||
idx := typ.idx()
|
idx := typ.idx()
|
||||||
if idx > 0 {
|
if idx > 0 {
|
||||||
return unsafe { &t.types[idx] }
|
return unsafe { &t.type_symbols[idx] }
|
||||||
}
|
}
|
||||||
// this should never happen
|
// 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.
|
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 {
|
pub fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol {
|
||||||
idx := typ.idx()
|
idx := typ.idx()
|
||||||
if idx > 0 {
|
if idx > 0 {
|
||||||
current_type := t.types[idx]
|
current_type := t.type_symbols[idx]
|
||||||
if current_type.kind == .alias {
|
if current_type.kind == .alias {
|
||||||
alias_info := current_type.info as Alias
|
alias_info := current_type.info as Alias
|
||||||
return t.get_final_type_symbol(alias_info.parent_type)
|
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
|
// 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.')
|
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 )')
|
// println('register_type_symbol( $typ.name )')
|
||||||
existing_idx := t.type_idxs[typ.name]
|
existing_idx := t.type_idxs[typ.name]
|
||||||
if existing_idx > 0 {
|
if existing_idx > 0 {
|
||||||
ex_type := t.types[existing_idx]
|
ex_type := t.type_symbols[existing_idx]
|
||||||
match ex_type.kind {
|
match ex_type.kind {
|
||||||
.placeholder {
|
.placeholder {
|
||||||
// override placeholder
|
// override placeholder
|
||||||
// println('overriding type placeholder `$typ.name`')
|
// println('overriding type placeholder `$typ.name`')
|
||||||
t.types[existing_idx] = TypeSymbol{
|
t.type_symbols[existing_idx] = TypeSymbol{
|
||||||
...typ
|
...typ
|
||||||
methods: ex_type.methods
|
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)
|
if (existing_idx >= string_type_idx && existing_idx <= map_type_idx)
|
||||||
|| existing_idx == error_type_idx {
|
|| existing_idx == error_type_idx {
|
||||||
if existing_idx == string_type_idx {
|
if existing_idx == string_type_idx {
|
||||||
// existing_type := t.types[existing_idx]
|
// existing_type := t.type_symbols[existing_idx]
|
||||||
t.types[existing_idx] = TypeSymbol{
|
t.type_symbols[existing_idx] = TypeSymbol{
|
||||||
...typ
|
...typ
|
||||||
kind: ex_type.kind
|
kind: ex_type.kind
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.types[existing_idx] = typ
|
t.type_symbols[existing_idx] = typ
|
||||||
}
|
}
|
||||||
return existing_idx
|
return existing_idx
|
||||||
}
|
}
|
||||||
|
@ -476,8 +476,8 @@ pub fn (mut t Table) register_type_symbol(typ TypeSymbol) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typ_idx := t.types.len
|
typ_idx := t.type_symbols.len
|
||||||
t.types << typ
|
t.type_symbols << typ
|
||||||
t.type_idxs[typ.name] = typ_idx
|
t.type_idxs[typ.name] = typ_idx
|
||||||
return 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
|
anon := f.name.len == 0 || is_anon
|
||||||
// existing
|
// existing
|
||||||
existing_idx := t.type_idxs[name]
|
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 existing_idx
|
||||||
}
|
}
|
||||||
return t.register_type_symbol(
|
return t.register_type_symbol(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user