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