Skip to content

v.transformer #

fn new_transformer #

fn new_transformer(pref &pref.Preferences) &Transformer

fn new_transformer_with_table #

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

struct IndexState #

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

Current limitations: * any function using break/continue or goto/label stopped from being optimised as soon as the relevant AST nodes are found as the code can not be ensured to be sequential * enum and const indexes are not optimised (they could probably be looked up) * for loops with multiple var in their init and/or inc are not analysed * mut array are not analysed as their size can be reduced, but self-assignment in a single line

struct Transformer #

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

fn (Transformer) transform_files #

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

fn (Transformer) transform #

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

fn (Transformer) find_new_array_len #

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

fn (Transformer) find_new_range #

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

fn (Transformer) find_mut_self_assign #

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

fn (Transformer) check_safe_array #

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

fn (Transformer) stmt #

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

fn (Transformer) assert_stmt #

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

fn (Transformer) expr_stmt_if_expr #

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

fn (Transformer) expr_stmt_match_expr #

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

fn (Transformer) for_c_stmt #

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

fn (Transformer) for_stmt #

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

fn (Transformer) interface_decl #

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

fn (Transformer) expr #

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

fn (Transformer) call_expr #

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

fn (Transformer) infix_expr #

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

fn (Transformer) if_expr #

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

fn (Transformer) match_expr #

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

fn (Transformer) sql_expr #

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

fn (Transformer) fn_decl #

fn (mut t Transformer) fn_decl(mut node 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.