@@ -31,6 +31,7 @@ struct BooleanDecisionCtx {
3131 /// To construct condition evaluation tree.
3232 decision_stack : VecDeque < ConditionInfo > ,
3333 conditions : Vec < MCDCBranchSpan > ,
34+ condition_id_counter : usize ,
3435}
3536
3637impl BooleanDecisionCtx {
@@ -40,9 +41,15 @@ impl BooleanDecisionCtx {
4041 decision_info : MCDCDecisionSpan :: new ( Span :: default ( ) ) ,
4142 decision_stack : VecDeque :: new ( ) ,
4243 conditions : vec ! [ ] ,
44+ condition_id_counter : 0 ,
4345 }
4446 }
4547
48+ fn next_condition_id ( & mut self ) -> ConditionId {
49+ self . condition_id_counter += 1 ;
50+ ConditionId :: from_usize ( self . condition_id_counter )
51+ }
52+
4653 // At first we assign ConditionIds for each sub expression.
4754 // If the sub expression is composite, re-assign its ConditionId to its LHS and generate a new ConditionId for its RHS.
4855 //
@@ -86,14 +93,12 @@ impl BooleanDecisionCtx {
8693 fn record_conditions ( & mut self , op : LogicalOp ) {
8794 let parent_condition = self . decision_stack . pop_back ( ) . unwrap_or_default ( ) ;
8895 let lhs_id = if parent_condition. condition_id == ConditionId :: NONE {
89- self . decision_info . num_conditions += 1 ;
90- ConditionId :: from ( self . decision_info . num_conditions )
96+ ConditionId :: from ( self . next_condition_id ( ) )
9197 } else {
9298 parent_condition. condition_id
9399 } ;
94100
95- self . decision_info . num_conditions += 1 ;
96- let rhs_condition_id = ConditionId :: from ( self . decision_info . num_conditions ) ;
101+ let rhs_condition_id = self . next_condition_id ( ) ;
97102
98103 let ( lhs, rhs) = match op {
99104 LogicalOp :: And => {
@@ -144,13 +149,10 @@ impl BooleanDecisionCtx {
144149
145150 self . conditions . push ( MCDCBranchSpan {
146151 span,
147- condition_info : Some ( condition_info) ,
148- true_marker,
149- false_marker,
150- decision_depth : 0 ,
152+ condition_info,
153+ true_markers : vec ! [ true_marker] ,
154+ false_markers : vec ! [ false_marker] ,
151155 } ) ;
152- // In case this decision had only one condition
153- self . decision_info . num_conditions = self . decision_info . num_conditions . max ( 1 ) ;
154156 }
155157
156158 fn is_finished ( & self ) -> bool {
@@ -244,7 +246,6 @@ struct MCDCTargetInfo {
244246impl MCDCTargetInfo {
245247 fn set_depth ( & mut self , depth : u16 ) {
246248 self . decision . decision_depth = depth;
247- self . conditions . iter_mut ( ) . for_each ( |branch| branch. decision_depth = depth) ;
248249 }
249250}
250251
@@ -338,7 +339,9 @@ impl MCDCInfoBuilder {
338339 }
339340
340341 fn append_normal_branches ( & mut self , mut branches : Vec < MCDCBranchSpan > ) {
341- branches. iter_mut ( ) . for_each ( |branch| branch. condition_info = None ) ;
342+ branches
343+ . iter_mut ( )
344+ . for_each ( |branch| branch. condition_info . condition_id = ConditionId :: NONE ) ;
342345 self . normal_branch_spans . extend ( branches) ;
343346 }
344347
0 commit comments