@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
93 lines (92 loc) • 4.77 kB
TypeScript
import { VariableResolve } from '../../../config';
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 { Identifier } from '../../environments/identifier';
import type { DataflowGraph } from '../../graph/graph';
import { type Lift, type Value, type ValueSet } from '../values/r-value';
import type { ReadOnlyFlowrAnalyzerContext } from '../../../project/context/flowr-analyzer-context';
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;
/** Variable resolve mode */
resolve?: VariableResolve;
/** Context used for resolving */
ctx: ReadOnlyFlowrAnalyzerContext;
/** If set, the ids that should not be considered during resolution (=> top) */
blocked?: Set<NodeId>;
}
/**
* 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
* @param resolve - Variable resolve mode
* @param ctx - Context used for clean environment
* @param blocked - If set, the ids that should not be considered during resolution (=>top)
*/
export declare function resolveIdToValue(id: NodeId | RNodeWithParent | undefined, { environment, graph, idMap, full, ctx, resolve, blocked }: 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 environment - Environment to use
* @param r - Resolve information (env, ctx, ...)
* @returns Value of Identifier or Top
*/
export declare function trackAliasInEnvironments(identifier: Identifier | undefined, environment: REnvironmentInformation, { blocked, idMap, resolve, ctx, graph }: Omit<ResolveInfo, 'environment'>): ResolveResult;
/**
* Please use {@link resolveIdToValue}
*
* Tries to resolve the value of a node by traversing the dataflow graph
* @param id - node to resolve
* @param ctx - analysis context
* @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, ctx: ReadOnlyFlowrAnalyzerContext, 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;