1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: minor cleanup in the checker.v (#12945)

This commit is contained in:
yuyi 2021-12-23 21:02:09 +08:00 committed by GitHub
parent 546c388b02
commit d4f28c88b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,13 +54,13 @@ pub mut:
nr_errors int nr_errors int
nr_warnings int nr_warnings int
nr_notices int nr_notices int
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.
errors []errors.Error errors []errors.Error
warnings []errors.Warning warnings []errors.Warning
notices []errors.Notice notices []errors.Notice
error_lines []int // to avoid printing multiple errors for the same line error_lines []int // to avoid printing multiple errors for the same line
expected_type ast.Type expected_type ast.Type
expected_or_type ast.Type // fn() or { 'this type' } eg. string. expected or block type expected_or_type ast.Type // fn() or { 'this type' } eg. string. expected or block type
mod string // current module name
const_decl string const_decl string
const_deps []string const_deps []string
const_names []string const_names []string
@ -69,20 +69,20 @@ pub mut:
rlocked_names []string // vars that are currently read-locked rlocked_names []string // vars that are currently read-locked
in_for_count int // if checker is currently in a for loop in_for_count int // if checker is currently in a for loop
// checked_ident string // to avoid infinite checker loops // checked_ident string // to avoid infinite checker loops
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 returns bool
scope_returns bool scope_returns bool
mod string // current module name is_builtin_mod bool // true inside the 'builtin', 'os' or 'strconv' modules; TODO: remove the need for special casing this
is_builtin_mod bool // true inside the 'builtin', 'os' or 'strconv' modules; TODO: remove the need for special casing this is_generated bool // true for `[generated] module xyz` .v files
is_generated bool // true for `[generated] module xyz` .v files inside_unsafe bool // true inside `unsafe {}` blocks
inside_unsafe bool // true inside `unsafe {}` blocks inside_const bool // true inside `const ( ... )` blocks
inside_const bool // true inside `const ( ... )` blocks inside_anon_fn bool // true inside `fn() { ... }()`
inside_anon_fn bool // true inside `fn() { ... }()` inside_ref_lit bool // true inside `a := &something`
inside_ref_lit bool // true inside `a := &something` inside_defer bool // true inside `defer {}` blocks
inside_defer bool // true inside `defer {}` blocks inside_fn_arg bool // `a`, `b` in `a.f(b)`
inside_fn_arg bool // `a`, `b` in `a.f(b)` inside_ct_attr bool // true inside `[if expr]`
inside_ct_attr bool // true inside `[if expr]` skip_flags bool // should `#flag` and `#include` be skipped
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
fn_level int // 0 for the top level, 1 for `fn abc() {}`, 2 for a nested fn, etc
ct_cond_stack []ast.Expr ct_cond_stack []ast.Expr
mut: mut:
stmt_level int // the nesting level inside each stmts list; stmt_level int // the nesting level inside each stmts list;
@ -90,29 +90,28 @@ mut:
// 1 for statements directly at each inner scope level; // 1 for statements directly at each inner scope level;
// increases for `x := if cond { statement_list1} else {statement_list2}`; // increases for `x := if cond { statement_list1} else {statement_list2}`;
// increases for `x := optfn() or { statement_list3 }`; // increases for `x := optfn() or { statement_list3 }`;
is_last_stmt bool
files []ast.File files []ast.File
expr_level int // to avoid infinite recursion segfaults due to compiler bugs expr_level int // to avoid infinite recursion segfaults due to compiler bugs
inside_sql bool // to handle sql table fields pseudo variables
cur_orm_ts ast.TypeSymbol cur_orm_ts ast.TypeSymbol
error_details []string error_details []string
vmod_file_content string // needed for @VMOD_FILE, contents of the file, *NOT its path** vmod_file_content string // needed for @VMOD_FILE, contents of the file, *NOT its path**
vweb_gen_types []ast.Type // vweb route checks
prevent_sum_type_unwrapping_once bool // needed for assign new values to sum type, stopping unwrapping then
loop_label string // set when inside a labelled for loop loop_label string // set when inside a labelled for loop
vweb_gen_types []ast.Type // vweb route checks
timers &util.Timers = util.get_timers() timers &util.Timers = util.get_timers()
comptime_fields_default_type ast.Type comptime_fields_default_type ast.Type
comptime_fields_type map[string]ast.Type comptime_fields_type map[string]ast.Type
fn_scope &ast.Scope = voidptr(0) fn_scope &ast.Scope = voidptr(0)
main_fn_decl_node ast.FnDecl main_fn_decl_node ast.FnDecl
match_exhaustive_cutoff_limit int = 10 match_exhaustive_cutoff_limit int = 10
// TODO: these are here temporarily and used for deprecations; remove soon is_last_stmt bool
using_new_err_struct bool prevent_sum_type_unwrapping_once bool // needed for assign new values to sum type, stopping unwrapping then
inside_selector_expr bool using_new_err_struct bool
inside_println_arg bool need_recheck_generic_fns bool // need recheck generic fns because there are cascaded nested generic fn
inside_decl_rhs bool inside_sql bool // to handle sql table fields pseudo variables
inside_if_guard bool // true inside the guard condition of `if x := opt() {}` inside_selector_expr bool
need_recheck_generic_fns bool // need recheck generic fns because there are cascaded nested generic fn inside_println_arg bool
inside_decl_rhs bool
inside_if_guard bool // true inside the guard condition of `if x := opt() {}`
} }
pub fn new_checker(table &ast.Table, pref &pref.Preferences) &Checker { pub fn new_checker(table &ast.Table, pref &pref.Preferences) &Checker {