[clang] [clang] Add Bytes/Column types to TextDiagnostic (PR #165541)

via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 29 06:18:20 PDT 2025


Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>,
Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/165541 at github.com>


================
@@ -47,6 +47,43 @@ static constexpr raw_ostream::Colors CommentColor = raw_ostream::YELLOW;
 static constexpr raw_ostream::Colors LiteralColor = raw_ostream::GREEN;
 static constexpr raw_ostream::Colors KeywordColor = raw_ostream::BLUE;
 
+namespace {
+template <typename Sub> class ColumnsOrBytes {
+public:
+  int V = 0;
+  ColumnsOrBytes(int V) : V(V) {}
+  bool isValid() const { return V != -1; }
+  Sub next() const { return Sub(V + 1); }
+  Sub prev() const { return Sub(V - 1); }
+
+  bool operator>(ColumnsOrBytes O) const { return V > O.V; }
+  bool operator<(ColumnsOrBytes O) const { return V < O.V; }
+  bool operator<=(ColumnsOrBytes B) const { return V <= B.V; }
+  bool operator!=(ColumnsOrBytes C) const { return C.V != V; }
+
+  Sub operator+(Sub B) const { return Sub(V + B.V); }
+  Sub &operator+=(Sub B) {
+    V += B.V;
+    return *(Sub *)this;
+  }
+  Sub operator-(Sub B) const { return Sub(V - B.V); }
+  Sub &operator-=(Sub B) {
+    V -= B.V;
+    return *(Sub *)this;
----------------
Sirraide wrote:

```suggestion
    return *static_cast<Sub *>(this);
```

https://github.com/llvm/llvm-project/pull/165541


More information about the cfe-commits mailing list