Bug 575870 - Enable the firefox button on xp themed, classic, and aero basic. r=dao...
[mozilla-central.git] / layout / analysis / simple-match.js
blob263962a3b552725a031cb7e7eb770c6c7909dd76
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");
15 var matches = {};
17 function identity(x) x;
19 function process_cp_pre_genericize(fndecl)
21     var c = [];
22     function calls(t, stack)
23     {
24         try {
25             t.tree_check(CALL_EXPR);
26             var fn = callable_arg_function_decl(CALL_EXPR_FN(t));
27             if (fn)
28                 c.push(decl_name_string(fn));
29         }
30         catch (e if e.TreeCheckError) { }
31     }
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);