@@ -34,6 +34,7 @@ struct BooleanDecisionCtx {
3434 /// To construct condition evaluation tree.
3535 decision_stack : VecDeque < ConditionInfo > ,
3636 conditions : Vec < MCDCBranchSpan > ,
37+ condition_id_counter : usize ,
3738}
3839
3940impl BooleanDecisionCtx {
@@ -43,9 +44,15 @@ impl BooleanDecisionCtx {
4344 decision_info : MCDCDecisionSpan :: new ( Span :: default ( ) ) ,
4445 decision_stack : VecDeque :: new ( ) ,
4546 conditions : vec ! [ ] ,
47+ condition_id_counter : 0 ,
4648 }
4749 }
4850
51+ fn next_condition_id ( & mut self ) -> ConditionId {
52+ self . condition_id_counter += 1 ;
53+ ConditionId :: from_usize ( self . condition_id_counter )
54+ }
55+
4956 // At first we assign ConditionIds for each sub expression.
5057 // If the sub expression is composite, re-assign its ConditionId to its LHS and generate a new ConditionId for its RHS.
5158 //
@@ -89,14 +96,12 @@ impl BooleanDecisionCtx {
8996 fn record_conditions ( & mut self , op : LogicalOp ) {
9097 let parent_condition = self . decision_stack . pop_back ( ) . unwrap_or_default ( ) ;
9198 let lhs_id = if parent_condition. condition_id == ConditionId :: NONE {
92- self . decision_info . num_conditions += 1 ;
93- ConditionId :: from ( self . decision_info . num_conditions )
99+ ConditionId :: from ( self . next_condition_id ( ) )
94100 } else {
95101 parent_condition. condition_id
96102 } ;
97103
98- self . decision_info . num_conditions += 1 ;
99- let rhs_condition_id = ConditionId :: from ( self . decision_info . num_conditions ) ;
104+ let rhs_condition_id = self . next_condition_id ( ) ;
100105
101106 let ( lhs, rhs) = match op {
102107 LogicalOp :: And => {
@@ -147,13 +152,10 @@ impl BooleanDecisionCtx {
147152
148153 self . conditions . push ( MCDCBranchSpan {
149154 span,
150- condition_info : Some ( condition_info) ,
151- true_marker,
152- false_marker,
153- decision_depth : 0 ,
155+ condition_info,
156+ true_markers : vec ! [ true_marker] ,
157+ false_markers : vec ! [ false_marker] ,
154158 } ) ;
155- // In case this decision had only one condition
156- self . decision_info . num_conditions = self . decision_info . num_conditions . max ( 1 ) ;
157159 }
158160
159161 fn is_finished ( & self ) -> bool {
@@ -247,7 +249,6 @@ struct MCDCTargetInfo {
247249impl MCDCTargetInfo {
248250 fn set_depth ( & mut self , depth : u16 ) {
249251 self . decision . decision_depth = depth;
250- self . conditions . iter_mut ( ) . for_each ( |branch| branch. decision_depth = depth) ;
251252 }
252253}
253254
@@ -341,7 +342,9 @@ impl MCDCInfoBuilder {
341342 }
342343
343344 fn append_normal_branches ( & mut self , mut branches : Vec < MCDCBranchSpan > ) {
344- branches. iter_mut ( ) . for_each ( |branch| branch. condition_info = None ) ;
345+ branches
346+ . iter_mut ( )
347+ . for_each ( |branch| branch. condition_info . condition_id = ConditionId :: NONE ) ;
345348 self . normal_branch_spans . extend ( branches) ;
346349 }
347350
0 commit comments