Skip to content

v.gen.golang #

fn gen #

fn gen(files []&ast.File, mut table ast.Table, out_file string, pref_ &pref.Preferences) (int, int)

struct AttrsOptions #

@[params]
struct AttrsOptions {
pub:
	inline bool
}

struct Gen #

struct Gen {
	pref &pref.Preferences = unsafe { nil }
pub mut:
	table &ast.Table = unsafe { nil }
	// is_debug           bool
	out                strings.Builder
	out_imports        strings.Builder
	indent             int
	empty_line         bool
	line_len           int  // the current line length, Note: it counts \t as 4 spaces, and starts at 0 after f.writeln
	buffering          bool // disables line wrapping for exprs that will be analyzed later
	par_level          int  // how many parentheses are put around the current expression
	single_line_if     bool
	cur_mod            string
	did_imports        bool
	is_assign          bool
	is_struct_init     bool
	auto_imports       []string          // automatically inserted imports that the user forgot to specify
	import_pos         int               // position of the imports in the resulting string for later autoimports insertion
	used_imports       []string          // to remove unused imports
	import_syms_used   map[string]bool   // to remove unused import symbols.
	mod2alias          map[string]string // for `import time as t`, will contain: 'time'=>'t'
	mod2syms           map[string]string // import time { now } 'time.now'=>'now'
	use_short_fn_args  bool
	single_line_fields bool   // should struct fields be on a single line
	it_name            string // the name to replace `it` with
	in_lambda_depth    int
	inside_const       bool
	is_mbranch_expr    bool // match a { x...y { } }
	fn_scope           &ast.Scope = unsafe { nil }
	wsinfix_depth      int
	nlines             int
}

fn (Gen) alias_type_decl #

fn (mut f Gen) alias_type_decl(node ast.AliasTypeDecl)

fn (Gen) anon_fn #

fn (mut f Gen) anon_fn(node ast.AnonFn)

fn (Gen) array_decompose #

fn (mut f Gen) array_decompose(node ast.ArrayDecompose)

=== Specific Expr methods ===//

fn (Gen) array_init #

fn (mut f Gen) array_init(node ast.ArrayInit)

fn (Gen) as_cast #

fn (mut f Gen) as_cast(node ast.AsCast)

fn (Gen) assert_stmt #

fn (mut f Gen) assert_stmt(node ast.AssertStmt)

=== Specific Stmt methods ===//

fn (Gen) assign_stmt #

fn (mut f Gen) assign_stmt(node ast.AssignStmt)

fn (Gen) assoc #

fn (mut f Gen) assoc(node ast.Assoc)

fn (Gen) at_expr #

fn (mut f Gen) at_expr(node ast.AtExpr)

fn (Gen) attrs #

fn (mut f Gen) attrs(attrs []ast.Attr)

fn (Gen) block #

fn (mut f Gen) block(node ast.Block)

fn (Gen) branch_stmt #

fn (mut f Gen) branch_stmt(node ast.BranchStmt)

fn (Gen) call_args #

fn (mut f Gen) call_args(args []ast.CallArg)

fn (Gen) call_expr #

fn (mut f Gen) call_expr(node ast.CallExpr)

fn (Gen) cast_expr #

fn (mut f Gen) cast_expr(node ast.CastExpr)

fn (Gen) chan_init #

fn (mut f Gen) chan_init(mut node ast.ChanInit)

fn (Gen) char_literal #

fn (mut f Gen) char_literal(node ast.CharLiteral)

fn (Gen) comptime_call #

fn (mut f Gen) comptime_call(node ast.ComptimeCall)

fn (Gen) comptime_for #

fn (mut f Gen) comptime_for(node ast.ComptimeFor)

fn (Gen) comptime_selector #

fn (mut f Gen) comptime_selector(node ast.ComptimeSelector)

fn (Gen) concat_expr #

fn (mut f Gen) concat_expr(node ast.ConcatExpr)

fn (Gen) const_decl #

fn (mut f Gen) const_decl(node ast.ConstDecl)

fn (Gen) defer_stmt #

fn (mut f Gen) defer_stmt(node ast.DeferStmt)

fn (Gen) dump_expr #

fn (mut f Gen) dump_expr(node ast.DumpExpr)

fn (Gen) enum_decl #

fn (mut f Gen) enum_decl(node ast.EnumDecl)

fn (Gen) enum_val #

fn (mut f Gen) enum_val(node ast.EnumVal)

fn (Gen) error #

fn (mut g Gen) error(s string)

fn (Gen) expr #

fn (mut f Gen) expr(node_ ast.Expr)

=== General Expr-related methods and helpers ===//

fn (Gen) expr_stmt #

fn (mut f Gen) expr_stmt(node ast.ExprStmt)

fn (Gen) fn_decl #

fn (mut f Gen) fn_decl(node ast.FnDecl)

fn (Gen) fn_type_decl #

fn (mut f Gen) fn_type_decl(node ast.FnTypeDecl)

fn (Gen) for_c_stmt #

fn (mut f Gen) for_c_stmt(node ast.ForCStmt)

fn (Gen) for_in_stmt #

fn (mut f Gen) for_in_stmt(node ast.ForInStmt)

fn (Gen) for_stmt #

fn (mut f Gen) for_stmt(node ast.ForStmt)

fn (Gen) global_decl #

fn (mut f Gen) global_decl(node ast.GlobalDecl)

fn (Gen) go_expr #

fn (mut f Gen) go_expr(node ast.GoExpr)

fn (Gen) goto_label #

fn (mut f Gen) goto_label(node ast.GotoLabel)

fn (Gen) goto_stmt #

fn (mut f Gen) goto_stmt(node ast.GotoStmt)

fn (Gen) hash_stmt #

fn (mut f Gen) hash_stmt(node ast.HashStmt)

fn (Gen) ident #

fn (mut f Gen) ident(node ast.Ident)

fn (Gen) if_expr #

fn (mut f Gen) if_expr(node ast.IfExpr)

fn (Gen) if_guard_expr #

fn (mut f Gen) if_guard_expr(node ast.IfGuardExpr)

fn (Gen) imp_stmt_str #

fn (f Gen) imp_stmt_str(imp ast.Import) string

fn (Gen) imports #

fn (mut f Gen) imports(imports []ast.Import)

fn (Gen) index_expr #

fn (mut f Gen) index_expr(node ast.IndexExpr)

fn (Gen) infix_expr #

fn (mut f Gen) infix_expr(node ast.InfixExpr)

fn (Gen) interface_decl #

fn (mut f Gen) interface_decl(node ast.InterfaceDecl)

fn (Gen) interface_field #

fn (mut f Gen) interface_field(field ast.StructField)

fn (Gen) interface_method #

fn (mut f Gen) interface_method(method ast.FnDecl)

fn (Gen) is_ref_type #

fn (mut f Gen) is_ref_type(node ast.IsRefType)

fn (Gen) likely #

fn (mut f Gen) likely(node ast.Likely)

fn (Gen) lock_expr #

fn (mut f Gen) lock_expr(node ast.LockExpr)

fn (Gen) map_init #

fn (mut f Gen) map_init(node ast.MapInit)

fn (Gen) mark_import_as_used #

fn (mut f Gen) mark_import_as_used(name string)

name is a function (foo.bar()) or type (foo.Bar{})

fn (Gen) mark_types_import_as_used #

fn (mut f Gen) mark_types_import_as_used(typ ast.Type)

=== Import-related methods ===//

fn (Gen) match_expr #

fn (mut f Gen) match_expr(node ast.MatchExpr)

fn (Gen) module_stmt #

fn (mut f Gen) module_stmt(mod ast.Module)

fn (Gen) no_cur_mod #

fn (mut f Gen) no_cur_mod(typename string) string

fn (Gen) node_str #

fn (mut f Gen) node_str(node ast.Node) string

fn (Gen) offset_of #

fn (mut f Gen) offset_of(node ast.OffsetOf)

fn (Gen) or_expr #

fn (mut f Gen) or_expr(node ast.OrExpr)

fn (Gen) par_expr #

fn (mut f Gen) par_expr(node ast.ParExpr)

fn (Gen) postfix_expr #

fn (mut f Gen) postfix_expr(node ast.PostfixExpr)

fn (Gen) prefix_expr #

fn (mut f Gen) prefix_expr(node ast.PrefixExpr)

fn (Gen) process_file_imports #

fn (mut f Gen) process_file_imports(file &ast.File)

fn (Gen) range_expr #

fn (mut f Gen) range_expr(node ast.RangeExpr)

fn (Gen) remove_new_line #

fn (mut f Gen) remove_new_line(cfg RemoveNewLineConfig)

fn (Gen) return_stmt #

fn (mut f Gen) return_stmt(node ast.Return)

fn (Gen) select_expr #

fn (mut f Gen) select_expr(node ast.SelectExpr)

fn (Gen) selector_expr #

fn (mut f Gen) selector_expr(node ast.SelectorExpr)

fn (Gen) set_current_module_name #

fn (mut f Gen) set_current_module_name(cmodname string)

=== Module handling helper methods ===//

fn (Gen) short_module #

fn (mut f Gen) short_module(name string) string

foo.bar.fn() => bar.fn()

fn (Gen) single_line_attrs #

fn (mut f Gen) single_line_attrs(attrs []ast.Attr, options AttrsOptions)

fn (Gen) size_of #

fn (mut f Gen) size_of(node ast.SizeOf)

fn (Gen) spawn_expr #

fn (mut f Gen) spawn_expr(node ast.SpawnExpr)

fn (Gen) sql_expr #

fn (mut f Gen) sql_expr(node ast.SqlExpr)

fn (Gen) sql_stmt #

fn (mut f Gen) sql_stmt(node ast.SqlStmt)

fn (Gen) sql_stmt_line #

fn (mut f Gen) sql_stmt_line(node ast.SqlStmtLine)

fn (Gen) stmt #

fn (mut f Gen) stmt(node ast.Stmt)

fn (Gen) stmts #

fn (mut f Gen) stmts(stmts []ast.Stmt)

=== General Stmt-related methods and helpers ===//

fn (Gen) string_inter_literal #

fn (mut f Gen) string_inter_literal(node ast.StringInterLiteral)

fn (Gen) string_literal #

fn (mut f Gen) string_literal(node ast.StringLiteral)

fn (Gen) struct_decl #

fn (mut f Gen) struct_decl(node ast.StructDecl)

fn (Gen) struct_init #

fn (mut f Gen) struct_init(node ast.StructInit)

fn (Gen) sum_type_decl #

fn (mut f Gen) sum_type_decl(node ast.SumTypeDecl)

fn (Gen) type_decl #

fn (mut f Gen) type_decl(node ast.TypeDecl)

fn (Gen) type_expr #

fn (mut f Gen) type_expr(node ast.TypeNode)

fn (Gen) type_of #

fn (mut f Gen) type_of(node ast.TypeOf)

fn (Gen) unsafe_expr #

fn (mut f Gen) unsafe_expr(node ast.UnsafeExpr)

fn (Gen) wrap_infix #

fn (mut f Gen) wrap_infix(start_pos int, start_len int, is_cond bool)

fn (Gen) wrap_long_line #

fn (mut f Gen) wrap_long_line(penalty_idx int, add_indent bool) bool

fn (Gen) write #

fn (mut f Gen) write(s string)

=== Basic buffer write operations ===//

fn (Gen) writeln #

fn (mut f Gen) writeln(s string)

struct RemoveNewLineConfig #

@[params]
struct RemoveNewLineConfig {
pub:
	imports_buffer bool // Work on f.out_imports instead of f.out
}