Revert change to datatypes API for passing pointers, instead make deep copy during...
authorajreynol <andrew.j.reynolds@gmail.com>
Tue, 1 Nov 2016 18:33:38 +0000 (13:33 -0500)
committerajreynol <andrew.j.reynolds@gmail.com>
Tue, 1 Nov 2016 18:33:38 +0000 (13:33 -0500)
12 files changed:
src/compat/cvc3_compat.cpp
src/expr/expr_manager_template.cpp
src/expr/expr_manager_template.h
src/expr/node_manager.cpp
src/expr/node_manager.h
src/parser/cvc/Cvc.g
src/parser/parser.cpp
src/parser/parser.h
src/parser/smt2/Smt2.g
src/parser/smt2/smt2.cpp
src/parser/smt2/smt2.h
src/smt/boolean_terms.cpp

index 0482c99ee7990c717fc20710e16c06e8fc499bec..5de62a458ac21114ceb143940e3274f60f72fde6 100644 (file)
@@ -1384,11 +1384,11 @@ void ValidityChecker::dataType(const std::vector<std::string>& names,
   CompatCheckArgument(names.size() == types.size(), types,
                       "Expected names and types vectors to be of equal "
                       "length.");
-  vector<CVC4::Datatype*> dv;
+  vector<CVC4::Datatype> dv;
 
   // Set up the datatype specifications.
   for(unsigned i = 0; i < names.size(); ++i) {
-    CVC4::Datatype* dt = new CVC4::Datatype(names[i], false);
+    CVC4::Datatype dt(names[i], false);
     CompatCheckArgument(constructors[i].size() == selectors[i].size(),
                         "Expected sub-vectors in constructors and selectors "
                         "vectors to match in size.");
@@ -1409,7 +1409,7 @@ void ValidityChecker::dataType(const std::vector<std::string>& names,
           ctor.addArg(selectors[i][j][k], exprToType(types[i][j][k]));
         }
       }
-      dt->addConstructor(ctor);
+      dt.addConstructor(ctor);
     }
     dv.push_back(dt);
   }
index 525f8ead32dec1e3bd5367ac8c3bb092bbae230d..d36ff5a3ddd260d25ad583d431012f9612267eed 100644 (file)
@@ -645,10 +645,10 @@ SetType ExprManager::mkSetType(Type elementType) const {
   return SetType(Type(d_nodeManager, new TypeNode(d_nodeManager->mkSetType(*elementType.d_typeNode))));
 }
 
-DatatypeType ExprManager::mkDatatypeType(Datatype*& datatype) {
+DatatypeType ExprManager::mkDatatypeType(Datatype& datatype) {
   // Not worth a special implementation; this doesn't need to be fast
   // code anyway.
-  vector<Datatype*> datatypes;
+  vector<Datatype> datatypes;
   datatypes.push_back(datatype);
   std::vector<DatatypeType> result;
   mkMutualDatatypeTypes(datatypes, result);
@@ -656,28 +656,28 @@ DatatypeType ExprManager::mkDatatypeType(Datatype*& datatype) {
   return result.front();
 }
 
-void ExprManager::mkMutualDatatypeTypes(std::vector<Datatype*>& datatypes, std::vector<DatatypeType>& dtts) {
+void ExprManager::mkMutualDatatypeTypes(std::vector<Datatype>& datatypes, std::vector<DatatypeType>& dtts) {
   std::set<Type> unresolvedTypes;
   return mkMutualDatatypeTypes(datatypes, unresolvedTypes, dtts);
 }
 
-void ExprManager::mkMutualDatatypeTypes(std::vector<Datatype*>& datatypes, std::set<Type>& unresolvedTypes, std::vector<DatatypeType>& dtts) {
+void ExprManager::mkMutualDatatypeTypes(std::vector<Datatype>& datatypes, std::set<Type>& unresolvedTypes, std::vector<DatatypeType>& dtts) {
   NodeManagerScope nms(d_nodeManager);
   std::map<std::string, DatatypeType> nameResolutions;
 
   Trace("ajr-temp") << "Build datatypes..." << std::endl;
-  //std::vector< Datatype* > dt_copies;
-  //for(std::vector<Datatype*>::iterator i = datatypes.begin(), i_end = datatypes.end(); i != i_end; ++i) {
-  //  dt_copies.push_back( new Datatype( **i ) );
-  //}
-  
+  //have to build deep copy so that datatypes will live in NodeManager
+  std::vector< Datatype* > dt_copies;
+  for(std::vector<Datatype>::iterator i = datatypes.begin(), i_end = datatypes.end(); i != i_end; ++i) {
+    dt_copies.push_back( new Datatype( *i ) );
+  }
   
   // First do some sanity checks, set up the final Type to be used for
   // each datatype, and set up the "named resolutions" used to handle
   // simple self- and mutual-recursion, for example in the definition
   // "nat = succ(pred:nat) | zero", a named resolution can handle the
   // pred selector.
-  for(std::vector<Datatype*>::iterator i = datatypes.begin(), i_end = datatypes.end(); i != i_end; ++i) {
+  for(std::vector<Datatype*>::iterator i = dt_copies.begin(), i_end = dt_copies.end(); i != i_end; ++i) {
     TypeNode* typeNode;
     if( (*i)->getNumParameters() == 0 ) {
       unsigned index = d_nodeManager->registerDatatype( *i );
@@ -699,7 +699,7 @@ void ExprManager::mkMutualDatatypeTypes(std::vector<Datatype*>& datatypes, std::
     DatatypeType dtt(type);
     PrettyCheckArgument(
         nameResolutions.find((*i)->getName()) == nameResolutions.end(),
-        datatypes,
+        dt_copies,
         "cannot construct two datatypes at the same time "
         "with the same name `%s'",
         (*i)->getName().c_str());
index 3f29396a36326c730b9163fbff3b581d6cfe89e1..d08c53e3dba5ee0b82051227af70d9151a3a3c56 100644 (file)
@@ -374,13 +374,13 @@ public:
   SetType mkSetType(Type elementType) const;
 
   /** Make a type representing the given datatype. */
-  DatatypeType mkDatatypeType(Datatype*& datatype);
+  DatatypeType mkDatatypeType(Datatype& datatype);
 
   /**
    * Make a set of types representing the given datatypes, which may be
    * mutually recursive.
    */
-  void mkMutualDatatypeTypes(std::vector<Datatype*>& datatypes, std::vector<DatatypeType>& dtts);
+  void mkMutualDatatypeTypes(std::vector<Datatype>& datatypes, std::vector<DatatypeType>& dtts);
 
   /**
    * Make a set of types representing the given datatypes, which may
@@ -411,7 +411,7 @@ public:
    * then no complicated Type needs to be created, and the above,
    * simpler form of mkMutualDatatypeTypes() is enough.
    */
-  void mkMutualDatatypeTypes(std::vector<Datatype*>& datatypes, std::set<Type>& unresolvedTypes, std::vector<DatatypeType>& dtts);
+  void mkMutualDatatypeTypes(std::vector<Datatype>& datatypes, std::set<Type>& unresolvedTypes, std::vector<DatatypeType>& dtts);
 
   /**
    * Make a type representing a constructor with the given parameterization.
index af0b1a2d058089c4f827491fcbeda4dbf39ab048..2e6792bdd9f380fb376f80790376415ab0a2a539 100644 (file)
@@ -489,15 +489,15 @@ TypeNode NodeManager::mkSubrangeType(const SubrangeBounds& bounds)
 TypeNode NodeManager::TupleTypeCache::getTupleType( NodeManager * nm, std::vector< TypeNode >& types, unsigned index ) {
   if( index==types.size() ){
     if( d_data.isNull() ){
-      Datatype* dt = new Datatype("__cvc4_tuple");
-      dt->setTuple();
+      Datatype dt("__cvc4_tuple");
+      dt.setTuple();
       DatatypeConstructor c("__cvc4_tuple_ctor");
       for (unsigned i = 0; i < types.size(); ++ i) {
         std::stringstream ss;
         ss << "__cvc4_tuple_stor_" << i;
         c.addArg(ss.str().c_str(), types[i].toType());
       }
-      dt->addConstructor(c);
+      dt.addConstructor(c);
       d_data = TypeNode::fromType(nm->toExprManager()->mkDatatypeType(dt));
       Debug("tuprec-debug") << "Return type : " << d_data << std::endl;
     }
@@ -511,13 +511,13 @@ TypeNode NodeManager::RecTypeCache::getRecordType( NodeManager * nm, const Recor
   if( index==rec.getNumFields() ){
     if( d_data.isNull() ){
       const Record::FieldVector& fields = rec.getFields();
-      Datatype* dt = new Datatype("__cvc4_record");
-      dt->setRecord();
+      Datatype dt("__cvc4_record");
+      dt.setRecord();
       DatatypeConstructor c("__cvc4_record_ctor");
       for(Record::FieldVector::const_iterator i = fields.begin(); i != fields.end(); ++i) {
         c.addArg((*i).first, (*i).second);
       }
-      dt->addConstructor(c);
+      dt.addConstructor(c);
       d_data = TypeNode::fromType(nm->toExprManager()->mkDatatypeType(dt));
       Debug("tuprec-debug") << "Return type : " << d_data << std::endl;
     }
index 9342a02c40e6e634bdca42f6d3854445eab83a21..5e6fcf3d39f3bf9b58271e9f88dcc98ecdc4f5b2 100644 (file)
@@ -84,7 +84,7 @@ class NodeManager {
   friend Expr ExprManager::mkVar(Type, uint32_t flags);
 
   // friend so it can access NodeManager's d_listeners and notify clients
-  friend void ExprManager::mkMutualDatatypeTypes(std::vector<Datatype*>&, std::set<Type>&, std::vector<DatatypeType>&);
+  friend void ExprManager::mkMutualDatatypeTypes(std::vector<Datatype>&, std::set<Type>&, std::vector<DatatypeType>&);
 
   /** Predicate for use with STL algorithms */
   struct NodeValueReferenceCountNonZero {
index 7ca6beb60eb8bf205d290bcbfdd8bb233cc4ad51..8c5d972548a16f4a92fc8e382f0cba59e85f3568 100644 (file)
@@ -708,7 +708,7 @@ mainCommand[CVC4::Command*& cmd]
   SExpr sexpr;
   std::string id;
   Type t;
-  std::vector<CVC4::Datatype*> dts;
+  std::vector<CVC4::Datatype> dts;
   Debug("parser-extra") << "command: " << AntlrInput::tokenText(LT(1)) << std::endl;
   std::string s;
 }
@@ -2175,7 +2175,7 @@ iteElseTerm[CVC4::Expr& f]
 /**
  * Parses a datatype definition
  */
-datatypeDef[std::vector<CVC4::Datatype*>& datatypes]
+datatypeDef[std::vector<CVC4::Datatype>& datatypes]
 @init {
   std::string id, id2;
   Type t;
@@ -2195,7 +2195,7 @@ datatypeDef[std::vector<CVC4::Datatype*>& datatypes]
         params.push_back( t ); }
       )* RBRACKET
     )?
-    { datatypes.push_back(new Datatype(id, params, false));
+    { datatypes.push_back(Datatype(id, params, false));
       if(!PARSER_STATE->isUnresolvedType(id)) {
         // if not unresolved, must be undeclared
         PARSER_STATE->checkDeclaration(id, CHECK_UNDECLARED, SYM_SORT);
@@ -2209,7 +2209,7 @@ datatypeDef[std::vector<CVC4::Datatype*>& datatypes]
 /**
  * Parses a constructor defintion for type
  */
-constructorDef[CVC4::Datatype*& type]
+constructorDef[CVC4::Datatype& type]
 @init {
   std::string id;
   CVC4::DatatypeConstructor* ctor = NULL;
@@ -2227,7 +2227,7 @@ constructorDef[CVC4::Datatype*& type]
       RPAREN
     )?
     { // make the constructor
-      type->addConstructor(*ctor);
+      type.addConstructor(*ctor);
       Debug("parser-idt") << "constructor: " << id.c_str() << std::endl;
       delete ctor;
     }
index e46c13140db10ba7dc3b022a6e4727ad02d21dab..cef8c4be4690a50e2372a2dddae1482062456c75 100644 (file)
@@ -303,7 +303,7 @@ bool Parser::isUnresolvedType(const std::string& name) {
   return d_unresolved.find(getSort(name)) != d_unresolved.end();
 }
 
-void Parser::mkMutualDatatypeTypes(std::vector<Datatype*>& datatypes, std::vector<DatatypeType>& types) {
+void Parser::mkMutualDatatypeTypes(std::vector<Datatype>& datatypes, std::vector<DatatypeType>& types) {
 
   try {
     d_exprManager->mkMutualDatatypeTypes(datatypes, d_unresolved, types);
index 52f8dcb86d79c065c0b6d0325e5de1d52455e7da..7c9870edbbc400549d18cb4fd38066d07d7b4ad0 100644 (file)
@@ -501,7 +501,7 @@ public:
   /**
    * Create sorts of mutually-recursive datatypes.
    */
-  void mkMutualDatatypeTypes(std::vector<Datatype*>& datatypes, std::vector<DatatypeType>& dtts);
+  void mkMutualDatatypeTypes(std::vector<Datatype>& datatypes, std::vector<DatatypeType>& dtts);
 
   /**
    * Add an operator to the current legal set.
index 0fbd454b49cf6609ed67a001aca9b10b44b4a1f2..3bd308559c026293b4075d00bd84999797238f8a 100644 (file)
@@ -512,7 +512,7 @@ sygusCommand returns [CVC4::Command* cmd = NULL]
   SExpr sexpr;
   CommandSequence* seq;
   std::vector< std::vector< CVC4::SygusGTerm > > sgts;
-  std::vector< CVC4::Datatype* > datatypes;
+  std::vector< CVC4::Datatype > datatypes;
   std::vector< std::vector<Expr> > ops;
   std::vector< std::vector< std::string > > cnames;
   std::vector< std::vector< std::vector< CVC4::Type > > > cargs;
@@ -621,14 +621,14 @@ sygusCommand returns [CVC4::Command* cmd = NULL]
         //swap index if necessary
         Debug("parser-sygus") << "--- Making sygus datatypes..." << std::endl;
         for( unsigned i=0; i<datatypes.size(); i++ ){
-          Debug("parser-sygus") << "..." << datatypes[i]->getName() << " has builtin sort " << sorts[i] << std::endl;
+          Debug("parser-sygus") << "..." << datatypes[i].getName() << " has builtin sort " << sorts[i] << std::endl;
         }
         for( unsigned i=0; i<datatypes.size(); i++ ){
-          Debug("parser-sygus") << "...make " << datatypes[i]->getName() << " with builtin sort " << sorts[i] << std::endl;
+          Debug("parser-sygus") << "...make " << datatypes[i].getName() << " with builtin sort " << sorts[i] << std::endl;
           if( sorts[i].isNull() ){
             PARSER_STATE->parseError(std::string("Internal error : could not infer builtin sort for nested gterm."));
           }
-          datatypes[i]->setSygus( sorts[i], terms[0], allow_const[i], false );
+          datatypes[i].setSygus( sorts[i], terms[0], allow_const[i], false );
           PARSER_STATE->mkSygusDatatype( datatypes[i], ops[i], cnames[i], cargs[i], unresolved_gterm_sym[i], sygus_to_builtin );
         }
         PARSER_STATE->setSygusStartIndex( fun, startIndex, datatypes, sorts, ops );
@@ -637,7 +637,7 @@ sygusCommand returns [CVC4::Command* cmd = NULL]
       PARSER_STATE->popScope();
       Debug("parser-sygus") << "--- Make " << datatypes.size() << " mutual datatypes..." << std::endl;
       for( unsigned i=0; i<datatypes.size(); i++ ){
-        Debug("parser-sygus") << "  " << i << " : " << datatypes[i]->getName() << std::endl;
+        Debug("parser-sygus") << "  " << i << " : " << datatypes[i].getName() << std::endl;
       }
       seq = new CommandSequence();
       std::vector<DatatypeType> datatypeTypes; 
@@ -1169,7 +1169,7 @@ smt25Command[CVC4::Command*& cmd]
 
 extendedCommand[CVC4::Command*& cmd]
 @declarations {
-  std::vector<CVC4::Datatype*> dts;
+  std::vector<CVC4::Datatype> dts;
   Expr e, e2;
   Type t;
   std::string name;
@@ -1325,7 +1325,7 @@ extendedCommand[CVC4::Command*& cmd]
 
 datatypesDefCommand[bool isCo, CVC4::Command*& cmd]
 @declarations {
-  std::vector<CVC4::Datatype*> dts;
+  std::vector<CVC4::Datatype> dts;
   std::vector<CVC4::DatatypeType> dtts;
   std::string name;
   std::vector<Type> sorts;
@@ -2475,7 +2475,7 @@ nonemptyNumeralList[std::vector<uint64_t>& numerals]
 /**
  * Parses a datatype definition
  */
-datatypeDef[bool isCo, std::vector<CVC4::Datatype*>& datatypes, std::vector< CVC4::Type >& params]
+datatypeDef[bool isCo, std::vector<CVC4::Datatype>& datatypes, std::vector< CVC4::Type >& params]
 @init {
   std::string id;
 }
@@ -2493,7 +2493,7 @@ datatypeDef[bool isCo, std::vector<CVC4::Datatype*>& datatypes, std::vector< CVC
         params.push_back( t ); }
       )* ']'
     )?*/ //AJR: this isn't necessary if we use z3's style
-    { datatypes.push_back(new Datatype(id,params,isCo));
+    { datatypes.push_back(Datatype(id,params,isCo));
       if(!PARSER_STATE->isUnresolvedType(id)) {
         // if not unresolved, must be undeclared
         PARSER_STATE->checkDeclaration(id, CHECK_UNDECLARED, SYM_SORT);
@@ -2506,7 +2506,7 @@ datatypeDef[bool isCo, std::vector<CVC4::Datatype*>& datatypes, std::vector< CVC
 /**
  * Parses a constructor defintion for type
  */
-constructorDef[CVC4::Datatype*& type]
+constructorDef[CVC4::Datatype& type]
 @init {
   std::string id;
   CVC4::DatatypeConstructor* ctor = NULL;
@@ -2520,7 +2520,7 @@ constructorDef[CVC4::Datatype*& type]
     }
     ( LPAREN_TOK selector[*ctor] RPAREN_TOK )*
     { // make the constructor
-      type->addConstructor(*ctor);
+      type.addConstructor(*ctor);
       Debug("parser-idt") << "constructor: " << id.c_str() << std::endl;
       delete ctor;
     }
index dd48ceca74c2655a0f1ad82523ce5f3d91e01106..8db344f929b7bcccbe32dbc6deca535204d2b240 100644 (file)
@@ -563,7 +563,7 @@ void collectSygusGrammarTypesFor( Type range, std::vector< Type >& types, std::m
   }
 }
 
-void Smt2::mkSygusDefaultGrammar( const Type& range, Expr& bvl, const std::string& fun, std::vector< CVC4::Datatype* >& datatypes,
+void Smt2::mkSygusDefaultGrammar( const Type& range, Expr& bvl, const std::string& fun, std::vector<CVC4::Datatype>& datatypes,
                                   std::vector<Type>& sorts, std::vector< std::vector<Expr> >& ops, std::vector<Expr> sygus_vars, int& startIndex ) {
 
   //if( !range.isBoolean() && !range.isInteger() && !range.isBitVector() && !range.isDatatype() ){
@@ -594,7 +594,7 @@ void Smt2::mkSygusDefaultGrammar( const Type& range, Expr& bvl, const std::strin
     std::stringstream ss;
     ss << fun << "_" << types[i];
     std::string dname = ss.str();
-    datatypes.push_back(new Datatype(dname));
+    datatypes.push_back(Datatype(dname));
     ops.push_back(std::vector<Expr>());
     //make unresolved type
     Type unres_t = mkUnresolvedType(dname);
@@ -683,7 +683,7 @@ void Smt2::mkSygusDefaultGrammar( const Type& range, Expr& bvl, const std::strin
       }
     }
     Debug("parser-sygus") << "...make datatype " << datatypes.back() << std::endl;
-    datatypes[i]->setSygus( types[i], bvl, true, true );
+    datatypes[i].setSygus( types[i], bvl, true, true );
     mkSygusDatatype( datatypes[i], ops[i], cnames, cargs, unresolved_gterm_sym, sygus_to_builtin );
     sorts.push_back( types[i] );
     //set start index if applicable
@@ -694,12 +694,12 @@ void Smt2::mkSygusDefaultGrammar( const Type& range, Expr& bvl, const std::strin
 
   //make Boolean type
   Type btype = getExprManager()->booleanType();
-  datatypes.push_back(new Datatype(dbname));
+  datatypes.push_back(Datatype(dbname));
   ops.push_back(std::vector<Expr>());
   std::vector<std::string> cnames;
   std::vector<std::vector<CVC4::Type> > cargs;
   std::vector<std::string> unresolved_gterm_sym;
-  Debug("parser-sygus") << "Make grammar for " << btype << " " << *(datatypes.back()) << std::endl;
+  Debug("parser-sygus") << "Make grammar for " << btype << " " << datatypes.back() << std::endl;
   //add variables
   for( unsigned i=0; i<sygus_vars.size(); i++ ){
     if( sygus_vars[i].getType().isBoolean() ){
@@ -776,8 +776,8 @@ void Smt2::mkSygusDefaultGrammar( const Type& range, Expr& bvl, const std::strin
   if( range==btype ){
     startIndex = sorts.size();
   }
-  Debug("parser-sygus") << "...make datatype " << *(datatypes.back()) << std::endl;
-  datatypes.back()->setSygus( btype, bvl, true, true );
+  Debug("parser-sygus") << "...make datatype " << datatypes.back() << std::endl;
+  datatypes.back().setSygus( btype, bvl, true, true );
   mkSygusDatatype( datatypes.back(), ops.back(), cnames, cargs, unresolved_gterm_sym, sygus_to_builtin );
   sorts.push_back( btype );
 
@@ -804,7 +804,7 @@ void Smt2::mkSygusConstantsForType( const Type& type, std::vector<CVC4::Expr>& o
 //  This method adds N operators to ops[index], N names to cnames[index] and N type argument vectors to cargs[index] (where typically N=1)
 //  This method may also add new elements pairwise into datatypes/sorts/ops/cnames/cargs in the case of non-flat gterms.
 void Smt2::processSygusGTerm( CVC4::SygusGTerm& sgt, int index,
-                              std::vector< CVC4::Datatype* >& datatypes,
+                              std::vector< CVC4::Datatype >& datatypes,
                               std::vector< CVC4::Type>& sorts,
                               std::vector< std::vector<CVC4::Expr> >& ops,
                               std::vector< std::vector<std::string> >& cnames,
@@ -848,7 +848,7 @@ void Smt2::processSygusGTerm( CVC4::SygusGTerm& sgt, int index,
     cargs[index].push_back( std::vector< CVC4::Type >() );
     for( unsigned i=0; i<sgt.d_children.size(); i++ ){
       std::stringstream ss;
-      ss << datatypes[index]->getName() << "_" << ops[index].size() << "_arg_" << i;
+      ss << datatypes[index].getName() << "_" << ops[index].size() << "_arg_" << i;
       std::string sub_dname = ss.str();
       //add datatype for child
       Type null_type;
@@ -921,7 +921,7 @@ void Smt2::processSygusGTerm( CVC4::SygusGTerm& sgt, int index,
 }
 
 bool Smt2::pushSygusDatatypeDef( Type t, std::string& dname,
-                                  std::vector< CVC4::Datatype* >& datatypes,
+                                  std::vector< CVC4::Datatype >& datatypes,
                                   std::vector< CVC4::Type>& sorts,
                                   std::vector< std::vector<CVC4::Expr> >& ops,
                                   std::vector< std::vector<std::string> >& cnames,
@@ -929,7 +929,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(new Datatype(dname));
+  datatypes.push_back(Datatype(dname));
   ops.push_back(std::vector<Expr>());
   cnames.push_back(std::vector<std::string>());
   cargs.push_back(std::vector<std::vector<CVC4::Type> >());
@@ -938,7 +938,7 @@ bool Smt2::pushSygusDatatypeDef( Type t, std::string& dname,
   return true;
 }
 
-bool Smt2::popSygusDatatypeDef( std::vector< CVC4::Datatype* >& datatypes,
+bool Smt2::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,
@@ -955,7 +955,7 @@ bool Smt2::popSygusDatatypeDef( std::vector< CVC4::Datatype* >& datatypes,
   return true;
 }
 
-Type Smt2::processSygusNestedGTerm( int sub_dt_index, std::string& sub_dname, std::vector< CVC4::Datatype* >& datatypes,
+Type Smt2::processSygusNestedGTerm( int sub_dt_index, std::string& sub_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,
@@ -1024,7 +1024,7 @@ Type Smt2::processSygusNestedGTerm( int sub_dt_index, std::string& sub_dname, st
     sygus_to_builtin[t] = curr_t;
   }else{
     Debug("parser-sygus") << "simple argument " << t << std::endl;
-    Debug("parser-sygus") << "...removing " << datatypes.back()->getName() << std::endl;
+    Debug("parser-sygus") << "...removing " << datatypes.back().getName() << std::endl;
     //otherwise, datatype was unecessary
     //pop argument datatype definition
     popSygusDatatypeDef( datatypes, sorts, ops, cnames, cargs, allow_const, unresolved_gterm_sym );
@@ -1034,7 +1034,7 @@ Type Smt2::processSygusNestedGTerm( int sub_dt_index, std::string& sub_dname, st
 
 void Smt2::processSygusLetConstructor( std::vector< CVC4::Expr >& let_vars,
                                        int index,
-                                       std::vector< CVC4::Datatype* >& datatypes,
+                                       std::vector< CVC4::Datatype >& datatypes,
                                        std::vector< CVC4::Type>& sorts,
                                        std::vector< std::vector<CVC4::Expr> >& ops,
                                        std::vector< std::vector<std::string> >& cnames,
@@ -1045,7 +1045,7 @@ void Smt2::processSygusLetConstructor( std::vector< CVC4::Expr >& let_vars,
   std::vector< CVC4::Expr > let_define_args;
   Expr let_body;
   int dindex = cargs[index].size()-1;
-  Debug("parser-sygus") << "Process let constructor for datatype " << datatypes[index]->getName() << ", #subtypes = " << cargs[index][dindex].size() << std::endl;
+  Debug("parser-sygus") << "Process let constructor for datatype " << datatypes[index].getName() << ", #subtypes = " << cargs[index][dindex].size() << std::endl;
   for( unsigned i=0; i<cargs[index][dindex].size(); i++ ){
     Debug("parser-sygus") << "  " << i << " : " << cargs[index][dindex][i] << std::endl;
     if( i+1==cargs[index][dindex].size() ){
@@ -1054,7 +1054,7 @@ void Smt2::processSygusLetConstructor( std::vector< CVC4::Expr >& let_vars,
         let_body = it->second;
       }else{
         std::stringstream ss;
-        ss << datatypes[index]->getName() << "_body";
+        ss << datatypes[index].getName() << "_body";
         let_body = mkBoundVar(ss.str(), sygus_to_builtin[cargs[index][dindex][i]]);
         d_sygus_bound_var_type[let_body] = cargs[index][dindex][i];
       }
@@ -1094,7 +1094,7 @@ void Smt2::processSygusLetConstructor( std::vector< CVC4::Expr >& let_vars,
 
   Type ft = getExprManager()->mkFunctionType(fsorts, let_body.getType());
   std::stringstream ss;
-  ss << datatypes[index]->getName() << "_let";
+  ss << datatypes[index].getName() << "_let";
   Expr let_func = mkFunction(ss.str(), ft, ExprManager::VAR_FLAG_DEFINED);
   d_sygus_defined_funs.push_back( let_func );
   preemptCommand( new DefineFunctionCommand(ss.str(), let_func, let_define_args, let_body) );
@@ -1130,11 +1130,11 @@ void Smt2::collectSygusLetArgs( CVC4::Expr e, std::vector< CVC4::Type >& sygusAr
 }
 
 void Smt2::setSygusStartIndex( std::string& fun, int startIndex,
-                               std::vector< CVC4::Datatype* >& datatypes,
+                               std::vector< CVC4::Datatype >& datatypes,
                                std::vector< CVC4::Type>& sorts,
                                std::vector< std::vector<CVC4::Expr> >& ops ) {
   if( startIndex>0 ){
-    CVC4::Datatype* tmp_dt = datatypes[0];
+    CVC4::Datatype tmp_dt = datatypes[0];
     Type tmp_sort = sorts[0];
     std::vector< Expr > tmp_ops;
     tmp_ops.insert( tmp_ops.end(), ops[0].begin(), ops[0].end() );
@@ -1218,11 +1218,11 @@ void Smt2::defineSygusFuns() {
   }
 }
 
-void Smt2::mkSygusDatatype( CVC4::Datatype* dt, std::vector<CVC4::Expr>& ops,
+void Smt2::mkSygusDatatype( CVC4::Datatype& dt, std::vector<CVC4::Expr>& ops,
                             std::vector<std::string>& cnames, std::vector< std::vector< CVC4::Type > >& cargs,
                             std::vector<std::string>& unresolved_gterm_sym,
                             std::map< CVC4::Type, CVC4::Type >& sygus_to_builtin ) {
-  Debug("parser-sygus") << "Making sygus datatype " << dt->getName() << std::endl;
+  Debug("parser-sygus") << "Making sygus datatype " << dt.getName() << std::endl;
   Debug("parser-sygus") << "  add constructors..." << std::endl;
   for( int i=0; i<(int)cnames.size(); i++ ){
     bool is_dup = false;
@@ -1260,7 +1260,7 @@ void Smt2::mkSygusDatatype( CVC4::Datatype* dt, std::vector<CVC4::Expr>& ops,
       for( unsigned j=0; j<cargs[i].size(); j++ ){
         Type bt = sygus_to_builtin[cargs[i][j]];
         std::stringstream ss;
-        ss << dt->getName() << "_x_" << i << "_" << j;
+        ss << dt.getName() << "_x_" << i << "_" << j;
         Expr v = mkBoundVar(ss.str(), bt);
         let_args.push_back( v );
         fsorts.push_back( bt );
@@ -1280,7 +1280,7 @@ void Smt2::mkSygusDatatype( CVC4::Datatype* dt, std::vector<CVC4::Expr>& ops,
       Type ft = getExprManager()->mkFunctionType(fsorts, let_body.getType());
       Debug("parser-sygus") << ": function type is " << ft << std::endl;
       std::stringstream ss;
-      ss << dt->getName() << "_df_" << i;
+      ss << dt.getName() << "_df_" << i;
       //replace operator and name
       ops[i] = mkFunction(ss.str(), ft, ExprManager::VAR_FLAG_DEFINED);
       cnames[i] = ss.str();
@@ -1309,7 +1309,7 @@ void Smt2::mkSygusDatatype( CVC4::Datatype* dt, std::vector<CVC4::Expr>& ops,
         if( std::find( types.begin(), types.end(), t )==types.end() ){
           types.push_back( t );
           //identity element
-          Type bt = dt->getSygusType();
+          Type bt = dt.getSygusType();
           Debug("parser-sygus") << ":  make identity function for " << bt << ", argument type " << t << std::endl;
           std::stringstream ss;
           ss << t << "_x_id";
@@ -1338,19 +1338,19 @@ void Smt2::mkSygusDatatype( CVC4::Datatype* dt, std::vector<CVC4::Expr>& ops,
 
 }
 
-void Smt2::addSygusDatatypeConstructor( CVC4::Datatype* dt, CVC4::Expr op, std::string& cname, std::vector< CVC4::Type >& cargs,
+void Smt2::addSygusDatatypeConstructor( CVC4::Datatype& dt, CVC4::Expr op, std::string& cname, std::vector< CVC4::Type >& cargs,
                                         CVC4::Expr& let_body, std::vector< CVC4::Expr >& let_args, unsigned let_num_input_args ) {
-  Debug("parser-sygus") << "--> Add constructor " << cname << " to " << dt->getName() << std::endl;
+  Debug("parser-sygus") << "--> Add constructor " << cname << " to " << dt.getName() << std::endl;
   if( !let_body.isNull() ){
     Debug("parser-sygus") << "    let body = " << let_body << ", args = " << let_args.size() << "," << let_num_input_args << std::endl;
     //TODO : remove arguments not occurring in body
     //if this is a self identity function, ignore
     if( let_args.size()==0 && let_args[0]==let_body ){
-      Debug("parser-sygus") << "    identity function " << cargs[0] << " to " << dt->getName() << std::endl;
+      Debug("parser-sygus") << "    identity function " << cargs[0] << " to " << dt.getName() << std::endl;
       //TODO
     }
   }
-  std::string name = dt->getName() + "_" + cname;
+  std::string name = dt.getName() + "_" + cname;
   std::string testerId("is-");
   testerId.append(name);
   checkDeclaration(name, CHECK_UNDECLARED, SYM_VARIABLE);
@@ -1363,7 +1363,7 @@ void Smt2::addSygusDatatypeConstructor( CVC4::Datatype* dt, CVC4::Expr op, std::
     sname << name << "_" << j;
     c.addArg(sname.str(), cargs[j]);
   }
-  dt->addConstructor(c);
+  dt.addConstructor(c);
 }
 
 
index ac4be9bee3046303f8b4c88b5168c85a04b074ac..b99e142ba657039eaafc8727ad5c64ab9b6f54e3 100644 (file)
@@ -173,13 +173,13 @@ public:
 
   Expr mkSygusVar(const std::string& name, const Type& type, bool isPrimed = false);
 
-  void mkSygusDefaultGrammar( const Type& range, Expr& bvl, const std::string& fun, std::vector< CVC4::Datatype* >& datatypes,
+  void mkSygusDefaultGrammar( const Type& range, Expr& bvl, const std::string& fun, std::vector<CVC4::Datatype>& datatypes,
                               std::vector<Type>& sorts, std::vector< std::vector<Expr> >& ops, std::vector<Expr> sygus_vars, int& startIndex );
 
   void mkSygusConstantsForType( const Type& type, std::vector<CVC4::Expr>& ops );
 
   void processSygusGTerm( CVC4::SygusGTerm& sgt, int index,
-                          std::vector< CVC4::Datatype* >& datatypes,
+                          std::vector< CVC4::Datatype >& datatypes,
                           std::vector< CVC4::Type>& sorts,
                           std::vector< std::vector<CVC4::Expr> >& ops,
                           std::vector< std::vector<std::string> >& cnames,
@@ -191,7 +191,7 @@ public:
                           CVC4::Type& ret, bool isNested = false );
 
   static bool pushSygusDatatypeDef( Type t, std::string& dname,
-                                    std::vector< CVC4::Datatype* >& datatypes,
+                                    std::vector< CVC4::Datatype >& datatypes,
                                     std::vector< CVC4::Type>& sorts,
                                     std::vector< std::vector<CVC4::Expr> >& ops,
                                     std::vector< std::vector<std::string> >& cnames,
@@ -199,7 +199,7 @@ public:
                                     std::vector< bool >& allow_const,
                                     std::vector< std::vector< std::string > >& unresolved_gterm_sym );
 
-  static bool popSygusDatatypeDef( std::vector< CVC4::Datatype* >& datatypes,
+  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,
@@ -208,7 +208,7 @@ public:
                                    std::vector< std::vector< std::string > >& unresolved_gterm_sym );
 
   void setSygusStartIndex( std::string& fun, int startIndex,
-                           std::vector< CVC4::Datatype* >& datatypes,
+                           std::vector< CVC4::Datatype >& datatypes,
                            std::vector< CVC4::Type>& sorts,
                            std::vector< std::vector<CVC4::Expr> >& ops );
 
@@ -218,7 +218,7 @@ public:
 
   void defineSygusFuns();
 
-  void mkSygusDatatype( CVC4::Datatype* dt, std::vector<CVC4::Expr>& ops,
+  void mkSygusDatatype( CVC4::Datatype& dt, std::vector<CVC4::Expr>& ops,
                         std::vector<std::string>& cnames, std::vector< std::vector< CVC4::Type > >& cargs,
                         std::vector<std::string>& unresolved_gterm_sym,
                         std::map< CVC4::Type, CVC4::Type >& sygus_to_builtin );
@@ -314,10 +314,10 @@ private:
 
   void collectSygusLetArgs( CVC4::Expr e, std::vector< CVC4::Type >& sygusArgs, std::vector< CVC4::Expr >& builtinArgs );
 
-  void addSygusDatatypeConstructor( CVC4::Datatype* dt, CVC4::Expr op, std::string& cname, std::vector< CVC4::Type >& cargs,
+  void addSygusDatatypeConstructor( CVC4::Datatype& dt, CVC4::Expr op, std::string& cname, std::vector< CVC4::Type >& cargs,
                                     CVC4::Expr& let_body, std::vector< CVC4::Expr >& let_args, unsigned let_num_input_args );
 
-  Type processSygusNestedGTerm( int sub_dt_index, std::string& sub_dname, std::vector< CVC4::Datatype* >& datatypes,
+  Type processSygusNestedGTerm( int sub_dt_index, std::string& sub_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,
@@ -328,7 +328,7 @@ private:
                                 std::map< CVC4::Type, CVC4::Expr >& sygus_to_builtin_expr, Type sub_ret );
 
   void processSygusLetConstructor( std::vector< CVC4::Expr >& let_vars, int index,
-                                   std::vector< CVC4::Datatype* >& datatypes,
+                                   std::vector< CVC4::Datatype >& datatypes,
                                    std::vector< CVC4::Type>& sorts,
                                    std::vector< std::vector<CVC4::Expr> >& ops,
                                    std::vector< std::vector<std::string> >& cnames,
index e9b51c47b6a5c26bded9ddd8b875d68423a1c080..0771cfc064862b65a9fd5d61084e8a0cdc716533 100644 (file)
@@ -60,10 +60,10 @@ BooleanTermConverter::BooleanTermConverter(SmtEngine& smt) :
     d_ffDt = d_ff;
     d_ttDt = d_tt;
   } else {
-    Datatype* spec = new Datatype("BooleanTerm");
+    Datatype spec("BooleanTerm");
     // don't change the order; false is assumed to come first by the model postprocessor
-    spec->addConstructor(DatatypeConstructor("BT_False"));
-    spec->addConstructor(DatatypeConstructor("BT_True"));
+    spec.addConstructor(DatatypeConstructor("BT_False"));
+    spec.addConstructor(DatatypeConstructor("BT_True"));
     const Datatype& dt = NodeManager::currentNM()->toExprManager()->mkDatatypeType(spec).getDatatype();
     d_ffDt = NodeManager::currentNM()->mkNode(kind::APPLY_CONSTRUCTOR, Node::fromExpr(dt["BT_False"].getConstructor()));
     d_ttDt = NodeManager::currentNM()->mkNode(kind::APPLY_CONSTRUCTOR, Node::fromExpr(dt["BT_True"].getConstructor()));
@@ -255,13 +255,13 @@ const Datatype& BooleanTermConverter::convertDatatype(const Datatype& dt) throw(
           mySelfType = NodeManager::currentNM()->toExprManager()->mkSortConstructor(dt.getName() + "'", dt.getNumParameters());
           unresolvedTypes.insert(mySelfType);
         }
-        vector<Datatype*> newDtVector;
+        vector<Datatype> newDtVector;
         if(dt.isParametric()) {
-          newDtVector.push_back(new Datatype(dt.getName() + "'", dt.getParameters(), false));
+          newDtVector.push_back(Datatype(dt.getName() + "'", dt.getParameters(), false));
         } else {
-          newDtVector.push_back(new Datatype(dt.getName() + "'", false));
+          newDtVector.push_back(Datatype(dt.getName() + "'", false));
         }
-        Datatype * newDt = newDtVector.front();
+        Datatype& newDt = newDtVector.front();
         Debug("boolean-terms") << "found a Boolean arg in constructor " << (*c).getName() << endl;
         for(c = dt.begin(); c != dt.end(); ++c) {
           DatatypeConstructor ctor((*c).getName() + "'", (*c).getTesterName() + "'");
@@ -286,7 +286,7 @@ const Datatype& BooleanTermConverter::convertDatatype(const Datatype& dt) throw(
               }
             }
           }
-          newDt->addConstructor(ctor);
+          newDt.addConstructor(ctor);
         }
         vector<DatatypeType> newDttVector;
         NodeManager::currentNM()->toExprManager()->mkMutualDatatypeTypes(newDtVector, unresolvedTypes, newDttVector);