Remove unused Target argument from AsmParser construction methods.
[oota-llvm.git] / include / llvm / ADT / SmallBitVector.h
index 7563e81e1cef5e46c01234f08bca20f1f16b4d42..b15b3ee0418f9ce1f0b5f131058f0cda4ffc87da 100644 (file)
@@ -52,6 +52,34 @@ class SmallBitVector {
     SmallNumDataBits = SmallNumRawBits - SmallNumSizeBits
   };
 
+public:
+  // Encapsulation of a single bit.
+  class reference {
+    SmallBitVector &TheVector;
+    unsigned BitPos;
+
+  public:
+    reference(SmallBitVector &b, unsigned Idx) : TheVector(b), BitPos(Idx) {}
+
+    reference& operator=(reference t) {
+      *this = bool(t);
+      return *this;
+    }
+
+    reference& operator=(bool t) {
+      if (t)
+        TheVector.set(BitPos);
+      else
+        TheVector.reset(BitPos);
+      return *this;
+    }
+
+    operator bool() const {
+      return const_cast<const SmallBitVector &>(TheVector).operator[](BitPos);
+    }
+  };
+
+private:
   bool isSmall() const {
     return X & uintptr_t(1);
   }
@@ -81,7 +109,7 @@ class SmallBitVector {
 
   void setSmallRawBits(uintptr_t NewRawBits) {
     assert(isSmall());
-    X = NewRawBits << 1 | uintptr_t(1);
+    X = (NewRawBits << 1) | uintptr_t(1);
   }
 
   // Return the size.
@@ -99,7 +127,7 @@ class SmallBitVector {
   }
 
   void setSmallBits(uintptr_t NewBits) {
-    setSmallRawBits(NewBits & ~(~uintptr_t(0) << getSmallSize()) |
+    setSmallRawBits((NewBits & ~(~uintptr_t(0) << getSmallSize())) |
                     (getSmallSize() << SmallNumDataBits));
   }
 
@@ -159,6 +187,13 @@ public:
     return getPointer()->any();
   }
 
+  /// all - Returns true if all bits are set.
+  bool all() const {
+    if (isSmall())
+      return getSmallBits() == (uintptr_t(1) << getSmallSize()) - 1;
+    return getPointer()->all();
+  }
+
   /// none - Returns true if none of the bits are set.
   bool none() const {
     if (isSmall())
@@ -171,13 +206,12 @@ public:
   int find_first() const {
     if (isSmall()) {
       uintptr_t Bits = getSmallBits();
-      if (sizeof(uintptr_t) * CHAR_BIT == 32) {
-        size_t FirstBit = CountTrailingZeros_32(Bits);
-        return FirstBit == 32 ? -1 : FirstBit;
-      } else if (sizeof(uintptr_t) * CHAR_BIT == 64) {
-        size_t FirstBit = CountTrailingZeros_64(Bits);
-        return FirstBit == 64 ? -1 : FirstBit;
-      }
+      if (Bits == 0)
+        return -1;
+      if (sizeof(uintptr_t) * CHAR_BIT == 32)
+        return CountTrailingZeros_32(Bits);
+      if (sizeof(uintptr_t) * CHAR_BIT == 64)
+        return CountTrailingZeros_64(Bits);
       assert(0 && "Unsupported!");
     }
     return getPointer()->find_first();
@@ -190,13 +224,12 @@ public:
       uintptr_t Bits = getSmallBits();
       // Mask off previous bits.
       Bits &= ~uintptr_t(0) << (Prev + 1);
-      if (sizeof(uintptr_t) * CHAR_BIT == 32) {
-        size_t FirstBit = CountTrailingZeros_32(Bits);
-        return FirstBit == 32 ? -1 : FirstBit;
-      } else if (sizeof(uintptr_t) * CHAR_BIT == 64) {
-        size_t FirstBit = CountTrailingZeros_64(Bits);
-        return FirstBit == 64 ? -1 : FirstBit;
-      }
+      if (Bits == 0 || Prev + 1 >= getSmallSize())
+        return -1;
+      if (sizeof(uintptr_t) * CHAR_BIT == 32)
+        return CountTrailingZeros_32(Bits);
+      if (sizeof(uintptr_t) * CHAR_BIT == 64)
+        return CountTrailingZeros_64(Bits);
       assert(0 && "Unsupported!");
     }
     return getPointer()->find_next(Prev);
@@ -298,7 +331,11 @@ public:
   }
 
   // Indexing.
-  // TODO: Add an index operator which returns a "reference" (proxy class).
+  reference operator[](unsigned Idx) {
+    assert(Idx < size() && "Out-of-bounds Bit access.");
+    return reference(*this, Idx);
+  }
+
   bool operator[](unsigned Idx) const {
     assert(Idx < size() && "Out-of-bounds Bit access.");
     if (isSmall())