UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

60 lines (59 loc) 3.46 kB
/** * 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 */ import Joi from 'joi'; import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id'; import type { NormalizedAst } from '../../r-bridge/lang-4.x/ast/model/processing/decorate'; import { SlicingCriteria } from '../../slicing/criterion/parse'; import type { DataflowGraph } from '../../dataflow/graph/graph'; import { type InlineFull, type ReconstructionResult } from '../../reconstruct/reconstruct'; /** The options every slicing query understands, independent of how it picks the nodes to keep. */ export interface SliceQueryOptions { /** do not reconstruct the slice into readable code */ readonly noReconstruction?: boolean; /** Should the magic comments (force-including lines within the slice) be ignored? */ readonly noMagicComments?: boolean; /** * Inline resolvable `source()` calls into the reconstruction so the result is a single self-contained R text. * Cyclic and unresolvable `source()` calls are kept verbatim and reported via `reconstruct.inlineWarnings`. */ readonly inlineSources?: boolean; /** * Inline _every_ file into the reconstruction, in flowR's loading order (which respects implicit sources), * independent of whether it is sourced explicitly; `'banner'` additionally precedes each file with a banner * comment naming it. Overrides {@link inlineSources}. */ readonly inlineFull?: InlineFull; /** * If set (and slicing backward), continue the slice past a function-definition boundary, also including * the definition's binding and call sites. Defaults to `false`. */ readonly includeCallees?: boolean; /** * Reconstruct the slice as the project's files rather than as one program, reported in * {@link ReconstructionResult#files} in loading order with their paths. Without this only the entry file is * reconstructed. Overridden by {@link inlineSources}/{@link inlineFull}, which produce the opposite. */ readonly perFile?: boolean; /** Also report the packages the slice calls into; see {@link Dataflow.packagesOf}. */ readonly reportPackages?: boolean; } /** The Joi keys of {@link SliceQueryOptions}, to be spread into the schema of every slicing query. */ export declare const SliceQueryOptionsSchema: { readonly noReconstruction: Joi.BooleanSchema<boolean>; readonly noMagicComments: Joi.BooleanSchema<boolean>; readonly inlineSources: Joi.BooleanSchema<boolean>; readonly inlineFull: Joi.AlternativesSchema<string | boolean>; readonly includeCallees: Joi.BooleanSchema<boolean>; readonly perFile: Joi.BooleanSchema<boolean>; readonly reportPackages: Joi.BooleanSchema<boolean>; }; /** * Resolves the criteria to their node ids, reporting those that match no node: they would slice nothing, * as {@link SlicingCriteria.convertAll} keeps them verbatim. */ export declare function resolveSliceCriteria(criteria: SlicingCriteria, ast: NormalizedAst): NodeId[]; /** Reconstruct the given `nodes` of `ast`, honoring the inlining, per-file and magic-comment options. */ export declare function reconstructSlice(ast: NormalizedAst, graph: DataflowGraph, nodes: ReadonlySet<NodeId>, options: SliceQueryOptions): ReconstructionResult;