Ejemplo n.º 1
0
def detect_presence(functionorlist):
    walk_condition = lambda x, y: not isinstance(x, Function) or y[
        "function_init"] == x
    if type(functionorlist) != list:
        functionorlist = [functionorlist]
    args = {
        "this_present": False,
        "break_present": False,
        "eval_present": False,
        "function_init": functionorlist,
        "arguments": False
    }
    for s in functionorlist:
        ret, args = tree_walker.walker(s,
                                       detect_presence_func,
                                       arg=args,
                                       walk_condition=walk_condition)
    if type(functionorlist) != list:
        functionorlist = [functionorlist]
    for s in functionorlist:
        ret, args = tree_walker.walker(s,
                                       detect_presence_func,
                                       arg=args,
                                       walk_condition=walk_condition)
    return args
Ejemplo n.º 2
0
def examine_function_vars(functionorlist, tillencounter=None):
    walk_condition = lambda x, y: y["continue"] and not x.__class__ in [
        Try, CatchClause, FinallyClause
    ] and (not isinstance(x, Function) or y["function_init"] == x)
    args = {
        "function_init": functionorlist,
        "var_dec": {},
        "var_dec_and_assigned": {},
        "ref": {},
        "thisdotref": {},
        "assignment": {},
        "decassignment": {},
        'continue': True,
        "till": tillencounter
    }
    if type(functionorlist) != list:
        functionorlist = [functionorlist]
    for s in functionorlist:
        ret, args = tree_walker.walker(s,
                                       examine_function_vars_func,
                                       examine_function_vars_func_post,
                                       arg=args,
                                       walk_condition=walk_condition)
    local_var = {}
    for k in args["var_dec"].keys():
        local_var[k] = [{"has_been_assigned": False}] + args["var_dec"][k]
    for k in args["var_dec_and_assigned"].keys():
        local_var[k] = [{
            "has_been_assigned": True
        }] + args["var_dec_and_assigned"][k]
    for k in args["ref"].keys():
        if local_var.has_key(k):
            local_var[k] += args["ref"].pop(k)
    for k in args["assignment"].keys():
        if local_var.has_key(k):
            local_var[k] += args["assignment"].pop(k)
            local_var[k][0]["has_been_assigned"] = True
    set_before_ref = args["decassignment"]
    for k in set_before_ref.keys():
        set_before_ref[k] = [{}] + set_before_ref[k]
    var_global_ref = args["ref"]
    for k in var_global_ref.keys():
        var_global_ref[k] = [{}] + var_global_ref[k]
    var_global_set = args["assignment"]
    for k in var_global_set.keys():
        var_global_set[k] = [{}] + var_global_set[k]
    if isinstance(functionorlist, Program):
        for k in var_global_set.keys():
            if local_var.has_key(k):
                local_var[k] += var_global_set[k]
            else:
                local_var[k] = var_global_set[k]
        var_global_set = {}
    return {
        "local_var": local_var,
        "var_global_ref": var_global_ref,
        "var_global_set": var_global_set,
        "thisdotref": args["thisdotref"]
    }
Ejemplo n.º 3
0
def removeindex(program):
    ret, arg = tree_walker.walker(program=program, function=removeindex_func)