This adds a few utilities in preparation for the print benchmark utility, which will replace our own dumping infrastructure.
return d_constructors;
}
+std::unordered_set<TypeNode> DType::getSubfieldTypes() const
+{
+ std::unordered_set<TypeNode> subFieldTypes;
+ for (std::shared_ptr<DTypeConstructor> ctor : d_constructors)
+ {
+ for (size_t i = 0, nargs = ctor->getNumArgs(); i < nargs; i++)
+ {
+ subFieldTypes.insert(ctor->getArgType(i));
+ }
+ }
+ return subFieldTypes;
+}
+
std::ostream& operator<<(std::ostream& os, const DType& dt)
{
// can only output datatypes in the cvc5 native language
const std::vector<std::shared_ptr<DTypeConstructor> >& getConstructors()
const;
+ /**
+ * Return the subfield types of this datatype. This is the set of all types T
+ * for which there exists an argument to a constructor of type T.
+ */
+ std::unordered_set<TypeNode> getSubfieldTypes() const;
+
/** prints this datatype to stream */
void toStream(std::ostream& out) const;
printUnknownCommand(out, "declare-fun");
}
+void Printer::toStreamCmdDeclareFunction(std::ostream& out, const Node& v) const
+{
+ std::stringstream vs;
+ vs << v;
+ toStreamCmdDeclareFunction(out, vs.str(), v.getType());
+}
+
void Printer::toStreamCmdDeclarePool(std::ostream& out,
const std::string& id,
TypeNode type,
printUnknownCommand(out, "define-fun");
}
+void Printer::toStreamCmdDefineFunction(std::ostream& out,
+ Node v,
+ Node lambda) const
+{
+ std::stringstream vs;
+ vs << v;
+ std::vector<Node> formals;
+ Node body = lambda;
+ TypeNode rangeType = v.getType();
+ if (body.getKind() == kind::LAMBDA)
+ {
+ formals.insert(formals.end(), lambda[0].begin(), lambda[0].end());
+ body = lambda[1];
+ Assert(rangeType.isFunction());
+ rangeType = rangeType.getRangeType();
+ }
+ toStreamCmdDefineFunction(out, vs.str(), formals, rangeType, body);
+}
+
void Printer::toStreamCmdDefineFunctionRec(
std::ostream& out,
const std::vector<Node>& funcs,
printUnknownCommand(out, "define-fun-rec");
}
+void Printer::toStreamCmdDefineFunctionRec(
+ std::ostream& out,
+ const std::vector<Node>& funcs,
+ const std::vector<Node>& lambdas) const
+{
+ std::vector<std::vector<Node>> formals;
+ std::vector<Node> formulas;
+ for (const Node& l : lambdas)
+ {
+ std::vector<Node> formalsVec;
+ Node formula;
+ if (l.getKind() == kind::LAMBDA)
+ {
+ formalsVec.insert(formalsVec.end(), l[0].begin(), l[0].end());
+ formula = l[1];
+ }
+ else
+ {
+ formula = l;
+ }
+ formals.emplace_back(formalsVec);
+ formulas.emplace_back(formula);
+ }
+ toStreamCmdDefineFunctionRec(out, funcs, formals, formulas);
+}
+
void Printer::toStreamCmdSetUserAttribute(std::ostream& out,
const std::string& attr,
Node n) const
virtual void toStreamCmdDeclareFunction(std::ostream& out,
const std::string& id,
TypeNode type) const;
+ /** Variant of above for a pre-existing variable */
+ void toStreamCmdDeclareFunction(std::ostream& out, const Node& v) const;
/** Print declare-pool command */
virtual void toStreamCmdDeclarePool(std::ostream& out,
const std::string& id,
const std::vector<Node>& formals,
TypeNode range,
Node formula) const;
+ /** Variant of above that takes the definition */
+ void toStreamCmdDefineFunction(std::ostream& out, Node v, Node lambda) const;
/** Print define-fun-rec command */
virtual void toStreamCmdDefineFunctionRec(
const std::vector<Node>& funcs,
const std::vector<std::vector<Node>>& formals,
const std::vector<Node>& formulas) const;
+ /** Variant of above that takes the definition */
+ void toStreamCmdDefineFunctionRec(std::ostream& out,
+ const std::vector<Node>& funcs,
+ const std::vector<Node>& lambdas) const;
/** Print set-user-attribute command */
void toStreamCmdSetUserAttribute(std::ostream& out,
size_t dag,
Language language) const
{
- Printer::getPrinter(language)->toStreamCmdDeclareFunction(
- out, d_func.toString(), sortToTypeNode(d_sort));
+ Printer::getPrinter(language)->toStreamCmdDeclareFunction(out,
+ termToNode(d_func));
}
/* -------------------------------------------------------------------------- */