v.markused: handle interface implementation methods, and vweb programs
							parent
							
								
									106cd384da
								
							
						
					
					
						commit
						ae898e77c5
					
				|  | @ -24,6 +24,7 @@ pub mut: | ||||||
| 	is_fmt           bool | 	is_fmt           bool | ||||||
| 	used_fns         map[string]bool // filled in by the checker, when pref.skip_unused = true;
 | 	used_fns         map[string]bool // filled in by the checker, when pref.skip_unused = true;
 | ||||||
| 	used_consts      map[string]bool // filled in by the checker, when pref.skip_unused = true;
 | 	used_consts      map[string]bool // filled in by the checker, when pref.skip_unused = true;
 | ||||||
|  | 	used_vweb_types  []Type // vweb context types, filled in by checker, when pref.skip_unused = true;
 | ||||||
| 	panic_handler    FnPanicHandler = default_table_panic_handler | 	panic_handler    FnPanicHandler = default_table_panic_handler | ||||||
| 	panic_userdata   voidptr        = voidptr(0) // can be used to pass arbitrary data to panic_handler;
 | 	panic_userdata   voidptr        = voidptr(0) // can be used to pass arbitrary data to panic_handler;
 | ||||||
| 	panic_npanics    int | 	panic_npanics    int | ||||||
|  | @ -44,6 +45,7 @@ pub fn (t &Table) free() { | ||||||
| 		t.cmod_prefix.free() | 		t.cmod_prefix.free() | ||||||
| 		t.used_fns.free() | 		t.used_fns.free() | ||||||
| 		t.used_consts.free() | 		t.used_consts.free() | ||||||
|  | 		t.used_vweb_types.free() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -79,7 +79,6 @@ mut: | ||||||
| 	timers                           &util.Timers = util.new_timers(false) | 	timers                           &util.Timers = util.new_timers(false) | ||||||
| 	comptime_fields_type             map[string]ast.Type | 	comptime_fields_type             map[string]ast.Type | ||||||
| 	fn_scope                         &ast.Scope = voidptr(0) | 	fn_scope                         &ast.Scope = voidptr(0) | ||||||
| 	used_fns                         map[string]bool // used_fns['println'] == true
 |  | ||||||
| 	main_fn_decl_node                ast.FnDecl | 	main_fn_decl_node                ast.FnDecl | ||||||
| 	match_exhaustive_cutoff_limit    int = 10 | 	match_exhaustive_cutoff_limit    int = 10 | ||||||
| 	// TODO: these are here temporarily and used for deprecations; remove soon
 | 	// TODO: these are here temporarily and used for deprecations; remove soon
 | ||||||
|  | @ -6746,7 +6745,11 @@ fn (mut c Checker) post_process_generic_fns() { | ||||||
| 			node.cur_concrete_types = concrete_types | 			node.cur_concrete_types = concrete_types | ||||||
| 			c.fn_decl(mut node) | 			c.fn_decl(mut node) | ||||||
| 			if node.name in ['vweb.run_app', 'vweb.run'] { | 			if node.name in ['vweb.run_app', 'vweb.run'] { | ||||||
| 				c.vweb_gen_types << concrete_types | 				for ct in concrete_types { | ||||||
|  | 					if ct !in c.vweb_gen_types { | ||||||
|  | 						c.vweb_gen_types << ct | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		node.cur_concrete_types = [] | 		node.cur_concrete_types = [] | ||||||
|  | @ -6961,6 +6964,7 @@ fn (mut c Checker) verify_all_vweb_routes() { | ||||||
| 	if c.vweb_gen_types.len == 0 { | 	if c.vweb_gen_types.len == 0 { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  | 	c.table.used_vweb_types = c.vweb_gen_types | ||||||
| 	typ_vweb_result := c.table.find_type_idx('vweb.Result') | 	typ_vweb_result := c.table.find_type_idx('vweb.Result') | ||||||
| 	old_file := c.file | 	old_file := c.file | ||||||
| 	for vgt in c.vweb_gen_types { | 	for vgt in c.vweb_gen_types { | ||||||
|  |  | ||||||
|  | @ -158,6 +158,8 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []ast.Fi | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	// handle assertions and testing framework callbacks:
 | ||||||
| 	if pref.is_debug { | 	if pref.is_debug { | ||||||
| 		all_fn_root_names << 'panic_debug' | 		all_fn_root_names << 'panic_debug' | ||||||
| 	} | 	} | ||||||
|  | @ -174,6 +176,40 @@ pub fn mark_used(mut table ast.Table, pref &pref.Preferences, ast_files []ast.Fi | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// handle interface implementation methods:
 | ||||||
|  | 	for isym in table.type_symbols { | ||||||
|  | 		if isym.kind != .interface_ { | ||||||
|  | 			continue | ||||||
|  | 		} | ||||||
|  | 		interface_info := isym.info as ast.Interface | ||||||
|  | 		if interface_info.methods.len == 0 { | ||||||
|  | 			continue | ||||||
|  | 		} | ||||||
|  | 		for itype in interface_info.types { | ||||||
|  | 			for method in interface_info.methods { | ||||||
|  | 				interface_implementation_method_name := '${itype}.$method.name' | ||||||
|  | 				all_fn_root_names << interface_implementation_method_name | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// handle vweb magic router methods:
 | ||||||
|  | 	typ_vweb_result := table.find_type_idx('vweb.Result') | ||||||
|  | 	if typ_vweb_result != 0 { | ||||||
|  | 		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' | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	//
 | ||||||
|  | 
 | ||||||
| 	mut walker := Walker{ | 	mut walker := Walker{ | ||||||
| 		table: table | 		table: table | ||||||
| 		files: ast_files | 		files: ast_files | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue