@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
45 lines • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.processClassGenerator = processClassGenerator;
exports.resolveClassMethodsToEnvState = resolveClassMethodsToEnvState;
exports.resolveConstructorInstanceEnvState = resolveConstructorInstanceEnvState;
const r_function_call_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/nodes/r-function-call");
const known_call_handling_1 = require("../known-call-handling");
const built_in_proc_name_1 = require("../../../../../environments/built-in-proc-name");
const built_in_list_1 = require("./built-in-list");
const built_in_envir_utils_1 = require("./built-in-envir-utils");
const type_1 = require("../../../../../../r-bridge/lang-4.x/ast/model/type");
const identifier_1 = require("../../../../../environments/identifier");
const resolve_helper_1 = require("../../../../../environments/resolve-helper");
/** R6's `public` / Reference Class's `methods` argument carrying the class generator's methods. */
const MethodListArguments = ['public', 'methods'];
/** Processes an `R6Class`/`setRefClass` generator call, tagging it so the assignment layer can record its method list. */
function processClassGenerator(name, args, rootId, data) {
return (0, known_call_handling_1.processKnownFunctionCall)({ name, args, rootId, data, origin: built_in_proc_name_1.BuiltInProcName.ClassGenerator }).information;
}
/** The method env of a class generator's `public`/`methods` `list(...)` (via {@link resolveListToEnvState}); `undefined` if absent. */
function resolveClassMethodsToEnvState(source, data) {
if (!r_function_call_1.RFunctionCall.isNamed(source)) {
return undefined;
}
const methodList = source.arguments.find(arg => arg !== r_function_call_1.EmptyArgument && arg.name !== undefined && MethodListArguments.includes(arg.name.content));
return methodList && methodList !== r_function_call_1.EmptyArgument && methodList.value !== undefined ? (0, built_in_list_1.resolveListToEnvState)(methodList.value, data) : undefined;
}
const ConstructorField = 'new';
/** The method env an instance from `<Cls>$new(...)`/`<Cls>[["new"]](...)` carries, from the generator's recorded `returnsEnvState`; `undefined` otherwise. */
function resolveConstructorInstanceEnvState(source, data) {
if (source.type !== type_1.RType.FunctionCall || source.named) {
return undefined;
}
const callee = source.calledFunction;
if (callee.type !== type_1.RType.Access || (callee.operator !== '$' && callee.operator !== '[[') || callee.accessed.type !== type_1.RType.Symbol) {
return undefined;
}
const field = callee.access[0] === r_function_call_1.EmptyArgument ? undefined : callee.access[0]?.value;
const fieldName = field?.type === type_1.RType.String ? field.content.str : field?.lexeme;
if (fieldName !== ConstructorField) {
return undefined;
}
return (0, built_in_envir_utils_1.findReturnsEnvState)(resolve_helper_1.Resolve.byNameAndType(callee.accessed.content, data.environment, identifier_1.ReferenceType.Variable));
}
//# sourceMappingURL=built-in-class-generator.js.map