summaryrefslogtreecommitdiff
path: root/src/PureUtils.ml
diff options
context:
space:
mode:
authorSon Ho2022-02-03 19:44:26 +0100
committerSon Ho2022-02-03 19:44:26 +0100
commit5eacfc7cdbe99f401d6cf925cbb50d63c3a780c3 (patch)
tree940463f3d64b43534bb09bafafd8beccee366d43 /src/PureUtils.ml
parent1dd71ca1d37d5ca7fae5a7e9766e03194dfb764f (diff)
Implement extraction of `if ... then ... else ...`
Diffstat (limited to 'src/PureUtils.ml')
-rw-r--r--src/PureUtils.ml11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/PureUtils.ml b/src/PureUtils.ml
index dfa8c1a3..aa383d8c 100644
--- a/src/PureUtils.ml
+++ b/src/PureUtils.ml
@@ -183,3 +183,14 @@ let functions_not_mutually_recursive (funs : fun_def list) : bool =
with Utils.Found -> false
in
List.for_all body_only_calls_itself funs
+
+(** We use this to check whether we need to add parentheses around expressions.
+ We only look for outer monadic let-bindings.
+ *)
+let rec expression_requires_parentheses (e : texpression) : bool =
+ match e.e with
+ | Value _ | Call _ -> false
+ | Let (monadic, _, _, next_e) ->
+ if monadic then true else expression_requires_parentheses next_e
+ | Switch (_, _) -> false
+ | Meta (_, next_e) -> expression_requires_parentheses next_e