v.ast: handle more expressions in Expr.str()

pull/9310/head weekly.2021.11
Delyan Angelov 2021-03-15 06:22:22 +02:00
parent 80ac1aaf93
commit 25c07c2f43
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 27 additions and 12 deletions

View File

@ -209,6 +209,12 @@ pub fn (lit &StringInterLiteral) get_fspec_braces(i int) (string, bool) {
// string representation of expr // string representation of expr
pub fn (x Expr) str() string { pub fn (x Expr) str() string {
match x { match x {
AnonFn {
return 'anon_fn'
}
DumpExpr {
return 'dump($x.expr.str())'
}
ArrayInit { ArrayInit {
mut fields := []string{} mut fields := []string{}
if x.has_len { if x.has_len {
@ -226,6 +232,12 @@ pub fn (x Expr) str() string {
return x.exprs.str() return x.exprs.str()
} }
} }
AsCast {
return '$x.expr.str() as Type($x.typ)'
}
AtExpr {
return '$x.val'
}
CTempVar { CTempVar {
return x.orig.str() return x.orig.str()
} }
@ -235,9 +247,6 @@ pub fn (x Expr) str() string {
CastExpr { CastExpr {
return '${x.typname}($x.expr.str())' return '${x.typname}($x.expr.str())'
} }
AtExpr {
return '$x.val'
}
CallExpr { CallExpr {
sargs := args2str(x.args) sargs := args2str(x.args)
if x.is_method { if x.is_method {

View File

@ -13,12 +13,9 @@ import v.util
import v.errors import v.errors
import v.pkgconfig import v.pkgconfig
const ( const int_min = int(0x80000000)
max_nr_errors = 300
match_exhaustive_cutoff_limit = 10 const int_max = int(0x7FFFFFFF)
int_min = int(0x80000000)
int_max = 0x7FFFFFFF
)
const ( const (
valid_comp_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu', 'qnx', valid_comp_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu', 'qnx',
@ -78,6 +75,7 @@ mut:
fn_scope &ast.Scope = voidptr(0) fn_scope &ast.Scope = voidptr(0)
used_fns map[string]bool // used_fns['println'] == true used_fns map[string]bool // used_fns['println'] == true
main_fn_decl_node ast.FnDecl main_fn_decl_node ast.FnDecl
match_exhaustive_cutoff_limit int = 10
// TODO: these are here temporarily and used for deprecations; remove soon // TODO: these are here temporarily and used for deprecations; remove soon
using_new_err_struct bool using_new_err_struct bool
inside_selector_expr bool inside_selector_expr bool
@ -94,6 +92,7 @@ pub fn new_checker(table &table.Table, pref &pref.Preferences) Checker {
pref: pref pref: pref
cur_fn: 0 cur_fn: 0
timers: util.new_timers(timers_should_print) timers: util.new_timers(timers_should_print)
match_exhaustive_cutoff_limit: pref.checker_match_exhaustive_cutoff_limit
} }
} }
@ -4707,11 +4706,11 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym table.TypeS
mut err_details := 'match must be exhaustive' mut err_details := 'match must be exhaustive'
if unhandled.len > 0 { if unhandled.len > 0 {
err_details += ' (add match branches for: ' err_details += ' (add match branches for: '
if unhandled.len < checker.match_exhaustive_cutoff_limit { if unhandled.len < c.match_exhaustive_cutoff_limit {
err_details += unhandled.join(', ') err_details += unhandled.join(', ')
} else { } else {
remaining := unhandled.len - checker.match_exhaustive_cutoff_limit remaining := unhandled.len - c.match_exhaustive_cutoff_limit
err_details += unhandled[0..checker.match_exhaustive_cutoff_limit].join(', ') err_details += unhandled[0..c.match_exhaustive_cutoff_limit].join(', ')
err_details += ', and $remaining others ...' err_details += ', and $remaining others ...'
} }
err_details += ' or `else {}` at the end)' err_details += ' or `else {}` at the end)'

View File

@ -144,6 +144,8 @@ pub mut:
build_options []string // list of options, that should be passed down to `build-module`, if needed for -usecache build_options []string // list of options, that should be passed down to `build-module`, if needed for -usecache
cache_manager vcache.CacheManager cache_manager vcache.CacheManager
is_help bool // -h, -help or --help was passed is_help bool // -h, -help or --help was passed
// checker settings:
checker_match_exhaustive_cutoff_limit int = 10
} }
pub fn parse_args(known_external_commands []string, args []string) (&Preferences, string) { pub fn parse_args(known_external_commands []string, args []string) (&Preferences, string) {
@ -370,6 +372,11 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
res.build_options << '$arg "$res.ccompiler"' res.build_options << '$arg "$res.ccompiler"'
i++ i++
} }
'-checker-match-exhaustive-cutoff-limit' {
res.checker_match_exhaustive_cutoff_limit = cmdline.option(current_args,
arg, '10').int()
i++
}
'-o' { '-o' {
res.out_name = cmdline.option(current_args, '-o', '') res.out_name = cmdline.option(current_args, '-o', '')
if res.out_name.ends_with('.js') { if res.out_name.ends_with('.js') {