UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

745 lines (744 loc) 33.5 kB
import type { FlowrSearchElement, FlowrSearchElements } from '../flowr-search'; import type { NormalizedAst, ParentInformation } from '../../r-bridge/lang-4.x/ast/model/processing/decorate'; import type { DataflowInformation } from '../../dataflow/info'; import { type MergeableRecord } from '../../util/objects'; import type { LinkToLastCall } from '../../queries/catalog/call-context-query/call-context-query-format'; import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id'; import type { ControlFlowInformation } from '../../control-flow/control-flow-graph'; import type { Query, QueryResult } from '../../queries/query'; import { type CfgSimplificationPassName } from '../../control-flow/cfg-simplification'; import type { AsyncOrSync } from 'ts-essentials'; import type { ReadonlyFlowrAnalysisProvider } from '../../project/flowr-analyzer'; import type { KnownRoxygenTags, RoxygenTag } from '../../r-bridge/roxygen2/roxygen-ast'; export interface EnrichmentData<ElementContent extends MergeableRecord, ElementArguments = undefined, SearchContent extends MergeableRecord = never, SearchArguments = ElementArguments> { /** * A function that is applied to each element of the search to enrich it with additional data. */ readonly enrichElement?: (element: FlowrSearchElement<ParentInformation>, search: FlowrSearchElements<ParentInformation>, analyzer: ReadonlyFlowrAnalysisProvider, args: ElementArguments | undefined, previousValue: ElementContent | undefined) => AsyncOrSync<ElementContent>; readonly enrichSearch?: (search: FlowrSearchElements<ParentInformation>, data: ReadonlyFlowrAnalysisProvider, args: SearchArguments | undefined, previousValue: SearchContent | undefined) => AsyncOrSync<SearchContent>; /** * The mapping function used by the {@link Mapper.Enrichment} mapper. */ readonly mapper?: (content: ElementContent) => FlowrSearchElement<ParentInformation>[]; } export type EnrichmentElementContent<E extends Enrichment> = typeof Enrichments[E] extends EnrichmentData<infer EC, infer _EA, infer _SC, infer _SA> ? EC : never; export type EnrichmentElementArguments<E extends Enrichment> = typeof Enrichments[E] extends EnrichmentData<infer _EC, infer EA, infer _SC, infer _SA> ? EA : never; export type EnrichmentSearchContent<E extends Enrichment> = typeof Enrichments[E] extends EnrichmentData<infer _EC, infer _EA, infer SC, infer _SA> ? SC : never; export type EnrichmentSearchArguments<E extends Enrichment> = typeof Enrichments[E] extends EnrichmentData<infer _EC, infer _EA, infer _SC, infer SA> ? SA : 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", CfgInformation = "cfg-information", Roxygen = "roxygen", QueryData = "query-data" } 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. * If the `qualifyNames` argument is unset or `true`, the returned call targets will always be stringified fully-qualified identifiers. */ targets: (FlowrSearchElement<ParentInformation> | string)[]; } /** Analysis artifacts resolved once for the whole search rather than once per element. */ export interface CallTargetsSearchContent extends MergeableRecord { dfg: DataflowInformation; ast: NormalizedAst; } export interface LastCallContent extends MergeableRecord { linkedIds: FlowrSearchElement<ParentInformation>[]; } /** @see {@link CallTargetsSearchContent} */ export interface LastCallSearchContent extends CallTargetsSearchContent { cfg: ControlFlowInformation; } export interface CfgInformationElementContent extends MergeableRecord { /** * Whether the current node is a root node in the CFG, which is a node that is not contained inside of a function definition. */ isRoot: boolean; /** * Whether the current node is reachable from the root of the CFG. * Only has a value if {@link CfgInformationArguments.checkReachable} was true. */ isReachable?: boolean; } export interface CfgInformationSearchContent extends MergeableRecord { /** * The CFG attached to the search, extracted using {@link extractCfg}. */ cfg: ControlFlowInformation; /** * The set of all nodes that are reachable from the root of the CFG, extracted using {@link visitCfgInOrder}. * Only has a value if {@link CfgInformationArguments.checkReachable} was true. */ reachableNodes?: Set<NodeId>; } export interface CfgInformationArguments extends MergeableRecord { /** Whether to recalculate the CFG information if it already exists on the current search. Defaults to `false`. */ forceRefresh?: boolean; /** The simplification passes that should be run on the extracted CFG. Defaults to the entries of {@link DefaultCfgSimplificationOrder}. */ simplificationPasses?: CfgSimplificationPassName[]; /** Whether to check nodes for reachability, and subsequently set {@link CfgInformationSearchContent.reachableNodes} and {@link CfgInformationElementContent.isReachable}. Defaults to `false`. */ checkReachable?: boolean; } export interface RoxygenElementContent extends MergeableRecord { documentation: readonly RoxygenTag[]; tags: { [T in KnownRoxygenTags]?: readonly (RoxygenTag & { type: T; })[]; }; } /** @see {@link CallTargetsSearchContent} */ export interface RoxygenSearchContent extends MergeableRecord { ast: NormalizedAst; } export interface QueryDataElementContent extends MergeableRecord { /** The name of the query that this element originated from. To get each query's data, see {@link QueryDataSearchContent}. */ query: Query['type']; } export interface QueryDataSearchContent extends MergeableRecord { queries: { [QueryType in Query['type']]: Awaited<QueryResult<QueryType>>; }; } /** * 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": { enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: { onlyBuiltin?: boolean; qualifyNames?: boolean; } | undefined, prev: CallTargetsSearchContent | undefined) => Promise<CallTargetsSearchContent>; enrichElement: (e: FlowrSearchElement<ParentInformation>, s: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: { onlyBuiltin?: boolean; qualifyNames?: boolean; } | undefined, prev: CallTargetsContent | undefined) => Promise<CallTargetsContent>; mapper: ({ targets }: CallTargetsContent) => FlowrSearchElement<ParentInformation>[]; }; readonly "last-call": { enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: Omit<LinkToLastCall<import("../../queries/catalog/call-context-query/call-context-query-format").CallNameTypes>, "type">[] | undefined, prev: LastCallSearchContent | undefined) => Promise<LastCallSearchContent>; enrichElement: (e: FlowrSearchElement<ParentInformation>, s: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: Omit<LinkToLastCall<import("../../queries/catalog/call-context-query/call-context-query-format").CallNameTypes>, "type">[] | undefined, prev: LastCallContent | undefined) => Promise<LastCallContent>; mapper: ({ linkedIds }: LastCallContent) => FlowrSearchElement<ParentInformation>[]; }; readonly "cfg-information": { enrichElement: (e: FlowrSearchElement<ParentInformation>, search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, _data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: CfgInformationArguments | undefined, prev: CfgInformationElementContent | undefined) => { isRoot: boolean; isReachable: boolean | undefined; }; enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: CfgInformationArguments | undefined, prev: CfgInformationSearchContent | undefined) => Promise<CfgInformationSearchContent>; }; readonly roxygen: { enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: undefined, prev: RoxygenSearchContent | undefined) => Promise<RoxygenSearchContent>; enrichElement: (e: FlowrSearchElement<ParentInformation>, search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, analyzer: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, _args: undefined, prev: RoxygenElementContent | undefined) => Promise<{ [x: string]: unknown; documentation: ({ value: string[]; type: KnownRoxygenTags.Aliases; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Backref; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Concept; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Family; inherited?: boolean | undefined; } | { value: string[]; type: KnownRoxygenTags.Keywords; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.References; inherited?: boolean | undefined; } | { value: string[]; type: KnownRoxygenTags.SeeAlso; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.EvalNamespace; inherited?: boolean | undefined; } | { type: KnownRoxygenTags.Export; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.ExportClass; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.ExportMethod; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.ExportPattern; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.ExportS3Method; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Import; inherited?: boolean | undefined; } | { value: { package: string; classes: string[]; }; type: KnownRoxygenTags.ImportClassesFrom; inherited?: boolean | undefined; } | { value: { package: string; methods: string[]; }; type: KnownRoxygenTags.ImportMethodsFrom; inherited?: boolean | undefined; } | { value: { package: string; symbols: string[]; }; type: KnownRoxygenTags.ImportFrom; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.RawNamespace; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.UseDynLib; inherited?: boolean | undefined; } | { type: KnownRoxygenTags.Md; inherited?: boolean | undefined; } | { type: KnownRoxygenTags.NoMd; inherited?: boolean | undefined; } | { value: { title: string; content: string; }; type: KnownRoxygenTags.Section; inherited?: boolean | undefined; } | { value: { name: string; description: string; }; type: KnownRoxygenTags.Field; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Format; inherited?: boolean | undefined; } | { value: { generic: string; class: string; }; type: KnownRoxygenTags.Method; inherited?: boolean | undefined; } | { value: { name: string; description: string; }; type: KnownRoxygenTags.Slot; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Source; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Description; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Details; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Example; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Examples; inherited?: boolean | undefined; } | { value: { condition: string; content: string; }; type: KnownRoxygenTags.ExamplesIf; inherited?: boolean | undefined; } | { type: KnownRoxygenTags.NoRd; inherited?: boolean | undefined; } | { value: { name: string; description: string; }; type: KnownRoxygenTags.Param; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.RawRd; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Return | KnownRoxygenTags.Returns; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Title; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Usage; inherited?: boolean | undefined; } | { value: { dest: string; description: string; }; type: KnownRoxygenTags.DescribeIn; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Eval; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.EvalRd; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.IncludeRmd; inherited?: boolean | undefined; } | { value: { source: string; components: string[]; }; type: KnownRoxygenTags.Inherit; inherited?: boolean | undefined; } | { value: { source: string; args: string[]; }; type: KnownRoxygenTags.InheritDotParams; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.InheritParams; inherited?: boolean | undefined; } | { value: { source: string; section: string; }; type: KnownRoxygenTags.InheritSection; inherited?: boolean | undefined; } | { value: number | undefined; type: KnownRoxygenTags.Order; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.RdName; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Template; inherited?: boolean | undefined; } | { value: { name: string; value: string; }; type: KnownRoxygenTags.TemplateVar; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Author; inherited?: boolean | undefined; } | { value: { tag: string; content: string; }; type: KnownRoxygenTags.Unknown; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.DocType; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Name; inherited?: boolean | undefined; } | { value: string; type: KnownRoxygenTags.Text; inherited?: boolean | undefined; })[]; tags: { aliases?: { value: string[]; type: KnownRoxygenTags.Aliases; inherited?: boolean | undefined; }[] | undefined; backref?: { value: string; type: KnownRoxygenTags.Backref; inherited?: boolean | undefined; }[] | undefined; concept?: { value: string; type: KnownRoxygenTags.Concept; inherited?: boolean | undefined; }[] | undefined; family?: { value: string; type: KnownRoxygenTags.Family; inherited?: boolean | undefined; }[] | undefined; keywords?: { value: string[]; type: KnownRoxygenTags.Keywords; inherited?: boolean | undefined; }[] | undefined; references?: { value: string; type: KnownRoxygenTags.References; inherited?: boolean | undefined; }[] | undefined; seealso?: { value: string[]; type: KnownRoxygenTags.SeeAlso; inherited?: boolean | undefined; }[] | undefined; evalNamespace?: { value: string; type: KnownRoxygenTags.EvalNamespace; inherited?: boolean | undefined; }[] | undefined; export?: { type: KnownRoxygenTags.Export; inherited?: boolean | undefined; }[] | undefined; exportClass?: { value: string; type: KnownRoxygenTags.ExportClass; inherited?: boolean | undefined; }[] | undefined; exportMethod?: { value: string; type: KnownRoxygenTags.ExportMethod; inherited?: boolean | undefined; }[] | undefined; exportPattern?: { value: string; type: KnownRoxygenTags.ExportPattern; inherited?: boolean | undefined; }[] | undefined; exportS3Method?: { value: string; type: KnownRoxygenTags.ExportS3Method; inherited?: boolean | undefined; }[] | undefined; import?: { value: string; type: KnownRoxygenTags.Import; inherited?: boolean | undefined; }[] | undefined; importClassesFrom?: { value: { package: string; classes: string[]; }; type: KnownRoxygenTags.ImportClassesFrom; inherited?: boolean | undefined; }[] | undefined; importMethodsFrom?: { value: { package: string; methods: string[]; }; type: KnownRoxygenTags.ImportMethodsFrom; inherited?: boolean | undefined; }[] | undefined; importFrom?: { value: { package: string; symbols: string[]; }; type: KnownRoxygenTags.ImportFrom; inherited?: boolean | undefined; }[] | undefined; rawNamespace?: { value: string; type: KnownRoxygenTags.RawNamespace; inherited?: boolean | undefined; }[] | undefined; useDynLib?: { value: string; type: KnownRoxygenTags.UseDynLib; inherited?: boolean | undefined; }[] | undefined; md?: { type: KnownRoxygenTags.Md; inherited?: boolean | undefined; }[] | undefined; noMd?: { type: KnownRoxygenTags.NoMd; inherited?: boolean | undefined; }[] | undefined; section?: { value: { title: string; content: string; }; type: KnownRoxygenTags.Section; inherited?: boolean | undefined; }[] | undefined; field?: { value: { name: string; description: string; }; type: KnownRoxygenTags.Field; inherited?: boolean | undefined; }[] | undefined; format?: { value: string; type: KnownRoxygenTags.Format; inherited?: boolean | undefined; }[] | undefined; method?: { value: { generic: string; class: string; }; type: KnownRoxygenTags.Method; inherited?: boolean | undefined; }[] | undefined; slot?: { value: { name: string; description: string; }; type: KnownRoxygenTags.Slot; inherited?: boolean | undefined; }[] | undefined; source?: { value: string; type: KnownRoxygenTags.Source; inherited?: boolean | undefined; }[] | undefined; description?: { value: string; type: KnownRoxygenTags.Description; inherited?: boolean | undefined; }[] | undefined; details?: { value: string; type: KnownRoxygenTags.Details; inherited?: boolean | undefined; }[] | undefined; example?: { value: string; type: KnownRoxygenTags.Example; inherited?: boolean | undefined; }[] | undefined; examples?: { value: string; type: KnownRoxygenTags.Examples; inherited?: boolean | undefined; }[] | undefined; examplesIf?: { value: { condition: string; content: string; }; type: KnownRoxygenTags.ExamplesIf; inherited?: boolean | undefined; }[] | undefined; noRd?: { type: KnownRoxygenTags.NoRd; inherited?: boolean | undefined; }[] | undefined; param?: { value: { name: string; description: string; }; type: KnownRoxygenTags.Param; inherited?: boolean | undefined; }[] | undefined; rawRd?: { value: string; type: KnownRoxygenTags.RawRd; inherited?: boolean | undefined; }[] | undefined; return?: { value: string; type: KnownRoxygenTags.Return; inherited?: boolean | undefined; }[] | undefined; returns?: { value: string; type: KnownRoxygenTags.Returns; inherited?: boolean | undefined; }[] | undefined; title?: { value: string; type: KnownRoxygenTags.Title; inherited?: boolean | undefined; }[] | undefined; usage?: { value: string; type: KnownRoxygenTags.Usage; inherited?: boolean | undefined; }[] | undefined; describeIn?: { value: { dest: string; description: string; }; type: KnownRoxygenTags.DescribeIn; inherited?: boolean | undefined; }[] | undefined; eval?: { value: string; type: KnownRoxygenTags.Eval; inherited?: boolean | undefined; }[] | undefined; evalRd?: { value: string; type: KnownRoxygenTags.EvalRd; inherited?: boolean | undefined; }[] | undefined; includeRmd?: { value: string; type: KnownRoxygenTags.IncludeRmd; inherited?: boolean | undefined; }[] | undefined; inherit?: { value: { source: string; components: string[]; }; type: KnownRoxygenTags.Inherit; inherited?: boolean | undefined; }[] | undefined; inheritDotParams?: { value: { source: string; args: string[]; }; type: KnownRoxygenTags.InheritDotParams; inherited?: boolean | undefined; }[] | undefined; inheritParams?: { value: string; type: KnownRoxygenTags.InheritParams; inherited?: boolean | undefined; }[] | undefined; inheritSection?: { value: { source: string; section: string; }; type: KnownRoxygenTags.InheritSection; inherited?: boolean | undefined; }[] | undefined; order?: { value: number | undefined; type: KnownRoxygenTags.Order; inherited?: boolean | undefined; }[] | undefined; rdname?: { value: string; type: KnownRoxygenTags.RdName; inherited?: boolean | undefined; }[] | undefined; template?: { value: string; type: KnownRoxygenTags.Template; inherited?: boolean | undefined; }[] | undefined; templateVar?: { value: { name: string; value: string; }; type: KnownRoxygenTags.TemplateVar; inherited?: boolean | undefined; }[] | undefined; text?: { value: string; type: KnownRoxygenTags.Text; inherited?: boolean | undefined; }[] | undefined; name?: { value: string; type: KnownRoxygenTags.Name; inherited?: boolean | undefined; }[] | undefined; docType?: { value: string; type: KnownRoxygenTags.DocType; inherited?: boolean | undefined; }[] | undefined; author?: { value: string; type: KnownRoxygenTags.Author; inherited?: boolean | undefined; }[] | undefined; unknown?: { value: { tag: string; content: string; }; type: KnownRoxygenTags.Unknown; inherited?: boolean | undefined; }[] | undefined; }; }>; }; readonly "query-data": { enrichElement: (_e: FlowrSearchElement<ParentInformation>, _search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, _data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: QueryDataElementContent | undefined, prev: QueryDataElementContent | undefined) => QueryDataElementContent; enrichSearch: (_search: FlowrSearchElements<ParentInformation, FlowrSearchElement<ParentInformation>[]>, _data: ReadonlyFlowrAnalysisProvider<import("../../r-bridge/parser").KnownParser>, args: QueryDataSearchContent | undefined, prev: QueryDataSearchContent | undefined) => Required<QueryDataSearchContent>; }; }; /** * 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): EnrichmentElementContent<E>; /** * Enriches the given search element with the given enrichment type, using the provided analysis data. */ export declare function enrichElement<Element extends FlowrSearchElement<ParentInformation>, E extends Enrichment>(e: Element, s: FlowrSearchElements<ParentInformation>, analyzer: ReadonlyFlowrAnalysisProvider, enrichment: E, args?: EnrichmentElementArguments<E>): Promise<Element>;