https://github.com/mozilla/gecko-dev
Raw File
Tip revision: 1b2df193b616a5c17614109e5fe2a121845aabd2 authored by ffxbld on 24 June 2012, 08:11:04 UTC
Added FIREFOX_14_0b9_RELEASE FIREFOX_14_0b9_BUILD1 tag(s) for changeset d050090e578c. DONTBUILD CLOSED TREE a=release
Tip revision: 1b2df19
simple-match.js
// This executes a very simple search for all functions that call a
// given set of functions. It's intended to be the simplest possible
// way of refactoring a common pattern of function calls. Of course,
// it's still up to a human to decide if the replacement is truely
// suitable, but this gets the low-hanging fruit.

// Expects the variable 'patterns' to hold an object with replacement
// function names as keys and function lists as values. Any function
// in the tested source that calls all of the functions named in the
// list will be listed in the output as being likely candidates to
// instead call the replacement function.

include("unstable/lazy_types.js");

var matches = {};

function identity(x) x;

function process_cp_pre_genericize(fndecl)
{
    var c = [];
    function calls(t, stack)
    {
        try {
            t.tree_check(CALL_EXPR);
            var fn = callable_arg_function_decl(CALL_EXPR_FN(t));
            if (fn)
                c.push(decl_name_string(fn));
        }
        catch (e if e.TreeCheckError) { }
    }

    walk_tree(DECL_SAVED_TREE(fndecl), calls);

    for (let [fnreplace, pattern] in patterns)
        if (pattern.map(function(e){ return c.some(function(f) { return e == f; }); }).every(identity))
            if (fnreplace != (n = decl_name_string(fndecl)))
                print(fnreplace +" could probably be used in "+ n);
}
back to top