#include "sat.h"
#include "prop/cnf_stream.h"
#include "prop/prop_engine.h"
+#include "theory/theory_engine.h"
#include "expr/node.h"
#include "util/Assert.h"
#include "util/output.h"
namespace CVC4 {
namespace prop {
-CnfStream::CnfStream(SatInputInterface *satSolver) :
- d_satSolver(satSolver) {
+CnfStream::CnfStream(SatInputInterface *satSolver, theory::Registrar reg) :
+ d_satSolver(satSolver), d_registrar(reg) {
}
void CnfStream::recordTranslation(TNode node) {
}
}
-TseitinCnfStream::TseitinCnfStream(SatInputInterface* satSolver) :
- CnfStream(satSolver) {
+
+TseitinCnfStream::TseitinCnfStream(SatInputInterface* satSolver, theory::Registrar reg) :
+ CnfStream(satSolver, reg) {
}
void CnfStream::assertClause(TNode node, SatClause& c) {
// Here, you can have it
Debug("cnf") << "newLiteral(" << node << ") => " << lit << endl;
+ // have to keep track of this, because with the call to preRegister(),
+ // the cnf stream is re-entrant!
+ bool wasAssertingLemma = d_assertingLemma;
+ d_registrar.preRegister(node);
+ d_assertingLemma = wasAssertingLemma;
+
return lit;
}
SatLiteral CnfStream::getLiteral(TNode node) {
TranslationCache::iterator find = d_translationCache.find(node);
- Assert(find != d_translationCache.end(), "Literal not in the CNF Cache: %s", node.toString().c_str());
+ Assert(find != d_translationCache.end(), "Literal not in the CNF Cache: %s\n", node.toString().c_str());
SatLiteral literal = find->second.literal;
Debug("cnf") << "CnfStream::getLiteral(" << node << ") => " << literal << std::endl;
return literal;
#include "expr/node.h"
#include "prop/sat.h"
+#include "theory/registrar.h"
#include <ext/hash_map>
protected:
+ theory::Registrar d_registrar;
+
/** Top level nodes that we translated */
std::vector<TNode> d_translationTrail;
* set of clauses and sends them to the given sat solver.
* @param satSolver the sat solver to use
*/
- CnfStream(SatInputInterface* satSolver);
+ CnfStream(SatInputInterface* satSolver, theory::Registrar r);
/**
* Destructs a CnfStream. This implementation does nothing, but we
* Constructs the stream to use the given sat solver.
* @param satSolver the sat solver to use
*/
- TseitinCnfStream(SatInputInterface* satSolver);
+ TseitinCnfStream(SatInputInterface* satSolver, theory::Registrar reg);
private:
#include "sat.h"
#include "theory/theory_engine.h"
+#include "theory/registrar.h"
#include "util/Assert.h"
#include "util/options.h"
#include "util/output.h"
d_context(context) {
Debug("prop") << "Constructing the PropEngine" << endl;
d_satSolver = new SatSolver(this, d_theoryEngine, d_context);
- d_cnfStream = new CVC4::prop::TseitinCnfStream(d_satSolver);
+ theory::Registrar reg(d_theoryEngine);
+ d_cnfStream = new CVC4::prop::TseitinCnfStream(d_satSolver, reg);
d_satSolver->setCnfStream(d_cnfStream);
}
throw(NoSuchFunctionException, AssertionException) {
Debug("smt") << "push_back assertion " << n << endl;
smt.d_haveAdditions = true;
- smt.d_propEngine->assertFormula(SmtEnginePrivate::preprocess(smt, n));
+ Node node = SmtEnginePrivate::preprocess(smt, n);
+ smt.d_propEngine->assertFormula(node);
}
void SmtEngine::ensureBoolean(const BoolExpr& e) {
shared_term_manager.cpp \
shared_data.h \
shared_data.cpp \
+ registrar.h \
rewriter.h \
rewriter_attributes.h \
rewriter.cpp \
--- /dev/null
+#include "cvc4_private.h"
+
+#ifndef __CVC4__THEORY_REGISTRAR_H
+#define __CVC4__THEORY_REGISTRAR_H
+#include "theory/theory_engine.h"
+
+namespace CVC4 {
+namespace theory {
+
+class Registrar {
+private:
+ TheoryEngine* d_theoryEngine;
+
+public:
+ Registrar() : d_theoryEngine(NULL){ }
+
+ Registrar(TheoryEngine* te) : d_theoryEngine(te){ }
+
+ void preRegister(Node n){
+ if(d_theoryEngine != NULL){
+ d_theoryEngine->preRegister(n);
+ }
+ }
+
+};/* class Registrar */
+
+
+}/* CVC4::theory namespace */
+}/* CVC4 namespace */
+
+#endif /* __CVC4__THEORY_REGISTRAR_H */
};
Node TheoryEngine::preprocess(TNode node) {
-
// Remove ITEs and rewrite the node
Node preprocessed = Rewriter::rewrite(removeITEs(node));
+ return preprocessed;
+}
+void TheoryEngine::preRegister(TNode preprocessed) {
// If we are pre-registered already we are done
if (preprocessed.getAttribute(PreRegistered())) {
- return preprocessed;
+ return;
}
// Do a topological sort of the subexpressions and preregister them
}
}
}
-
- return preprocessed;
}
/**
* @param n the node to preprocess
*/
Node preprocess(TNode n);
+ void preRegister(TNode preprocessed);
/**
* Assert the formula to the appropriate theory.
#include "prop/prop_engine.h"
#include "prop/sat.h"
#include "smt/smt_engine.h"
+#include "theory/registrar.h"
using namespace CVC4;
using namespace CVC4::context;
d_context = new Context;
d_nodeManager = new NodeManager(d_context);
d_satSolver = new FakeSatSolver;
- d_cnfStream = new CVC4::prop::TseitinCnfStream(d_satSolver);
+ d_cnfStream = new CVC4::prop::TseitinCnfStream(d_satSolver, theory::Registrar());
}
void tearDown() {