mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: fix unused import warnings
This commit is contained in:

committed by
Alexander Medvednikov

parent
868d6c808b
commit
c24a1b3786
@ -103,6 +103,7 @@ const (
|
||||
)
|
||||
|
||||
struct ParserState {
|
||||
scanner_file_path string
|
||||
scanner_line_nr int
|
||||
scanner_text string
|
||||
scanner_pos int
|
||||
@ -323,6 +324,7 @@ fn (p &Parser) log(s string) {
|
||||
|
||||
pub fn (p &Parser) save_state() ParserState {
|
||||
return ParserState{
|
||||
scanner_file_path: p.scanner.file_path
|
||||
scanner_line_nr: p.scanner.line_nr
|
||||
scanner_text: p.scanner.text
|
||||
scanner_pos: p.scanner.pos
|
||||
@ -343,6 +345,7 @@ pub fn (p &Parser) save_state() ParserState {
|
||||
|
||||
pub fn (p mut Parser) restore_state(state ParserState, scanner bool, cgen bool) {
|
||||
if scanner {
|
||||
p.scanner.file_path = state.scanner_file_path
|
||||
p.scanner.line_nr = state.scanner_line_nr
|
||||
p.scanner.text = state.scanner_text
|
||||
p.scanner.pos = state.scanner_pos
|
||||
@ -390,9 +393,12 @@ pub fn (p mut Parser) add_text(text string) {
|
||||
p.scan_tokens()
|
||||
}
|
||||
|
||||
fn (p mut Parser) statements_from_text(text string, rcbr bool) {
|
||||
fn (p mut Parser) statements_from_text(text string, rcbr bool, fpath string) {
|
||||
saved_state := p.save_state()
|
||||
p.clear_state(true, false)
|
||||
if fpath != '' {
|
||||
p.scanner.file_path = fpath
|
||||
}
|
||||
p.add_text(text)
|
||||
p.next()
|
||||
if rcbr {
|
||||
@ -3077,7 +3083,10 @@ fn (p mut Parser) check_and_register_used_imported_type(typ_name string) {
|
||||
us_idx := typ_name.index('__') or {
|
||||
return
|
||||
}
|
||||
arg_mod := typ_name[..us_idx]
|
||||
mut arg_mod := typ_name[..us_idx]
|
||||
if arg_mod.contains('_dot_') {
|
||||
arg_mod = arg_mod.all_after('_dot_')
|
||||
}
|
||||
if p.import_table.known_alias(arg_mod) {
|
||||
p.import_table.register_used_import(arg_mod)
|
||||
}
|
||||
@ -3098,11 +3107,13 @@ fn (p mut Parser) check_unused_imports() {
|
||||
if output == '' {
|
||||
return
|
||||
}
|
||||
|
||||
// the imports are usually at the start of the file
|
||||
//p.production_error_with_token_index('the following imports were never used: $output', 0)
|
||||
if !p.file_path.contains ('vlib/v/') {
|
||||
p.warn('the following imports were never used: $output')
|
||||
if p.pref.is_verbose {
|
||||
eprintln('Used imports table: ${p.import_table.used_imports.str()}')
|
||||
}
|
||||
p.warn('the following imports were never used: $output')
|
||||
}
|
||||
|
||||
fn (p &Parser) is_expr_fn_call(start_tok_idx int) (bool,string) {
|
||||
|
Reference in New Issue
Block a user