UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

86 lines 5.02 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.diffIdentifierReferences = diffIdentifierReferences; exports.diffEnvironment = diffEnvironment; exports.diffEnvironmentInformation = diffEnvironmentInformation; const diff_1 = require("../../util/diff"); const environment_1 = require("./environment"); const json_1 = require("../../util/json"); const info_1 = require("../info"); function diffIdentifierReferences(a, b, info) { if (a === undefined || b === undefined) { if (a !== b) { info.report.addComment(`${info.position}Different identifier references: ${info.leftname}: ${JSON.stringify(a, json_1.jsonReplacer)} vs. ${info.rightname}: ${JSON.stringify(b, json_1.jsonReplacer)}`); } return; } if (a.name !== b.name) { info.report.addComment(`${info.position}Different identifier names: ${info.leftname}: ${a.name} vs. ${info.rightname}: ${b.name}`); } if (a.nodeId !== b.nodeId) { info.report.addComment(`${info.position}Different nodeIds: ${info.leftname}: ${a.nodeId} vs. ${info.rightname}: ${b.nodeId}`); } (0, info_1.diffControlDependencies)(a.controlDependencies, b.controlDependencies, info); } function diffMemory(a, b, info) { for (const [key, value] of a.memory) { const value2 = b.memory.get(key); if (value2 === undefined || value.length !== value2.length) { info.report.addComment(`${info.position}Different definitions for ${key}. ${info.leftname}: ${JSON.stringify(value, json_1.jsonReplacer)} vs. ${info.rightname}: ${JSON.stringify(value2, json_1.jsonReplacer)}`); continue; } // we sort both value arrays by their id so that we have no problems with differently ordered arrays (which have no impact) const sorted = [...value].sort((a, b) => String(a.nodeId).localeCompare(String(b.nodeId))); const sorted2 = [...value2].sort((a, b) => String(a.nodeId).localeCompare(String(b.nodeId))); for (let i = 0; i < value.length; ++i) { const aVal = sorted[i]; const bVal = sorted2[i]; if (aVal.name !== bVal.name) { info.report.addComment(`${info.position}Different names for ${key}. ${info.leftname}: ${aVal.name} vs. ${info.rightname}: ${bVal.name}`); } if (aVal.nodeId !== bVal.nodeId) { info.report.addComment(`${info.position}Different ids for ${key}. ${info.leftname}: ${aVal.nodeId} vs. ${info.rightname}: ${bVal.nodeId}`); } (0, info_1.diffControlDependencies)(aVal.controlDependencies, bVal.controlDependencies, { ...info, position: `${info.position} For ${key}. ` }); if (aVal.definedAt !== bVal.definedAt) { info.report.addComment(`${info.position}Different definition ids (definedAt) for ${key} (${aVal.nodeId}). ${info.leftname}: ${aVal.definedAt} vs. ${info.rightname}: ${bVal.definedAt}`); } if (aVal.type !== bVal.type) { info.report.addComment(`${info.position}Different types for ${key} (${aVal.nodeId}). ${info.leftname}: ${aVal.type} vs. ${info.rightname}: ${bVal.type}`); } } } } function diffEnvironment(a, b, info, depth) { if (a === undefined || b === undefined) { if (a !== b) { info.report.addComment(`${info.position}[at level: ${depth}] Different environments. ${info.leftname}: ${a !== undefined ? 'present' : 'undefined'} vs. ${info.rightname}: ${b !== undefined ? 'present' : 'undefined'}`); } return; } if (a.builtInEnv && b.builtInEnv) { return; } if (a.memory.size !== b.memory.size) { info.report.addComment(`${info.position}[at level: ${depth}] Different number of definitions in environment. ${info.leftname}: ${a.memory.size} vs. ${info.rightname}: ${b.memory.size}`); (0, diff_1.setDifference)(new Set([...a.memory.keys()]), new Set([...b.memory.keys()]), { ...info, position: `${info.position}[at level: ${depth}] Key comparison. ` }); } diffMemory(a, b, { ...info, position: `${info.position}[at level: ${depth}] ` }); diffEnvironment(a.parent, b.parent, { ...info, position: `${info.position}Parents of ${a.id} & ${b.id}. ` }, depth--); } function diffEnvironmentInformation(a, b, info) { if (a === undefined || b === undefined) { if (a !== b) { info.report.addComment(`${info.position}Different environments: ${JSON.stringify(a, environment_1.builtInEnvJsonReplacer)} vs. ${JSON.stringify(b, environment_1.builtInEnvJsonReplacer)}`); } return; } if (a.level !== b.level) { info.report.addComment(`${info.position}Different environment levels: ${info.leftname}: ${a.level} vs. ${info.rightname}: ${b.level}. Using max to report level for further errors.`); } diffEnvironment(a.current, b.current, info, Math.max(a.level, b.level)); } //# sourceMappingURL=diff.js.map