@informalsystems/quint
Version:
Core tool for the Quint specification language
177 lines • 4.39 kB
JavaScript
;
/* ----------------------------------------------------------------------------------
* Copyright 2022-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.builtinNames = exports.addNamespacesToDef = exports.copyNames = exports.getTopLevelDef = void 0;
/**
* Type definitions and utilities for Quint name resolution.
*
* @author Gabriela Moreira
*
* @module
*/
const lodash_1 = require("lodash");
function getTopLevelDef(defs, name) {
return defs.get(name)?.at(0);
}
exports.getTopLevelDef = getTopLevelDef;
/**
* Copy the names of a definitions table to a new one, ignoring hidden
* definitions, and optionally adding a namespace.
*
* @param originTable - The definitions table to copy from
* @param namespace - Optional namespace to be added to copied names
* @param copyAsHidden - Optional, true iff the copied definitions should be tagged as 'hidden'
*
* @returns a definitions table with the filtered and namespaced names
*/
function copyNames(originTable, namespace, copyAsHidden) {
const table = new Map();
originTable.forEach((defs, identifier) => {
const name = namespace ? [namespace, identifier].join('::') : identifier;
const newDefs = defs.map(def => {
if (!def.hidden || def.kind === 'const') {
return (0, lodash_1.cloneDeep)(copyAsHidden ? { ...def, hidden: copyAsHidden } : def);
}
});
table.set(name, (0, lodash_1.compact)(newDefs));
});
return table;
}
exports.copyNames = copyNames;
/**
* Add namespaces to a definition's `namespaces` field, if it doesn't already
* have them on the last position or in the beginning of its name.
*
* @param def - The definition to add the namespaces to
* @param namespaces - The namespaces to be added
*
* @returns The definition with the namespaces added
*/
function addNamespacesToDef(def, namespaces) {
// FIXME(#1111): This doesn't take care of some corner cases.
return namespaces.reduce((def, namespace) => {
if (def.namespaces && def.namespaces[def.namespaces?.length - 1] === namespace) {
// If this is already the last namespace, don't add it again
return def;
}
if (def.name.startsWith(`${namespace}::`)) {
// If the namespace is already in the beginning of the name, don't add it again
return def;
}
const namespaces = namespace ? def.namespaces?.concat([namespace]) ?? [namespace] : [];
return { ...def, namespaces };
}, def);
}
exports.addNamespacesToDef = addNamespacesToDef;
/**
* Built-in name definitions that are always resolved and generate conflicts if collected.
*/
exports.builtinNames = [
'not',
'and',
'or',
'iff',
'implies',
'exists',
'forall',
'in',
'union',
'contains',
'fold',
'intersect',
'exclude',
'subseteq',
'map',
'applyTo',
'filter',
'powerset',
'flatten',
'allLists',
'allListsUpTo',
'getOnlyElement',
'chooseSome',
'apalache::generate',
'oneOf',
'isFinite',
'size',
'get',
'put',
'keys',
'mapBy',
'setToMap',
'setOfMaps',
'set',
'setBy',
'fields',
'with',
'tuples',
'append',
'concat',
'head',
'tail',
'length',
'nth',
'indices',
'replaceAt',
'slice',
'select',
'foldl',
'foldr',
'to',
'always',
'eventually',
'next',
'then',
'expect',
'reps',
'fail',
'assert',
'orKeep',
'mustChange',
'enabled',
'weakFair',
'strongFair',
'Bool',
'Int',
'Nat',
'Set',
'Map',
'List',
'Tup',
'Rec',
'range',
'igt',
'ilt',
'igte',
'ilte',
'iadd',
'isub',
'iuminus',
'imul',
'idiv',
'imod',
'ipow',
'actionAll',
'actionAny',
'field',
'fieldNames',
'item',
'assign',
'of',
'eq',
'neq',
'ite',
'cross',
'difference',
'matchVariant',
'variant',
'q::debug',
'q::lastTrace',
'q::test',
'q::testOnce',
];
//# sourceMappingURL=base.js.map