@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
101 lines • 5.71 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StaticSliceQueryDefinition = void 0;
const ansi_1 = require("../../../util/text/ansi");
const time_1 = require("../../../util/text/time");
const joi_1 = __importDefault(require("joi"));
const static_slice_query_executor_1 = require("./static-slice-query-executor");
const query_print_1 = require("../../query-print");
const slice_query_parser_1 = require("../../../cli/repl/parser/slice-query-parser");
const slice_query_options_1 = require("../slice-query-options");
const slice_direction_1 = require("../../../util/slice-direction");
const SliceCriterionHelp = [
'Each criterion picks one element of the program, separate multiple ones with ";":',
' <line>@<name> <name> in line <line>, preferring a call over the symbol (e.g. 2@x)',
' <line>@[<n>]<name> the n-th occurrence of <name> in line <line> (e.g. 2@[2]x, 2@[-1]x)',
' <line>:<col> the element starting at line <line>, column <col> (e.g. 2:5)',
' <line>~<col> the innermost element containing line <line>, column <col> (e.g. 2~5)',
' <line>^ the top-level statement line <line> belongs to (e.g. 2^)',
' $<id> the normalized node with the id <id> (e.g. $42)',
'A negative <line> counts from the end; a trailing (file-regex) restricts to a file (e.g. 2@x(tmp/.*)).',
`Append flags after the ")": ${(0, slice_query_parser_1.describeSliceFlags)(slice_query_parser_1.StaticSliceFlags)}.`,
'Example: :query @static-slice (2@x;3:1)fc'
].join('\n');
function sliceQueryLineParser(output, line, _config) {
const criteria = (0, slice_query_parser_1.sliceCriteriaParser)(line[0]);
const direction = (0, slice_query_parser_1.sliceDirectionParser)(line[0]);
const options = (0, slice_query_parser_1.sliceQueryOptionsParser)(line[0]);
if (!criteria || criteria.length === 0) {
output.stderr(output.formatter.format('Invalid static-slice query format, slicing criteria must be given in the form "(criterion1;criterion2;...)"', { color: 1 /* Colors.Red */, effect: ansi_1.ColorEffect.Foreground, style: 1 /* FontStyles.Bold */ }));
output.stderr(SliceCriterionHelp);
return { query: [] };
}
(0, slice_query_parser_1.warnAboutSliceFlags)(output, line[0], slice_query_parser_1.StaticSliceFlags);
return { query: [
{
type: 'static-slice',
criteria: criteria,
direction: direction,
...options
}
], rCode: (0, slice_query_parser_1.queryLineCode)(line) };
}
exports.StaticSliceQueryDefinition = {
title: 'Static Slice Query',
executor: static_slice_query_executor_1.executeStaticSliceQuery,
asciiSummarizer: (formatter, _analyzer, queryResults, result) => {
const out = queryResults;
if (Object.keys(out.results).length === 1) {
// just print the single result without fingerprint
const [, obj] = Object.entries(out.results)[0];
if ('reconstruct' in obj) {
const code = Array.isArray(obj.reconstruct.code) ? obj.reconstruct.code : [obj.reconstruct.code];
if (code.length === 1) {
result.push(code[0]);
return true;
}
}
}
result.push(`Query: ${(0, ansi_1.bold)('static-slice', formatter)} (${(0, time_1.printAsMs)(out['.meta'].timing, 0)})`);
for (const [fingerprint, obj] of Object.entries(out.results)) {
const { criteria, noMagicComments, noReconstruction } = JSON.parse(fingerprint);
const addons = [];
if (noReconstruction) {
addons.push('no reconstruction');
}
if (noMagicComments) {
addons.push('no magic comments');
}
result.push(` ╰ Slice for {${criteria.join(', ')}} ${addons.join(', ')}`);
if ('reconstruct' in obj) {
const code = Array.isArray(obj.reconstruct.code) ? obj.reconstruct.code : [obj.reconstruct.code];
result.push(' ╰ Code (newline as <code>\n</code>): <code>' + code.flatMap(c => c.split('\n')).join('\\n') + '</code>');
}
else {
result.push(` ╰ Id List: {${(0, query_print_1.summarizeIdsIfTooLong)(formatter, [...obj.slice.result])}}`);
}
}
return true;
},
fromLine: sliceQueryLineParser,
completer: slice_query_parser_1.criteriaQueryCompleter,
syntax: '@static-slice (<crit>;...)[fiIcB] <code | file://path>',
schema: joi_1.default.object({
type: joi_1.default.string().valid('static-slice').required().description('The type of the query.'),
criteria: joi_1.default.array().items(joi_1.default.string()).min(0).required().description('The slicing criteria to use.'),
direction: joi_1.default.string().valid(...Object.values(slice_direction_1.SliceDirection)).optional().description('The direction to slice in. Defaults to backward slicing if unset.'),
...slice_query_options_1.SliceQueryOptionsSchema
}).description('Slice query used to slice the dataflow graph'),
flattenInvolvedNodes: (queryResults) => {
const flattened = [];
const out = queryResults;
for (const [_, obj] of Object.entries(out.results)) {
flattened.push(...obj.slice.result);
}
return flattened;
}
};
//# sourceMappingURL=static-slice-query-format.js.map