def int_check_term(self, ast_node, ctxt): (s0, ts, cs0) = self.int_check_term(ast_node.terms, ctxt) cs1 = [] t1 = tyVar() for t0 in ts: cs1.append(t1 |Eq| tyMSet(t0) |just| [ast_node]) self.mark_for_infer(ast_node, t1) return (s0, t1, cs1 + cs0)
def int_check_term(self, ast_node, ctxt): (s0, ts, cs0) = self.int_check_term(ast_node.terms, ctxt) cs1 = [] t1 = tyVar() for t0 in ts: cs1.append(t1 | Eq | tyMSet(t0) | just | [ast_node]) self.mark_for_infer(ast_node, t1) return (s0, t1, cs1 + cs0)
def int_check_term(self, ast_node, ctxt): (s0,t0,cs0) = self.int_check_term(ast_node.term1, ctxt) (s1,t1,cs1) = self.int_check_term(ast_node.term2, ctxt) t3 = tyVar() if ast_node.op in BOOL_OPS_1: cs3 = [t0 |Eq| t1 |just| [ast_node], t3 |Eq| tyBool |just| [ast_node]] elif ast_node.op in BOOL_OPS_2: cs3 = [tyMSet(t0) |Eq| t1 |just| [ast_node], t3 |Eq| tyBool |just| [ast_node]] elif ast_node.op in NUM_OPS: cs3 = [t0 |Eq| t1 |just| [ast_node], t0 |Eq| t3 |just| [ast_node]] self.mark_for_infer(ast_node, t3) return (s0 and s1, t3, cs3 + cs0 + cs1)
def int_check_term(self, ast_node, ctxt): local_ctxt = copy_ctxt( ctxt ) s0 = True all_cons = [] for comp_range in ast_node.comp_ranges: (s,cs) = self.int_check_comp_range( comp_range, ctxt, local_ctxt ) s0 = s0 and s all_cons += cs (s,t0,cs) = self.int_check_term(ast_node.term, local_ctxt) t1 = tyVar() s0 = s0 and s all_cons += [t1 |Eq| tyMSet(t0) |just| [ast_node]] + cs for guard in ast_node.guards: (s,tg,cs) = self.int_check_term( guard, local_ctxt ) s0 = s0 and s all_cons += [tg |Eq| tyBool |just| [ast_node]] + cs self.mark_for_infer(ast_node, t1) return (s0, t1, all_cons)
def int_check_term(self, ast_node, ctxt): local_ctxt = copy_ctxt(ctxt) s0 = True all_cons = [] for comp_range in ast_node.comp_ranges: (s, cs) = self.int_check_comp_range(comp_range, ctxt, local_ctxt) s0 = s0 and s all_cons += cs (s, t0, cs) = self.int_check_term(ast_node.term, local_ctxt) t1 = tyVar() s0 = s0 and s all_cons += [t1 | Eq | tyMSet(t0) | just | [ast_node]] + cs for guard in ast_node.guards: (s, tg, cs) = self.int_check_term(guard, local_ctxt) s0 = s0 and s all_cons += [tg | Eq | tyBool | just | [ast_node]] + cs self.mark_for_infer(ast_node, t1) return (s0, t1, all_cons)
def transformCompre(self, compre, rule_dec): if len(compre.comp_ranges) == 0 and compre.compre_mod in [ast.COMP_NONE_EXISTS,ast.COMP_ONE_OR_MORE]: term_vars = ast.TermLit(1,"int") next_rule_idx = rule_dec.next_rule_idx rule_dec.next_rule_idx += 1 term_range = ast.TermVar( "comp_mod_%s" % next_rule_idx ) term_range.rule_idx = next_rule_idx term_range.type = ast.TypeMSet( term_vars.type ) term_range.smt_type = tyMSet( tyInt ) compre.comp_ranges = [ ast.CompRange(term_vars, term_range) ] if compre.compre_mod == ast.COMP_NONE_EXISTS: term_range = compre.comp_ranges[0].term_range comp_none_exist_grd = ast.TermBinOp( ast.TermApp(ast.TermCons("size"), term_range), "==", ast.TermLit(0, "int")) rule_dec.grd += [comp_none_exist_grd] elif compre.compre_mod == ast.COMP_ONE_OR_MORE: term_range = compre.comp_ranges[0].term_range comp_one_or_more_grd = ast.TermBinOp( ast.TermApp(ast.TermCons("size"), term_range), ">", ast.TermLit(0, "int")) rule_dec.grd += [comp_one_or_more_grd]
def int_check_term(self, ast_node, ctxt): (s0, t0, cs0) = self.int_check_term(ast_node.term1, ctxt) (s1, t1, cs1) = self.int_check_term(ast_node.term2, ctxt) t3 = tyVar() if ast_node.op in BOOL_OPS_1: cs3 = [ t0 | Eq | t1 | just | [ast_node], t3 | Eq | tyBool | just | [ast_node] ] elif ast_node.op in BOOL_OPS_2: cs3 = [ tyMSet(t0) | Eq | t1 | just | [ast_node], t3 | Eq | tyBool | just | [ast_node] ] elif ast_node.op in NUM_OPS: cs3 = [ t0 | Eq | t1 | just | [ast_node], t0 | Eq | t3 | just | [ast_node] ] self.mark_for_infer(ast_node, t3) return (s0 and s1, t3, cs3 + cs0 + cs1)
def int_check_type(self, ast_node, ctxt): (s,t1,cons) = self.int_check_type(ast_node.type, ctxt) t0 = tyVar() return (s,t0,[t0 |Eq| tyMSet(t1) |just| [ast_node]] + cons)
def int_check_comp_range(self, comp_range, ctxt, local_ctxt): (s0,t0,cs0) = self.int_check_term(comp_range.term_vars, local_ctxt) (s1,t1,cs1) = self.int_check_term(comp_range.term_range, ctxt) return (s0 and s1, [(t1 |Eq| tyMSet(t0) |just| [comp_range])|Or|(t1 |Eq| tyList(t0) |just| [comp_range])] + cs0 + cs1)
def int_check_type(self, ast_node, ctxt): (s, t1, cons) = self.int_check_type(ast_node.type, ctxt) t0 = tyVar() return (s, t0, [t0 | Eq | tyMSet(t1) | just | [ast_node]] + cons)
def int_check_comp_range(self, comp_range, ctxt, local_ctxt): (s0, t0, cs0) = self.int_check_term(comp_range.term_vars, local_ctxt) (s1, t1, cs1) = self.int_check_term(comp_range.term_range, ctxt) return (s0 and s1, [(t1 | Eq | tyMSet(t0) | just | [comp_range]) | Or | (t1 | Eq | tyList(t0) | just | [comp_range])] + cs0 + cs1)