From 256a572cbe2592c95f12dc1619d9d3bab0c5720d Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 6 Oct 2020 07:07:50 +0200 Subject: [PATCH] vet: fix vet_errors --- cmd/tools/vvet.v | 8 +++++--- vlib/v/parser/parser.v | 8 ++++---- vlib/v/scanner/scanner.v | 11 +++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/cmd/tools/vvet.v b/cmd/tools/vvet.v index 303e4be4bf..39abeed85b 100644 --- a/cmd/tools/vvet.v +++ b/cmd/tools/vvet.v @@ -12,6 +12,7 @@ import os.cmdline struct VetOptions { is_verbose bool +mut: errors []string } @@ -25,7 +26,7 @@ fn (vet_options &VetOptions) vprintln(s string) { fn main() { args := util.join_env_vflags_and_os_args() paths := cmdline.only_non_options(cmdline.options_after(args, ['vet'])) - vet_options := VetOptions{ + mut vet_options := VetOptions{ is_verbose: '-verbose' in args || '-v' in args } for path in paths { @@ -63,11 +64,12 @@ fn main() { } } -fn (vet_options &VetOptions) vet_file(path string) { +fn (mut vet_options VetOptions) vet_file(path string) { mut prefs := pref.new_preferences() prefs.is_vet = true table := table.new_table() vet_options.vprintln("vetting file '$path'...") - file_ast := parser.parse_vet_file(path, table, prefs, vet_options.errors) + file_ast, errors := parser.parse_vet_file(path, table, prefs) + vet_options.errors = errors vet.vet(file_ast, table, true) } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index fb107f718e..e8446244ba 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -119,12 +119,12 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme return p.parse() } -pub fn parse_vet_file(path string, table_ &table.Table, pref &pref.Preferences, vet_errors []string) ast.File { +pub fn parse_vet_file(path string, table_ &table.Table, pref &pref.Preferences) (ast.File, []string) { global_scope := &ast.Scope{ parent: 0 } mut p := Parser{ - scanner: scanner.new_vet_scanner_file(path, .parse_comments, pref, vet_errors) + scanner: scanner.new_vet_scanner_file(path, .parse_comments, pref) comments_mode: .parse_comments table: table_ file_name: path @@ -137,7 +137,6 @@ pub fn parse_vet_file(path string, table_ &table.Table, pref &pref.Preferences, errors: []errors.Error{} warnings: []errors.Warning{} global_scope: global_scope - vet_errors: vet_errors } if p.scanner.text.contains('\n ') { source_lines := os.read_lines(path) or { @@ -149,7 +148,8 @@ pub fn parse_vet_file(path string, table_ &table.Table, pref &pref.Preferences, } } } - return p.parse() + file := p.parse() + return file, p.vet_errors } fn (mut p Parser) parse() ast.File { diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index d19f5bb354..d318bab8ea 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -97,10 +97,10 @@ pub enum CommentsMode { // new scanner from file. pub fn new_scanner_file(file_path string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner { - return new_vet_scanner_file(file_path, comments_mode, pref, []) + return new_vet_scanner_file(file_path, comments_mode, pref) } -pub fn new_vet_scanner_file(file_path string, comments_mode CommentsMode, pref &pref.Preferences, vet_errors []string) &Scanner { +pub fn new_vet_scanner_file(file_path string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner { if !os.exists(file_path) { verror("$file_path doesn't exist") } @@ -108,17 +108,17 @@ pub fn new_vet_scanner_file(file_path string, comments_mode CommentsMode, pref & verror(err) return voidptr(0) } - mut s := new_vet_scanner(raw_text, comments_mode, pref, vet_errors) + mut s := new_vet_scanner(raw_text, comments_mode, pref) s.file_path = file_path return s } // new scanner from string. pub fn new_scanner(text string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner { - return new_vet_scanner(text, comments_mode, pref, []) + return new_vet_scanner(text, comments_mode, pref) } -pub fn new_vet_scanner(text string, comments_mode CommentsMode, pref &pref.Preferences, vet_errors []string) &Scanner { +pub fn new_vet_scanner(text string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner { is_fmt := pref.is_fmt mut s := &Scanner{ pref: pref @@ -128,7 +128,6 @@ pub fn new_vet_scanner(text string, comments_mode CommentsMode, pref &pref.Prefe is_print_rel_paths_on_error: true is_fmt: is_fmt comments_mode: comments_mode - vet_errors: vet_errors } s.file_path = 'internal_memory' return s