UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

90 lines (89 loc) 5.56 kB
import { type DataflowProcessorInformation } from '../../../../processor'; import type { DataflowInformation } from '../../../../info'; import { type ForceArguments } from './common'; import type { RSymbol } from '../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol'; import type { ParentInformation } from '../../../../../r-bridge/lang-4.x/ast/model/processing/decorate'; import type { PotentiallyEmptyRArgument } from '../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call'; import type { NodeId } from '../../../../../r-bridge/lang-4.x/ast/model/processing/node-id'; import type { RNode } from '../../../../../r-bridge/lang-4.x/ast/model/model'; import { type IdentifierReference } from '../../../../environments/identifier'; import type { FunctionArgument } from '../../../../graph/graph'; import { DataflowGraph } from '../../../../graph/graph'; import { type FunctionOriginInformation } from '../../../../graph/vertex'; export interface ProcessKnownFunctionCallInput<OtherInfo> extends ForceArguments { /** The name of the function being called. */ readonly name: RSymbol<OtherInfo & ParentInformation>; /** The arguments to the function call. */ readonly args: readonly (RNode<OtherInfo & ParentInformation> | PotentiallyEmptyRArgument<OtherInfo & ParentInformation>)[]; /** The node ID to use for the function call vertex. */ readonly rootId: NodeId; /** The dataflow processor information at the point of the function call. */ readonly data: DataflowProcessorInformation<OtherInfo & ParentInformation>; /** should arguments be processed from right to left? This does not affect the order recorded in the call but of the environments */ readonly reverseOrder?: boolean; /** which arguments are {@link NseKind.Reevaluated|reevaluated}, like a loop body */ readonly markAsNSE?: readonly number[]; /** allows passing a data processor in-between each argument */ readonly patchData?: (data: DataflowProcessorInformation<OtherInfo & ParentInformation>, arg: number) => DataflowProcessorInformation<OtherInfo & ParentInformation>; /** Does the call have a side effect that we do not know a lot about which may have further consequences? */ readonly hasUnknownSideEffect?: boolean; /** The origin to use for the function being called. */ readonly origin: FunctionOriginInformation | 'default'; /** see {@link ProcessAllArgumentInput#nonFunction} */ readonly nonFunction?: ReadonlySet<NodeId>; } /** The result of processing a known function call. */ export interface ProcessKnownFunctionCallResult { /** This is the overall information about the function call itself. */ readonly information: DataflowInformation; /** The processed arguments in order, they are included in the information but sometimes useful separately. */ readonly processedArguments: readonly (DataflowInformation | undefined)[]; /** A reference to the function being called. */ readonly fnRef: IdentifierReference; /** * The arguments as recorded on the function call vertex. * They are also part of the information via the function call vertex adde, but sometimes useful separately. * For example, together with {@link pMatch} to do custom parameter matching. */ readonly callArgs: readonly FunctionArgument[]; } /** * Which arguments of a call {@link markArgumentsAsNonStandardEvaluation|are non-standardly evaluated}: * every argument, all but the (data) first one, or only the first one. */ export declare enum NseArguments { /** every argument, e.g. the operands of a formula `~` or `aes(x, y)` */ All = "all", /** all but the first, e.g. `subset(data, col > 1)` where the first argument is the data object */ AllButFirst = "all-but-first", /** only the first, e.g. the native routine name in `.C(routine, ...)` */ First = "first" } /** * How an argument escapes standard evaluation, which decides what is marked * {@link EdgeType.NonStandardEvaluation}. */ export declare enum NseKind { /** the argument is not evaluated at all (`quote(x + y)`), so nothing within it is */ Quoted = "quoted", /** the argument is evaluated in a data mask (`subset(d, a > k)`), where only its symbols may name columns */ DataMasked = "data-masked", /** evaluated, just not exactly once (a loop body), so only the argument itself is marked */ Reevaluated = "reevaluated" } export interface NseMarkOptions { readonly kind?: NseKind; /** ids an unquote escape splices back in, see {@link Nse.unquoted} */ readonly evaluated?: ReadonlySet<NodeId>; } /** * Marks the selected arguments as {@link EdgeType.NonStandardEvaluation}: a {@link NseKind.Quoted|quoted} one * entirely, a {@link NseKind.DataMasked|data-masked} one only where {@link Nse.suppliedByMask} holds, and a * {@link NseKind.Reevaluated|reevaluated} one as a whole but not within. */ export declare function markArgumentsAsNonStandardEvaluation(graph: DataflowGraph, rootId: NodeId, processedArguments: readonly (DataflowInformation | undefined)[], which: NseArguments | readonly number[] | undefined, { kind, evaluated }?: NseMarkOptions): void; /** * The main processor for function calls for which we know the target but need not * add any specific handling. */ export declare function processKnownFunctionCall<OtherInfo>({ name, args, rootId, data, reverseOrder, markAsNSE, forceArgs, patchData, hasUnknownSideEffect, origin, nonFunction }: ProcessKnownFunctionCallInput<OtherInfo>): ProcessKnownFunctionCallResult;