v.ast #
Constants #
const (
empty_expr = Expr(EmptyExpr(0))
empty_stmt = Stmt(EmptyStmt{})
empty_node = Node(EmptyNode{})
)
const (
// reference: https://en.wikipedia.org/wiki/X86#/media/File:Table_of_x86_Registers_svg.svg
// map register size -> register name
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']
}
// 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 registors
// st#: floating point numbers
// cr#: control/status registers
// dr#: debug registers
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
}
}
)
const (
arm_no_number_register_list = ['fp' ///aka r11, ///not instruction pointer: 'ip' ///aka r12,
'sp' ///aka r13, 'lr' ///aka r14, ///this is instruction pointer ('program counter'):
'pc' ///aka r15,
] // 'cpsr' and 'apsr' are special flags registers, but cannot be referred to directly
arm_with_number_register_list = {
'r#': 16
}
)
TODO: saved priviled registers for arm
const (
riscv_no_number_register_list = ['zero', 'ra', 'sp', 'gp', 'tp']
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']
valid_comptime_compression_types = ['none', 'zlib']
valid_comptime_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
valid_comptime_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32']
valid_comptime_if_cpu_features = ['x64', 'x32', 'little_endian', 'big_endian']
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_emscripten', 'wasm32_wasi']
valid_comptime_not_user_defined = all_valid_comptime_idents()
)
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 invalid_type_idx = -1
const invalid_type_symbol = &TypeSymbol{
idx: invalid_type_idx
parent_idx: invalid_type_idx
language: .v
mod: 'builtin'
kind: .placeholder
name: 'InvalidType'
cname: 'InvalidType'
}
const (
void_type_idx = 1
voidptr_type_idx = 2
byteptr_type_idx = 3
charptr_type_idx = 4
i8_type_idx = 5
i16_type_idx = 6
int_type_idx = 7
i64_type_idx = 8
isize_type_idx = 9
u8_type_idx = 10
u16_type_idx = 11
u32_type_idx = 12
u64_type_idx = 13
usize_type_idx = 14
f32_type_idx = 15
f64_type_idx = 16
char_type_idx = 17
bool_type_idx = 18
none_type_idx = 19
string_type_idx = 20
rune_type_idx = 21
array_type_idx = 22
map_type_idx = 23
chan_type_idx = 24
any_type_idx = 25
float_literal_type_idx = 26
int_literal_type_idx = 27
thread_type_idx = 28
error_type_idx = 29
nil_type_idx = 30
)
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']
Note: builtin_type_names must be in the same order as the idx consts above
const builtin_type_names_matcher = token.new_keywords_matcher_from_array_trie(builtin_type_names)
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]
signed_integer_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, int_type_idx,
i64_type_idx, isize_type_idx]
unsigned_integer_type_idxs = [u8_type_idx, u16_type_idx, u32_type_idx, u64_type_idx,
usize_type_idx]
// C will promote any type smaller than int to int in an expression
int_promoted_type_idxs = [char_type_idx, i8_type_idx, i16_type_idx, u8_type_idx, u16_type_idx]
float_type_idxs = [f32_type_idx, f64_type_idx, float_literal_type_idx]
number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, 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]
pointer_type_idxs = [voidptr_type_idx, byteptr_type_idx, charptr_type_idx, nil_type_idx]
string_type_idxs = [string_type_idx]
)
const (
void_type = new_type(void_type_idx)
ovoid_type = new_type(void_type_idx).set_flag(.option) // the return type of `fn ()?`
rvoid_type = new_type(void_type_idx).set_flag(.result) // the return type of `fn () !`
voidptr_type = new_type(voidptr_type_idx)
byteptr_type = new_type(byteptr_type_idx)
charptr_type = new_type(charptr_type_idx)
i8_type = new_type(i8_type_idx)
int_type = new_type(int_type_idx)
i16_type = new_type(i16_type_idx)
i64_type = new_type(i64_type_idx)
isize_type = new_type(isize_type_idx)
u8_type = new_type(u8_type_idx)
u16_type = new_type(u16_type_idx)
u32_type = new_type(u32_type_idx)
u64_type = new_type(u64_type_idx)
usize_type = new_type(usize_type_idx)
f32_type = new_type(f32_type_idx)
f64_type = new_type(f64_type_idx)
char_type = new_type(char_type_idx)
bool_type = new_type(bool_type_idx)
none_type = new_type(none_type_idx)
string_type = new_type(string_type_idx)
rune_type = new_type(rune_type_idx)
array_type = new_type(array_type_idx)
map_type = new_type(map_type_idx)
chan_type = new_type(chan_type_idx)
any_type = new_type(any_type_idx)
float_literal_type = new_type(float_literal_type_idx)
int_literal_type = new_type(int_literal_type_idx)
thread_type = new_type(thread_type_idx)
error_type = new_type(error_type_idx)
charptr_types = new_charptr_types()
byteptr_types = new_byteptr_types()
voidptr_types = new_voidptr_types()
cptr_types = merge_types(voidptr_types, byteptr_types, charptr_types)
nil_type = new_type(nil_type_idx)
)
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
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
fn set_global_table #
fn set_global_table(t &Table)
fn type_can_start_with_token #
fn type_can_start_with_token(tok &token.Token) bool
fn ([]Attr) contains #
fn (attrs []Attr) contains(str 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
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
| i64
| i8
| int
| rune
| string
| u16
| u32
| u64
| u8
| voidptr
fn (ComptTimeConstValue) i8 #
fn (val ComptTimeConstValue) i8() ?i8
fn (ComptTimeConstValue) i16 #
fn (val ComptTimeConstValue) i16() ?i16
fn (ComptTimeConstValue) int #
fn (val ComptTimeConstValue) int() ?int
fn (ComptTimeConstValue) voidptr #
fn (val ComptTimeConstValue) voidptr() ?voidptr
fn (ComptTimeConstValue) i64 #
fn (val ComptTimeConstValue) i64() ?i64
fn (ComptTimeConstValue) u8 #
fn (val ComptTimeConstValue) u8() ?u8
fn (ComptTimeConstValue) u16 #
fn (val ComptTimeConstValue) u16() ?u16
fn (ComptTimeConstValue) u32 #
fn (val ComptTimeConstValue) u32() ?u32
fn (ComptTimeConstValue) u64 #
fn (val ComptTimeConstValue) u64() ?u64
fn (ComptTimeConstValue) f32 #
fn (val ComptTimeConstValue) f32() ?f32
fn (ComptTimeConstValue) f64 #
fn (val ComptTimeConstValue) f64() ?f64
fn (ComptTimeConstValue) string #
fn (val ComptTimeConstValue) string() ?string
type EmptyExpr #
type EmptyExpr = u8
type Expr #
type Expr = 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
| Likely
| LockExpr
| MapInit
| MatchExpr
| Nil
| NodeError
| None
| OffsetOf
| OrExpr
| ParExpr
| PostfixExpr
| PrefixExpr
| RangeExpr
| SelectExpr
| SelectorExpr
| SizeOf
| SpawnExpr
| SqlExpr
| StringInterLiteral
| StringLiteral
| StructInit
| TypeNode
| TypeOf
| UnsafeExpr
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) 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
| DeferStmt
| EmptyStmt
| EnumDecl
| ExprStmt
| FnDecl
| ForCStmt
| ForInStmt
| ForStmt
| GlobalDecl
| GotoLabel
| GotoStmt
| HashStmt
| Import
| InterfaceDecl
| Module
| NodeError
| Return
| SqlStmt
| StructDecl
| TypeDecl
fn (Stmt) str #
fn (node Stmt) str() string
type Type #
type Type = int
fn (Type) atomic_typename #
fn (t Type) atomic_typename() string
<atomic.h> defines special typenames
fn (Type) idx #
fn (t Type) idx() int
return TypeSymbol idx for t
fn (Type) is_void #
fn (t Type) is_void() bool
fn (Type) is_full #
fn (t Type) is_full() bool
fn (Type) nr_muls #
fn (t Type) nr_muls() int
return nr_muls for t
fn (Type) is_ptr #
fn (t Type) is_ptr() bool
return true if t
is a pointer (nr_muls>0)
fn (Type) is_any_kind_of_pointer #
fn (t Type) is_any_kind_of_pointer() bool
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) set_flag #
fn (t Type) set_flag(flag TypeFlag) Type
set flag
on t
and return t
fn (Type) clear_flag #
fn (t Type) clear_flag(flag TypeFlag) Type
clear flag
on t
and return t
fn (Type) clear_flags #
fn (t Type) clear_flags(flags ...TypeFlag) Type
clear all flags or multi flags
fn (Type) has_flag #
fn (t Type) has_flag(flag TypeFlag) bool
return true if flag
is set on t
fn (Type) str #
fn (t Type) str() string
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) is_pointer #
fn (typ Type) is_pointer() bool
fn (Type) is_voidptr #
fn (typ Type) is_voidptr() bool
fn (Type) is_real_pointer #
fn (typ Type) is_real_pointer() bool
fn (Type) is_float #
fn (typ Type) is_float() bool
fn (Type) is_int #
fn (typ Type) is_int() bool
fn (Type) is_int_valptr #
fn (typ Type) is_int_valptr() bool
fn (Type) is_float_valptr #
fn (typ Type) is_float_valptr() bool
fn (Type) is_pure_int #
fn (typ Type) is_pure_int() bool
fn (Type) is_pure_float #
fn (typ Type) is_pure_float() bool
fn (Type) is_signed #
fn (typ Type) is_signed() bool
fn (Type) is_unsigned #
fn (typ Type) is_unsigned() bool
fn (Type) flip_signedness #
fn (typ Type) flip_signedness() Type
fn (Type) is_int_literal #
fn (typ Type) is_int_literal() bool
fn (Type) is_number #
fn (typ Type) is_number() bool
fn (Type) is_string #
fn (typ Type) is_string() bool
fn (Type) is_bool #
fn (typ Type) is_bool() bool
type TypeDecl #
type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl
type TypeInfo #
type TypeInfo = Aggregate
| Alias
| Array
| ArrayFixed
| Chan
| Enum
| FnType
| GenericInst
| Interface
| Map
| MultiReturn
| Struct
| SumType
| Thread
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
}
adressing 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
}
fn (ComptimeForKind) str #
fn (e ComptimeForKind) str() string
enum ComptimeTypeKind #
enum ComptimeTypeKind {
map_
int
float
struct_
iface
array
sum_type
enum_
alias
function
option
}
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
}
enum GenericKindField #
enum GenericKindField {
unknown
name
typ
}
enum IdentKind #
enum IdentKind {
unresolved
blank_ident
variable
constant
global
function
}
enum Kind #
enum Kind {
placeholder
void
voidptr
byteptr
charptr
i8
i16
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 SqlStmtKind #
enum SqlStmtKind {
insert
update
delete
create
drop
}
enum StructInitKind #
enum StructInitKind {
normal
short_syntax
anon
}
enum TypeFlag #
enum TypeFlag {
option
result
variadic
generic
shared_f
atomic_f
}
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 #
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 // has been generated
}
anonymous function
fn (AnonFn) stringify #
fn (node &AnonFn) stringify(t &Table, cur_mod string, m2a map[string]string) string
These methods are used only by vfmt, vdoc, and for debugging.
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 #
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
}
struct ArrayInit #
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_default 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
default_expr Expr // init: expr
expr_types []Type // [Dog, Cat] // also used for interface_types
elem_type Type // element type
default_type Type // default value type
typ Type // array 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
expr Expr // (a)
comments []Comment // // this is a comment
typ Type
pos token.Pos
}
: [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 #
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 #
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 #
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 #
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
comments []Comment
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
}
variable assign statement
struct Assoc #
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 #
struct Attr {
pub:
name string // [name]
has_arg bool
arg string // [name: arg]
kind AttrKind
ct_expr Expr // .kind == comptime_define, for [if !name]
ct_opt bool // true for [if user_defined_name?]
pos token.Pos
pub mut:
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:
stmts []Stmt
is_unsafe bool
pos token.Pos
}
{stmts}
or unsafe {stmts}
struct BoolLiteral #
struct BoolLiteral {
pub:
val bool
pos token.Pos
}
struct BranchStmt #
struct BranchStmt {
pub:
kind token.Kind
label string
pos token.Pos
}
break, continue
fn (BranchStmt) str #
fn (node &BranchStmt) str() string
struct CallArg #
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
// tmp_name string // for autofree
}
function call argument: f(callarg)
fn (CallArg) str #
fn (a CallArg) str() string
struct CallExpr #
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]`
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
return_type Type
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
}
function or method call expr
fn (CallExpr) fkey #
fn (node &CallExpr) fkey() string
struct CastExpr #
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
is_inline bool // true for all /* comment */ comments
pos token.Pos
}
struct ComptimeCall #
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 }
left Expr
is_vweb bool
vweb_tmpl File
is_embed bool
is_env bool
env_pos token.Pos
is_pkgconfig bool
or_block OrExpr
pub mut:
left_type Type
result_type Type
env_value string
args_var string
args []CallArg
embed_file EmbeddedFile
}
struct ComptimeFor #
struct ComptimeFor {
pub:
val_var string
stmts []Stmt
kind ComptimeForKind
pos token.Pos
typ_pos token.Pos
pub mut:
typ Type
}
struct ComptimeSelector #
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 #
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 explict `[markused]` tag; the const will NOT be removed by `-skip-unused`, no matter what
pos token.Pos
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 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 DeferStmt #
struct DeferStmt {
pub:
stmts []Stmt
pos token.Pos
pub mut:
defer_vars []Ident
ifdef string
idx_in_fn int = -1 // index in FnDecl.defer_stmts
}
TODO: handle this differently v1 excludes non current os ifdefs so the defer's never get added in the first place
struct DumpExpr #
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 #
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 #
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
pos token.Pos
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
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 #
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 implicitely 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
}
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 #
fn (f &File) free()
struct FloatLiteral #
struct FloatLiteral {
pub:
val string
pos token.Pos
}
struct Fn #
struct Fn {
pub:
is_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)
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
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]
}
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 #
struct FnDecl {
pub:
name string // 'math.bits.normalize'
short_name string // 'normalize'
mod string // 'math.bits'
is_deprecated bool
is_pub 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 explict `[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
method_type_pos token.Pos // `User` in ` fn (u User)` position
method_idx int
rec_mut bool // is receiver mutable
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
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
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
}
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) 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
fn (FnDecl) stringify #
fn (node &FnDecl) stringify(t &Table, cur_mod string, m2a map[string]string) string
struct FnSignatureOpts #
struct FnSignatureOpts {
skip_receiver bool
type_only 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 #
struct ForInStmt {
pub:
key_var string
val_var string
is_range bool
high Expr // `10` in `for i in 0..10 {`
stmts []Stmt
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_type Type
kind Kind // array/map/string
label string // `label: for {`
scope &Scope = unsafe { nil }
}
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 #
struct GetEmbedsOptions {
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 #
struct GlobalField {
pub:
name string
has_expr bool
pos token.Pos
typ_pos token.Pos
is_markused bool // an explict `[markused]` tag; the global will NOT be removed by `-skip-unused`
is_volatile bool
pub mut:
expr Expr
typ Type
comments []Comment
}
struct GoExpr #
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 #
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
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) 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 #
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.obj instead 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 #
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:
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 #
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
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 #
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 = ast.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 #
struct Interface {
pub mut:
types []Type // all types that implement this interface
fields []StructField
methods []Fn
embeds []Type
// `I1 is I2` conversions
conversions 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
struct InterfaceDecl #
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 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 #
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
}
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 #
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 #
struct OffsetOf {
pub:
struct_type Type
field string
pos token.Pos
}
struct OrExpr #
struct OrExpr {
pub:
stmts []Stmt
kind OrKind
pos token.Pos
}
or { ... }
struct Param #
struct Param {
pub:
pos token.Pos
name string
is_mut bool
is_shared bool
is_atomic bool
is_auto_rec bool
type_pos token.Pos
is_hidden bool // interface first arg
pub mut:
typ Type
}
fn (Param) specifier #
fn (p &Param) specifier() string
struct ParExpr #
struct ParExpr {
pub:
pos token.Pos
pub mut:
expr Expr
}
(3+4)
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 #
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 #
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 #
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 #
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) 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) contains #
fn (s &Scope) contains(pos int) bool
fn (Scope) has_inherited_vars #
fn (s &Scope) has_inherited_vars() bool
fn (Scope) show #
fn (sc Scope) show(depth int, max_depth int) string
fn (Scope) str #
fn (sc Scope) str() string
struct ScopeStructField #
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 #
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 #
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
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 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 #
struct SpawnExpr {
pub:
pos token.Pos
pub mut:
call_expr CallExpr
is_expr bool
}
struct SqlExpr #
struct SqlExpr {
pub:
is_count bool
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
or_expr OrExpr
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
}
struct SqlStmt #
struct SqlStmt {
pub:
db_expr Expr // `db` in `sql db {`
or_expr OrExpr
pos token.Pos
pub mut:
lines []SqlStmtLine
db_expr_type Type // the type of the `db` in `sql db {`
}
struct SqlStmtLine #
struct SqlStmtLine {
pub:
kind SqlStmtKind
pos token.Pos
where_expr Expr
update_exprs []Expr // for `update`
// 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_name string // `user`
updated_columns []string // for `update set x=y`
table_expr TypeNode
fields []StructField
sub_structs map[int]SqlStmtLine
}
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 #
struct StringLiteral {
pub:
val string
is_raw bool
language Language
pos token.Pos
}
struct Struct #
struct Struct {
pub:
attrs []Attr
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
generic_types []Type
concrete_types []Type
parent_type Type
}
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 #
struct StructDecl {
pub:
pos token.Pos
name string
generic_types []Type
is_pub bool
// _pos fields for vfmt
mut_pos int // mut:
pub_pos int // pub:
pub_mut_pos int // pub mut:
global_pos int // __global:
module_pos int // module:
language Language
is_union bool
attrs []Attr
end_comments []Comment
embeds []Embed
pub mut:
fields []StructField
}
struct StructField #
struct StructField {
pub:
pos token.Pos
type_pos token.Pos
option_pos token.Pos
comments []Comment
i int
has_default_expr bool
attrs []Attr
is_pub bool
default_val string
is_mut bool
is_global bool
is_volatile bool
is_deprecated bool
pub mut:
is_recursive bool
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 #
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`
fields []StructInitField
generic_types []Type
}
s := Foo{ ...a field1: 'hello' }
struct StructInitField #
struct StructInitField {
pub:
pos token.Pos
name_pos token.Pos
comments []Comment
next_comments []Comment
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 #
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_field #
fn (s &SumType) find_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 #
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
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_vweb_types []Type // vweb context types, filled in by checker, when pref.skip_unused = true;
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_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) 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) 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 int value from the enum name and enum field
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_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_idx #
fn (t &Table) find_type_idx(name string) int
fn (Table) fn_signature #
fn (t &Table) fn_signature(func &Fn, opts FnSignatureOpts) string
fn (Table) fn_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 #
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_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_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_type_name #
fn (t &Table) get_type_name(typ Type) string
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 childs that are references
fn (Table) has_method #
fn (t &Table) has_method(s &TypeSymbol, name string) bool
fn (Table) is_comptime_type #
fn (t &Table) is_comptime_type(x Type, y ComptimeType) 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_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(sym_ &TypeSymbol)
fn (Table) resolve_generic_to_concrete #
fn (mut t Table) resolve_generic_to_concrete(generic_type Type, generic_names []string, concrete_types []Type) ?Type
resolve_generic_to_concrete resolves generics to real types T => int.
Even map[string]map[string]T can be resolved.
This is used for resolving the generic return type of CallExpr white unwrap_generic
is used to resolve generic usage in FnDecl.
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) 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 pointer so 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
returns TypeSymbol kind only if there are no type modifiers
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 (mytable &Table) type_to_code(t 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) 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
end_comments []Comment // comments that after current type node
}
struct TypeOf #
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 #
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
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 intoTable.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
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) 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_bool #
fn (t &TypeSymbol) is_bool() bool
fn (TypeSymbol) is_builtin #
fn (t &TypeSymbol) is_builtin() 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) register_method #
fn (mut t TypeSymbol) register_method(new_fn Fn) int
fn (TypeSymbol) str #
fn (t TypeSymbol) str() string
fn (TypeSymbol) str_method_info #
fn (t &TypeSymbol) str_method_info() (bool, bool, int)
fn (TypeSymbol) struct_info #
fn (t &TypeSymbol) struct_info() Struct
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. For example, main.Abc[int]
-> main.Abc
fn (TypeSymbol) thread_info #
fn (t &TypeSymbol) thread_info() Thread
struct UnsafeExpr #
struct UnsafeExpr {
pub:
pos token.Pos
pub mut:
expr Expr
}
struct Var #
struct Var {
pub:
name string
share ShareType
is_mut bool
is_autofree_tmp bool
is_arg bool // fn args should not be autofreed
is_auto_deref bool
is_inherited bool
has_inherited bool
pub mut:
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 whoes address goes out of scope
is_stack_obj bool // may be pointer to stack value (`mut` or `&` arg and not [heap] struct)
}
- Constants
- fn all_registers
- fn args2str
- fn empty_comptime_const_expr
- fn merge_types
- fn mktyp
- fn new_table
- fn new_type
- fn new_type_ptr
- fn pref_arch_to_table_language
- fn set_global_table
- fn sharetype_from_flags
- fn type_can_start_with_token
- type []Attr
- type []Kind
- type AsmArg
- type ComptTimeConstValue
- type EmptyExpr
- type Expr
- type FnPanicHandler
- type IdentInfo
- type Node
- type ScopeObject
- type Stmt
- type Type
- fn atomic_typename
- fn share
- fn idx
- fn is_void
- fn is_full
- fn nr_muls
- fn is_ptr
- fn is_any_kind_of_pointer
- fn set_nr_muls
- fn ref
- fn deref
- fn set_flag
- fn clear_flag
- fn clear_flags
- fn has_flag
- fn str
- fn debug
- fn derive
- fn derive_add_muls
- fn is_pointer
- fn is_voidptr
- fn is_real_pointer
- fn is_float
- fn is_int
- fn is_int_valptr
- fn is_float_valptr
- fn is_pure_int
- fn is_pure_float
- fn is_signed
- fn is_unsigned
- fn flip_signedness
- fn is_int_literal
- fn is_number
- fn is_string
- fn is_bool
- type TypeDecl
- type TypeInfo
- enum AddressingMode
- enum AttrKind
- enum ComptimeForKind
- enum ComptimeTypeKind
- enum ComptimeVarKind
- enum GenericKindField
- enum IdentKind
- enum Kind
- enum Language
- enum OrKind
- enum ShareType
- enum SqlStmtKind
- enum StructInitKind
- enum TypeFlag
- struct Aggregate
- struct Alias
- struct AliasTypeDecl
- struct AnonFn
- struct Array
- struct ArrayDecompose
- struct ArrayFixed
- struct ArrayInit
- struct AsCast
- struct AsmAddressing
- struct AsmAlias
- struct AsmClobbered
- struct AsmDisp
- struct AsmIO
- struct AsmRegister
- struct AsmStmt
- struct AsmTemplate
- struct AssertStmt
- struct AssignStmt
- struct Assoc
- struct AtExpr
- struct Attr
- struct Block
- struct BoolLiteral
- struct BranchStmt
- struct CallArg
- struct CallExpr
- struct CastExpr
- struct Chan
- struct ChanInit
- struct CharLiteral
- struct Comment
- struct ComptimeCall
- struct ComptimeFor
- struct ComptimeSelector
- struct ComptimeType
- struct ConcatExpr
- struct ConstDecl
- struct ConstField
- struct CTempVar
- struct DeferStmt
- struct DumpExpr
- struct Embed
- struct EmbeddedFile
- struct EmptyNode
- struct EmptyStmt
- struct Enum
- struct EnumDecl
- struct EnumField
- struct EnumVal
- struct ExprStmt
- struct File
- struct FloatLiteral
- struct Fn
- struct FnDecl
- struct FnSignatureOpts
- struct FnType
- struct FnTypeDecl
- struct ForCStmt
- struct ForInStmt
- struct ForStmt
- struct GenericInst
- struct GetEmbedsOptions
- struct GlobalDecl
- struct GlobalField
- struct GoExpr
- struct GotoLabel
- struct GotoStmt
- struct HashStmt
- struct Ident
- struct IdentFn
- struct IdentVar
- struct IfBranch
- struct IfExpr
- struct IfGuardExpr
- struct IfGuardVar
- struct Import
- struct ImportSymbol
- struct IndexExpr
- struct InfixExpr
- struct IntegerLiteral
- struct Interface
- struct InterfaceDecl
- struct InterfaceEmbedding
- struct IsRefType
- struct Likely
- struct LockExpr
- struct Map
- struct MapInit
- struct MatchBranch
- struct MatchExpr
- struct Module
- struct MultiReturn
- struct Nil
- struct NodeError
- struct None
- struct OffsetOf
- struct OrExpr
- struct Param
- struct ParExpr
- struct PostfixExpr
- struct PrefixExpr
- struct RangeExpr
- struct Return
- struct Scope
- struct ScopeStructField
- struct SelectBranch
- struct SelectExpr
- struct SelectorExpr
- struct SizeOf
- struct SpawnExpr
- struct SqlExpr
- struct SqlStmt
- struct SqlStmtLine
- struct StringInterLiteral
- struct StringLiteral
- struct Struct
- struct StructDecl
- struct StructField
- struct StructInit
- struct StructInitField
- struct SumType
- struct SumTypeDecl
- struct Table
- fn add_placeholder_type
- fn array_cname
- fn array_fixed_cname
- fn array_fixed_name
- fn array_name
- fn bitsize_to_type
- fn chan_cname
- fn chan_name
- fn clean_generics_type_str
- fn complete_interface_check
- fn dependent_names_in_expr
- fn dependent_names_in_stmt
- fn does_type_implement_interface
- fn final_sym
- fn find_enum_field_val
- fn find_field
- fn find_field_from_embeds
- fn find_field_with_embeds
- fn find_fn
- fn find_method
- fn find_method_from_embeds
- fn find_method_with_embeds
- fn find_or_register_array
- fn find_or_register_array_fixed
- fn find_or_register_array_with_dims
- fn find_or_register_chan
- fn find_or_register_fn_type
- fn find_or_register_map
- fn find_or_register_multi_return
- fn find_or_register_promise
- fn find_or_register_thread
- fn find_sym
- fn find_sym_and_type_idx
- fn find_type_idx
- fn fn_signature
- fn fn_signature_using_aliases
- fn fn_type_signature
- fn fn_type_source_signature
- fn free
- fn generic_insts_to_concrete
- fn generic_type_names
- fn get_embed_methods
- fn get_embeds
- fn get_final_type_name
- fn get_generic_names
- fn get_type_name
- fn has_cflag
- fn has_deep_child_no_ref
- fn has_method
- fn is_comptime_type
- fn is_same_method
- fn is_sumtype_or_in_variant
- fn known_fn
- fn known_type
- fn known_type_idx
- fn known_type_names
- fn map_cname
- fn map_name
- fn panic
- fn parse_cflag
- fn promise_cname
- fn promise_name
- fn register_aggregate_method
- fn register_anon_struct
- fn register_builtin_type_symbols
- fn register_enum_decl
- fn register_fn
- fn register_fn_concrete_types
- fn register_fn_generic_types
- fn register_interface
- fn register_sym
- fn reset_parsing_type
- fn resolve_common_sumtype_fields
- fn resolve_generic_to_concrete
- fn resolve_init
- fn start_parsing_type
- fn struct_fields
- fn struct_has_field
- fn sumtype_has_variant
- fn sym
- fn sym_by_idx
- fn thread_cname
- fn thread_name
- fn type_is_for_pointer_arithmetic
- fn type_kind
- fn type_size
- fn type_str
- fn type_to_code
- fn type_to_str
- fn type_to_str_using_aliases
- fn unalias_num_type
- fn unaliased_type
- fn unwrap_generic_type
- fn value_type
- struct Thread
- struct TypeNode
- struct TypeOf
- struct TypeSymbol
- fn array_fixed_info
- fn array_info
- fn chan_info
- fn dbg
- fn debug
- fn embed_name
- fn enum_info
- fn find_field
- fn find_method
- fn find_method_with_generic_parent
- fn has_field
- fn has_method
- fn has_method_with_generic_parent
- fn is_bool
- fn is_builtin
- fn is_float
- fn is_heap
- fn is_int
- fn is_js_compatible
- fn is_number
- fn is_pointer
- fn is_primitive
- fn is_string
- fn map_info
- fn mr_info
- fn register_method
- fn str
- fn str_method_info
- fn struct_info
- fn sumtype_info
- fn symbol_name_except_generic
- fn thread_info
- struct UnsafeExpr
- struct Var