const (
void_type_idx = 1
voidptr_type_idx = 2
byteptr_type_idx = 3
charptr_type_idx = 4
i8_type_idx = 5
i16_type_idx = 6
int_type_idx = 7
i64_type_idx = 8
byte_type_idx = 9
u16_type_idx = 10
u32_type_idx = 11
u64_type_idx = 12
f32_type_idx = 13
f64_type_idx = 14
char_type_idx = 15
bool_type_idx = 16
none_type_idx = 17
string_type_idx = 18
ustring_type_idx = 19
rune_type_idx = 20
array_type_idx = 21
map_type_idx = 22
chan_type_idx = 23
sizet_type_idx = 24
any_type_idx = 25
float_literal_type_idx = 26
int_literal_type_idx = 27
gohandle_type_idx = 28
)
const (
integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, byte_type_idx,
u16_type_idx, u32_type_idx, u64_type_idx, int_literal_type_idx, rune_type_idx]
signed_integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx]
unsigned_integer_type_idxs = [byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx]
float_type_idxs = [f32_type_idx, f64_type_idx, float_literal_type_idx]
number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, byte_type_idx,
u16_type_idx, u32_type_idx, u64_type_idx, f32_type_idx, f64_type_idx, int_literal_type_idx,
float_literal_type_idx, rune_type_idx]
pointer_type_idxs = [voidptr_type_idx, byteptr_type_idx, charptr_type_idx]
string_type_idxs = [string_type_idx, ustring_type_idx]
)
const (
void_type = new_type(void_type_idx)
ovoid_type = new_type(void_type_idx).set_flag(.optional)
voidptr_type = new_type(voidptr_type_idx)
byteptr_type = new_type(byteptr_type_idx)
charptr_type = new_type(charptr_type_idx)
i8_type = new_type(i8_type_idx)
int_type = new_type(int_type_idx)
i16_type = new_type(i16_type_idx)
i64_type = new_type(i64_type_idx)
byte_type = new_type(byte_type_idx)
u16_type = new_type(u16_type_idx)
u32_type = new_type(u32_type_idx)
u64_type = new_type(u64_type_idx)
f32_type = new_type(f32_type_idx)
f64_type = new_type(f64_type_idx)
char_type = new_type(char_type_idx)
bool_type = new_type(bool_type_idx)
none_type = new_type(none_type_idx)
string_type = new_type(string_type_idx)
ustring_type = new_type(ustring_type_idx)
rune_type = new_type(rune_type_idx)
array_type = new_type(array_type_idx)
map_type = new_type(map_type_idx)
chan_type = new_type(chan_type_idx)
any_type = new_type(any_type_idx)
float_literal_type = new_type(float_literal_type_idx)
int_literal_type = new_type(int_literal_type_idx)
gohandle_type = new_type(gohandle_type_idx)
)
const (
builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16',
'u32', 'u64', 'int_literal', 'f32', 'f64', 'float_literal', 'string', 'ustring', 'char',
'byte', 'bool', 'none', 'array', 'array_fixed', 'map', 'chan', 'any', 'struct', 'mapnode',
'size_t', 'rune', 'gohandle']
)
fn new_table() &Table
fn new_type(idx int) Type
return new type with TypeSymbol idx set to idx
fn new_type_ptr(idx int, nr_muls int) Type
return new type with TypeSymbol idx set to idx
& nr_muls set to nr_muls
fn (attrs []Attr) contains(str string) bool
fn (kinds []Kind) str() string
type FExpr = byteptr | voidptr
NB: FExpr here is a actually an ast.Expr . It should always be used by casting to ast.Expr, using ast.fe2ex()/ast.ex2fe() That hack is needed to break an import cycle between v.ast and v.table .
type Type = int
fn (t Type) atomic_typename() string
<atomic.h> defines special typenames
fn (t Type) idx() int
return TypeSymbol idx for t
fn (t Type) is_void() bool
fn (t Type) is_full() bool
fn (t Type) nr_muls() int
return nr_muls for t
fn (t Type) is_ptr() bool
return true if t
is a pointer (nr_muls>0)
fn (t Type) set_nr_muls(nr_muls int) Type
set nr_muls on t
and return it
fn (t Type) to_ptr() Type
increments nr_nuls on t
and return it
fn (t Type) deref() Type
decrement nr_muls on t
and return it
fn (t Type) set_flag(flag TypeFlag) Type
set flag
on t
and return t
fn (t Type) clear_flag(flag TypeFlag) Type
clear flag
on t
and return t
fn (t Type) clear_flags() Type
clear all flags
fn (t Type) has_flag(flag TypeFlag) bool
return true if flag
is set on t
fn (t Type) debug() []string
fn (t Type) derive(t_from Type) Type
copy flags & nr_muls from t_from
to t
and return t
fn (typ Type) is_pointer() bool
built in pointers (voidptr, byteptr, charptr)
fn (typ Type) is_float() bool
fn (typ Type) is_int() bool
fn (typ Type) is_signed() bool
fn (typ Type) is_unsigned() bool
fn (typ Type) is_int_literal() bool
fn (typ Type) is_number() bool
fn (typ Type) is_string() bool
type TypeInfo = Aggregate | Alias | Array | ArrayFixed | Chan | Enum | FnType | GenericStructInst |
GoHandle | Interface | Map | MultiReturn | Struct | SumType
enum Kind {
placeholder
void
voidptr
byteptr
charptr
i8
i16
int
i64
byte
u16
u32
u64
f32
f64
char
size_t
rune
bool
none_
string
ustring
array
array_fixed
map
chan
any
struct_
generic_struct_inst
multi_return
sum_type
alias
enum_
function
interface_
float_literal
int_literal
aggregate
gohandle
}
fn (k Kind) str() string
for debugging/errors only, perf is not an issue
enum Language {
v
c
js
}
enum TypeFlag {
optional
variadic
generic
shared_f
atomic_f
}
max of 8
struct Aggregate {
mut:
fields []Field
pub:
types []Type
}
struct Alias {
pub:
parent_type Type
language Language
is_import bool
}
struct Array {
pub:
nr_dims int
pub mut:
elem_type Type
}
struct ArrayFixed {
pub:
size int
pub mut:
elem_type Type
}
struct Attr {
pub:
name string
is_string bool
is_ctdefine bool
arg string
is_string_arg bool
pos token.Position
}
e.g. [unsafe]
fn (attr Attr) str() string
no square brackets
struct Chan {
pub mut:
elem_type Type
is_mut bool
}
struct Enum {
pub:
vals []string
is_flag bool
is_multi_allowed bool
}
struct Field {
pub:
name string
pub mut:
typ Type
default_expr FExpr
has_default_expr bool
default_val string
attrs []Attr
is_pub bool
is_mut bool
is_global bool
}
struct Fn {
pub:
params []Param
return_type Type
is_variadic bool
language Language
generic_names []string
is_pub bool
is_deprecated bool
is_unsafe bool
is_placeholder bool
no_body bool
mod string
ctdefine string
attrs []Attr
pub mut:
name string
source_fn voidptr
}
struct FnSignatureOpts {
skip_receiver bool
type_only bool
}
struct FnType {
pub:
is_anon bool
has_decl bool
func Fn
}
struct GenericStructInst {
pub mut:
parent_idx int
generic_types []Type
}
instantiation of a generic struct
struct GoHandle {
pub mut:
return_type Type
}
struct Interface {
pub mut:
types []Type
fields []Field
methods []Fn
}
fn (i &Interface) find_field(name string) ?Field
fn (i Interface) defines_method(name string) bool
struct Map {
pub mut:
key_type Type
value_type Type
}
struct MultiReturn {
pub mut:
types []Type
}
struct Param {
pub:
pos token.Position
name string
is_mut bool
typ Type
type_pos token.Position
is_hidden bool
}
struct Struct {
pub:
attrs []Attr
pub mut:
embeds []Type
fields []Field
is_typedef bool
is_union bool
is_ref_only bool
generic_types []Type
}
fn (s Struct) find_field(name string) ?Field
fn (s Struct) get_field(name string) Field
struct SumType {
pub:
variants []Type
}
struct Table {
pub mut:
types []TypeSymbol
type_idxs map[string]int
fns map[string]Fn
imports []string
modules []string
cflags []cflag.CFlag
redefined_fns []string
fn_gen_types map[string][][]Type
cmod_prefix string
is_fmt bool
}
fn (mut t Table) add_placeholder_type(name string, language Language) int
fn (t &Table) array_cname(elem_type Type) string
fn (t &Table) array_fixed_cname(elem_type Type, size int) string
fn (t &Table) array_fixed_name(elem_type Type, size int) string
array_fixed_source_name generates the original name for the v source. e. g. [16][8]int
fn (t &Table) array_name(elem_type Type) string
array_source_name generates the original name for the v source. e. g. []int
fn (t &Table) chan_cname(elem_type Type, is_mut bool) string
fn (t &Table) chan_name(elem_type Type, is_mut bool) string
fn (t &Table) find_field(s &TypeSymbol, name string) ?Field
search from current type up through each parent looking for field
fn (t &Table) find_fn(name string) ?Fn
fn (mut t Table) find_or_register_array(elem_type Type) int
fn (mut t Table) find_or_register_array_fixed(elem_type Type, size int) int
fn (mut t Table) find_or_register_array_with_dims(elem_type Type, nr_dims int) int
fn (mut t Table) find_or_register_chan(elem_type Type, is_mut bool) int
fn (mut t Table) find_or_register_fn_type(mod string, f Fn, is_anon bool, has_decl bool) int
fn (mut t Table) find_or_register_gohandle(return_type Type) int
fn (mut t Table) find_or_register_map(key_type Type, value_type Type) int
fn (mut t Table) find_or_register_multi_return(mr_typs []Type) int
fn (t &Table) find_type(name string) ?TypeSymbol
fn (t &Table) find_type_idx(name string) int
fn (t &Table) fn_signature(func &Fn, opts FnSignatureOpts) string
fn (t &Table) fn_type_signature(f &Fn) string
used to compare fn's & for naming anon fn's
fn (t &Table) fn_type_source_signature(f &Fn) string
source_signature generates the signature of a function which looks like in the V source
fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol
get_final_type_symbol follows aliases until it gets to a "real" Type
fn (t &Table) get_type_name(typ Type) string
fn (t &Table) get_type_symbol(typ Type) &TypeSymbol
fn (t &Table) gohandle_cname(return_type Type) string
fn (t &Table) gohandle_name(return_type Type) string
fn (mytable &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool
has_deep_child_no_ref returns true if type is struct and has any child or nested child with the type of the given name the given name consists of module and name (mod.Name
) it doesn't care about childs that are references
fn (t &Table) is_same_method(f &Fn, func &Fn) string
fn (t &Table) known_fn(name string) bool
fn (t &Table) known_type(name string) bool
fn (mytable &Table) known_type_names() []string
fn (t &Table) map_cname(key_type Type, value_type Type) string
fn (t &Table) map_name(key_type Type, value_type Type) string
map_source_name generates the original name for the v source. e. g. map[string]int
fn (t &Table) mktyp(typ Type) Type
fn (mut mytable Table) parse_cflag(cflg string, mod string, ctimedefines []string) ?bool
parse the flags to (table.cflags) []CFlag Note: clean up big time (joe-c)
fn (t &Table) register_aggregate_method(mut sym TypeSymbol, name string) ?Fn
fn (mut t Table) register_builtin_type_symbols()
fn (mut t Table) register_fn(new_fn Fn)
fn (mut mytable Table) register_fn_gen_type(fn_name string, types []Type)
fn (mut t Table) register_type_symbol(typ TypeSymbol) int
fn (t &Table) struct_has_field(s &TypeSymbol, name string) bool
fn (mytable &Table) sumtype_has_variant(parent Type, variant Type) bool
TODO: there is a bug when casting sumtype the other way if its pointer so until fixed at least show v (not C) error x(variant) = y(SumType*)
fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn
search from current type up through each parent looking for method
fn (t &Table) type_has_method(s &TypeSymbol, name string) bool
fn (table &Table) type_kind(typ Type) Kind
returns TypeSymbol kind only if there are no type modifiers
fn (mytable &Table) type_to_code(t Type) string
type name in code (for builtin)
fn (table &Table) type_to_str(t Type) string
human readable type name
fn (mytable &Table) type_to_str_using_aliases(t Type, import_aliases map[string]string) string
import_aliases is a map of imported symbol aliases 'module.Type' => 'Type'
fn (t &Table) unalias_num_type(typ Type) Type
fn (t &Table) value_type(typ Type) Type
struct TypeSymbol {
pub:
parent_idx int
pub mut:
info TypeInfo
kind Kind
name string
cname string
methods []Fn
mod string
is_public bool
language Language
}
Represents a type that only needs an identifier, e.g. int, array_int. A pointer type &T
would have a TypeSymbol T
. Note: For a Type, use: * Table.type_to_str(typ) not TypeSymbol.name. * Table.type_kind(typ) not TypeSymbol.kind. Each TypeSymbol is entered into Table.types
. See also: Table.get_type_symbol.
fn (t &TypeSymbol) array_fixed_info() ArrayFixed
fn (t &TypeSymbol) array_info() Array
fn (t &TypeSymbol) chan_info() Chan
fn (ts TypeSymbol) debug() []string
fn (t &TypeSymbol) embed_name() string
fn (t &TypeSymbol) enum_info() Enum
fn (t &TypeSymbol) find_field(name string) ?Field
fn (t &TypeSymbol) find_method(name string) ?Fn
fn (t &TypeSymbol) gohandle_info() GoHandle
fn (t &TypeSymbol) has_method(name string) bool
fn (t &TypeSymbol) is_builtin() bool
fn (t &TypeSymbol) is_float() bool
fn (t &TypeSymbol) is_int() bool
fn (t &TypeSymbol) is_number() bool
fn (t &TypeSymbol) is_pointer() bool
fn (t &TypeSymbol) is_primitive() bool
fn (t &TypeSymbol) is_string() bool
fn (t &TypeSymbol) map_info() Map
fn (t &TypeSymbol) mr_info() MultiReturn
fn (mut t TypeSymbol) register_method(new_fn Fn) int
fn (t &TypeSymbol) str() string
fn (t &TypeSymbol) str_method_info() (bool, bool, int)
fn (t &TypeSymbol) struct_info() Struct
struct Var {
pub:
name string
is_mut bool
mut:
typ Type
}