UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

83 lines 3.18 kB
"use strict"; /* ---------------------------------------------------------------------------------- * Copyright 2023 Informal Systems * Licensed under the Apache License, Version 2.0. * See LICENSE in the project root for license information. * --------------------------------------------------------------------------------- */ Object.defineProperty(exports, "__esModule", { value: true }); exports.generateFreshIds = void 0; /** * Generation of fresh ids for IR components. This is used to generate fresh ids for * modules generate from instances, enabling them to assume different values in evaluation. * * @author Gabriela Moreira * * @module */ const IRTransformer_1 = require("./IRTransformer"); /** * Given a QuintDef, generates fresh IDs for all its components using the * provided IdGenerator. Returns a new QuintDef with the updated IDs. Also extends * the provided source map and analysis output, such that they contain the respective * entries under both their old and new IDs. * * @param def - The QuintDef to update with fresh IDs. * @param idGenerator - The IdGenerator to use for generating fresh IDs. * @param sourceMap - A source map to be updated with sources for the new ids * (should contain entries for the existing ids) * @param analysisOutput - An analysis output to be updated with analysis for the new ids * (should contain entries for the existing ids) * @returns A new QuintDef with fresh IDs. */ function generateFreshIds(def, idGenerator, sourceMap, analysisOutput) { const transformer = new IdRefresher(idGenerator, sourceMap, analysisOutput); return (0, IRTransformer_1.transformDefinition)(transformer, def); } exports.generateFreshIds = generateFreshIds; class IdRefresher { constructor(idGenerator, sourceMap, analysisOutput) { this.idGenerator = idGenerator; this.sourceMap = sourceMap; this.analysisOutput = analysisOutput; } /* New ID generation */ enterDef(def) { return { ...def, id: this.getNewIdWithSameData(def.id) }; } enterLambda(expr) { return { ...expr, params: expr.params.map(p => ({ ...p, id: this.getNewIdWithSameData(p.id) })), }; } enterExpr(expr) { return { ...expr, id: this.getNewIdWithSameData(expr.id) }; } enterType(type) { if (!type.id) { return type; } return { ...type, id: this.getNewIdWithSameData(type.id) }; } getNewIdWithSameData(id) { const newId = this.idGenerator.nextId(); const type = this.analysisOutput.types.get(id); const effect = this.analysisOutput.effects.get(id); const mode = this.analysisOutput.modes.get(id); const source = this.sourceMap.get(id); if (type) { this.analysisOutput.types.set(newId, type); } if (effect) { this.analysisOutput.effects.set(newId, effect); } if (mode) { this.analysisOutput.modes.set(newId, mode); } if (source) { this.sourceMap.set(newId, source); } return newId; } } //# sourceMappingURL=idRefresher.js.map