@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
54 lines • 3.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SliceQueryOptionsSchema = void 0;
exports.resolveSliceCriteria = resolveSliceCriteria;
exports.reconstructSlice = reconstructSlice;
/**
* The options shared by the queries that slice the dataflow graph (`static-slice` and `dice`), so both offer the
* same knobs without repeating their definition, schema, or reconstruction handling.
* @module
*/
const joi_1 = __importDefault(require("joi"));
const parse_1 = require("../../slicing/criterion/parse");
const reconstruct_1 = require("../../reconstruct/reconstruct");
const source_inline_map_1 = require("../../reconstruct/inline/source-inline-map");
const auto_select_defaults_1 = require("../../reconstruct/auto-select/auto-select-defaults");
const magic_comments_1 = require("../../reconstruct/auto-select/magic-comments");
/** The Joi keys of {@link SliceQueryOptions}, to be spread into the schema of every slicing query. */
exports.SliceQueryOptionsSchema = {
noReconstruction: joi_1.default.boolean().optional().description('Do not reconstruct the slice into readable code.'),
noMagicComments: joi_1.default.boolean().optional().description('Should the magic comments (force-including lines within the slice) be ignored?'),
inlineSources: joi_1.default.boolean().optional().description('Inline resolvable source() calls into the reconstruction so the result is a single self-contained R text.'),
inlineFull: joi_1.default.alternatives(joi_1.default.boolean(), joi_1.default.string().valid('banner')).optional().description('Inline all files into the reconstruction, in flowR\'s loading order and independent of whether they are sourced explicitly; "banner" precedes every file with a banner comment naming it.'),
includeCallees: joi_1.default.boolean().optional().description('If set (and slicing backward), continue the slice past a function-definition boundary, also including the definition\'s binding and call sites.'),
perFile: joi_1.default.boolean().optional().description('Reconstruct the slice as the project\'s files, reported in `reconstruct.files` in loading order with their paths, instead of only the entry file.'),
reportPackages: joi_1.default.boolean().optional().description('Also report the packages the slice calls into, i.e. what this selection needs installed rather than what the whole program loads.')
};
/**
* Resolves the criteria to their node ids, reporting those that match no node: they would slice nothing,
* as {@link SlicingCriteria.convertAll} keeps them verbatim.
*/
function resolveSliceCriteria(criteria, ast) {
const ids = parse_1.SlicingCriteria.convertAll(criteria, ast.idMap);
const unresolved = criteria.filter((_, i) => !ast.idMap.has(ids[i]));
if (unresolved.length > 0) {
throw new parse_1.CriteriaParseError(`the slicing criteria ${unresolved.map(c => `'${c}'`).join(', ')} match no element of the program`);
}
return ids;
}
/** Reconstruct the given `nodes` of `ast`, honoring the inlining, per-file and magic-comment options. */
function reconstructSlice(ast, graph, nodes, options) {
const { inlineSources, inlineFull, perFile, noMagicComments } = options;
const inlining = inlineSources || inlineFull;
return (0, reconstruct_1.reconstructToCode)(ast, {
nodes,
inlineSources,
inlineFull,
reconstructFiles: perFile && !inlining ? 'all' : undefined,
sourceMap: inlining ? source_inline_map_1.SourceInlineMap.build(ast, graph) : undefined
}, noMagicComments ? auto_select_defaults_1.doNotAutoSelect : (0, magic_comments_1.makeMagicCommentHandler)(auto_select_defaults_1.doNotAutoSelect));
}
//# sourceMappingURL=slice-query-options.js.map