fn args2str(args []CallArg) string
fn ex2fe(x Expr) table.FExpr
fn fe2ex(x table.FExpr) Expr
TODO: remove this fugly hack :-| fe2ex/1 and ex2fe/1 are used to convert back and forth from table.FExpr to ast.Expr , which in turn is needed to break a dependency cycle between v.ast and v.table, for the single field table.Field.default_expr, which should be ast.Expr
fn new_scope(parent &Scope, start_pos int) &Scope
type Expr = AnonFn | ArrayDecompose | ArrayInit | AsCast | Assoc | AtExpr | BoolLiteral |
CTempVar | CallExpr | CastExpr | ChanInit | CharLiteral | Comment | ComptimeCall |
ComptimeSelector | ConcatExpr | EnumVal | FloatLiteral | GoExpr | Ident | IfExpr |
IfGuardExpr | IndexExpr | InfixExpr | IntegerLiteral | Likely | LockExpr | MapInit |
MatchExpr | None | OrExpr | ParExpr | PostfixExpr | PrefixExpr | RangeExpr | SelectExpr |
SelectorExpr | SizeOf | SqlExpr | StringInterLiteral | StringLiteral | StructInit |
Type | TypeOf | UnsafeExpr
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 = ConstField | EnumField | Expr | Field | File | GlobalField | IfBranch |
MatchBranch | ScopeObject | SelectBranch | Stmt | StructField | StructInitField |
table.Param
TOOD: replace table.Param
fn (node Node) position() token.Position
fn (node Node) children() []Node
type ScopeObject = 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 = AssertStmt | AssignStmt | Block | BranchStmt | CompFor | ConstDecl | DeferStmt |
EnumDecl | ExprStmt | FnDecl | ForCStmt | ForInStmt | ForStmt | GlobalDecl | GoStmt |
GotoLabel | GotoStmt | HashStmt | Import | InterfaceDecl | Module | Return | SqlStmt |
StructDecl | TypeDecl
fn (stmt Stmt) check_c_expr() ?
check if stmt can be an expression in C
fn (stmt Stmt) position() token.Position
fn (node Stmt) str() string
type TypeDecl = AliasTypeDecl | FnTypeDecl | SumTypeDecl
enum CompForKind {
methods
fields
}
fn (e CompForKind) str() string
enum IdentKind {
unresolved
blank_ident
variable
constant
global
function
}
enum OrKind {
absent
block
propagate
}
enum SqlStmtKind {
insert
update
delete
}
struct AliasTypeDecl {
pub:
name string
is_pub bool
parent_type table.Type
pos token.Position
comments []Comment
}
struct AnonFn {
pub:
decl FnDecl
pub mut:
typ table.Type
}
anonymous function
struct ArrayDecompose {
pub:
expr Expr
pos token.Position
pub mut:
expr_type table.Type
arg_type table.Type
}
struct ArrayInit {
pub:
pos token.Position
elem_type_pos token.Position
exprs []Expr
ecmnts [][]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 []table.Type
is_interface bool
interface_type table.Type
elem_type table.Type
typ table.Type
}
struct AsCast {
pub:
expr Expr
typ table.Type
pos token.Position
pub mut:
expr_type table.Type
}
struct AssertStmt {
pub:
pos token.Position
pub mut:
expr Expr
}
struct AssignStmt {
pub:
right []Expr
op token.Kind
pos token.Position
comments []Comment
end_comments []Comment
pub mut:
left []Expr
left_types []table.Type
right_types []table.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 table.Type
scope &Scope
}
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 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 table.ShareType
expr Expr
comments []Comment
pub mut:
typ table.Type
is_tmp_autofree bool
pos token.Position
}
function call argument: f(callarg)
fn (a CallArg) str() string
struct CallExpr {
pub:
pos token.Position
left Expr
mod string
pub mut:
name string
is_method bool
is_field bool
args []CallArg
expected_arg_types []table.Type
language table.Language
or_block OrExpr
left_type table.Type
receiver_type table.Type
return_type table.Type
should_be_skipped bool
generic_types []table.Type
generic_list_pos token.Position
free_receiver bool
scope &Scope
from_embed_type table.Type
comments []Comment
}
function or method call expr
struct CastExpr {
pub:
expr Expr
arg Expr
typ table.Type
pos token.Position
pub mut:
typname string
expr_type table.Type
has_arg bool
in_prexpr bool
}
NB: &string(x) gets parsed as ast.PrefixExpr{ right: ast.CastExpr{...} } TODO: that is very likely a parsing bug. It should get parsed as just ast.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 ChanInit {
pub:
pos token.Position
cap_expr Expr
has_cap bool
pub mut:
typ table.Type
elem_type table.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
pub mut:
typ table.Type
}
struct ComptimeCall {
pub:
has_parens bool
method_name string
left Expr
is_vweb bool
vweb_tmpl File
args_var string
is_embed bool
embed_file EmbeddedFile
pub mut:
sym table.TypeSymbol
}
struct ComptimeSelector {
pub:
has_parens bool
left Expr
field_expr Expr
pub mut:
left_type table.Type
typ table.Type
}
struct ConcatExpr {
pub:
vals []Expr
pos token.Position
pub mut:
return_type table.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 table.Type
comments []Comment
}
const field in const declaration group
struct CTempVar {
pub:
name string
orig Expr
typ table.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
}
TODO: handle this differently v1 excludes non current os ifdefs so the defer's never get added in the first place
struct Embed {
pub:
typ table.Type
pos token.Position
}
struct EmbeddedFile {
pub:
rpath string
apath string
}
struct EnumDecl {
pub:
name string
is_pub bool
is_flag bool
is_multi_allowed bool
comments []Comment
fields []EnumField
attrs []table.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 table.Type
}
an enum value, like OS.macos or .macos
struct ExprStmt {
pub:
expr Expr
pos token.Position
comments []Comment
is_expr bool
pub mut:
typ table.Type
}
| IncDecStmt k Stand-alone expression in a statement list.
struct Field {
pub:
name string
pos token.Position
pub mut:
typ table.Type
}
struct File {
pub:
path string
path_base string
mod Module
global_scope &Scope
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
generic_fns []&FnDecl
}
Each V source file is represented by one ast.File structure. When the V compiler runs, the parser will fill an []ast.File. That array is then passed to V's checker.
struct FloatLiteral {
pub:
val string
pos token.Position
}
struct FnDecl {
pub:
name string
mod string
params []table.Param
is_deprecated bool
is_pub bool
is_variadic bool
is_anon bool
is_manualfree bool
receiver Field
receiver_pos token.Position
is_method bool
method_type_pos token.Position
method_idx int
rec_mut bool
rec_share table.ShareType
language table.Language
no_body bool
is_builtin bool
pos token.Position
body_pos token.Position
file string
generic_params []GenericParam
is_direct_arr bool
attrs []table.Attr
pub mut:
stmts []Stmt
return_type table.Type
comments []Comment
next_comments []Comment
source_file &File = 0
scope &Scope
}
function or method declaration
fn (node &FnDecl) modname() string
fn (node &FnDecl) stringify(t &table.Table, cur_mod string, m2a map[string]string) string
These methods are used only by vfmt, vdoc, and for debugging.
struct FnTypeDecl {
pub:
name string
is_pub bool
typ table.Type
pos token.Position
comments []Comment
}
struct ForCStmt {
pub:
init Stmt
has_init bool
cond Expr
has_cond bool
inc Stmt
has_inc 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 table.Type
val_type table.Type
cond_type table.Type
kind table.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 GenericParam {
pub:
name string
}
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 table.Type
comments []Comment
}
struct GoExpr {
pub:
pos token.Position
pub mut:
go_stmt GoStmt
mut:
return_type table.Type
}
struct GoStmt {
pub:
pos token.Position
pub mut:
call_expr CallExpr
}
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 table.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 table.Type
}
struct IdentVar {
pub mut:
typ table.Type
is_mut bool
is_static bool
is_optional bool
share table.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
smartcast bool
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 table.Type
has_else bool
}
struct IfGuardExpr {
pub:
var_name string
expr Expr
pos token.Position
pub mut:
expr_type table.Type
}
if [x := opt()] {
struct Import {
pub:
mod string
alias string
pos token.Position
mod_pos token.Position
alias_pos token.Position
pub mut:
syms []ImportSymbol
}
import statement
struct ImportSymbol {
pub:
pos token.Position
name string
}
import symbol,for import {symbol} syntax
struct IndexExpr {
pub:
pos token.Position
left Expr
index Expr
or_expr OrExpr
pub mut:
left_type table.Type
is_setter bool
}
struct InfixExpr {
pub:
op token.Kind
pos token.Position
pub mut:
left Expr
right Expr
left_type table.Type
right_type table.Type
auto_locked string
or_block OrExpr
}
left op right See: token.Kind.is_infix
struct IntegerLiteral {
pub:
val string
pos token.Position
}
struct InterfaceDecl {
pub:
name string
field_names []string
is_pub bool
methods []FnDecl
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 table.Type
}
struct MapInit {
pub:
pos token.Position
keys []Expr
vals []Expr
pub mut:
typ table.Type
key_type table.Type
value_type table.Type
}
struct MatchBranch {
pub:
exprs []Expr
ecmnts [][]Comment
stmts []Stmt
pos token.Position
comments []Comment
is_else bool
post_comments []Comment
pub mut:
scope &Scope
}
struct MatchExpr {
pub:
tok_kind token.Kind
cond Expr
branches []MatchBranch
pos token.Position
pub mut:
is_expr bool
return_type table.Type
cond_type table.Type
expected_type table.Type
is_sum_type bool
}
struct Module {
pub:
name string
short_name string
attrs []table.Attr
pos token.Position
name_pos token.Position
is_skipped bool
}
module declaration
struct None {
pub:
pos token.Position
foo int
}
struct OrExpr {
pub:
stmts []Stmt
kind OrKind
pos token.Position
}
or { ... }
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
right Expr
pos token.Position
pub mut:
right_type table.Type
or_block OrExpr
}
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 []table.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 table.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 table.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 table.Type
name string
pos token.Position
typ table.Type
sum_type_casts []table.Type
orig_type table.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 table.Type
}
struct SelectorExpr {
pub:
pos token.Position
expr Expr
field_name string
is_mut bool
mut_pos token.Position
next_token token.Kind
pub mut:
expr_type table.Type
typ table.Type
name_type table.Type
scope &Scope
from_embed_type table.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 table.Type
}
struct SqlExpr {
pub:
typ table.Type
is_count bool
db_expr Expr
where_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:
table_expr Type
fields []table.Field
}
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 Type
fields []table.Field
}
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 []table.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 table.Language
pos token.Position
}
struct StructDecl {
pub:
pos token.Position
name string
gen_types []table.Type
is_pub bool
mut_pos int
pub_pos int
pub_mut_pos int
module_pos int
language table.Language
is_union bool
attrs []table.Attr
end_comments []Comment
embeds []Embed
pub mut:
fields []StructField
}
struct StructEmbedding {
pub:
name string
typ table.Type
pos token.Position
}
struct StructField {
pub:
pos token.Position
type_pos token.Position
comments []Comment
default_expr Expr
has_default_expr bool
attrs []table.Attr
is_public bool
pub mut:
name string
typ table.Type
}
struct StructInit {
pub:
pos token.Position
is_short bool
pub mut:
pre_comments []Comment
typ table.Type
update_expr Expr
update_expr_type table.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 table.Type
expected_type table.Type
}
struct StructInitField {
pub:
expr Expr
pos token.Position
comments []Comment
next_comments []Comment
pub mut:
name string
typ table.Type
expected_type table.Type
}
struct SumTypeDecl {
pub:
name string
is_pub bool
pos token.Position
comments []Comment
pub mut:
variants []SumTypeVariant
}
New implementation of sum types
struct SumTypeVariant {
pub:
typ table.Type
pos token.Position
}
struct Type {
pub:
typ table.Type
pos token.Position
}
struct TypeOf {
pub:
expr Expr
pos token.Position
pub mut:
expr_type table.Type
}
struct UnsafeExpr {
pub:
expr Expr
pos token.Position
}
struct Var {
pub:
name string
expr Expr
share table.ShareType
is_mut bool
is_autofree_tmp bool
is_arg bool
pub mut:
typ table.Type
orig_type table.Type
sum_type_casts []table.Type
pos token.Position
is_used bool
is_changed bool
is_or bool
is_tmp bool
}