UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

115 lines 3.54 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.findParameterWithId = exports.findDefinitionWithId = exports.findTypeWithId = exports.findExpressionWithId = void 0; /** * Finding expressions in a list of modules * * @author Gabriela Moreira * * @module */ const IRVisitor_1 = require("./IRVisitor"); /** * Finds a quint expression with a given id in a list of modules * * @param modules the modules in which to search for the expression * @param id the id to be searched for * * @returns a quint expression with the given id, or undefined if no expression is found */ function findExpressionWithId(modules, id) { const visitor = new IRExpressionFinder(id); modules.forEach(module => (0, IRVisitor_1.walkModule)(visitor, module)); return visitor.expression; } exports.findExpressionWithId = findExpressionWithId; /** * Finds a quint type with a given id in a list of modules * * @param modules the modules in which to search for the type * @param id the id to be searched for * * @returns a quint type with the given id, or undefined if no type is found */ function findTypeWithId(modules, id) { const visitor = new IRTypeFinder(id); modules.forEach(module => (0, IRVisitor_1.walkModule)(visitor, module)); return visitor.type; } exports.findTypeWithId = findTypeWithId; /** * Finds a quint definition with a given id in a list of modules * * @param modules the modules in which to search for the definition * @param id the id to be searched for * * @returns a quint definition with the given id, or undefined if no expression is found */ function findDefinitionWithId(modules, id) { const visitor = new IRDefinitionFinder(id); modules.forEach(module => (0, IRVisitor_1.walkModule)(visitor, module)); return visitor.def; } exports.findDefinitionWithId = findDefinitionWithId; /** * Find a quint parameter with a given id in a list of modules * * @param modules the modules in which to search for the parameter * @param id the id to be searched for * * @returns a quint lambda parameter with the given id, or undefined if no parameter is found */ function findParameterWithId(modules, id) { const visitor = new IRParameterFinder(id); modules.forEach(module => (0, IRVisitor_1.walkModule)(visitor, module)); return visitor.param; } exports.findParameterWithId = findParameterWithId; class IRExpressionFinder { constructor(id) { this.id = id; } exitExpr(expr) { if (expr.id === this.id) { this.expression = expr; } } } class IRTypeFinder { constructor(id) { this.id = id; } exitType(type) { if (type.id === this.id) { this.type = type; } } } class IRDefinitionFinder { constructor(id) { this.id = id; } exitDef(def) { if (def.id === this.id) { this.def = def; } } } class IRParameterFinder { constructor(id) { this.id = id; } exitLambda(lambda) { lambda.params.forEach(param => { if (param.id == this.id) { this.param = param; } }); } } //# sourceMappingURL=IRFinder.js.map