mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
vet: fix vet_errors
This commit is contained in:
parent
ed15b40529
commit
256a572cbe
@ -12,6 +12,7 @@ import os.cmdline
|
|||||||
|
|
||||||
struct VetOptions {
|
struct VetOptions {
|
||||||
is_verbose bool
|
is_verbose bool
|
||||||
|
mut:
|
||||||
errors []string
|
errors []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ fn (vet_options &VetOptions) vprintln(s string) {
|
|||||||
fn main() {
|
fn main() {
|
||||||
args := util.join_env_vflags_and_os_args()
|
args := util.join_env_vflags_and_os_args()
|
||||||
paths := cmdline.only_non_options(cmdline.options_after(args, ['vet']))
|
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
|
is_verbose: '-verbose' in args || '-v' in args
|
||||||
}
|
}
|
||||||
for path in paths {
|
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()
|
mut prefs := pref.new_preferences()
|
||||||
prefs.is_vet = true
|
prefs.is_vet = true
|
||||||
table := table.new_table()
|
table := table.new_table()
|
||||||
vet_options.vprintln("vetting file '$path'...")
|
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)
|
vet.vet(file_ast, table, true)
|
||||||
}
|
}
|
||||||
|
@ -119,12 +119,12 @@ pub fn parse_file(path string, b_table &table.Table, comments_mode scanner.Comme
|
|||||||
return p.parse()
|
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{
|
global_scope := &ast.Scope{
|
||||||
parent: 0
|
parent: 0
|
||||||
}
|
}
|
||||||
mut p := Parser{
|
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
|
comments_mode: .parse_comments
|
||||||
table: table_
|
table: table_
|
||||||
file_name: path
|
file_name: path
|
||||||
@ -137,7 +137,6 @@ pub fn parse_vet_file(path string, table_ &table.Table, pref &pref.Preferences,
|
|||||||
errors: []errors.Error{}
|
errors: []errors.Error{}
|
||||||
warnings: []errors.Warning{}
|
warnings: []errors.Warning{}
|
||||||
global_scope: global_scope
|
global_scope: global_scope
|
||||||
vet_errors: vet_errors
|
|
||||||
}
|
}
|
||||||
if p.scanner.text.contains('\n ') {
|
if p.scanner.text.contains('\n ') {
|
||||||
source_lines := os.read_lines(path) or {
|
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 {
|
fn (mut p Parser) parse() ast.File {
|
||||||
|
@ -97,10 +97,10 @@ pub enum CommentsMode {
|
|||||||
|
|
||||||
// new scanner from file.
|
// new scanner from file.
|
||||||
pub fn new_scanner_file(file_path string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner {
|
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) {
|
if !os.exists(file_path) {
|
||||||
verror("$file_path doesn't exist")
|
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)
|
verror(err)
|
||||||
return voidptr(0)
|
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
|
s.file_path = file_path
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
// new scanner from string.
|
// new scanner from string.
|
||||||
pub fn new_scanner(text string, comments_mode CommentsMode, pref &pref.Preferences) &Scanner {
|
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
|
is_fmt := pref.is_fmt
|
||||||
mut s := &Scanner{
|
mut s := &Scanner{
|
||||||
pref: pref
|
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_print_rel_paths_on_error: true
|
||||||
is_fmt: is_fmt
|
is_fmt: is_fmt
|
||||||
comments_mode: comments_mode
|
comments_mode: comments_mode
|
||||||
vet_errors: vet_errors
|
|
||||||
}
|
}
|
||||||
s.file_path = 'internal_memory'
|
s.file_path = 'internal_memory'
|
||||||
return s
|
return s
|
||||||
|
Loading…
Reference in New Issue
Block a user