UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

71 lines (70 loc) 5.54 kB
import type { DataflowProcessorInformation } from '../../../../../processor'; import type { DataflowInformation, ControlDependency } from '../../../../../info'; import type { DataflowGraph } from '../../../../../graph/graph'; 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 { RSymbol } from '../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-symbol'; import { NodeId } from '../../../../../../r-bridge/lang-4.x/ast/model/processing/node-id'; import type { REnvironmentInformation } from '../../../../../environments/environment'; import type { FlowrAnalyzerContext } from '../../../../../../project/context/flowr-analyzer-context'; import { Package } from '../../../../../../project/plugins/package-version-plugins/package'; /** Controls how {@link processLibrary} brings a package into scope. */ export interface LibraryProcessorConfig { /** `requireNamespace("pkg")` / `loadNamespace("pkg")`: load without attaching bare names */ readonly namespaceOnly?: boolean; /** the package argument is evaluated, not taken as a symbol (`requireNamespace`/`loadNamespace`/`attachNamespace`, unlike `library`) */ readonly characterOnly?: boolean; /** `import::from(pkg, a, b)`: attach only the symbols named in the call */ readonly fromImports?: boolean; /** `box::use(pkg[a, b])`: attach only the symbols listed in the `[...]` bracket */ readonly boxUse?: boolean; } /** Restricts/aliases which exports of a package are attached; `undefined` fields attach every export. */ interface AttachSpec { readonly namespaceOnly?: boolean; /** attached exports as attachedName to exportName (`import::from`/`box::use` selection or aliasing) */ readonly include?: ReadonlyMap<string, string>; /** attach all exports except these (`import::from` `.except`) */ readonly exclude?: ReadonlySet<string>; /** attach every export (`import::from` `.all`, `box::use(pkg[...])`) */ readonly all?: boolean; /** `library(pkg, pos = 3)`: the `search()` position to attach at, {@link DefaultAttachPosition} if unset */ readonly pos?: number; } /** * Process a library call like `library` or `require` */ export declare function processLibrary<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly PotentiallyEmptyRArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config?: LibraryProcessorConfig): DataflowInformation; /** Materialize the empty built-in function-definition vertex for a package export (idempotent). */ export declare function attachExportVertex(graph: DataflowGraph, builtInId: NodeId, environment: REnvironmentInformation, ctx: FlowrAnalyzerContext, cds?: ControlDependency[]): void; /** * The load calls (`library()`/`require()`) that brought package `pack` into scope without a database, collected from * the {@link libraryLoadMarker} of every matching {@link EnvType.LoadedNamespace} layer below the global environment. */ export declare function loadNodesForNamespace(env: REnvironmentInformation, pack: string): NodeId[]; /** * Attaches `dependency`'s exports at `spec`'s {@link AttachSpec#pos|search position} (below the global environment by * default, see {@link REnvironment.attachAt|attachPackageAt}) and returns the * enriched environment (the graph is untouched). Used by `library()`, `import::from`, `box::use`, `requireNamespace`, * and the transitive side-effect propagation. */ export declare function attachDependencyToEnvironment(dependency: Package, envInfo: REnvironmentInformation, ctx: FlowrAnalyzerContext, spec?: AttachSpec, definedAt?: NodeId): REnvironmentInformation; /** * Attach the {@link baseRPackages|base-R} exports below the global so bare base calls resolve without `library()`. * Names with a registered built-in are skipped, it is a no-op when no database resolves a base package, and the * built layer is cached per {@link baseNamespaceCacheKey}. */ export declare function attachBaseRNamespaces(env: REnvironmentInformation, ctx: FlowrAnalyzerContext): REnvironmentInformation; /** * Attach the exports of the project's declared `DESCRIPTION` dependencies (Imports/Depends, registered by the * package-version plugins into {@link FlowrAnalyzerContext.deps|deps}) below the global so their bare calls resolve * without an explicit `library()`, mirroring base-R auto-attach. A dependency whose {@link Package.namespaceInfo| * namespaceInfo} no database resolves is skipped, and a package base-R or an earlier iteration already attached is a * no-op via the {@link isAttached} guard inside {@link attachDependencyToEnvironment}. */ export declare function attachDeclaredDependencies(env: REnvironmentInformation, ctx: FlowrAnalyzerContext): REnvironmentInformation; /** attach the analyzed package's own `NAMESPACE importFrom(...)` symbols (by their bare name) below the global, so a bare imported call resolves to its source package */ export declare function attachProjectImports(env: REnvironmentInformation, ctx: FlowrAnalyzerContext): REnvironmentInformation; /** attach every project-level environment layer in order: base R namespaces, the project's own `importFrom` symbols, then its declared dependencies */ export declare function attachProject(env: REnvironmentInformation, ctx: FlowrAnalyzerContext): REnvironmentInformation; export {};