vet: fix vet_errors

pull/6298/head
Alexander Medvednikov 2020-10-06 07:07:50 +02:00
parent ed15b40529
commit 256a572cbe
3 changed files with 14 additions and 13 deletions

View File

@ -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)
}

View File

@ -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 {

View File

@ -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