001package org.clafer.ig; 002 003import java.util.List; 004import java.util.function.UnaryOperator; 005 006/** 007 * A solver of a model behind the solution loop ({@link Repl}): Choco for a 008 * static model, whose solutions are instances, and Alloy for a temporal 009 * model, whose solutions are traces. The loop keeps the solutions shown and 010 * their views; the backend solves, and handles its own commands with its own 011 * messages. 012 */ 013public interface Backend { 014 015 /** 016 * A solution as it is shown, with Alloy's XML of it, if any. 017 */ 018 record Shown(Solution solution, String xml) { 019 } 020 021 /** 022 * @return whether the model is temporal: its solutions are traces 023 */ 024 boolean isDynamic(); 025 026 /** 027 * @return the prompt of the loop 028 */ 029 String prompt(); 030 031 /** 032 * @return the help of the loop's commands 033 */ 034 String help(); 035 036 /** 037 * Prints what comes before the first solution, which the loop then asks 038 * for. 039 */ 040 void start(Repl.Io io) throws Exception; 041 042 /** 043 * The next solution, or null once the backend has said why there is none. 044 */ 045 Shown next(Repl.Io io) throws Exception; 046 047 /** 048 * {@code fork}: another trace with the states of the last trace before 049 * the given state, or null once the backend has said why there is none. 050 */ 051 Shown fork(Repl.Io io, int state) throws Exception; 052 053 /** 054 * {@code config}: a solution with another configuration, or null once the 055 * backend has said why there is none. 056 */ 057 Shown nextConfiguration(Repl.Io io) throws Exception; 058 059 /** 060 * {@code check}: checks the assertions (on the line, if positive), and 061 * shows each counterexample with the loop. 062 */ 063 void check(Repl.Io io, Integer line, Repl.Displayer display) throws Exception; 064 065 /** 066 * Handles a command of the backend's own. 067 * 068 * @param words the command and its arguments 069 * @return whether it is one 070 */ 071 boolean command(Repl.Io io, String input, List<String> words, Repl.Context context) throws Exception; 072 073 /** 074 * Says that the input is no command. 075 */ 076 void unknown(Repl.Io io, String input); 077 078 /** 079 * @return the number of the next solution shown 080 */ 081 int number(Repl.Context context); 082 083 /** 084 * The full view of the n-th solution, as the backend prints it. 085 */ 086 String show(int n, Shown shown); 087 088 /** 089 * @return the least-partially-qualified name of a clafer by its UID, for 090 * the diff view 091 */ 092 UnaryOperator<String> names(); 093 094 /** 095 * @return the name of the model's file, which names the saved files 096 */ 097 String modelFileName(); 098 099 /** 100 * Releases the solver. 101 */ 102 void quit(); 103}