From ef0161c233ca88854b089bbfedd9922449e96a89 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 27 Jul 2021 15:42:25 +0300 Subject: [PATCH] v.markused: handle compiling vweb, `-live` and orm example programs --- vlib/v/ast/table.v | 8 +++++++- vlib/v/markused/markused.v | 30 ++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/vlib/v/ast/table.v b/vlib/v/ast/table.v index 341c7c3189..fbcc5e239f 100644 --- a/vlib/v/ast/table.v +++ b/vlib/v/ast/table.v @@ -13,6 +13,7 @@ pub mut: type_symbols []TypeSymbol type_idxs map[string]int fns map[string]Fn + iface_types map[string][]Type dumps map[int]string // needed for efficiently generating all _v_dump_expr_TNAME() functions imports []string // List of all imports modules []string // Topologically sorted list of all modules registered by the application @@ -1111,7 +1112,12 @@ pub fn (mut t Table) complete_interface_check() { && tsym.mod != t.get_type_symbol(idecl.typ).mod { continue } - t.does_type_implement_interface(tk, idecl.typ) + if t.does_type_implement_interface(tk, idecl.typ) { + $if trace_types_implementing_each_interface ? { + eprintln('>>> tsym.mod: $tsym.mod | tsym.name: $tsym.name | tk: $tk | idecl.name: $idecl.name | idecl.typ: $idecl.typ') + } + t.iface_types[idecl.name] << tk + } } } } diff --git a/vlib/v/markused/markused.v b/vlib/v/markused/markused.v index ff9c4118bd..a81651c745 100644 --- a/vlib/v/markused/markused.v +++ b/vlib/v/markused/markused.v @@ -271,19 +271,45 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []&ast.F // 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.get_type_symbol(vgt) for m in sym_app.methods { if m.return_type == typ_vweb_result { 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 << '${pvgt}.$m.name' + all_fn_root_names << '${int(pvgt)}.$m.name' } } } } - // + // handle ORM drivers: + orm_connection_implementations := table.iface_types['orm.Connection'] or { []ast.Type{} } + if orm_connection_implementations.len > 0 { + for k, _ in all_fns { + if k.starts_with('orm.') { + all_fn_root_names << k + } + } + for orm_type in orm_connection_implementations { + all_fn_root_names << '${int(orm_type)}.select' + all_fn_root_names << '${int(orm_type)}.insert' + all_fn_root_names << '${int(orm_type)}.update' + all_fn_root_names << '${int(orm_type)}.delete' + all_fn_root_names << '${int(orm_type)}.create' + all_fn_root_names << '${int(orm_type)}.drop' + all_fn_root_names << '${int(orm_type)}.last_id' + } + } + + // handle -live main programs: + if pref.is_livemain { + all_fn_root_names << 'v.live.executable.start_reloader' + all_fn_root_names << 'v.live.executable.new_live_reload_info' + } mut walker := Walker{ table: table