Module v.transformer stdlib

Dependencies from vmod:
Imported by:
Show selected OS-specific symbols.
Show selected Backend-specific symbols.

Dependencies defined in v.mod

This section is empty.


Imported by


This section is empty.


This section is empty.

Sum types

This section is empty.


#fn new_transformer_with_table

fn new_transformer_with_table(table &v.ast.Table, pref_ &v.pref.Preferences) &Transformer


#struct IndexState

pub struct IndexState {
	// max_index has the biggest array index accessed for then named array
	// so if a[2] was set or read, it will be 2
	// A new array with no .len will recorded as -1 (accessing a[0] would be invalid)
	// the value -2 is used to indicate that the array should not be analysed
	// this is used for a mut array
	max_index map[string]int
	// We need to snapshot when entering `if` and `for` blocks and restore on exit
	// as the statements may not be run. This is managed by indent() & unindent().
	saved_disabled []bool
	saved_key_vals [][]KeyVal
pub mut:
	// on encountering goto/break/continue statements we stop any analysis
	// for the current function (as the code is not linear anymore)
	disabled bool
	level    int

#fn (&IndexState) safe_access

fn (mut i &IndexState) safe_access(key string, new int) bool

we are remembering the last array accessed and checking if the value is safe the node is updated with this information which can then be used by the code generators

#fn (&IndexState) safe_offset

fn (mut i &IndexState) safe_offset(key string) int

safe_offset returns for a previvous array what was the highest offset we ever accessed for that identifier

#fn (&IndexState) indent

fn (mut i &IndexState) indent(is_function bool)

indent is used for when encountering new code blocks (if, for and functions) The code analysis needs to take into consideration blocks of code which may not run at runtime (if/for) and therefore even if a new maximum for an index access is found on an if branch it can not be used within the parent code. The same is true with for blocks. indent() snapshot the current state, to allow restoration with unindent() Also within a function, analysis must be disabled when goto or break are encountered as the code flow is then not lineear, and only restart when a new function analysis is started.

#fn (&IndexState) unindent

fn (mut i &IndexState) unindent()

restoring the data as it was before the if/for/unsafe block

#struct Transformer

pub struct Transformer {
	pref &pref.Preferences
pub mut:
	index &IndexState
	table &ast.Table = unsafe { nil }
	is_assert bool

#fn new_transformer

fn new_transformer(pref_ &v.pref.Preferences) &Transformer

#fn (&Transformer) transform_files

fn (mut t &Transformer) transform_files(ast_files []&v.ast.File)

#fn (&Transformer) transform

fn (mut t &Transformer) transform(mut ast_file &v.ast.File)

#fn (&Transformer) find_new_array_len

fn (mut t &Transformer) find_new_array_len(node v.ast.AssignStmt)

#fn (&Transformer) find_new_range

fn (mut t &Transformer) find_new_range(node v.ast.AssignStmt)

#fn (&Transformer) find_mut_self_assign

fn (mut t &Transformer) find_mut_self_assign(node v.ast.AssignStmt)

#fn (&Transformer) check_safe_array

fn (mut t &Transformer) check_safe_array(mut node &v.ast.IndexExpr)

#fn (&Transformer) stmt

fn (mut t &Transformer) stmt(mut node &v.ast.Stmt) v.ast.Stmt

#fn (&Transformer) assert_stmt

fn (mut t &Transformer) assert_stmt(mut node &v.ast.AssertStmt) v.ast.Stmt

#fn (&Transformer) expr_stmt_if_expr

fn (mut t &Transformer) expr_stmt_if_expr(mut node &v.ast.IfExpr) v.ast.Expr

#fn (&Transformer) expr_stmt_match_expr

fn (mut t &Transformer) expr_stmt_match_expr(mut node &v.ast.MatchExpr) v.ast.Expr

#fn (&Transformer) for_c_stmt

fn (mut t &Transformer) for_c_stmt(mut node &v.ast.ForCStmt) v.ast.Stmt

#fn (&Transformer) for_stmt

fn (mut t &Transformer) for_stmt(mut node &v.ast.ForStmt) v.ast.Stmt

#fn (&Transformer) interface_decl

fn (mut t &Transformer) interface_decl(mut node &v.ast.InterfaceDecl) v.ast.Stmt

#fn (&Transformer) expr

fn (mut t &Transformer) expr(mut node &v.ast.Expr) v.ast.Expr

#fn (&Transformer) call_expr

fn (mut t &Transformer) call_expr(mut node &v.ast.CallExpr) v.ast.Expr

#fn (&Transformer) infix_expr

fn (mut t &Transformer) infix_expr(mut node &v.ast.InfixExpr) v.ast.Expr

#fn (&Transformer) if_expr

fn (mut t &Transformer) if_expr(mut node &v.ast.IfExpr) v.ast.Expr

#fn (&Transformer) match_expr

fn (mut t &Transformer) match_expr(mut node &v.ast.MatchExpr) v.ast.Expr

#fn (&Transformer) sql_expr

fn (mut t &Transformer) sql_expr(mut node &v.ast.SqlExpr) v.ast.Expr

#fn (&Transformer) fn_decl

fn (mut t &Transformer) fn_decl(mut node &v.ast.FnDecl)

fn_decl mutates node.

if pref.trace_calls is true ast Nodes for eprintln(...) is prepended to the FnDecl's stmts list to let the gen backend generate the target specific code for the print.


This section is empty.


This section is empty.