def translate(self, translator: 'AbstractTranslator', ctx: 'Context', position: Position, info: Info) -> Expr: if not self._elements: return translator.viper.IntLit(0, position, info) else: elements = [ element.translate(translator, ctx, position, info) for element in self._elements ] plus_operator = (lambda left, right: translator.viper.Add( left, right, position, info)) return join_expressions(plus_operator, elements)
def _create_guard_condition(self) -> Expr: """Generate a Silver expression that guards current AST node.""" guard_sil_parts = [] for part in self.current_guard: sil_part = self._translate_expr(part, target_type=self._viper.Bool) guard_sil_parts.append(sil_part) and_operator = ( lambda left, right: self._viper.And(left, right, self._position(), self._no_info())) condition = join_expressions( and_operator, [self._termination_condition] + guard_sil_parts) return condition
def translate(self, translator: 'AbstractTranslator', ctx: 'Context', position: Position, info: Info) -> Expr: if self.is_always_true(): return translator.viper.TrueLit(position, info) disjuncts = [ disjunct.translate(translator, ctx, position, info) for disjunct in self._disjuncts if not disjunct.is_always_false()] if not disjuncts: return translator.viper.FalseLit(position, info) else: or_operator = ( lambda left, right: translator.viper.Or(left, right, position, info)) return join_expressions(or_operator, disjuncts)
def _translate_obligation_use( self, node: ast.Call, ctx: Context, expected_type: type) -> StmtsAndExpr: obligation_info = self._get_obligation_info(ctx) guarded_obligation_instance = obligation_info.get_instance(node) obligation_instance = guarded_obligation_instance.obligation_instance assert isinstance(obligation_instance, expected_type) exprs_with_rules = self._create_obligation_instance_use( obligation_instance, ctx) info = self.no_info(ctx) translated_expressions = [] for expression, rules in exprs_with_rules: position = self.to_position(node, ctx, rules=rules) translated_expression = expression.translate( self, ctx, position, info) translated_expressions.append(translated_expression) and_operator = ( lambda left, right: self.viper.And(left, right, position, info)) return ([], join_expressions(and_operator, translated_expressions))