const (
x86_no_number_register_list = map{
8: ['al', 'ah', 'bl', 'bh', 'cl', 'ch', 'dl', 'dh', 'bpl', 'sil', 'dil', 'spl']
16: ['ax', 'bx', 'cx', 'dx', 'bp', 'si', 'di', 'sp', 'cs', 'ss', 'ds', 'es', 'fs', 'gs',
'flags', 'ip', 'gdtr', 'idtr', 'tr', 'ldtr', 'fp_cs', 'fp_ds', 'fp_opc']
32: [
'eax',
'ebx',
'ecx',
'edx',
'ebp',
'esi',
'edi',
'esp',
'eflags',
'eip',
'mxcsr',
]
64: ['rax', 'rbx', 'rcx', 'rdx', 'rbp', 'rsi', 'rdi', 'rsp', 'rflags', 'rip']
}
x86_with_number_register_list = map{
8: map{
'r#b': 16
}
16: map{
'r#w': 16
}
32: map{
'r#d': 16
}
64: map{
'r#': 16
'mm#': 16
'cr#': 16
'dr#': 16
}
80: map{
'st#': 16
}
128: map{
'xmm#': 32
}
256: map{
'ymm#': 32
}
512: map{
'zmm#': 32
}
}
)
const (
arm_no_number_register_list = ['fp', 'ip', 'sp', 'lr', 'pc']
arm_with_number_register_list = map{
'r#': 16
}
)
TODO: saved priviled registers for arm
const (
riscv_no_number_register_list = ['zero', 'ra', 'sp', 'gp', 'tp']
riscv_with_number_register_list = map{
'x#': 32
't#': 3
's#': 12
'a#': 8
}
)
const (
void_type_idx = 1
voidptr_type_idx = 2
byteptr_type_idx = 3
charptr_type_idx = 4
i8_type_idx = 5
i16_type_idx = 6
int_type_idx = 7
i64_type_idx = 8
byte_type_idx = 9
u16_type_idx = 10
u32_type_idx = 11
u64_type_idx = 12
f32_type_idx = 13
f64_type_idx = 14
char_type_idx = 15
bool_type_idx = 16
none_type_idx = 17
string_type_idx = 18
ustring_type_idx = 19
rune_type_idx = 20
array_type_idx = 21
map_type_idx = 22
chan_type_idx = 23
size_t_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
)
const (
integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx,
byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, int_literal_type_idx, rune_type_idx]
signed_integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx]
unsigned_integer_type_idxs = [byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx]
float_type_idxs = [f32_type_idx, f64_type_idx, float_literal_type_idx]
number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx,
byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx, f32_type_idx, f64_type_idx,
int_literal_type_idx, float_literal_type_idx, rune_type_idx]
pointer_type_idxs = [voidptr_type_idx, byteptr_type_idx, charptr_type_idx]
string_type_idxs = [string_type_idx, ustring_type_idx]
)
const (
void_type = new_type(void_type_idx)
ovoid_type = new_type(void_type_idx).set_flag(.optional)
voidptr_type = new_type(voidptr_type_idx)
byteptr_type = new_type(byteptr_type_idx)
charptr_type = new_type(charptr_type_idx)
i8_type = new_type(i8_type_idx)
int_type = new_type(int_type_idx)
i16_type = new_type(i16_type_idx)
i64_type = new_type(i64_type_idx)
byte_type = new_type(byte_type_idx)
u16_type = new_type(u16_type_idx)
u32_type = new_type(u32_type_idx)
u64_type = new_type(u64_type_idx)
f32_type = new_type(f32_type_idx)
f64_type = new_type(f64_type_idx)
char_type = new_type(char_type_idx)
bool_type = new_type(bool_type_idx)
none_type = new_type(none_type_idx)
string_type = new_type(string_type_idx)
ustring_type = new_type(ustring_type_idx)
rune_type = new_type(rune_type_idx)
array_type = new_type(array_type_idx)
map_type = new_type(map_type_idx)
chan_type = new_type(chan_type_idx)
any_type = new_type(any_type_idx)
float_literal_type = new_type(float_literal_type_idx)
int_literal_type = new_type(int_literal_type_idx)
thread_type = new_type(thread_type_idx)
error_type = new_type(error_type_idx)
charptr_types = [charptr_type, new_type(char_type_idx).set_nr_muls(1)]
byteptr_types = [byteptr_type, new_type(byte_type_idx).set_nr_muls(1)]
)
const (
builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16',
'u32', 'u64', 'int_literal', 'f32', 'f64', 'float_literal', 'string', 'ustring', 'char',
'byte', 'bool', 'none', 'array', 'array_fixed', 'map', 'chan', 'any', 'struct', 'mapnode',
'size_t', 'rune', 'thread', 'Error']
)
fn all_registers(mut t Table, arch pref.Arch) map[string]ScopeObject
return all the registers for a give architecture
fn args2str(args []CallArg) string
fn empty_expr() Expr
fn empty_node() Node
fn empty_stmt() Stmt
fn new_scope(parent &Scope, start_pos int) &Scope
fn new_table() &Table
fn new_type(idx int) Type
return new type with TypeSymbol idx set to idx
fn new_type_ptr(idx int, nr_muls int) Type
return new type with TypeSymbol idx set to idx
& nr_muls set to nr_muls
fn pref_arch_to_table_language(pref_arch pref.Arch) Language
fn resolve_init(node StructInit, typ Type, t &Table) Expr
fn (attrs []Attr) contains(str string) bool
fn (attrs []Attr) has_comptime_define() (bool, string)
fn (kinds []Kind) str() string
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 Expr = AnonFn | ArrayDecompose | ArrayInit | AsCast | Assoc | AtExpr | BoolLiteral |
CTempVar | CallExpr | CastExpr | ChanInit | CharLiteral | Comment | ComptimeCall |
ComptimeSelector | ConcatExpr | DumpExpr | EmptyExpr | EnumVal | FloatLiteral | GoExpr |
Ident | IfExpr | IfGuardExpr | IndexExpr | InfixExpr | IntegerLiteral | Likely | LockExpr |
MapInit | MatchExpr | NodeError | None | OffsetOf | OrExpr | ParExpr | PostfixExpr |
PrefixExpr | RangeExpr | SelectExpr | SelectorExpr | SizeOf | SqlExpr | StringInterLiteral |
StringLiteral | StructInit | TypeNode | TypeOf | UnsafeExpr
fn (expr Expr) is_auto_deref_var() bool
fn (expr Expr) is_blank_ident() bool
fn (expr Expr) is_expr() bool
fn (expr Expr) is_lit() bool
fn (expr Expr) is_lvalue() bool
fn (expr Expr) position() token.Position
fn (x Expr) str() string
string representation of expr
type IdentInfo = IdentFn | IdentVar
type Node = CallArg | ConstField | EmptyNode | EnumField | Expr | File | GlobalField |
IfBranch | MatchBranch | NodeError | Param | ScopeObject | SelectBranch | Stmt | StructField |
StructInitField | SumTypeVariant
TODO: replace Param
fn (node Node) position() token.Position
fn (node Node) children() []Node
type ScopeObject = AsmRegister | ConstField | GlobalField | Var
NB: when you add a new Expr or Stmt type with a .pos field, remember to update the .position() token.Position methods too.
type Stmt = AsmStmt | AssertStmt | AssignStmt | Block | BranchStmt | CompFor | ConstDecl |
DeferStmt | EmptyStmt | EnumDecl | ExprStmt | FnDecl | ForCStmt | ForInStmt | ForStmt |
GlobalDecl | GotoLabel | GotoStmt | HashStmt | Import | InterfaceDecl | Module | NodeError |
Return | SqlStmt | StructDecl | TypeDecl
fn (stmt Stmt) check_c_expr() ?
check if stmt can be an expression in C
fn (node Stmt) str() string
type Type = int
fn (t Type) atomic_typename() string
<atomic.h> defines special typenames
fn (t Type) idx() int
return TypeSymbol idx for t
fn (t Type) is_void() bool
fn (t Type) is_full() bool
fn (t Type) nr_muls() int
return nr_muls for t
fn (t Type) is_ptr() bool
return true if t
is a pointer (nr_muls>0)
fn (t Type) set_nr_muls(nr_muls int) Type
set nr_muls on t
and return it
fn (t Type) to_ptr() Type
increments nr_nuls on t
and return it
fn (t Type) deref() Type
decrement nr_muls on t
and return it
fn (t Type) set_flag(flag TypeFlag) Type
set flag
on t
and return t
fn (t Type) clear_flag(flag TypeFlag) Type
clear flag
on t
and return t
fn (t Type) clear_flags() Type
clear all flags
fn (t Type) has_flag(flag TypeFlag) bool
return true if flag
is set on t
fn (t Type) debug() []string
fn (t Type) derive(t_from Type) Type
copy flags & nr_muls from t_from
to t
and return t
fn (typ Type) is_pointer() bool
fn (typ Type) is_float() bool
fn (typ Type) is_int() bool
fn (typ Type) is_int_valptr() bool
fn (typ Type) is_float_valptr() bool
fn (typ Type) is_pure_int() bool
fn (typ Type) is_pure_float() bool
fn (typ Type) is_signed() bool
fn (typ Type) is_unsigned() bool
fn (typ Type) is_int_literal() bool
fn (typ Type) is_number() bool
fn (typ Type) is_number_or_literal() bool
fn (typ Type) is_string() bool
type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl
type TypeInfo = Aggregate | Alias | Array | ArrayFixed | Chan | Enum | FnType | GenericStructInst |
Interface | Map | MultiReturn | Struct | SumType | Thread
enum AddressingMode {
invalid
displacement
base
base_plus_displacement
index_times_scale_plus_displacement
base_plus_index_plus_displacement
base_plus_index_times_scale_plus_displacement
rip_plus_displacement
}
adressing modes:
enum CompForKind {
methods
fields
}
fn (e CompForKind) str() string
enum IdentKind {
unresolved
blank_ident
variable
constant
global
function
}
enum Kind {
placeholder
void
voidptr
byteptr
charptr
i8
i16
int
i64
byte
u16
u32
u64
f32
f64
char
size_t
rune
bool
none_
string
ustring
array
array_fixed
map
chan
any
struct_
generic_struct_inst
multi_return
sum_type
alias
enum_
function
interface_
float_literal
int_literal
aggregate
thread
}
fn (k Kind) str() string
for debugging/errors only, perf is not an issue
enum Language {
v
c
js
amd64
i386
aarch64
aarch32
rv64
rv32
}
enum OrKind {
absent
block
propagate
}
enum SqlStmtKind {
insert
update
delete
create
drop
}
enum TypeFlag {
optional
variadic
generic
shared_f
atomic_f
}
max of 8
struct Aggregate {
mut:
fields []StructField
pub:
types []Type
}
struct Alias {
pub:
parent_type Type
language Language
is_import bool
}
struct AliasTypeDecl {
pub:
name string
is_pub bool
parent_type Type
pos token.Position
type_pos token.Position
comments []Comment
}
struct AnonFn {
pub mut:
decl FnDecl
typ Type
has_gen bool
}
anonymous function
struct Array {
pub:
nr_dims int
pub mut:
elem_type Type
}
struct ArrayDecompose {
pub:
expr Expr
pos token.Position
pub mut:
expr_type Type
arg_type Type
}
struct ArrayFixed {
pub:
size int
pub mut:
elem_type Type
}
struct ArrayInit {
pub:
pos token.Position
elem_type_pos token.Position
exprs []Expr
ecmnts [][]Comment
pre_cmnts []Comment
is_fixed bool
has_val bool
mod string
len_expr Expr
cap_expr Expr
default_expr Expr
has_len bool
has_cap bool
has_default bool
pub mut:
expr_types []Type
elem_type Type
typ Type
}
struct AsCast {
pub:
expr Expr
typ Type
pos token.Position
pub mut:
expr_type Type
}
struct AsmAddressing {
pub:
scale int = -1
mode AddressingMode
pos token.Position
pub mut:
displacement AsmArg
base AsmArg
index AsmArg
}
struct AsmAlias {
pub:
name string
pos token.Position
}
struct AsmClobbered {
pub mut:
reg AsmRegister
comments []Comment
}
struct AsmDisp {
pub:
val string
pos token.Position
}
struct AsmIO {
pub:
alias string
constraint string
expr Expr
comments []Comment
typ Type
pos token.Position
}
: [alias_a] '=r' (a) // this is a comment
struct AsmRegister {
pub:
name string
mut:
typ Type
size int
}
struct AsmStmt {
pub:
arch pref.Arch
is_top_level bool
is_volatile bool
is_goto bool
clobbered []AsmClobbered
pos token.Position
pub mut:
templates []AsmTemplate
scope &Scope
output []AsmIO
input []AsmIO
global_labels []string
local_labels []string
}
struct AsmTemplate {
pub mut:
name string
is_label bool
is_directive bool
args []AsmArg
comments []Comment
pos token.Position
}
struct AssertStmt {
pub:
pos token.Position
pub mut:
expr Expr
is_used bool
}
struct AssignStmt {
pub:
op token.Kind
pos token.Position
comments []Comment
end_comments []Comment
pub mut:
right []Expr
left []Expr
left_types []Type
right_types []Type
is_static bool
is_simple bool
has_cross_var bool
}
variable assign statement
struct Assoc {
pub:
var_name string
fields []string
exprs []Expr
pos token.Position
pub mut:
typ Type
scope &Scope
}
deprecated
struct AtExpr {
pub:
name string
pos token.Position
kind token.AtKind
pub mut:
val string
}
@FN, @STRUCT, @MOD etc. See full list in token.valid_at_tokens
struct Attr {
pub:
name string
is_string bool
is_comptime_define bool
arg string
is_string_arg bool
pos token.Position
}
e.g. [unsafe]
fn (attr Attr) str() string
no square brackets
struct Block {
pub:
stmts []Stmt
is_unsafe bool
pos token.Position
}
{stmts}
or unsafe {stmts}
struct BoolLiteral {
pub:
val bool
pos token.Position
}
struct BranchStmt {
pub:
kind token.Kind
label string
pos token.Position
}
break, continue
fn (node &BranchStmt) str() string
struct CallArg {
pub:
is_mut bool
share ShareType
expr Expr
comments []Comment
pub mut:
typ Type
is_tmp_autofree bool
pos token.Position
}
function call argument: f(callarg)
fn (a CallArg) str() string
struct CallExpr {
pub:
pos token.Position
name_pos token.Position
mod string
pub mut:
name string
is_method bool
is_field bool
is_keep_alive bool
args []CallArg
expected_arg_types []Type
language Language
or_block OrExpr
left Expr
left_type Type
receiver_type Type
return_type Type
should_be_skipped bool
generic_types []Type
generic_list_pos token.Position
free_receiver bool
scope &Scope
from_embed_type Type
comments []Comment
}
function or method call expr
struct CastExpr {
pub:
expr Expr
arg Expr
typ Type
pos token.Position
pub mut:
typname string
expr_type Type
has_arg bool
in_prexpr bool
}
NB: &string(x) gets parsed as PrefixExpr{ right: CastExpr{...} } TODO: that is very likely a parsing bug. It should get parsed as just CastExpr{...}, where .typname is '&string' instead. The current situation leads to special cases in vfmt and cgen (see prefix_expr_cast_expr in fmt.v, and .is_amp in cgen.v) .in_prexpr is also needed because of that, because the checker needs to show warnings about the deprecated C->V conversions string(x)
and string(x,y)
, while skipping the real pointer casts like &string(x)
.
struct Chan {
pub mut:
elem_type Type
is_mut bool
}
struct ChanInit {
pub:
pos token.Position
cap_expr Expr
has_cap bool
pub mut:
typ Type
elem_type Type
}
struct CharLiteral {
pub:
val string
pos token.Position
}
struct Comment {
pub:
text string
is_multi bool
line_nr int
pos token.Position
}
struct CompFor {
pub:
val_var string
stmts []Stmt
kind CompForKind
pos token.Position
typ_pos token.Position
pub mut:
typ Type
}
struct ComptimeCall {
pub:
pos token.Position
has_parens bool
method_name string
method_pos token.Position
scope &Scope
left Expr
args_var string
is_vweb bool
vweb_tmpl File
is_embed bool
embed_file EmbeddedFile
is_env bool
env_pos token.Position
pub mut:
sym TypeSymbol
result_type Type
env_value string
args []CallArg
}
struct ComptimeSelector {
pub:
has_parens bool
left Expr
field_expr Expr
pos token.Position
pub mut:
left_type Type
typ Type
}
struct ConcatExpr {
pub:
vals []Expr
pos token.Position
pub mut:
return_type Type
}
struct ConstDecl {
pub:
is_pub bool
pos token.Position
pub mut:
fields []ConstField
end_comments []Comment
is_block bool
}
const declaration
struct ConstField {
pub:
mod string
name string
expr Expr
is_pub bool
pos token.Position
pub mut:
typ Type
comments []Comment
}
const field in const declaration group
struct CTempVar {
pub:
name string
orig Expr
typ Type
is_ptr bool
}
CTempVar is used in cgen only, to hold nodes for temporary variables
struct DeferStmt {
pub:
stmts []Stmt
pos token.Position
pub mut:
ifdef string
idx_in_fn int = -1
}
TODO: handle this differently v1 excludes non current os ifdefs so the defer's never get added in the first place
struct DumpExpr {
pub:
expr Expr
pos token.Position
pub mut:
expr_type Type
cname string
}
struct Embed {
pub:
typ Type
pos token.Position
}
struct EmbeddedFile {
pub:
rpath string
apath string
}
struct EmptyExpr {
x int
}
struct EmptyNode {
x int
}
struct EmptyStmt {
pub:
pos token.Position
}
struct Enum {
pub:
vals []string
is_flag bool
is_multi_allowed bool
}
struct EnumDecl {
pub:
name string
is_pub bool
is_flag bool
is_multi_allowed bool
comments []Comment
fields []EnumField
attrs []Attr
pos token.Position
}
enum declaration
struct EnumField {
pub:
name string
pos token.Position
comments []Comment
next_comments []Comment
expr Expr
has_expr bool
}
enum field in enum declaration
struct EnumVal {
pub:
enum_name string
val string
mod string
pos token.Position
pub mut:
typ Type
}
an enum value, like OS.macos or .macos
struct ExprStmt {
pub:
expr Expr
pos token.Position
comments []Comment
pub mut:
is_expr bool
typ Type
}
| IncDecStmt k Stand-alone expression in a statement list.
struct File {
pub:
path string
path_base string
lines int
bytes int
mod Module
global_scope &Scope
is_test bool
pub mut:
scope &Scope
stmts []Stmt
imports []Import
auto_imports []string
embedded_files []EmbeddedFile
imported_symbols map[string]string
errors []errors.Error
warnings []errors.Warning
notices []errors.Notice
generic_fns []&FnDecl
global_labels []string
}
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.
struct FloatLiteral {
pub:
val string
pos token.Position
}
struct Fn {
pub:
params []Param
return_type Type
is_variadic bool
language Language
generic_names []string
is_pub bool
is_deprecated bool
is_unsafe bool
is_placeholder bool
is_main bool
is_test bool
is_conditional bool
is_keep_alive bool
no_body bool
mod string
ctdefine string
attrs []Attr
pub mut:
name string
source_fn voidptr
usages int
}
struct FnDecl {
pub:
name string
mod string
params []Param
is_deprecated bool
is_pub bool
is_variadic bool
is_anon bool
is_manualfree bool
is_main bool
is_test bool
is_conditional bool
is_keep_alive bool
receiver StructField
receiver_pos token.Position
is_method bool
method_type_pos token.Position
method_idx int
rec_mut bool
rec_share ShareType
language Language
no_body bool
is_builtin bool
body_pos token.Position
file string
generic_names []string
is_direct_arr bool
attrs []Attr
skip_gen bool
pub mut:
stmts []Stmt
defer_stmts []DeferStmt
return_type Type
return_type_pos token.Position
has_return bool
comments []Comment
next_comments []Comment
source_file &File = 0
scope &Scope
label_names []string
pos token.Position
}
function or method declaration
fn (node &FnDecl) modname() string
fn (node &FnDecl) stringify(t &Table, cur_mod string, m2a map[string]string) string
These methods are used only by vfmt, vdoc, and for debugging.
struct FnSignatureOpts {
skip_receiver bool
type_only bool
}
struct FnType {
pub:
is_anon bool
has_decl bool
func Fn
}
struct FnTypeDecl {
pub:
name string
is_pub bool
typ Type
pos token.Position
type_pos token.Position
comments []Comment
}
struct ForCStmt {
pub:
init Stmt
has_init bool
cond Expr
has_cond bool
inc Stmt
has_inc bool
is_multi bool
stmts []Stmt
pos token.Position
pub mut:
label string
scope &Scope
}
struct ForInStmt {
pub:
key_var string
val_var string
cond Expr
is_range bool
high Expr
stmts []Stmt
pos token.Position
val_is_mut bool
pub mut:
key_type Type
val_type Type
cond_type Type
kind Kind
label string
scope &Scope
}
struct ForStmt {
pub:
cond Expr
stmts []Stmt
is_inf bool
pos token.Position
pub mut:
label string
scope &Scope
}
struct GenericStructInst {
pub mut:
parent_idx int
generic_types []Type
}
instantiation of a generic struct
struct GlobalDecl {
pub:
pos token.Position
pub mut:
fields []GlobalField
end_comments []Comment
}
struct GlobalField {
pub:
name string
expr Expr
has_expr bool
pos token.Position
pub mut:
typ Type
comments []Comment
}
struct GoExpr {
pub:
pos token.Position
pub mut:
call_expr CallExpr
is_expr bool
}
struct GotoLabel {
pub:
name string
pos token.Position
}
struct GotoStmt {
pub:
name string
pos token.Position
}
struct HashStmt {
pub:
mod string
pos token.Position
source_file string
pub mut:
val string
kind string
main string
msg string
}
#include etc
struct Ident {
pub:
language Language
tok_kind token.Kind
pos token.Position
mut_pos token.Position
pub mut:
scope &Scope
obj ScopeObject
mod string
name string
kind IdentKind
info IdentInfo
is_mut bool
}
A single identifier
fn (i &Ident) var_info() IdentVar
struct IdentFn {
pub mut:
typ Type
}
struct IdentVar {
pub mut:
typ Type
is_mut bool
is_static bool
is_optional bool
share ShareType
}
TODO: (joe) remove completely, use ident.obj instead which points to the scope object
struct IfBranch {
pub:
cond Expr
pos token.Position
body_pos token.Position
comments []Comment
pub mut:
stmts []Stmt
scope &Scope
}
struct IfExpr {
pub:
is_comptime bool
tok_kind token.Kind
left Expr
pos token.Position
post_comments []Comment
pub mut:
branches []IfBranch
is_expr bool
typ Type
has_else bool
}
struct IfGuardExpr {
pub:
var_name string
pos token.Position
pub mut:
expr Expr
expr_type Type
}
if [x := opt()] {
struct Import {
pub:
mod string
alias string
pos token.Position
mod_pos token.Position
alias_pos token.Position
syms_pos token.Position
pub mut:
syms []ImportSymbol
comments []Comment
next_comments []Comment
}
import statement
struct ImportSymbol {
pub:
pos token.Position
name string
}
import symbol,for import {symbol} syntax
struct IndexExpr {
pub:
pos token.Position
index Expr
or_expr OrExpr
pub mut:
left Expr
left_type Type
is_setter bool
is_map bool
is_array bool
is_farray bool
is_option bool
}
fn (mut lx IndexExpr) recursive_mapset_is_setter(val bool)
helper for dealing with m[k1][k2][k3][k3] = value
struct InfixExpr {
pub:
op token.Kind
pos token.Position
is_stmt bool
pub mut:
left Expr
right Expr
left_type Type
right_type Type
auto_locked string
or_block OrExpr
}
left op right See: token.Kind.is_infix
struct IntegerLiteral {
pub:
val string
pos token.Position
}
struct Interface {
pub mut:
types []Type
fields []StructField
methods []Fn
}
fn (i &Interface) find_field(name string) ?StructField
fn (i &Interface) find_method(name string) ?Fn
fn (i &Interface) has_method(name string) bool
fn (i Interface) defines_method(name string) bool
struct InterfaceDecl {
pub:
name string
name_pos token.Position
field_names []string
is_pub bool
methods []FnDecl
mut_pos int
fields []StructField
pos token.Position
pre_comments []Comment
}
struct Likely {
pub:
expr Expr
pos token.Position
is_likely bool
}
struct LockExpr {
pub:
stmts []Stmt
is_rlock []bool
pos token.Position
pub mut:
lockeds []Ident
is_expr bool
typ Type
}
struct Map {
pub mut:
key_type Type
value_type Type
}
struct MapInit {
pub:
pos token.Position
keys []Expr
vals []Expr
comments [][]Comment
pre_cmnts []Comment
pub mut:
typ Type
key_type Type
value_type Type
}
struct MatchBranch {
pub:
exprs []Expr
ecmnts [][]Comment
stmts []Stmt
pos token.Position
is_else bool
post_comments []Comment
pub mut:
scope &Scope
}
struct MatchExpr {
pub:
tok_kind token.Kind
cond Expr
branches []MatchBranch
pos token.Position
comments []Comment
pub mut:
is_expr bool
return_type Type
cond_type Type
expected_type Type
is_sum_type bool
}
struct Module {
pub:
name string
short_name string
attrs []Attr
pos token.Position
name_pos token.Position
is_skipped bool
}
module declaration
struct MultiReturn {
pub mut:
types []Type
}
struct NodeError {
pub:
idx int
pos token.Position
}
struct None {
pub:
pos token.Position
}
struct OffsetOf {
pub:
struct_type Type
field string
pos token.Position
}
struct OrExpr {
pub:
stmts []Stmt
kind OrKind
pos token.Position
}
or { ... }
struct Param {
pub:
pos token.Position
name string
is_mut bool
is_auto_rec bool
typ Type
type_pos token.Position
is_hidden bool
}
struct ParExpr {
pub:
expr Expr
pos token.Position
}
(3+4)
struct PostfixExpr {
pub:
op token.Kind
expr Expr
pos token.Position
pub mut:
auto_locked string
}
++, --
struct PrefixExpr {
pub:
op token.Kind
pos token.Position
pub mut:
right_type Type
right Expr
or_block OrExpr
is_option bool
}
See: token.Kind.is_prefix
struct RangeExpr {
pub:
low Expr
high Expr
has_high bool
has_low bool
pos token.Position
}
s[10..20]
struct Return {
pub:
pos token.Position
exprs []Expr
comments []Comment
pub mut:
types []Type
}
function return statement
struct Scope {
pub mut:
objects map[string]ScopeObject
struct_fields []ScopeStructField
parent &Scope
detached_from_parent bool
children []&Scope
start_pos int
end_pos int
}
fn (s &Scope) find_with_scope(name string) ?(ScopeObject, &Scope)
fn (s &Scope) find(name string) ?ScopeObject
fn (s &Scope) find_struct_field(struct_type Type, field_name string) ?ScopeStructField
fn (s &Scope) is_known(name string) bool
fn (s &Scope) find_var(name string) ?&Var
fn (s &Scope) find_const(name string) ?&ConstField
fn (s &Scope) known_var(name string) bool
fn (mut s Scope) update_var_type(name string, typ Type)
fn (mut s Scope) register_struct_field(field ScopeStructField)
fn (mut s Scope) register(obj ScopeObject)
fn (s &Scope) outermost() &Scope
fn (s &Scope) innermost(pos int) &Scope
returns the innermost scope containing pos pub fn (s &Scope) innermost(pos int) ?&Scope {
fn (sc Scope) show(depth int, max_depth int) string
fn (sc Scope) str() string
struct ScopeStructField {
pub:
struct_type Type
name string
pos token.Position
typ Type
smartcasts []Type
orig_type Type
}
used for smartcasting only struct fields change type in scopes
struct SelectBranch {
pub:
stmt Stmt
stmts []Stmt
pos token.Position
comment Comment
is_else bool
is_timeout bool
post_comments []Comment
}
struct SelectExpr {
pub:
branches []SelectBranch
pos token.Position
has_exception bool
pub mut:
is_expr bool
expected_type Type
}
struct SelectorExpr {
pub:
pos token.Position
field_name string
is_mut bool
mut_pos token.Position
next_token token.Kind
pub mut:
expr Expr
expr_type Type
typ Type
name_type Type
scope &Scope
from_embed_type Type
}
foo.bar
fn (e &SelectorExpr) root_ident() ?Ident
root_ident returns the origin ident where the selector started.
struct SizeOf {
pub:
is_type bool
expr Expr
pos token.Position
pub mut:
typ Type
}
struct SqlExpr {
pub:
typ Type
is_count bool
db_expr Expr
has_where bool
has_offset bool
offset_expr Expr
has_order bool
order_expr Expr
has_desc bool
is_array bool
pos token.Position
has_limit bool
limit_expr Expr
pub mut:
where_expr Expr
table_expr TypeNode
fields []StructField
sub_structs map[int]SqlExpr
}
struct SqlStmt {
pub:
kind SqlStmtKind
db_expr Expr
object_var_name string
pos token.Position
where_expr Expr
updated_columns []string
update_exprs []Expr
pub mut:
table_expr TypeNode
fields []StructField
sub_structs map[int]SqlStmt
}
struct StringInterLiteral {
pub:
vals []string
exprs []Expr
fwidths []int
precisions []int
pluss []bool
fills []bool
fmt_poss []token.Position
pos token.Position
pub mut:
expr_types []Type
fmts []byte
need_fmts []bool
}
'name: $name'
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 {
pub:
val string
is_raw bool
language Language
pos token.Position
}
struct Struct {
pub:
attrs []Attr
pub mut:
embeds []Type
fields []StructField
is_typedef bool
is_union bool
is_heap bool
generic_types []Type
concrete_types []Type
parent_type Type
}
fn (s Struct) find_field(name string) ?StructField
fn (s Struct) get_field(name string) StructField
struct StructDecl {
pub:
pos token.Position
name string
gen_types []Type
is_pub bool
mut_pos int
pub_pos int
pub_mut_pos int
global_pos int
module_pos int
language Language
is_union bool
attrs []Attr
end_comments []Comment
embeds []Embed
pub mut:
fields []StructField
}
struct StructEmbedding {
pub:
name string
typ Type
pos token.Position
}
struct StructField {
pub:
pos token.Position
type_pos token.Position
comments []Comment
default_expr Expr
has_default_expr bool
attrs []Attr
is_pub bool
default_val string
is_mut bool
is_global bool
pub mut:
default_expr_typ Type
name string
typ Type
}
fn (f &StructField) equals(o &StructField) bool
NB: FExpr here is a actually an ast.Expr . It should always be used by casting to ast.Expr, using ast.fe2ex()/ast.ex2fe() That hack is needed to break an import cycle between v.ast and v.ast . pub type FExpr = byteptr | voidptr
struct StructInit {
pub:
pos token.Position
name_pos token.Position
is_short bool
pub mut:
unresolved bool
pre_comments []Comment
typ Type
update_expr Expr
update_expr_type Type
update_expr_comments []Comment
has_update_expr bool
fields []StructInitField
embeds []StructInitEmbed
}
struct StructInitEmbed {
pub:
expr Expr
pos token.Position
comments []Comment
next_comments []Comment
pub mut:
name string
typ Type
expected_type Type
}
struct StructInitField {
pub:
expr Expr
pos token.Position
name_pos token.Position
comments []Comment
next_comments []Comment
pub mut:
name string
typ Type
expected_type Type
parent_type Type
}
struct SumType {
pub:
variants []Type
pub mut:
fields []StructField
found_fields bool
}
fn (s &SumType) find_field(name string) ?StructField
struct SumTypeDecl {
pub:
name string
is_pub bool
pos token.Position
comments []Comment
typ Type
pub mut:
variants []SumTypeVariant
}
New implementation of sum types
struct SumTypeVariant {
pub:
typ Type
pos token.Position
}
struct Table {
pub mut:
type_symbols []TypeSymbol
type_idxs map[string]int
fns map[string]Fn
dumps map[int]string
imports []string
modules []string
cflags []cflag.CFlag
redefined_fns []string
fn_gen_types map[string][][]Type
cmod_prefix string
is_fmt bool
used_fns map[string]bool
used_consts map[string]bool
}
fn (mut t Table) add_placeholder_type(name string, language Language) int
fn (t &Table) array_cname(elem_type Type) string
fn (t &Table) array_fixed_cname(elem_type Type, size int) string
fn (t &Table) array_fixed_name(elem_type Type, size int) string
array_fixed_source_name generates the original name for the v source. e. g. [16][8]int
fn (t &Table) array_name(elem_type Type) string
array_source_name generates the original name for the v source. e. g. []int
fn (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]byte
608 > [76]byte
fn (t &Table) chan_cname(elem_type Type, is_mut bool) string
fn (t &Table) chan_name(elem_type Type, is_mut bool) string
fn (t &Table) find_field(s &TypeSymbol, name string) ?StructField
search from current type up through each parent looking for field
fn (t &Table) find_field_with_embeds(sym &TypeSymbol, field_name string) ?StructField
search for a given field, looking through embedded fields
fn (t &Table) find_fn(name string) ?Fn
fn (mut t Table) find_or_register_array(elem_type Type) int
fn (mut t Table) find_or_register_array_fixed(elem_type Type, size int) int
fn (mut t Table) find_or_register_array_with_dims(elem_type Type, nr_dims int) int
fn (mut t Table) find_or_register_chan(elem_type Type, is_mut bool) int
fn (mut t Table) find_or_register_fn_type(mod string, f Fn, is_anon bool, has_decl bool) int
fn (mut t Table) find_or_register_map(key_type Type, value_type Type) int
fn (mut t Table) find_or_register_multi_return(mr_typs []Type) int
fn (mut t Table) find_or_register_thread(return_type Type) int
fn (t &Table) find_type(name string) ?TypeSymbol
fn (t &Table) find_type_idx(name string) int
fn (t &Table) fn_signature(func &Fn, opts FnSignatureOpts) string
fn (t &Table) fn_type_signature(f &Fn) string
used to compare fn's & for naming anon fn's
fn (t &Table) fn_type_source_signature(f &Fn) string
source_signature generates the signature of a function which looks like in the V source
fn (mut t Table) generic_struct_insts_to_concrete()
generic struct instantiations to concrete types
fn (t &Table) get_final_type_symbol(typ Type) &TypeSymbol
get_final_type_symbol follows aliases until it gets to a "real" Type
fn (t &Table) get_type_name(typ Type) string
fn (t &Table) get_type_symbol(typ Type) &TypeSymbol
fn (t &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool
has_deep_child_no_ref returns true if type is struct and has any child or nested child with the type of the given name the given name consists of module and name (mod.Name
) it doesn't care about childs that are references
fn (t &Table) is_same_method(f &Fn, func &Fn) string
fn (t &Table) known_fn(name string) bool
fn (t &Table) known_type(name string) bool
fn (t &Table) known_type_idx(typ Type) bool
fn (t &Table) known_type_names() []string
only used for debugging V compiler type bugs
fn (t &Table) map_cname(key_type Type, value_type Type) string
fn (t &Table) map_name(key_type Type, value_type Type) string
map_source_name generates the original name for the v source. e. g. map[string]int
fn (t &Table) mktyp(typ Type) Type
fn (mut t Table) parse_cflag(cflg string, mod string, ctimedefines []string) ?bool
parse the flags to (ast.cflags) []CFlag Note: clean up big time (joe-c)
fn (t &Table) register_aggregate_method(mut sym TypeSymbol, name string) ?Fn
fn (mut t Table) register_builtin_type_symbols()
fn (mut t Table) register_fn(new_fn Fn)
fn (mut t Table) register_fn_gen_type(fn_name string, types []Type)
fn (mut t Table) register_type_symbol(typ TypeSymbol) int
fn (t &Table) resolve_common_sumtype_fields(sym_ &TypeSymbol)
fn (mut t Table) resolve_generic_by_names(generic_type Type, generic_names []string, generic_types []Type) ?Type
resolve_generic_by_names 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 (mut t Table) resolve_generic_by_types(generic_type Type, from_types []Type, to_types []Type) ?Type
resolve_generic_by_types 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 (t &Table) struct_has_field(s &TypeSymbol, name string) bool
fn (t &Table) sumtype_has_variant(parent Type, variant Type) bool
TODO: there is a bug when casting sumtype the other way if its pointer so until fixed at least show v (not C) error x(variant) = y(SumType*)
fn (t &Table) thread_cname(return_type Type) string
fn (t &Table) thread_name(return_type Type) string
fn (t &Table) type_find_method(s &TypeSymbol, name string) ?Fn
search from current type up through each parent looking for method
fn (t &Table) type_has_method(s &TypeSymbol, name string) bool
fn (t &Table) type_kind(typ Type) Kind
returns TypeSymbol kind only if there are no type modifiers
fn (mytable &Table) type_to_code(t Type) string
type name in code (for builtin)
fn (t &Table) type_to_str(typ Type) string
human readable type name
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 (t &Table) unalias_num_type(typ Type) Type
fn (t &Table) value_type(typ Type) Type
struct Thread {
pub mut:
return_type Type
}
struct TypeNode {
pub:
typ Type
pos token.Position
}
struct TypeOf {
pub:
expr Expr
pos token.Position
pub mut:
expr_type Type
}
struct TypeSymbol {
pub:
parent_idx int
pub mut:
info TypeInfo
kind Kind
name string
cname string
methods []Fn
mod string
is_public bool
language Language
}
Represents a type that only needs an identifier, e.g. int, array_int. A pointer type &T
would have a TypeSymbol T
. Note: For a Type, use: * Table.type_to_str(typ) not TypeSymbol.name. * Table.type_kind(typ) not TypeSymbol.kind. Each TypeSymbol is entered into Table.types
. See also: Table.get_type_symbol.
fn (t &TypeSymbol) array_fixed_info() ArrayFixed
fn (t &TypeSymbol) array_info() Array
fn (t &TypeSymbol) chan_info() Chan
fn (ts TypeSymbol) debug() []string
fn (t &TypeSymbol) embed_name() string
fn (t &TypeSymbol) enum_info() Enum
fn (t &TypeSymbol) find_field(name string) ?StructField
fn (t &TypeSymbol) find_method(name string) ?Fn
fn (t &TypeSymbol) has_method(name string) bool
fn (t &TypeSymbol) is_builtin() bool
fn (t &TypeSymbol) is_float() bool
fn (t &TypeSymbol) is_int() bool
fn (t &TypeSymbol) is_number() bool
fn (t &TypeSymbol) is_pointer() bool
fn (t &TypeSymbol) is_primitive() bool
fn (t &TypeSymbol) is_string() bool
fn (t &TypeSymbol) map_info() Map
fn (t &TypeSymbol) mr_info() MultiReturn
fn (mut t TypeSymbol) register_method(new_fn Fn) int
fn (t &TypeSymbol) str() string
fn (t &TypeSymbol) str_method_info() (bool, bool, int)
fn (t &TypeSymbol) struct_info() Struct
fn (t &TypeSymbol) sumtype_info() SumType
fn (t &TypeSymbol) thread_info() Thread
struct UnsafeExpr {
pub:
expr Expr
pos token.Position
}
struct Var {
pub:
name string
expr Expr
share ShareType
is_mut bool
is_autofree_tmp bool
is_arg bool
is_auto_deref bool
pub mut:
typ Type
orig_type Type
smartcasts []Type
pos token.Position
is_used bool
is_changed bool
is_or bool
is_tmp bool
}