[libcxxabi] [llvm] [ItaniumDemangle] Add customizable printLeft/printRight APIs to OutputBuffer (PR #133249)

Richard Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 16 11:58:24 PDT 2025


================
@@ -79,10 +81,24 @@ class OutputBuffer {
   OutputBuffer(const OutputBuffer &) = delete;
   OutputBuffer &operator=(const OutputBuffer &) = delete;
 
+  virtual ~OutputBuffer() {}
+
   operator std::string_view() const {
     return std::string_view(Buffer, CurrentPosition);
   }
 
+  /// Called by the demangler when printing the demangle tree. By
+  /// default calls into \c Node::print{Left|Right} but can be overriden
+  /// by clients to track additional state when printing the demangled name.
+  virtual void printLeft(const Node &N);
+  virtual void printRight(const Node &N);
+
+  /// Called when we write to this object anywhere other than the end.
+  virtual void notifyInsertion(size_t /*Position*/, size_t /*Count*/) {}
+
+  /// Called when we reset the \c CurrentPosition of this object.
+  virtual void notifyPositionChanged(size_t /*OldPos*/, size_t /*NewPos*/) {}
----------------
zygoloid wrote:

I think `notifyDeletion` / `notifyErasure` would make more sense here. `setCurrentPosition` is an erase operation, because `CurrentPosition` is treated as the end of the buffer.

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


More information about the llvm-commits mailing list