Skip to content

v.reflection #

fn get_aliases #

fn get_aliases() []Type

get_aliases returns the registered aliases

fn get_enums #

fn get_enums() []Type

get_enums returns the registered enums

fn get_funcs #

fn get_funcs() []Function

get_functions returns the functions built with V source

fn get_interfaces #

fn get_interfaces() []Interface

get_interfaces returns the registered aliases

fn get_modules #

fn get_modules() []Module

get_modules returns the module name built with V source

fn get_string_by_idx #

fn get_string_by_idx(idx int) string

API module

fn get_structs #

fn get_structs() []Type

fn get_sum_types #

fn get_sum_types() []Type

get_sum_types returns the registered sum types

fn get_type #

fn get_type(idx int) ?Type

fn get_type_symbol #

fn get_type_symbol(idx int) ?TypeSymbol

fn get_type_symbols #

fn get_type_symbols() []TypeSymbol

get_type_symbol returns the registered type symbols

fn get_types #

fn get_types() []Type

get_types returns the registered types

fn type_name #

fn type_name(idx int) string

Type API

fn type_of #

fn type_of[T](val T) Type

type_of returns the type info of the passed value

fn type_symbol_name #

fn type_symbol_name(idx int) string

Type Symbol API

type TypeInfo #

type TypeInfo = Alias
	| Array
	| ArrayFixed
	| Enum
	| Function
	| Interface
	| Map
	| MultiReturn
	| None
	| Struct
	| SumType

fn (VType) has_flag #

fn (t VType) has_flag(flag VTypeFlag) bool

return true if flag is set on t

fn (VType) idx #

fn (t VType) idx() int

fn (VType) str #

fn (t VType) str() string

fn (VType) is_ptr #

fn (t VType) is_ptr() bool

return true if t is a pointer (nr_muls>0)

enum VKind #

enum VKind {
	placeholder
	void
	voidptr
	byteptr
	charptr
	i8
	i16
	i32
	i64
	int
	isize
	u8
	u16
	u32
	u64
	usize
	f32
	f64
	char
	rune
	bool
	none_
	string
	array
	array_fixed
	map
	chan
	any
	struct_
	generic_inst
	multi_return
	sum_type
	alias
	enum_
	function
	interface_
	float_literal
	int_literal
	aggregate
	thread
}

enum VLanguage #

enum VLanguage {
	v
	c
	js
	amd64 // aka x86_64
	i386
	arm64 // 64-bit arm
	arm32 // 32-bit arm
	rv64 // 64-bit risc-v
	rv32 // 32-bit risc-v
	wasm32
}

enum VTypeFlag #

enum VTypeFlag {
	option
	result
	variadic
	generic
	shared_f
	atomic_f
}

max of 8

struct Alias #

struct Alias {
pub:
	parent_idx int       // parent type idx
	language   VLanguage // language
}

struct Array #

struct Array {
pub:
	nr_dims   int // nr of dimensions
	elem_type int // elem type idx
}

struct ArrayFixed #

struct ArrayFixed {
pub:
	size      int // array size
	elem_type int // elem type idx
}

struct Enum #

struct Enum {
pub:
	vals    []string // enum values
	is_flag bool     // is flag?
}

struct Function #

struct Function {
pub:
	mod_name     string        // module name
	name         string        // function/method name
	args         []FunctionArg // function/method args
	file_idx     int   // source file name
	line_start   int   // decl start line
	line_end     int   // decl end line
	is_variadic  bool  // is variadic?
	return_typ   VType // return type idx
	receiver_typ VType // receiver type idx (is a method)
	is_pub       bool  // is pub?
}

struct FunctionArg #

struct FunctionArg {
pub:
	name   string // argument name
	typ    VType  // argument type idx
	is_mut bool   // is mut?
}

struct Interface #

struct Interface {
pub:
	name       string        // interface name
	methods    []Function    // methods
	fields     []StructField // fields
	is_generic bool // is generic?
}

struct Map #

struct Map {
pub:
	key_type   VType // key type
	value_type VType // value type
}

struct Module #

struct Module {
pub:
	name string // module name
}

struct MultiReturn #

struct MultiReturn {
pub:
	types []VType // types
}

struct None #

struct None {
pub:
	parent_idx int
}

struct Reflection #

@[heap]
@[minify]
struct Reflection {
pub mut:
	modules      []Module
	funcs        []Function
	types        []Type
	type_symbols []TypeSymbol
	enums        []Enum
	interfaces   []Interface
	strings      map[int]string
}

struct Struct #

struct Struct {
pub:
	parent_idx int           // parent type
	attrs      []string      // struct attrs
	fields     []StructField // fields
}

struct StructField #

struct StructField {
pub:
	name   string   // field name
	typ    VType    // type
	attrs  []string // field attrs
	is_pub bool     // is pub?
	is_mut bool     // is mut?
}

struct SumType #

struct SumType {
pub:
	parent_idx int     // parent type
	variants   []VType // variant type
}

struct Type #

struct Type {
pub:
	name string     // type name
	idx  int        // type idx
	sym  TypeSymbol // type symbol
}

struct TypeSymbol #

struct TypeSymbol {
pub:
	name       string     // symbol name
	idx        int        // symbol idx
	parent_idx int        // symbol parent idx
	language   VLanguage  // language
	kind       VKind      // kind
	info       TypeInfo   // info
	methods    []Function // methods
}