UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

62 lines 2.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.controlflowBbStarCommand = exports.controlflowBbCommand = exports.controlflowStarCommand = exports.controlflowCommand = void 0; const cfg_1 = require("../../../util/mermaid/cfg"); const ansi_1 = require("../../../util/text/ansi"); const cfg_simplification_1 = require("../../../control-flow/cfg-simplification"); const core_1 = require("../core"); const repl_clipboard_1 = require("./repl-clipboard"); function formatInfo(out, type) { return out.formatter.format(`Copied ${type} to clipboard.`, { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground, style: 3 /* FontStyles.Italic */ }); } async function produceAndPrintCfg(analyzer, output, simplifications, cfgConverter) { const cfg = await analyzer.controlflow([...cfg_simplification_1.DefaultCfgSimplificationOrder, ...simplifications]); const normalizedAst = await analyzer.normalize(); const mermaid = cfgConverter(cfg, normalizedAst); await repl_clipboard_1.ReplClipboard.print(output, mermaid, formatInfo(output, 'mermaid code')); } exports.controlflowCommand = { description: 'Get mermaid code for the control-flow graph of R code', isCodeCommand: true, usageExample: ':controlflow', aliases: ['cfg', 'cf'], script: false, argsParser: (args) => (0, core_1.handleString)(args), fn: async ({ output, analyzer }) => { await produceAndPrintCfg(analyzer, output, [], cfg_1.cfgToMermaid); } }; exports.controlflowStarCommand = { description: 'Returns the URL to mermaid.live', isCodeCommand: true, usageExample: ':controlflow*', aliases: ['cfg*', 'cf*'], script: false, argsParser: (args) => (0, core_1.handleString)(args), fn: async ({ output, analyzer }) => { await produceAndPrintCfg(analyzer, output, [], cfg_1.cfgToMermaidUrl); } }; exports.controlflowBbCommand = { description: 'Get mermaid code for the control-flow graph with basic blocks', isCodeCommand: true, usageExample: ':controlflowbb', aliases: ['cfgb', 'cfb'], script: false, argsParser: (args) => (0, core_1.handleString)(args), fn: async ({ output, analyzer }) => { await produceAndPrintCfg(analyzer, output, ['to-basic-blocks'], cfg_1.cfgToMermaid); } }; exports.controlflowBbStarCommand = { description: 'Returns the URL to mermaid.live', isCodeCommand: true, usageExample: ':controlflowbb*', aliases: ['cfgb*', 'cfb*'], script: false, argsParser: (args) => (0, core_1.handleString)(args), fn: async ({ output, analyzer }) => { await produceAndPrintCfg(analyzer, output, ['to-basic-blocks'], cfg_1.cfgToMermaidUrl); } }; //# sourceMappingURL=repl-cfg.js.map