@eagleoutice/flowr-dev
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
41 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.functionInfosFromProps = functionInfosFromProps;
const built_in_props_1 = require("../../../../dataflow/environments/built-in-props");
const default_builtin_config_1 = require("../../../../dataflow/environments/default-builtin-config");
const query_fn_props_1 = require("../../../../dataflow/environments/query-fn-props");
const identifier_1 = require("../../../../dataflow/environments/identifier");
/** what an entry links to, like `sink` for `cat`: the link reports it already, so it is not an entry of its own */
function linkTargets(f) {
return (f.linkTo ?? []).flatMap(l => typeof l.callName === 'string' ? [l.callName]
: Array.isArray(l.callName) ? l.callName.map(n => identifier_1.Identifier.getName(n)) : []);
}
/**
* The built-ins that carry all of `props` and name the resource they act on, as entries of a dependency
* category. This is what the {@link DefaultBuiltinConfig} already states, so only the functions it does not
* know (most package functions) and the ones needing more than a resource argument (`ignoreIf`, `linkTo`,
* a default, ...) have to be written down in the category itself. Names in `except` stay with whoever
* wrote them down.
*/
function functionInfosFromProps(props, except) {
const taken = new Set(except.flatMap(f => [f.name, ...linkTargets(f)]));
const found = [];
for (const d of default_builtin_config_1.DefaultBuiltinConfig) {
const info = d.type !== 'constant' ? d.config : undefined;
if (info?.props === undefined || (info.props & props) !== props || info.sig === undefined) {
continue;
}
const argIdx = info.sig.findIndex(([, p]) => (p & built_in_props_1.ArgProp.Resource) !== 0);
if (argIdx < 0) {
continue;
}
for (const id of (0, query_fn_props_1.builtInNames)(d)) {
const name = identifier_1.Identifier.getName(id);
if (!taken.has(name)) {
found.push({ package: identifier_1.Identifier.getNamespace(id), name, argIdx, argName: info.sig[argIdx][0], resolveValue: true });
}
}
}
return found;
}
//# sourceMappingURL=derived-functions.js.map