v.checker #
Constants #
const (
valid_comptime_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu',
'qnx', 'linux', 'freebsd', 'openbsd', 'netbsd', 'bsd', 'dragonfly', 'android', 'termux',
'solaris', 'haiku', 'serenity', 'vinix']
valid_comptime_compression_types = ['none', 'zlib']
valid_comptime_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
valid_comptime_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32']
valid_comptime_if_cpu_features = ['x64', 'x32', 'little_endian', 'big_endian']
valid_comptime_if_other = ['apk', 'js', 'debug', 'prod', 'test', 'glibc', 'prealloc',
'no_bounds_checking', 'freestanding', 'threads', 'js_node', 'js_browser', 'js_freestanding',
'interpreter', 'es5', 'profile', 'wasm32_emscripten']
valid_comptime_not_user_defined = all_valid_comptime_idents()
array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice',
'sort', 'contains', 'index', 'wait', 'any', 'all', 'first', 'last', 'pop']
array_builtin_methods_chk = token.new_keywords_matcher_from_array_trie(array_builtin_methods)
// TODO: remove `byte` from this list when it is no longer supported
reserved_type_names = ['byte', 'bool', 'char', 'i8', 'i16', 'int', 'i64', 'u8',
'u16', 'u32', 'u64', 'f32', 'f64', 'map', 'string', 'rune']
reserved_type_names_chk = token.new_keywords_matcher_from_array_trie(reserved_type_names)
vroot_is_deprecated_message = '@VROOT is deprecated, use @VMODROOT or @VEXEROOT instead'
)
fn new_checker #
fn new_checker(table &ast.Table, pref &pref.Preferences) &Checker
struct Checker #
struct Checker {
pref &pref.Preferences = unsafe { nil } // Preferences shared from V struct
pub mut:
table &ast.Table = unsafe { nil }
file &ast.File = unsafe { nil }
nr_errors int
nr_warnings int
nr_notices int
errors []errors.Error
warnings []errors.Warning
notices []errors.Notice
error_lines []int // to avoid printing multiple errors for the same line
expected_type ast.Type
expected_or_type ast.Type // fn() or { 'this type' } eg. string. expected or block type
expected_expr_type ast.Type // if/match is_expr: expected_type
mod string // current module name
const_var &ast.ConstField = unsafe { nil } // the current constant, when checking const declarations
const_deps []string
const_names []string
global_names []string
locked_names []string // vars that are currently locked
rlocked_names []string // vars that are currently read-locked
in_for_count int // if checker is currently in a for loop
should_abort bool // when too many errors/warnings/notices are accumulated, .should_abort becomes true. It is checked in statement/expression loops, so the checker can return early, instead of wasting time.
returns bool
scope_returns bool
is_builtin_mod bool // true inside the 'builtin', 'os' or 'strconv' modules; TODO: remove the need for special casing this
is_just_builtin_mod bool // true only inside 'builtin'
is_generated bool // true for `[generated] module xyz` .v files
inside_unsafe bool // true inside `unsafe {}` blocks
inside_const bool // true inside `const ( ... )` blocks
inside_anon_fn bool // true inside `fn() { ... }()`
inside_ref_lit bool // true inside `a := &something`
inside_defer bool // true inside `defer {}` blocks
inside_fn_arg bool // `a`, `b` in `a.f(b)`
inside_ct_attr bool // true inside `[if expr]`
inside_x_is_type bool // true inside the Type expression of `if x is Type {`
inside_comptime_for_field bool
inside_for_in_any_cond bool
skip_flags bool // should `#flag` and `#include` be skipped
fn_level int // 0 for the top level, 1 for `fn abc() {}`, 2 for a nested fn, etc
smartcast_mut_pos token.Pos // match mut foo, if mut foo is Foo
smartcast_cond_pos token.Pos // match cond
ct_cond_stack []ast.Expr
mut:
stmt_level int // the nesting level inside each stmts list;
// .stmt_level is used to check for `evaluated but not used` ExprStmts like `1 << 1`
// 1 for statements directly at each inner scope level;
// increases for `x := if cond { statement_list1} else {statement_list2}`;
// increases for `x := optfn() or { statement_list3 }`;
files []ast.File
expr_level int // to avoid infinite recursion segfaults due to compiler bugs
cur_orm_ts ast.TypeSymbol
error_details []string
vmod_file_content string // needed for @VMOD_FILE, contents of the file, *NOT its path**
loop_label string // set when inside a labelled for loop
vweb_gen_types []ast.Type // vweb route checks
timers &util.Timers = util.get_timers()
for_in_any_val_type ast.Type
comptime_fields_default_type ast.Type
comptime_fields_type map[string]ast.Type
fn_scope &ast.Scope = unsafe { nil }
main_fn_decl_node ast.FnDecl
match_exhaustive_cutoff_limit int = 10
is_last_stmt bool
prevent_sum_type_unwrapping_once bool // needed for assign new values to sum type, stopping unwrapping then
using_new_err_struct bool
need_recheck_generic_fns bool // need recheck generic fns because there are cascaded nested generic fn
inside_sql bool // to handle sql table fields pseudo variables
inside_selector_expr bool
inside_println_arg bool
inside_decl_rhs bool
inside_if_guard bool // true inside the guard condition of `if x := opt() {}`
comptime_call_pos int // needed for correctly checking use before decl for templates
goto_labels map[string]int // to check for unused goto labels
}
fn (Checker) add_error_detail #
fn (mut c Checker) add_error_detail(s string)
call this before calling error or warn
fn (Checker) add_error_detail_with_pos #
fn (mut c Checker) add_error_detail_with_pos(msg string, pos token.Pos)
fn (Checker) add_instruction_for_optional_type #
fn (mut c Checker) add_instruction_for_optional_type()
fn (Checker) add_instruction_for_result_type #
fn (mut c Checker) add_instruction_for_result_type()
fn (Checker) alias_type_decl #
fn (mut c Checker) alias_type_decl(node ast.AliasTypeDecl)
fn (Checker) array_init #
fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type
fn (Checker) assign_stmt #
fn (mut c Checker) assign_stmt(mut node ast.AssignStmt)
TODO 600 line function
fn (Checker) builtin_args #
fn (mut c Checker) builtin_args(mut node ast.CallExpr, fn_name string, func ast.Fn)
fn (Checker) call_expr #
fn (mut c Checker) call_expr(mut node ast.CallExpr) ast.Type
fn (Checker) cast_expr #
fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type
for bit_size, array in ast.x86_no_number_register_list { if name in array { return c.table.bitsize_to_type(bit_size) } } for bit_size, array in ast.x86_with_number_register_list { if name in array { return c.table.bitsize_to_type(bit_size) } } c.error('invalid register name: `$name`', node.pos) return ast.void_type }
fn (Checker) chan_init #
fn (mut c Checker) chan_init(mut node ast.ChanInit) ast.Type
fn (Checker) change_current_file #
fn (mut c Checker) change_current_file(file &ast.File)
fn (Checker) check #
fn (mut c Checker) check(ast_file_ &ast.File)
fn (Checker) check2 #
fn (mut c Checker) check2(ast_file &ast.File) []errors.Error
not used right now
fn (Checker) check_basic #
fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool
fn (Checker) check_dup_keys #
fn (mut c Checker) check_dup_keys(node &ast.MapInit, i int)
fn (Checker) check_expected #
fn (mut c Checker) check_expected(got ast.Type, expected ast.Type) ?
fn (Checker) check_expected_arg_count #
fn (mut c Checker) check_expected_arg_count(mut node ast.CallExpr, f &ast.Fn) ?
fn (Checker) check_expected_call_arg #
fn (mut c Checker) check_expected_call_arg(got ast.Type, expected_ ast.Type, language ast.Language, arg ast.CallArg) ?
fn (Checker) check_expr_opt_call #
fn (mut c Checker) check_expr_opt_call(expr ast.Expr, ret_type ast.Type) ast.Type
return the actual type of the expression, once the optional is handled
fn (Checker) check_files #
fn (mut c Checker) check_files(ast_files []&ast.File)
fn (Checker) check_matching_function_symbols #
fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSymbol, exp_type_sym &ast.TypeSymbol) bool
fn (Checker) check_or_expr #
fn (mut c Checker) check_or_expr(node ast.OrExpr, ret_type ast.Type, expr_return_type ast.Type)
fn (Checker) check_scope_vars #
fn (mut c Checker) check_scope_vars(sc &ast.Scope)
fn (Checker) check_types #
fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool
TODO: promote(), check_types(), symmetric_check() and check() overlap - should be rearranged
fn (Checker) concat_expr #
fn (mut c Checker) concat_expr(mut node ast.ConcatExpr) ast.Type
fn (Checker) const_decl #
fn (mut c Checker) const_decl(mut node ast.ConstDecl)
fn (Checker) ensure_sumtype_array_has_default_value #
fn (mut c Checker) ensure_sumtype_array_has_default_value(node ast.ArrayInit)
fn (Checker) enum_decl #
fn (mut c Checker) enum_decl(mut node ast.EnumDecl)
fn (Checker) enum_val #
fn (mut c Checker) enum_val(mut node ast.EnumVal) ast.Type
.green or Color.green If a short form is used, expected_type needs to be an enum
with this value.
fn (Checker) error #
fn (mut c Checker) error(message string, pos token.Pos)
fn (Checker) expand_iface_embeds #
fn (mut c Checker) expand_iface_embeds(idecl &ast.InterfaceDecl, level int, iface_embeds []ast.InterfaceEmbedding) []ast.InterfaceEmbedding
fn (Checker) expr #
fn (mut c Checker) expr(node_ ast.Expr) ast.Type
TODO node must be mut
fn (Checker) fail_if_unreadable #
fn (mut c Checker) fail_if_unreadable(expr ast.Expr, typ ast.Type, what string)
fn (Checker) find_unreachable_statements_after_noreturn_calls #
fn (mut c Checker) find_unreachable_statements_after_noreturn_calls(stmts []ast.Stmt)
fn (Checker) fn_call #
fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.Type
fn (Checker) fn_type_decl #
fn (mut c Checker) fn_type_decl(node ast.FnTypeDecl)
fn (Checker) get_base_name #
fn (mut c Checker) get_base_name(node &ast.Expr) string
fn (Checker) get_default_fmt #
fn (mut c Checker) get_default_fmt(ftyp ast.Type, typ ast.Type) u8
fn (Checker) goto_stmt #
fn (mut c Checker) goto_stmt(node ast.GotoStmt)
fn (Checker) ident #
fn (mut c Checker) ident(mut node ast.Ident) ast.Type
fn (Checker) if_expr #
fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type
fn (Checker) index_expr #
fn (mut c Checker) index_expr(mut node ast.IndexExpr) ast.Type
fn (Checker) infer_fn_generic_types #
fn (mut c Checker) infer_fn_generic_types(func ast.Fn, mut node ast.CallExpr)
fn (Checker) infix_expr #
fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type
fn (Checker) int_lit #
fn (mut c Checker) int_lit(mut node ast.IntegerLiteral) ast.Type
fn (Checker) interface_decl #
fn (mut c Checker) interface_decl(mut node ast.InterfaceDecl)
fn (Checker) invalid_operator_error #
fn (mut c Checker) invalid_operator_error(op token.Kind, left_type ast.Type, right_type ast.Type, pos token.Pos)
fn (Checker) lock_expr #
fn (mut c Checker) lock_expr(mut node ast.LockExpr) ast.Type
fn (Checker) map_init #
fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type
fn (Checker) mark_as_referenced #
fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool)
fn (Checker) match_expr #
fn (mut c Checker) match_expr(mut node ast.MatchExpr) ast.Type
fn (Checker) method_call #
fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type
fn (Checker) note #
fn (mut c Checker) note(message string, pos token.Pos)
fn (Checker) offset_of #
fn (mut c Checker) offset_of(node ast.OffsetOf) ast.Type
fn (Checker) postfix_expr #
fn (mut c Checker) postfix_expr(mut node ast.PostfixExpr) ast.Type
fn (Checker) prefix_expr #
fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type
fn (Checker) promote #
fn (mut c Checker) promote(left_type ast.Type, right_type ast.Type) ast.Type
fn (Checker) promote_keeping_aliases #
fn (mut c Checker) promote_keeping_aliases(left_type ast.Type, right_type ast.Type, left_kind ast.Kind, right_kind ast.Kind) ast.Type
fn (Checker) return_stmt #
fn (mut c Checker) return_stmt(mut node ast.Return)
TODO: non deferred
fn (Checker) select_expr #
fn (mut c Checker) select_expr(mut node ast.SelectExpr) ast.Type
fn (Checker) selector_expr #
fn (mut c Checker) selector_expr(mut node ast.SelectorExpr) ast.Type
fn (Checker) string_inter_lit #
fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) ast.Type
fn (Checker) string_lit #
fn (mut c Checker) string_lit(mut node ast.StringLiteral) ast.Type
unicode character literals are limited to a maximum value of 0x10ffff https://stackoverflow.com/questions/52203351/why-unicode-is-restricted-to-0x10ffff
fn (Checker) struct_decl #
fn (mut c Checker) struct_decl(mut node ast.StructDecl)
fn (Checker) struct_init #
fn (mut c Checker) struct_init(mut node ast.StructInit) ast.Type
fn (Checker) sum_type_decl #
fn (mut c Checker) sum_type_decl(node ast.SumTypeDecl)
fn (Checker) symmetric_check #
fn (mut c Checker) symmetric_check(left ast.Type, right ast.Type) bool
fn (Checker) type_decl #
fn (mut c Checker) type_decl(node ast.TypeDecl)
fn (Checker) unsafe_expr #
fn (mut c Checker) unsafe_expr(mut node ast.UnsafeExpr) ast.Type
fn (Checker) unwrap_generic #
fn (mut c Checker) unwrap_generic(typ ast.Type) ast.Type
fn (Checker) warn #
fn (mut c Checker) warn(s string, pos token.Pos)
- Constants
- fn new_checker
- struct Checker
- fn add_error_detail
- fn add_error_detail_with_pos
- fn add_instruction_for_optional_type
- fn add_instruction_for_result_type
- fn alias_type_decl
- fn array_init
- fn assign_stmt
- fn builtin_args
- fn call_expr
- fn cast_expr
- fn chan_init
- fn change_current_file
- fn check
- fn check2
- fn check_basic
- fn check_dup_keys
- fn check_expected
- fn check_expected_arg_count
- fn check_expected_call_arg
- fn check_expr_opt_call
- fn check_files
- fn check_matching_function_symbols
- fn check_or_expr
- fn check_scope_vars
- fn check_types
- fn concat_expr
- fn const_decl
- fn ensure_sumtype_array_has_default_value
- fn enum_decl
- fn enum_val
- fn error
- fn expand_iface_embeds
- fn expr
- fn fail_if_unreadable
- fn find_unreachable_statements_after_noreturn_calls
- fn fn_call
- fn fn_type_decl
- fn get_base_name
- fn get_default_fmt
- fn goto_stmt
- fn ident
- fn if_expr
- fn index_expr
- fn infer_fn_generic_types
- fn infix_expr
- fn int_lit
- fn interface_decl
- fn invalid_operator_error
- fn lock_expr
- fn map_init
- fn mark_as_referenced
- fn match_expr
- fn method_call
- fn note
- fn offset_of
- fn postfix_expr
- fn prefix_expr
- fn promote
- fn promote_keeping_aliases
- fn return_stmt
- fn select_expr
- fn selector_expr
- fn string_inter_lit
- fn string_lit
- fn struct_decl
- fn struct_init
- fn sum_type_decl
- fn symmetric_check
- fn type_decl
- fn unsafe_expr
- fn unwrap_generic
- fn warn