UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

63 lines 2.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RProject = void 0; const model_1 = require("../model"); const type_1 = require("../type"); /** * Helper object to identify RProject nodes by their type and to provide related functions. * @see {@link RNode.visitAst} - to visit all nodes in the project */ exports.RProject = { name: 'RProject', /** * Visits all nodes in the project by visiting the root of each file. * @param project - The project to visit file by file * @param onVisit - Called before visiting the subtree of each node. Can be used to stop visiting the subtree starting with this node (return `true` stop) * @param onExit - Called after the subtree of a node has been visited, called for leafs too (even though their subtree is empty) */ visitAst(project, onVisit, onExit) { return model_1.RNode.visitAst(project.files.map(f => f.root), onVisit, onExit); }, /** * Collects all node ids within a project * @param project - The project to collect ids from * @see {@link RNode.collectAllIds} - to stop collecting at certain nodes * @see {@link RProject.collectAllIdsWithStop} - to stop collecting at certain nodes */ collectAllIds(project) { return model_1.RNode.collectAllIds(exports.RProject.asNodes(project)); }, /** * Collects all node ids within a project, but stops collecting at nodes where the given `stop` function returns `true`. * @param project - The project to collect ids from * @param stop - A function that determines whether to stop collecting at a given node, does not stop by default * @see {@link RNode.collectAllIdsWithStop} - to collect all ids without stopping * @see {@link RProject.collectAllIds} - to collect all ids without stopping */ collectAllIdsWithStop(project, stop) { return model_1.RNode.collectAllIdsWithStop(exports.RProject.asNodes(project), stop); }, /** * Flattens the project to an array of nodes by collecting the root nodes of each file. */ asNodes(project) { return project.files.map(f => f.root); }, /** * Type guard for RProject nodes. */ is(node) { return typeof node === 'object' && node !== null && 'type' in node && node.type === type_1.RType.Project; }, /** * Merge multiple projects into a single one by concatenating their files. * This will remove the `info` property of the resulting project. */ merge(projects) { return { type: type_1.RType.Project, files: projects.flatMap(p => p.files) }; } }; //# sourceMappingURL=r-project.js.map