@@ -31,6 +31,7 @@ struct BooleanDecisionCtx {
31
31
/// To construct condition evaluation tree.
32
32
decision_stack : VecDeque < ConditionInfo > ,
33
33
conditions : Vec < MCDCBranchSpan > ,
34
+ condition_id_counter : usize ,
34
35
}
35
36
36
37
impl BooleanDecisionCtx {
@@ -40,9 +41,15 @@ impl BooleanDecisionCtx {
40
41
decision_info : MCDCDecisionSpan :: new ( Span :: default ( ) ) ,
41
42
decision_stack : VecDeque :: new ( ) ,
42
43
conditions : vec ! [ ] ,
44
+ condition_id_counter : 0 ,
43
45
}
44
46
}
45
47
48
+ fn next_condition_id ( & mut self ) -> ConditionId {
49
+ self . condition_id_counter += 1 ;
50
+ ConditionId :: from_usize ( self . condition_id_counter )
51
+ }
52
+
46
53
// At first we assign ConditionIds for each sub expression.
47
54
// If the sub expression is composite, re-assign its ConditionId to its LHS and generate a new ConditionId for its RHS.
48
55
//
@@ -86,14 +93,12 @@ impl BooleanDecisionCtx {
86
93
fn record_conditions ( & mut self , op : LogicalOp ) {
87
94
let parent_condition = self . decision_stack . pop_back ( ) . unwrap_or_default ( ) ;
88
95
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 ( ) )
91
97
} else {
92
98
parent_condition. condition_id
93
99
} ;
94
100
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 ( ) ;
97
102
98
103
let ( lhs, rhs) = match op {
99
104
LogicalOp :: And => {
@@ -144,13 +149,10 @@ impl BooleanDecisionCtx {
144
149
145
150
self . conditions . push ( MCDCBranchSpan {
146
151
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] ,
151
155
} ) ;
152
- // In case this decision had only one condition
153
- self . decision_info . num_conditions = self . decision_info . num_conditions . max ( 1 ) ;
154
156
}
155
157
156
158
fn is_finished ( & self ) -> bool {
@@ -244,7 +246,6 @@ struct MCDCTargetInfo {
244
246
impl MCDCTargetInfo {
245
247
fn set_depth ( & mut self , depth : u16 ) {
246
248
self . decision . decision_depth = depth;
247
- self . conditions . iter_mut ( ) . for_each ( |branch| branch. decision_depth = depth) ;
248
249
}
249
250
}
250
251
@@ -338,7 +339,9 @@ impl MCDCInfoBuilder {
338
339
}
339
340
340
341
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 ) ;
342
345
self . normal_branch_spans . extend ( branches) ;
343
346
}
344
347
0 commit comments