UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

80 lines 3.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowrAnalyzerEnvironmentContext = void 0; const environment_1 = require("../../dataflow/environments/environment"); const built_in_config_1 = require("../../dataflow/environments/built-in-config"); const identifier_1 = require("../../dataflow/environments/identifier"); const fingerprint_1 = require("../../slicing/static/fingerprint"); /** * Provides the built-in environment, created from the {@link FlowrAnalyzerContext} configuration. */ class FlowrAnalyzerEnvironmentContext { name = 'flowr-analyzer-environment-context'; builtInEnv; emptyBuiltInEnv; builtInEnvFingerprint; /** the packages {@link knowsPackage} answers for, collected from the built-in environment on first use */ knownPackages; constructor(ctx) { const builtInsConfig = ctx.config.semantics.environment.overwriteBuiltIns; const builtIns = (0, built_in_config_1.getBuiltInDefinitions)(builtInsConfig.definitions, builtInsConfig.loadDefaults); this.builtInEnv = new environment_1.Environment(undefined, true); this.builtInEnv.memory = builtIns.builtInMemory; this.emptyBuiltInEnv = new environment_1.Environment(undefined, true); this.emptyBuiltInEnv.memory = builtIns.emptyBuiltInMemory; } get builtInEnvironment() { return this.builtInEnv; } get emptyBuiltInEnvironment() { return this.emptyBuiltInEnv; } builtInDefinitionsOf(name) { return this.builtInEnv.memory.get(identifier_1.Identifier.getName(name)) ?? []; } knowsPackage(pkg) { if (this.knownPackages === undefined) { this.knownPackages = new Set(); for (const [, definitions] of this.builtInEnv.memory) { for (const definition of definitions) { const namespace = definition.name === undefined ? undefined : identifier_1.Identifier.getNamespace(definition.name); if (namespace !== undefined) { this.knownPackages.add(String(namespace)); } } } } return this.knownPackages.has(pkg); } builtInFunctionOf(name) { const namespace = identifier_1.Identifier.getNamespace(name); return this.builtInDefinitionsOf(name).find((d) => d.type === identifier_1.ReferenceType.BuiltInFunction && typeof d.processor === 'function' && (namespace === undefined || (d.name !== undefined && identifier_1.Identifier.getNamespace(d.name) === namespace))); } makeCleanEnv() { return { current: new environment_1.Environment(this.builtInEnv).asGlobal(), level: 0 }; } getCleanEnvFingerprint() { if (!this.builtInEnvFingerprint) { this.builtInEnvFingerprint = (0, fingerprint_1.envFingerprint)(this.makeCleanEnv()); } return this.builtInEnvFingerprint; } makeCleanEnvWithEmptyBuiltIns() { return { current: new environment_1.Environment(this.emptyBuiltInEnv).asGlobal(), level: 0 }; } makeEmptyEnv() { return { current: new environment_1.Environment(undefined, true), level: 0 }; } } exports.FlowrAnalyzerEnvironmentContext = FlowrAnalyzerEnvironmentContext; //# sourceMappingURL=flowr-analyzer-environment-context.js.map