v.table #

Constants #

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 #

fn new_table() &Table

fn new_type #

fn new_type(idx int) Type

return new type with TypeSymbol idx set to idx

fn new_type_ptr #

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 sharetype_from_flags #

fn sharetype_from_flags(is_shared bool, is_atomic bool) ShareType

fn ([]Attr) contains #

fn (attrs []Attr) contains(str string) bool

fn ([]Kind) str #

fn (kinds []Kind) str() string

type FExpr #

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 #

type Type = int

fn (Type) atomic_typename #

fn (t Type) atomic_typename() string

<atomic.h> defines special typenames

fn (Type) share #

fn (t Type) share() ShareType

fn (Type) idx #

fn (t Type) idx() int

return TypeSymbol idx for t

fn (Type) is_void #

fn (t Type) is_void() bool

fn (Type) is_full #

fn (t Type) is_full() bool

fn (Type) nr_muls #

fn (t Type) nr_muls() int

return nr_muls for t

fn (Type) is_ptr #

fn (t Type) is_ptr() bool

return true if t is a pointer (nr_muls>0)

fn (Type) set_nr_muls #

fn (t Type) set_nr_muls(nr_muls int) Type

set nr_muls on t and return it

fn (Type) to_ptr #

fn (t Type) to_ptr() Type

increments nr_nuls on t and return it

fn (Type) deref #

fn (t Type) deref() Type

decrement nr_muls on t and return it

fn (Type) set_flag #

fn (t Type) set_flag(flag TypeFlag) Type

set flag on t and return t

fn (Type) clear_flag #

fn (t Type) clear_flag(flag TypeFlag) Type

clear flag on t and return t

fn (Type) clear_flags #

fn (t Type) clear_flags() Type

clear all flags

fn (Type) has_flag #

fn (t Type) has_flag(flag TypeFlag) bool

return true if flag is set on t

fn (Type) debug #

fn (t Type) debug() []string

fn (Type) derive #

fn (t Type) derive(t_from Type) Type

copy flags & nr_muls from t_from to t and return t

fn (Type) is_pointer #

fn (typ Type) is_pointer() bool

built in pointers (voidptr, byteptr, charptr)

fn (Type) is_float #

fn (typ Type) is_float() bool

fn (Type) is_int #

fn (typ Type) is_int() bool

fn (Type) is_signed #

fn (typ Type) is_signed() bool

fn (Type) is_unsigned #

fn (typ Type) is_unsigned() bool

fn (Type) is_int_literal #

fn (typ Type) is_int_literal() bool

fn (Type) is_number #

fn (typ Type) is_number() bool

fn (Type) is_string #

fn (typ Type) is_string() bool

type TypeInfo #

type TypeInfo = Aggregate | Alias | Array | ArrayFixed | Chan | Enum | FnType | GenericStructInst |
	GoHandle | Interface | Map | MultiReturn | Struct | SumType

enum Kind #

enum Kind {

fn (Kind) str #

fn (k Kind) str() string

for debugging/errors only, perf is not an issue

enum Language #

enum Language {

enum ShareType #

enum ShareType {

fn (ShareType) str #

fn (t ShareType) str() string

enum TypeFlag #

enum TypeFlag {

max of 8

struct Aggregate #

struct Aggregate {
	fields []Field
	types []Type

struct Alias #

struct Alias {
	parent_type Type
	language    Language
	is_import   bool

struct Array #

struct Array {
	nr_dims int
pub mut:
	elem_type Type

struct ArrayFixed #

struct ArrayFixed {
	size int
pub mut:
	elem_type Type

struct Attr #

struct Attr {
	name          string
	is_string     bool
	is_ctdefine   bool
	arg           string
	is_string_arg bool
	pos           token.Position

e.g. [unsafe]

fn (Attr) str #

fn (attr Attr) str() string

no square brackets

struct Chan #

struct Chan {
pub mut:
	elem_type Type
	is_mut    bool

struct Enum #

struct Enum {
	vals             []string
	is_flag          bool
	is_multi_allowed bool

struct Field #

struct Field {
	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 #

struct Fn {
	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 #

struct FnSignatureOpts {
	skip_receiver bool
	type_only     bool

struct FnType #

struct FnType {
	is_anon  bool
	has_decl bool
	func     Fn

struct GenericStructInst #

struct GenericStructInst {
pub mut:
	parent_idx    int
	generic_types []Type

instantiation of a generic struct

struct GoHandle #

struct GoHandle {
pub mut:
	return_type Type

struct Interface #

struct Interface {
pub mut:
	types   []Type
	fields  []Field
	methods []Fn

fn (Interface) find_field #

fn (i &Interface) find_field(name string) ?Field

fn (Interface) defines_method #

fn (i Interface) defines_method(name string) bool

struct Map #

struct Map {
pub mut:
	key_type   Type
	value_type Type

struct MultiReturn #

struct MultiReturn {
pub mut:
	types []Type

struct Param #

struct Param {
	pos       token.Position
	name      string
	is_mut    bool
	typ       Type
	type_pos  token.Position
	is_hidden bool

struct Struct #

struct Struct {
	attrs []Attr
pub mut:
	embeds        []Type
	fields        []Field
	is_typedef    bool
	is_union      bool
	is_ref_only   bool
	generic_types []Type

fn (Struct) find_field #

fn (s Struct) find_field(name string) ?Field

fn (Struct) get_field #

fn (s Struct) get_field(name string) Field

struct SumType #

struct SumType {
	variants []Type

struct Table #

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 (Table) add_placeholder_type #

fn (mut t Table) add_placeholder_type(name string, language Language) int

fn (Table) array_cname #

fn (t &Table) array_cname(elem_type Type) string

fn (Table) array_fixed_cname #

fn (t &Table) array_fixed_cname(elem_type Type, size int) string

fn (Table) array_fixed_name #

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 (Table) array_name #

fn (t &Table) array_name(elem_type Type) string

array_source_name generates the original name for the v source. e. g. []int

fn (Table) chan_cname #

fn (t &Table) chan_cname(elem_type Type, is_mut bool) string

fn (Table) chan_name #

fn (t &Table) chan_name(elem_type Type, is_mut bool) string

fn (Table) find_field #

fn (t &Table) find_field(s &TypeSymbol, name string) ?Field

search from current type up through each parent looking for field

fn (Table) find_fn #

fn (t &Table) find_fn(name string) ?Fn

fn (Table) find_or_register_array #

fn (mut t Table) find_or_register_array(elem_type Type) int

fn (Table) find_or_register_array_fixed #

fn (mut t Table) find_or_register_array_fixed(elem_type Type, size int) int

fn (Table) find_or_register_array_with_dims #

fn (mut t Table) find_or_register_array_with_dims(elem_type Type, nr_dims int) int

fn (Table) find_or_register_chan #

fn (mut t Table) find_or_register_chan(elem_type Type, is_mut bool) int

fn (Table) find_or_register_fn_type #

fn (mut t Table) find_or_register_fn_type(mod string, f Fn, is_anon bool, has_decl bool) int

fn (Table) find_or_register_gohandle #

fn (mut t Table) find_or_register_gohandle(return_type Type) int

fn (Table) find_or_register_map #

fn (mut t Table) find_or_register_map(key_type Type, value_type Type) int

fn (Table) find_or_register_multi_return #

fn (mut t Table) find_or_register_multi_return(mr_typs []Type) int

fn (Table) find_type #

fn (t &Table) find_type(name string) ?TypeSymbol

fn (Table) find_type_idx #

fn (t &Table) find_type_idx(name string) int

fn (Table) fn_signature #

fn (t &Table) fn_signature(func &Fn, opts FnSignatureOpts) string

fn (Table) fn_type_signature #

fn (t &Table) fn_type_signature(f &Fn) string

used to compare fn's & for naming anon fn's

fn (Table) fn_type_source_signature #

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 (Table) get_final_type_symbol #

fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol

get_final_type_symbol follows aliases until it gets to a "real" Type

fn (Table) get_type_name #

fn (t &Table) get_type_name(typ Type) string

fn (Table) get_type_symbol #

fn (t &Table) get_type_symbol(typ Type) &TypeSymbol

fn (Table) gohandle_cname #

fn (t &Table) gohandle_cname(return_type Type) string

fn (Table) gohandle_name #

fn (t &Table) gohandle_name(return_type Type) string

fn (Table) has_deep_child_no_ref #

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 (Table) is_same_method #

fn (t &Table) is_same_method(f &Fn, func &Fn) string

fn (Table) known_fn #

fn (t &Table) known_fn(name string) bool

fn (Table) known_type #

fn (t &Table) known_type(name string) bool

fn (Table) known_type_names #

fn (mytable &Table) known_type_names() []string

fn (Table) map_cname #

fn (t &Table) map_cname(key_type Type, value_type Type) string

fn (Table) map_name #

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 (Table) mktyp #

fn (t &Table) mktyp(typ Type) Type

fn (Table) parse_cflag #

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 (Table) register_aggregate_method #

fn (t &Table) register_aggregate_method(mut sym TypeSymbol, name string) ?Fn

fn (Table) register_builtin_type_symbols #

fn (mut t Table) register_builtin_type_symbols()

fn (Table) register_fn #

fn (mut t Table) register_fn(new_fn Fn)

fn (Table) register_fn_gen_type #

fn (mut mytable Table) register_fn_gen_type(fn_name string, types []Type)

fn (Table) register_type_symbol #

fn (mut t Table) register_type_symbol(typ TypeSymbol) int

fn (Table) struct_has_field #

fn (t &Table) struct_has_field(s &TypeSymbol, name string) bool

fn (Table) sumtype_has_variant #

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 (Table) type_find_method #

fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn

search from current type up through each parent looking for method

fn (Table) type_has_method #

fn (t &Table) type_has_method(s &TypeSymbol, name string) bool

fn (Table) type_kind #

fn (table &Table) type_kind(typ Type) Kind

returns TypeSymbol kind only if there are no type modifiers

fn (Table) type_to_code #

fn (mytable &Table) type_to_code(t Type) string

type name in code (for builtin)

fn (Table) type_to_str #

fn (table &Table) type_to_str(t Type) string

human readable type name

fn (Table) type_to_str_using_aliases #

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 (Table) unalias_num_type #

fn (t &Table) unalias_num_type(typ Type) Type

fn (Table) value_type #

fn (t &Table) value_type(typ Type) Type

struct TypeSymbol #

struct TypeSymbol {
	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 (TypeSymbol) array_fixed_info #

fn (t &TypeSymbol) array_fixed_info() ArrayFixed

fn (TypeSymbol) array_info #

fn (t &TypeSymbol) array_info() Array

fn (TypeSymbol) chan_info #

fn (t &TypeSymbol) chan_info() Chan

fn (TypeSymbol) debug #

fn (ts TypeSymbol) debug() []string

fn (TypeSymbol) embed_name #

fn (t &TypeSymbol) embed_name() string

fn (TypeSymbol) enum_info #

fn (t &TypeSymbol) enum_info() Enum

fn (TypeSymbol) find_field #

fn (t &TypeSymbol) find_field(name string) ?Field

fn (TypeSymbol) find_method #

fn (t &TypeSymbol) find_method(name string) ?Fn

fn (TypeSymbol) gohandle_info #

fn (t &TypeSymbol) gohandle_info() GoHandle

fn (TypeSymbol) has_method #

fn (t &TypeSymbol) has_method(name string) bool

fn (TypeSymbol) is_builtin #

fn (t &TypeSymbol) is_builtin() bool

fn (TypeSymbol) is_float #

fn (t &TypeSymbol) is_float() bool

fn (TypeSymbol) is_int #

fn (t &TypeSymbol) is_int() bool

fn (TypeSymbol) is_number #

fn (t &TypeSymbol) is_number() bool

fn (TypeSymbol) is_pointer #

fn (t &TypeSymbol) is_pointer() bool

fn (TypeSymbol) is_primitive #

fn (t &TypeSymbol) is_primitive() bool

fn (TypeSymbol) is_string #

fn (t &TypeSymbol) is_string() bool

fn (TypeSymbol) map_info #

fn (t &TypeSymbol) map_info() Map

fn (TypeSymbol) mr_info #

fn (t &TypeSymbol) mr_info() MultiReturn

fn (TypeSymbol) register_method #

fn (mut t TypeSymbol) register_method(new_fn Fn) int

fn (TypeSymbol) str #

fn (t &TypeSymbol) str() string

fn (TypeSymbol) str_method_info #

fn (t &TypeSymbol) str_method_info() (bool, bool, int)

fn (TypeSymbol) struct_info #

fn (t &TypeSymbol) struct_info() Struct

struct Var #

struct Var {
	name   string
	is_mut bool
	typ Type