summaryrefslogtreecommitdiff
path: root/src/expr/node.h
diff options
context:
space:
mode:
authorMorgan Deters <mdeters@gmail.com>2012-08-03 20:39:25 +0000
committerMorgan Deters <mdeters@gmail.com>2012-08-03 20:39:25 +0000
commit3daaecd22fe5f6147cb08e5a4e08177b33a2daa2 (patch)
tree46cb65c3673a5678a7779ff970aea9460233f1f1 /src/expr/node.h
parente26a44d5f98a9953dffeb07b29a21e7efd501684 (diff)
fix uses of getMetaKind() from outside the expr package. (they now use isConst() and isVar() as appropriate)
also some base infrastructure for the new ::isConst().
Diffstat (limited to 'src/expr/node.h')
-rw-r--r--src/expr/node.h36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/expr/node.h b/src/expr/node.h
index b0fda3354..cada443a1 100644
--- a/src/expr/node.h
+++ b/src/expr/node.h
@@ -442,10 +442,7 @@ public:
* 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
@@ -917,6 +914,7 @@ inline std::ostream& operator<<(std::ostream& out,
#include "expr/attribute.h"
#include "expr/node_manager.h"
+#include "expr/type_checker.h"
namespace CVC4 {
@@ -1263,6 +1261,36 @@ TypeNode NodeTemplate<ref_count>::getType(bool check) const
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 {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback