[llvm] r302460 - Add some useful helper methods / operators to TypeIndex.

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Mon May 8 12:46:38 PDT 2017


Author: zturner
Date: Mon May  8 14:46:37 2017
New Revision: 302460

URL: http://llvm.org/viewvc/llvm-project?rev=302460&view=rev
Log:
Add some useful helper methods / operators to TypeIndex.

Modified:
    llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h

Modified: llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h?rev=302460&r1=302459&r2=302460&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/CodeView/TypeIndex.h Mon May  8 14:46:37 2017
@@ -106,6 +106,15 @@ public:
 
   bool isNoneType() const { return *this == None(); }
 
+  uint32_t toArrayIndex() const {
+    assert(!isSimple());
+    return getIndex() - FirstNonSimpleIndex;
+  }
+
+  static TypeIndex fromArrayIndex(uint32_t Index) {
+    return TypeIndex(Index + FirstNonSimpleIndex);
+  }
+
   SimpleTypeKind getSimpleKind() const {
     assert(isSimple());
     return static_cast<SimpleTypeKind>(Index & SimpleKindMask);
@@ -159,6 +168,39 @@ public:
   static TypeIndex Float32() { return TypeIndex(SimpleTypeKind::Float32); }
   static TypeIndex Float64() { return TypeIndex(SimpleTypeKind::Float64); }
 
+  TypeIndex &operator+=(unsigned N) {
+    Index += N;
+    return *this;
+  }
+
+  TypeIndex &operator++() {
+    Index += 1;
+    return *this;
+  }
+
+  TypeIndex operator++(int) {
+    TypeIndex Copy = *this;
+    operator++();
+    return Copy;
+  }
+
+  TypeIndex &operator-=(unsigned N) {
+    assert(Index >= N);
+    Index -= N;
+    return *this;
+  }
+
+  TypeIndex &operator--() {
+    Index -= 1;
+    return *this;
+  }
+
+  TypeIndex operator--(int) {
+    TypeIndex Copy = *this;
+    operator--();
+    return Copy;
+  }
+
   friend inline bool operator==(const TypeIndex &A, const TypeIndex &B) {
     return A.getIndex() == B.getIndex();
   }
@@ -183,6 +225,19 @@ public:
     return A.getIndex() >= B.getIndex();
   }
 
+  friend inline TypeIndex operator+(const TypeIndex &A, uint32_t N) {
+    TypeIndex Result(A);
+    Result += N;
+    return Result;
+  }
+
+  friend inline TypeIndex operator-(const TypeIndex &A, uint32_t N) {
+    assert(A.getIndex() >= N);
+    TypeIndex Result(A);
+    Result -= N;
+    return Result;
+  }
+
 private:
   support::ulittle32_t Index;
 };




More information about the llvm-commits mailing list