UNPKG

@informalsystems/quint

Version:

Core tool for the Quint specification language

89 lines (88 loc) 3.09 kB
/** * Compute the call graph of Quint definitions. Technically, it is a "uses" * graph, as it also captures type aliases. * * @author Igor Konnov, Informal Systems, 2023 * * Copyright 2022-2023 Informal Systems * Licensed under the Apache License, Version 2.0. * See LICENSE in the project root for license information. */ import { Map, Set } from 'immutable'; import type { RecordOf } from 'immutable'; import { IRVisitor } from '../ir/IRVisitor'; import { LookupTable } from '../names/base'; import { QuintApp, QuintDef, QuintExport, QuintImport, QuintInstance, QuintModule, QuintName } from '../ir/quintIr'; import { QuintConstType } from '../ir/quintTypes'; /** * The call graph is simply a mapping from the caller's id * to the set of callees' ids. */ export type CallGraph = Map<bigint, Set<bigint>>; type ImportKeyRecordProps = { importingModuleId: bigint; importedModuleName: string; }; type ImportKeyRecordType = RecordOf<ImportKeyRecordProps>; /** * A context that is needed for computing a call graph in the presence * of multiple modules, imports, and exports. */ export type CallGraphContext = { /** * The map from a module name to the corresponding module. */ modulesByName: Map<string, QuintModule>; /** * For every module A and the imported module name B, keep the set of * import statements that refer to B in A. The values are sets of identifiers * that refer to the import statements. */ importsByName: Map<ImportKeyRecordType, Set<bigint>>; /** * For every definition in a set of modules, map the definition id to * the module id, where it has been defined. */ definedAt: Map<bigint, QuintModule>; }; /** * Compute the context for computing the call graph. * * @param modules the modules to compute the context for */ export declare function mkCallGraphContext(modules: QuintModule[]): CallGraphContext; /** * IR visitor that computes the call graph. This class accumulates the graph in * its state. If you want to compute a new graph, create a new instance. */ export declare class CallGraphVisitor implements IRVisitor { private lookupTable; private context; private stack; private currentModuleId; /** * The call graph computed by the visitor. */ private _graph; constructor(lookupTable: LookupTable, context: CallGraphContext); get graph(): CallGraph; /** * Print the graph in the graphviz dot format. Use it for debugging purposes, * e.g., print(console.log) */ print(out: (s: string) => void): void; enterModule(module: QuintModule): void; enterDef(def: QuintDef): void; exitDef(_def: QuintDef): void; enterImport(decl: QuintImport): void; enterInstance(decl: QuintInstance): void; exitInstance(_decl: QuintInstance): void; enterExport(decl: QuintExport): void; exitApp(app: QuintApp): void; exitName(name: QuintName): void; exitConstType(tp: QuintConstType): void; private graphAddOne; private graphAddImports; private graphAddAll; } export {};