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:
parent
868d6c808b
commit
c24a1b3786
@ -103,6 +103,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
struct ParserState {
|
struct ParserState {
|
||||||
|
scanner_file_path string
|
||||||
scanner_line_nr int
|
scanner_line_nr int
|
||||||
scanner_text string
|
scanner_text string
|
||||||
scanner_pos int
|
scanner_pos int
|
||||||
@ -323,6 +324,7 @@ fn (p &Parser) log(s string) {
|
|||||||
|
|
||||||
pub fn (p &Parser) save_state() ParserState {
|
pub fn (p &Parser) save_state() ParserState {
|
||||||
return ParserState{
|
return ParserState{
|
||||||
|
scanner_file_path: p.scanner.file_path
|
||||||
scanner_line_nr: p.scanner.line_nr
|
scanner_line_nr: p.scanner.line_nr
|
||||||
scanner_text: p.scanner.text
|
scanner_text: p.scanner.text
|
||||||
scanner_pos: p.scanner.pos
|
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) {
|
pub fn (p mut Parser) restore_state(state ParserState, scanner bool, cgen bool) {
|
||||||
if scanner {
|
if scanner {
|
||||||
|
p.scanner.file_path = state.scanner_file_path
|
||||||
p.scanner.line_nr = state.scanner_line_nr
|
p.scanner.line_nr = state.scanner_line_nr
|
||||||
p.scanner.text = state.scanner_text
|
p.scanner.text = state.scanner_text
|
||||||
p.scanner.pos = state.scanner_pos
|
p.scanner.pos = state.scanner_pos
|
||||||
@ -390,9 +393,12 @@ pub fn (p mut Parser) add_text(text string) {
|
|||||||
p.scan_tokens()
|
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()
|
saved_state := p.save_state()
|
||||||
p.clear_state(true, false)
|
p.clear_state(true, false)
|
||||||
|
if fpath != '' {
|
||||||
|
p.scanner.file_path = fpath
|
||||||
|
}
|
||||||
p.add_text(text)
|
p.add_text(text)
|
||||||
p.next()
|
p.next()
|
||||||
if rcbr {
|
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 {
|
us_idx := typ_name.index('__') or {
|
||||||
return
|
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) {
|
if p.import_table.known_alias(arg_mod) {
|
||||||
p.import_table.register_used_import(arg_mod)
|
p.import_table.register_used_import(arg_mod)
|
||||||
}
|
}
|
||||||
@ -3098,11 +3107,13 @@ fn (p mut Parser) check_unused_imports() {
|
|||||||
if output == '' {
|
if output == '' {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// the imports are usually at the start of the file
|
// the imports are usually at the start of the file
|
||||||
//p.production_error_with_token_index('the following imports were never used: $output', 0)
|
//p.production_error_with_token_index('the following imports were never used: $output', 0)
|
||||||
if !p.file_path.contains ('vlib/v/') {
|
if p.pref.is_verbose {
|
||||||
p.warn('the following imports were never used: $output')
|
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) {
|
fn (p &Parser) is_expr_fn_call(start_tok_idx int) (bool,string) {
|
||||||
|
@ -159,13 +159,13 @@ fn (p mut Parser) comp_time() {
|
|||||||
p.check(.rcbr)
|
p.check(.rcbr)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
// $vweb.html()
|
|
||||||
// Compile vweb html template to V code, parse that V code and embed the resulting V functions
|
|
||||||
// that returns an html string
|
|
||||||
else if p.tok == .name && p.lit == 'vweb' {
|
else if p.tok == .name && p.lit == 'vweb' {
|
||||||
|
// $vweb.html()
|
||||||
|
// Compile vweb html template to V code, parse that V code and embed the resulting V functions
|
||||||
|
// that returns an html string
|
||||||
mut path := p.cur_fn.name + '.html'
|
mut path := p.cur_fn.name + '.html'
|
||||||
if p.pref.is_debug {
|
if p.pref.is_debug {
|
||||||
println('compiling tmpl $path')
|
println('>>> compiling vweb HTML template "$path"')
|
||||||
}
|
}
|
||||||
if !os.exists(path) {
|
if !os.exists(path) {
|
||||||
// Can't find the template file in current directory,
|
// Can't find the template file in current directory,
|
||||||
@ -183,8 +183,11 @@ fn (p mut Parser) comp_time() {
|
|||||||
p.check(.rpar)
|
p.check(.rpar)
|
||||||
v_code := tmpl.compile_template(path)
|
v_code := tmpl.compile_template(path)
|
||||||
if p.pref.is_verbose {
|
if p.pref.is_verbose {
|
||||||
println('vweb template:')
|
println('\n\n')
|
||||||
|
println('>>> vweb template for ${path}:')
|
||||||
println(v_code)
|
println(v_code)
|
||||||
|
println('>>> vweb template END')
|
||||||
|
println('\n\n')
|
||||||
}
|
}
|
||||||
is_strings_imorted := p.import_table.known_import('strings')
|
is_strings_imorted := p.import_table.known_import('strings')
|
||||||
if !is_strings_imorted {
|
if !is_strings_imorted {
|
||||||
@ -192,16 +195,14 @@ fn (p mut Parser) comp_time() {
|
|||||||
}
|
}
|
||||||
p.import_table.register_used_import('strings')
|
p.import_table.register_used_import('strings')
|
||||||
p.genln('/////////////////// tmpl start')
|
p.genln('/////////////////// tmpl start')
|
||||||
p.scanner.file_path = path
|
p.statements_from_text(v_code, false, path)
|
||||||
p.scanner.line_nr = 0
|
|
||||||
p.statements_from_text(v_code, false)
|
|
||||||
p.genln('/////////////////// tmpl end')
|
p.genln('/////////////////// tmpl end')
|
||||||
receiver := p.cur_fn.args[0]
|
receiver := p.cur_fn.args[0]
|
||||||
dot := if receiver.is_mut || receiver.ptr || receiver.typ.ends_with('*') { '->' } else { '.' }
|
dot := if receiver.is_mut || receiver.ptr || receiver.typ.ends_with('*') { '->' } else { '.' }
|
||||||
p.genln('vweb__Context_html( & $receiver.name /*!*/$dot vweb, tmpl_res)')
|
p.genln('vweb__Context_html( & $receiver.name /*!*/$dot vweb, tmpl_res)')
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p.error('bad comptime expr')
|
p.error('bad comp_time expression')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
strings
|
strings
|
||||||
v.ast
|
v.ast
|
||||||
v.table
|
v.table
|
||||||
v.types
|
|
||||||
term
|
term
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,13 +4,9 @@
|
|||||||
module parser
|
module parser
|
||||||
|
|
||||||
import (
|
import (
|
||||||
v.scanner
|
|
||||||
v.ast
|
v.ast
|
||||||
v.token
|
|
||||||
v.table
|
v.table
|
||||||
v.types
|
v.types
|
||||||
term
|
|
||||||
os
|
|
||||||
)
|
)
|
||||||
|
|
||||||
pub fn (p mut Parser) call_expr() (ast.CallExpr,types.TypeIdent) {
|
pub fn (p mut Parser) call_expr() (ast.CallExpr,types.TypeIdent) {
|
||||||
|
@ -19,7 +19,7 @@ pub fn compile_template(path string) string {
|
|||||||
mut header := ''
|
mut header := ''
|
||||||
if os.exists('header.html') {
|
if os.exists('header.html') {
|
||||||
h := os.read_file('header.html')or{
|
h := os.read_file('header.html')or{
|
||||||
panic('html failed')
|
panic('reading file header.html failed')
|
||||||
}
|
}
|
||||||
header = h.replace("\'", '"')
|
header = h.replace("\'", '"')
|
||||||
html = header + html
|
html = header + html
|
||||||
|
Loading…
Reference in New Issue
Block a user