From 680af6f4dc9e5d6616918e8fde18cd64774d0df5 Mon Sep 17 00:00:00 2001 From: Andrew Reynolds Date: Mon, 10 Sep 2012 22:29:17 +0000 Subject: [PATCH] modified getValue to return Expr instead of Node --- src/printer/cvc/cvc_printer.cpp | 2 +- src/printer/smt2/smt2_printer.cpp | 2 +- src/smt/smt_engine.cpp | 4 ++-- src/theory/model.cpp | 16 +++++++++------- src/theory/model.h | 12 +++++------- src/theory/quantifiers/first_order_model.cpp | 2 +- src/util/model.h | 5 +++++ 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/printer/cvc/cvc_printer.cpp b/src/printer/cvc/cvc_printer.cpp index 5803ad23f..9e61fb8df 100644 --- a/src/printer/cvc/cvc_printer.cpp +++ b/src/printer/cvc/cvc_printer.cpp @@ -777,7 +777,7 @@ void CvcPrinter::toStream(std::ostream& out, Model* m, Command* c, int c_type ) } out << "): "; } - out << tm->getValue( n ); + out << Node::fromExpr( tm->getValue( n.toExpr() ) ); out << ";" << std::endl; /* diff --git a/src/printer/smt2/smt2_printer.cpp b/src/printer/smt2/smt2_printer.cpp index 9400b7732..6c6d2a576 100644 --- a/src/printer/smt2/smt2_printer.cpp +++ b/src/printer/smt2/smt2_printer.cpp @@ -558,7 +558,7 @@ void Smt2Printer::toStream(std::ostream& out, Model* m, Command* c, int c_type ) out << ") " << tn; } out << " "; - out << tm->getValue( n ); + out << Node::fromExpr( tm->getValue( n.toExpr() ) ); out << ")" << std::endl; /* diff --git a/src/smt/smt_engine.cpp b/src/smt/smt_engine.cpp index b9732c32e..6e6ee365a 100644 --- a/src/smt/smt_engine.cpp +++ b/src/smt/smt_engine.cpp @@ -1768,7 +1768,7 @@ Expr SmtEngine::getValue(const Expr& e) theory::TheoryModel* m = d_theoryEngine->getModel(); Node resultNode; if( m ){ - resultNode = m->getValue( n ); + resultNode = Node::fromExpr( m->getValue( n.toExpr() ) ); } Trace("smt") << "--- got value " << n << " = " << resultNode << endl; // type-check the result we got @@ -1846,7 +1846,7 @@ CVC4::SExpr SmtEngine::getAssignment() throw(ModalException, AssertionException) theory::TheoryModel* m = d_theoryEngine->getModel(); Node resultNode; if( m ){ - resultNode = m->getValue( n ); + resultNode = Node::fromExpr( m->getValue( n.toExpr() ) ); } // type-check the result we got diff --git a/src/theory/model.cpp b/src/theory/model.cpp index 51d5a77b5..67640c309 100644 --- a/src/theory/model.cpp +++ b/src/theory/model.cpp @@ -46,6 +46,15 @@ void TheoryModel::reset(){ d_rep_set.clear(); } +Expr TheoryModel::getValue( const Expr& expr ){ + Node n = Node::fromExpr( expr ); + //apply substitutions + Node nn = d_substitutions.apply( n ); + //get value in model + Node ret = getModelValue( nn ); + return ret.toExpr(); +} + void TheoryModel::toStream( std::ostream& out ){ /*//for debugging eq::EqClassesIterator eqcs_i = eq::EqClassesIterator( &d_equalityEngine ); @@ -114,13 +123,6 @@ Node TheoryModel::getModelValue( TNode n ){ } } -Node TheoryModel::getValue( TNode n ){ - //apply substitutions - Node nn = d_substitutions.apply( n ); - //get value in model - return getModelValue( nn ); -} - Node TheoryModel::getDomainValue( TypeNode tn, std::vector< Node >& exclude ){ if( d_rep_set.d_type_reps.find( tn )!=d_rep_set.d_type_reps.end() ){ //try to find a pre-existing arbitrary element diff --git a/src/theory/model.h b/src/theory/model.h index 086e39f3e..06618e07c 100644 --- a/src/theory/model.h +++ b/src/theory/model.h @@ -70,11 +70,6 @@ protected: */ Node getModelValue( TNode n ); public: - /** - * Get value function. This should be called only after a ModelBuilder has called buildModel(...) - * on this model. - */ - Node getValue( TNode n ); /** get existing domain value, with possible exclusions * This function returns a term in d_rep_set.d_type_reps[tn] but not in exclude */ @@ -112,13 +107,16 @@ public: Node getRepresentative( Node a ); bool areEqual( Node a, Node b ); bool areDisequal( Node a, Node b ); +public: + /** get value function */ + Expr getValue( const Expr& expr ); + /** to stream function */ + void toStream( std::ostream& out ); public: /** print representative debug function */ void printRepresentativeDebug( const char* c, Node r ); /** print representative function */ void printRepresentative( std::ostream& out, Node r ); - /** to stream function */ - void toStream( std::ostream& out ); }; /** Default model class diff --git a/src/theory/quantifiers/first_order_model.cpp b/src/theory/quantifiers/first_order_model.cpp index c3be1cdaf..b03261195 100644 --- a/src/theory/quantifiers/first_order_model.cpp +++ b/src/theory/quantifiers/first_order_model.cpp @@ -274,7 +274,7 @@ Node FirstOrderModel::evaluateTerm( Node n, int& depIndex, RepSetIterator* ri ){ if( !n.hasAttribute(InstConstantAttribute()) ){ //if evaluating a ground term, just consult the standard getValue functionality depIndex = -1; - return getValue( n ); + return getModelValue( n ); }else{ Node val; depIndex = ri->getNumTerms()-1; diff --git a/src/util/model.h b/src/util/model.h index 747247ae1..ca7565aaa 100644 --- a/src/util/model.h +++ b/src/util/model.h @@ -22,6 +22,8 @@ #include #include +#include "expr/expr.h" + namespace CVC4 { class Command; @@ -52,6 +54,9 @@ public: /** get type of command */ int getCommandType( int i ) { return d_command_types[i]; } public: + /** get value */ + virtual Expr getValue( const Expr& expr ) = 0; + /** to stream function */ virtual void toStream(std::ostream& out) = 0; };/* class Model */ -- 2.30.2