1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // This executes a very simple search for all functions that call a
6 // given set of functions. It's intended to be the simplest possible
7 // way of refactoring a common pattern of function calls. Of course,
8 // it's still up to a human to decide if the replacement is truely
9 // suitable, but this gets the low-hanging fruit.
11 // Expects the variable 'patterns' to hold an object with replacement
12 // function names as keys and function lists as values. Any function
13 // in the tested source that calls all of the functions named in the
14 // list will be listed in the output as being likely candidates to
15 // instead call the replacement function.
17 include("unstable/lazy_types.js");
21 function identity(x) x;
23 function process_cp_pre_genericize(fndecl)
26 function calls(t, stack)
29 t.tree_check(CALL_EXPR);
30 var fn = callable_arg_function_decl(CALL_EXPR_FN(t));
32 c.push(decl_name_string(fn));
34 catch (e if e.TreeCheckError) { }
37 walk_tree(DECL_SAVED_TREE(fndecl), calls);
39 for (let [fnreplace, pattern] in patterns)
40 if (pattern.map(function(e){ return c.some(function(f) { return e == f; }); }).every(identity))
41 if (fnreplace != (n = decl_name_string(fndecl)))
42 print(fnreplace +" could probably be used in "+ n);