@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
91 lines (90 loc) • 3.48 kB
TypeScript
import type { NodeId } from '../../../r-bridge/lang-4.x/ast/model/processing/node-id';
import type { DataflowGraph } from '../../../dataflow/graph/graph';
import type { MergeableRecord } from '../../../util/objects';
import { Identifier } from '../../../dataflow/environments/identifier';
/**
* Lattice flattening until we have a taint engine :)
*
*```
* [ Unknown ]
* / / | \ \
*[Param] [File] [Net] [Rand] [Scope]
* \ \ | / /
* [ DerivedConstant ]
* |
* [ Constant ]
*```
*
*/
export declare enum InputType {
Parameter = "param",
File = "file",
Network = "net",
Random = "rand",
Constant = "const",
/** Read from environment/call scope */
Scope = "scope",
/** Pure calculations from constants that lead to a constant */
DerivedConstant = "dconst",
Unknown = "unknown"
}
export declare enum InputTraceType {
/** Derived only from aliasing */
Alias = "alias",
/** Derived from pure function chains */
Pure = "pure",
/** Derived from known but not necessarily all pure function chains */
Known = "known",
/** Not fully known origin */
Unknown = "unknown"
}
/**
* Object attached to an input source
* @see {@link InputSources}
*/
export interface InputSource extends MergeableRecord {
id: NodeId;
type: InputType[];
trace: InputTraceType;
/** if the trace is affected by control dependencies, they are classified too, this is a duplicate free array */
cds?: InputType[];
}
/**
* Map of input sources, keyed by the node id of the input source. Each input source is classified with an {@link InputSource} object.
*/
export type InputSources = InputSource[];
/**
* This is either an {@link NodeId|id} of a known functions all of that category (e.g., you can issue a dependencies query before and then pass all
* identified ids to this query here).
*/
export type InputClassifierFunctionIdentifier = Identifier | NodeId;
/**
* For the specifications of `pureFns` etc. please have a look at {@link InputClassifierFunctionIdentifier}.
*/
export interface InputClassifierConfig extends MergeableRecord {
/**
* Functions which are considered to be pure (i.e., deterministic, trusted, safe, idempotent on the lub of the input types)
*/
pureFns: readonly InputClassifierFunctionIdentifier[];
/**
* Functions that read from the network
*/
networkFns: readonly InputClassifierFunctionIdentifier[];
/**
* Functions that produce a random value
* Note: may need to check with respect to seeded randomness
*/
randomFns: readonly InputClassifierFunctionIdentifier[];
/**
* Functions that read from the file system
*/
readFileFns: readonly InputClassifierFunctionIdentifier[];
}
/**
* Takes the given id which is expected to either be:
* - a function call - in this case all arguments are considered to be inputs (additionally to all read edges from the function call in the dataflow graph)
* - anything else - in that case the node itself is considered as an "input" - please note that in these scenarios the *return* value will only contain one mapping - that for the id you pased in.
*
* This method traces the dependencies in the dataflow graph using the specification of functions passed in
*/
export declare function classifyInput(id: NodeId, dfg: DataflowGraph, config: InputClassifierConfig): InputSources;