diff options
author | Morgan Deters <mdeters@cs.nyu.edu> | 2013-11-06 16:58:16 -0500 |
---|---|---|
committer | Tianyi Liang <tianyi-liang@uiowa.edu> | 2013-11-10 18:47:35 -0600 |
commit | 726603e0e5a5482cf98538079790747e43313276 (patch) | |
tree | 12e41e99a21a16cf9cff7374a84d9a6527f03c8b /src/expr/node.cpp | |
parent | 6c6f44c32a6bb957c1e82ae75fbf62db2e286595 (diff) |
Flatten libcvc4 build structure; remove some #include interdependences
Diffstat (limited to 'src/expr/node.cpp')
-rw-r--r-- | src/expr/node.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/expr/node.cpp b/src/expr/node.cpp index 30f7ce8b9..b1614f31b 100644 --- a/src/expr/node.cpp +++ b/src/expr/node.cpp @@ -15,6 +15,7 @@ **/ #include "expr/node.h" +#include "expr/attribute.h" #include "util/output.h" #include <iostream> @@ -51,4 +52,42 @@ UnknownTypeException::UnknownTypeException(TNode n) throw() : " its type cannot be computed until it is substituted away") { } +/** 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> +bool NodeTemplate<ref_count>::isConst() const { + assertTNodeNotExpired(); + Debug("isConst") << "Node::isConst() for: " << *this << std::endl; + if(isNull()) { + return false; + } + switch(getMetaKind()) { + case kind::metakind::CONSTANT: + Debug("isConst") << "Node::isConst() returning true, it's a CONSTANT" << std::endl; + return true; + case kind::metakind::VARIABLE: + Debug("isConst") << "Node::isConst() returning false, it's a VARIABLE" << std::endl; + return false; + default: + if(getAttribute(IsConstComputedAttr())) { + bool bval = getAttribute(IsConstAttr()); + Debug("isConst") << "Node::isConst() returning cached value " << (bval ? "true" : "false") << " for: " << *this << std::endl; + return bval; + } else { + bool bval = expr::TypeChecker::computeIsConst(NodeManager::currentNM(), *this); + Debug("isConst") << "Node::isConst() computed value " << (bval ? "true" : "false") << " for: " << *this << std::endl; + const_cast< NodeTemplate<ref_count>* >(this)->setAttribute(IsConstAttr(), bval); + const_cast< NodeTemplate<ref_count>* >(this)->setAttribute(IsConstComputedAttr(), true); + return bval; + } + } +} + +template bool NodeTemplate<true>::isConst() const; +template bool NodeTemplate<false>::isConst() const; + }/* CVC4 namespace */ |