@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
32 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.instrumentDataflowCount = instrumentDataflowCount;
/**
* This takes the out parameter `countMap` and fills it with the count of how many times each RType was processed.
* The accompanying `reset` function can be used to reset the map to an empty state.
* @example
* ```ts
* const map = new Map<RType, number>();
* const analyzer = await new FlowrAnalyzerBuilder()
* .configure('solver.instrument.dataflowExtractors', instrumentDataflowCount(map, () => map.clear()))
* .build();
* analyzer.addRequest(requestFromInput(code));
* await analyzer.dataflow();
* ```
* Now, you can inspect the counts in the `map` objects, these will be reset for each new analysis request using the `() => map.clear()` function.
*/
function instrumentDataflowCount(countMap, reset) {
return (extractor, _ctx) => {
reset(countMap);
const instrumented = {};
for (const [key, processor] of Object.entries(extractor)) {
instrumented[key] = ((...args) => {
const prev = countMap.get(key) ?? 0;
countMap.set(key, prev + 1);
return processor(...args);
});
}
return instrumented;
};
}
//# sourceMappingURL=instrument-dataflow-count.js.map