UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

61 lines 1.83 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.simplifyRow = exports.simplify = void 0; /** * Simplification for quint types * * @author Gabriela Moreira * * @module */ const IRTransformer_1 = require("../ir/IRTransformer"); /** * Simplifies a type scheme by flattening all type rows. * * A row like `{ a: int | { b: bool | r } }` becomes * `{ a: int, b: bool | r }`. * * @param typeScheme - The type scheme to be simplified * * @returns The simplified type scheme */ function simplify(typeScheme) { const simplifier = new RowSimplifier(); return { ...typeScheme, type: (0, IRTransformer_1.transformType)(simplifier, typeScheme.type) }; } exports.simplify = simplify; /** * Simplifies a row type. * * A row like `{ a: int | { b: bool | r } }` becomes * `{ a: int, b: bool | r }`. * * @param row - The row to be simplified * * @returns The simplified row */ function simplifyRow(row) { const simplifier = new RowSimplifier(); return (0, IRTransformer_1.transformRow)(simplifier, row); } exports.simplifyRow = simplifyRow; class RowSimplifier { exitRow(row) { if (row.kind !== 'row') { return row; } if (row.fields.length === 0) { return row.other; } if (row.other.kind !== 'row') { return row; } return { ...row, fields: row.fields.concat(row.other.fields), other: row.other.other }; } } //# sourceMappingURL=simplification.js.map