diff options
author | Son Ho | 2022-01-06 11:27:46 +0100 |
---|---|---|
committer | Son Ho | 2022-01-06 11:27:46 +0100 |
commit | 3cadf01e5b67af4ec91f2de3c32e119cd90c678c (patch) | |
tree | 57728573700705269e6c08f2c490f678fc766637 /src/ValuesUtils.ml | |
parent | 6ef1bf7e2f1b7a0067169bf71860671f8b3f6bca (diff) |
Move more definitions and do more cleanup
Diffstat (limited to '')
-rw-r--r-- | src/ValuesUtils.ml | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/ValuesUtils.ml b/src/ValuesUtils.ml index 4a503a65..f4a10287 100644 --- a/src/ValuesUtils.ml +++ b/src/ValuesUtils.ml @@ -1,3 +1,4 @@ +open Utils open TypesUtils open Types open Values @@ -12,3 +13,48 @@ let mk_box_value (v : typed_value) : typed_value = let box_ty = mk_box_ty v.ty in let box_v = Adt { variant_id = None; field_values = [ v ] } in mk_typed_value box_ty box_v + +(** Check if a value contains a borrow *) +let borrows_in_value (v : typed_value) : bool = + let obj = + object + inherit [_] iter_typed_value + + method! visit_borrow_content _env _ = raise Found + end + in + (* We use exceptions *) + try + obj#visit_typed_value () v; + false + with Found -> true + +(** Check if a value contains inactivated mutable borrows *) +let inactivated_in_value (v : typed_value) : bool = + let obj = + object + inherit [_] iter_typed_value + + method! visit_InactivatedMutBorrow _env _ = raise Found + end + in + (* We use exceptions *) + try + obj#visit_typed_value () v; + false + with Found -> true + +(** Check if a value contains a loan *) +let loans_in_value (v : typed_value) : bool = + let obj = + object + inherit [_] iter_typed_value + + method! visit_loan_content _env _ = raise Found + end + in + (* We use exceptions *) + try + obj#visit_typed_value () v; + false + with Found -> true |