mirror of
https://github.com/vlang/v.git
synced 2025-09-12 17:07:11 -04:00
markused: add -skip-unused
for programs that import x.vweb
too (do not skip unused routing methods)
This commit is contained in:
parent
923b410d4d
commit
969402461f
@ -2489,7 +2489,7 @@ fn (mut c Checker) post_process_generic_fns() ! {
|
||||
for concrete_types in gtypes {
|
||||
c.table.cur_concrete_types = concrete_types
|
||||
c.fn_decl(mut node)
|
||||
if node.name in ['vweb.run', 'vweb.run_at'] {
|
||||
if node.name in ['x.vweb.run', 'x.vweb.run_at', 'vweb.run', 'vweb.run_at'] {
|
||||
for ct in concrete_types {
|
||||
if ct !in c.vweb_gen_types {
|
||||
c.vweb_gen_types << ct
|
||||
|
@ -304,33 +304,8 @@ pub fn mark_used(mut table ast.Table, pref_ &pref.Preferences, ast_files []&ast.
|
||||
}
|
||||
}
|
||||
|
||||
// handle vweb magic router methods:
|
||||
typ_vweb_result := table.find_type_idx('vweb.Result')
|
||||
if typ_vweb_result != 0 {
|
||||
all_fn_root_names << 'vweb.filter'
|
||||
typ_vweb_context := ast.Type(table.find_type_idx('vweb.Context')).set_nr_muls(1)
|
||||
all_fn_root_names << '${int(typ_vweb_context)}.html'
|
||||
for vgt in table.used_vweb_types {
|
||||
sym_app := table.sym(vgt)
|
||||
for m in sym_app.methods {
|
||||
mut skip := true
|
||||
if m.name == 'before_request' {
|
||||
// TODO: handle expansion of method calls in generic functions in a more universal way
|
||||
skip = false
|
||||
}
|
||||
if m.return_type == typ_vweb_result {
|
||||
skip = false
|
||||
}
|
||||
//
|
||||
if skip {
|
||||
continue
|
||||
}
|
||||
pvgt := vgt.set_nr_muls(1)
|
||||
// eprintln('vgt: $vgt | pvgt: $pvgt | sym_app.name: $sym_app.name | m.name: $m.name')
|
||||
all_fn_root_names << '${int(pvgt)}.${m.name}'
|
||||
}
|
||||
}
|
||||
}
|
||||
handle_vweb(mut table, mut all_fn_root_names, 'vweb.Result', 'vweb.filter', 'vweb.Context')
|
||||
handle_vweb(mut table, mut all_fn_root_names, 'x.vweb.Result', 'x.vweb.filter', 'x.vweb.Context')
|
||||
|
||||
// handle ORM drivers:
|
||||
orm_connection_implementations := table.iface_types['orm.Connection'] or { []ast.Type{} }
|
||||
@ -464,3 +439,32 @@ fn all_fn_const_and_global(ast_files []&ast.File) (map[string]ast.FnDecl, map[st
|
||||
}
|
||||
return all_fns, all_consts, all_globals
|
||||
}
|
||||
|
||||
fn handle_vweb(mut table ast.Table, mut all_fn_root_names []string, result_name string, filter_name string, context_name string) {
|
||||
// handle vweb magic router methods:
|
||||
result_type_idx := table.find_type_idx(result_name)
|
||||
if result_type_idx != 0 {
|
||||
all_fn_root_names << filter_name
|
||||
typ_vweb_context := ast.Type(table.find_type_idx(context_name)).set_nr_muls(1)
|
||||
all_fn_root_names << '${int(typ_vweb_context)}.html'
|
||||
for vgt in table.used_vweb_types {
|
||||
sym_app := table.sym(vgt)
|
||||
for m in sym_app.methods {
|
||||
mut skip := true
|
||||
if m.name == 'before_request' {
|
||||
// TODO: handle expansion of method calls in generic functions in a more universal way
|
||||
skip = false
|
||||
}
|
||||
if m.return_type == result_type_idx {
|
||||
skip = false
|
||||
}
|
||||
if skip {
|
||||
continue
|
||||
}
|
||||
pvgt := vgt.set_nr_muls(1)
|
||||
// eprintln('vgt: $vgt | pvgt: $pvgt | sym_app.name: $sym_app.name | m.name: $m.name')
|
||||
all_fn_root_names << '${int(pvgt)}.${m.name}'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
vlib/v/tests/skip_unused/x_vweb_run_at.run.out
Normal file
2
vlib/v/tests/skip_unused/x_vweb_run_at.run.out
Normal file
@ -0,0 +1,2 @@
|
||||
[Vweb] Running app on http://localhost:38090/
|
||||
done
|
@ -0,0 +1,2 @@
|
||||
[Vweb] Running app on http://localhost:38090/
|
||||
done
|
23
vlib/v/tests/skip_unused/x_vweb_run_at.vv
Normal file
23
vlib/v/tests/skip_unused/x_vweb_run_at.vv
Normal file
@ -0,0 +1,23 @@
|
||||
import x.vweb
|
||||
import time
|
||||
|
||||
pub struct App {}
|
||||
|
||||
pub struct Context {
|
||||
vweb.Context
|
||||
}
|
||||
|
||||
fn main() {
|
||||
spawn fn () {
|
||||
time.sleep(100 * time.millisecond)
|
||||
println('done')
|
||||
exit(0)
|
||||
}()
|
||||
mut app := &App{}
|
||||
vweb.run_at[App, Context](mut app, port: 38090)!
|
||||
}
|
||||
|
||||
@['/']
|
||||
pub fn (app &App) index(mut ctx Context) vweb.Result {
|
||||
return ctx.text('Hello World')
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user