Skip to content

v3.flat

Constants #

const empty_node = NodeId(-1)

fn child_count #

fn child_count(count int) i16

child_count converts a dynamic child count to Node's compact storage type.

fn node_kind_from_id #

fn node_kind_from_id(id int) NodeKind

node_kind_from_id converts node kind from id data for flat.

fn FlatAst.new #

fn FlatAst.new() FlatAst

new creates a FlatAst value for flat.

fn NodeKind.from #

fn NodeKind.from[W](input W) !NodeKind

fn Op.from #

fn Op.from[W](input W) !Op

type NodeId #

type NodeId = int

NodeId aliases node id values used by flat.

enum NodeKind #

enum NodeKind {
	empty
	// expressions
	int_literal
	float_literal
	bool_literal
	char_literal
	string_literal
	string_interp
	ident
	infix
	prefix
	postfix
	paren
	call
	selector
	index
	if_expr
	struct_init
	field_init
	array_literal
	array_init
	map_init
	fn_literal
	or_expr
	cast_expr
	as_expr
	enum_val
	assoc
	range
	nil_literal
	none_expr
	spawn_expr
	lock_expr
	lambda_expr
	sizeof_expr
	typeof_expr
	dump_expr
	offsetof_expr
	is_expr
	in_expr
	// statements
	expr_stmt
	assign
	decl_assign
	selector_assign
	index_assign
	return_stmt
	block
	for_stmt
	for_in_stmt
	break_stmt
	continue_stmt
	match_stmt
	match_branch
	defer_stmt
	assert_stmt
	goto_stmt
	label_stmt
	select_stmt
	select_branch
	comptime_if
	comptime_for
	asm_stmt
	// declarations
	fn_decl
	struct_decl
	field_decl
	global_decl
	const_decl
	const_field
	enum_decl
	enum_field
	type_decl
	interface_decl
	interface_field
	import_decl
	module_decl
	directive
	param
	c_fn_decl
	// top-level
	file
	sql_expr
}

NodeKind lists node kind values used by flat.

enum Op #

enum Op {
	none
	plus
	minus
	mul
	div
	mod
	eq
	ne
	lt
	gt
	le
	ge
	amp
	pipe
	xor
	left_shift
	right_shift
	right_shift_unsigned
	logical_and
	logical_or
	not
	bit_not
	assign
	plus_assign
	minus_assign
	mul_assign
	div_assign
	mod_assign
	amp_assign
	pipe_assign
	xor_assign
	left_shift_assign
	right_shift_assign
	right_shift_unsigned_assign
	inc
	dec
	dot
	arrow
}

Op lists op values used by flat.

struct FlatAst #

@[heap]
struct FlatAst {
pub mut:
	nodes           []Node
	children        []NodeId
	user_code_start int
	disabled_fns    map[string]bool
	export_fn_names map[string]string
	noreturn_fns    map[string]bool
}

FlatAst represents flat ast data used by flat.

fn (FlatAst) set_node_is_mut #

fn (mut a FlatAst) set_node_is_mut(id NodeId, is_mut bool)

set_node_is_mut updates a node's mut declaration marker in place.

fn (FlatAst) add #

fn (mut a FlatAst) add(kind NodeKind) NodeId

add updates add state for FlatAst.

fn (FlatAst) add_id #

fn (mut a FlatAst) add_id(kind_id int) NodeId

add_id updates add id state for FlatAst.

fn (FlatAst) add_val #

fn (mut a FlatAst) add_val(kind NodeKind, value string) NodeId

add_val updates add val state for FlatAst.

fn (FlatAst) add_val_id #

fn (mut a FlatAst) add_val_id(kind_id int, value string) NodeId

add_val_id updates add val id state for FlatAst.

fn (FlatAst) add_node #

fn (mut a FlatAst) add_node(node Node) NodeId

add_node updates add node state for FlatAst.

fn (FlatAst) begin_children #

fn (mut a FlatAst) begin_children() int

begin_children supports begin children handling for FlatAst.

fn (FlatAst) add_child #

fn (mut a FlatAst) add_child(id NodeId)

add_child updates add child state for FlatAst.

fn (FlatAst) child #

fn (a &FlatAst) child(node &Node, index int) NodeId

child supports child handling for FlatAst.

fn (FlatAst) child_node #

fn (a &FlatAst) child_node(node &Node, index int) &Node

child_node supports child node handling for FlatAst.

fn (FlatAst) node #

fn (a &FlatAst) node(id NodeId) &Node

node supports node handling for FlatAst.

fn (FlatAst) children_of #

fn (a &FlatAst) children_of(node &Node) []NodeId

children_of supports children of handling for FlatAst.

fn (FlatAst) print_tree #

fn (a &FlatAst) print_tree(id NodeId, indent int)

print_tree updates print tree state for FlatAst.

struct Node #

struct Node {
pub mut:
	value          string
	typ            string
	generic_params []string
	kind_id        int
	is_mut         bool
pub:
	pos            token.Pos
	children_start i32
	children_count i16
	kind           NodeKind
	op             Op
}

Node represents node data used by flat.

fn (Node) with_shifted_children #

fn (n Node) with_shifted_children(shift i32) Node

with_shifted_children returns a copy of the node whose children_start is moved by shift. children_start lives in the immutable section of Node, so callers that relocate a node's children block (e.g. the parallel-transform merge) build a fresh node instead of mutating in place.