* src/expr/attribute.h: fixed an issue with "const pointer"-valued
authorMorgan Deters <mdeters@gmail.com>
Mon, 22 Feb 2010 20:51:01 +0000 (20:51 +0000)
committerMorgan Deters <mdeters@gmail.com>
Mon, 22 Feb 2010 20:51:01 +0000 (20:51 +0000)
  attributes.

* src/expr/attribute.h, src/expr/node_manager.h, src/expr/node.h:
  hasAttribute() and getAttribute() are now const member functions.

src/expr/attribute.h
src/expr/node.h
src/expr/node_manager.h

index 54500d0d5a27bc98b9bc52a1cc97a8cb1c138f4a..95433688ec289b952cc4bad3f419b4116b062a6e 100644 (file)
@@ -100,7 +100,7 @@ struct KindValueToTableValueMapping<const T*> {
   inline static void* convert(const T* const& t) {
     return reinterpret_cast<void*>(const_cast<T*>(t));
   }
-  inline static const T* convertBack(const void*& t) {
+  inline static const T* convertBack(const void* const& t) {
     return reinterpret_cast<const T*>(t);
   }
 };
@@ -381,16 +381,16 @@ public:
 
   template <class AttrKind>
   typename AttrKind::value_type getAttribute(const Node& n,
-                                             const AttrKind&);
+                                             const AttrKind&) const;
 
   template <class AttrKind>
   bool hasAttribute(const Node& n,
-                    const AttrKind&);
+                    const AttrKind&) const;
 
   template <class AttrKind>
   bool hasAttribute(const Node& n,
                     const AttrKind&,
-                    typename AttrKind::value_type*);
+                    typename AttrKind::value_type*) const;
 
   template <class AttrKind>
   void setAttribute(const Node& n,
@@ -406,6 +406,9 @@ struct getTable<bool> {
   static inline table_type& get(AttributeManager& am) {
     return am.d_bools;
   }
+  static inline const table_type& get(const AttributeManager& am) {
+    return am.d_bools;
+  }
 };
 
 template <>
@@ -414,6 +417,9 @@ struct getTable<uint64_t> {
   static inline table_type& get(AttributeManager& am) {
     return am.d_ints;
   }
+  static inline const table_type& get(const AttributeManager& am) {
+    return am.d_ints;
+  }
 };
 
 template <>
@@ -422,6 +428,9 @@ struct getTable<Node> {
   static inline table_type& get(AttributeManager& am) {
     return am.d_exprs;
   }
+  static inline const table_type& get(const AttributeManager& am) {
+    return am.d_exprs;
+  }
 };
 
 template <>
@@ -430,28 +439,34 @@ struct getTable<std::string> {
   static inline table_type& get(AttributeManager& am) {
     return am.d_strings;
   }
+  static inline const table_type& get(const AttributeManager& am) {
+    return am.d_strings;
+  }
 };
 
 template <class T>
-struct getTable<T*> {
+struct getTable<const T*> {
   typedef AttrHash<void*> table_type;
   static inline table_type& get(AttributeManager& am) {
     return am.d_ptrs;
   }
+  static inline const table_type& get(const AttributeManager& am) {
+    return am.d_ptrs;
+  }
 };
 
 // ATTRIBUTE MANAGER IMPLEMENTATIONS ===========================================
 
 template <class AttrKind>
 typename AttrKind::value_type AttributeManager::getAttribute(const Node& n,
-                                                             const AttrKind&) {
+                                                             const AttrKind&) const {
 
   typedef typename AttrKind::value_type value_type;
   typedef KindValueToTableValueMapping<value_type> mapping;
   typedef typename getTable<value_type>::table_type table_type;
 
-  table_type& ah = getTable<value_type>::get(*this);
-  typename table_type::iterator i = ah.find(std::make_pair(AttrKind::getId(), n));
+  const table_type& ah = getTable<value_type>::get(*this);
+  typename table_type::const_iterator i = ah.find(std::make_pair(AttrKind::getId(), n));
 
   if(i == ah.end()) {
     return typename AttrKind::value_type();
@@ -468,12 +483,12 @@ struct HasAttribute;
 
 template <class AttrKind>
 struct HasAttribute<true, AttrKind> {
-  static inline bool hasAttribute(AttributeManager* am,
+  static inline bool hasAttribute(const AttributeManager* am,
                                   const Node& n) {
     return true;
   }
 
-  static inline bool hasAttribute(AttributeManager* am,
+  static inline bool hasAttribute(const AttributeManager* am,
                                   const Node& n,
                                   typename AttrKind::value_type* ret) {
     if(ret != NULL) {
@@ -481,8 +496,8 @@ struct HasAttribute<true, AttrKind> {
       typedef KindValueToTableValueMapping<value_type> mapping;
       typedef typename getTable<value_type>::table_type table_type;
 
-      table_type& ah = getTable<value_type>::get(*am);
-      typename table_type::iterator i = ah.find(std::make_pair(AttrKind::getId(), n));
+      const table_type& ah = getTable<value_type>::get(*am);
+      typename table_type::const_iterator i = ah.find(std::make_pair(AttrKind::getId(), n));
 
       if(i == ah.end()) {
         *ret = AttrKind::default_value;
@@ -497,14 +512,14 @@ struct HasAttribute<true, AttrKind> {
 
 template <class AttrKind>
 struct HasAttribute<false, AttrKind> {
-  static inline bool hasAttribute(AttributeManager* am,
+  static inline bool hasAttribute(const AttributeManager* am,
                                   const Node& n) {
     typedef typename AttrKind::value_type value_type;
     typedef KindValueToTableValueMapping<value_type> mapping;
     typedef typename getTable<value_type>::table_type table_type;
 
-    table_type& ah = getTable<value_type>::get(*am);
-    typename table_type::iterator i = ah.find(std::make_pair(AttrKind::getId(), n));
+    const table_type& ah = getTable<value_type>::get(*am);
+    typename table_type::const_iterator i = ah.find(std::make_pair(AttrKind::getId(), n));
 
     if(i == ah.end()) {
       return false;
@@ -513,15 +528,15 @@ struct HasAttribute<false, AttrKind> {
     return true;
   }
 
-  static inline bool hasAttribute(AttributeManager* am,
+  static inline bool hasAttribute(const AttributeManager* am,
                                   const Node& n,
                                   typename AttrKind::value_type* ret) {
     typedef typename AttrKind::value_type value_type;
     typedef KindValueToTableValueMapping<value_type> mapping;
     typedef typename getTable<value_type>::table_type table_type;
 
-    table_type& ah = getTable<value_type>::get(*am);
-    typename table_type::iterator i = ah.find(std::make_pair(AttrKind::getId(), n));
+    const table_type& ah = getTable<value_type>::get(*am);
+    typename table_type::const_iterator i = ah.find(std::make_pair(AttrKind::getId(), n));
 
     if(i == ah.end()) {
       return false;
@@ -537,14 +552,14 @@ struct HasAttribute<false, AttrKind> {
 
 template <class AttrKind>
 bool AttributeManager::hasAttribute(const Node& n,
-                                    const AttrKind&) {
+                                    const AttrKind&) const {
   return HasAttribute<AttrKind::has_default_value, AttrKind>::hasAttribute(this, n);
 }
 
 template <class AttrKind>
 bool AttributeManager::hasAttribute(const Node& n,
                                     const AttrKind&,
-                                    typename AttrKind::value_type* ret) {
+                                    typename AttrKind::value_type* ret) const {
   return HasAttribute<AttrKind::has_default_value, AttrKind>::hasAttribute(this, n, ret);
 }
 
index a39dc5b7e1895cab131525a7335867342295faf0..517a9eb7fddc6a920dd082283c76d95b2828e7fc 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "cvc4_config.h"
 #include "expr/kind.h"
+#include "expr/type.h"
 #include "util/Assert.h"
 
 namespace CVC4 {
@@ -156,11 +157,11 @@ public:
   bool isAtomic() const;
 
   template <class AttrKind>
-  inline typename AttrKind::value_type getAttribute(const AttrKind&);
+  inline typename AttrKind::value_type getAttribute(const AttrKind&) const;
 
   template <class AttrKind>
   inline bool hasAttribute(const AttrKind&,
-                           typename AttrKind::value_type* = NULL);
+                           typename AttrKind::value_type* = NULL) const;
 
   template <class AttrKind>
   inline void setAttribute(const AttrKind&,
@@ -262,7 +263,7 @@ inline size_t Node::getNumChildren() const {
 }
 
 template <class AttrKind>
-inline typename AttrKind::value_type Node::getAttribute(const AttrKind&) {
+inline typename AttrKind::value_type Node::getAttribute(const AttrKind&) const {
   Assert( NodeManager::currentNM() != NULL,
           "There is no current CVC4::NodeManager associated to this thread.\n"
           "Perhaps a public-facing function is missing a NodeManagerScope ?" );
@@ -272,7 +273,7 @@ inline typename AttrKind::value_type Node::getAttribute(const AttrKind&) {
 
 template <class AttrKind>
 inline bool Node::hasAttribute(const AttrKind&,
-                               typename AttrKind::value_type* ret) {
+                               typename AttrKind::value_type* ret) const {
   Assert( NodeManager::currentNM() != NULL,
           "There is no current CVC4::NodeManager associated to this thread.\n"
           "Perhaps a public-facing function is missing a NodeManagerScope ?" );
index 97f5ba9cd666c22641dd622d51d31fa03670e2f4..d6d54bd5d65637f3dde4f161017abfe864d70a7f 100644 (file)
@@ -79,12 +79,12 @@ public:
 
   template <class AttrKind>
   inline typename AttrKind::value_type getAttribute(const Node& n,
-                                                    const AttrKind&);
+                                                    const AttrKind&) const;
 
   template <class AttrKind>
   inline bool hasAttribute(const Node& n,
                            const AttrKind&,
-                           typename AttrKind::value_type* = NULL);
+                           typename AttrKind::value_type* = NULL) const;
 
   template <class AttrKind>
   inline void setAttribute(const Node& n,
@@ -110,14 +110,14 @@ public:
 
 template <class AttrKind>
 inline typename AttrKind::value_type NodeManager::getAttribute(const Node& n,
-                                                               const AttrKind&) {
+                                                               const AttrKind&) const {
   return d_am.getAttribute(n, AttrKind());
 }
 
 template <class AttrKind>
 inline bool NodeManager::hasAttribute(const Node& n,
                                       const AttrKind&,
-                                      typename AttrKind::value_type* ret) {
+                                      typename AttrKind::value_type* ret) const {
   return d_am.hasAttribute(n, AttrKind(), ret);
 }