1 // This executes a very simple search for all functions that call a
2 // given set of functions. It's intended to be the simplest possible
3 // way of refactoring a common pattern of function calls. Of course,
4 // it's still up to a human to decide if the replacement is truely
5 // suitable, but this gets the low-hanging fruit.
7 // Expects the variable 'patterns' to hold an object with replacement
8 // function names as keys and function lists as values. Any function
9 // in the tested source that calls all of the functions named in the
10 // list will be listed in the output as being likely candidates to
11 // instead call the replacement function.
13 include("unstable/lazy_types.js");
17 function identity(x) x;
19 function process_cp_pre_genericize(fndecl)
22 function calls(t, stack)
25 t.tree_check(CALL_EXPR);
26 var fn = callable_arg_function_decl(CALL_EXPR_FN(t));
28 c.push(decl_name_string(fn));
30 catch (e if e.TreeCheckError) { }
33 walk_tree(DECL_SAVED_TREE(fndecl), calls);
35 for (let [fnreplace, pattern] in patterns)
36 if (pattern.map(function(e){ return c.some(function(f) { return e == f; }); }).every(identity))
37 if (fnreplace != (n = decl_name_string(fndecl)))
38 print(fnreplace +" could probably be used in "+ n);