@@ -86,6 +86,8 @@ let alwaysGenerateVarDecl = false
8686*)
8787let addNestedScopeAttr = ref false
8888
89+ let addLoopConditionLabels = ref false
90+
8991(* * Indicates whether we're allowed to duplicate small chunks. *)
9092let allowDuplication: bool ref = ref true
9193
@@ -1257,6 +1259,12 @@ let consLabContinue (c: chunk) =
12571259 | While :: rest -> c
12581260 | NotWhile lr :: rest -> if ! lr = " " then c else consLabel ! lr c ! currentLoc false
12591261
1262+ let consLabLoopCondition (c : chunk ) =
1263+ if ! addLoopConditionLabels then
1264+ consLabel (newLabelName " __loop_condition" ) c ! currentLoc false
1265+ else
1266+ c
1267+
12601268let break_env = Stack. create ()
12611269
12621270let enter_break_env () = Stack. push () break_env
@@ -6792,7 +6800,7 @@ and doStatement (s : A.statement) : chunk =
67926800 exitLoop () ;
67936801 currentLoc := SynthetizeLoc. doLoc loc';
67946802 currentExpLoc := SynthetizeLoc. doLoc eloc';
6795- loopChunk ((doCondition false e skipChunk break_cond)
6803+ loopChunk (consLabLoopCondition (doCondition false e skipChunk break_cond)
67966804 @@ s')
67976805
67986806 | A. DOWHILE (e ,s ,loc ,eloc ) ->
@@ -6803,7 +6811,7 @@ and doStatement (s : A.statement) : chunk =
68036811 currentLoc := SynthetizeLoc. doLoc loc';
68046812 currentExpLoc := SynthetizeLoc. doLoc eloc';
68056813 let s'' =
6806- consLabContinue (doCondition false e skipChunk (breakChunk loc')) (* TODO: use eloc'? *)
6814+ consLabContinue (consLabLoopCondition ( doCondition false e skipChunk (breakChunk loc') )) (* TODO: use eloc'? *)
68076815 in
68086816 exitLoop () ;
68096817 loopChunk (s' @@ s'')
@@ -6837,9 +6845,9 @@ and doStatement (s : A.statement) : chunk =
68376845 let res =
68386846 match e2 with
68396847 A. NOTHING -> (* This means true *)
6840- se1 @@ loopChunk (s' @@ s'')
6848+ se1 @@ loopChunk (consLabLoopCondition s' @@ s'')
68416849 | _ ->
6842- se1 @@ loopChunk ((doCondition false e2 skipChunk break_cond)
6850+ se1 @@ loopChunk (consLabLoopCondition (doCondition false e2 skipChunk break_cond)
68436851 @@ s' @@ s'')
68446852 in
68456853 exitScope () ;
0 commit comments