layout/analysis/simple-match.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial