also some base infrastructure for the new ::isConst().
static Node exportConstant(TNode n, NodeManager* to);
Node exportInternal(TNode n, ExprManager* from, ExprManager* to, ExprManagerMapCollection& vmap) {
- if(n.getMetaKind() == kind::metakind::CONSTANT) {
+ if(n.isConst()) {
return exportConstant(n, NodeManager::fromExprManager(to));
- } else if(n.getMetaKind() == kind::metakind::VARIABLE) {
+ } else if(n.isVar()) {
Expr from_e(from, new Node(n));
Expr& to_e = vmap.d_typeMap[from_e];
if(! to_e.isNull()) {
namespace expr {
static Node exportConstant(TNode n, NodeManager* to) {
- Assert(n.getMetaKind() == kind::metakind::CONSTANT);
+ Assert(n.isConst());
switch(n.getKind()) {
${exportConstant_cases}
mkConst_implementations=
exportConstant_cases=
+typerules=
+construles=
+
seen_theory=false
seen_theory_builtin=false
"
}
+function construle {
+ # isconst OPERATOR isconst-checking-class
+ lineno=${BASH_LINENO[0]}
+ check_theory_seen
+ construles="${construles}
+ case kind::$1:
+ return $2::computeIsConst(nodeManager, n);
+"
+}
+
function sort {
# sort TYPE cardinality [well-founded ground-term header | not-well-founded] ["comment"]
lineno=${BASH_LINENO[0]}
exportConstant_cases \
typechecker_includes \
typerules \
+ construles \
; do
eval text="\${text//\\\$\\{$var\\}/\${$var}}"
done
check_theory_seen
}
+function construle {
+ # construle OPERATOR isconst-checking-class
+ lineno=${BASH_LINENO[0]}
+ check_theory_seen
+}
+
function rewriter {
# properties prop*
lineno=${BASH_LINENO[0]}
check_theory_seen
}
+function construle {
+ # construle OPERATOR isconst-checking-class
+ lineno=${BASH_LINENO[0]}
+ check_theory_seen
+}
+
function rewriter {
# rewriter class header
lineno=${BASH_LINENO[0]}
* Returns true if this node represents a constant
* @return true if const
*/
- inline bool isConst() const {
- assertTNodeNotExpired();
- return getMetaKind() == kind::metakind::CONSTANT;
- }
+ inline bool isConst() const;
/**
* Returns true if this node represents a constant
#include "expr/attribute.h"
#include "expr/node_manager.h"
+#include "expr/type_checker.h"
namespace CVC4 {
return NodeManager::currentNM()->getType(*this, check);
}
+/** Is this node constant? (and has that been computed yet?) */
+struct IsConstTag { };
+struct IsConstComputedTag { };
+typedef expr::Attribute<IsConstTag, bool> IsConstAttr;
+typedef expr::Attribute<IsConstComputedTag, bool> IsConstComputedAttr;
+
+template <bool ref_count>
+inline bool
+NodeTemplate<ref_count>::isConst() const {
+ assertTNodeNotExpired();
+ if(isNull()) {
+ return false;
+ }
+ switch(getMetaKind()) {
+ case kind::metakind::CONSTANT:
+ return true;
+ case kind::metakind::VARIABLE:
+ return false;
+ default:
+ if(getAttribute(IsConstComputedAttr())) {
+ return getAttribute(IsConstAttr());
+ } else {
+ bool bval = expr::TypeChecker::computeIsConst(NodeManager::currentNM(), *this);
+ const_cast< NodeTemplate<ref_count>* >(this)->setAttribute(IsConstAttr(), bval);
+ const_cast< NodeTemplate<ref_count>* >(this)->setAttribute(IsConstComputedAttr(), true);
+ return bval;
+ }
+ }
+}
+
template <bool ref_count>
inline Node
NodeTemplate<ref_count>::substitute(TNode node, TNode replacement) const {
// Definition of an attribute for the variable name.
// TODO: hide this attribute behind a NodeManager interface.
namespace attr {
- struct VarNameTag {};
- struct SortArityTag {};
+ struct VarNameTag { };
+ struct SortArityTag { };
}/* CVC4::expr::attr namespace */
typedef Attribute<attr::VarNameTag, std::string> VarNameAttr;
};/* struct NodeManager::NVStorage<N> */
// attribute tags
- struct TypeTag {};
- struct TypeCheckedTag;
+ struct TypeTag { };
+ struct TypeCheckedTag { };
// NodeManager's attributes. These aren't exposed outside of this
// class; use the getters.
#include "cvc4_private.h"
+// ordering dependence
+#include "expr/node.h"
+
#ifndef __CVC4__EXPR__TYPE_CHECKER_H
#define __CVC4__EXPR__TYPE_CHECKER_H
-#include "expr/node.h"
-
namespace CVC4 {
namespace expr {
static TypeNode computeType(NodeManager* nodeManager, TNode n, bool check = false)
throw (TypeCheckingExceptionPrivate, AssertionException);
+ static bool computeIsConst(NodeManager* nodeManager, TNode n)
+ throw (AssertionException);
+
};/* class TypeChecker */
}/* CVC4::expr namespace */
}/* TypeChecker::computeType */
+bool TypeChecker::computeIsConst(NodeManager* nodeManager, TNode n)
+ throw (AssertionException) {
+
+ Assert(n.getMetaKind() == kind::metakind::OPERATOR || n.getMetaKind() == kind::metakind::PARAMETERIZED);
+
+ switch(n.getKind()) {
+${construles}
+
+#line 74 "${template}"
+
+ default:;
+ }
+
+ return false;
+
+}/* TypeChecker::computeIsConst */
+
}/* CVC4::expr namespace */
}/* CVC4 namespace */
}
// variables
- if(n.getMetaKind() == kind::metakind::VARIABLE) {
+ if(n.isVar()) {
string s;
if(n.getAttribute(expr::VarNameAttr(), s)) {
out << s;
}
// constants
- if(n.getMetaKind() == kind::metakind::CONSTANT) {
+ if(n.isConst()) {
switch(n.getKind()) {
case kind::BITVECTOR_TYPE:
out << "BITVECTOR(" << n.getConst<BitVectorSize>().size << ")";
// the count beyond the threshold already, we've done the same
// for all subexpressions, so it isn't useful to traverse and
// increment again (they'll be dagified anyway).
- return current.getMetaKind() == kind::metakind::VARIABLE ||
- current.getMetaKind() == kind::metakind::CONSTANT ||
+ return current.isVar() ||
+ current.isConst() ||
( ( current.getKind() == kind::NOT ||
current.getKind() == kind::UMINUS ) &&
- ( current[0].getMetaKind() == kind::metakind::VARIABLE ||
- current[0].getMetaKind() == kind::metakind::CONSTANT ) ) ||
+ ( current[0].isVar() ||
+ current[0].isConst() ) ) ||
current.getKind() == kind::SORT_TYPE ||
d_nodeCount[current] > d_threshold;
}
}
// variable
- if(n.getMetaKind() == kind::metakind::VARIABLE) {
+ if(n.isVar()) {
string s;
if(n.getAttribute(expr::VarNameAttr(), s)) {
out << s;
}
// constant
- if(n.getMetaKind() == kind::metakind::CONSTANT) {
+ if(n.isConst()) {
switch(n.getKind()) {
case kind::TYPE_CONSTANT:
switch(n.getConst<TypeConstant>()) {
}
if( theory::Theory::theoryOf(n) == theory::THEORY_BOOL &&
- n.getMetaKind() != kind::metakind::VARIABLE ) {
+ !n.isVar() ) {
// If we were called with something other than a theory atom (or
// Boolean variable), we get a SatLiteral that is definitionally
// equal to it.
( d_definedFunctions->find(n.getOperator()) !=
d_definedFunctions->end() ) &&
n.getNumChildren() == 0 ) ||
- n.getMetaKind() == kind::metakind::VARIABLE ), e,
+ n.isVar() ), e,
"expected variable or defined-function application "
"in addToAssignment(),\ngot %s", e.toString().c_str() );
if(!options::produceAssignments()) {
Assert((*i).getNumChildren() == 0);
v.push_back((*i).getOperator().toString());
} else {
- Assert((*i).getMetaKind() == kind::metakind::VARIABLE);
+ Assert((*i).isVar());
v.push_back((*i).toString());
}
v.push_back(resultNode.toString());
namespace theory {
namespace arith {
-bool isVariable(TNode t){
- return t.getMetaKind() == kind::metakind::VARIABLE;
-}
-
bool ArithRewriter::isAtom(TNode n) {
return arith::isRelationOperator(n.getKind());
}
RewriteResponse ArithRewriter::rewriteConstant(TNode t){
- Assert(t.getMetaKind() == kind::metakind::CONSTANT);
+ Assert(t.isConst());
Assert(t.getKind() == kind::CONST_RATIONAL);
return RewriteResponse(REWRITE_DONE, t);
}
RewriteResponse ArithRewriter::rewriteVariable(TNode t){
- Assert(isVariable(t));
+ Assert(t.isVar());
return RewriteResponse(REWRITE_DONE, t);
}
}
RewriteResponse ArithRewriter::preRewriteTerm(TNode t){
- if(t.getMetaKind() == kind::metakind::CONSTANT){
+ if(t.isConst()){
return rewriteConstant(t);
- }else if(isVariable(t)){
+ }else if(t.isVar()){
return rewriteVariable(t);
}else if(t.getKind() == kind::MINUS){
return rewriteMinus(t, true);
}
}
RewriteResponse ArithRewriter::postRewriteTerm(TNode t){
- if(t.getMetaKind() == kind::metakind::CONSTANT){
+ if(t.isConst()){
return rewriteConstant(t);
- }else if(isVariable(t)){
+ }else if(t.isVar()){
return rewriteVariable(t);
}else if(t.getKind() == kind::MINUS){
return rewriteMinus(t, false);
case IMPLIES:
// == 3-FINITE VALUE SET : Collect information ==
if(n[1].getKind() == EQUAL &&
- n[1][0].getMetaKind() == metakind::VARIABLE &&
+ n[1][0].isVar() &&
defTrue.find(n) != defTrue.end()){
Node eqTo = n[1][1];
Node rewriteEqTo = Rewriter::rewrite(eqTo);
break;
}
Node var, c1, c2;
- if(n[0][0].getMetaKind() == metakind::VARIABLE &&
- n[0][1].getMetaKind() == metakind::CONSTANT) {
+ if(n[0][0].isVar() &&
+ n[0][1].isConst()) {
var = n[0][0];
c1 = n[0][1];
- } else if(n[0][1].getMetaKind() == metakind::VARIABLE &&
- n[0][0].getMetaKind() == metakind::CONSTANT) {
+ } else if(n[0][1].isVar() &&
+ n[0][0].isConst()) {
var = n[0][1];
c1 = n[0][0];
} else {
*
* variable := n
* where
- * n.getMetaKind() == metakind::VARIABLE or is foreign
+ * n.isVar() or is foreign
* n.getType() \in {Integer, Real}
*
* constant := n
}
bool isMetaKindVariable() const {
- return getNode().getMetaKind() == kind::metakind::VARIABLE;
+ return getNode().isVar();
}
bool operator<(const Variable& v) const {
case kind::LT:
case kind::GEQ:
case kind::GT:
- if (in[0].getMetaKind() == kind::metakind::VARIABLE) {
+ if (in[0].isVar()) {
d_learner.addBound(in);
}
break;
{
d_ppFacts.push_back(in);
d_ppEqualityEngine.assertEquality(in, true, in);
- if (in[0].getMetaKind() == kind::metakind::VARIABLE && !in[1].hasSubterm(in[0])) {
+ if (in[0].isVar() && !in[1].hasSubterm(in[0])) {
outSubstitutions.addSubstitution(in[0], in[1]);
return PP_ASSERT_STATUS_SOLVED;
}
- if (in[1].getMetaKind() == kind::metakind::VARIABLE && !in[0].hasSubterm(in[1])) {
+ if (in[1].isVar() && !in[0].hasSubterm(in[1])) {
outSubstitutions.addSubstitution(in[1], in[0]);
return PP_ASSERT_STATUS_SOLVED;
}
Debug("circuit-prop") << "CircuitPropagator::propagate(): assigned to " << (assignment ? "true" : "false") << std::endl;
// Is this an atom
- bool atom = Theory::theoryOf(current) != THEORY_BOOL || current.getMetaKind() == kind::metakind::VARIABLE;
+ bool atom = Theory::theoryOf(current) != THEORY_BOOL || current.isVar();
// If an atom, add to the list for simplification
if (atom) {
switch(in.getKind()) {
case kind::EQUAL:
- if (in[0].getMetaKind() == kind::metakind::VARIABLE && !in[1].hasSubterm(in[0])) {
+ if (in[0].isVar() && !in[1].hasSubterm(in[0])) {
++(d_statistics.d_solveSubstitutions);
outSubstitutions.addSubstitution(in[0], in[1]);
return PP_ASSERT_STATUS_SOLVED;
}
- if (in[1].getMetaKind() == kind::metakind::VARIABLE && !in[0].hasSubterm(in[1])) {
+ if (in[1].isVar() && !in[0].hasSubterm(in[1])) {
++(d_statistics.d_solveSubstitutions);
outSubstitutions.addSubstitution(in[1], in[0]);
return PP_ASSERT_STATUS_SOLVED;
template<> inline
bool RewriteRule<SolveEq>::applies(TNode node) {
if (node.getKind() != kind::EQUAL ||
- (node[0].getMetaKind() == kind::metakind::VARIABLE && !node[1].hasSubterm(node[0])) ||
- (node[1].getMetaKind() == kind::metakind::VARIABLE && !node[0].hasSubterm(node[1]))) {
+ (node[0].isVar() && !node[1].hasSubterm(node[0])) ||
+ (node[1].isVar() && !node[0].hasSubterm(node[1]))) {
return false;
}
return true;
check_theory_seen
}
+function construle {
+ # construle OPERATOR isconst-checking-class
+ lineno=${BASH_LINENO[0]}
+ check_theory_seen
+}
+
function rewriter {
# rewriter class header
lineno=${BASH_LINENO[0]}
check_theory_seen
}
+function construle {
+ # construle OPERATOR isconst-checking-class
+ lineno=${BASH_LINENO[0]}
+ check_theory_seen
+}
+
function rewriter {
# rewriter class header
class="$1"
check_theory_seen
}
+function construle {
+ # construle OPERATOR isconst-checking-class
+ lineno=${BASH_LINENO[0]}
+ check_theory_seen
+}
+
function instantiator {
# instantiator class header
lineno=${BASH_LINENO[0]}
Node TheoryModel::getValue( TNode n ){
Debug("model") << "TheoryModel::getValue " << n << std::endl;
- kind::MetaKind metakind = n.getMetaKind();
-
//// special case: prop engine handles boolean vars
- //if(metakind == kind::metakind::VARIABLE && n.getType().isBoolean()) {
+ //if(n.isVar() && n.getType().isBoolean()) {
// Debug("model") << "-> Propositional variable." << std::endl;
// return d_te->getPropEngine()->getValue( n );
//}
// special case: value of a constant == itself
- if(metakind == kind::metakind::CONSTANT) {
+ if(n.isConst()) {
Debug("model") << "-> Constant." << std::endl;
return n;
}
Node nn;
if( n.getNumChildren()>0 ){
std::vector< Node > children;
- if( metakind == kind::metakind::PARAMETERIZED ){
+ if( n.getMetaKind() == kind::metakind::PARAMETERIZED ){
Debug("model-debug") << "get operator: " << n.getOperator() << std::endl;
children.push_back( n.getOperator() );
}
nn = Rewriter::rewrite( nn );
// special case: value of a constant == itself
- if(metakind == kind::metakind::CONSTANT) {
+ if(n.isConst()) {
Debug("model") << "-> Theory-interpreted term." << std::endl;
return nn;
}else{
while( !eqc_i.isFinished() ){
Node n = *eqc_i;
//check if this is constant, if so, we will use it as representative
- if( n.getMetaKind()==kind::metakind::CONSTANT ){
+ if( n.isConst() ){
const_rep = n;
}
//theory-specific information needed
eq::EqClassIterator eqc_i = eq::EqClassIterator( eqc, &d_equalityEngine );
while( !eqc_i.isFinished() ){
//do not print things that have interpretations in model
- if( (*eqc_i).getMetaKind()!=kind::metakind::CONSTANT && !hasInterpretedValue( *eqc_i ) ){
+ if( !(*eqc_i).isConst() && !hasInterpretedValue( *eqc_i ) ){
out << "(" << (*eqc_i) << " " << rep << ")" << std::endl;
}
++eqc_i;
//if not set already, rewrite and consult model for interpretation
if( !setVal ){
val = Rewriter::rewrite( val );
- if( val.getMetaKind()!=kind::metakind::CONSTANT ){
+ if( !val.isConst() ){
//FIXME: we cannot do this until we trust all theories collectModelInfo!
//val = d_model->getInterpretedValue( val );
//val = d_model->getRepresentative( val );
switch(mode) {
case THEORY_OF_TYPE_BASED:
// Constants, variables, 0-ary constructors
- if (node.getMetaKind() == kind::metakind::VARIABLE || node.getMetaKind() == kind::metakind::CONSTANT) {
+ if (node.isVar() || node.isConst()) {
return theoryOf(node.getType());
}
// Equality is owned by the theory that owns the domain
break;
case THEORY_OF_TERM_BASED:
// Variables
- if (node.getMetaKind() == kind::metakind::VARIABLE) {
+ if (node.isVar()) {
if (theoryOf(node.getType()) != theory::THEORY_BOOL) {
// We treat the varibables as uninterpreted
return s_uninterpretedSortOwner;
}
}
// Constants
- if (node.getMetaKind() == kind::metakind::CONSTANT) {
+ if (node.isConst()) {
// Constants go to the theory of the type
return theoryOf(node.getType());
}
*/
virtual PPAssertStatus ppAssert(TNode in, SubstitutionMap& outSubstitutions) {
if (in.getKind() == kind::EQUAL) {
- if (in[0].getMetaKind() == kind::metakind::VARIABLE && !in[1].hasSubterm(in[0])) {
+ if (in[0].isVar() && !in[1].hasSubterm(in[0])) {
outSubstitutions.addSubstitution(in[0], in[1]);
return PP_ASSERT_STATUS_SOLVED;
}
- if (in[1].getMetaKind() == kind::metakind::VARIABLE && !in[0].hasSubterm(in[1])) {
+ if (in[1].isVar() && !in[0].hasSubterm(in[1])) {
outSubstitutions.addSubstitution(in[1], in[0]);
return PP_ASSERT_STATUS_SOLVED;
}
- if (in[0].getMetaKind() == kind::metakind::CONSTANT && in[1].getMetaKind() == kind::metakind::CONSTANT) {
+ if (in[0].isConst() && in[1].isConst()) {
if (in[0] != in[1]) {
return PP_ASSERT_STATUS_CONFLICT;
}
}
if(t.getNumChildren() == 0) {
- if(t.getMetaKind() == kind::metakind::CONSTANT) {
- Assert(n.getMetaKind() == kind::metakind::CONSTANT);
+ if(t.isConst()) {
+ Assert(n.isConst());
Debug("ufsymm:match") << "UFSYMM we have constants, failing match" << endl;
return false;
}
- Assert(t.getMetaKind() == kind::metakind::VARIABLE &&
- n.getMetaKind() == kind::metakind::VARIABLE);
+ Assert(t.isVar() &&
+ n.isVar());
t = find(t);
n = find(n);
Debug("ufsymm:match") << "UFSYMM variable match " << t << " , " << n << endl;
} else if((*i).getKind() == kind::IFF ||
(*i).getKind() == kind::EQUAL) {
kids.push_back(normInternal(*i));
- if((*i)[0].getMetaKind() == kind::metakind::VARIABLE ||
- (*i)[1].getMetaKind() == kind::metakind::VARIABLE) {
+ if((*i)[0].isVar() ||
+ (*i)[1].isVar()) {
d_termEqs[(*i)[0]].insert((*i)[1]);
d_termEqs[(*i)[1]].insert((*i)[0]);
Debug("ufsymm:eq") << "UFSYMM " << (*i)[0] << " <==> " << (*i)[1] << endl;
case kind::IFF:
case kind::EQUAL:
- if(n[0].getMetaKind() == kind::metakind::VARIABLE ||
- n[1].getMetaKind() == kind::metakind::VARIABLE) {
+ if(n[0].isVar() ||
+ n[1].isVar()) {
d_termEqs[n[0]].insert(n[1]);
d_termEqs[n[1]].insert(n[0]);
Debug("ufsymm:eq") << "UFSYMM " << n[0] << " <==> " << n[1] << endl;
}
}else{
if(negateNode){
- if(child.getMetaKind() == kind::metakind::CONSTANT) {
+ if(child.isConst()) {
if((k == kind::AND && child.getConst<bool>()) ||
(k == kind::OR && !child.getConst<bool>())) {
buffer.clear();
buffer.push_back(negate(child));
}
}else{
- if(child.getMetaKind() == kind::metakind::CONSTANT) {
+ if(child.isConst()) {
if((k == kind::OR && child.getConst<bool>()) ||
(k == kind::AND && !child.getConst<bool>())) {
buffer.clear();
base = base[0];
polarity = !polarity;
}
- if(n.getMetaKind() == kind::metakind::CONSTANT) {
+ if(n.isConst()) {
return NodeManager::currentNM()->mkConst(!n.getConst<bool>());
}
if(polarity){