summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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"
)