Skip to content

Commit

Permalink
Let arbitrary boolean values used in MaySet encoding depend on reference
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoeilers committed May 6, 2024
1 parent 9ee9d5f commit ea98a33
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/nagini_translation/translators/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,15 +921,15 @@ def get_fresh_int_lit(self, ctx: Context) -> Expr:
return self.viper.IntLit(ctx.get_fresh_int(), self.no_position(ctx),
self.no_info(ctx))

def get_unknown_bool(self, ctx: Context) -> Expr:
def get_unknown_bool(self, arg: Expr, ctx: Context) -> Expr:
"""
Returns an arbitrary but fixed boolean value.
Returns an arbitrary but fixed boolean value that depends on the value of arg.
"""
pos = self.no_position(ctx)
info = self.no_info(ctx)
fresh_int = self.get_fresh_int_lit(ctx)
param = self.viper.LocalVarDecl('i', self.viper.Int, pos, info)
return self.viper.FuncApp(ARBITRARY_BOOL_FUNC, [fresh_int], pos, info,
return self.viper.FuncApp(ARBITRARY_BOOL_FUNC, [fresh_int, self.to_ref(arg, ctx)], pos, info,
self.viper.Bool, [param])

def _conjoin(self, eqs: List[Expr], pos: Position, info: Info) -> Expr:
Expand Down
2 changes: 1 addition & 1 deletion src/nagini_translation/translators/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def translate_may_set(self, node: ast.Call, ctx: Context) -> StmtsAndExpr:
pos, info)
result_ex = self.viper.CondExp(have_normal_perm, normal_acc, may_set_pred, pos,
info)
unknown = self.get_unknown_bool(ctx)
unknown = self.get_unknown_bool(rec, ctx)
result_in = self.viper.CondExp(unknown, normal_acc, may_set_pred, pos, info)
return [], self.viper.InhaleExhaleExp(result_in, result_ex, pos, info)

Expand Down
3 changes: 2 additions & 1 deletion src/nagini_translation/translators/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,8 @@ def create_arbitrary_bool_func(self, ctx: Context) -> 'silver.ast.Function':
pos = self.no_position(ctx)
info = self.no_info(ctx)
i_param_decl = self.viper.LocalVarDecl('i', self.viper.Int, pos, info)
return self.viper.Function(ARBITRARY_BOOL_FUNC, [i_param_decl],
r_param_decl = self.viper.LocalVarDecl('r', self.viper.Ref, pos, info)
return self.viper.Function(ARBITRARY_BOOL_FUNC, [i_param_decl, r_param_decl],
self.viper.Bool, [], [], None, pos, info)

def create_may_set_predicate(self, ctx: Context) -> 'silver.ast.Predicate':
Expand Down

0 comments on commit ea98a33

Please sign in to comment.