5656public class BitwuzlaFormulaCreator extends FormulaCreator <Term , Sort , Void , BitwuzlaDeclaration > {
5757 private final TermManager termManager ;
5858
59+ /**
60+ * Variable cache, contains terms for all declared symbols
61+ *
62+ * <p>Bitwuzla allows the variables to be declared multiple times. Each of these instances will be
63+ * considered a separate variable, even if the names and types are the same. We fix this by
64+ * keeping track of all declared variables in this cache. If a variable is already defined we
65+ * return it from the cache, otherwise a new Term for the variable is created and added to the
66+ * cache.
67+ *
68+ * <p>It is important to keep this cache synchronized with the variable declarations for the
69+ * parser. This is handled in {@link BitwuzlaFormulaManager#parse(String)}.
70+ */
5971 private final Table <String , Sort , Term > formulaCache = HashBasedTable .create ();
6072
73+ /**
74+ * Remove SMTLIB quotes from a symbol name.
75+ *
76+ * <p>If the symbol is not quoted, just return it as is .
77+ */
78+ static String removeQuotes (String pSymbol ) {
79+ if (pSymbol .startsWith ("|" ) && pSymbol .endsWith ("|" )) {
80+ return pSymbol .substring (1 , pSymbol .length () - 1 );
81+ }
82+ return pSymbol ;
83+ }
84+
6185 /**
6286 * This mapping stores symbols and their constraints, such as from fp-to-bv casts with their
6387 * defining equation.
@@ -401,7 +425,7 @@ public <R> R visit(FormulaVisitor<R> visitor, Formula formula, Term f)
401425 return visitor .visitFreeVariable (formula , name );
402426
403427 } else if (f .is_variable ()) {
404- String name = f .symbol ();
428+ String name = removeQuotes ( f .symbol () );
405429 Sort sort = f .sort ();
406430 Term originalVar = formulaCache .get (name , sort );
407431 return visitor .visitBoundVariable (encapsulate (getFormulaType (originalVar ), originalVar ), 0 );
@@ -419,7 +443,7 @@ public <R> R visit(FormulaVisitor<R> visitor, Formula formula, Term f)
419443 for (int i = 0 ; i < size - 1 ; i ++) {
420444 Term boundVar = children .get (i );
421445 boundVars [i ] = boundVar ;
422- String name = boundVar .symbol ();
446+ String name = removeQuotes ( boundVar .symbol () );
423447 assert name != null ;
424448 Sort sort = boundVar .sort ();
425449 Term freeVar ;
0 commit comments