UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

55 lines 3.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InspectExceptionQueryDefinition = void 0; const ansi_1 = require("../../../util/text/ansi"); const joi_1 = __importDefault(require("joi")); const inspect_exception_query_executor_1 = require("./inspect-exception-query-executor"); const node_id_1 = require("../../../r-bridge/lang-4.x/ast/model/processing/node-id"); const slice_query_parser_1 = require("../../../cli/repl/parser/slice-query-parser"); const range_1 = require("../../../util/range"); const info_1 = require("../../../dataflow/info"); function inspectExceptionLineParser(_output, line, _config) { const criteria = (0, slice_query_parser_1.sliceCriteriaParser)(line[0]); return { query: { type: 'inspect-exception', filter: criteria }, rCode: criteria ? line[1] : line[0] }; } exports.InspectExceptionQueryDefinition = { executor: inspect_exception_query_executor_1.executeExceptionQuery, asciiSummarizer: async (formatter, processed, queryResults, result) => { const out = queryResults; result.push(`Query: ${(0, ansi_1.bold)('inspect-exception', formatter)} (${out['.meta'].timing.toFixed(0)}ms)`); const n = await processed.normalize(); function getLoc(r) { const node = n.idMap.get(node_id_1.NodeId.normalize(r)); return node ? range_1.SourceLocation.fromNode(node) : undefined; } function getLexeme(r) { return n.idMap.get(node_id_1.NodeId.normalize(r))?.lexeme ?? String(r); } for (const [r, v] of Object.entries(out.exceptions)) { result.push(` - Function ${(0, ansi_1.bold)(r, formatter)} (${range_1.SourceLocation.format(getLoc(r))}) ${v.length > 0 ? 'throws exceptions:' : 'does not throw exceptions.'}`); for (const { id: ex, cds } of v) { result.push(` - Exception ${(0, info_1.happensInEveryBranch)(cds) ? 'always ' : 'maybe '}thrown at id ${(0, ansi_1.bold)(String(ex), formatter)} "${getLexeme(ex)}" (${range_1.SourceLocation.format(getLoc(ex))}, cds: ${cds?.map(c => c.when + ':' + range_1.SourceLocation.format(getLoc(c.id))).join(', ') ?? 'none'})`); } } return true; }, fromLine: inspectExceptionLineParser, schema: joi_1.default.object({ type: joi_1.default.string().valid('inspect-exception').required().description('The type of the query.'), filter: joi_1.default.array().items(joi_1.default.string().required()).optional().description('If given, only function definitions that match one of the given slicing criteria are considered. Each criterion can be either `line:column`, `line@variable-name`, or `$id`, where the latter directly specifies the node id of the function definition to be considered.'), }).description('Query to inspect which functions throw exceptions.'), flattenInvolvedNodes: (queryResults) => { const out = queryResults; return Object.keys(out.exceptions).filter(id => out.exceptions[id].length > 0); } }; //# sourceMappingURL=inspect-exception-query-format.js.map