def add_if_statement(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply add_if_statement transformation", "with", numbermax
    p = deepcopy(program_tree)
    arg = {"numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])
    walker(p, postfunction=add_if_statement_func_post, arg=arg)
    return p
def change_str(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply change_str transformation", "with", numbermax
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    arg = {"numbermax": numbermax, "ident_present": ret}
    arg["size"] = count_object(p, [String])
    walker(p, postfunction=change_str_func, arg=arg)
    return p
def modify_data_flow_1(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply modify_data_flow_1 transformation"
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    arg = {"ident_present":ret, "numbermax":numbermax}
    arg["size"] = count_object(p, [Assignment])
    walker(p, postfunction=modify_data_flow_1_post_func, arg=arg)
    return p
def duplicate_function(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply duplicate_function transformation", "with", numbermax
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    arg = {"ident_present": ret, "numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])
    walker(p, postfunction=duplicate_function_func_post, arg=arg)
    return p
def evalification(program_tree, verbose=False, numbermax=NUMBERMAX):
    if verbose:
        print "apply evalification transformation"
    p = deepcopy(program_tree)
    arg = {"numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])

    #~ ret =get_all_ident(program_tree)
    walker(p, evalification_func, arg=arg)
    return p
示例#6
0
def rename_variables(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply rename_variables transformation"
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    if "eval" in ret:
        return program_tree
    arg = {"idents": ret, "switcher": [], "numbermax": numbermax}
    arg["size"] = count_object(p, [Ident])
    walker(p, rename_variables_func, rename_variables_post_func, arg=arg)
    return p
def add_dummy_variables(parse_tree, verbose=0, numbermax=NUMBERMAX):
    """This function takes in arpument parse_tree as a parse tree, and will add some dummy variables,
    it will return a new parse tree, with these dummy variables
    the verbose argument allows to increase verbosity"""
    if verbose > 1:
        print "apply add_dummy_var transformation"
    p = deepcopy(parse_tree)
    ret = get_all_ident(parse_tree)
    arg = {"ident_present": ret, "numbermax": numbermax}
    arg["size"] = count_object(p, [Statements])
    walker(p, postfunction=add_dummy_var_func_post, arg=arg)
    return p
def aggregate_data(program_tree, verbose=0, numbermax=NUMBERMAX):
    if verbose > 1:
        print "apply aggregate_data transformation"
    p = deepcopy(program_tree)
    ret = get_all_ident(program_tree)
    arg = {
        "ident_present": ret,
        "numbermax": numbermax,
        "list_aggregation": []
    }
    arg["size"] = count_object(p, [Number])
    walker(p, aggregate_data_func, aggregate_data_post_func, arg=arg)
    return p
示例#9
0
def simplify_if(program_tree, verbose=False, numbermax=NUMBERMAX):
    if verbose:
        print "apply simplify_if transformation"
    p = deepcopy(program_tree)
    walker(p, simplify_if_func, arg=[])
    return p
def remove_empty_statement(program_tree, verbose=False, numbermax=NUMBERMAX):
    if verbose:
        print "apply remove_empty_statement transformation"
    p = deepcopy(program_tree)
    walker(p, remove_empty_statement_func, arg=[])
    return p
示例#11
0
def get_all_ident(program):
    ret, arg = walker(program, function=get_all_ident_func, arg=None)
    ret = list(set(ret))
    return ret
示例#12
0
def get_funcs(program):
    ret, arg = walker(program, function=get_funcs_func)
    return ret 
示例#13
0
def find_ident(program, name):
    ret, arg = walker(program, function=find_ident_func, arg=name)
    return ret
示例#14
0
def find_func(program, funcname):
    ret, arg = walker(program, function=find_func_func, arg=funcname)
    return ret
示例#15
0
def count_object(p, list_obj):
    arg = {}
    arg["size"] = 0
    arg["tocount"] = list_obj
    walker(p, function=count_object_func, arg=arg)
    return arg["size"]
示例#16
0
def gen_dot(program_tree):
    p = copy.deepcopy(program_tree)
    g = pydot.Graph(name="Tree")
    nodelist = []
    walker(p, function=tree_dumper, arg=(g, nodelist))
    return g.to_string()