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 {
mut:
// 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
andconst
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 }
file &ast.File = unsafe { nil }
mut:
is_assert bool
inside_dump bool
//
strings_builder_type ast.Type = ast.no_type
}
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_trace_calls #
fn (mut t Transformer) fn_decl_trace_calls(mut node ast.FnDecl)
fn (Transformer) simplify_nested_interpolation_in_sb #
fn (mut t Transformer) simplify_nested_interpolation_in_sb(mut onode ast.Stmt, mut nexpr ast.CallExpr, ntype ast.Type) bool
- fn new_transformer
- fn new_transformer_with_table
- struct IndexState
- struct Transformer
- fn transform_files
- fn transform
- fn find_new_array_len
- fn find_new_range
- fn find_mut_self_assign
- fn check_safe_array
- fn stmt
- fn assert_stmt
- fn expr_stmt_if_expr
- fn expr_stmt_match_expr
- fn for_c_stmt
- fn for_stmt
- fn interface_decl
- fn expr
- fn call_expr
- fn infix_expr
- fn if_expr
- fn match_expr
- fn sql_expr
- fn fn_decl_trace_calls
- fn simplify_nested_interpolation_in_sb