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 flatten #

fn flatten(files []ast.File) FlatAst

fn FlatAst.new #

fn FlatAst.new() FlatAst

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

enum NodeKind #

enum NodeKind as u8 {
	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
}

enum Op #

enum Op as u8 {
	none
	plus
	minus
	mul
	div
	mod
	eq
	ne
	lt
	gt
	le
	ge
	amp
	pipe
	xor
	left_shift
	right_shift
	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
	inc
	dec
	dot
	arrow
}

struct FlatAst #

@[heap]
struct FlatAst {
pub mut:
	nodes           []Node
	children        []NodeId
	user_code_start int
}

fn (FlatAst) add #

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

fn (FlatAst) add_val #

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

fn (FlatAst) add_node #

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

fn (FlatAst) begin_children #

fn (mut a FlatAst) begin_children() int

fn (FlatAst) add_child #

fn (mut a FlatAst) add_child(id NodeId)

fn (FlatAst) child #

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

fn (FlatAst) child_node #

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

fn (FlatAst) node #

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

fn (FlatAst) children_of #

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

fn (FlatAst) print_tree #

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

struct Node #

struct Node {
pub mut:
	value string
	typ   string
pub:
	pos            token.Pos
	children_start i32
	children_count i16
	kind           NodeKind
	op             Op
}