UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

74 lines 3.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowrAnalyzerFunctionsContext = exports.FunctionTypes = void 0; const abstract_flowr_analyzer_context_1 = require("./abstract-flowr-analyzer-context"); const flowr_analyzer_package_versions_plugin_1 = require("../plugins/package-version-plugins/flowr-analyzer-package-versions-plugin"); const flowr_analyzer_package_versions_namespace_file_plugin_1 = require("../plugins/package-version-plugins/flowr-analyzer-package-versions-namespace-file-plugin"); var FunctionTypes; (function (FunctionTypes) { FunctionTypes["Function"] = "function"; FunctionTypes["ExportTypes"] = "exportTypes"; FunctionTypes["S3"] = "S3"; })(FunctionTypes || (exports.FunctionTypes = FunctionTypes = {})); /** * This context is responsible for managing the functions identified in the project, including their origins, types, and other metadata. * It works in conjunction with {@link FlowrAnalyzerPackageVersionsPlugin}s to gather and maintain this information. * * If you are interested in inspecting these functions, refer to {@link ReadOnlyFlowrAnalyzerFunctionsContext}. */ class FlowrAnalyzerFunctionsContext extends abstract_flowr_analyzer_context_1.AbstractFlowrAnalyzerContext { name = 'flowr-analyzer-functions-context'; functionInfo = new Map(); constructor(ctx, plugins) { super(ctx, flowr_analyzer_package_versions_plugin_1.FlowrAnalyzerPackageVersionsPlugin.defaultPlugin(), plugins); } addFunctionInfo(info) { const list = this.functionInfo.get(info.name); if (!list) { this.functionInfo.set(info.name, [info]); return; } const other = list.find(e => e.name === info.name && e.packageOrigin === info.packageOrigin && e.s3TypeDispatch === info.s3TypeDispatch); if (other) { flowr_analyzer_package_versions_namespace_file_plugin_1.namespaceFileLog.warn('Namespace information is being merged!'); this.mergeFunctionInfo(other, info); } else { list.push(info); } } mergeFunctionInfo(functionInfo, other) { if (functionInfo.name !== other.name || functionInfo.packageOrigin !== other.packageOrigin) { throw new Error(`Cannot merge FunctionInfo for ${functionInfo.name} and ${other.name}`); } if (functionInfo.s3TypeDispatch !== other.s3TypeDispatch) { throw new Error(`Cannot merge FunctionInfo with different S3 dispatch for ${functionInfo.name}`); } if (!functionInfo.inferredType && other.inferredType) { functionInfo.inferredType = other.inferredType; } functionInfo.isExported ||= other.isExported; functionInfo.isS3Generic ||= other.isS3Generic; } getFunctionInfo(pkg, name, s3TypeDispatch) { if (s3TypeDispatch) { return this.functionInfo.get(`${name}`)?.find(e => e.packageOrigin === pkg && e.s3TypeDispatch === s3TypeDispatch); } else if (name.includes('.')) { const parts = name.split('.'); s3TypeDispatch = parts.pop(); const splitName = parts.join('.'); if (this.functionInfo.has(splitName)) { return this.functionInfo.get(splitName)?.find(e => e.packageOrigin === pkg && e.s3TypeDispatch === s3TypeDispatch); } } return this.functionInfo.get(name)?.filter(e => e.packageOrigin === pkg); } reset() { this.functionInfo = new Map(); } } exports.FlowrAnalyzerFunctionsContext = FlowrAnalyzerFunctionsContext; //# sourceMappingURL=flowr-analyzer-functions-context.js.map