@@ -86,7 +86,8 @@ measure <- function(expr, only_time = FALSE) {
86
86
87
87
build_return_value <- function (covr , covr_time ,
88
88
slicing_coverage , slicing_points , ana_time , slicing_time , query_time ,
89
- unknown_locations ) {
89
+ unknown_locations ,
90
+ srcrefs ) {
90
91
if (get_option(" measure_time" ) || get_option(" return_covr_result" ) || get_option(" slicing_points" )) {
91
92
res <- list (coverage = slicing_coverage )
92
93
if (get_option(" measure_time" )) {
@@ -105,6 +106,9 @@ build_return_value <- function(covr, covr_time,
105
106
if (get_option(" unknown_locations" )) {
106
107
res $ unknown_locations <- unknown_locations
107
108
}
109
+ if (get_option(" return_srcrefs" )) {
110
+ res $ srcrefs <- srcrefs
111
+ }
108
112
return (res )
109
113
}
110
114
@@ -146,7 +150,7 @@ build_loc2id_map <- function(nodes) {
146
150
return (location_to_id )
147
151
}
148
152
149
- add_ids_to_coverage <- function (coverage ) {
153
+ add_slc_to_coverage <- function (coverage , slice ) {
150
154
logger :: log_trace(" Merging coverage and slice" , namespace = " slicingCoverage" )
151
155
if (" result" %in% names(coverage )) {
152
156
coverage <- coverage $ result
@@ -173,6 +177,7 @@ add_ids_to_coverage <- function(coverage) {
173
177
next
174
178
}
175
179
elem $ flowr_ids <- ids
180
+ elem $ in_slice <- any(ids %in% slice )
176
181
coverage [[file_and_srcref ]] <- elem
177
182
}
178
183
@@ -194,24 +199,25 @@ add_ids_to_coverage <- function(coverage) {
194
199
))
195
200
}
196
201
197
- remove_ids_from_coverage <- function (coverage ) {
202
+ remove_slc_from_coverage <- function (coverage ) {
198
203
for (i in seq_along(coverage )) {
199
204
elem <- coverage [[i ]]
200
205
elem $ flowr_ids <- NULL
206
+ elem $ in_slice <- NULL
201
207
coverage [[i ]] <- elem
202
208
}
203
209
return (coverage )
204
210
}
205
211
206
- recalculate_values <- function (coverage , exec_and_slc_ids ) {
212
+ recalculate_values <- function (coverage ) {
207
213
logger :: log_trace(" Adjusting coverage values" , namespace = " slicingCoverage" )
208
214
for (i in seq_along(coverage )) {
209
215
elem <- coverage [[i ]]
210
- flowr_ids <- elem $ flowr_ids
211
- if (is.null(flowr_ids )) { # This should not happen (see add_ids_to_coverage)
216
+ in_slice <- elem $ in_slice
217
+ if (is.null(in_slice )) { # This should not happen (see add_ids_to_coverage)
212
218
next
213
219
}
214
- if (any( flowr_ids %in% exec_and_slc_ids ) ) { # No need to change anything as element is in the slice
220
+ if (in_slice ) { # No need to change anything as element is in the slice
215
221
next
216
222
}
217
223
@@ -221,22 +227,24 @@ recalculate_values <- function(coverage, exec_and_slc_ids) {
221
227
return (coverage )
222
228
}
223
229
224
- as_slicing_coverage <- function (coverage , slice ) {
225
- coverage_with_ids <- add_ids_to_coverage(coverage )
226
- unknown_locations <- coverage_with_ids $ unknown_locations
227
- coverage_with_ids <- coverage_with_ids $ coverage
228
-
229
- set_executed <- Filter(was_executed , coverage_with_ids ) | >
230
- lapply(get_flowr_id ) | >
231
- uneverything()
232
- set_slice <- unlist(slice )
233
- set_exec_and_slice <- intersect(set_executed , set_slice )
234
-
235
- slicing_coverage <- recalculate_values(coverage_with_ids , set_exec_and_slice ) | > remove_ids_from_coverage()
236
-
230
+ get_coverered_and_sliced_srcrefs <- function (slc_coverage ) { # nolint: object_length_linter.
231
+ all <- c()
232
+ covered <- c()
233
+ sliced <- c()
234
+ for (srcref in names(slc_coverage )) {
235
+ elem <- slc_coverage [[srcref ]]
236
+ all <- c(all , srcref )
237
+ if (was_executed(elem )) {
238
+ covered <- c(covered , srcref )
239
+ }
240
+ if (elem $ in_slice ) {
241
+ sliced <- c(sliced , srcref )
242
+ }
243
+ }
237
244
return (list (
238
- coverage = slicing_coverage ,
239
- unknown_locations = unknown_locations
245
+ all = all ,
246
+ covered = covered ,
247
+ sliced = sliced
240
248
))
241
249
}
242
250
@@ -251,13 +259,19 @@ give_me_covr_and_i_do_the_rest <- function(covr_measure, sources, tests) { # nol
251
259
slicing_points <- slicing_measure $ slicing_points
252
260
slicing_time <- slicing_measure $ slicing_time
253
261
query_time <- slicing_measure $ query_time
254
- slicing_coverage <- as_slicing_coverage(covr , slicing_measure $ slice )
255
- unknown_locations <- slicing_coverage $ unknown_locations
256
- slicing_coverage <- slicing_coverage $ coverage
262
+
263
+ coverage_with_slc <- add_slc_to_coverage(covr , slicing_measure $ slice )
264
+ unknown_locations <- coverage_with_slc $ unknown_locations
265
+ coverage_with_slc <- coverage_with_slc $ coverage
266
+
267
+ srcrefs <- get_coverered_and_sliced_srcrefs(coverage_with_slc )
268
+
269
+ slicing_coverage <- recalculate_values(coverage_with_slc ) | > remove_slc_from_coverage()
257
270
258
271
return (build_return_value(
259
272
covr , covr_time ,
260
273
slicing_coverage , slicing_points , ana_time , slicing_time , query_time ,
261
- unknown_locations
274
+ unknown_locations ,
275
+ srcrefs
262
276
))
263
277
}
0 commit comments