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

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

This commit is contained in:
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
pub fn (x Expr) str() string {
match x {
AnonFn {
return 'anon_fn'
}
DumpExpr {
return 'dump($x.expr.str())'
}
ArrayInit {
mut fields := []string{}
if x.has_len {
@ -226,6 +232,12 @@ pub fn (x Expr) str() string {
return x.exprs.str()
}
}
AsCast {
return '$x.expr.str() as Type($x.typ)'
}
AtExpr {
return '$x.val'
}
CTempVar {
return x.orig.str()
}
@ -235,9 +247,6 @@ pub fn (x Expr) str() string {
CastExpr {
return '${x.typname}($x.expr.str())'
}
AtExpr {
return '$x.val'
}
CallExpr {
sargs := args2str(x.args)
if x.is_method {

View File

@ -13,12 +13,9 @@ import v.util
import v.errors
import v.pkgconfig
const (
max_nr_errors = 300
match_exhaustive_cutoff_limit = 10
int_min = int(0x80000000)
int_max = 0x7FFFFFFF
)
const int_min = int(0x80000000)
const int_max = int(0x7FFFFFFF)
const (
valid_comp_if_os = ['windows', 'ios', 'macos', 'mach', 'darwin', 'hpux', 'gnu', 'qnx',
@ -78,6 +75,7 @@ mut:
fn_scope &ast.Scope = voidptr(0)
used_fns map[string]bool // used_fns['println'] == true
main_fn_decl_node ast.FnDecl
match_exhaustive_cutoff_limit int = 10
// TODO: these are here temporarily and used for deprecations; remove soon
using_new_err_struct bool
inside_selector_expr bool
@ -94,6 +92,7 @@ pub fn new_checker(table &table.Table, pref &pref.Preferences) Checker {
pref: pref
cur_fn: 0
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'
if unhandled.len > 0 {
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(', ')
} else {
remaining := unhandled.len - checker.match_exhaustive_cutoff_limit
err_details += unhandled[0..checker.match_exhaustive_cutoff_limit].join(', ')
remaining := unhandled.len - c.match_exhaustive_cutoff_limit
err_details += unhandled[0..c.match_exhaustive_cutoff_limit].join(', ')
err_details += ', and $remaining others ...'
}
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
cache_manager vcache.CacheManager
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) {
@ -370,6 +372,11 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
res.build_options << '$arg "$res.ccompiler"'
i++
}
'-checker-match-exhaustive-cutoff-limit' {
res.checker_match_exhaustive_cutoff_limit = cmdline.option(current_args,
arg, '10').int()
i++
}
'-o' {
res.out_name = cmdline.option(current_args, '-o', '')
if res.out_name.ends_with('.js') {