UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

88 lines (87 loc) 3.98 kB
import type { AstIdMap, RNodeWithParent } from '../../../r-bridge/lang-4.x/ast/model/processing/decorate'; import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id'; import type { REnvironmentInformation } from '../../environments/environment'; import type { Identifier } from '../../environments/identifier'; import type { DataflowGraph } from '../../graph/graph'; import type { Lift, Value, ValueSet } from '../values/r-value'; export type ResolveResult = Lift<ValueSet<Value[]>>; export interface ResolveInfo { /** The current environment used for name resolution */ environment?: REnvironmentInformation; /** The id map to resolve the node if given as an id */ idMap?: AstIdMap; /** The graph to resolve in */ graph?: DataflowGraph; /** Whether to track variables */ full?: boolean; } /** * Gets the definitions / aliases of a node * * This function is called by the built-in-assignment processor so that we can * track assignments inside the environment. The returned ids are stored in * the sourceIds value field of their InGraphIdentifierDefinition. This enables * us later, in the {@link trackAliasInEnvironments} function, to get all the * aliases of an identifier. * * @param sourceIds - node ids to get the definitions for * @param dataflow - dataflow graph * @param environment - environment * @returns node id of alias */ export declare function getAliases(sourceIds: readonly NodeId[], dataflow: DataflowGraph, environment: REnvironmentInformation): NodeId[] | undefined; /** * Evaluates the value of a node in the set domain. * * resolveIdToValue tries to resolve the value using the data it has been given. * If the environment is provided the approximation is more precise, as we can * track aliases in the environment. * Otherwise, the graph is used to try and resolve the nodes value. * If neither is provided the value cannot be resolved. * * This function is also used by the Resolve Value Query and the Dependency Query * to resolve values. For e.g. in the Dependency Query it is used to resolve calls * like `lapply(c("a", "b", "c"), library, character.only = TRUE)` * * @param id - The node id or node to resolve * @param environment - The current environment used for name resolution * @param graph - The graph to resolve in * @param idMap - The id map to resolve the node if given as an id * @param full - Whether to track aliases on resolve */ export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefined, { environment, graph, idMap, full }: ResolveInfo): ResolveResult; /** * Please use {@link resolveIdToValue} * * Uses the aliases that were tracked in the environments (by the * {@link getAliases} function) to resolve a node to a value. * * * @param identifier - Identifier to resolve * @param use - Environment to use * @param graph - Dataflow graph * @param idMap - id map of Dataflow graph * @returns Value of Identifier or Top */ export declare function trackAliasInEnvironments(identifier: Identifier | undefined, use: REnvironmentInformation, graph?: DataflowGraph, idMap?: AstIdMap): ResolveResult; /** * Please use {@link resolveIdToValue} * * Tries to resolve the value of a node by traversing the dataflow graph * * @param id - node to resolve * @param graph - dataflow graph * @param idMap - idmap of dataflow graph * @returns Value of node or Top/Bottom */ export declare function trackAliasesInGraph(id: NodeId, graph: DataflowGraph, idMap?: AstIdMap): ResolveResult; /** * Please use {@link resolveIdToValue} * * Resolve an Identifier to a constant, if the identifier is a constant * * @param name - Identifier to resolve * @param environment - Environment to use * @returns Value of Constant or Top */ export declare function resolveToConstants(name: Identifier | undefined, environment: REnvironmentInformation): ResolveResult;