@@ -6853,24 +6853,31 @@ and doStatement (s : A.statement) : chunk =
68536853 exitLoop () ;
68546854 loopChunk (s' @@ s'')
68556855
6856- | A. FOR (fc1 ,e2 ,e3 ,s ,loc ,eloc ) -> begin
6856+ | A. FOR (fc1 ,fc_loc , e2 ,e2_loc , e3 , e3_loc ,s ,loc ,eloc ) -> begin
68576857 let loc' = convLoc loc in
68586858 let eloc' = convLoc eloc in
6859- currentLoc := loc'; (* For loop statement location is not synthetic. *)
6860- currentExpLoc := SynthetizeLoc. doLoc eloc';
6859+ let fc_loc' = convLoc fc_loc in
6860+ let e2_loc' = convLoc e2_loc in
6861+ let e3_loc' = convLoc e3_loc in
6862+ currentLoc := loc'; (* For loop statement location is not synthetic (see se1 comment below). *)
6863+ currentExpLoc := SynthetizeLoc. doLoc fc_loc';
68616864 enterScope () ; (* Just in case we have a declaration *)
68626865 let (se1, _, _) =
68636866 match fc1 with
68646867 FC_EXP e1 -> doExp false e1 ADrop
6865- | FC_DECL d1 -> (doDecl false false d1, zero, voidType)
6868+ | FC_DECL d1 -> (doDecl false false d1, zero, voidType) (* doDecl may modify currentLoc and currentExpLoc! *)
68666869 in
68676870 (* First instruction (assignment) in for loop initializer has non-synthetic statement location before for loop.
68686871 Its expression location inside for loop parentheses is synthetic.
68696872 All other instructions are fully synthetic. *)
68706873 let se1 = SynthetizeLoc. eDoChunkHead (SynthetizeLoc. doChunkTail se1) in
6871- let (se3, _, _) = doExp false e3 ADrop in
6872- let se3 = SynthetizeLoc. doChunkHead se3 in
6874+ (* Reset both locations due to doDecl (see above). *)
6875+ currentLoc := loc'; (* TODO: Why is statement location not synthetic here? Not needed? *)
6876+ currentExpLoc := SynthetizeLoc. doLoc e3_loc';
6877+ let (se3, _, _) = doExp false e3 ADrop in (* doExp does doChunkTail *)
6878+ let se3 = SynthetizeLoc. doChunkHead se3 in (* So just doChunkHead is enough *)
68736879 startLoop false ;
6880+ (* TODO: Are these locations ever used in doStatement? Why not synthetic? *)
68746881 currentLoc := loc';
68756882 currentExpLoc := eloc';
68766883 let s' = doStatement s in
@@ -6880,6 +6887,8 @@ and doStatement (s : A.statement) : chunk =
68806887 let break_cond = breakChunk loc' in (* TODO: use eloc'? *)
68816888 exitLoop () ;
68826889 let res =
6890+ currentLoc := SynthetizeLoc. doLoc loc';
6891+ currentExpLoc := SynthetizeLoc. doLoc e2_loc';
68836892 match e2 with
68846893 A. NOTHING -> (* This means true *)
68856894 se1 @@ loopChunk (consLabLoopCondition s' @@ s'')
0 commit comments