Gets the correct `NodeManagerScope` for getting the `toString` of a term, op, or sort. The following program had strange output:
```
#include "cvc4/api/cvc4cpp.h"
using namespace CVC4::api;
using namespace std;
int main()
{
Solver s;
Term x = s.mkConst(s.getIntegerSort(), "x");
cout << "x = " << x << endl;
Solver s2;
cout << "x = " << x << endl;
return 0;
}
```
It was outputting:
```
x = x
x = var_267
```
Fixing the scope makes the output `x = x` both times, as expected.
.toType());
}
-std::string Sort::toString() const { return d_type->toString(); }
+std::string Sort::toString() const
+{
+ if (d_solver != nullptr)
+ {
+ NodeManagerScope scope(d_solver->getNodeManager());
+ return d_type->toString();
+ }
+ return d_type->toString();
+}
// !!! This is only temporarily available until the parser is fully migrated
// to the new API. !!!
{
CVC4_API_CHECK(!d_node->isNull())
<< "Expecting a non-null internal expression";
+ if (d_solver != nullptr)
+ {
+ NodeManagerScope scope(d_solver->getNodeManager());
+ return d_node->toString();
+ }
return d_node->toString();
}
}
}
}
-std::string Term::toString() const { return d_node->toString(); }
+std::string Term::toString() const
+{
+ if (d_solver != nullptr)
+ {
+ NodeManagerScope scope(d_solver->getNodeManager());
+ return d_node->toString();
+ }
+ return d_node->toString();
+}
Term::const_iterator::const_iterator()
: d_solver(nullptr), d_origNode(nullptr), d_pos(0)
void testGetIndicesUint();
void testGetIndicesPairUint();
+ void testOpScopingToString();
+
private:
Solver d_solver;
};
TS_ASSERT_THROWS(floatingpoint_to_fp_generic_ot.getIndices<std::string>(),
CVC4ApiException&);
}
+
+void OpBlack::testOpScopingToString()
+{
+ Op bitvector_repeat_ot = d_solver.mkOp(BITVECTOR_REPEAT, 5);
+ std::string op_repr = bitvector_repeat_ot.toString();
+ Solver solver2;
+ TS_ASSERT_EQUALS(bitvector_repeat_ot.toString(), op_repr);
+}
void testSortCompare();
void testSortSubtyping();
+ void testSortScopedToString();
+
private:
Solver d_solver;
};
TS_ASSERT(!setSortR.isComparableTo(setSortI));
TS_ASSERT(!setSortR.isSubsortOf(setSortI));
}
+
+void SortBlack::testSortScopedToString()
+{
+ std::string name = "uninterp-sort";
+ Sort bvsort8 = d_solver.mkBitVectorSort(8);
+ Sort uninterp_sort = d_solver.mkUninterpretedSort(name);
+ TS_ASSERT_EQUALS(bvsort8.toString(), "(_ BitVec 8)");
+ TS_ASSERT_EQUALS(uninterp_sort.toString(), name);
+ Solver solver2;
+ TS_ASSERT_EQUALS(bvsort8.toString(), "(_ BitVec 8)");
+ TS_ASSERT_EQUALS(uninterp_sort.toString(), name);
+}
void testConstArray();
void testConstSequenceElements();
+ void testTermScopedToString();
+
private:
Solver d_solver;
};
Term su = d_solver.mkTerm(SEQ_UNIT, d_solver.mkReal(1));
TS_ASSERT_THROWS(su.getConstSequenceElements(), CVC4ApiException&);
}
+
+void TermBlack::testTermScopedToString()
+{
+ Sort intsort = d_solver.getIntegerSort();
+ Term x = d_solver.mkConst(intsort, "x");
+ TS_ASSERT_EQUALS(x.toString(), "x");
+ Solver solver2;
+ TS_ASSERT_EQUALS(x.toString(), "x");
+}