Skip to content

v.type_resolver #

fn TypeResolver.new #

fn TypeResolver.new(table &ast.Table, resolver &IResolverType) &TypeResolver

interface IResolverType #

interface IResolverType {
mut:
	file &ast.File
	unwrap_generic(t ast.Type) ast.Type
}

Interface for cgen / checker instance

struct DummyResolver #

struct DummyResolver {
mut:
	file &ast.File = unsafe { nil }
}

struct ResolverInfo #

@[minify]
struct ResolverInfo {
pub mut:
	saved_type_map map[string]ast.Type

	// loop id for loop distinction
	comptime_loop_id int
	// $for
	inside_comptime_for bool
	// .variants
	comptime_for_variant_var string
	// .fields
	comptime_for_field_var   string
	comptime_for_field_type  ast.Type
	comptime_for_field_value ast.StructField
	// .values
	comptime_for_enum_var string
	// .attributes
	comptime_for_attr_var string
	// .methods
	comptime_for_method_var      string
	comptime_for_method          &ast.Fn = unsafe { nil }
	comptime_for_method_ret_type ast.Type
	// .args
	comptime_for_method_param_var string
}

fn (ResolverInfo) check_comptime_is_field_selector #

fn (t &ResolverInfo) check_comptime_is_field_selector(node ast.SelectorExpr) bool

check_comptime_is_field_selector checks if the SelectorExpr is related to $for variable

fn (ResolverInfo) check_comptime_is_field_selector_bool #

fn (t &ResolverInfo) check_comptime_is_field_selector_bool(node ast.SelectorExpr) bool

check_comptime_is_field_selector_bool checks if the SelectorExpr is related to field.is_* boolean fields

fn (ResolverInfo) get_ct_type_var #

fn (t &ResolverInfo) get_ct_type_var(node ast.Expr) ast.ComptimeVarKind

get_ct_type_var gets the comptime type of the variable (.generic_param, .key_var, etc)

fn (ResolverInfo) has_comptime_expr #

fn (t &ResolverInfo) has_comptime_expr(node ast.Expr) bool

has_comptime_expr checks if the expr contains some comptime expr

fn (ResolverInfo) is_comptime #

fn (t &ResolverInfo) is_comptime(node ast.Expr) bool

is_comptime checks if the node is related to a comptime marked variable

fn (ResolverInfo) is_comptime_expr #

fn (t &ResolverInfo) is_comptime_expr(node ast.Expr) bool

is_comptime_expr checks if the node is related to a comptime expr

fn (ResolverInfo) is_comptime_selector_field_name #

fn (t &ResolverInfo) is_comptime_selector_field_name(node ast.SelectorExpr, field_name string) bool

is_comptime_selector_field_name checks if the SelectorExpr is related to $for variable accessing specific field name provided by field_name

fn (ResolverInfo) is_comptime_selector_type #

fn (t &ResolverInfo) is_comptime_selector_type(node ast.SelectorExpr) bool

is_comptime_selector_type checks if the SelectorExpr is related to $for variable accessing .typ field

fn (ResolverInfo) is_comptime_variant_var #

fn (t &ResolverInfo) is_comptime_variant_var(node ast.Ident) bool

is_comptime_variant_var checks if the node is related to a comptime variant variable

struct TypeResolver #

@[heap]
struct TypeResolver {
pub mut:
	resolver   IResolverType = DummyResolver{}
	table      &ast.Table    = unsafe { nil }
	info       ResolverInfo        // current info
	info_stack []ResolverInfo      // stores the values from the above on each $for loop, to make nesting them easier
	type_map   map[string]ast.Type // map for storing dynamic resolved types on checker/gen phase
}

fn (TypeResolver) get_comptime_selector_bool_field #

fn (mut t TypeResolver) get_comptime_selector_bool_field(field_name string) bool

get_comptime_selector_bool_field evaluates the bool value for field.is_* fields

fn (TypeResolver) get_comptime_selector_type #

fn (mut t TypeResolver) get_comptime_selector_type(node ast.ComptimeSelector, default_type ast.Type) ast.Type

get_comptime_selector_type retrieves the var.$(field.name) type when field_name is 'name' otherwise default_type is returned

fn (TypeResolver) get_comptime_selector_var_type #

fn (mut t TypeResolver) get_comptime_selector_var_type(node ast.ComptimeSelector) (ast.StructField, string)

fn (TypeResolver) get_ct_type_or_default #

fn (t &TypeResolver) get_ct_type_or_default(key string, default_type ast.Type) ast.Type

get_ct_type_or_default retrieves a comptime variable value on type map or default_type otherwise

fn (TypeResolver) get_expr_type_or_default #

fn (mut t TypeResolver) get_expr_type_or_default(node ast.Expr, default_typ ast.Type) ast.Type

get_expr_type_or_default computes the ast node type regarding its or_expr if its comptime var otherwise default_typ is returned

fn (TypeResolver) get_generic_array_element_type #

fn (t &TypeResolver) get_generic_array_element_type(array ast.Array) ast.Type

get_generic_array_element_type retrieves the plain element type from a nested array [][]T -> T

fn (TypeResolver) get_generic_array_fixed_element_type #

fn (t &TypeResolver) get_generic_array_fixed_element_type(array ast.ArrayFixed) ast.Type

get_generic_array_fixed_element_type retrieves the plain element type from a nested fixed array [N][N]T -> T

fn (TypeResolver) get_type #

fn (mut t TypeResolver) get_type(node ast.Expr) ast.Type

get_type retrieves the actual type from a comptime related ast node

fn (TypeResolver) get_type_from_comptime_var #

fn (t &TypeResolver) get_type_from_comptime_var(var ast.Ident) ast.Type

get_type_from_comptime_var retrives the comptime type related to $for variable

fn (TypeResolver) get_type_or_default #

fn (mut t TypeResolver) get_type_or_default(node ast.Expr, default_typ ast.Type) ast.Type

get_type_or_default retries the comptime value if the AST node is related to comptime otherwise default_typ is returned

fn (TypeResolver) is_comptime_type #

fn (t &TypeResolver) is_comptime_type(x ast.Type, y ast.ComptimeType) bool

is_comptime_type check if the type is compatible with the supplied ComptimeType

fn (TypeResolver) is_generic_expr #

fn (t &TypeResolver) is_generic_expr(node ast.Expr) bool

is_generic_expr checks if the expr relies on fn generic argument

fn (TypeResolver) is_generic_param_var #

fn (t &TypeResolver) is_generic_param_var(node ast.Expr) bool

is_generic_param_var checks if the var is related to generic parameter

fn (TypeResolver) resolve_args #

fn (mut t TypeResolver) resolve_args(cur_fn &ast.FnDecl, func &ast.Fn, mut node_ ast.CallExpr, concrete_types []ast.Type) map[int]ast.Type

resolve_args resolves the ast node types dynamically depending on its special meaning

fn (TypeResolver) resolve_fn_generic_args #

fn (mut t TypeResolver) resolve_fn_generic_args(cur_fn &ast.FnDecl, func &ast.Fn, mut node ast.CallExpr) (bool, []ast.Type)

fn (TypeResolver) unwrap_generic_expr #

fn (mut ct TypeResolver) unwrap_generic_expr(expr ast.Expr, default_typ ast.Type) ast.Type

unwrap_generic_expr retrieves the concrete type from a generic expr

fn (TypeResolver) update_ct_type #

fn (mut t TypeResolver) update_ct_type(key string, var_type ast.Type)

update_ct_type updates current type for specific key (comptime vars) var iteration vars, comptime vars var.typ => for comptime $for variables var.unaliased_typ => for comptime $for variables var.return_type => for .method return type