@@ -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 {
@@ -39,15 +40,20 @@ impl BooleanDecisionCtx {
39
40
id,
40
41
decision_info : MCDCDecisionSpan {
41
42
span : Span :: default ( ) ,
42
- num_conditions : 0 ,
43
43
end_markers : vec ! [ ] ,
44
44
decision_depth : 0 ,
45
45
} ,
46
46
decision_stack : VecDeque :: new ( ) ,
47
47
conditions : vec ! [ ] ,
48
+ condition_id_counter : 0 ,
48
49
}
49
50
}
50
51
52
+ fn next_condition_id ( & mut self ) -> ConditionId {
53
+ self . condition_id_counter += 1 ;
54
+ ConditionId :: from_usize ( self . condition_id_counter )
55
+ }
56
+
51
57
// At first we assign ConditionIds for each sub expression.
52
58
// If the sub expression is composite, re-assign its ConditionId to its LHS and generate a new ConditionId for its RHS.
53
59
//
@@ -91,14 +97,12 @@ impl BooleanDecisionCtx {
91
97
fn record_conditions ( & mut self , op : LogicalOp ) {
92
98
let parent_condition = self . decision_stack . pop_back ( ) . unwrap_or_default ( ) ;
93
99
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 ( ) )
96
101
} else {
97
102
parent_condition. condition_id
98
103
} ;
99
104
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 ( ) ;
102
106
103
107
let ( lhs, rhs) = match op {
104
108
LogicalOp :: And => {
@@ -149,13 +153,10 @@ impl BooleanDecisionCtx {
149
153
150
154
self . conditions . push ( MCDCBranchSpan {
151
155
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] ,
156
159
} ) ;
157
- // In case this decision had only one condition
158
- self . decision_info . num_conditions = self . decision_info . num_conditions . max ( 1 ) ;
159
160
}
160
161
161
162
fn is_finished ( & self ) -> bool {
@@ -247,7 +248,6 @@ struct MCDCTargetInfo {
247
248
impl MCDCTargetInfo {
248
249
fn set_depth ( & mut self , depth : u16 ) {
249
250
self . decision . decision_depth = depth;
250
- self . conditions . iter_mut ( ) . for_each ( |branch| branch. decision_depth = depth) ;
251
251
}
252
252
}
253
253
@@ -340,7 +340,9 @@ impl MCDCInfoBuilder {
340
340
}
341
341
342
342
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 ) ;
344
346
self . normal_branch_spans . extend ( branches) ;
345
347
}
346
348
0 commit comments