|
12 | 12 | import static org.sosy_lab.common.collect.Collections3.transformedImmutableSetCopy; |
13 | 13 |
|
14 | 14 | import com.google.common.base.Preconditions; |
15 | | -import com.google.common.collect.HashBasedTable; |
16 | 15 | import com.google.common.collect.ImmutableList; |
17 | 16 | import com.google.common.collect.Table; |
| 17 | +import com.google.common.collect.TreeBasedTable; |
18 | 18 | import java.math.BigInteger; |
19 | 19 | import java.util.ArrayDeque; |
20 | 20 | import java.util.ArrayList; |
21 | 21 | import java.util.Collection; |
| 22 | +import java.util.Comparator; |
22 | 23 | import java.util.Deque; |
23 | 24 | import java.util.HashMap; |
24 | 25 | import java.util.Iterator; |
|
59 | 60 | public class BitwuzlaFormulaCreator extends FormulaCreator<Term, Sort, Void, BitwuzlaDeclaration> { |
60 | 61 | private final TermManager termManager; |
61 | 62 |
|
62 | | - private final Table<String, Sort, Term> formulaCache = HashBasedTable.create(); |
| 63 | + /** |
| 64 | + * Returns the symbol name without any SMTLIB quotes. |
| 65 | + * |
| 66 | + * <p>Will turn <code>| 1var\n|</code> into just <code> 1 var\n</code>. Symbols that are not |
| 67 | + * quoted are unaffected. |
| 68 | + */ |
| 69 | + private String removeQuotes(String symbol) { |
| 70 | + return (symbol.startsWith("|") && symbol.endsWith("|")) |
| 71 | + ? symbol.substring(1, symbol.length() - 1) |
| 72 | + : symbol; |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Stores Bitwuzla terms for all defined symbols. |
| 77 | + * |
| 78 | + * <p>The cache maps from <code>String x Sort</code> to <code>Term</code>. Here the first argument |
| 79 | + * is the name of the symbol, and we allow polymorphic symbols where the same name can have more |
| 80 | + * than one sort. If the symbol can be printed as a simple symbol or a quoted symbol (like <code> |
| 81 | + * var1</code> and <code>|var1|</code>) in SMTLIB we identify both version as they refer to the |
| 82 | + * same variable. |
| 83 | + */ |
| 84 | + private final Table<String, Sort, Term> formulaCache = |
| 85 | + TreeBasedTable.create( |
| 86 | + (String symA, String symB) -> removeQuotes(symA).compareTo(removeQuotes(symB)), |
| 87 | + Comparator.comparing(Sort::toString)); |
63 | 88 |
|
64 | 89 | /** |
65 | 90 | * This mapping stores symbols and their constraints, such as from fp-to-bv casts with their |
|
0 commit comments