UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

74 lines (73 loc) 4.78 kB
import type { FlowrSearchElement, FlowrSearchInput } from '../flowr-search'; import type { ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate'; import type { Pipeline } from '../../core/steps/pipeline/pipeline'; import type { MergeableRecord } from '../../util/objects'; import type { Identifier } from '../../dataflow/environments/identifier'; import type { LinkToLastCall } from '../../queries/catalog/call-context-query/call-context-query-format'; /** * A {@link FlowrSearchElement} that is enriched with a set of enrichments through {@link FlowrSearchBuilder.with}. * Enrichments can be retrieved easily from an element through {@link enrichmentContent}. */ export interface EnrichedFlowrSearchElement<Info> extends FlowrSearchElement<Info> { enrichments: { [E in Enrichment]?: EnrichmentContent<E>; }; } export interface EnrichmentData<EnrichmentContent extends MergeableRecord, EnrichmentArguments = undefined> { /** * A function that is applied to each element of the search to enrich it with additional data. */ readonly enrich: (e: FlowrSearchElement<ParentInformation>, data: FlowrSearchInput<Pipeline>, args: EnrichmentArguments | undefined) => EnrichmentContent; /** * The mapping function used by the {@link Mapper.Enrichment} mapper. */ readonly mapper: (c: EnrichmentContent) => FlowrSearchElement<ParentInformation>[]; } export type EnrichmentContent<E extends Enrichment> = typeof Enrichments[E] extends EnrichmentData<infer Content, infer _Args> ? Content : never; export type EnrichmentArguments<E extends Enrichment> = typeof Enrichments[E] extends EnrichmentData<infer _Content, infer Args> ? Args : never; /** * An enumeration that stores the names of the available enrichments that can be applied to a set of search elements. * See {@link FlowrSearchBuilder.with} for more information on how to apply enrichments. */ export declare enum Enrichment { CallTargets = "call-targets", LastCall = "last-call" } export interface CallTargetsContent extends MergeableRecord { /** * The call targets of the function call. * For identifier call targets, the identifier is the name of the library function being called. */ targets: (FlowrSearchElement<ParentInformation> | Identifier)[]; } export interface LastCallContent extends MergeableRecord { linkedIds: FlowrSearchElement<ParentInformation>[]; } /** * The registry of enrichments that are currently supported by the search. * See {@link FlowrSearchBuilder.with} for more information on how to apply enrichments. */ export declare const Enrichments: { readonly "call-targets": { enrich: (e: FlowrSearchElement<ParentInformation>, data: import("../../core/steps/pipeline/pipeline").PipelineOutput<Pipeline<import("../../core/steps/pipeline-step").IPipelineStep<import("../../core/steps/pipeline-step").PipelineStepName, (...args: any[]) => any>>> & { normalize: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").NormalizedAst; dataflow: import("../../dataflow/info").DataflowInformation; }) => CallTargetsContent; mapper: ({ targets }: CallTargetsContent) => FlowrSearchElement<ParentInformation>[]; }; readonly "last-call": { enrich: (e: FlowrSearchElement<ParentInformation>, data: import("../../core/steps/pipeline/pipeline").PipelineOutput<Pipeline<import("../../core/steps/pipeline-step").IPipelineStep<import("../../core/steps/pipeline-step").PipelineStepName, (...args: any[]) => any>>> & { normalize: import("../../r-bridge/lang-4.x/ast/model/processing/decorate").NormalizedAst; dataflow: import("../../dataflow/info").DataflowInformation; }, args: Omit<LinkToLastCall<string | RegExp>, "type">[] | undefined) => LastCallContent; mapper: ({ linkedIds }: LastCallContent) => FlowrSearchElement<ParentInformation>[]; }; }; /** * Returns the content of the given enrichment type from a {@link FlowrSearchElement}. * If the search element is not enriched with the given enrichment, `undefined` is returned. * @param e - The search element whose enrichment content should be retrieved. * @param enrichment - The enrichment content, if present, else `undefined`. */ export declare function enrichmentContent<E extends Enrichment>(e: FlowrSearchElement<ParentInformation>, enrichment: E): EnrichmentContent<E>; export declare function enrich<ElementIn extends FlowrSearchElement<ParentInformation>, ElementOut extends ElementIn & EnrichedFlowrSearchElement<ParentInformation>, ConcreteEnrichment extends Enrichment>(e: ElementIn, data: FlowrSearchInput<Pipeline>, enrichment: ConcreteEnrichment, args?: EnrichmentArguments<ConcreteEnrichment>): ElementOut;