The new API does not use inheritence for Sorts. The current DatatypeDeclarationCommand uses DatatypeType, which inherits from Type. This commit simplifies the class DatatypeType -> Type and updates the necessary code (e.g. in the printers). Notice we are not yet converting commands Type -> Sort here.
It also makes the main call for constructing datatypes in the parser from DatatypeType -> api::Sort.
This is in preparation for converting Expr-level Datatype to Term-level DatatypeDecl in the parsers.
END_TOK
{ PARSER_STATE->popScope();
cmd->reset(new DatatypeDeclarationCommand(
- PARSER_STATE->mkMutualDatatypeTypes(dts)));
+ api::sortVectorToTypes(PARSER_STATE->mkMutualDatatypeTypes(dts))));
}
| CONTEXT_TOK
return d_unresolved.find(getSort(name)) != d_unresolved.end();
}
-std::vector<DatatypeType> Parser::mkMutualDatatypeTypes(
+std::vector<api::Sort> Parser::mkMutualDatatypeTypes(
std::vector<Datatype>& datatypes, bool doOverload, uint32_t flags)
{
try {
throw ParserException(dt.getName() + " is not well-founded");
}
}
- std::vector<DatatypeType> retTypes;
- for (unsigned i = 0, ntypes = types.size(); i < ntypes; i++)
- {
- retTypes.push_back(DatatypeType(types[i].getType()));
- }
- return retTypes;
+ return types;
} catch (IllegalArgumentException& ie) {
throw ParserException(ie.getMessage());
}
* printed out as a definition in models or not
* (see enum in expr_manager_template.h).
*/
- std::vector<DatatypeType> mkMutualDatatypeTypes(
+ std::vector<api::Sort> mkMutualDatatypeTypes(
std::vector<Datatype>& datatypes,
bool doOverload = false,
uint32_t flags = ExprManager::DATATYPE_FLAG_NONE);
Debug("parser-sygus") << " " << i << " : " << datatypes[i].getName()
<< std::endl;
}
- std::vector<DatatypeType> datatypeTypes =
+ std::vector<api::Sort> datatypeTypes =
PARSER_STATE->mkMutualDatatypeTypes(
datatypes, false, ExprManager::DATATYPE_FLAG_PLACEHOLDER);
ret = datatypeTypes[0];
datatypes, utypes,
ExprManager::DATATYPE_FLAG_PLACEHOLDER);
// return is the first datatype
- ret = datatypeTypes[0];
+ ret = api::Sort(datatypeTypes[0]);
}
;
RPAREN_TOK
LPAREN_TOK ( LPAREN_TOK datatypeDef[isCo, dts, sorts] RPAREN_TOK )+ RPAREN_TOK
{ PARSER_STATE->popScope();
- cmd->reset(new DatatypeDeclarationCommand(PARSER_STATE->mkMutualDatatypeTypes(dts, true)));
+ cmd->reset(new DatatypeDeclarationCommand(
+ api::sortVectorToTypes(PARSER_STATE->mkMutualDatatypeTypes(dts, true))));
}
;
)+
{
PARSER_STATE->popScope();
- cmd->reset(new DatatypeDeclarationCommand(PARSER_STATE->mkMutualDatatypeTypes(dts, true)));
+ cmd->reset(new DatatypeDeclarationCommand(
+ api::sortVectorToTypes(PARSER_STATE->mkMutualDatatypeTypes(dts, true))));
}
;
static void toStream(std::ostream& out, const DatatypeDeclarationCommand* c)
{
- const vector<DatatypeType>& datatypes = c->getDatatypes();
+ const vector<Type>& datatypes = c->getDatatypes();
out << "DatatypeDeclarationCommand([";
- for(vector<DatatypeType>::const_iterator i = datatypes.begin(),
- i_end = datatypes.end();
- i != i_end;
- ++i) {
- out << *i << ";" << endl;
+ for (const Type& t : datatypes)
+ {
+ out << t << ";" << endl;
}
out << "])";
}
const DatatypeDeclarationCommand* c,
bool cvc3Mode)
{
- const vector<DatatypeType>& datatypes = c->getDatatypes();
+ const vector<Type>& datatypes = c->getDatatypes();
+ Assert(!datatypes.empty() && datatypes[0].isDatatype());
+ const Datatype& dt0 = DatatypeType(datatypes[0]).getDatatype();
//do not print tuple/datatype internal declarations
- if( datatypes.size()!=1 || ( !datatypes[0].getDatatype().isTuple() && !datatypes[0].getDatatype().isRecord() ) ){
+ if (datatypes.size() != 1 || (!dt0.isTuple() && !dt0.isRecord()))
+ {
out << "DATATYPE" << endl;
bool firstDatatype = true;
- for(vector<DatatypeType>::const_iterator i = datatypes.begin(),
- i_end = datatypes.end();
- i != i_end;
- ++i) {
+ for (const Type& t : datatypes)
+ {
if(! firstDatatype) {
out << ',' << endl;
}
- const Datatype& dt = (*i).getDatatype();
+ const Datatype& dt = DatatypeType(t).getDatatype();
out << " " << dt.getName();
if(dt.isParametric()) {
out << '[';
}
firstSelector = false;
const DatatypeConstructorArg& selector = *k;
- Type t = SelectorType(selector.getType()).getRangeType();
- if( t.isDatatype() ){
- const Datatype & sdt = ((DatatypeType)t).getDatatype();
+ Type tr = SelectorType(selector.getType()).getRangeType();
+ if (tr.isDatatype())
+ {
+ const Datatype& sdt = DatatypeType(tr).getDatatype();
out << selector.getName() << ": " << sdt.getName();
- }else{
- out << selector.getName() << ": " << t;
+ }
+ else
+ {
+ out << selector.getName() << ": " << tr;
}
}
out << ')';
const DatatypeDeclarationCommand* c,
Variant v)
{
- const vector<DatatypeType>& datatypes = c->getDatatypes();
+ const std::vector<Type>& datatypes = c->getDatatypes();
Assert(!datatypes.empty());
- if (datatypes[0].getDatatype().isTuple())
+ Assert(datatypes[0].isDatatype());
+ DatatypeType dt0 = DatatypeType(datatypes[0]);
+ const Datatype& d0 = dt0.getDatatype();
+ if (d0.isTuple())
{
// not necessary to print tuples
Assert(datatypes.size() == 1);
return;
}
out << "(declare-";
- if (datatypes[0].getDatatype().isCodatatype())
+ if (d0.isCodatatype())
{
out << "co";
}
if (isVariant_2_6(v))
{
out << " (";
- for (vector<DatatypeType>::const_iterator i = datatypes.begin(),
- i_end = datatypes.end();
- i != i_end;
- ++i)
+ for (const Type& t : datatypes)
{
- const Datatype& d = i->getDatatype();
+ Assert(t.isDatatype());
+ const Datatype& d = DatatypeType(t).getDatatype();
out << "(" << CVC4::quoteSymbol(d.getName());
out << " " << d.getNumParameters() << ")";
}
out << ") (";
- for (vector<DatatypeType>::const_iterator i = datatypes.begin(),
- i_end = datatypes.end();
- i != i_end;
- ++i)
+ for (const Type& t : datatypes)
{
- const Datatype& d = i->getDatatype();
+ Assert(t.isDatatype());
+ const Datatype& d = DatatypeType(t).getDatatype();
if (d.isParametric())
{
out << "(par (";
// be impossible to print a datatype block where datatypes were given
// different parameter lists.
bool success = true;
- const Datatype& d = datatypes[0].getDatatype();
- unsigned nparam = d.getNumParameters();
+ unsigned nparam = d0.getNumParameters();
for (unsigned j = 1, ndt = datatypes.size(); j < ndt; j++)
{
- const Datatype& dj = datatypes[j].getDatatype();
+ Assert(datatypes[j].isDatatype());
+ const Datatype& dj = DatatypeType(datatypes[j]).getDatatype();
if (dj.getNumParameters() != nparam)
{
success = false;
// must also have identical parameter lists
for (unsigned k = 0; k < nparam; k++)
{
- if (dj.getParameter(k) != d.getParameter(k))
+ if (dj.getParameter(k) != d0.getParameter(k))
{
success = false;
break;
{
for (unsigned j = 0; j < nparam; j++)
{
- out << (j > 0 ? " " : "") << d.getParameter(j);
+ out << (j > 0 ? " " : "") << d0.getParameter(j);
}
}
else
out << std::endl;
}
out << ") (";
- for (vector<DatatypeType>::const_iterator i = datatypes.begin(),
- i_end = datatypes.end();
- i != i_end;
- ++i)
+ for (const Type& t : datatypes)
{
- const Datatype& dt = i->getDatatype();
+ Assert(t.isDatatype());
+ const Datatype& dt = DatatypeType(t).getDatatype();
out << "(" << CVC4::quoteSymbol(dt.getName()) << " ";
toStream(out, dt);
out << ")";
#include "base/output.h"
#include "expr/expr_iomanip.h"
#include "expr/node.h"
+#include "expr/type.h"
#include "options/options.h"
#include "options/smt_options.h"
#include "printer/printer.h"
/* class DatatypeDeclarationCommand */
/* -------------------------------------------------------------------------- */
-DatatypeDeclarationCommand::DatatypeDeclarationCommand(
- const DatatypeType& datatype)
+DatatypeDeclarationCommand::DatatypeDeclarationCommand(const Type& datatype)
: d_datatypes()
{
d_datatypes.push_back(datatype);
}
DatatypeDeclarationCommand::DatatypeDeclarationCommand(
- const std::vector<DatatypeType>& datatypes)
+ const std::vector<Type>& datatypes)
: d_datatypes(datatypes)
{
}
-const std::vector<DatatypeType>& DatatypeDeclarationCommand::getDatatypes()
- const
+const std::vector<Type>& DatatypeDeclarationCommand::getDatatypes() const
{
return d_datatypes;
}
class CVC4_PUBLIC DatatypeDeclarationCommand : public Command
{
private:
- std::vector<DatatypeType> d_datatypes;
+ std::vector<Type> d_datatypes;
public:
- DatatypeDeclarationCommand(const DatatypeType& datatype);
+ DatatypeDeclarationCommand(const Type& datatype);
- DatatypeDeclarationCommand(const std::vector<DatatypeType>& datatypes);
- const std::vector<DatatypeType>& getDatatypes() const;
+ DatatypeDeclarationCommand(const std::vector<Type>& datatypes);
+ const std::vector<Type>& getDatatypes() const;
void invoke(SmtEngine* smtEngine) override;
Command* exportTo(ExprManager* exprManager,
ExprManagerMapCollection& variableMap) override;
{
if ((flags & ExprManager::DATATYPE_FLAG_PLACEHOLDER) == 0)
{
- DatatypeDeclarationCommand c(dtts);
+ std::vector<Type> types(dtts.begin(), dtts.end());
+ DatatypeDeclarationCommand c(types);
d_smt.addToModelCommandAndDump(c);
}
}