@@ -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 {
@@ -39,15 +40,20 @@ impl BooleanDecisionCtx {
3940 id,
4041 decision_info : MCDCDecisionSpan {
4142 span : Span :: default ( ) ,
42- num_conditions : 0 ,
4343 end_markers : vec ! [ ] ,
4444 decision_depth : 0 ,
4545 } ,
4646 decision_stack : VecDeque :: new ( ) ,
4747 conditions : vec ! [ ] ,
48+ condition_id_counter : 0 ,
4849 }
4950 }
5051
52+ fn next_condition_id ( & mut self ) -> ConditionId {
53+ self . condition_id_counter += 1 ;
54+ ConditionId :: from_usize ( self . condition_id_counter )
55+ }
56+
5157 // At first we assign ConditionIds for each sub expression.
5258 // If the sub expression is composite, re-assign its ConditionId to its LHS and generate a new ConditionId for its RHS.
5359 //
@@ -91,14 +97,12 @@ impl BooleanDecisionCtx {
9197 fn record_conditions ( & mut self , op : LogicalOp ) {
9298 let parent_condition = self . decision_stack . pop_back ( ) . unwrap_or_default ( ) ;
9399 let lhs_id = if parent_condition. condition_id == ConditionId :: NONE {
94- self . decision_info . num_conditions += 1 ;
95- ConditionId :: from ( self . decision_info . num_conditions )
100+ ConditionId :: from ( self . next_condition_id ( ) )
96101 } else {
97102 parent_condition. condition_id
98103 } ;
99104
100- self . decision_info . num_conditions += 1 ;
101- let rhs_condition_id = ConditionId :: from ( self . decision_info . num_conditions ) ;
105+ let rhs_condition_id = self . next_condition_id ( ) ;
102106
103107 let ( lhs, rhs) = match op {
104108 LogicalOp :: And => {
@@ -149,13 +153,10 @@ impl BooleanDecisionCtx {
149153
150154 self . conditions . push ( MCDCBranchSpan {
151155 span,
152- condition_info : Some ( condition_info) ,
153- true_marker,
154- false_marker,
155- decision_depth : 0 ,
156+ condition_info,
157+ true_markers : vec ! [ true_marker] ,
158+ false_markers : vec ! [ false_marker] ,
156159 } ) ;
157- // In case this decision had only one condition
158- self . decision_info . num_conditions = self . decision_info . num_conditions . max ( 1 ) ;
159160 }
160161
161162 fn is_finished ( & self ) -> bool {
@@ -247,7 +248,6 @@ struct MCDCTargetInfo {
247248impl MCDCTargetInfo {
248249 fn set_depth ( & mut self , depth : u16 ) {
249250 self . decision . decision_depth = depth;
250- self . conditions . iter_mut ( ) . for_each ( |branch| branch. decision_depth = depth) ;
251251 }
252252}
253253
@@ -340,7 +340,9 @@ impl MCDCInfoBuilder {
340340 }
341341
342342 fn append_normal_branches ( & mut self , mut branches : Vec < MCDCBranchSpan > ) {
343- branches. iter_mut ( ) . for_each ( |branch| branch. condition_info = None ) ;
343+ branches
344+ . iter_mut ( )
345+ . for_each ( |branch| branch. condition_info . condition_id = ConditionId :: NONE ) ;
344346 self . normal_branch_spans . extend ( branches) ;
345347 }
346348
0 commit comments