def to_abstract(t): if isinstance(t, syntax.TBag): return syntax.TBag(t.t) if isinstance(t, syntax.TSet): return syntax.TSet(t.t) if isinstance(t, syntax.TList): return syntax.TList(t.t) return t
def visit_TApp(self, t): if t.t == "Set": return syntax.TSet(self.visit(t.args)) elif t.t == "Bag": return syntax.TBag(self.visit(t.args)) elif t.t == "List": return syntax.TList(self.visit(t.args)) else: self.report_err(t, "unknown type {}".format(t.t)) return t
def lub(self, src, t1, t2, explanation): if t1 == t2: return t1 if is_numeric(t1) and is_numeric(t2): return self.numeric_lub(src, t1, t2) if isinstance(t1, syntax.TList) and isinstance(t2, syntax.TList): return syntax.TList(t1.t) if is_collection(t1) and is_collection(t2): return syntax.TBag(t1.t) self.report_err( src, "cannot unify types {} and {} ({})".format(pprint(t1), pprint(t2), explanation)) return DEFAULT_TYPE
def visit_EListComprehension(self, e): with self.scope(): for clause in e.clauses: self.visit(clause) self.visit(e.e) e.type = syntax.TList(e.e.type)
def visit_ESingleton(self, e): self.visit(e.e) e.type = syntax.TList(e.e.type)