def visit_constraint_if_else(self, c: ConstraintIfElseModel): from .model_pretty_printer import ModelPrettyPrinter if self.do_copy_level > 0: ret = ConstraintIfElseModel(self.expr(c.cond)) ret.true_c = ConstraintScopeModel() with ConstraintCollector(self, ret.true_c): for cs in c.true_c.constraint_l: cs.accept(self) if c.false_c is not None: ret.false_c = ConstraintScopeModel() with ConstraintCollector(self, ret.false_c): c.false_c.accept(self) self.constraints.append(ret) else: super().visit_constraint_if_else(c)
def __enter__(self): if not in_constraint_scope(): raise Exception("Attempting to use if_then constraint outside constraint scope") last_stmt = last_constraint_stmt() if last_stmt == None or not isinstance(last_stmt, ConstraintIfElseModel): raise Exception("Attempting to use else_then where it doesn't follow if_then/else_if") # Need to find where to think this in while last_stmt.false_c != None: last_stmt = last_stmt.false_c stmt = ConstraintScopeModel() last_stmt.false_c = stmt push_constraint_scope(stmt)
def __enter__(self): if self.stmt is not None: self.stmt.true_c = ConstraintScopeModel() push_constraint_scope(self.stmt.true_c)