def check_feu(assumes, asserts, macros): """ Take a list of assumes, assert and macros, and determines whether collectively they are in the FEU fragment, raising an error exception if not. """ # Alpha convert so that all the variables have unique names, global var_uniq var_uniq = il.VariableUniqifier() def vupair(p): return (var_uniq(p[0]), p[1]) assumes = map(vupair, assumes) asserts = map(vupair, asserts) macros = map(vupair, macros) # Create the stratificaiton graph, as described above. create_strat_map(assumes, asserts, macros) # Check for cycles in the stratification graph. report_cycle( iu.cycle(arcs, first=lambda x: find(x[0]), second=lambda x: find(x[1])))
def get_unstratified_funs(assumes, asserts, macros): vu = il.VariableUniqifier() def vupair(p): return (vu(p[0]), p[1]) assumes = map(vupair, assumes) asserts = map(vupair, asserts) macros = map(vupair, macros) strat_map = create_strat_map(assumes, asserts, macros) # for f,g in macros: # print 'macro: {}'.format(f) arcs = list(get_sort_arcs(assumes + macros, asserts, strat_map)) sccs = get_sort_sccs(arcs) scc_map = dict((name, idx) for idx, scc in enumerate(sccs) for name in scc) scc_arcs = [[] for x in sccs] unstrat = set() for ds, rng, ast in arcs: if scc_map[ds] == scc_map[rng]: scc_arcs[scc_map[ds]].append(ast) for y in strat_map.values(): find(y).variables.update(y.variables) fun_sccs = [(x, y) for x, y in zip(sccs, scc_arcs) if y and any(len(n.variables) > 0 for n in x)] arc_map = defaultdict(list) for x, y, z in arcs: arc_map[x].append(y) for scc in sccs: for n in scc: for m in arc_map[n]: m.variables.update(n.variables) # print 'sccs:' # for scc in sccs: # print [str(x) for x in scc] # show_strat_map(strat_map) bad_interpreted = set() for x, y in strat_map.iteritems(): y = find(y) if isinstance(x, tuple) and (il.is_interpreted_symbol(x[0]) or x[0].name == '='): if any(v in universally_quantified_variables and v.sort == x[0]. sort.dom[x[1]] and il.has_infinite_interpretation(v.sort) for v in y.variables): bad_interpreted.add(x[0]) return fun_sccs, bad_interpreted