diff options
author | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2019-12-06 11:00:33 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-06 11:00:33 -0600 |
commit | c7c2d593674e3776ab0c720be1c0c759db8f9453 (patch) | |
tree | fc129a2f0453eb2944009249c4a83ba3bdbaf5a0 /src | |
parent | 499aa5641e2b830f60159c2ce1c791bf4d45aac1 (diff) |
Add ExprManager as argument to Datatype (#3535)
Diffstat (limited to 'src')
-rw-r--r-- | src/api/cvc4cpp.cpp | 44 | ||||
-rw-r--r-- | src/api/cvc4cpp.h | 103 | ||||
-rw-r--r-- | src/expr/datatype.cpp | 9 | ||||
-rw-r--r-- | src/expr/datatype.h | 7 | ||||
-rw-r--r-- | src/expr/node_manager.cpp | 4 | ||||
-rw-r--r-- | src/expr/sygus_datatype.cpp | 5 | ||||
-rw-r--r-- | src/parser/cvc/Cvc.g | 2 | ||||
-rw-r--r-- | src/parser/smt2/Smt2.g | 8 | ||||
-rw-r--r-- | src/parser/smt2/smt2.cpp | 2 | ||||
-rw-r--r-- | src/parser/smt2/smt2.h | 35 |
10 files changed, 151 insertions, 68 deletions
diff --git a/src/api/cvc4cpp.cpp b/src/api/cvc4cpp.cpp index 7a3577e0d..f7ffe850a 100644 --- a/src/api/cvc4cpp.cpp +++ b/src/api/cvc4cpp.cpp @@ -1680,20 +1680,26 @@ std::ostream& operator<<(std::ostream& out, /* DatatypeDecl ------------------------------------------------------------- */ -DatatypeDecl::DatatypeDecl(const std::string& name, bool isCoDatatype) - : d_dtype(new CVC4::Datatype(name, isCoDatatype)) +DatatypeDecl::DatatypeDecl(const Solver* s, + const std::string& name, + bool isCoDatatype) + : d_dtype(new CVC4::Datatype(s->getExprManager(), name, isCoDatatype)) { } -DatatypeDecl::DatatypeDecl(const std::string& name, +DatatypeDecl::DatatypeDecl(const Solver* s, + const std::string& name, Sort param, bool isCoDatatype) - : d_dtype(new CVC4::Datatype( - name, std::vector<Type>{*param.d_type}, isCoDatatype)) + : d_dtype(new CVC4::Datatype(s->getExprManager(), + name, + std::vector<Type>{*param.d_type}, + isCoDatatype)) { } -DatatypeDecl::DatatypeDecl(const std::string& name, +DatatypeDecl::DatatypeDecl(const Solver* s, + const std::string& name, const std::vector<Sort>& params, bool isCoDatatype) { @@ -1703,7 +1709,7 @@ DatatypeDecl::DatatypeDecl(const std::string& name, tparams.push_back(*s.d_type); } d_dtype = std::shared_ptr<CVC4::Datatype>( - new CVC4::Datatype(name, tparams, isCoDatatype)); + new CVC4::Datatype(s->getExprManager(), name, tparams, isCoDatatype)); } DatatypeDecl::~DatatypeDecl() {} @@ -2867,6 +2873,28 @@ Term Solver::mkVar(Sort sort, const std::string& symbol) const CVC4_API_SOLVER_TRY_CATCH_END; } +/* Create datatype declarations */ +/* -------------------------------------------------------------------------- */ + +DatatypeDecl Solver::mkDatatypeDecl(const std::string& name, bool isCoDatatype) +{ + return DatatypeDecl(this, name, isCoDatatype); +} + +DatatypeDecl Solver::mkDatatypeDecl(const std::string& name, + Sort param, + bool isCoDatatype) +{ + return DatatypeDecl(this, name, param, isCoDatatype); +} + +DatatypeDecl Solver::mkDatatypeDecl(const std::string& name, + const std::vector<Sort>& params, + bool isCoDatatype) +{ + return DatatypeDecl(this, name, params, isCoDatatype); +} + /* Create terms */ /* -------------------------------------------------------------------------- */ @@ -3409,7 +3437,7 @@ Sort Solver::declareDatatype( { CVC4_API_ARG_CHECK_EXPECTED(ctors.size() > 0, ctors) << "a datatype declaration with at least one constructor"; - DatatypeDecl dtdecl(symbol); + DatatypeDecl dtdecl(this, symbol); for (const DatatypeConstructorDecl& ctor : ctors) { dtdecl.addConstructor(ctor); diff --git a/src/api/cvc4cpp.h b/src/api/cvc4cpp.h index 8c9bdc10c..e05c228bc 100644 --- a/src/api/cvc4cpp.h +++ b/src/api/cvc4cpp.h @@ -1093,6 +1093,7 @@ class CVC4_PUBLIC DatatypeConstructorDecl std::shared_ptr<CVC4::DatatypeConstructor> d_ctor; }; +class Solver; /** * A CVC4 datatype declaration. */ @@ -1100,37 +1101,8 @@ class CVC4_PUBLIC DatatypeDecl { friend class DatatypeConstructorArg; friend class Solver; - public: /** - * Constructor. - * @param name the name of the datatype - * @param isCoDatatype true if a codatatype is to be constructed - * @return the DatatypeDecl - */ - DatatypeDecl(const std::string& name, bool isCoDatatype = false); - - /** - * Constructor for parameterized datatype declaration. - * Create sorts parameter with Solver::mkParamSort(). - * @param name the name of the datatype - * @param param the sort parameter - * @param isCoDatatype true if a codatatype is to be constructed - */ - DatatypeDecl(const std::string& name, Sort param, bool isCoDatatype = false); - - /** - * Constructor for parameterized datatype declaration. - * Create sorts parameter with Solver::mkParamSort(). - * @param name the name of the datatype - * @param params a list of sort parameters - * @param isCoDatatype true if a codatatype is to be constructed - */ - DatatypeDecl(const std::string& name, - const std::vector<Sort>& params, - bool isCoDatatype = false); - - /** * Destructor. */ ~DatatypeDecl(); @@ -1157,6 +1129,42 @@ class CVC4_PUBLIC DatatypeDecl const CVC4::Datatype& getDatatype(void) const; private: + /** + * Constructor. + * @param s the solver that created this datatype declaration + * @param name the name of the datatype + * @param isCoDatatype true if a codatatype is to be constructed + * @return the DatatypeDecl + */ + DatatypeDecl(const Solver* s, + const std::string& name, + bool isCoDatatype = false); + + /** + * Constructor for parameterized datatype declaration. + * Create sorts parameter with Solver::mkParamSort(). + * @param s the solver that created this datatype declaration + * @param name the name of the datatype + * @param param the sort parameter + * @param isCoDatatype true if a codatatype is to be constructed + */ + DatatypeDecl(const Solver* s, + const std::string& name, + Sort param, + bool isCoDatatype = false); + + /** + * Constructor for parameterized datatype declaration. + * Create sorts parameter with Solver::mkParamSort(). + * @param s the solver that created this datatype declaration + * @param name the name of the datatype + * @param params a list of sort parameters + * @param isCoDatatype true if a codatatype is to be constructed + */ + DatatypeDecl(const Solver* s, + const std::string& name, + const std::vector<Sort>& params, + bool isCoDatatype = false); /* The internal (intermediate) datatype wrapped by this datatype * declaration * This is a shared_ptr rather than a unique_ptr since CVC4::Datatype is @@ -2293,6 +2301,43 @@ class CVC4_PUBLIC Solver Term mkVar(Sort sort, const std::string& symbol = std::string()) const; /* .................................................................... */ + /* Create datatype declarations */ + /* .................................................................... */ + + /** + * Create a datatype declaration. + * @param name the name of the datatype + * @param isCoDatatype true if a codatatype is to be constructed + * @return the DatatypeDecl + */ + DatatypeDecl mkDatatypeDecl(const std::string& name, + bool isCoDatatype = false); + + /** + * Create a datatype declaration. + * Create sorts parameter with Solver::mkParamSort(). + * @param name the name of the datatype + * @param param the sort parameter + * @param isCoDatatype true if a codatatype is to be constructed + * @return the DatatypeDecl + */ + DatatypeDecl mkDatatypeDecl(const std::string& name, + Sort param, + bool isCoDatatype = false); + + /** + * Create a datatype declaration. + * Create sorts parameter with Solver::mkParamSort(). + * @param name the name of the datatype + * @param params a list of sort parameters + * @param isCoDatatype true if a codatatype is to be constructed + * @return the DatatypeDecl + */ + DatatypeDecl mkDatatypeDecl(const std::string& name, + const std::vector<Sort>& params, + bool isCoDatatype = false); + + /* .................................................................... */ /* Formula Handling */ /* .................................................................... */ diff --git a/src/expr/datatype.cpp b/src/expr/datatype.cpp index f3f4c10d3..07af9617d 100644 --- a/src/expr/datatype.cpp +++ b/src/expr/datatype.cpp @@ -55,8 +55,8 @@ typedef expr::Attribute<expr::attr::DatatypeFiniteComputedTag, bool> DatatypeFin typedef expr::Attribute<expr::attr::DatatypeUFiniteTag, bool> DatatypeUFiniteAttr; typedef expr::Attribute<expr::attr::DatatypeUFiniteComputedTag, bool> DatatypeUFiniteComputedAttr; -Datatype::Datatype(std::string name, bool isCo) - : d_internal(nullptr), // until the Node-level datatype API is activated +Datatype::Datatype(ExprManager* em, std::string name, bool isCo) + : d_em(em), d_name(name), d_params(), d_isCo(isCo), @@ -75,10 +75,11 @@ Datatype::Datatype(std::string name, bool isCo) { } -Datatype::Datatype(std::string name, +Datatype::Datatype(ExprManager* em, + std::string name, const std::vector<Type>& params, bool isCo) - : d_internal(nullptr), // until the Node-level datatype API is activated + : d_em(em), d_name(name), d_params(params), d_isCo(isCo), diff --git a/src/expr/datatype.h b/src/expr/datatype.h index c78fbc436..c9191aadf 100644 --- a/src/expr/datatype.h +++ b/src/expr/datatype.h @@ -656,13 +656,14 @@ class CVC4_PUBLIC Datatype { typedef DatatypeConstructorIterator const_iterator; /** Create a new Datatype of the given name. */ - explicit Datatype(std::string name, bool isCo = false); + explicit Datatype(ExprManager* em, std::string name, bool isCo = false); /** * Create a new Datatype of the given name, with the given * parameterization. */ - Datatype(std::string name, + Datatype(ExprManager* em, + std::string name, const std::vector<Type>& params, bool isCo = false); @@ -976,6 +977,8 @@ class CVC4_PUBLIC Datatype { void toStream(std::ostream& out) const; private: + /** The expression manager that created this datatype */ + ExprManager* d_em; /** The internal representation */ std::shared_ptr<DType> d_internal; /** name of this datatype */ diff --git a/src/expr/node_manager.cpp b/src/expr/node_manager.cpp index 201e428de..1142da429 100644 --- a/src/expr/node_manager.cpp +++ b/src/expr/node_manager.cpp @@ -545,7 +545,7 @@ TypeNode NodeManager::TupleTypeCache::getTupleType( NodeManager * nm, std::vecto for (unsigned i = 0; i < types.size(); ++ i) { sst << "_" << types[i]; } - Datatype dt(sst.str()); + Datatype dt(nm->toExprManager(), sst.str()); dt.setTuple(); std::stringstream ssc; ssc << sst.str() << "_ctor"; @@ -574,7 +574,7 @@ TypeNode NodeManager::RecTypeCache::getRecordType( NodeManager * nm, const Recor for(Record::FieldVector::const_iterator i = fields.begin(); i != fields.end(); ++i) { sst << "_" << (*i).first << "_" << (*i).second; } - Datatype dt(sst.str()); + Datatype dt(nm->toExprManager(), sst.str()); dt.setRecord(); std::stringstream ssc; ssc << sst.str() << "_ctor"; diff --git a/src/expr/sygus_datatype.cpp b/src/expr/sygus_datatype.cpp index 73f7c5769..bea8a41b8 100644 --- a/src/expr/sygus_datatype.cpp +++ b/src/expr/sygus_datatype.cpp @@ -20,7 +20,10 @@ using namespace CVC4::kind; namespace CVC4 { -SygusDatatype::SygusDatatype(const std::string& name) : d_dt(Datatype(name)) {} +SygusDatatype::SygusDatatype(const std::string& name) + : d_dt(Datatype(NodeManager::currentNM()->toExprManager(), name)) +{ +} std::string SygusDatatype::getName() const { return d_dt.getName(); } diff --git a/src/parser/cvc/Cvc.g b/src/parser/cvc/Cvc.g index 94bb87fdb..e4849aae6 100644 --- a/src/parser/cvc/Cvc.g +++ b/src/parser/cvc/Cvc.g @@ -2294,7 +2294,7 @@ datatypeDef[std::vector<CVC4::Datatype>& datatypes] params.push_back( t ); } )* RBRACKET )? - { datatypes.push_back(Datatype(id, params, false)); + { datatypes.push_back(Datatype(EXPR_MANAGER, id, params, false)); if(!PARSER_STATE->isUnresolvedType(id)) { // if not unresolved, must be undeclared PARSER_STATE->checkDeclaration(id, CHECK_UNDECLARED, SYM_SORT); diff --git a/src/parser/smt2/Smt2.g b/src/parser/smt2/Smt2.g index c1a9df887..96ac7d48e 100644 --- a/src/parser/smt2/Smt2.g +++ b/src/parser/smt2/Smt2.g @@ -959,7 +959,7 @@ sygusGrammar[CVC4::Type & ret, std::stringstream ss; ss << "dt_" << fun << "_" << i.first; std::string dname = ss.str(); - datatypes.push_back(Datatype(dname)); + datatypes.push_back(Datatype(EXPR_MANAGER, dname)); // make its unresolved type, used for referencing the final version of // the datatype PARSER_STATE->checkDeclaration(dname, CHECK_UNDECLARED, SYM_SORT); @@ -1523,7 +1523,7 @@ datatypesDef[bool isCo, PARSER_STATE->parseError("Wrong number of parameters for datatype."); } Debug("parser-dt") << params.size() << " parameters for " << dnames[dts.size()] << std::endl; - dts.push_back(Datatype(dnames[dts.size()],params,isCo)); + dts.push_back(Datatype(EXPR_MANAGER, dnames[dts.size()],params,isCo)); } LPAREN_TOK ( LPAREN_TOK constructorDef[dts.back()] RPAREN_TOK )+ @@ -1533,7 +1533,7 @@ datatypesDef[bool isCo, PARSER_STATE->parseError("No parameters given for datatype."); } Debug("parser-dt") << params.size() << " parameters for " << dnames[dts.size()] << std::endl; - dts.push_back(Datatype(dnames[dts.size()],params,isCo)); + dts.push_back(Datatype(EXPR_MANAGER, dnames[dts.size()],params,isCo)); } ( LPAREN_TOK constructorDef[dts.back()] RPAREN_TOK )+ ) @@ -2596,7 +2596,7 @@ datatypeDef[bool isCo, std::vector<CVC4::Datatype>& datatypes, params.push_back( t ); } )* ']' )?*/ //AJR: this isn't necessary if we use z3's style - { datatypes.push_back(Datatype(id,params,isCo)); + { datatypes.push_back(Datatype(EXPR_MANAGER, id, params, isCo)); if(!PARSER_STATE->isUnresolvedType(id)) { // if not unresolved, must be undeclared PARSER_STATE->checkDeclaration(id, CHECK_UNDECLARED, SYM_SORT); diff --git a/src/parser/smt2/smt2.cpp b/src/parser/smt2/smt2.cpp index c7e70495e..73dea766a 100644 --- a/src/parser/smt2/smt2.cpp +++ b/src/parser/smt2/smt2.cpp @@ -1099,7 +1099,7 @@ bool Smt2::pushSygusDatatypeDef( Type t, std::string& dname, std::vector< bool >& allow_const, std::vector< std::vector< std::string > >& unresolved_gterm_sym ){ sorts.push_back(t); - datatypes.push_back(Datatype(dname)); + datatypes.push_back(Datatype(getExprManager(), dname)); ops.push_back(std::vector<Expr>()); cnames.push_back(std::vector<std::string>()); cargs.push_back(std::vector<std::vector<CVC4::Type> >()); diff --git a/src/parser/smt2/smt2.h b/src/parser/smt2/smt2.h index 215f565cd..efdb0c70f 100644 --- a/src/parser/smt2/smt2.h +++ b/src/parser/smt2/smt2.h @@ -383,22 +383,25 @@ class Smt2 : public Parser CVC4::Type& ret, bool isNested = false); - static bool pushSygusDatatypeDef( Type t, std::string& dname, - std::vector< CVC4::Datatype >& datatypes, - std::vector< CVC4::Type>& sorts, - std::vector< std::vector<CVC4::Expr> >& ops, - std::vector< std::vector<std::string> >& cnames, - std::vector< std::vector< std::vector< CVC4::Type > > >& cargs, - std::vector< bool >& allow_const, - std::vector< std::vector< std::string > >& unresolved_gterm_sym ); - - static bool popSygusDatatypeDef( std::vector< CVC4::Datatype >& datatypes, - std::vector< CVC4::Type>& sorts, - std::vector< std::vector<CVC4::Expr> >& ops, - std::vector< std::vector<std::string> >& cnames, - std::vector< std::vector< std::vector< CVC4::Type > > >& cargs, - std::vector< bool >& allow_const, - std::vector< std::vector< std::string > >& unresolved_gterm_sym ); + bool pushSygusDatatypeDef( + Type t, + std::string& dname, + std::vector<CVC4::Datatype>& datatypes, + std::vector<CVC4::Type>& sorts, + std::vector<std::vector<CVC4::Expr>>& ops, + std::vector<std::vector<std::string>>& cnames, + std::vector<std::vector<std::vector<CVC4::Type>>>& cargs, + std::vector<bool>& allow_const, + std::vector<std::vector<std::string>>& unresolved_gterm_sym); + + bool popSygusDatatypeDef( + std::vector<CVC4::Datatype>& datatypes, + std::vector<CVC4::Type>& sorts, + std::vector<std::vector<CVC4::Expr>>& ops, + std::vector<std::vector<std::string>>& cnames, + std::vector<std::vector<std::vector<CVC4::Type>>>& cargs, + std::vector<bool>& allow_const, + std::vector<std::vector<std::string>>& unresolved_gterm_sym); void setSygusStartIndex(const std::string& fun, int startIndex, |