@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
49 lines • 2.77 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processRepeatLoop = processRepeatLoop;
const info_1 = require("../../../../../info");
const linker_1 = require("../../../../linker");
const known_call_handling_1 = require("../known-call-handling");
const assert_1 = require("../../../../../../util/assert");
const unpack_argument_1 = require("../argument/unpack-argument");
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
const logger_1 = require("../../../../../logger");
const identifier_1 = require("../../../../../environments/identifier");
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
/**
* Process a built-in repeat loop function call like `repeat { ... }`.
* @param name - The name of the function being called.
* @param args - The arguments passed to the function.
* @param rootId - The root node ID for the current processing context.
* @param data - Additional dataflow processor information.
* @returns - The resulting dataflow information after processing the repeat loop.
*/
function processRepeatLoop(name, args, rootId, data) {
if (args.length !== 1 || args[0] === r_function_call_1.EmptyArgument) {
logger_1.dataflowLogger.warn(`Repeat-Loop ${identifier_1.Identifier.toString(name.content)} does not have 1 argument, skipping`);
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: 'default' }).information;
}
const unpacked = (0, unpack_argument_1.unpackNonameArg)(args[0]);
const { information, processedArguments } = (0, known_call_handling_1.processKnownFunctionCall)({
name,
args: unpacked ? [unpacked] : args,
rootId,
data,
forceArgs: 'all',
patchData: (d, i) => {
if (i === 0) {
return { ...d, cds: [...d.cds ?? [], { id: name.info.id }] };
}
return d;
},
markAsNSE: [0],
origin: built_in_proc_name_1.BuiltInProcName.RepeatLoop
});
const body = processedArguments[0];
(0, assert_1.guard)(body !== undefined, () => `Repeat-Loop ${identifier_1.Identifier.toString(name.content)} has no body, impossible!`);
(0, linker_1.linkCircularRedefinitionsWithinALoop)(information.graph, (0, linker_1.produceNameSharedIdMap)((0, linker_1.findNonLocalReads)(information.graph)), body.out);
(0, linker_1.reapplyLoopExitPoints)(body.exitPoints, body.in.concat(body.out, body.unknownReferences), information.graph);
information.exitPoints = (0, info_1.filterOutLoopExitPoints)(information.exitPoints);
return information;
}
//# sourceMappingURL=built-in-repeat-loop.js.map