#ifndef __CVC4__EXPR__ATTRIBUTE_INTERNALS_H
#define __CVC4__EXPR__ATTRIBUTE_INTERNALS_H
+#include <cstdint>
#include <unordered_map>
namespace CVC4 {
namespace attr {
+// Returns a 64 bit integer with a single `bit` set when `bit` < 64.
+// Avoids problems in (1 << x) when sizeof(x) <= sizeof(uint64_t).
+inline uint64_t GetBitSet(uint64_t bit)
+{
+ constexpr uint64_t kOne = 1;
+ return kOne << bit;
+}
+
/**
* An "AttrHash<value_type>"---the hash table underlying
* attributes---is simply a mapping of pair<unique-attribute-id, Node>
uint64_t& d_word;
- unsigned d_bit;
-
- public:
+ uint64_t d_bit;
- BitAccessor(uint64_t& word, unsigned bit) :
- d_word(word),
- d_bit(bit) {
- }
+ public:
+ BitAccessor(uint64_t& word, uint64_t bit) : d_word(word), d_bit(bit) {}
BitAccessor& operator=(bool b) {
if(b) {
// set the bit
- d_word |= (1 << d_bit);
+ d_word |= GetBitSet(d_bit);
} else {
// clear the bit
- d_word &= ~(1 << d_bit);
+ d_word &= ~GetBitSet(d_bit);
}
return *this;
}
- operator bool() const {
- return (d_word & (1 << d_bit)) ? true : false;
- }
+ operator bool() const { return (d_word & GetBitSet(d_bit)) ? true : false; }
};/* class AttrHash<bool>::BitAccessor */
/**
std::pair<NodeValue* const, uint64_t>* d_entry;
- unsigned d_bit;
+ uint64_t d_bit;
- public:
+ public:
BitIterator() :
d_entry(NULL),
d_bit(0) {
}
- BitIterator(std::pair<NodeValue* const, uint64_t>& entry, unsigned bit) :
- d_entry(&entry),
- d_bit(bit) {
+ BitIterator(std::pair<NodeValue* const, uint64_t>& entry, uint64_t bit)
+ : d_entry(&entry), d_bit(bit)
+ {
}
std::pair<NodeValue* const, BitAccessor> operator*() {
const std::pair<NodeValue* const, uint64_t>* d_entry;
- unsigned d_bit;
+ uint64_t d_bit;
- public:
+ public:
ConstBitIterator() :
d_entry(NULL),
}
ConstBitIterator(const std::pair<NodeValue* const, uint64_t>& entry,
- unsigned bit) :
- d_entry(&entry),
- d_bit(bit) {
+ uint64_t bit)
+ : d_entry(&entry), d_bit(bit)
+ {
}
- std::pair<NodeValue* const, bool> operator*() {
- return std::make_pair(d_entry->first,
- (d_entry->second & (1 << d_bit)) ? true : false);
+ std::pair<NodeValue* const, bool> operator*()
+ {
+ return std::make_pair(
+ d_entry->first, (d_entry->second & GetBitSet(d_bit)) ? true : false);
}
bool operator==(const ConstBitIterator& b) {
Debug.printf("boolattr",
"underlying word at 0x%p looks like 0x%016llx, bit is %u\n",
&(*i).second,
- (unsigned long long)((*i).second),
- unsigned(k.first));
+ (uint64_t)((*i).second),
+ uint64_t(k.first));
*/
return BitIterator(*i, k.first);
}
Debug.printf("boolattr",
"underlying word at 0x%p looks like 0x%016llx, bit is %u\n",
&(*i).second,
- (unsigned long long)((*i).second),
- unsigned(k.first));
+ (uint64_t)((*i).second),
+ uint64_t(k.first));
*/
return ConstBitIterator(*i, k.first);
}