Skip to content

v.ast #

Constants #

const nil_type = new_type(nil_type_idx)
const cptr_types = merge_types(voidptr_types, byteptr_types, charptr_types)
const voidptr_types = new_voidptr_types()
const byteptr_types = new_byteptr_types()
const charptr_types = new_charptr_types()
const error_type = new_type(error_type_idx)
const thread_type = new_type(thread_type_idx)
const int_literal_type = new_type(int_literal_type_idx)
const float_literal_type = new_type(float_literal_type_idx)
const any_type = new_type(any_type_idx)
const chan_type = new_type(chan_type_idx)
const map_type = new_type(map_type_idx)
const array_type = new_type(array_type_idx)
const rune_type = new_type(rune_type_idx)
const string_type = new_type(string_type_idx)
const none_type = new_type(none_type_idx)
const bool_type = new_type(bool_type_idx)
const char_type = new_type(char_type_idx)
const f64_type = new_type(f64_type_idx)
const f32_type = new_type(f32_type_idx)
const usize_type = new_type(usize_type_idx)
const u64_type = new_type(u64_type_idx)
const u32_type = new_type(u32_type_idx)
const u16_type = new_type(u16_type_idx)
const u8_type = new_type(u8_type_idx)
const isize_type = new_type(isize_type_idx)
const i64_type = new_type(i64_type_idx)
const int_type = new_type(int_type_idx)
const i32_type = new_type(i32_type_idx)
const i16_type = new_type(i16_type_idx)
const i8_type = new_type(i8_type_idx)
const charptr_type = new_type(charptr_type_idx)
const byteptr_type = new_type(byteptr_type_idx)
const voidptr_type = new_type(voidptr_type_idx)
const rvoid_type = new_type(void_type_idx).set_flag(.result) // the return type of `fn () !`
const ovoid_type = new_type(void_type_idx).set_flag(.option) // the return type of `fn ()?`
const void_type = new_type(void_type_idx)
const no_type = idx_to_type(no_type_idx) // 0 is an invalid type, but it is useful for initialising default ast.Type values, in fields or before loops
const invalid_type = idx_to_type(invalid_type_idx) // -1 is a purposefully invalid type, not by default, but to signify checker errors
const pointer_type_idxs = [voidptr_type_idx, byteptr_type_idx, charptr_type_idx, nil_type_idx]
const number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i32_type_idx, i64_type_idx,
	u8_type_idx, char_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, isize_type_idx,
	usize_type_idx, f32_type_idx, f64_type_idx, int_literal_type_idx, float_literal_type_idx,
	rune_type_idx]
const float_type_idxs = [f32_type_idx, f64_type_idx, float_literal_type_idx]
const int_promoted_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, u8_type_idx,
	u16_type_idx]

C will promote any type smaller than int to int in an expression

const unsigned_integer_type_idxs = [u8_type_idx, u16_type_idx, u32_type_idx, u64_type_idx,
	usize_type_idx]
const signed_integer_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, int_type_idx,
	i64_type_idx, i32_type_idx, isize_type_idx]
const integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, u8_type_idx,
	u16_type_idx, u32_type_idx, u64_type_idx, isize_type_idx, usize_type_idx, int_literal_type_idx,
	rune_type_idx, i32_type_idx]
const builtin_type_names_matcher = token.new_keywords_matcher_from_array_trie(builtin_type_names)
const builtin_type_names = ['void', 'voidptr', 'byteptr', 'charptr', 'i8', 'i16', 'int', 'i64',
	'isize', 'u8', 'u16', 'u32', 'u64', 'usize', 'f32', 'f64', 'char', 'bool', 'none', 'string',
	'rune', 'array', 'map', 'chan', 'any', 'float_literal', 'int_literal', 'thread', 'Error', 'nil',
	'i32']

Note: builtin_type_names must be in the same order as the idx consts above

const nil_type_idx = 31
const error_type_idx = 30
const thread_type_idx = 29
const int_literal_type_idx = 28
const float_literal_type_idx = 27
const any_type_idx = 26
const chan_type_idx = 25
const map_type_idx = 24
const array_type_idx = 23
const rune_type_idx = 22
const string_type_idx = 21
const none_type_idx = 20
const bool_type_idx = 19
const char_type_idx = 18
const f64_type_idx = 17
const f32_type_idx = 16
const usize_type_idx = 15
const u64_type_idx = 14
const u32_type_idx = 13
const u16_type_idx = 12
const u8_type_idx = 11
const isize_type_idx = 10
const i64_type_idx = 9
const int_type_idx = 8
const i32_type_idx = 7
const i16_type_idx = 6
const i8_type_idx = 5
const charptr_type_idx = 4
const byteptr_type_idx = 3
const voidptr_type_idx = 2
const void_type_idx = 1
const no_type_idx = 0
const invalid_type_idx = -1
const native_builtins = ['assert', 'print', 'eprint', 'println', 'eprintln', 'exit', 'C.syscall']

This file contains definitions that are specific to the native backend, but also have to be known by previous stages too, like the parser/checker etc. Please keep it as small/simple as possible, in order to not burden the other backends.

const global_reserved_type_names = ['byte', 'bool', 'char', 'i8', 'i16', 'int', 'i64', 'u8',
	'u16', 'u32', 'u64', 'f32', 'f64', 'map', 'string', 'rune', 'usize', 'isize', 'voidptr', 'thread',
	'array']

V type names that cannot be used as global var name

const result_name = '_result'
const option_name = '_option'
const builtins = ['string', 'array', 'DenseArray', 'map', 'Error', 'IError', option_name,
	result_name]

V builtin types defined on .v files

const int_type_name = $if new_int ? {
	//'int'
	'i64'
} $else {
	'int'
}

pub const int_type_name = $if amd64 || arm64 {

const empty_expr = Expr(EmptyExpr(0))
const empty_stmt = Stmt(EmptyStmt{})
const empty_node = Node(EmptyNode{})
const x86_no_number_register_list = {
	8:  ['al', 'ah', 'bl', 'bh', 'cl', 'ch', 'dl', 'dh', 'bpl', 'sil', 'dil', 'spl']
	16: ['ax', 'bx', 'cx', 'dx', 'bp', 'si', 'di', 'sp', // segment registers
	 	'cs', 'ss', 'ds', 'es', 'fs', 'gs', 'flags', 'ip', // task registers
	 	'gdtr', 'idtr', 'tr', 'ldtr', // CSR register 'msw', /* FP core registers */ 'cw', 'sw', 'tw', 'fp_ip', 'fp_dp', 'fp_cs',
	 	'fp_ds', 'fp_opc']
	32: [
		'eax',
		'ebx',
		'ecx',
		'edx',
		'ebp',
		'esi',
		'edi',
		'esp',
		'eflags',
		'eip', // CSR register
		'mxcsr', // 32-bit FP core registers 'fp_dp', 'fp_ip' (TODO: why are there duplicates?)
	]
	64: ['rax', 'rbx', 'rcx', 'rdx', 'rbp', 'rsi', 'rdi', 'rsp', 'rflags', 'rip']
}

reference: https://en.wikipedia.org/wiki/X86#/media/File:Table_of_x86_Registers_svg.svg map register size -> register name

const x86_with_number_register_list = {
	8:   {
		'r#b': 16
	}
	16:  {
		'r#w': 16
	}
	32:  {
		'r#d': 16
	}
	64:  {
		'r#':  16
		'mm#': 16
		'cr#': 16
		'dr#': 16
	}
	80:  {
		'st#': 16
	}
	128: {
		'xmm#': 32
	}
	256: {
		'ymm#': 32
	}
	512: {
		'zmm#': 32
	}
}

no comments because maps do not support comments r#*: gp registers added in 64-bit extensions, can only be from 8-15 actually *mm#: vector/simd registers st#: floating point numbers cr#: control/status registers dr#: debug registers

const arm_no_number_register_list = ['fp', // aka r11
 'ip', // not instruction pointer: aka r12
 'sp', // aka r13
 'lr', // aka r14
 'pc', // this is instruction pointer ('program counter'): aka r15
] // 'cpsr' and 'apsr' are special flags registers, but cannot be referred to directly

Todo: saved priviled registers for arm

const arm_with_number_register_list = {
	'r#': 16
}
const riscv_no_number_register_list = ['zero', 'ra', 'sp', 'gp', 'tp']
const riscv_with_number_register_list = {
	'x#': 32
	't#': 3
	's#': 12
	'a#': 8
}
const valid_comptime_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu', 'qnx',
	'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'termux', 'solaris',
	'haiku', 'serenity', 'vinix', 'plan9', 'wasm32_emscripten']
const valid_comptime_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
const valid_comptime_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64',
	'rv32']
const valid_comptime_if_cpu_features = ['x64', 'x32', 'little_endian', 'big_endian']
const valid_comptime_if_other = ['apk', 'js', 'debug', 'prod', 'test', 'glibc', 'prealloc',
	'no_bounds_checking', 'freestanding', 'threads', 'js_node', 'js_browser', 'js_freestanding',
	'interpreter', 'es5', 'profile', 'wasm32', 'wasm32_wasi', 'fast_math', 'native', 'autofree']
const valid_comptime_not_user_defined = all_valid_comptime_idents()
const valid_comptime_compression_types = ['none', 'zlib']
const fn_type_escape_seq = [' ', '', '(', '_', ')', '']
const map_cname_escape_seq = ['[', '_T_', ', ', '_', ']', '']
const invalid_type_symbol = &TypeSymbol{
	idx:        invalid_type_idx
	parent_idx: invalid_type_idx
	language:   .v
	mod:        'builtin'
	kind:       .placeholder
	name:       'InvalidType'
	cname:      'InvalidType'
	is_builtin: false
}

fn all_registers #

fn all_registers(mut t Table, arch pref.Arch) map[string]ScopeObject

return all the registers for the given architecture

fn args2str #

fn args2str(args []CallArg) string

fn empty_comptime_const_expr #

fn empty_comptime_const_expr() ComptTimeConstValue

empty_comptime_const_expr return an EmptyExpr.

fn idx_to_type #

fn idx_to_type(idx int) Type

fn merge_types #

fn merge_types(params ...[]Type) []Type

fn mktyp #

fn mktyp(typ Type) Type

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

fn pref_arch_to_table_language(pref_arch pref.Arch) Language

pref_arch_to_table_language returns target language based on pref_arch

fn sharetype_from_flags #

fn sharetype_from_flags(is_shared bool, is_atomic bool) ShareType

fn type_can_start_with_token #

fn type_can_start_with_token(tok &token.Token) bool

fn validate_type_string_is_pure_literal #

fn validate_type_string_is_pure_literal(typ Type, str string) !

validate_type_string_is_pure_literal returns Error if str can not be converted to pure literal typ (i64, f64, bool, char or string).

type AsmArg #

type AsmArg = AsmAddressing
	| AsmAlias
	| AsmDisp
	| AsmRegister
	| BoolLiteral
	| CharLiteral
	| FloatLiteral
	| IntegerLiteral
	| string

[eax+5] | j | displacement literal (e.g. 123 in [rax + 123] ) | eax | true | a | 0.594 | 123 | label_name

type ComptTimeConstValue #

type ComptTimeConstValue = EmptyExpr
	| f32
	| f64
	| i16
	| i32
	| i64
	| i8
	| rune
	| string
	| u16
	| u32
	| u64
	| u8
	| voidptr

fn (ComptTimeConstValue) i8 #

fn (val ComptTimeConstValue) i8() ?i8

i8 tries to return a ComptTimeConstValue as i8 type.

fn (ComptTimeConstValue) i16 #

fn (val ComptTimeConstValue) i16() ?i16

i16 tries to return a ComptTimeConstValue as i16 type.

fn (ComptTimeConstValue) int #

fn (val ComptTimeConstValue) int() ?int

int tries to return a ComptTimeConstValue as int type.

fn (ComptTimeConstValue) i32 #

fn (val ComptTimeConstValue) i32() ?i32

i32 tries to return a ComptTimeConstValue as i32 type.

fn (ComptTimeConstValue) voidptr #

fn (val ComptTimeConstValue) voidptr() ?voidptr

voidptr tries to return a ComptTimeConstValue as voidptr type.

fn (ComptTimeConstValue) i64 #

fn (val ComptTimeConstValue) i64() ?i64

i64 tries to return a ComptTimeConstValue as i64 type.

fn (ComptTimeConstValue) u8 #

fn (val ComptTimeConstValue) u8() ?u8

u8 tries to return a ComptTimeConstValue as u8 type.

fn (ComptTimeConstValue) u16 #

fn (val ComptTimeConstValue) u16() ?u16

u16 tries to return a ComptTimeConstValue as u16 type.

fn (ComptTimeConstValue) u32 #

fn (val ComptTimeConstValue) u32() ?u32

u32 tries to return a ComptTimeConstValue as u32 type.

fn (ComptTimeConstValue) u64 #

fn (val ComptTimeConstValue) u64() ?u64

u64 tries to return a ComptTimeConstValue as u64 type.

fn (ComptTimeConstValue) f32 #

fn (val ComptTimeConstValue) f32() ?f32

f32 tries to return a ComptTimeConstValue as f32 type.

fn (ComptTimeConstValue) f64 #

fn (val ComptTimeConstValue) f64() ?f64

f64 tries to return a ComptTimeConstValue as f64 type.

fn (ComptTimeConstValue) string #

fn (val ComptTimeConstValue) string() ?string

string tries to return a ComptTimeConstValue as string type.

type EmptyExpr #

type EmptyExpr = u8

type Expr #

type Expr = NodeError
	| AnonFn
	| ArrayDecompose
	| ArrayInit
	| AsCast
	| Assoc
	| AtExpr
	| BoolLiteral
	| CTempVar
	| CallExpr
	| CastExpr
	| ChanInit
	| CharLiteral
	| Comment
	| ComptimeCall
	| ComptimeSelector
	| ComptimeType
	| ConcatExpr
	| DumpExpr
	| EmptyExpr
	| EnumVal
	| FloatLiteral
	| GoExpr
	| Ident
	| IfExpr
	| IfGuardExpr
	| IndexExpr
	| InfixExpr
	| IntegerLiteral
	| IsRefType
	| LambdaExpr
	| Likely
	| LockExpr
	| MapInit
	| MatchExpr
	| Nil
	| None
	| OffsetOf
	| OrExpr
	| ParExpr
	| PostfixExpr
	| PrefixExpr
	| RangeExpr
	| SelectExpr
	| SelectorExpr
	| SizeOf
	| SpawnExpr
	| SqlExpr
	| StringInterLiteral
	| StringLiteral
	| StructInit
	| TypeNode
	| TypeOf
	| UnsafeExpr

fn (Expr) get_pure_type #

fn (expr Expr) get_pure_type() Type

fn (Expr) has_fn_call #

fn (e &Expr) has_fn_call() bool

returns if an expression has call expr`

fn (Expr) is_auto_deref_var #

fn (expr Expr) is_auto_deref_var() bool

fn (Expr) is_blank_ident #

fn (expr Expr) is_blank_ident() bool

fn (Expr) is_expr #

fn (expr Expr) is_expr() bool

fn (Expr) is_literal #

fn (expr Expr) is_literal() bool

is expr a literal, i.e. it does not depend on any other declarations (C compile time constant)

fn (Expr) is_lockable #

fn (e &Expr) is_lockable() bool

returns if an expression can be used in lock x, y.z {

fn (Expr) is_lvalue #

fn (expr Expr) is_lvalue() bool

fn (Expr) is_nil #

fn (e Expr) is_nil() bool

fn (Expr) is_pure_literal #

fn (expr Expr) is_pure_literal() bool

fn (Expr) is_reference #

fn (expr Expr) is_reference() bool

fn (Expr) pos #

fn (expr Expr) pos() token.Pos

fn (Expr) str #

fn (x &Expr) str() string

string representation of expr

type FnPanicHandler #

type FnPanicHandler = fn (&Table, string)

type IdentInfo #

type IdentInfo = IdentFn | IdentVar

type Node #

type Node = CallArg
	| ConstField
	| EmptyNode
	| EnumField
	| Expr
	| File
	| GlobalField
	| IfBranch
	| MatchBranch
	| NodeError
	| Param
	| ScopeObject
	| SelectBranch
	| Stmt
	| StructField
	| StructInitField

Todo: replace Param

fn (Node) pos #

fn (node Node) pos() token.Pos

fn (Node) children #

fn (node Node) children() []Node

type ScopeObject #

type ScopeObject = AsmRegister | ConstField | GlobalField | Var

fn (ScopeObject) is_simple_define_const #

fn (obj ScopeObject) is_simple_define_const() bool

type Stmt #

type Stmt = AsmStmt
	| AssertStmt
	| AssignStmt
	| Block
	| BranchStmt
	| ComptimeFor
	| ConstDecl
	| DebuggerStmt
	| DeferStmt
	| EmptyStmt
	| EnumDecl
	| ExprStmt
	| FnDecl
	| ForCStmt
	| ForInStmt
	| ForStmt
	| GlobalDecl
	| GotoLabel
	| GotoStmt
	| HashStmt
	| Import
	| InterfaceDecl
	| Module
	| NodeError
	| Return
	| SemicolonStmt
	| SqlStmt
	| StructDecl
	| TypeDecl

fn (Stmt) str #

fn (node Stmt) str() string

type Type #

type Type = u32

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

is_void return true if t is of type void

fn (Type) is_full #

fn (t Type) is_full() bool

is_full return true if t is not of type void

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) is_pointer #

fn (typ Type) is_pointer() bool

is_pointer returns true if typ is any of the builtin pointer types (voidptr, byteptr, charptr)

fn (Type) is_voidptr #

fn (typ Type) is_voidptr() bool

is_voidptr returns true if typ is a voidptr

fn (Type) is_any_kind_of_pointer #

fn (t Type) is_any_kind_of_pointer() bool

is_any_kind_of_pointer returns true if t is any type of pointer

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) ref #

fn (t Type) ref() Type

increments nr_muls on t and return it

fn (Type) deref #

fn (t Type) deref() Type

decrement nr_muls on t and return it

fn (Type) has_flag #

fn (t Type) has_flag(flag TypeFlag) bool

has_flag returns whether the given named flag is set

fn (Type) set_flag #

fn (t Type) set_flag(flag TypeFlag) Type

set_flag returns a new type, that is like the input t, but with the named flag set

fn (Type) clear_flag #

fn (t Type) clear_flag(flag TypeFlag) Type

clear_flag returns a new type, that is like t, but with the named flag cleared

fn (Type) clear_flags #

fn (t Type) clear_flags(flags ...TypeFlag) Type

clear_flags returns a new type, based on t, but with cleared named flags

fn (Type) clear_option_and_result #

fn (t Type) clear_option_and_result() Type

clear option and result flags

fn (Type) has_option_or_result #

fn (t Type) has_option_or_result() bool

fn (Type) str #

fn (t Type) str() string

str returns a string representation of the type.

fn (Type) debug #

fn (t Type) debug() []string

debug returns a verbose representation of the information in the type t, useful for tracing/debugging

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) derive_add_muls #

fn (t Type) derive_add_muls(t_from Type) Type

copy flags from t_from to t and return t

fn (Type) idx_type #

fn (t Type) idx_type() Type

return new type from its idx

fn (Type) is_float #

fn (typ Type) is_float() bool

is_float returns true if typ is float

fn (Type) is_int #

fn (typ Type) is_int() bool

is_int returns true if typ is int

fn (Type) is_int_valptr #

fn (typ Type) is_int_valptr() bool

is_int_valptr returns true if typ is a pointer to a int

fn (Type) is_float_valptr #

fn (typ Type) is_float_valptr() bool

is_float_valptr return true if typ is a pointer to float

fn (Type) is_pure_int #

fn (typ Type) is_pure_int() bool

is_pure_int return true if typ is a pure int

fn (Type) is_pure_float #

fn (typ Type) is_pure_float() bool

is_pure_float return true if typ is a pure float

fn (Type) is_signed #

fn (typ Type) is_signed() bool

is_signed return true if typ is signed

fn (Type) is_unsigned #

fn (typ Type) is_unsigned() bool

is_unsigned return true if typ is unsigned

fn (Type) flip_signedness #

fn (typ Type) flip_signedness() Type

fn (Type) is_int_literal #

fn (typ Type) is_int_literal() bool

is_int_literal returns true if typ is a int literal

fn (Type) is_number #

fn (typ Type) is_number() bool

is_number returns true if typ is a number

fn (Type) is_string #

fn (typ Type) is_string() bool

is_string returns true if typ is a string type

fn (Type) is_bool #

fn (typ Type) is_bool() bool

is_bool returns true if typ is of bool type

type TypeDecl #

type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl

type TypeInfo #

type TypeInfo = UnknownTypeInfo
	| Aggregate
	| Alias
	| Array
	| ArrayFixed
	| Chan
	| Enum
	| FnType
	| GenericInst
	| Interface
	| Map
	| MultiReturn
	| Struct
	| SumType
	| Thread

fn ([]Attr) contains #

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

fn ([]Attr) contains_arg #

fn (attrs []Attr) contains_arg(str string, arg string) bool

fn ([]Attr) find_first #

fn (attrs []Attr) find_first(aname string) ?Attr

fn ([]Attr) find_last #

fn (attrs []Attr) find_last(aname string) ?Attr

fn ([]Attr) find_comptime_define #

fn (attrs []Attr) find_comptime_define() ?int

fn ([]Kind) str #

fn (kinds []Kind) str() string

enum AddressingMode #

enum AddressingMode {
	invalid
	displacement                                  // displacement
	base                                          // base
	base_plus_displacement                        // base + displacement
	index_times_scale_plus_displacement           // (index ∗ scale) + displacement
	base_plus_index_plus_displacement             // base + (index ∗ scale) + displacement
	base_plus_index_times_scale_plus_displacement // base + index + displacement
	rip_plus_displacement                         // rip + displacement
}

addressing modes:

enum AttrKind #

enum AttrKind {
	plain           // [name]
	string          // ['name']
	number          // [123]
	bool            // [true] || [false]
	comptime_define // [if name]
}

enum ComptimeForKind #

enum ComptimeForKind {
	methods
	fields
	attributes
	values
	variants
	params
}

fn (ComptimeForKind) str #

fn (e ComptimeForKind) str() string

enum ComptimeTypeKind #

enum ComptimeTypeKind {
	unknown
	map
	int
	float
	struct
	iface
	array
	array_fixed
	array_dynamic
	sum_type
	enum
	alias
	function
	option
	string
}

enum ComptimeVarKind #

enum ComptimeVarKind {
	no_comptime   // it is not a comptime var
	key_var       // map key from `for k,v in t.$(field.name)`
	value_var     // map value from `for k,v in t.$(field.name)`
	field_var     // comptime field var `a := t.$(field.name)`
	generic_param // generic fn parameter
	generic_var   // generic var
	smartcast     // smart cast when used in `is v` (when `v` is from $for .variants)
}

enum GenericKindField #

enum GenericKindField {
	unknown
	name
	typ
	unaliased_typ
	indirections
}

enum IdentKind #

enum IdentKind {
	unresolved
	blank_ident // discard identifier, `_` in `_ := 1`
	variable
	constant
	global
	function
}

enum Kind #

enum Kind {
	placeholder
	void
	voidptr
	byteptr
	charptr
	i8
	i16
	i32
	int
	i64
	isize
	u8
	u16
	u32
	u64
	usize
	f32
	f64
	char
	rune
	bool
	none
	string
	array
	array_fixed
	map
	chan
	any
	struct
	generic_inst
	multi_return
	sum_type
	alias
	enum
	function
	interface
	float_literal
	int_literal
	aggregate
	thread
}

fn (Kind) str #

fn (k Kind) str() string

for debugging/errors only, perf is not an issue

enum Language #

enum Language {
	v
	c
	js
	wasm
	amd64 // aka x86_64
	i386
	arm64 // 64-bit arm
	arm32 // 32-bit arm
	rv64  // 64-bit risc-v
	rv32  // 32-bit risc-v
	wasm32
}

enum OrKind #

enum OrKind {
	absent
	block
	propagate_option
	propagate_result
}

enum ShareType #

enum ShareType {
	mut_t
	shared_t
	atomic_t
}

fn (ShareType) str #

fn (t ShareType) str() string

str converts t to it's string form of ShareType i.e. mut, shared, atomic

enum SqlExprKind #

enum SqlExprKind {
	insert
	select_
}

enum SqlStmtKind #

enum SqlStmtKind {
	insert
	update
	delete
	create
	drop
}

enum StructInitKind #

enum StructInitKind {
	normal
	short_syntax
	anon
}

enum TypeFlag #

enum TypeFlag as u32 {
	option   = 1 << 24
	result   = 1 << 25
	variadic = 1 << 26
	generic  = 1 << 27
	shared_f = 1 << 28
	atomic_f = 1 << 29
}

max of 8

struct Aggregate #

struct Aggregate {
mut:
	fields []StructField // used for faster lookup inside the module
pub:
	sum_type Type
	types    []Type
}

struct Alias #

@[minify]
struct Alias {
pub:
	parent_type Type
	language    Language
	is_import   bool
}

struct AliasTypeDecl #

struct AliasTypeDecl {
pub:
	name        string
	is_pub      bool
	typ         Type
	parent_type Type
	pos         token.Pos
	type_pos    token.Pos
	comments    []Comment
}

struct AnonFn #

struct AnonFn {
pub mut:
	decl           FnDecl
	inherited_vars []Param
	typ            Type            // the type of anonymous fn. Both .typ and .decl.name are auto generated
	has_gen        map[string]bool // a map of the names of all generic anon functions, generated from it
}

anonymous function

struct Array #

struct Array {
pub:
	nr_dims int
pub mut:
	elem_type Type
}

struct ArrayDecompose #

struct ArrayDecompose {
pub:
	pos token.Pos
pub mut:
	expr      Expr
	expr_type Type
	arg_type  Type
}

struct ArrayFixed #

@[minify]
struct ArrayFixed {
pub:
	size      int
	size_expr Expr // used by fmt for e.g. ´[my_const]u8´
pub mut:
	elem_type Type
	is_fn_ret bool
}

fn (ArrayFixed) is_compatible #

fn (t &ArrayFixed) is_compatible(t2 ArrayFixed) bool

struct ArrayInit #

@[minify]
struct ArrayInit {
pub:
	pos           token.Pos   // `[]` in []Type{} position
	elem_type_pos token.Pos   // `Type` in []Type{} position
	ecmnts        [][]Comment // optional iembed comments after each expr
	pre_cmnts     []Comment
	is_fixed      bool
	has_val       bool // fixed size literal `[expr, expr]!`
	mod           string
	has_len       bool
	has_cap       bool
	has_init      bool
	has_index     bool // true if temp variable index is used
pub mut:
	exprs      []Expr // `[expr, expr]` or `[expr]Type{}` for fixed array
	len_expr   Expr   // len: expr
	cap_expr   Expr   // cap: expr
	init_expr  Expr   // init: expr
	expr_types []Type // [Dog, Cat] // also used for interface_types
	elem_type  Type   // element type
	init_type  Type   // init: value type
	typ        Type   // array type
	alias_type Type   // alias type
}

struct AsCast #

struct AsCast {
pub:
	typ Type // to type
	pos token.Pos
pub mut:
	expr      Expr // from expr: `expr` in `expr as Ident`
	expr_type Type // from type
}

expr as Ident

struct AsmAddressing #

struct AsmAddressing {
pub:
	scale int = -1 // 1, 2, 4, or 8 literal
	mode  AddressingMode
	pos   token.Pos
pub mut:
	segment      string // fs:
	displacement AsmArg // 8, 16 or 32 bit literal value
	base         AsmArg // gpr
	index        AsmArg // gpr
}

struct AsmAlias #

struct AsmAlias {
pub:
	pos token.Pos
pub mut:
	name string // a
}

struct AsmClobbered #

struct AsmClobbered {
pub mut:
	reg      AsmRegister
	comments []Comment
}

struct AsmDisp #

struct AsmDisp {
pub:
	val string
	pos token.Pos
}

struct AsmIO #

struct AsmIO {
pub:
	alias      string    // [alias_a]
	constraint string    // '=r' TODO: allow all backends to easily use this with a struct
	comments   []Comment // // this is a comment
	typ        Type
	pos        token.Pos
pub mut:
	expr Expr // (a)
}

: [alias_a] '=r' (a) // this is a comment

struct AsmRegister #

struct AsmRegister {
pub mut:
	name string // eax or r12d etc.
	typ  Type
	size int
}

struct AsmStmt #

@[minify]
struct AsmStmt {
pub:
	arch        pref.Arch
	is_basic    bool
	is_volatile bool
	is_goto     bool
	clobbered   []AsmClobbered
	pos         token.Pos
pub mut:
	templates     []AsmTemplate
	scope         &Scope = unsafe { nil }
	output        []AsmIO
	input         []AsmIO
	global_labels []string // labels defined in assembly block, exported with `.globl`
	local_labels  []string // local to the assembly block
}

struct AsmTemplate #

@[minify]
struct AsmTemplate {
pub mut:
	name         string
	is_label     bool // `example_label:`
	is_directive bool // .globl assembly_function
	args         []AsmArg
	comments     []Comment
	pos          token.Pos
}

struct AssertStmt #

@[minify]
struct AssertStmt {
pub:
	pos       token.Pos
	extra_pos token.Pos
pub mut:
	expr    Expr // `a == 0`
	extra   Expr // `'a is zero'`
	is_used bool // asserts are used in _test.v files, as well as in non -prod builds of all files
}

assert a == 0, 'a is zero'

struct AssignStmt #

@[minify]
struct AssignStmt {
pub:
	op           token.Kind // include: =,:=,+=,-=,*=,/= and so on; for a list of all the assign operators, see vlib/token/token.v
	pos          token.Pos
	end_comments []Comment
pub mut:
	right         []Expr
	left          []Expr
	left_types    []Type
	right_types   []Type
	is_static     bool // for translated code only
	is_volatile   bool // for disabling variable access optimisations (needed for hardware drivers)
	is_simple     bool // `x+=2` in `for x:=1; ; x+=2`
	has_cross_var bool
	attr          Attr
}

variable assign statement

struct Assoc #

@[minify]
struct Assoc {
pub:
	var_name string
	fields   []string
	pos      token.Pos
pub mut:
	exprs []Expr
	typ   Type
	scope &Scope = unsafe { nil }
}

deprecated

struct AtExpr #

struct AtExpr {
pub:
	name string
	pos  token.Pos
	kind token.AtKind
pub mut:
	val string
}

@FN, @STRUCT, @MOD etc. See full list in token.valid_at_tokens

struct Attr #

@[minify]
struct Attr {
pub:
	name    string // [name]
	has_arg bool
	arg     string // [name: arg]
	kind    AttrKind
	ct_opt  bool // true for [if user_defined_name?]
	pos     token.Pos
	has_at  bool // new syntax `@[attr]`
pub mut:
	ct_expr   Expr // .kind == comptime_define, for [if !name]
	ct_evaled bool // whether ct_skip has been evaluated already
	ct_skip   bool // is the comptime expr *false*, filled by checker
}

e.g. @[unsafe]

fn (Attr) debug #

fn (a &Attr) debug() string

fn (Attr) str #

fn (a &Attr) str() string

str returns the string representation without square brackets

struct Block #

struct Block {
pub:
	is_unsafe bool
	pos       token.Pos
pub mut:
	stmts []Stmt
}

{stmts} or unsafe {stmts}

struct BoolLiteral #

struct BoolLiteral {
pub:
	val bool
	pos token.Pos
}

struct BranchStmt #

@[minify]
struct BranchStmt {
pub:
	kind  token.Kind
	label string
	pos   token.Pos
}

break, continue

fn (BranchStmt) str #

fn (node &BranchStmt) str() string

struct CTempVar #

struct CTempVar {
pub:
	name   string // the name of the C temporary variable; used by g.expr(x)
	typ    Type   // the type of the original expression
	is_ptr bool   // whether the type is a pointer
pub mut:
	orig Expr // the original expression, which produced the C temp variable; used by x.str()
}

CTempVar is used in cgen only, to hold nodes for temporary variables

struct CallArg #

@[minify]
struct CallArg {
pub:
	is_mut   bool
	share    ShareType
	comments []Comment
pub mut:
	expr            Expr
	typ             Type
	is_tmp_autofree bool // this tells cgen that a tmp variable has to be used for the arg expression in order to free it after the call
	pos             token.Pos
	should_be_ptr   bool // fn expects a ptr for this arg
	// tmp_name        string // for autofree
}

function call argument: f(callarg)

fn (CallArg) str #

fn (a CallArg) str() string

struct CallExpr #

@[minify]
struct CallExpr {
pub:
	pos      token.Pos
	name_pos token.Pos
	mod      string
pub mut:
	name                   string // left.name()
	is_method              bool
	is_field               bool // temp hack, remove ASAP when re-impl CallExpr / Selector (joe)
	is_fn_var              bool // fn variable, `a := fn() {}`, then: `a()`
	is_fn_a_const          bool // fn const, `const c = abc`, where `abc` is a function, then: `c()`
	is_keep_alive          bool // GC must not free arguments before fn returns
	is_noreturn            bool // whether the function/method is marked as [noreturn]
	is_ctor_new            bool // if JS ctor calls requires `new` before call, marked as `[use_new]` in V
	is_file_translated     bool // true, when the file it resides in is `@[translated]`
	is_static_method       bool // it is a static method call
	args                   []CallArg
	expected_arg_types     []Type
	comptime_ret_val       bool
	language               Language
	or_block               OrExpr
	left                   Expr // `user` in `user.register()`
	left_type              Type // type of `user`
	receiver_type          Type // User / T, if receiver is generic, then cgen requires receiver_type to be T
	receiver_concrete_type Type // if receiver_type is T, then receiver_concrete_type is concrete type, otherwise it is the same as receiver_type
	return_type            Type
	return_type_generic    Type // the original generic return type from fn def
	nr_ret_values          int = -1 // amount of return values
	fn_var_type            Type   // the fn type, when `is_fn_a_const` or `is_fn_var` is true
	const_name             string // the fully qualified name of the const, i.e. `main.c`, given `const c = abc`, and callexpr: `c()`
	should_be_skipped      bool   // true for calls to `[if someflag?]` functions, when there is no `-d someflag`
	concrete_types         []Type // concrete types, e.g. 
	concrete_list_pos      token.Pos
	raw_concrete_types     []Type
	free_receiver          bool // true if the receiver expression needs to be freed
	scope                  &Scope = unsafe { nil }
	from_embed_types       []Type // holds the type of the embed that the method is called from
	comments               []Comment
	is_return_used         bool // return value is used for another expr
	//
	is_expand_simple_interpolation bool // true, when the function/method is marked as @[expand_simple_interpolation]
	// Calls to it with an interpolation argument like `b.f('x ${y}')`, will be converted to `b.f('x ')` followed by `b.f(y)`.
	// The same type, has to support also a .write_decimal(n i64) method.
}

function or method call expr

fn (CallExpr) fkey #

fn (node &CallExpr) fkey() string

fn (CallExpr) get_name #

fn (f &CallExpr) get_name() string

get_name returns the real name for the function calling

struct CastExpr #

@[minify]
struct CastExpr {
pub mut:
	arg       Expr   // `n` in `string(buf, n)`
	typ       Type   // `string`
	expr      Expr   // `buf` in `string(buf, n)` and `&Type(buf)`
	typname   string // `&Type` in `&Type(buf)`
	expr_type Type   // `byteptr`, the type of the `buf` expression
	has_arg   bool   // true for `string(buf, n)`, false for `&Type(buf)`
	pos       token.Pos
}

struct Chan #

struct Chan {
pub mut:
	elem_type Type
	is_mut    bool
}

struct ChanInit #

struct ChanInit {
pub:
	pos           token.Pos
	elem_type_pos token.Pos
	has_cap       bool
pub mut:
	cap_expr  Expr
	typ       Type
	elem_type Type
}

struct CharLiteral #

struct CharLiteral {
pub:
	val string
	pos token.Pos
}

struct Comment #

struct Comment {
pub:
	text     string
	is_multi bool // true only for /* comment */, that use many lines
	pos      token.Pos
}

struct ComptimeCall #

@[minify]
struct ComptimeCall {
pub:
	pos              token.Pos
	has_parens       bool // if $() is used, for vfmt
	method_name      string
	method_pos       token.Pos
	scope            &Scope = unsafe { nil }
	is_vweb          bool
	is_veb           bool
	is_embed         bool // $embed_file(...)
	is_env           bool // $env(...) // TODO: deprecate after $d() is stable
	is_compile_value bool // $d(...)
	env_pos          token.Pos
	is_pkgconfig     bool
mut:
	is_d_resolved bool
pub mut:
	veb_tmpl      File
	left          Expr
	left_type     Type
	result_type   Type
	env_value     string
	compile_value string
	args_var      string
	args          []CallArg
	embed_file    EmbeddedFile
	or_block      OrExpr
}

fn (ComptimeCall) resolve_compile_value #

fn (mut cc ComptimeCall) resolve_compile_value(compile_values map[string]string) !

resolve_compile_value resolves the value and return type of $d() calls. The result is stored in fields compile_value and result_type. The argument compile_values is expected to be the Preferences.compile_values field.

fn (ComptimeCall) expr_str #

fn (cc ComptimeCall) expr_str() string

expr_str returns the string representation of ComptimeCall for use with ast.Expr's `str()' method (used by e.g. vfmt).

struct ComptimeFor #

struct ComptimeFor {
pub:
	val_var string
	kind    ComptimeForKind
	pos     token.Pos
	typ_pos token.Pos
pub mut:
	stmts []Stmt
	typ   Type
	expr  Expr
}

struct ComptimeSelector #

@[minify]
struct ComptimeSelector {
pub:
	has_parens bool // if $() is used, for vfmt
	pos        token.Pos
pub mut:
	left       Expr
	left_type  Type
	field_expr Expr
	typ        Type
}

struct ComptimeType #

struct ComptimeType {
pub:
	kind ComptimeTypeKind
	pos  token.Pos
}

fn (ComptimeType) str #

fn (cty ComptimeType) str() string

struct ConcatExpr #

struct ConcatExpr {
pub:
	vals []Expr
	pos  token.Pos
pub mut:
	return_type Type
}

struct ConstDecl #

@[minify]
struct ConstDecl {
pub:
	is_pub bool
	pos    token.Pos
	attrs  []Attr // tags like `@[markused]`, valid for all the consts in the list
pub mut:
	fields       []ConstField // all the const fields in the `const (...)` block
	end_comments []Comment    // comments that after last const field
	is_block     bool         // const() block
}

const declaration

struct ConstField #

struct ConstField {
pub:
	mod         string
	name        string
	is_pub      bool
	is_markused bool // an explicit `@[markused]` tag; the const will NOT be removed by `-skip-unused`, no matter what
	pos         token.Pos
	attrs       []Attr // same value as `attrs` of the ConstDecl to which it belongs
pub mut:
	expr         Expr      // the value expr of field; everything after `=`
	typ          Type      // the type of the const field, it can be any type in V
	comments     []Comment // comments before current const field
	end_comments []Comment // comments that after const field
	// the comptime_expr_value field is filled by the checker, when it has enough
	// info to evaluate the constant at compile time
	comptime_expr_value ComptTimeConstValue = empty_comptime_const_expr()
}

const field in const declaration group

fn (ConstField) comptime_expr_value #

fn (obj ConstField) comptime_expr_value() ?ComptTimeConstValue

fn (ConstField) is_simple_define_const #

fn (obj ConstField) is_simple_define_const() bool

struct DebuggerStmt #

struct DebuggerStmt {
pub:
	pos token.Pos
}

struct DeferStmt #

@[minify]
struct DeferStmt {
pub:
	pos token.Pos
pub mut:
	stmts      []Stmt
	defer_vars []Ident
	ifdef      string
	idx_in_fn  int = -1 // index in FnDecl.defer_stmts
}

Todo: handle this differentlyv1 excludes non current os ifdefs so the defer's never get added in the first place

struct DumpExpr #

@[minify]
struct DumpExpr {
pub:
	pos token.Pos
pub mut:
	expr      Expr
	expr_type Type
	cname     string // filled in the checker
}

struct Embed #

struct Embed {
pub:
	typ      Type
	pos      token.Pos
	comments []Comment
}

struct EmbeddedFile #

@[minify]
struct EmbeddedFile {
pub:
	compression_type string
pub mut:
	rpath string // used in the source code, as an ID/key to the embed
	apath string // absolute path during compilation to the resource
	// these are set by gen_embed_file_init in v/gen/c/embed
	is_compressed bool
	bytes         []u8
	len           int
}

fn (EmbeddedFile) hash #

fn (e EmbeddedFile) hash() u64

struct EmptyNode #

struct EmptyNode {
pub:
	pos token.Pos
}

struct EmptyStmt #

struct EmptyStmt {
pub:
	pos token.Pos
}

struct Enum #

struct Enum {
pub:
	vals             []string
	is_flag          bool
	is_multi_allowed bool
	uses_exprs       bool
	typ              Type
	attrs            map[string][]Attr
}

struct EnumDecl #

@[minify]
struct EnumDecl {
pub:
	name             string
	is_pub           bool
	is_flag          bool        // true when the enum has @[flag] tag,for bit field enum
	is_multi_allowed bool        // true when the enum has [_allow_multiple_values] tag
	comments         []Comment   // comments before the first EnumField
	fields           []EnumField // all the enum fields
	attrs            []Attr      // attributes of enum declaration
	typ              Type        // the default is `int`; can be changed by `enum Big as u64 { a = 5 }`
	typ_pos          token.Pos
	pos              token.Pos
}

enum declaration

struct EnumField #

struct EnumField {
pub:
	name             string // just `lock`, or `abc`, etc, no matter if the name is a keyword or not.
	source_name      string // The name in the source, for example `lock`, and `abc`. Note that `lock` is a keyword in V.
	pos              token.Pos
	pre_comments     []Comment // comment before Enumfield
	comments         []Comment // comment after Enumfield in the same line
	next_comments    []Comment // comments between current EnumField and next EnumField
	has_expr         bool      // true, when .expr has a value
	has_prev_newline bool      // empty newline before Enumfield
	has_break_line   bool
	attrs            []Attr
pub mut:
	expr Expr // the value of current EnumField; 123 in `ename = 123`
}

enum field in enum declaration

struct EnumVal #

struct EnumVal {
pub:
	enum_name string
	val       string
	mod       string // for full path `mod_Enum_val`
	pos       token.Pos
pub mut:
	typ Type
}

An enum value, like OS.macos or .macos

struct ExprStmt #

struct ExprStmt {
pub:
	pos      token.Pos
	comments []Comment
pub mut:
	expr    Expr
	is_expr bool
	typ     Type
}

| IncDecStmt k Stand-alone expression in a statement list.

struct File #

@[heap]
struct File {
pub:
	nr_lines      int    // number of source code lines in the file (including newlines and comments)
	nr_bytes      int    // number of processed source code bytes
	mod           Module // the module of the source file (from `module xyz` at the top)
	global_scope  &Scope = unsafe { nil }
	is_test       bool // true for _test.v files
	is_generated  bool // true for `@[generated] module xyz` files; turn off notices
	is_translated bool // true for `@[translated] module xyz` files; turn off some checks
pub mut:
	idx              int    // index in an external container; can be used to refer to the file in a more efficient way, just by its integer index
	path             string // absolute path of the source file - '/projects/v/file.v'
	path_base        string // file name - 'file.v' (useful for tracing)
	scope            &Scope = unsafe { nil }
	stmts            []Stmt            // all the statements in the source file
	imports          []Import          // all the imports
	auto_imports     []string          // imports that were implicitly added
	embedded_files   []EmbeddedFile    // list of files to embed in the binary
	imported_symbols map[string]string // used for `import {symbol}`, it maps symbol => module.symbol
	errors           []errors.Error    // all the checker errors in the file
	warnings         []errors.Warning  // all the checker warnings in the file
	notices          []errors.Notice   // all the checker notices in the file
	generic_fns      []&FnDecl
	global_labels    []string // from `asm { .globl labelname }`
	template_paths   []string // all the .html/.md files that were processed with $tmpl
	unique_prefix    string   // a hash of the `.path` field, used for making anon fn generation unique
	//
	is_parse_text    bool // true for files, produced by parse_text
	is_template_text bool // true for files, produced by parse_comptime
}

Each V source file is represented by one File structure. When the V compiler runs, the parser will fill an []File. That array is then passed to V's checker.

fn (File) free #

unsafe
fn (f &File) free()

struct FloatLiteral #

struct FloatLiteral {
pub:
	val string
	pos token.Pos
}

struct Fn #

@[minify]
struct Fn {
pub:
	is_variadic           bool
	is_c_variadic         bool
	language              Language
	is_pub                bool
	is_ctor_new           bool // `@[use_new] fn JS.Array.prototype.constructor()`
	is_deprecated         bool // `@[deprecated] fn abc(){}`
	is_noreturn           bool // `@[noreturn] fn abc(){}`
	is_unsafe             bool // `@[unsafe] fn abc(){}`
	is_placeholder        bool
	is_main               bool // `fn main(){}`
	is_test               bool // `fn test_abc(){}`
	is_keep_alive         bool // passed memory must not be freed (by GC) before function returns
	is_method             bool // true for `fn (x T) name()`, and for interface declarations (which are also for methods)
	is_static_type_method bool // true for `fn Foo.bar() {}`
	no_body               bool // a pure declaration like `fn abc(x int)`; used in .vh files, C./JS. fns.
	is_file_translated    bool // true, when the file it resides in is `@[translated]`
	mod                   string
	file                  string
	file_mode             Language
	pos                   token.Pos
	name_pos              token.Pos
	return_type_pos       token.Pos
pub mut:
	return_type        Type
	receiver_type      Type // != 0, when .is_method == true
	name               string
	params             []Param
	source_fn          voidptr // set in the checker, while processing fn declarations // TODO: get rid of voidptr
	usages             int
	generic_names      []string
	dep_names          []string // globals or consts dependent names
	attrs              []Attr   // all fn attributes
	is_conditional     bool     // true for `[if abc]fn(){}`
	ctdefine_idx       int      // the index of the attribute, containing the compile time define [if mytag]
	from_embedded_type Type     // for interface only, fn from the embedded interface
	from_embeded_type  Type @[deprecated: 'use from_embedded_type instead'; deprecated_after: '2024-03-31']
	//
	is_expand_simple_interpolation bool // for tagging b.f(s string), which is then called with `b.f('some $x $y')`,
	// when that call, should be expanded to `b.f('some '); b.f(x); b.f(' '); b.f(y);`
	// Note: the same type, has to support also a .write_decimal(n i64) method.
}

fn (Fn) fkey #

fn (node &Fn) fkey() string

fn (Fn) new_method_with_receiver_type #

fn (f &Fn) new_method_with_receiver_type(new_type_ Type) Fn

struct FnDecl #

@[minify]
struct FnDecl {
pub:
	name                  string // 'math.bits.normalize'
	short_name            string // 'normalize'
	mod                   string // 'math.bits'
	is_deprecated         bool
	is_pub                bool
	is_c_variadic         bool
	is_c_extern           bool
	is_variadic           bool
	is_anon               bool
	is_noreturn           bool        // true, when @[noreturn] is used on a fn
	is_manualfree         bool        // true, when @[manualfree] is used on a fn
	is_main               bool        // true for `fn main()`
	is_test               bool        // true for `fn test_abcde() {}`, false for `fn test_abc(x int) {}`, or for fns that do not start with test_
	is_conditional        bool        // true for `@[if abc] fn abc(){}`
	is_exported           bool        // true for `@[export: 'exact_C_name']`
	is_keep_alive         bool        // passed memory must not be freed (by GC) before function returns
	is_unsafe             bool        // true, when @[unsafe] is used on a fn
	is_markused           bool        // true, when an explicit `@[markused]` tag was put on a fn; `-skip-unused` will not remove that fn
	is_file_translated    bool        // true, when the file it resides in is `@[translated]`
	receiver              StructField // TODO: this is not a struct field
	receiver_pos          token.Pos   // `(u User)` in `fn (u User) name()` position
	is_method             bool
	is_static_type_method bool      // true for `fn Foo.bar() {}`
	static_type_pos       token.Pos // `Foo` in `fn Foo.bar() {}`
	method_type_pos       token.Pos // `User` in ` fn (u User)` position
	method_idx            int
	rec_mut               bool // is receiver mutable
	has_prev_newline      bool
	has_break_line        bool
	rec_share             ShareType
	language              Language // V, C, JS
	file_mode             Language // whether *the file*, where a function was a '.c.v', '.js.v' etc.
	no_body               bool     // just a definition `fn C.malloc()`
	is_builtin            bool     // this function is defined in builtin/strconv
	name_pos              token.Pos
	body_pos              token.Pos // function bodys position
	file                  string
	generic_names         []string
	is_direct_arr         bool // direct array access
	attrs                 []Attr
	ctdefine_idx          int = -1 // the index in fn.attrs of `[if xyz]`, when such attribute exists
pub mut:
	idx               int // index in an external container; can be used to refer to the function in a more efficient way, just by its integer index
	params            []Param
	stmts             []Stmt
	defer_stmts       []DeferStmt
	trace_fns         map[string]FnTrace
	return_type       Type
	return_type_pos   token.Pos // `string` in `fn (u User) name() string` position
	has_return        bool
	should_be_skipped bool // true, when -skip-unused could not find any usages of that function, starting from main + other known used functions
	ninstances        int  // 0 for generic functions with no concrete instances
	has_await         bool // 'true' if this function uses JS.await

	comments      []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
	end_comments  []Comment // comments *after* header declarations. E.g.: `fn C.C_func(x int) int // Comment`
	next_comments []Comment // comments that are one line after the decl; used for InterfaceDecl

	source_file &File  = unsafe { nil }
	scope       &Scope = unsafe { nil }
	label_names []string
	pos         token.Pos // function declaration position
	//
	is_expand_simple_interpolation bool // true, when @[expand_simple_interpolation] is used on a fn. It should have a single string argument.
}

function or method declaration

fn (FnDecl) fkey #

fn (node &FnDecl) fkey() string

fkey returns a unique name of the function/method. it is used in table.used_fns and v.markused.

fn (FnDecl) get_name #

fn (f &FnDecl) get_name() string

get_name returns the real name for the function declaration

fn (FnDecl) modname #

fn (node &FnDecl) modname() string

fn (FnDecl) new_method_with_receiver_type #

fn (f &FnDecl) new_method_with_receiver_type(new_type_ Type) FnDecl

struct FnSignatureOpts #

@[minify]
struct FnSignatureOpts {
pub:
	skip_receiver bool
	type_only     bool
}

struct FnTrace #

@[minify]
struct FnTrace {
pub mut:
	name string
pub:
	file        string
	line        i64
	return_type Type
	func        &Fn = unsafe { nil }
	is_fn_var   bool
}

struct FnType #

struct FnType {
pub mut:
	is_anon  bool
	has_decl bool
	func     Fn
}

struct FnTypeDecl #

struct FnTypeDecl {
pub:
	name          string
	is_pub        bool
	typ           Type
	pos           token.Pos
	type_pos      token.Pos
	comments      []Comment
	generic_types []Type
	attrs         []Attr // attributes of type declaration
}

struct ForCStmt #

struct ForCStmt {
pub:
	has_init bool
	has_cond bool
	has_inc  bool
	is_multi bool // for a,b := 0,1; a < 10; a,b = a+b, a {...}
	pos      token.Pos
	comments []Comment
pub mut:
	init  Stmt // i := 0;
	cond  Expr // i < 10;
	inc   Stmt // i++; i += 2
	stmts []Stmt
	label string // `label: for {`
	scope &Scope = unsafe { nil }
}

struct ForInStmt #

@[minify]
struct ForInStmt {
pub:
	key_var    string
	val_var    string
	is_range   bool
	pos        token.Pos
	kv_pos     token.Pos
	vv_pos     token.Pos
	comments   []Comment
	val_is_mut bool // `for mut val in vals {` means that modifying `val` will modify the array
	// and the array cannot be indexed inside the loop
pub mut:
	val_is_ref bool // `for val in &arr {` means that value of `val` will be the reference of the value in `arr`
	cond       Expr
	key_type   Type
	val_type   Type
	cond_type  Type
	high       Expr // `10` in `for i in 0..10 {`
	high_type  Type
	kind       Kind   // array/map/string
	label      string // `label: for {`
	scope      &Scope = unsafe { nil }
	stmts      []Stmt
}

struct ForStmt #

struct ForStmt {
pub:
	is_inf   bool // `for {}`
	pos      token.Pos
	comments []Comment
pub mut:
	cond  Expr
	stmts []Stmt
	label string // `label: for {`
	scope &Scope = unsafe { nil }
}

struct GenericInst #

struct GenericInst {
pub mut:
	parent_idx     int    // idx of the base generic struct
	concrete_types []Type // concrete types, e.g. [int, string]
}

instantiation of a generic struct

struct GetEmbedsOptions #

@[params]
struct GetEmbedsOptions {
pub:
	preceding []Type
}

struct GlobalDecl #

struct GlobalDecl {
pub:
	mod      string
	pos      token.Pos
	is_block bool   // __global() block
	attrs    []Attr // tags like `@[markused]`, valid for all the globals in the list
pub mut:
	fields       []GlobalField
	end_comments []Comment
}

struct GlobalField #

@[minify]
struct GlobalField {
pub:
	name        string
	has_expr    bool
	pos         token.Pos
	typ_pos     token.Pos
	is_markused bool // an explicit `@[markused]` tag; the global will NOT be removed by `-skip-unused`
	is_volatile bool
	is_exported bool // an explicit `@[export]` tag; the global will NOT be removed by `-skip-unused`
pub mut:
	expr     Expr
	typ      Type
	comments []Comment
}

struct GoExpr #

@[minify]
struct GoExpr {
pub:
	pos token.Pos
pub mut:
	call_expr CallExpr
	is_expr   bool
}

struct GotoLabel #

struct GotoLabel {
pub:
	name string
	pos  token.Pos
pub mut:
	is_used bool
}

struct GotoStmt #

struct GotoStmt {
pub:
	name string
	pos  token.Pos
}

struct HashStmt #

struct HashStmt {
pub:
	mod         string
	pos         token.Pos
	source_file string
pub mut:
	val      string // example: 'include  # please install openssl // comment'
	kind     string // : 'include'
	main     string // : ''
	msg      string // : 'please install openssl'
	ct_conds []Expr // *all* comptime conditions, that must be true, for the hash to be processed
	// ct_conds is filled by the checker, based on the current nesting of `$if cond1 {}` blocks
}

#include, #define etc

struct Ident #

@[minify]
struct Ident {
pub:
	language Language
	tok_kind token.Kind
	pos      token.Pos
	mut_pos  token.Pos
	comptime bool
pub mut:
	scope          &Scope = unsafe { nil }
	obj            ScopeObject
	mod            string
	name           string
	full_name      string
	cached_name    string
	kind           IdentKind
	info           IdentInfo
	is_mut         bool // if mut *token* is before name. Use `is_mut()` to lookup mut variable
	or_expr        OrExpr
	concrete_types []Type
}

A single identifier

fn (Ident) full_name #

fn (mut i Ident) full_name() string

full_name returns the name of the ident, prefixed with the module name

fn (Ident) is_auto_heap #

fn (i &Ident) is_auto_heap() bool

fn (Ident) is_mut #

fn (i &Ident) is_mut() bool

fn (Ident) var_info #

fn (i &Ident) var_info() IdentVar

struct IdentFn #

struct IdentFn {
pub mut:
	typ Type
}

struct IdentVar #

@[minify]
struct IdentVar {
pub mut:
	typ         Type
	is_mut      bool
	is_static   bool
	is_volatile bool
	is_option   bool
	share       ShareType
}

Todo: (joe) remove completely, use ident.objinstead which points to the scope object

struct IfBranch #

struct IfBranch {
pub:
	pos      token.Pos
	body_pos token.Pos
	comments []Comment
pub mut:
	cond      Expr
	pkg_exist bool
	stmts     []Stmt
	scope     &Scope = unsafe { nil }
}

struct IfExpr #

@[minify]
struct IfExpr {
pub:
	is_comptime   bool
	tok_kind      token.Kind
	pos           token.Pos
	post_comments []Comment
pub mut:
	left     Expr       // `a` in `a := if ...`
	branches []IfBranch // includes all `else if` branches
	is_expr  bool
	typ      Type
	has_else bool
	// implements bool // comptime $if implements interface
}

struct IfGuardExpr #

struct IfGuardExpr {
pub:
	vars []IfGuardVar
pub mut:
	expr      Expr // `opt()`
	expr_type Type // type of `opt()`
}

if x := opt() {

struct IfGuardVar #

struct IfGuardVar {
pub mut:
	name   string
	is_mut bool
	pos    token.Pos
}

struct Import #

struct Import {
pub:
	source_name string // The original name in the source, `import abc.def` -> 'abc.def', *no matter* how the module is resolved

	mod       string // the module name of the import
	alias     string // the `x` in `import xxx as x`
	pos       token.Pos
	mod_pos   token.Pos
	alias_pos token.Pos
	syms_pos  token.Pos
pub mut:
	syms          []ImportSymbol // the list of symbols in `import {symbol1, symbol2}`
	comments      []Comment
	next_comments []Comment
}

import statement

struct ImportSymbol #

struct ImportSymbol {
pub:
	pos  token.Pos
	name string
}

import symbol,for import {symbol} syntax

struct IndexExpr #

@[minify]
struct IndexExpr {
pub:
	pos token.Pos
pub mut:
	index     Expr // [0], RangeExpr [start..end] or map[key]
	or_expr   OrExpr
	left      Expr
	left_type Type // array, map, fixed array
	is_setter bool
	is_map    bool
	is_array  bool
	is_farray bool // fixed array
	is_option bool // IfGuard
	is_direct bool // Set if the underlying memory can be safely accessed
	is_gated  bool // #[] gated array
}

fn (IndexExpr) recursive_mapset_is_setter #

fn (mut lx IndexExpr) recursive_mapset_is_setter(val bool)

helper for dealing with m[k1][k2][k3][k3] = value

fn (IndexExpr) recursive_arraymap_set_is_setter #

fn (mut lx IndexExpr) recursive_arraymap_set_is_setter()

struct InfixExpr #

@[minify]
struct InfixExpr {
pub:
	op      token.Kind
	pos     token.Pos
	is_stmt bool
pub mut:
	left          Expr
	right         Expr
	left_type     Type
	right_type    Type
	promoted_type Type = void_type
	auto_locked   string
	or_block      OrExpr

	ct_left_value_evaled  bool
	ct_left_value         ComptTimeConstValue = empty_comptime_const_expr()
	ct_right_value_evaled bool
	ct_right_value        ComptTimeConstValue = empty_comptime_const_expr()

	before_op_comments []Comment
	after_op_comments  []Comment
}

left op right See: token.Kind.is_infix

struct IntegerLiteral #

struct IntegerLiteral {
pub:
	val string
	pos token.Pos
}

struct Interface #

@[minify]
struct Interface {
pub mut:
	types   []Type // all types that implement this interface
	fields  []StructField
	methods []Fn
	embeds  []Type
	// `I1 is I2` conversions
	conversions shared map[int][]Type
	// generic interface support
	is_generic     bool
	generic_types  []Type
	concrete_types []Type
	parent_type    Type
}

fn (Interface) find_field #

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

fn (Interface) find_method #

fn (i &Interface) find_method(name string) ?Fn

fn (Interface) has_method #

fn (i &Interface) has_method(name string) bool

fn (Interface) defines_method #

fn (i Interface) defines_method(name string) bool

fn (Interface) get_methods #

fn (i Interface) get_methods() []string

struct InterfaceDecl #

@[minify]
struct InterfaceDecl {
pub:
	name          string
	typ           Type
	name_pos      token.Pos
	language      Language
	field_names   []string
	is_pub        bool
	mut_pos       int // mut:
	pos           token.Pos
	pre_comments  []Comment
	generic_types []Type
	attrs         []Attr
pub mut:
	methods             []FnDecl
	fields              []StructField
	embeds              []InterfaceEmbedding
	are_embeds_expanded bool
}

struct InterfaceEmbedding #

struct InterfaceEmbedding {
pub:
	name     string
	typ      Type
	pos      token.Pos
	comments []Comment
}

struct IsRefType #

struct IsRefType {
pub:
	guessed_type bool // a legacy `isreftype( GuessedType )` => a deprecation notice, suggesting `v fmt -w .` => `isreftype[ Type ]()`
	is_type      bool
	pos          token.Pos
pub mut:
	expr Expr // checker uses this to set typ, when !is_type
	typ  Type
}

struct LambdaExpr #

struct LambdaExpr {
pub:
	pos token.Pos
pub mut:
	params     []Ident
	pos_expr   token.Pos
	expr       Expr
	pos_end    token.Pos
	scope      &Scope  = unsafe { nil }
	func       &AnonFn = unsafe { nil }
	is_checked bool
	typ        Type
	call_ctx   &CallExpr = unsafe { nil }
}

struct Likely #

struct Likely {
pub:
	pos       token.Pos
	is_likely bool // false for _unlikely_
pub mut:
	expr Expr
}

struct LockExpr #

struct LockExpr {
pub:
	is_rlock []bool
	pos      token.Pos
pub mut:
	stmts    []Stmt
	lockeds  []Expr // `x`, `y.z` in `lock x, y.z {`
	comments []Comment
	is_expr  bool
	typ      Type
	scope    &Scope = unsafe { nil }
}

struct Map #

struct Map {
pub mut:
	key_type   Type
	value_type Type
}

struct MapInit #

@[minify]
struct MapInit {
pub:
	pos       token.Pos
	comments  [][]Comment // comments after key-value pairs
	pre_cmnts []Comment   // comments before the first key-value pair
pub mut:
	keys                 []Expr
	vals                 []Expr
	val_types            []Type
	typ                  Type
	key_type             Type
	value_type           Type
	has_update_expr      bool // has `...a`
	update_expr          Expr // `a` in `...a`
	update_expr_pos      token.Pos
	update_expr_comments []Comment
}

struct MatchBranch #

struct MatchBranch {
pub:
	ecmnts        [][]Comment // inline comments for each left side expr
	pos           token.Pos
	is_else       bool
	post_comments []Comment // comments below ´... }´
	branch_pos    token.Pos // for checker errors about invalid branches
pub mut:
	stmts []Stmt // right side
	exprs []Expr // left side
	scope &Scope = unsafe { nil }
}

struct MatchExpr #

@[minify]
struct MatchExpr {
pub:
	tok_kind token.Kind
	pos      token.Pos
	comments []Comment // comments before the first branch
pub mut:
	cond          Expr
	branches      []MatchBranch
	is_expr       bool // returns a value
	return_type   Type
	cond_type     Type // type of `x` in `match x {`
	expected_type Type // for debugging only
	is_sum_type   bool
}

struct Module #

struct Module {
pub:
	name       string // encoding.base64
	short_name string // base64
	attrs      []Attr
	pos        token.Pos
	name_pos   token.Pos // `name` in import name
	is_skipped bool      // module main can be skipped in single file programs
}

module declaration

struct MultiReturn #

struct MultiReturn {
pub mut:
	types []Type
}

struct Nil #

struct Nil {
pub:
	pos token.Pos
}

struct NodeError #

struct NodeError {
pub:
	idx int // index for referencing the related File error
	pos token.Pos
}

struct None #

struct None {
pub:
	pos token.Pos
}

struct OffsetOf #

@[minify]
struct OffsetOf {
pub:
	struct_type Type
	field       string
	pos         token.Pos
}

struct OrExpr #

struct OrExpr {
pub:
	kind OrKind
	pos  token.Pos
pub mut:
	stmts []Stmt
}

or { ... }

struct ParExpr #

struct ParExpr {
pub:
	pos token.Pos
pub mut:
	expr     Expr
	comments []Comment
}

(3+4)

struct Param #

@[minify]
struct Param {
pub:
	pos        token.Pos
	name       string
	is_mut     bool
	is_shared  bool
	is_atomic  bool
	type_pos   token.Pos
	is_hidden  bool // interface first arg
	on_newline bool // whether the argument starts on a new line
pub mut:
	typ Type
}

fn (Param) specifier #

fn (p &Param) specifier() string

struct PostfixExpr #

struct PostfixExpr {
pub:
	op            token.Kind
	pos           token.Pos
	is_c2v_prefix bool // for `--x` (`x--$`), only for translated code until c2v can handle it
pub mut:
	expr        Expr
	typ         Type
	auto_locked string
}

++, --

struct PrefixExpr #

@[minify]
struct PrefixExpr {
pub:
	op  token.Kind
	pos token.Pos
pub mut:
	right_type Type
	right      Expr
	or_block   OrExpr
	is_option  bool // IfGuard
}

See: token.Kind.is_prefix

struct RangeExpr #

@[minify]
struct RangeExpr {
pub:
	has_high bool
	has_low  bool
	pos      token.Pos
	is_gated bool // #[] gated array
pub mut:
	low  Expr
	high Expr
	typ  Type // filled in by checker; the type of `0...1` is `int` for example, while `a`...`z` is `rune` etc
}

s[10..20]

struct Return #

struct Return {
pub:
	pos      token.Pos
	comments []Comment
pub mut:
	exprs []Expr
	types []Type
}

function return statement

struct Scope #

@[heap]
struct Scope {
pub mut:
	// mut:
	objects              map[string]ScopeObject
	struct_fields        map[string]ScopeStructField
	parent               &Scope = unsafe { nil }
	detached_from_parent bool
	children             []&Scope
	start_pos            int
	end_pos              int
}

fn (Scope) free #

unsafe
fn (s &Scope) free()

fn (Scope) find #

fn (s &Scope) find(name string) ?ScopeObject

fn (Scope) find_struct_field #

fn (s &Scope) find_struct_field(name string, struct_type Type, field_name string) ?ScopeStructField

selector_expr: name.field_name

fn (Scope) find_var #

fn (s &Scope) find_var(name string) ?&Var

fn (Scope) find_global #

fn (s &Scope) find_global(name string) ?&GlobalField

fn (Scope) find_const #

fn (s &Scope) find_const(name string) ?&ConstField

fn (Scope) known_var #

fn (s &Scope) known_var(name string) bool

fn (Scope) known_global #

fn (s &Scope) known_global(name string) bool

fn (Scope) known_const #

fn (s &Scope) known_const(name string) bool

fn (Scope) update_var_type #

fn (mut s Scope) update_var_type(name string, typ Type)

fn (Scope) update_ct_var_kind #

fn (mut s Scope) update_ct_var_kind(name string, kind ComptimeVarKind)

fn (Scope) update_smartcasts #

fn (mut s Scope) update_smartcasts(name string, typ Type, is_unwrapped bool)

fn (Scope) register_struct_field #

fn (mut s Scope) register_struct_field(name string, field ScopeStructField)

selector_expr: name.field_name

fn (Scope) register #

fn (mut s Scope) register(obj ScopeObject)

fn (Scope) innermost #

fn (s &Scope) innermost(pos int) &Scope

returns the innermost scope containing pos pub fn (s &Scope) innermost(pos int) ?&Scope {

fn (Scope) get_all_vars #

fn (s &Scope) get_all_vars() []ScopeObject

get_all_vars extracts all current scope vars

fn (Scope) contains #

fn (s &Scope) contains(pos int) bool

fn (Scope) has_inherited_vars #

fn (s &Scope) has_inherited_vars() bool

fn (Scope) is_inherited_var #

fn (s &Scope) is_inherited_var(var_name string) bool

fn (Scope) show #

fn (sc &Scope) show(depth int, max_depth int) string

fn (Scope) mark_var_as_used #

fn (mut sc Scope) mark_var_as_used(varname string) bool

fn (Scope) str #

fn (sc &Scope) str() string

struct ScopeStructField #

@[minify]
struct ScopeStructField {
pub:
	struct_type Type // type of struct
	name        string
	pos         token.Pos
	typ         Type
	smartcasts  []Type // nested sum types require nested smart casting, for that a list of types is needed
	orig_type   Type   // original sumtype type; 0 if it's not a sumtype
	// TODO: move this to a real docs site later
	// 10 <- original type (orig_type)
	//   [11, 12, 13] <- cast order (smartcasts)
	//        12 <- the current casted type (typ)
}

used for smartcasting only struct fields change type in scopes

struct SelectBranch #

@[minify]
struct SelectBranch {
pub:
	pos           token.Pos
	comment       Comment // comment above `select {`
	is_else       bool
	is_timeout    bool
	post_comments []Comment
pub mut:
	stmt  Stmt   // `a := <-ch` or `ch <- a`
	stmts []Stmt // right side
}

struct SelectExpr #

struct SelectExpr {
pub:
	branches      []SelectBranch
	pos           token.Pos
	has_exception bool
pub mut:
	is_expr       bool // returns a value
	expected_type Type // for debugging only
}

struct SelectorExpr #

@[minify]
struct SelectorExpr {
pub:
	pos        token.Pos
	field_name string
	is_mut     bool // is used for the case `if mut ident.selector is MyType {`, it indicates if the root ident is mutable
	mut_pos    token.Pos
	next_token token.Kind
pub mut:
	expr                     Expr // expr.field_name
	expr_type                Type // type of `Foo` in `Foo.bar`
	typ                      Type // type of the entire thing (`Foo.bar`)
	name_type                Type // T in `T.name` or typeof in `typeof(expr).name`
	or_block                 OrExpr
	gkind_field              GenericKindField // `T.name` => ast.GenericKindField.name, `T.typ` => ast.GenericKindField.typ, or .unknown
	scope                    &Scope = unsafe { nil }
	from_embed_types         []Type   // holds the type of the embed that the method is called from
	generic_from_embed_types [][]Type // holds the types of the embeds for each generic instance when the same generic method is called.
	has_hidden_receiver      bool
}

foo.bar

fn (SelectorExpr) root_ident #

fn (e &SelectorExpr) root_ident() ?Ident

root_ident returns the origin ident where the selector started.

struct SemicolonStmt #

struct SemicolonStmt {
pub:
	pos token.Pos
}

struct SizeOf #

struct SizeOf {
pub:
	guessed_type bool // a legacy `sizeof( GuessedType )` => a deprecation notice, suggesting `v fmt -w .` => `sizeof[ Type ]()`
	is_type      bool
	pos          token.Pos
pub mut:
	expr Expr // checker uses this to set typ, when !is_type
	typ  Type
}

struct SpawnExpr #

@[minify]
struct SpawnExpr {
pub:
	pos token.Pos
pub mut:
	call_expr CallExpr
	is_expr   bool
}

struct SqlExpr #

struct SqlExpr {
pub:
	is_count     bool
	is_insert    bool // for insert expressions
	inserted_var string

	has_where  bool
	has_order  bool
	has_limit  bool
	has_offset bool
	has_desc   bool
	is_array   bool
	// is_generated indicates a statement is generated by ORM for complex queries with related tables.
	is_generated bool
	pos          token.Pos
pub mut:
	typ         Type
	db_expr     Expr // `db` in `sql db {`
	where_expr  Expr
	order_expr  Expr
	limit_expr  Expr
	offset_expr Expr
	table_expr  TypeNode
	fields      []StructField
	sub_structs map[int]SqlExpr
	or_expr     OrExpr
}

struct SqlStmt #

struct SqlStmt {
pub:
	pos token.Pos
pub mut:
	lines        []SqlStmtLine
	db_expr      Expr // `db` in `sql db {`
	or_expr      OrExpr
	db_expr_type Type // the type of the `db` in `sql db {`
}

struct SqlStmtLine #

struct SqlStmtLine {
pub:
	kind SqlStmtKind
	pos  token.Pos
	// is_generated indicates a statement is generated by ORM for complex queries with related tables.
	is_generated bool
	scope        &Scope = unsafe { nil }
pub mut:
	object_var      string   // `user`
	updated_columns []string // for `update set x=y`
	table_expr      TypeNode
	fields          []StructField
	sub_structs     map[int]SqlStmtLine
	where_expr      Expr
	update_exprs    []Expr // for `update`
	pre_comments    []Comment
	end_comments    []Comment
}

struct StringInterLiteral #

struct StringInterLiteral {
pub:
	vals       []string
	fwidths    []int
	precisions []int
	pluss      []bool
	fills      []bool
	fmt_poss   []token.Pos
	pos        token.Pos
pub mut:
	exprs      []Expr
	expr_types []Type
	fmts       []u8
	need_fmts  []bool // an explicit non-default fmt required, e.g. `x`
}

'name: $name'

fn (StringInterLiteral) get_fspec_braces #

fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool)

Expressions in string interpolations may have to be put in braces if they are non-trivial, if they would interfere with the next character or if a format specification is given. In the latter case the format specifier must be appended, separated by a colon: '$z $z.b $z.c.x ${x[4]} ${z:8.3f} ${a:-20} ${a>b+2}' This method creates the format specifier (including the colon) or an empty string if none is needed and also returns (as bool) if the expression must be enclosed in braces.

struct StringLiteral #

@[minify]
struct StringLiteral {
pub:
	val      string
	is_raw   bool
	language Language
	pos      token.Pos
}

struct Struct #

@[minify]
struct Struct {
pub:
	attrs       []Attr
	scoped_name string
pub mut:
	embeds         []Type
	fields         []StructField
	is_typedef     bool // C. [typedef]
	is_union       bool
	is_heap        bool
	is_minify      bool
	is_anon        bool
	is_generic     bool
	has_option     bool // contains any option field
	generic_types  []Type
	concrete_types []Type
	parent_type    Type
}

fn (Struct) is_empty_struct #

fn (t &Struct) is_empty_struct() bool

fn (Struct) is_unresolved_generic #

fn (t &Struct) is_unresolved_generic() bool

fn (Struct) find_field #

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

fn (Struct) get_field #

fn (s Struct) get_field(name string) StructField

struct StructDecl #

@[minify]
struct StructDecl {
pub:
	pos           token.Pos
	name          string
	scoped_name   string
	generic_types []Type
	is_pub        bool
	// _pos fields for vfmt
	mut_pos      int = -1 // mut:
	pub_pos      int = -1 // pub:
	pub_mut_pos  int = -1 // pub mut:
	global_pos   int = -1 // __global:
	module_pos   int = -1 // module:
	language     Language
	is_union     bool
	attrs        []Attr
	pre_comments []Comment
	end_comments []Comment
	embeds       []Embed

	is_implements    bool
	implements_types []TypeNode
pub mut:
	fields []StructField
}

struct StructField #

@[minify]
struct StructField {
pub:
	pos              token.Pos
	type_pos         token.Pos
	option_pos       token.Pos
	pre_comments     []Comment
	comments         []Comment
	next_comments    []Comment
	i                int
	has_default_expr bool
	has_prev_newline bool
	has_break_line   bool
	attrs            []Attr
	is_pub           bool
	default_val      string
	is_mut           bool
	is_global        bool
	is_volatile      bool
	is_deprecated    bool
	is_embed         bool
pub mut:
	is_recursive     bool
	is_part_of_union bool
	container_typ    Type
	default_expr     Expr
	default_expr_typ Type
	name             string
	typ              Type
	unaliased_typ    Type
	anon_struct_decl StructDecl // only if the field is an anonymous struct
}

fn (StructField) equals #

fn (f &StructField) equals(o &StructField) bool

struct StructInit #

@[minify]
struct StructInit {
pub:
	pos             token.Pos
	name_pos        token.Pos
	no_keys         bool // `Foo{val1, val2}`
	is_short_syntax bool // `foo(field1: val1, field2: val2)`
	is_anon         bool //  `x: struct{ foo: bar }`
pub mut:
	unresolved           bool
	pre_comments         []Comment
	typ_str              string // 'Foo'
	typ                  Type   // the type of this struct
	update_expr          Expr   // `a` in `...a`
	update_expr_type     Type
	update_expr_pos      token.Pos
	update_expr_comments []Comment
	is_update_embed      bool
	has_update_expr      bool // has `...a`
	init_fields          []StructInitField
	generic_types        []Type
}

s := Foo{ ...a field1: 'hello' }

struct StructInitField #

struct StructInitField {
pub:
	pos              token.Pos
	name_pos         token.Pos
	pre_comments     []Comment
	end_comments     []Comment
	next_comments    []Comment
	has_prev_newline bool
	has_break_line   bool
	is_embed         bool
pub mut:
	expr          Expr   // `val1`
	name          string // 'field1'
	typ           Type   // the type of this field
	expected_type Type
	parent_type   Type
}

field1: val1

struct SumType #

@[minify]
struct SumType {
pub mut:
	fields       []StructField
	found_fields bool
	is_anon      bool
	// generic sumtype support
	is_generic     bool
	variants       []Type
	generic_types  []Type
	concrete_types []Type
	parent_type    Type
}

fn (SumType) find_sum_type_field #

fn (s &SumType) find_sum_type_field(name string) ?StructField

struct SumTypeDecl #

struct SumTypeDecl {
pub:
	name          string
	is_pub        bool
	pos           token.Pos
	name_pos      token.Pos
	typ           Type
	generic_types []Type
	attrs         []Attr // attributes of type declaration
pub mut:
	variants []TypeNode
}

SumTypeDecl is the ast node for type MySumType = string | int

struct Table #

@[heap]
@[minify]
struct Table {
mut:
	parsing_type string // name of the type to enable recursive type parsing
pub mut:
	type_symbols       []&TypeSymbol
	type_idxs          map[string]int
	fns                map[string]Fn
	iface_types        map[string][]Type
	dumps              map[int]string // needed for efficiently generating all _v_dump_expr_TNAME() functions
	imports            []string       // List of all imports
	modules            []string       // Topologically sorted list of all modules registered by the application
	global_scope       &Scope = unsafe { nil }
	cflags             []cflag.CFlag
	redefined_fns      []string
	fn_generic_types   map[string][][]Type // for generic functions
	interfaces         map[int]InterfaceDecl
	sumtypes           map[int]SumTypeDecl
	cmod_prefix        string // needed for ast.type_to_str(Type) while vfmt; contains `os.`
	is_fmt             bool
	used_fns           map[string]bool // filled in by the checker, when pref.skip_unused = true;
	used_consts        map[string]bool // filled in by the checker, when pref.skip_unused = true;
	used_globals       map[string]bool // filled in by the checker, when pref.skip_unused = true;
	used_features      UsedFeatures    // filled in by the checker, when pref.skip_unused = true;
	used_veb_types     []Type          // veb context types, filled in by checker, when pref.skip_unused = true;
	veb_res_idx_cache  int             // Cache of `veb.Result` type
	veb_ctx_idx_cache  int             // Cache of `veb.Context` type
	used_maps          int             // how many times maps were used, filled in by checker, when pref.skip_unused = true;
	panic_handler      FnPanicHandler = default_table_panic_handler
	panic_userdata     voidptr        = unsafe { nil } // can be used to pass arbitrary data to panic_handler;
	panic_npanics      int
	cur_fn             &FnDecl     = unsafe { nil } // previously stored in Checker.cur_fn and Gen.cur_fn
	cur_lambda         &LambdaExpr = unsafe { nil } // current lambda node
	cur_concrete_types []Type // current concrete types, e.g. 
	gostmts            int    // how many `go` statements there were in the parsed files.
	// When table.gostmts > 0, __VTHREADS__ is defined, which can be checked with `$if threads {`
	enum_decls        map[string]EnumDecl
	module_deprecated map[string]bool
	module_attrs      map[string][]Attr // module attributes
	builtin_pub_fns   map[string]bool
	pointer_size      int
	// cache for type_to_str_using_aliases
	cached_type_to_str map[u64]string
	anon_struct_names  map[string]int // anon struct name -> struct sym idx
	// counter for anon struct, avoid name conflicts.
	anon_struct_counter int
}

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, size_expr Expr) 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) bitsize_to_type #

fn (mut t Table) bitsize_to_type(bit_size int) Type

bitsize_to_type returns a type corresponding to the bit_size Examples:

8 > i8

32 > int

123 > panic()

128 > [16]u8

608 > [76]u8

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) check_if_elements_need_unwrap #

fn (mut t Table) check_if_elements_need_unwrap(root_typ Type, typ Type) bool

check_if_elements_need_unwrap checks if the elements of a container (arrays, maps) need to be unwrapped to a concrete type

fn (Table) clean_generics_type_str #

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

clean type name from generics form. From Type[int] -> Type

fn (Table) complete_interface_check #

fn (mut t Table) complete_interface_check()

complete_interface_check does a MxN check for all M interfaces vs all N types, to determine what types implement what interfaces. It short circuits most checks when an interface can not possibly be implemented by a type.

fn (Table) convert_generic_static_type_name #

fn (mut t Table) convert_generic_static_type_name(fn_name string, generic_names []string, concrete_types []Type) (Type, string)

fn (Table) convert_generic_type #

fn (mut t Table) convert_generic_type(generic_type Type, generic_names []string, to_types []Type) ?Type

convert_generic_type convert generics to real types (T => int) or other generics type.

fn (Table) dependent_names_in_expr #

fn (t &Table) dependent_names_in_expr(expr Expr) []string

fn (Table) dependent_names_in_stmt #

fn (t &Table) dependent_names_in_stmt(stmt Stmt) []string

fn (Table) does_type_implement_interface #

fn (t &Table) does_type_implement_interface(typ Type, inter_typ Type) bool

fn (Table) final_sym #

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

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

fn (Table) find_enum_field_val #

fn (t &Table) find_enum_field_val(name string, field_ string) ?i64

find_enum_field_val finds the possible int value from the enum name and enum field (returns none if the value cannot be resolved at compile time)

fn (Table) find_field #

fn (t &Table) find_field(s &TypeSymbol, name string) !StructField

search from current type up through each parent looking for field

fn (Table) find_field_from_embeds #

fn (t &Table) find_field_from_embeds(sym &TypeSymbol, field_name string) !(StructField, []Type)

find_field_from_embeds tries to find a field in the nested embeds

fn (Table) find_field_with_embeds #

fn (t &Table) find_field_with_embeds(sym &TypeSymbol, field_name string) !StructField

find_field_with_embeds searches for a given field, also looking through embedded fields

fn (Table) find_fn #

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

fn (Table) find_method #

fn (t &Table) find_method(s &TypeSymbol, name string) !Fn

find_method searches from current type up through each parent looking for method

fn (Table) find_method_from_embeds #

fn (t &Table) find_method_from_embeds(sym &TypeSymbol, method_name string) !(Fn, []Type)

fn (Table) find_method_with_embeds #

fn (t &Table) find_method_with_embeds(sym &TypeSymbol, method_name string) !Fn

find_method_with_embeds searches for a given method, also looking through embedded fields

fn (Table) find_missing_variants #

fn (t &Table) find_missing_variants(s &SumType, field_name string) string

For the 'field does not exist or have the same type in all sumtype variants' error. To print all sumtype variants the developer has to fix.

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, size_expr Expr, is_fn_ret bool) 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(f Fn, is_anon bool, has_decl bool) 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_or_register_promise #

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

fn (Table) find_or_register_thread #

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

fn (Table) find_sym #

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

fn (Table) find_sym_and_type_idx #

fn (t &Table) find_sym_and_type_idx(name string) (&TypeSymbol, int)

fn (Table) find_type #

fn (t &Table) find_type(name string) Type

fn (Table) find_type_idx #

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

fn (Table) find_type_idx_fn_scoped #

fn (t &Table) find_type_idx_fn_scoped(name string, scope &Scope) int

fn (Table) fn_signature #

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

fn (Table) fn_signature_using_aliases #

fn (t &Table) fn_signature_using_aliases(func &Fn, import_aliases map[string]string, 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

fn_type_source_signature generates the signature of a function which looks like in the V source

fn (Table) free #

unsafe
fn (mut t Table) free()

used by vls to avoid leaks

Todo: remove manual memory management

fn (Table) generic_insts_to_concrete #

fn (mut t Table) generic_insts_to_concrete()

generic struct instantiations to concrete types

fn (Table) generic_type_names #

fn (mut t Table) generic_type_names(generic_type Type) []string

fn (Table) get_anon_fn_name #

fn (table &Table) get_anon_fn_name(prefix string, func &Fn, pos int) string

get_anon_fn_name returns the unique anonymous function name, based on the prefix, the func signature and its position in the source code

fn (Table) get_array_dims #

fn (t &Table) get_array_dims(arr Array) (int, Type)

fn (Table) get_attrs #

fn (t &Table) get_attrs(sym TypeSymbol) []Attr

get_attrs retrieve the attribrutes from the type symbol

fn (Table) get_embed_methods #

fn (t &Table) get_embed_methods(sym &TypeSymbol) []Fn

fn (Table) get_embeds #

fn (t &Table) get_embeds(sym &TypeSymbol, options GetEmbedsOptions) [][]Type

get_embeds returns all nested embedded structs the hierarchy of embeds is returned as a list

fn (Table) get_enum_field_names #

fn (t &Table) get_enum_field_names(name string) []string

fn (Table) get_enum_field_vals #

fn (t &Table) get_enum_field_vals(name string) []i64

fn (Table) get_final_type_name #

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

fn (Table) get_generic_names #

fn (t &Table) get_generic_names(generic_types []Type) []string

Extracts all type names from given types, notice that MultiReturn will be decompose and will not included in returned string

fn (Table) get_trace_fn_name #

fn (t &Table) get_trace_fn_name(cur_fn FnDecl, node CallExpr) (string, string)

fn (Table) get_type_name #

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

fn (Table) get_veb_result_type_idx #

fn (mut t Table) get_veb_result_type_idx() int

fn (Table) has_cflag #

fn (t &Table) has_cflag(flag cflag.CFlag) bool

check if cflag is in table

fn (Table) has_deep_child_no_ref #

fn (t &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 children that are references

fn (Table) has_method #

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

fn (Table) is_interface_smartcast #

fn (t &Table) is_interface_smartcast(var ScopeObject) bool

fn (Table) is_interface_var #

fn (t &Table) is_interface_var(var ScopeObject) bool

fn (Table) is_same_method #

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

fn (Table) is_sumtype_or_in_variant #

fn (t &Table) is_sumtype_or_in_variant(parent Type, typ Type) bool

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

fn (t &Table) known_type_idx(typ Type) bool

fn (Table) known_type_names #

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

only used for debugging V compiler type bugs

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) panic #

fn (t &Table) panic(message string)

fn (Table) parse_cflag #

fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string) !

parse the flags to (ast.cflags) []CFlag

Note: clean up big time (joe-c)

fn (Table) promise_cname #

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

fn (Table) promise_name #

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

fn (Table) register_aggregate_method #

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

fn (Table) register_anon_struct #

fn (mut t Table) register_anon_struct(name string, sym_idx int)

fn (Table) register_builtin_type_symbols #

fn (mut t Table) register_builtin_type_symbols()

fn (Table) register_enum_decl #

fn (mut t Table) register_enum_decl(enum_decl EnumDecl)

fn (Table) register_fn #

fn (mut t Table) register_fn(new_fn Fn)

fn (Table) register_fn_concrete_types #

fn (mut t Table) register_fn_concrete_types(fn_name string, types []Type) bool

fn (Table) register_fn_generic_types #

fn (mut t Table) register_fn_generic_types(fn_name string)

fn (Table) register_interface #

fn (mut t Table) register_interface(idecl InterfaceDecl)

fn (Table) register_sumtype #

fn (mut t Table) register_sumtype(sumtyp SumTypeDecl)

fn (Table) register_sym #

fn (mut t Table) register_sym(sym TypeSymbol) int

fn (Table) reset_parsing_type #

fn (mut t Table) reset_parsing_type()

fn (Table) resolve_common_sumtype_fields #

fn (t &Table) resolve_common_sumtype_fields(mut sym TypeSymbol)

fn (Table) resolve_init #

fn (t &Table) resolve_init(node StructInit, typ Type) Expr

fn (Table) start_parsing_type #

fn (mut t Table) start_parsing_type(type_name string)

start_parsing_type open the scope during the parsing of a type where the type name must include the module prefix

fn (Table) stringify_anon_decl #

fn (t &Table) stringify_anon_decl(node &AnonFn, cur_mod string, m2a map[string]string) string

These methods are used only by vfmt, vdoc, and for debugging.

fn (Table) stringify_fn_decl #

fn (t &Table) stringify_fn_decl(node &FnDecl, cur_mod string, m2a map[string]string, needs_wrap bool) string

fn (Table) struct_fields #

fn (t &Table) struct_fields(sym &TypeSymbol) []StructField

struct_fields returns all fields including fields from embeds use this instead symbol.info.fields to get all fields

fn (Table) struct_has_field #

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

fn (Table) sumtype_has_variant #

fn (t &Table) sumtype_has_variant(parent Type, variant Type, is_as bool) bool

Todo: there is a bug when casting sumtype the other way if its pointerso until fixed at least show v (not C) error x(variant) = y(SumType*)

fn (Table) sym #

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

fn (Table) sym_by_idx #

fn (t &Table) sym_by_idx(idx int) &TypeSymbol

fn (Table) thread_cname #

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

fn (Table) thread_name #

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

fn (Table) type_is_for_pointer_arithmetic #

fn (t &Table) type_is_for_pointer_arithmetic(typ Type) bool

fn (Table) type_kind #

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

type_kind returns the kind of the given type symbol.

fn (Table) type_size #

fn (t &Table) type_size(typ Type) (int, int)

type_size returns the size and alignment (in bytes) of typ, similarly to C's sizeof() and alignof().

fn (Table) type_str #

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

fn (Table) type_to_code #

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

type name in code (for builtin)

fn (Table) type_to_str #

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

human readable type name, also used by vfmt

fn (Table) type_to_str_using_aliases #

fn (t &Table) type_to_str_using_aliases(typ 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) unaliased_type #

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

fn (Table) unwrap_generic_type #

fn (mut t Table) unwrap_generic_type(typ Type, generic_names []string, concrete_types []Type) Type

fn (Table) unwrap_generic_type_ex #

fn (mut t Table) unwrap_generic_type_ex(typ Type, generic_names []string, concrete_types []Type, recheck_concrete_types bool) Type

fn (Table) value_type #

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

struct Thread #

struct Thread {
pub mut:
	return_type Type
}

struct TypeNode #

struct TypeNode {
pub:
	pos token.Pos
pub mut:
	typ          Type
	stmt         Stmt = empty_stmt // for anon struct
	end_comments []Comment // comments that after current type node
}

struct TypeOf #

@[minify]
struct TypeOf {
pub:
	is_type bool
	pos     token.Pos
pub mut:
	expr Expr // checker uses this to set typ, when !is_type
	typ  Type
}

struct TypeSymbol #

@[minify]
struct TypeSymbol {
pub:
	parent_idx int
pub mut:
	info          TypeInfo
	kind          Kind
	name          string // the internal & source name of the type, i.e. `[5]int`.
	cname         string // the name with no dots for use in the generated C code
	rname         string // the raw name
	methods       []Fn
	generic_types []Type
	mod           string
	is_pub        bool
	is_builtin    bool
	language      Language
	idx           int
	size          int = -1
	align         int = -1
}

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.sym.

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) dbg #

fn (ts &TypeSymbol) dbg() []string

same as .debug(), but without the verbose .info and .methods fields

fn (TypeSymbol) debug #

fn (ts &TypeSymbol) debug() []string

debug returns a verbose representation of the information in ts, useful for tracing/debugging

fn (TypeSymbol) embed_name #

fn (t &TypeSymbol) embed_name() string

embed_name return the pure name of the complete qualified name of the type, without the generic parts, concrete parts and mod parts. For example: main.Abc[int] -> Abc main.Abc<T>[int] -> Abc

fn (TypeSymbol) enum_info #

fn (t &TypeSymbol) enum_info() Enum

fn (TypeSymbol) find_field #

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

fn (TypeSymbol) find_method #

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

fn (TypeSymbol) find_method_with_generic_parent #

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

fn (TypeSymbol) get_methods #

fn (t &TypeSymbol) get_methods() []Fn

fn (TypeSymbol) has_field #

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

fn (TypeSymbol) has_method #

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

fn (TypeSymbol) has_method_with_generic_parent #

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

fn (TypeSymbol) is_array_fixed #

fn (t &TypeSymbol) is_array_fixed() bool

fn (TypeSymbol) is_array_fixed_ret #

fn (t &TypeSymbol) is_array_fixed_ret() bool

fn (TypeSymbol) is_bool #

fn (t &TypeSymbol) is_bool() bool

fn (TypeSymbol) is_builtin #

fn (t &TypeSymbol) is_builtin() bool

fn (TypeSymbol) is_c_struct #

fn (t &TypeSymbol) is_c_struct() bool

fn (TypeSymbol) is_empty_struct_array #

fn (t &TypeSymbol) is_empty_struct_array() bool

fn (TypeSymbol) is_float #

fn (t &TypeSymbol) is_float() bool

fn (TypeSymbol) is_heap #

fn (t &TypeSymbol) is_heap() bool

fn (TypeSymbol) is_int #

fn (t &TypeSymbol) is_int() bool

fn (TypeSymbol) is_js_compatible #

fn (t &TypeSymbol) is_js_compatible() bool

is_js_compatible returns true if type can be converted to JS type and from JS type back to V type

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) nr_dims #

fn (ts &TypeSymbol) nr_dims() int

fn (TypeSymbol) register_method #

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

fn (TypeSymbol) scoped_cname #

fn (ts &TypeSymbol) scoped_cname() string

fn (TypeSymbol) scoped_name #

fn (ts &TypeSymbol) scoped_name() string

fn (TypeSymbol) str #

fn (t &TypeSymbol) str() string

str returns the internal & source name of the type

fn (TypeSymbol) str_method_info #

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

fn (TypeSymbol) struct_info #

fn (t &TypeSymbol) struct_info() Struct

fn (TypeSymbol) sumtype_info #

fn (t &TypeSymbol) sumtype_info() SumType

fn (TypeSymbol) symbol_name_except_generic #

fn (t &TypeSymbol) symbol_name_except_generic() string

symbol_name_except_generic return the name of the complete qualified name of the type, but without the generic parts. The potential [], &[][] etc prefixes are kept. For example: main.Abc[int] -> main.Abc main.Abc<T>[int] -> main.Abc<T> []main.Abc<T>[int] -> []main.Abc<T> &[][]main.Abc<T>[int] -> &[][]main.Abc<T>

fn (TypeSymbol) thread_info #

fn (t &TypeSymbol) thread_info() Thread

fn (TypeSymbol) update_method #

fn (mut t TypeSymbol) update_method(f Fn) int

struct UnknownTypeInfo #

struct UnknownTypeInfo {}

struct UnsafeExpr #

struct UnsafeExpr {
pub:
	pos token.Pos
pub mut:
	expr Expr
}

struct UsedFeatures #

@[heap]
@[minify]
struct UsedFeatures {
pub mut:
	interfaces       bool         // interface
	dump             bool         // dump()
	builtin_types    bool         // uses any builtin type
	index            bool         // string[0]
	range_index      bool         // string[0..1]
	cast_ptr         bool         // &u8(...)
	as_cast          bool         // expr as Type
	anon_fn          bool         // fn () { }
	auto_str         bool         // auto str fns
	auto_str_ptr     bool         // auto str fns for ptr type
	arr_prepend      bool         // arr.prepend()
	arr_first        bool         // arr.first()
	arr_last         bool         // arr.last()
	arr_pop          bool         // arr.pop()
	option_or_result bool         // has panic call
	print_types      map[int]bool // print() idx types
}

struct Var #

@[minify]
struct Var {
pub:
	name            string
	share           ShareType
	is_mut          bool
	is_autofree_tmp bool
	is_inherited    bool
	has_inherited   bool
pub mut:
	is_arg        bool // fn args should not be autofreed
	is_auto_deref bool
	is_unwrapped  bool // ct type smartcast unwrapped
	expr          Expr
	typ           Type
	orig_type     Type   // original sumtype type; 0 if it's not a sumtype
	smartcasts    []Type // nested sum types require nested smart casting, for that a list of types is needed
	// TODO: move this to a real docs site later
	// 10 <- original type (orig_type)
	//   [11, 12, 13] <- cast order (smartcasts)
	//        12 <- the current casted type (typ)
	pos         token.Pos
	is_used     bool            // whether the local variable was used in other expressions
	is_changed  bool            // to detect mutable vars that are never changed
	ct_type_var ComptimeVarKind // comptime variable type
	// (for setting the position after the or block for autofree)
	is_or        bool // `x := foo() or { ... }`
	is_tmp       bool // for tmp for loop vars, so that autofree can skip them
	is_auto_heap bool // value whose address goes out of scope
	is_stack_obj bool // may be pointer to stack value (`mut` or `&` arg and not @[heap] struct)
}