summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bracht Laumann Jespersen <t@laumann.xyz>2024-12-20 17:01:47 +0100
committerThomas Bracht Laumann Jespersen <t@laumann.xyz>2024-12-20 17:01:47 +0100
commitde50c86cf584a22252c455194d798b40696729bc (patch)
tree0ed00d10b7dbd5571bd8083fcfdd55448efd1ea8
parentc61bb94156c757f70c2038bc929d077b51885262 (diff)
lc/semanticanalysis: simplify labeling with loops and switchHEADmaster
-rw-r--r--lc/lib/semanticanalysis.ml30
1 files changed, 6 insertions, 24 deletions
diff --git a/lc/lib/semanticanalysis.ml b/lc/lib/semanticanalysis.ml
index babe444..c82c960 100644
--- a/lc/lib/semanticanalysis.ml
+++ b/lc/lib/semanticanalysis.ml
@@ -66,39 +66,21 @@ let checklabels =
Ok (Compound (Block (List.rev blockitems')))
| While (_, exp, stmt) ->
let loop_label = mk_loop_label "while" in
- let labelstate' = match labelstate with
- | Some (switch_label, true, _) -> (* currently in a switch *)
- Some (loop_label, false, Some (switch_label, true))
- | _ ->
- Some (loop_label, false, None)
- in
- let* stmt' = map_labeled labelstate' stmt in
+ let* stmt' = map_labeled (Some (loop_label, false, None)) stmt in
Ok (While (loop_label, exp, stmt'))
| DoWhile (_, stmt, exp) ->
let loop_label = mk_loop_label "dowhile" in
- let labelstate' = match labelstate with
- | Some (switch_label, true, _) -> (* currently in a switch *)
- Some (loop_label, false, Some (switch_label, true))
- | _ ->
- Some (loop_label, false, None)
- in
- let* stmt' = map_labeled labelstate' stmt in
+ let* stmt' = map_labeled (Some (loop_label, false, None)) stmt in
Ok (DoWhile (loop_label, stmt', exp))
| For (_, init, cond, post, body) ->
let loop_label = mk_loop_label "for" in
- let labelstate' = match labelstate with
- | Some (_, true, _) -> (* currently in a switch *)
- Some (loop_label, false, None)
- | _ ->
- Some (loop_label, false, None)
- in
- let* body' = map_labeled labelstate' body in
+ let* body' = map_labeled (Some (loop_label, false, None)) body in
Ok (For (loop_label, init, cond, post, body'))
| Switch (_, cases, default, cond, body) ->
let switch_label = mk_loop_label "switch" in
let labelstate' = match labelstate with
- | Some (loop_label, false, _) -> (* currently in a loop *)
- Some (switch_label, true, Some (loop_label, false))
+ | Some (loop_label, false, _) -> (* currently in a loop *)
+ Some (switch_label, true, Some loop_label)
| _ ->
Some (switch_label, true, None)
in
@@ -121,7 +103,7 @@ let checklabels =
match labelstate with
| Some (label, false, _) ->
Ok (Continue label)
- | Some (_, true, Some (label, false)) ->
+ | Some (_, true, Some label) ->
Ok (Continue label)
| _ -> Error "continue statement not within a loop"
)