@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
161 lines (160 loc) • 11.1 kB
TypeScript
import type { DataflowProcessorInformation } from '../processor';
import type { DataflowInformation, ExitPointType } from '../info';
import { processAccess } from '../internal/process/functions/call/built-in/built-in-access';
import { processIfThenElse } from '../internal/process/functions/call/built-in/built-in-if-then-else';
import { processAssignment, processAssignmentLike } from '../internal/process/functions/call/built-in/built-in-assignment';
import { processSpecialBinOp } from '../internal/process/functions/call/built-in/built-in-special-bin-op';
import { processPipe } from '../internal/process/functions/call/built-in/built-in-pipe';
import { processForLoop } from '../internal/process/functions/call/built-in/built-in-for-loop';
import { processRepeatLoop } from '../internal/process/functions/call/built-in/built-in-repeat-loop';
import { processWhileLoop } from '../internal/process/functions/call/built-in/built-in-while-loop';
import { type BrandedIdentifier, type IdentifierDefinition, type IdentifierReference, ReferenceType } from './identifier';
import { processReplacementFunction } from '../internal/process/functions/call/built-in/built-in-replacement';
import { processQuote } from '../internal/process/functions/call/built-in/built-in-quote';
import { processFunctionDefinition } from '../internal/process/functions/call/built-in/built-in-function-definition';
import { processExpressionList } from '../internal/process/functions/call/built-in/built-in-expression-list';
import { processGet } from '../internal/process/functions/call/built-in/built-in-get';
import type { AstIdMap, ParentInformation, RNodeWithParent } from '../../r-bridge/lang-4.x/ast/model/processing/decorate';
import { type RFunctionArgument } from '../../r-bridge/lang-4.x/ast/model/nodes/r-function-call';
import { RSymbol } from '../../r-bridge/lang-4.x/ast/model/nodes/r-symbol';
import { type BuiltIn, NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
import { processLibrary } from '../internal/process/functions/call/built-in/built-in-library';
import { processSourceCall } from '../internal/process/functions/call/built-in/built-in-source';
import type { ForceArguments } from '../internal/process/functions/call/common';
import { processApply } from '../internal/process/functions/call/built-in/built-in-apply';
import type { LinkTo } from '../../queries/catalog/call-context-query/call-context-query-format';
import { processList } from '../internal/process/functions/call/built-in/built-in-list';
import { processVector } from '../internal/process/functions/call/built-in/built-in-vector';
import { processRm } from '../internal/process/functions/call/built-in/built-in-rm';
import { processEvalCall } from '../internal/process/functions/call/built-in/built-in-eval';
import type { REnvironmentInformation } from './environment';
import type { Value } from '../eval/values/r-value';
import { resolveAsMinus, resolveAsPlus, resolveAsSeq, resolveAsVector } from '../eval/resolve/resolve';
import type { DataflowGraph } from '../graph/graph';
import type { VariableResolve } from '../../config';
import type { BuiltInConstantDefinition, BuiltInDefinition, BuiltInFunctionDefinition, BuiltInReplacementDefinition } from './built-in-config';
import type { ReadOnlyFlowrAnalyzerContext } from '../../project/context/flowr-analyzer-context';
import { processStopIfNot } from '../internal/process/functions/call/built-in/built-in-stop-if-not';
import { processTryCatch } from '../internal/process/functions/call/built-in/built-in-try-catch';
import { processRegisterHook } from '../internal/process/functions/call/built-in/built-in-register-hook';
import { processLocal } from '../internal/process/functions/call/built-in/built-in-local';
import { processS3Dispatch } from '../internal/process/functions/call/built-in/built-in-s-three-dispatch';
import { processRecall } from '../internal/process/functions/call/built-in/built-in-recall';
import { processS7NewGeneric } from '../internal/process/functions/call/built-in/built-in-s-seven-new-generic';
import { processS7Dispatch } from '../internal/process/functions/call/built-in/built-in-s-seven-dispatch';
import { BuiltInProcName } from './built-in-proc-name';
export type BuiltInIdentifierProcessor = <OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly RFunctionArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>) => DataflowInformation;
export type BuiltInIdentifierProcessorWithConfig<Config> = <OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly RFunctionArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, config: Config) => DataflowInformation;
export interface BuiltInIdentifierDefinition extends IdentifierReference {
type: ReferenceType.BuiltInFunction;
definedAt: BuiltIn;
processor: BuiltInIdentifierProcessor;
config?: ConfigOfBuiltInMappingName<keyof typeof BuiltInProcessorMapper> & {
libFn?: boolean;
};
}
export interface BuiltInIdentifierConstant<T = unknown> extends IdentifierReference {
type: ReferenceType.BuiltInConstant;
definedAt: BuiltIn;
value: T;
}
export interface DefaultBuiltInProcessorConfiguration extends ForceArguments {
readonly returnsNthArgument?: number | 'last';
readonly cfg?: ExitPointType;
readonly readAllArguments?: boolean;
readonly hasUnknownSideEffects?: boolean | LinkTo<RegExp | string>;
/** record mapping the actual function name called to the arguments that should be treated as function calls */
readonly treatAsFnCall?: Record<string, readonly string[]>;
/**
* Name that should be used for the origin (useful when needing to differentiate between
* functions like 'return' that use the default builtin processor)
*/
readonly useAsProcessor?: BuiltInProcName;
}
export interface BuiltInEvalHandlerArgs {
resolve: VariableResolve;
node: RNodeWithParent;
ctx: ReadOnlyFlowrAnalyzerContext;
environment?: REnvironmentInformation;
graph?: DataflowGraph;
idMap?: AstIdMap;
blocked?: Set<NodeId>;
}
export type BuiltInEvalHandler = (args: BuiltInEvalHandlerArgs) => Value;
declare function defaultBuiltInProcessor<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly RFunctionArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, { returnsNthArgument, useAsProcessor, forceArgs, readAllArguments, cfg, hasUnknownSideEffects, treatAsFnCall }: DefaultBuiltInProcessorConfiguration): DataflowInformation;
declare function defaultBuiltInProcessorReadallArgs<OtherInfo>(name: RSymbol<OtherInfo & ParentInformation>, args: readonly RFunctionArgument<OtherInfo & ParentInformation>[], rootId: NodeId, data: DataflowProcessorInformation<OtherInfo & ParentInformation>, { useAsProcessor, forceArgs }: Pick<DefaultBuiltInProcessorConfiguration, 'useAsProcessor' | 'forceArgs'>): DataflowInformation;
export declare const BuiltInProcessorMapper: {
readonly "builtin:access": typeof processAccess;
readonly "builtin:apply": typeof processApply;
readonly "builtin:assignment": typeof processAssignment;
readonly "builtin:assignment-like": typeof processAssignmentLike;
readonly "builtin:default": typeof defaultBuiltInProcessor;
readonly "builtin:default-read-all-args": typeof defaultBuiltInProcessorReadallArgs;
readonly "builtin:eval": typeof processEvalCall;
readonly "builtin:expression-list": typeof processExpressionList;
readonly "builtin:for-loop": typeof processForLoop;
readonly "builtin:function-definition": typeof processFunctionDefinition;
readonly "builtin:get": typeof processGet;
readonly "builtin:if-then-else": typeof processIfThenElse;
readonly "builtin:library": typeof processLibrary;
readonly "builtin:list": typeof processList;
readonly "builtin:local": typeof processLocal;
readonly "builtin:pipe": typeof processPipe;
readonly "builtin:quote": typeof processQuote;
readonly "builtin:recall": typeof processRecall;
readonly "builtin:register-hook": typeof processRegisterHook;
readonly "builtin:repeat-loop": typeof processRepeatLoop;
readonly "builtin:replacement": typeof processReplacementFunction;
readonly "builtin:rm": typeof processRm;
readonly "builtin:s3-dispatch": typeof processS3Dispatch;
readonly "builtin:s7-new-generic": typeof processS7NewGeneric;
readonly "builtin:s7-dispatch": typeof processS7Dispatch;
readonly "builtin:source": typeof processSourceCall;
readonly "builtin:special-bin-op": typeof processSpecialBinOp;
readonly "builtin:stopifnot": typeof processStopIfNot;
readonly "builtin:try": typeof processTryCatch;
readonly "builtin:vector": typeof processVector;
readonly "builtin:while-loop": typeof processWhileLoop;
};
export declare const BuiltInEvalHandlerMapper: {
readonly 'built-in:c': typeof resolveAsVector;
readonly 'built-in::': typeof resolveAsSeq;
readonly 'built-in:+': typeof resolveAsPlus;
readonly 'built-in:-': typeof resolveAsMinus;
};
export type ConfigOfBuiltInMappingName<N extends keyof typeof BuiltInProcessorMapper> = Parameters<typeof BuiltInProcessorMapper[N]>[4];
export type BuiltInMemory = Map<BrandedIdentifier, IdentifierDefinition[]>;
export declare class BuiltIns {
/**
* Register a built-in constant (like `NULL` or `TRUE`) to the given {@link BuiltIns}
*/
registerBuiltInConstant<T>({ names, value, assumePrimitive }: BuiltInConstantDefinition<T>): void;
/**
* Register a built-in function (like `print` or `c`) to the given {@link BuiltIns}
*/
registerBuiltInFunctions<BuiltInProcessor extends keyof typeof BuiltInProcessorMapper>({ names, processor, config, assumePrimitive }: BuiltInFunctionDefinition<BuiltInProcessor>): void;
/**
* Registers all combinations of replacements
*/
registerReplacementFunctions({ names, suffixes, assumePrimitive, config }: BuiltInReplacementDefinition): void;
/**
* Register a single {@link BuiltInDefinition} to the given memories in {@link BuiltIns}
*/
registerBuiltInDefinition(definition: BuiltInDefinition): void;
/**
* The built-in {@link REnvironmentInformation|environment} is the root of all environments.
*
* For its default content (when not overwritten by a flowR config),
* see the {@link DefaultBuiltinConfig}.
*/
builtInMemory: BuiltInMemory;
/**
* The twin of the {@link builtInMemory} but with less built ins defined for
* cases in which we want some commonly overwritten variables to remain open.
* If you do not know if you need the empty environment, you do not need the empty environment (right now).
* @see {@link builtInMemory}
*/
emptyBuiltInMemory: BuiltInMemory;
set(identifier: BrandedIdentifier, definition: IdentifierDefinition[], includeInEmptyMemory: boolean | undefined): void;
}
export {};