Skip to content

v3.gen.v

fn format #

fn format(a &flat.FlatAst) string

format finds every trailing .file node in a and formats them in order, separated by a blank line. Useful when a single file was parsed on its own.

fn format_file #

fn format_file(a &flat.FlatAst, file_id flat.NodeId) string

format_file parses-independent convenience: format the file whose trailing .file node id is file_id within a.

fn format_with_options #

fn format_with_options(a &flat.FlatAst, options FormatOptions) string

format_with_options formats every trailing file node in a with options.

fn Gen.new #

fn Gen.new() &Gen

Gen.new returns a fresh formatter.

struct FormatOptions #

struct FormatOptions {
pub:
	is_debug   bool
	is_new_int bool
	backend    string = 'c'
}

FormatOptions controls optional formatter output.

struct Gen #

struct Gen {
mut:
	a               &flat.FlatAst = unsafe { nil }
	out             strings.Builder
	indent          int
	on_newline      bool
	in_init         bool
	file_id         int
	source          string
	comments        []flat.Comment
	comment_i       int
	source_end      int = -1
	migrate_json2   bool
	json_qualifier  string
	json_import_id  int = -1
	skip_decls      map[int]bool
	selective_json  bool
	implied_imports []string
	in_array_init   bool
	is_debug        bool
	is_new_int      bool
	is_translated   bool
	in_c_function   bool
	backend         string = 'c'
	formatter_types map[string]FormatterTypeSource
	array_breaks    []bool
	array_depth     int
	// suppress_mut skips the `mut ` prefix on an assignment (used for C-style
	// `for` loop init clauses, whose variable the parser always marks mutable).
	suppress_mut bool
	// attrs maps a declaration node id to its `@[...]` attribute strings. The parser stores
	// attributes on a separate floating `.directive` node rather than as a child, so they are
	// collected up-front in collect_attrs. attr_sources retains formatter-only source groups.
	attrs        map[int][]string
	attr_sources map[int]string
}

Gen holds the formatter state for one output buffer.

fn (Gen) reset #

fn (mut g Gen) reset()

reset clears the buffer so a Gen instance can be reused.

fn (Gen) gen_file #

fn (mut g Gen) gen_file(a &flat.FlatAst, file_id flat.NodeId) string

gen_file formats the top-level declarations of the given trailing file node.

fn (Gen) output_string #

fn (mut g Gen) output_string() string

output_string returns the generated V source code.