@informalsystems/quint
Version:
Core tool for the Quint specification language
151 lines • 3.35 kB
JavaScript
;
/*
* Intermediate representation of Quint. It almost mirrors the IR of Apalache,
* which assumes that module instances are flattened. Quint extends the Apalache IR
* by supporting hierarchical modules and instances.
*
* Igor Konnov, Gabriela Moreira, Shon Feder, 2021-2023
*
* Copyright 2021-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.qualifier = exports.isDef = exports.isAnnotatedDef = exports.isTypeAlias = exports.builtinOpCodes = exports.isQuintBuiltin = void 0;
/** A type guard to narrow the type of a `QuintApp` to a `QuintBuiltinApp`
*
* See https://stackoverflow.com/a/61129291
*/
function isQuintBuiltin(app) {
return exports.builtinOpCodes.includes(app.opcode);
}
exports.isQuintBuiltin = isQuintBuiltin;
// This should be the source of truth for all builtin opcodes
exports.builtinOpCodes = [
'List',
'Map',
'Rec',
'Set',
'Tup',
'actionAll',
'actionAny',
'allLists',
'allListsUpTo',
'always',
'and',
'append',
'assert',
'expect',
'assign',
'chooseSome',
'concat',
'contains',
'enabled',
'eq',
'eventually',
'exclude',
'exists',
'fail',
'field',
'fieldNames',
'filter',
'flatten',
'fold',
'foldl',
'foldr',
'forall',
'get',
'head',
'iadd',
'idiv',
'iff',
'igt',
'igte',
'ilt',
'ilte',
'imod',
'implies',
'imul',
'in',
'indices',
'intersect',
'ipow',
'isFinite',
'isub',
'ite',
'item',
'iuminus',
'keys',
'length',
'map',
'mapBy',
'matchVariant',
'mustChange',
'neq',
'next',
'not',
'nth',
'oneOf',
'or',
'orKeep',
'powerset',
'put',
'q::test',
'q::testOnce',
'q::debug',
'range',
'replaceAt',
'reps',
'select',
'set',
'setBy',
'setOfMaps',
'setToMap',
'size',
'slice',
'strongFair',
'subseteq',
'tail',
'then',
'to',
'tuples',
'union',
'variant',
'weakFair',
'with',
];
function isTypeAlias(def) {
return def.kind === 'typedef' && def.type;
}
exports.isTypeAlias = isTypeAlias;
/**
* Checks if a definition has a type annotation.
*
* @param def The definition to check.
*
* @returns True if the definition has a type annotation, false otherwise.
*/
function isAnnotatedDef(def) {
return def.typeAnnotation !== undefined;
}
exports.isAnnotatedDef = isAnnotatedDef;
/**
* Checks if a Declaration is a QuintDef, that is, it is not an import, an export, or an instance.
* Useful because all QuintDefs have a `name` field, so we can use this to narrow the type.
*
* @param decl The Declaration to check.
*
* @returns True if the Declaration is a QuintDef, false otherwise.
*/
function isDef(decl) {
return decl.kind !== 'instance' && decl.kind !== 'import' && decl.kind !== 'export';
}
exports.isDef = isDef;
function qualifier(decl) {
if (decl.kind === 'instance') {
return decl.qualifiedName;
}
return decl.defName ? undefined : decl.qualifiedName ?? decl.protoName;
}
exports.qualifier = qualifier;
//# sourceMappingURL=quintIr.js.map