layout/analysis/simple-match.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     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");
    19 var matches = {};
    21 function identity(x) x;
    23 function process_cp_pre_genericize(fndecl)
    24 {
    25     var c = [];
    26     function calls(t, stack)
    27     {
    28         try {
    29             t.tree_check(CALL_EXPR);
    30             var fn = callable_arg_function_decl(CALL_EXPR_FN(t));
    31             if (fn)
    32                 c.push(decl_name_string(fn));
    33         }
    34         catch (e if e.TreeCheckError) { }
    35     }
    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);
    43 }

mercurial