UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

40 lines (39 loc) 2.66 kB
import type { DataflowGraph } from '../../dataflow/graph/graph'; import { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id'; /** * Path heuristic for an R package `inst/` resource (installed verbatim, not namespace source). Fallback for * the authoritative `FileRole.Install`, covering requests that bypass the file-role plugins. */ export declare function isInstalledResourceFile(file: string | undefined): boolean; /** * Whether the variable use `id` resolves to a local definition, a parameter, or a built-in (function or * constant such as `T`, `pi`). Broader than `Dataflow.origin`, which misses built-in constants. */ export declare function useResolvesToDefinitionOrBuiltin(graph: DataflowGraph, id: NodeId): boolean; /** * Whether any edge incident to `id` marks it as non-standard-evaluated (quoted), e.g. `quote`/`substitute`. * A loop body is marked as non-standard-evaluated too, but it is evaluated, so it does not count here. */ export declare function isNonStandardEvaluated(graph: DataflowGraph, id: NodeId): boolean; /** * Whether the use `id` sits inside a `[`/`[[` subscript (not the accessed object). `data.table`'s * `DT[i, j, by]` masks the subscript symbols as columns, but flowR cannot tell this apart from ordinary * indexing (`x[i]`), so the rule suppresses subscript symbols by default. Stops at the enclosing function. */ export declare function isInSubscript(graph: DataflowGraph, id: NodeId): boolean; /** The lexical scope a definition/use belongs to: the id of the enclosing function definition, or the top level. */ export type Scope = NodeId | 'top'; /** Names bound unconditionally within each lexical scope, see {@link collectScopeDefinedNames}. */ export type ScopeDefinedNames = ReadonlyMap<Scope, ReadonlySet<string>>; /** * Per scope, the names it binds unconditionally. flowR's static resolution does not always link a use in a * nested function to a binding introduced later in an enclosing scope; the rule consults this as a fallback. * Only unconditional bindings are recorded: one assigned solely inside an `if`/loop is not guaranteed to * exist, so suppressing an unresolved use of it would hide a real possibly-undefined access. */ export declare function collectScopeDefinedNames(graph: DataflowGraph): ScopeDefinedNames; /** * Whether `name` is bound in the scope of `useId` or an enclosing scope (up to the top level), per * {@link collectScopeDefinedNames}. Suppresses forward-referenced closure variables flowR did not link. */ export declare function isDefinedInEnclosingScope(graph: DataflowGraph, defined: ScopeDefinedNames, useId: NodeId, name: string): boolean;