From 3d8853af2b48b2f77d175854d2e58077fd3a17a6 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 29 Apr 2020 13:04:09 +0300 Subject: [PATCH] builder: move warning/error printing into print_warnings_and_errors --- vlib/v/builder/builder.v | 29 +++++++++++++++-------------- vlib/v/builder/c.v | 8 +------- vlib/v/builder/js.v | 4 +--- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 35bcd6fe7a..9656c35efe 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -267,23 +267,24 @@ pub fn (b Builder) find_module_path(mod, fpath string) ?string { return error('module "$mod" not found in:\n$smodule_lookup_paths') } -fn (b &Builder) print_errors(errors []errors.Error) { - for err in errors { - kind := if b.pref.is_verbose { '$err.reporter error #$b.checker.nr_errors:' } else { 'error:' } - ferror := util.formatted_error(kind, err.message, err.file_path, err.pos) - eprintln(ferror) +fn (b &Builder) print_warnings_and_errors(){ + if b.checker.nr_warnings > 0 { + for err in b.checker.warnings { + kind := if b.pref.is_verbose { '$err.reporter warning #$b.checker.nr_warnings:' } else { 'warning:' } + ferror := util.formatted_error(kind, err.message, err.file_path, err.pos) + eprintln(ferror) + } + } + if b.checker.nr_errors > 0 { + for err in b.checker.errors { + kind := if b.pref.is_verbose { '$err.reporter error #$b.checker.nr_errors:' } else { 'error:' } + ferror := util.formatted_error(kind, err.message, err.file_path, err.pos) + eprintln(ferror) + } + exit(1) } } -fn (b &Builder) print_warnings(warnings []errors.Warning) { - for err in warnings { - kind := if b.pref.is_verbose { '$err.reporter warning #$b.checker.nr_errors:' } else { 'warning:' } - ferror := util.formatted_error(kind, err.message, err.file_path, err.pos) - eprintln(ferror) - } -} - - fn verror(s string) { util.verror('builder error', s) } diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index 77d3541e0f..bae0db0f0f 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -18,13 +18,7 @@ pub fn (mut b Builder) gen_c(v_files []string) string { t2 := time.ticks() check_time := t2 - t1 b.info('CHECK: ${check_time}ms') - if b.checker.nr_warnings > 0 { - b.print_warnings(b.checker.warnings) - } - if b.checker.nr_errors > 0 { - b.print_errors(b.checker.errors) - exit(1) - } + b.print_warnings_and_errors() // println('starting cgen...') // TODO: move gen.cgen() to c.gen() res := gen.cgen(b.parsed_files, b.table, b.pref) diff --git a/vlib/v/builder/js.v b/vlib/v/builder/js.v index 589855f5b8..3917c98399 100644 --- a/vlib/v/builder/js.v +++ b/vlib/v/builder/js.v @@ -18,9 +18,7 @@ pub fn (mut b Builder) gen_js(v_files []string) string { t2 := time.ticks() check_time := t2 - t1 b.info('CHECK: ${check_time}ms') - if b.checker.nr_errors > 0 { - exit(1) - } + b.print_warnings_and_errors() res := js.gen(b.parsed_files, b.table, b.pref) t3 := time.ticks() gen_time := t3 - t2