Beispiel #1
0
def update_method_stack(node, old_name, new_name):
    nname, children, *rest = node
    if not (':if_' in nname or ':while_' in nname):
        return
    method, ctrl, cname, num, can_empty, cstack = util.parse_pseudo_name(nname)
    assert method == old_name
    name = util.unparse_pseudo_name(new_name, ctrl, cname, num, can_empty,
                                    cstack)
    #assert '?' not in name
    node[0] = name
    for c in node[1]:
        update_method_stack(c, old_name, new_name)
Beispiel #2
0
def update_pseudo_name(k_m, my_id):
    # fixup k_m with what is in my_id
    original = k_m[0]
    method, ctrl, cid, altid, can_empty, method_stack = util.parse_pseudo_name(
        original)
    if ctrl == 'if':
        name = util.unparse_pseudo_name(method, ctrl, cid,
                                        "%s.%d" % (altid, my_id), can_empty,
                                        method_stack)
    elif ctrl == 'while':
        assert altid == '0'
        name = util.unparse_pseudo_name(method, ctrl, cid, my_id, can_empty,
                                        method_stack)
    else:
        assert False
    k_m[0] = name
    return name, k_m
Beispiel #3
0
def can_the_loop_be_deleted(pattern, k, executable):
    xnodes = [
        xnode for xnode in NODE_REGISTER[k] if xnode[-1]['pattern'] == pattern
    ]
    can_be_deleted = True
    for xnode in xnodes:
        node0, tree0, executable0, inputfile0, _info = xnode
        a = util.is_a_replaceable_with_b(
            (node0, '', tree0), (['', [], 0, 0], '', tree0), executable)
        if not a:
            can_be_deleted = False
            break
    for xnode in xnodes:
        node0, tree0, executable0, inputfile0, info = xnode
        method1, ctrl1, cname1, num1, can_empty, cstack1 = util.parse_pseudo_name(
            node0[0])
        name = util.unparse_pseudo_name(
            method1, ctrl1, cname1, num1,
            util.Epsilon if can_be_deleted else util.NoEpsilon, cstack1)
        info['node'][0] = name